Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring: Address, AssignVehicle, DriversScheduleswithTerritoriesV… #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public static void main(String[] args) {
optParameters.setAddresses(addresses);

try {
DataObject responseObject = manager.runOptimization(optParameters);
DataObject responseObject = manager.runOptimizationWithRedirect0(optParameters);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@r4m-cristianv

This is not needed we have this method:

public RoutingManager(String apiKey, boolean disableRedirects) {
    super(apiKey, disableRedirects);
}

to disabled redirects

https://github.com/route4me/route4me-java-sdk/blob/008e6a9e0c59899a8a3c7102d3cf9e46ba27552c/src/main/java/com/route4me/sdk/services/routing/RoutingManager.java#L48C1-L50C6

When that method is used we do this:

        if (this.disableRedirects) {
            builder.addParameter("redirect", "0");
            client = HttpClients.custom().disableRedirectHandling().build();
        }

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right, I missed this

System.out.println("Optimization Problem ID:" + responseObject.getOptimizationProblemId());
System.out.println("State:" + OptimizationState.get(responseObject.getState().intValue()));
if (responseObject.getAddresses() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package com.route4me.sdk.examples.orders;

import com.route4me.sdk.exception.APIException;
import com.route4me.sdk.services.orders.Order;
import com.route4me.sdk.services.orders.OrderRequest;
import com.route4me.sdk.services.orders.OrdersManager;

Expand All @@ -13,7 +12,7 @@ public static void main(String[] args) {
String apiKey = System.getenv("R4M_API_KEY");
OrdersManager manager = new OrdersManager(apiKey);
try {
List<Order> orders = manager.getOrders(new OrderRequest().setFields("member_id,order_id"));
List<List<Long>> orders = manager.getOrdersByCustomFields(new OrderRequest().setFields("member_id,order_id"));
System.out.println(orders);
} catch (APIException e) {
//handle exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void main(String[] args) {

address = new Address("4805 BELLEVUE AVE, Louisville, KY, 40215", 38.178844, -85.774864, 300);
address.setPickUp("PD0004");
address.setJoint(1);
address.setJoint(true);
address.setAlias("Pickup - Customer 004");
addresses.add(address);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.route4me.sdk.exception.APIException;
import com.route4me.sdk.services.routing.Route;
import com.route4me.sdk.services.routing.RoutesRequest;
import com.route4me.sdk.services.routing.RoutingManager;

/**
Expand All @@ -19,9 +20,9 @@ public static void main(String[] args) {
String apiKey = System.getenv("R4M_API_KEY");
RoutingManager routeManager = new RoutingManager(apiKey);
try {
String routeId = "FA249A8FAC4D7FA7938C77784737481F";
String vehicleId = "64ACF1E576D078D853F935E788A42F93";
Route newRoute = routeManager.assignVehicle(routeId, vehicleId);
Route route = routeManager.getRoute(new RoutesRequest().setId("")); //SET VALID ROUTE ID
String vehicleId = ""; //SET VALID VEHICLE ID
Route newRoute = routeManager.assignVehicle(route, vehicleId);
System.out.println(newRoute);
} catch (APIException e) {
//handle exceptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.route4me.sdk.exception.APIException;
import com.route4me.sdk.services.telematics.TelematicsManager;
import com.route4me.sdk.services.telematics.TelematicsVendorsInfo;

import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public List<Order> getOrders(OrderRequest request) throws APIException {
return this.makeJSONRequest(RequestMethod.GET, builder, request, GetOrdersResponse.class).getResults();
}

public List<List<Long>> getOrdersByCustomFields(OrderRequest request) throws APIException {
URIBuilder builder = Manager.defaultBuilder(ORDERS_EP);
return this.makeJSONRequest(RequestMethod.GET, builder, request, GetOrdersResponseByCustomFields.class).getResults();
}

public List<Order> getOrdersByScheduledDate(List<String> scheduledForYYMMDD) throws APIException {
return this.getOrdersByScheduledDate(scheduledForYYMMDD, 30, 0);
}
Expand Down Expand Up @@ -106,10 +111,20 @@ private static class GetOrdersResponse {
private Integer total;
}

@Getter
@Setter(AccessLevel.PRIVATE)
private static class GetOrdersResponseByCustomFields {
@SerializedName("results")
private List<List<Long>> results;
@SerializedName("total")
private Integer total;
@SerializedName("fields")
private List<String> fields;
}

@Data
@RequiredArgsConstructor
private static class DeleteOrdersRequest {

@SerializedName("order_ids")
private final long[] orderIds;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public class Address {
@SerializedName("dropoff")
private String dropOff;
@SerializedName("joint")
private Integer joint;
private Boolean joint;

@SerializedName("tags")
@QueryParameter("tags")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public DataObject runOptimization(OptimizationParameters parameters) throws APIE
URIBuilder builder = Manager.defaultBuilder(OPTIMIZATION_EP);
return this.makeJSONRequest(RequestMethod.POST, builder, parameters, DataObject.class);
}

public DataObject runOptimizationWithRedirect0(OptimizationParameters parameters) throws APIException {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed @r4m-cristianv

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

URIBuilder builder = Manager.defaultBuilder(OPTIMIZATION_EP);
builder.setParameter("redirect", "0");
return this.makeJSONRequest(RequestMethod.POST, builder, parameters, DataObject.class);
}

public DataObject[] runOptimizationMulti(OptimizationParameters parameters) throws APIException {
URIBuilder builder = Manager.defaultBuilder(OPTIMIZATION_EP);
Expand Down Expand Up @@ -138,7 +144,7 @@ public DataObject moveAddresses(DataObject dataObj, String routeId) throws APIEx
}

public void deleteAddress(String routeId, Number routeDestinationId) throws APIException {
URIBuilder builder = Manager.defaultBuilder(ROUTE_EP);
URIBuilder builder = Manager.defaultBuilder(ADDRESS_EP);
builder.setParameter("route_id", routeId);
builder.setParameter("route_destination_id", routeDestinationId.toString());
this.makeRequest(RequestMethod.DELETE, builder, "", null);
Expand Down Expand Up @@ -231,6 +237,16 @@ public Route assignVehicle(String routeId, String vehicle_id) throws APIExceptio
route.setParameters(params);
return updateRoute(route);
}

public Route assignVehicle(Route route, String vehicle_id) throws APIException {
Parameters params = new Parameters();
params.setVehicleId(vehicle_id);
route.setParameters(params);
URIBuilder builder = Manager.defaultBuilder(ROUTE_EP);
String routeId = route.getId();
builder.setParameter("route_id", routeId);
return this.makeJSONRequest(RequestMethod.PUT, builder, route.getParameters(), Route.class);
}

public RouteDeletedResponse deleteRoutes(String... routeIds) throws APIException {
URIBuilder builder = Manager.defaultBuilder(ROUTE_EP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public TelematicsManager(String apiKey) {
super(apiKey);
}

private URIBuilder getTelemaricsVendorURI() {
private URIBuilder getTelematicsVendorURI() {
URIBuilder builder = new URIBuilder();
builder.setScheme("https");
builder.setHost("telematics.route4me.com");
Expand All @@ -50,20 +50,18 @@ public List<TelematicsConnection> getTelematicsConnections(String apiToken) thro
}

public TelematicsVendorsInfo getTelematicsVendorsInfo() throws APIException {
URIBuilder builder = getTelemaricsVendorURI();
URIBuilder builder = getTelematicsVendorURI();
return makeRequest(RequestMethod.GET, builder, "", TelematicsVendorsInfo.class);

}

public TelematicsVendorsInfo getTelematicsVendorInfo(String vendorID) throws APIException {
URIBuilder builder = getTelemaricsVendorURI();
URIBuilder builder = getTelematicsVendorURI();
builder.setParameter("vendor_id", vendorID);
return makeRequest(RequestMethod.GET, builder, "", TelematicsVendorsInfo.class);

}

private TelematicsVendorsInfo searchVendor(String country, String size, String keyWord, String feature, String page, String perPage) throws APIException {
URIBuilder builder = getTelemaricsVendorURI();
URIBuilder builder = getTelematicsVendorURI();
if (country != null) {
builder.setParameter("country", country);
}
Expand Down Expand Up @@ -172,7 +170,7 @@ private List<TelematicsVendorComparison> parseVendorFeaturesComparison(Telematic
}

public List<TelematicsVendorComparison> compareTelematicsVendors(String vendorIDs) throws APIException {
URIBuilder builder = getTelemaricsVendorURI();
URIBuilder builder = getTelematicsVendorURI();
builder.setParameter("vendors", vendorIDs);
TelematicsVendorsInfo vendors = makeRequest(RequestMethod.GET, builder, "", TelematicsVendorsInfo.class);
return parseVendorFeaturesComparison(vendors);
Expand Down