implement routing/drections endpoint for requesting routes without alternatives logic, includes refactoring of previous alternative routing logic into carta DirectionsService to reuse code
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good

This commit is contained in:
2026-02-01 18:07:37 +01:00
parent 6aaff14c0d
commit cb397e7e63
16 changed files with 466 additions and 237 deletions
@@ -2,8 +2,8 @@ package SuMoC.backend.routing.controller;
import SuMoC.backend.routing.dtos.RouteDTO;
import SuMoC.backend.routing.dtos.RoutingAlternativeRequestDTO;
import SuMoC.backend.routing.services.AlternativeRoutingService;
import SuMoC.backend.routing.services.RoutingPreferencesService;
import SuMoC.backend.routing.services.RoutingService;
import SuMoC.backend.user.service.CurrentUserService;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
@@ -22,11 +22,11 @@ import java.util.logging.Logger;
@RestController
@RequestMapping("/routing/alternative")
@RequiredArgsConstructor
public class RoutingController {
public class RoutingAlternativeController {
private final Logger logger = Logger.getLogger(RoutingController.class.getName());
private final Logger logger = Logger.getLogger(RoutingAlternativeController.class.getName());
private final RoutingService routingService;
private final AlternativeRoutingService alternativeRoutingService;
private final RoutingPreferencesService routingPreferencesService;
@@ -48,7 +48,7 @@ public class RoutingController {
routingAlternativeRequestDTO.setRoutingPreferencesDTO(routingPreferencesService.getRoutingPreferencesForCurrentUser());
}
var routeDTOs = routingService.determineAlternativeRoutesOnUserRequest(routingAlternativeRequestDTO);
var routeDTOs = alternativeRoutingService.determineAlternativeRoutesOnUserRequest(routingAlternativeRequestDTO);
return ResponseEntity.ok(routeDTOs);
} catch (WebClientRequestException e) {
// nominatim container is not up yet, we return mock
@@ -0,0 +1,54 @@
package SuMoC.backend.routing.controller;
import SuMoC.backend.routing.dtos.RouteDTO;
import SuMoC.backend.routing.dtos.RoutingDirectionsRequestDTO;
import SuMoC.backend.routing.services.DirectionsRoutingService;
import SuMoC.backend.routing.services.RoutingPreferencesService;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/routing/directions")
@RequiredArgsConstructor
class RoutingDirectionsController {
private final DirectionsRoutingService directionsRoutingService;
private final RoutingPreferencesService routingPreferencesService;
@PostMapping("/request")
@Schema(description = "Endpoint to request routes from point A to B, also see RoutingDirectionsRequestDTO.")
public ResponseEntity<List<RouteDTO>> requestDirections(@Valid @RequestBody RoutingDirectionsRequestDTO directionsRequestDTO) {
validateRequestDTO(directionsRequestDTO);
// if routing preferences are not provided, get stored preferences or default
if (directionsRequestDTO.getRoutingPreferencesDTO() == null) {
directionsRequestDTO.setRoutingPreferencesDTO(routingPreferencesService.getRoutingPreferencesForCurrentUser());
}
return ResponseEntity.ok(directionsRoutingService.getDirections(directionsRequestDTO));
}
private void validateRequestDTO(RoutingDirectionsRequestDTO requestDTO) {
if (requestDTO.getArrivalTime() == null && requestDTO.getDepartureTime() == null) {
throw new IllegalArgumentException("Either arrivalTime or departureTime must be provided.");
}
if (requestDTO.getArrivalTime() != null && requestDTO.getDepartureTime() != null) {
throw new IllegalArgumentException("Only one of arrivalTime or departureTime should be provided.");
}
if (requestDTO.getOriginAddress() == null && (requestDTO.getOriginLat() == 0.0 || requestDTO.getOriginLon() == 0.0)) {
throw new IllegalArgumentException("Origin must be specified either by address or coordinates.");
}
if (requestDTO.getDestinationAddress() == null && (requestDTO.getDestinationLat() == 0.0 || requestDTO.getDestinationLon() == 0.0)) {
throw new IllegalArgumentException("Destination must be specified either by address or coordinates.");
}
}
}
@@ -46,7 +46,7 @@ public class RouteDTO {
private double co2Savings;
@Schema(description = "CO2e emission of this route.")
private double co2Emissions;
@Schema(description = "The temporal difference in minutes compared to the original route the user requested alternatives for.")
@Schema(description = "The temporal difference in minutes compared to the original route (in case alternative was requested) / the car route (when simply directions requested) .")
private double timeDifferenceSeconds;
public RouteDTO(AddressDTO startAddress, @Nullable String firstStopName, double startLat, double startLon, AddressDTO endAddress, @Nullable String lastStopName, double endLat, double endLon, Instant startDateTime, Instant endDateTime, List<StepDTO> steps, double co2Savings, double timeDifferenceSeconds, double co2Emissions) {
@@ -114,17 +114,18 @@ public class RouteDTO {
);
dto.steps.add(new StepDTO(
Modality.WALKING,
null,
400f
));
dto.steps.add(new StepDTO(
dto.steps.add(new TransitStepDTO(
Modality.TRAM,
5000f,
"106",
5000f
"Ich bin eine Testlinie",
"Ich bin ein Teststartbahnhof",
"Ich bin ein Testendbahnhof"
));
dto.steps.add(new StepDTO(
Modality.WALKING,
null,
300f
));
return dto;
@@ -1,5 +1,6 @@
package SuMoC.backend.routing.dtos;
import SuMoC.backend.carta.DirectionsRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.NotNull;
@@ -13,7 +14,7 @@ import java.time.Instant;
@AllArgsConstructor
@NoArgsConstructor
@Schema(description = "This DTO represents a request for alternative routes between an origin and a destination.")
public class RoutingAlternativeRequestDTO {
public class RoutingAlternativeRequestDTO implements DirectionsRequest {
@NotNull
private Double originLat;
@NotNull
@@ -0,0 +1,27 @@
package SuMoC.backend.routing.dtos;
import SuMoC.backend.carta.DirectionsRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Nullable;
import lombok.Getter;
import lombok.Setter;
import java.time.Instant;
@Getter
@Setter
@Schema(description = "DTO representing a request for routing directions between two points. Points can be specified either by coordinates or addresses." +
"If both provided, coordinates are preferred.")
public class RoutingDirectionsRequestDTO implements DirectionsRequest {
private Double originLat;
private Double originLon;
private Double destinationLat;
private Double destinationLon;
private String originAddress;
private String destinationAddress;
private Instant arrivalTime;
private Instant departureTime;
@Nullable
@Schema(description = "Routing preferences to customize the routing behavior. If null, will search for stored user preferences, if not found, use default.")
private RoutingPreferencesDTO routingPreferencesDTO;
}
@@ -12,7 +12,9 @@ import java.util.List;
@Setter
@Schema(description = "This DTO represents the user preferences for routing / alternative route suggestions.")
public class RoutingPreferencesDTO {
@Schema(description = "Whether to prefer alternative routes that involve physical activity (walking, cycling) when suggestin alternative routes.")
private boolean preferPhysicalActivity = false;
@Schema(description = "Whether to consider current weather conditions when suggesting alternative routes.")
private boolean considerWeatherConditions = true;
private List<Modality> modalitiesToConsider = new ArrayList<>(
List.of(Modality.WALKING, Modality.BICYCLE, Modality.ESCOOTER, Modality.BUS, Modality.TRAM, Modality.TRAIN)
@@ -14,6 +14,5 @@ import lombok.Setter;
@Schema(description = "A single step within a suggested alternative route.")
public class StepDTO {
private Modality modality;
private String lineNumber;
private double distanceMeters;
}
@@ -0,0 +1,24 @@
package SuMoC.backend.routing.dtos;
import SuMoC.backend.trip.Modality;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Schema(description = "A single transit step within a suggested alternative route.")
public class TransitStepDTO extends StepDTO {
private String lineNumber;
private String lineHeadsign;
private String startStop;
private String endStop;
public TransitStepDTO(Modality modality, double distanceMeters, String lineNumber, String lineHeadsign, String startStop, String endStop) {
super(modality, distanceMeters);
this.lineNumber = lineNumber;
this.lineHeadsign = lineHeadsign;
this.startStop = startStop;
this.endStop = endStop;
}
}
@@ -0,0 +1,89 @@
package SuMoC.backend.routing.services;
import SuMoC.backend.carta.DirectionsService;
import SuMoC.backend.routing.config.AdHocRoutingProperties;
import SuMoC.backend.routing.config.OnCallRoutingProperties;
import SuMoC.backend.routing.dtos.RouteDTO;
import SuMoC.backend.routing.dtos.RoutingAlternativeRequestDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Service to determine alternative routes for a given routing request.
*/
@Service
@RequiredArgsConstructor
public class AlternativeRoutingService {
private final AlternativeFilterService alternativeFilterService;
private final OnCallRoutingProperties onCallRoutingProperties;
private final AdHocRoutingProperties adHocRoutingProperties;
private final DirectionsService directionsService;
/**
* Gets possible routes from CARTA, converts them to our format and applies filter to only provide acceptable solutions without excessive additional travel time.
* This is the public method for alternatives explicitly asked for by the client.
*/
public List<RouteDTO> determineAlternativeRoutesOnUserRequest(RoutingAlternativeRequestDTO requestDTO) {
List<RouteDTO> routes = directionsService.getPossibleAlternativeRoutes(requestDTO);
routes = alternativeFilterService.filterForAdditionalTravelTime(requestDTO, routes, onCallRoutingProperties);
return routes;
}
/**
* Public alternative retrieval method which is used to check for alternatives we suggest to user via notification
* right after user finished the trip.
* Similar to determineAlternativeRoutesOnUserRequest but here we apply stricter thresholds for alternatives
* and also apply weather filtering (if enabled) to not suggest routes the user definitly would not have consideres.
*/
public List<RouteDTO> determineAlternativeRoutesAdHoc(RoutingAlternativeRequestDTO requestDTO) {
assert requestDTO.getRoutingPreferencesDTO() != null;
List<RouteDTO> routes = directionsService.getPossibleAlternativeRoutes(requestDTO);
routes = alternativeFilterService.filterForAdditionalTravelTime(requestDTO, routes, adHocRoutingProperties);
if (requestDTO.getRoutingPreferencesDTO().isConsiderWeatherConditions()) {
routes = alternativeFilterService.filterForBadWeather(requestDTO, routes, adHocRoutingProperties);
}
return routes;
}
public RouteDTO determineBestAlternativeRouteForRegularTrip(RoutingAlternativeRequestDTO requestDTO) {
assert requestDTO.getRoutingPreferencesDTO() != null;
// TODO for now we use adHocRoutingProperties here, in the future we might want to have separate properties for regular trip alternatives
List<RouteDTO> routes = directionsService.getPossibleAlternativeRoutes(requestDTO);
routes = alternativeFilterService.filterForAdditionalTravelTime(requestDTO, routes, adHocRoutingProperties);
if (requestDTO.getRoutingPreferencesDTO().isConsiderWeatherConditions()) {
routes = alternativeFilterService.filterForBadWeather(requestDTO, routes, adHocRoutingProperties);
}
RouteDTO bestRoute = null;
// if users wants physical activity, we pick the fastest physical activity route, if any
if (requestDTO.getRoutingPreferencesDTO().isPreferPhysicalActivity()) {
bestRoute = routes.stream()
.filter(RouteDTO::isPhysicalActivity)
.min((r1, r2) -> Long.compare(
r1.getDurationSeconds(),
r2.getDurationSeconds()
)).orElse(null);
if (bestRoute != null) {
return bestRoute;
}
}
// else we pick the fastest route overall
bestRoute = routes.stream()
.min((r1, r2) -> Long.compare(
r1.getDurationSeconds(),
r2.getDurationSeconds()
)).orElse(null);
return bestRoute;
}
}
@@ -1,6 +1,7 @@
package SuMoC.backend.routing.services;
import SuMoC.backend.routing.dtos.StepDTO;
import SuMoC.backend.routing.dtos.TransitStepDTO;
import SuMoC.backend.trip.Modality;
import sumoc.backend.carta.client.model.Route;
import sumoc.backend.carta.client.model.Step;
@@ -28,7 +29,7 @@ public class CartaTransitRouteProcessor {
/**
* Extracts information from the route.
*/
public void process() {
private void process() {
ArrayList<StepDTO> steps = new ArrayList<>();
assert cartaRoute.getSteps() != null;
@@ -46,11 +47,21 @@ public class CartaTransitRouteProcessor {
? Modality.fromCartaString(step.getLine().getType().toString())
: Modality.fromCartaString(step.getType());
steps.add(new StepDTO(
stepModality,
step.getType().equals("TransitStep") ? step.getLine().getCode() : null,
step.getDistance()
));
if (step.getType().equals("TransitStep")) {
steps.add(new TransitStepDTO(
stepModality,
step.getDistance(),
step.getLine().getCode(),
step.getLine().getHeadsign(),
step.getStops().getFirst().getName(),
step.getStops().getLast().getName()
));
} else {
steps.add(new StepDTO(
stepModality,
step.getDistance()
));
}
}
this.steps = steps;
@@ -0,0 +1,23 @@
package SuMoC.backend.routing.services;
import SuMoC.backend.carta.DirectionsService;
import SuMoC.backend.routing.dtos.RouteDTO;
import SuMoC.backend.routing.dtos.RoutingDirectionsRequestDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Service for getting directions between two given points.
*/
@Service
@RequiredArgsConstructor
public class DirectionsRoutingService {
private final DirectionsService directionsService;
public List<RouteDTO> getDirections(RoutingDirectionsRequestDTO requestDTO) {
return directionsService.getPossibleRoutes(requestDTO, true);
}
}
@@ -1,300 +0,0 @@
package SuMoC.backend.routing.services;
import SuMoC.backend.carta.CartaClient;
import SuMoC.backend.geocoding.AddressDTO;
import SuMoC.backend.geocoding.GeoCodingService;
import SuMoC.backend.routing.config.AdHocRoutingProperties;
import SuMoC.backend.routing.config.OnCallRoutingProperties;
import SuMoC.backend.routing.dtos.RouteDTO;
import SuMoC.backend.routing.dtos.RoutingAlternativeRequestDTO;
import SuMoC.backend.routing.dtos.StepDTO;
import SuMoC.backend.routing.exceptions.NoCarRouteFoundException;
import SuMoC.backend.routing.exceptions.NoCarbonEmissionFoundException;
import SuMoC.backend.trip.Modality;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
import sumoc.backend.carta.client.model.Direction;
import sumoc.backend.carta.client.model.Route;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
@Service
@RequiredArgsConstructor
public class RoutingService {
private final GeoCodingService geoCodingService;
private final CartaClient cartaClient;
private final AlternativeFilterService alternativeFilterService;
private final OnCallRoutingProperties onCallRoutingProperties;
private final AdHocRoutingProperties adHocRoutingProperties;
/**
* Makes an individual call to the CARTA API and returns a direction future.
*/
private CompletableFuture<Direction> getCartaFuture(
RoutingAlternativeRequestDTO requestDTO,
String mode,
String types,
int alternatives
) {
return cartaClient.asyncGetRoute(
requestDTO.getOriginLat() + "," + requestDTO.getOriginLon(),
requestDTO.getDestinationLat() + "," + requestDTO.getDestinationLon(),
mode,
requestDTO.getArrivalTime(),
null,
alternatives, // alternatives
null, // walkingSpeed
null, // transferTime TODO what is default? adapt?
types,
null, // range
requestDTO.getOriginLat() + "," + requestDTO.getOriginLon()
);
}
/**
* Makes concurrent direction calls to CARTA for all modes requested + car as baseline.
* Possible keys of the returned Map:
* - car (always)
* - walk (optional)
* - bike (optional)
* - transit (optional)
*/
private HashMap<String, Direction> getPossibleDirectionsFromCarta(RoutingAlternativeRequestDTO requestDTO) {
Map<String, CompletableFuture<Direction>> futuresByMode = new HashMap<>();
assert requestDTO.getRoutingPreferencesDTO() != null;
// serves as baseline
futuresByMode.put("car", getCartaFuture(requestDTO, "driving", "", 1));
// type string for carta api
List<String> typeList = new ArrayList<>();
// add request futures for all modes request by user + assemble type string for a possible transit directions request
for (Modality modality : requestDTO.getRoutingPreferencesDTO().getModalitiesToConsider()) {
switch (modality) {
case WALKING -> futuresByMode.put("walk", getCartaFuture(requestDTO, "walking", "", 1));
case BICYCLE -> futuresByMode.put("bike", getCartaFuture(requestDTO, "cycling", "", 1));
case BUS -> {
typeList.add("3"); // bus
typeList.add("8"); // trolleybus
}
// case ESCOOTER -> typeList.add("X"); TODO - check if this and bike should be included in transit or separate
case TRAM -> typeList.add("0");
case TRAIN -> {
typeList.add("1"); // subway
typeList.add("2"); // rail
typeList.add("9"); // monorail
}
}
}
if (!typeList.isEmpty()) { // if any public transit the app allows toggling is selcted we add the funny transit types and make the transit request
typeList.add("4"); // Ferry
typeList.add("5"); // cablecar
typeList.add("6"); // gondola
typeList.add("7"); // funicular
String types = String.join(",", typeList);
futuresByMode.put("transit", getCartaFuture(requestDTO, "transit", types, 3));
}
// return all future results as list when resvoled
HashMap<String, Direction> directions = new HashMap<>();
for (Map.Entry<String, CompletableFuture<Direction>> entry : futuresByMode.entrySet()) {
directions.put(entry.getKey(), entry.getValue().join());
}
return directions;
}
/**
* Gets possible routes from CARTA, converts them to our format and applies filter to only provide acceptable solutions without excessive additional travel time.
* This is the public method for alternatives explicitly asked for by the client.
*/
public List<RouteDTO> determineAlternativeRoutesOnUserRequest(RoutingAlternativeRequestDTO requestDTO) {
List<RouteDTO> routes = getPossibleAlternativeRoutes(requestDTO);
routes = alternativeFilterService.filterForAdditionalTravelTime(requestDTO, routes, onCallRoutingProperties);
return routes;
}
/**
* Public alternative retrieval method which is used to check for alternatives we suggest to user via notification
* right after user finished the trip.
* Similar to determineAlternativeRoutesOnUserRequest but here we apply stricter thresholds for alternatives
* and also apply weather filtering (if enabled) to not suggest routes the user definitly would not have consideres.
*/
public List<RouteDTO> determineAlternativeRoutesAdHoc(RoutingAlternativeRequestDTO requestDTO) {
assert requestDTO.getRoutingPreferencesDTO() != null;
List<RouteDTO> routes = getPossibleAlternativeRoutes(requestDTO);
routes = alternativeFilterService.filterForAdditionalTravelTime(requestDTO, routes, adHocRoutingProperties);
if (requestDTO.getRoutingPreferencesDTO().isConsiderWeatherConditions()) {
routes = alternativeFilterService.filterForBadWeather(requestDTO, routes, adHocRoutingProperties);
}
return routes;
}
public RouteDTO determineBestAlternativeRouteForRegularTrip(RoutingAlternativeRequestDTO requestDTO) {
assert requestDTO.getRoutingPreferencesDTO() != null;
// TODO for now we use adHocRoutingProperties here, in the future we might want to have separate properties for regular trip alternatives
List<RouteDTO> routes = getPossibleAlternativeRoutes(requestDTO);
routes = alternativeFilterService.filterForAdditionalTravelTime(requestDTO, routes, adHocRoutingProperties);
if (requestDTO.getRoutingPreferencesDTO().isConsiderWeatherConditions()) {
routes = alternativeFilterService.filterForBadWeather(requestDTO, routes, adHocRoutingProperties);
}
RouteDTO bestRoute = null;
// if users wants physical activity, we pick the fastest physical activity route, if any
if (requestDTO.getRoutingPreferencesDTO().isPreferPhysicalActivity()) {
bestRoute = routes.stream()
.filter(RouteDTO::isPhysicalActivity)
.min((r1, r2) -> Long.compare(
r1.getDurationSeconds(),
r2.getDurationSeconds()
)).orElse(null);
if (bestRoute != null) {
return bestRoute;
}
}
// else we pick the fastest route overall
bestRoute = routes.stream()
.min((r1, r2) -> Long.compare(
r1.getDurationSeconds(),
r2.getDurationSeconds()
)).orElse(null);
return bestRoute;
}
/**
* Returns possible alternative routes for the request - no sanity filtering regarding travel times etc. is applied.
*/
private List<RouteDTO> getPossibleAlternativeRoutes(RoutingAlternativeRequestDTO requestDTO) {
assert requestDTO.getRoutingPreferencesDTO() != null;
HashMap<String, Direction> directionMap = getPossibleDirectionsFromCarta(requestDTO);
ArrayList<RouteDTO> suggestedAlternatives = new ArrayList<>();
// Fetch origin and destination addresses concurrently
var addressesMono = Mono.zip(
geoCodingService.getAddress(requestDTO.getOriginLat(), requestDTO.getOriginLon()),
geoCodingService.getAddress(requestDTO.getDestinationLat(), requestDTO.getDestinationLon())
);
var addressesTuple = addressesMono.block();
AddressDTO originAddress = addressesTuple.getT1();
AddressDTO destinationAddress = addressesTuple.getT2();
// Setting up car data for baseline
Route carRoute;
try {
carRoute = directionMap.get("car").getRoutes().getFirst();
} catch (NullPointerException e) {
throw new NoCarRouteFoundException("No car route to compare to was found.");
}
double carCarbondDioxide;
try {
carCarbondDioxide = carRoute.getEmission().getCarbonDioxide();
} catch (NullPointerException e) {
throw new NoCarbonEmissionFoundException("No carbon emission was provided for the car route.");
}
if (directionMap.containsKey("bike")) {
Direction bikeDirection = directionMap.get("bike");
if (bikeDirection.getRoutes() != null && !bikeDirection.getRoutes().isEmpty()) {
Route bikeRoute = bikeDirection.getRoutes().getFirst();
ArrayList<StepDTO> steps = new ArrayList<>();
steps.add(new StepDTO(
Modality.BICYCLE,
null,
bikeRoute.getDistance()
)
);
RouteDTO routeDTO = new RouteDTO(
originAddress,
null,
bikeRoute.getSourceCoordinate().getLatitude(),
bikeRoute.getSourceCoordinate().getLongitude(),
destinationAddress,
null,
bikeRoute.getTargetCoordinate().getLatitude(),
bikeRoute.getTargetCoordinate().getLongitude(),
requestDTO.getArrivalTime().minusSeconds(bikeRoute.getDuration()),
requestDTO.getArrivalTime(),
steps,
carCarbondDioxide,
bikeRoute.getDuration() - carRoute.getDuration(),
0.0
);
suggestedAlternatives.add(routeDTO);
}
}
if (directionMap.containsKey("walk")) {
Direction walkDirection = directionMap.get("walk");
if (walkDirection.getRoutes() != null && !walkDirection.getRoutes().isEmpty()) {
Route walkRoute = walkDirection.getRoutes().getFirst();
ArrayList<StepDTO> steps = new ArrayList<>();
steps.add(new StepDTO(
Modality.WALKING,
null,
walkRoute.getDistance()
));
RouteDTO routeDTO = new RouteDTO(
originAddress,
null,
walkRoute.getSourceCoordinate().getLatitude(),
walkRoute.getSourceCoordinate().getLongitude(),
destinationAddress,
null,
walkRoute.getTargetCoordinate().getLatitude(),
walkRoute.getTargetCoordinate().getLongitude(),
requestDTO.getArrivalTime().minusSeconds(walkRoute.getDuration()),
requestDTO.getArrivalTime(),
steps,
carCarbondDioxide,
walkRoute.getDuration() - carRoute.getDuration(),
0.0
);
suggestedAlternatives.add(routeDTO);
}
}
if (directionMap.containsKey("transit")) {
Direction transitDirection = directionMap.get("transit");
if (transitDirection.getRoutes() != null && !transitDirection.getRoutes().isEmpty()) {
for (Route route : transitDirection.getRoutes()) {
CartaTransitRouteProcessor routeProcessor = new CartaTransitRouteProcessor(route);
RouteDTO routeDTO = new RouteDTO(
originAddress,
routeProcessor.getFirstStopName(),
route.getSourceCoordinate().getLatitude(),
route.getSourceCoordinate().getLongitude(),
destinationAddress,
routeProcessor.getLastStopName(),
route.getTargetCoordinate().getLatitude(),
route.getTargetCoordinate().getLongitude(),
requestDTO.getArrivalTime().minusSeconds(route.getDuration()),
requestDTO.getArrivalTime(),
routeProcessor.getSteps(),
carCarbondDioxide - route.getEmission().getCarbonDioxide(),
route.getDuration() - carRoute.getDuration(),
route.getEmission().getCarbonDioxide()
);
suggestedAlternatives.add(routeDTO);
}
}
}
return suggestedAlternatives;
}
}