diff --git a/examples/src/main/java/com/traveltime/examples/TimeFilterExample.java b/examples/src/main/java/com/traveltime/examples/TimeFilterExample.java index 5239785..52f45a5 100644 --- a/examples/src/main/java/com/traveltime/examples/TimeFilterExample.java +++ b/examples/src/main/java/com/traveltime/examples/TimeFilterExample.java @@ -5,9 +5,9 @@ import com.traveltime.sdk.dto.common.Coordinates; import com.traveltime.sdk.dto.common.Location; import com.traveltime.sdk.dto.common.Property; +import com.traveltime.sdk.dto.common.transportationfast.Driving; import com.traveltime.sdk.dto.requests.TimeFilterFastRequest; import com.traveltime.sdk.dto.requests.timefilterfast.ArrivalSearches; -import com.traveltime.sdk.dto.requests.timefilterfast.transportation.Driving; import com.traveltime.sdk.dto.requests.timefilterfast.OneToMany; import lombok.val; diff --git a/src/main/java/com/traveltime/sdk/TravelTimeSDK.java b/src/main/java/com/traveltime/sdk/TravelTimeSDK.java index 9c78077..83ac41c 100644 --- a/src/main/java/com/traveltime/sdk/TravelTimeSDK.java +++ b/src/main/java/com/traveltime/sdk/TravelTimeSDK.java @@ -78,23 +78,19 @@ private Either parseJsonBody(TravelTimeRequest reques private Either deserializeProtoResponse(ProtoRequest request, Response response) { String url = response.request().url().toString(); - switch(response.code()){ - case 404: { - RequestError error = new RequestError("Network response is 404 (Not found). Make sure URL " + - url + " is correct."); - return Either.left(error); - } - default: { - Either protoResponse = Try - .of(() -> Objects.requireNonNull(response.body()).bytes()) - .toEither() - .mapLeft(cause -> new IOError(cause, IO_CONNECTION_ERROR + cause.getMessage())) - .flatMap(request::parseBytes); - - response.close(); - return protoResponse; - } + if (response.code() == 404) { + RequestError error = new RequestError("Network response is 404 (Not found). Make sure URL " + + url + " is correct."); + return Either.left(error); } + Either protoResponse = Try + .of(() -> Objects.requireNonNull(response.body()).bytes()) + .toEither() + .mapLeft(cause -> new IOError(cause, IO_CONNECTION_ERROR + cause.getMessage())) + .flatMap(request::parseBytes); + + response.close(); + return protoResponse; } private Either getParsedResponse(TravelTimeRequest request, Response response) { diff --git a/src/main/java/com/traveltime/sdk/dto/responses/timemap/Shape.java b/src/main/java/com/traveltime/sdk/dto/common/Shape.java similarity index 63% rename from src/main/java/com/traveltime/sdk/dto/responses/timemap/Shape.java rename to src/main/java/com/traveltime/sdk/dto/common/Shape.java index d2bb662..04648cb 100644 --- a/src/main/java/com/traveltime/sdk/dto/responses/timemap/Shape.java +++ b/src/main/java/com/traveltime/sdk/dto/common/Shape.java @@ -1,7 +1,8 @@ -package com.traveltime.sdk.dto.responses.timemap; +package com.traveltime.sdk.dto.common; -import com.traveltime.sdk.dto.common.Coordinates; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Value; import lombok.extern.jackson.Jacksonized; import java.util.List; diff --git a/src/main/java/com/traveltime/sdk/dto/common/transportationfast/Cycling.java b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/Cycling.java new file mode 100644 index 0000000..ad77049 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/Cycling.java @@ -0,0 +1,6 @@ +package com.traveltime.sdk.dto.common.transportationfast; + +import lombok.Value; + +@Value +public class Cycling implements Transportation { } diff --git a/src/main/java/com/traveltime/sdk/dto/common/transportationfast/CyclingAndFerry.java b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/CyclingAndFerry.java new file mode 100644 index 0000000..e5b0c4e --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/CyclingAndFerry.java @@ -0,0 +1,6 @@ +package com.traveltime.sdk.dto.common.transportationfast; + +import lombok.Value; + +@Value +public class CyclingAndFerry implements Transportation { } diff --git a/src/main/java/com/traveltime/sdk/dto/common/transportationfast/Driving.java b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/Driving.java new file mode 100644 index 0000000..cfcf3f9 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/Driving.java @@ -0,0 +1,6 @@ +package com.traveltime.sdk.dto.common.transportationfast; + +import lombok.Value; + +@Value +public class Driving implements Transportation { } diff --git a/src/main/java/com/traveltime/sdk/dto/common/transportationfast/DrivingAndFerry.java b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/DrivingAndFerry.java new file mode 100644 index 0000000..d62ed2f --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/DrivingAndFerry.java @@ -0,0 +1,6 @@ +package com.traveltime.sdk.dto.common.transportationfast; + +import lombok.Value; + +@Value +public class DrivingAndFerry implements Transportation { } diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/DrivingAndPublicTransport.java b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/DrivingAndPublicTransport.java similarity index 76% rename from src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/DrivingAndPublicTransport.java rename to src/main/java/com/traveltime/sdk/dto/common/transportationfast/DrivingAndPublicTransport.java index e5a8c65..1936fe9 100644 --- a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/DrivingAndPublicTransport.java +++ b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/DrivingAndPublicTransport.java @@ -1,7 +1,6 @@ -package com.traveltime.sdk.dto.requests.timefilterfast.transportation; +package com.traveltime.sdk.dto.common.transportationfast; import com.fasterxml.jackson.annotation.JsonInclude; -import com.traveltime.sdk.dto.requests.timefilterfast.Transportation; import jakarta.validation.constraints.Positive; import lombok.AllArgsConstructor; import lombok.Builder; diff --git a/src/main/java/com/traveltime/sdk/dto/common/transportationfast/PublicTransport.java b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/PublicTransport.java new file mode 100644 index 0000000..2fb39ed --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/PublicTransport.java @@ -0,0 +1,6 @@ +package com.traveltime.sdk.dto.common.transportationfast; + +import lombok.Value; + +@Value +public class PublicTransport implements Transportation { } \ No newline at end of file diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/Transportation.java b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/Transportation.java similarity index 86% rename from src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/Transportation.java rename to src/main/java/com/traveltime/sdk/dto/common/transportationfast/Transportation.java index 1f1ff43..169ff50 100644 --- a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/Transportation.java +++ b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/Transportation.java @@ -1,8 +1,7 @@ -package com.traveltime.sdk.dto.requests.timefilterfast; +package com.traveltime.sdk.dto.common.transportationfast; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.traveltime.sdk.dto.requests.timefilterfast.transportation.*; @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, diff --git a/src/main/java/com/traveltime/sdk/dto/common/transportationfast/Walking.java b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/Walking.java new file mode 100644 index 0000000..d554ead --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/Walking.java @@ -0,0 +1,6 @@ +package com.traveltime.sdk.dto.common.transportationfast; + +import lombok.Value; + +@Value +public class Walking implements Transportation { } diff --git a/src/main/java/com/traveltime/sdk/dto/common/transportationfast/WalkingAndFerry.java b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/WalkingAndFerry.java new file mode 100644 index 0000000..6c2258b --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/common/transportationfast/WalkingAndFerry.java @@ -0,0 +1,6 @@ +package com.traveltime.sdk.dto.common.transportationfast; + +import lombok.Value; + +@Value +public class WalkingAndFerry implements Transportation { } diff --git a/src/main/java/com/traveltime/sdk/dto/requests/ProtoRequest.java b/src/main/java/com/traveltime/sdk/dto/requests/ProtoRequest.java index 31ec6bb..26a20a7 100644 --- a/src/main/java/com/traveltime/sdk/dto/requests/ProtoRequest.java +++ b/src/main/java/com/traveltime/sdk/dto/requests/ProtoRequest.java @@ -12,7 +12,6 @@ import okhttp3.Request; import okhttp3.RequestBody; -import java.net.URI; import java.util.List; public abstract class ProtoRequest { diff --git a/src/main/java/com/traveltime/sdk/dto/requests/TimeMapFastBoxesRequest.java b/src/main/java/com/traveltime/sdk/dto/requests/TimeMapFastBoxesRequest.java new file mode 100644 index 0000000..ec09a9b --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/requests/TimeMapFastBoxesRequest.java @@ -0,0 +1,39 @@ +package com.traveltime.sdk.dto.requests; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.traveltime.sdk.auth.TravelTimeCredentials; +import com.traveltime.sdk.dto.requests.timemapfast.ArrivalSearches; +import com.traveltime.sdk.dto.responses.TimeMapFastBoxesResponse; +import com.traveltime.sdk.dto.responses.errors.TravelTimeError; +import com.traveltime.sdk.utils.AcceptType; +import com.traveltime.sdk.utils.JsonUtils; +import io.vavr.control.Either; +import lombok.*; +import lombok.extern.jackson.Jacksonized; +import okhttp3.HttpUrl; +import okhttp3.Request; + +@Value +@Builder +@Jacksonized +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class TimeMapFastBoxesRequest extends TravelTimeRequest { + @NonNull + ArrivalSearches arrivalSearches; + + @Override + public Either createRequest(HttpUrl baseUri, TravelTimeCredentials credentials) { + val uri = baseUri.newBuilder().addPathSegments("time-map/fast").build(); + AcceptType acceptType = AcceptType.APPLICATION_BOUNDING_BOXES_JSON; + return JsonUtils + .toJson(this) + .map(json -> createPostRequest(credentials, uri, json, acceptType)); + } + + @Override + public Class responseType() { + return TimeMapFastBoxesResponse.class; + } +} diff --git a/src/main/java/com/traveltime/sdk/dto/requests/TimeMapFastGeoJsonRequest.java b/src/main/java/com/traveltime/sdk/dto/requests/TimeMapFastGeoJsonRequest.java new file mode 100644 index 0000000..0b53a3e --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/requests/TimeMapFastGeoJsonRequest.java @@ -0,0 +1,38 @@ +package com.traveltime.sdk.dto.requests; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.traveltime.sdk.auth.TravelTimeCredentials; +import com.traveltime.sdk.dto.requests.timemapfast.ArrivalSearches; +import com.traveltime.sdk.dto.responses.TimeMapFastGeoJsonResponse; +import com.traveltime.sdk.dto.responses.errors.TravelTimeError; +import com.traveltime.sdk.utils.AcceptType; +import com.traveltime.sdk.utils.JsonUtils; +import io.vavr.control.Either; +import lombok.*; +import lombok.extern.jackson.Jacksonized; +import okhttp3.HttpUrl; +import okhttp3.Request; + +@Value +@Builder +@Jacksonized +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class TimeMapFastGeoJsonRequest extends TravelTimeRequest { + @NonNull + ArrivalSearches arrivalSearches; + + @Override + public Either createRequest(HttpUrl baseUri, TravelTimeCredentials credentials) { + val uri = baseUri.newBuilder().addPathSegments("time-map/fast").build(); + return JsonUtils + .toJson(this) + .map(json -> createPostRequest(credentials, uri, json, AcceptType.APPLICATION_GEO_JSON)); + } + + @Override + public Class responseType() { + return TimeMapFastGeoJsonResponse.class; + } +} \ No newline at end of file diff --git a/src/main/java/com/traveltime/sdk/dto/requests/TimeMapFastRequest.java b/src/main/java/com/traveltime/sdk/dto/requests/TimeMapFastRequest.java new file mode 100644 index 0000000..0894d00 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/requests/TimeMapFastRequest.java @@ -0,0 +1,38 @@ +package com.traveltime.sdk.dto.requests; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.traveltime.sdk.auth.TravelTimeCredentials; +import com.traveltime.sdk.dto.requests.timemapfast.ArrivalSearches; +import com.traveltime.sdk.dto.responses.TimeMapFastResponse; +import com.traveltime.sdk.dto.responses.errors.TravelTimeError; +import com.traveltime.sdk.utils.AcceptType; +import com.traveltime.sdk.utils.JsonUtils; +import io.vavr.control.Either; +import lombok.*; +import lombok.extern.jackson.Jacksonized; +import okhttp3.HttpUrl; +import okhttp3.Request; + +@Value +@Builder +@Jacksonized +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class TimeMapFastRequest extends TravelTimeRequest { + @NonNull + ArrivalSearches arrivalSearches; + + @Override + public Either createRequest(HttpUrl baseUri, TravelTimeCredentials credentials) { + val uri = baseUri.newBuilder().addPathSegments("time-map/fast").build(); + return JsonUtils + .toJson(this) + .map(json -> createPostRequest(credentials, uri, json, AcceptType.APPLICATION_JSON)); + } + + @Override + public Class responseType() { + return TimeMapFastResponse.class; + } +} diff --git a/src/main/java/com/traveltime/sdk/dto/requests/TimeMapFastWktRequest.java b/src/main/java/com/traveltime/sdk/dto/requests/TimeMapFastWktRequest.java new file mode 100644 index 0000000..bf53dc7 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/requests/TimeMapFastWktRequest.java @@ -0,0 +1,44 @@ +package com.traveltime.sdk.dto.requests; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.traveltime.sdk.auth.TravelTimeCredentials; +import com.traveltime.sdk.dto.requests.timemapfast.ArrivalSearches; +import com.traveltime.sdk.dto.responses.TimeMapFastWktResponse; +import com.traveltime.sdk.dto.responses.errors.TravelTimeError; +import com.traveltime.sdk.utils.AcceptType; +import com.traveltime.sdk.utils.JsonUtils; +import io.vavr.control.Either; +import lombok.*; +import lombok.extern.jackson.Jacksonized; +import okhttp3.HttpUrl; +import okhttp3.Request; + +@Value +@Builder +@Jacksonized +@AllArgsConstructor +@EqualsAndHashCode(callSuper = true) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class TimeMapFastWktRequest extends TravelTimeRequest { + @NonNull + ArrivalSearches arrivalSearches; + @Builder.Default + boolean withHoles = true; + + private AcceptType acceptType() { + return withHoles ? AcceptType.APPLICATION_WKT_JSON : AcceptType.APPLICATION_WKT_NO_HOLES_JSON; + } + + @Override + public Either createRequest(HttpUrl baseUri, TravelTimeCredentials credentials) { + val uri = baseUri.newBuilder().addPathSegments("time-map/fast").build(); + return JsonUtils + .toJson(this) + .map(json -> createPostRequest(credentials, uri, json, acceptType())); + } + + @Override + public Class responseType() { + return TimeMapFastWktResponse.class; + } +} diff --git a/src/main/java/com/traveltime/sdk/dto/requests/TimeMapWktRequest.java b/src/main/java/com/traveltime/sdk/dto/requests/TimeMapWktRequest.java index fe68d6e..9f2d15b 100644 --- a/src/main/java/com/traveltime/sdk/dto/requests/TimeMapWktRequest.java +++ b/src/main/java/com/traveltime/sdk/dto/requests/TimeMapWktRequest.java @@ -43,11 +43,7 @@ public class TimeMapWktRequest extends TravelTimeRequest { boolean withHoles = true; public AcceptType acceptType() { - if (withHoles) { - return AcceptType.APPLICATION_WKT_JSON; - } else { - return AcceptType.APPLICATION_WKT_NO_HOLES_JSON; - } + return withHoles ? AcceptType.APPLICATION_WKT_JSON : AcceptType.APPLICATION_WKT_NO_HOLES_JSON; } @Override diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/ManyToOne.java b/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/ManyToOne.java index 529fe8b..de4f2cd 100644 --- a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/ManyToOne.java +++ b/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/ManyToOne.java @@ -1,6 +1,7 @@ package com.traveltime.sdk.dto.requests.timefilterfast; import com.traveltime.sdk.dto.common.Property; +import com.traveltime.sdk.dto.common.transportationfast.Transportation; import lombok.*; import lombok.extern.jackson.Jacksonized; diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/OneToMany.java b/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/OneToMany.java index 630239a..b1d46e8 100644 --- a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/OneToMany.java +++ b/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/OneToMany.java @@ -1,6 +1,7 @@ package com.traveltime.sdk.dto.requests.timefilterfast; import com.traveltime.sdk.dto.common.Property; +import com.traveltime.sdk.dto.common.transportationfast.Transportation; import lombok.*; import lombok.extern.jackson.Jacksonized; diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/Cycling.java b/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/Cycling.java deleted file mode 100644 index d7b708e..0000000 --- a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/Cycling.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.traveltime.sdk.dto.requests.timefilterfast.transportation; - -import com.traveltime.sdk.dto.requests.timefilterfast.Transportation; -import lombok.Value; - -@Value -public class Cycling implements Transportation { } diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/CyclingAndFerry.java b/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/CyclingAndFerry.java deleted file mode 100644 index c515ade..0000000 --- a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/CyclingAndFerry.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.traveltime.sdk.dto.requests.timefilterfast.transportation; - -import com.traveltime.sdk.dto.requests.timefilterfast.Transportation; -import lombok.Value; - -@Value -public class CyclingAndFerry implements Transportation { } diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/Driving.java b/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/Driving.java deleted file mode 100644 index 1f50132..0000000 --- a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/Driving.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.traveltime.sdk.dto.requests.timefilterfast.transportation; - -import com.traveltime.sdk.dto.requests.timefilterfast.Transportation; -import lombok.Value; - -@Value -public class Driving implements Transportation { } diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/DrivingAndFerry.java b/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/DrivingAndFerry.java deleted file mode 100644 index ec97aac..0000000 --- a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/DrivingAndFerry.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.traveltime.sdk.dto.requests.timefilterfast.transportation; - -import com.traveltime.sdk.dto.requests.timefilterfast.Transportation; -import lombok.Value; - -@Value -public class DrivingAndFerry implements Transportation { } diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/PublicTransport.java b/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/PublicTransport.java deleted file mode 100644 index 04abf63..0000000 --- a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/PublicTransport.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.traveltime.sdk.dto.requests.timefilterfast.transportation; - -import com.traveltime.sdk.dto.requests.timefilterfast.Transportation; -import lombok.Value; - -@Value -public class PublicTransport implements Transportation { } \ No newline at end of file diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/Walking.java b/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/Walking.java deleted file mode 100644 index fec888c..0000000 --- a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/Walking.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.traveltime.sdk.dto.requests.timefilterfast.transportation; - -import com.traveltime.sdk.dto.requests.timefilterfast.Transportation; -import lombok.Value; - -@Value -public class Walking implements Transportation { } diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/WalkingAndFerry.java b/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/WalkingAndFerry.java deleted file mode 100644 index be67c6c..0000000 --- a/src/main/java/com/traveltime/sdk/dto/requests/timefilterfast/transportation/WalkingAndFerry.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.traveltime.sdk.dto.requests.timefilterfast.transportation; - -import com.traveltime.sdk.dto.requests.timefilterfast.Transportation; -import lombok.Value; - -@Value -public class WalkingAndFerry implements Transportation { } diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/ArrivalSearches.java b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/ArrivalSearches.java new file mode 100644 index 0000000..2f7625a --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/ArrivalSearches.java @@ -0,0 +1,20 @@ +package com.traveltime.sdk.dto.requests.timemapfast; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NonNull; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +import java.util.List; + +@Value +@Builder +@Jacksonized +@AllArgsConstructor +public class ArrivalSearches { + @NonNull + List manyToOne; + @NonNull + List oneToMany; +} diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/ManyToOne.java b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/ManyToOne.java new file mode 100644 index 0000000..f1d9ff4 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/ManyToOne.java @@ -0,0 +1,28 @@ +package com.traveltime.sdk.dto.requests.timemapfast; + +import com.traveltime.sdk.dto.common.Coordinates; +import com.traveltime.sdk.dto.common.transportationfast.Transportation; +import com.traveltime.sdk.dto.requests.timemapfast.levelofdetail.LevelOfDetail; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NonNull; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +@Value +@Builder +@Jacksonized +@AllArgsConstructor +public class ManyToOne { + @NonNull + String id; + @NonNull + Coordinates coords; + @NonNull + String arrivalTimePeriod; + @NonNull + Integer travelTime; + @NonNull + Transportation transportation; + LevelOfDetail levelOfDetail; +} diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/OneToMany.java b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/OneToMany.java new file mode 100644 index 0000000..69ae020 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/OneToMany.java @@ -0,0 +1,28 @@ +package com.traveltime.sdk.dto.requests.timemapfast; + +import com.traveltime.sdk.dto.common.Coordinates; +import com.traveltime.sdk.dto.common.transportationfast.Transportation; +import com.traveltime.sdk.dto.requests.timemapfast.levelofdetail.LevelOfDetail; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NonNull; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +@Value +@Builder +@Jacksonized +@AllArgsConstructor +public class OneToMany { + @NonNull + String id; + @NonNull + Coordinates coords; + @NonNull + String arrivalTimePeriod; + @NonNull + Integer travelTime; + @NonNull + Transportation transportation; + LevelOfDetail levelOfDetail; +} diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/CoarseGridLevelOfDetail.java b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/CoarseGridLevelOfDetail.java new file mode 100644 index 0000000..db07c2d --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/CoarseGridLevelOfDetail.java @@ -0,0 +1,16 @@ +package com.traveltime.sdk.dto.requests.timemapfast.levelofdetail; + +import jakarta.validation.constraints.Min; +import lombok.AllArgsConstructor; +import lombok.NonNull; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +@Jacksonized +@AllArgsConstructor +@Value +public class CoarseGridLevelOfDetail implements LevelOfDetail { + @NonNull + @Min(value = 600, message = "squareSize should be more than 600") + Integer squareSize; +} diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/Level.java b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/Level.java new file mode 100644 index 0000000..54e94ec --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/Level.java @@ -0,0 +1,16 @@ +package com.traveltime.sdk.dto.requests.timemapfast.levelofdetail; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public enum Level { + @JsonProperty("lowest") + LOWEST, + @JsonProperty("low") + LOW, + @JsonProperty("medium") + MEDIUM, + @JsonProperty("high") + HIGH, + @JsonProperty("highest") + HIGHEST +} diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/LevelOfDetail.java b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/LevelOfDetail.java new file mode 100644 index 0000000..0c4de46 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/LevelOfDetail.java @@ -0,0 +1,16 @@ +package com.traveltime.sdk.dto.requests.timemapfast.levelofdetail; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; + +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + property = "scaleType" +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = SimpleLevelOfDetail.class, name = "simple"), + @JsonSubTypes.Type(value = SimpleNumericLevelOfDetail.class, name = "simple_numeric"), + @JsonSubTypes.Type(value = CoarseGridLevelOfDetail.class, name = "coarse_grid"), +}) +public interface LevelOfDetail { +} diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/SimpleLevelOfDetail.java b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/SimpleLevelOfDetail.java new file mode 100644 index 0000000..493e7fa --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/SimpleLevelOfDetail.java @@ -0,0 +1,14 @@ +package com.traveltime.sdk.dto.requests.timemapfast.levelofdetail; + +import lombok.AllArgsConstructor; +import lombok.NonNull; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +@Jacksonized +@AllArgsConstructor +@Value +public class SimpleLevelOfDetail implements LevelOfDetail { + @NonNull + Level level; +} diff --git a/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/SimpleNumericLevelOfDetail.java b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/SimpleNumericLevelOfDetail.java new file mode 100644 index 0000000..f06da38 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/requests/timemapfast/levelofdetail/SimpleNumericLevelOfDetail.java @@ -0,0 +1,18 @@ +package com.traveltime.sdk.dto.requests.timemapfast.levelofdetail; + +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import lombok.AllArgsConstructor; +import lombok.NonNull; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +@Jacksonized +@AllArgsConstructor +@Value +public class SimpleNumericLevelOfDetail implements LevelOfDetail { + @NonNull + @Min(value = -20, message = "level should be between -20 and 2") + @Max(value = 2, message = "level should be between -20 and 2") + Integer level; +} diff --git a/src/main/java/com/traveltime/sdk/dto/responses/TimeMapFastBoxesResponse.java b/src/main/java/com/traveltime/sdk/dto/responses/TimeMapFastBoxesResponse.java new file mode 100644 index 0000000..026283d --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/responses/TimeMapFastBoxesResponse.java @@ -0,0 +1,19 @@ +package com.traveltime.sdk.dto.responses; + +import com.traveltime.sdk.dto.responses.timemapfast.BoxesResult; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NonNull; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +import java.util.List; + +@Value +@Builder +@Jacksonized +@AllArgsConstructor +public class TimeMapFastBoxesResponse { + @NonNull + List results; +} diff --git a/src/main/java/com/traveltime/sdk/dto/responses/TimeMapFastGeoJsonResponse.java b/src/main/java/com/traveltime/sdk/dto/responses/TimeMapFastGeoJsonResponse.java new file mode 100644 index 0000000..0b84268 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/responses/TimeMapFastGeoJsonResponse.java @@ -0,0 +1,14 @@ +package com.traveltime.sdk.dto.responses; + +import com.traveltime.sdk.dto.geojson.FeatureCollection; +import com.traveltime.sdk.dto.responses.timemapfast.ResponseProperties; +import lombok.EqualsAndHashCode; +import lombok.experimental.SuperBuilder; +import lombok.extern.jackson.Jacksonized; +import org.geojson.MultiPolygon; + +@SuperBuilder +@EqualsAndHashCode(callSuper = true) +@Jacksonized +public class TimeMapFastGeoJsonResponse extends FeatureCollection { +} diff --git a/src/main/java/com/traveltime/sdk/dto/responses/TimeMapFastResponse.java b/src/main/java/com/traveltime/sdk/dto/responses/TimeMapFastResponse.java new file mode 100644 index 0000000..ca1c916 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/responses/TimeMapFastResponse.java @@ -0,0 +1,19 @@ +package com.traveltime.sdk.dto.responses; + +import com.traveltime.sdk.dto.responses.timemapfast.Result; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NonNull; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +import java.util.List; + +@Value +@Builder +@Jacksonized +@AllArgsConstructor +public class TimeMapFastResponse { + @NonNull + List results; +} diff --git a/src/main/java/com/traveltime/sdk/dto/responses/TimeMapFastWktResponse.java b/src/main/java/com/traveltime/sdk/dto/responses/TimeMapFastWktResponse.java new file mode 100644 index 0000000..5a21f81 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/responses/TimeMapFastWktResponse.java @@ -0,0 +1,19 @@ +package com.traveltime.sdk.dto.responses; + +import com.traveltime.sdk.dto.responses.timemapfast.WktResult; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NonNull; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +import java.util.List; + +@Value +@Builder +@Jacksonized +@AllArgsConstructor +public class TimeMapFastWktResponse { + @NonNull + List results; +} diff --git a/src/main/java/com/traveltime/sdk/dto/responses/timemap/Result.java b/src/main/java/com/traveltime/sdk/dto/responses/timemap/Result.java index 2c7bb8d..add9564 100644 --- a/src/main/java/com/traveltime/sdk/dto/responses/timemap/Result.java +++ b/src/main/java/com/traveltime/sdk/dto/responses/timemap/Result.java @@ -1,5 +1,6 @@ package com.traveltime.sdk.dto.responses.timemap; +import com.traveltime.sdk.dto.common.Shape; import lombok.*; import lombok.extern.jackson.Jacksonized; diff --git a/src/main/java/com/traveltime/sdk/dto/responses/timemapfast/BoxesResult.java b/src/main/java/com/traveltime/sdk/dto/responses/timemapfast/BoxesResult.java new file mode 100644 index 0000000..a7ded68 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/responses/timemapfast/BoxesResult.java @@ -0,0 +1,21 @@ +package com.traveltime.sdk.dto.responses.timemapfast; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.traveltime.sdk.dto.responses.timemap.BoundingBox; +import lombok.Builder; +import lombok.NonNull; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +import java.util.List; + +@Value +@Builder +@Jacksonized +@JsonIgnoreProperties(ignoreUnknown = true) +public class BoxesResult { + @NonNull + String searchId; + @NonNull + List boundingBoxes; +} diff --git a/src/main/java/com/traveltime/sdk/dto/responses/timemapfast/ResponseProperties.java b/src/main/java/com/traveltime/sdk/dto/responses/timemapfast/ResponseProperties.java new file mode 100644 index 0000000..deb93c2 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/responses/timemapfast/ResponseProperties.java @@ -0,0 +1,16 @@ +package com.traveltime.sdk.dto.responses.timemapfast; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +@Value +@Builder +@Jacksonized +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ResponseProperties { + +} diff --git a/src/main/java/com/traveltime/sdk/dto/responses/timemapfast/Result.java b/src/main/java/com/traveltime/sdk/dto/responses/timemapfast/Result.java new file mode 100644 index 0000000..de2f8c4 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/responses/timemapfast/Result.java @@ -0,0 +1,20 @@ +package com.traveltime.sdk.dto.responses.timemapfast; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.traveltime.sdk.dto.common.Shape; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; + +import java.util.List; + +@Value +@Builder +@Jacksonized +@AllArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class Result { + String searchId; + List shapes; +} diff --git a/src/main/java/com/traveltime/sdk/dto/responses/timemapfast/WktResult.java b/src/main/java/com/traveltime/sdk/dto/responses/timemapfast/WktResult.java new file mode 100644 index 0000000..8d03ce7 --- /dev/null +++ b/src/main/java/com/traveltime/sdk/dto/responses/timemapfast/WktResult.java @@ -0,0 +1,18 @@ +package com.traveltime.sdk.dto.responses.timemapfast; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Value; +import lombok.extern.jackson.Jacksonized; +import org.locationtech.jts.geom.Geometry; + +@Value +@Builder +@Jacksonized +@AllArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class WktResult { + String searchId; + Geometry shape; +} diff --git a/src/test/java/com/traveltime/sdk/TimeFilterTest.java b/src/test/java/com/traveltime/sdk/TimeFilterTest.java index b91124c..2e77bc3 100644 --- a/src/test/java/com/traveltime/sdk/TimeFilterTest.java +++ b/src/test/java/com/traveltime/sdk/TimeFilterTest.java @@ -6,13 +6,13 @@ import com.traveltime.sdk.dto.common.Location; import com.traveltime.sdk.dto.common.Property; import com.traveltime.sdk.dto.common.transportation.PublicTransport; +import com.traveltime.sdk.dto.common.transportationfast.DrivingAndPublicTransport; import com.traveltime.sdk.dto.requests.TimeFilterFastRequest; import com.traveltime.sdk.dto.requests.TimeFilterRequest; import com.traveltime.sdk.dto.requests.timefilter.*; import com.traveltime.sdk.dto.requests.timefilterfast.ArrivalSearches; import com.traveltime.sdk.dto.requests.timefilterfast.ManyToOne; import com.traveltime.sdk.dto.requests.timefilterfast.OneToMany; -import com.traveltime.sdk.dto.requests.timefilterfast.transportation.DrivingAndPublicTransport; import com.traveltime.sdk.dto.responses.*; import com.traveltime.sdk.dto.responses.errors.TravelTimeError; import io.vavr.control.Either; diff --git a/src/test/java/com/traveltime/sdk/TimeMapFastTest.java b/src/test/java/com/traveltime/sdk/TimeMapFastTest.java new file mode 100644 index 0000000..f912d55 --- /dev/null +++ b/src/test/java/com/traveltime/sdk/TimeMapFastTest.java @@ -0,0 +1,120 @@ +package com.traveltime.sdk; + +import com.traveltime.sdk.auth.TravelTimeCredentials; +import com.traveltime.sdk.dto.common.Coordinates; +import com.traveltime.sdk.dto.common.transportationfast.PublicTransport; +import com.traveltime.sdk.dto.common.transportationfast.Transportation; +import com.traveltime.sdk.dto.requests.TimeMapFastBoxesRequest; +import com.traveltime.sdk.dto.requests.TimeMapFastGeoJsonRequest; +import com.traveltime.sdk.dto.requests.TimeMapFastRequest; +import com.traveltime.sdk.dto.requests.TimeMapFastWktRequest; +import com.traveltime.sdk.dto.requests.timemapfast.ArrivalSearches; +import com.traveltime.sdk.dto.requests.timemapfast.OneToMany; +import com.traveltime.sdk.dto.responses.TimeMapFastBoxesResponse; +import com.traveltime.sdk.dto.responses.TimeMapFastGeoJsonResponse; +import com.traveltime.sdk.dto.responses.TimeMapFastResponse; +import com.traveltime.sdk.dto.responses.TimeMapFastWktResponse; +import com.traveltime.sdk.dto.responses.errors.TravelTimeError; +import com.traveltime.sdk.utils.JsonUtils; +import io.vavr.control.Either; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.Collections; + +public class TimeMapFastTest { + TravelTimeSDK sdk; + + @Before + public void init() { + TravelTimeCredentials credentials = new TravelTimeCredentials( + System.getenv("APP_ID"), + System.getenv("API_KEY") + ); + sdk = new TravelTimeSDK(credentials); + } + + @Test + public void shouldSendTimeMapFastRequest() { + Coordinates coords = new Coordinates(51.507609, -0.128315); + Transportation transportation = new PublicTransport(); + + TimeMapFastRequest request = new TimeMapFastRequest( + createArrivalSearches(coords, transportation) + ); + + Either response = sdk.send(request); + Assert.assertTrue(response.isRight()); + } + + @Test + public void shouldReceiveValidJsonResponse() { + Coordinates coords = new Coordinates(51.507609, -0.128315); + Transportation transportation = new PublicTransport(); + + TimeMapFastRequest request = new TimeMapFastRequest( + createArrivalSearches(coords, transportation) + ); + + Either response = sdk.getJsonResponse(request); + Assert.assertTrue(JsonUtils.isJsonValid(response.get())); + Assert.assertTrue(response.isRight()); + } + + @Test + public void shouldSendTimeMapFastGeoJsonRequest() { + Coordinates coords = new Coordinates(51.507609, -0.128315); + Transportation transportation = new PublicTransport(); + + TimeMapFastGeoJsonRequest request = new TimeMapFastGeoJsonRequest( + createArrivalSearches(coords, transportation) + ); + + Either response = sdk.send(request); + Assert.assertTrue(response.isRight()); + } + + @Test + public void shouldSendTimeMapFastBoundingBoxRequest() { + Coordinates coords = new Coordinates(51.507609, -0.128315); + Transportation transportation = new PublicTransport(); + + TimeMapFastBoxesRequest request = new TimeMapFastBoxesRequest( + createArrivalSearches(coords, transportation) + ); + + Either response = sdk.send(request); + Assert.assertTrue(response.isRight()); + } + + @Test + public void shouldSendTimeMapFastWktRequest() { + Coordinates coords = new Coordinates(51.507609, -0.128315); + Transportation transportation = new PublicTransport(); + + TimeMapFastWktRequest request = new TimeMapFastWktRequest( + createArrivalSearches(coords, transportation), true + ); + + Either response = sdk.send(request); + Assert.assertTrue(response.isRight()); + } + + private ArrivalSearches createArrivalSearches(Coordinates coords, Transportation transportation) { + OneToMany oneToMany = OneToMany + .builder() + .id("Test arrival search fast") + .arrivalTimePeriod("weekday_morning") + .transportation(transportation) + .coords(coords) + .travelTime(900) + .build(); + + return ArrivalSearches + .builder() + .oneToMany(Collections.singletonList(oneToMany)) + .manyToOne(Collections.emptyList()) + .build(); + } +}