Skip to content

Commit

Permalink
Generify OsrmService into RoutingService
Browse files Browse the repository at this point in the history
  • Loading branch information
solita-sabinaf committed Dec 9, 2024
1 parent 1c23716 commit 2464dc9
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import no.entur.uttu.export.netex.producer.NetexIdProducer;
import no.entur.uttu.export.netex.producer.NetexObjectFactory;
import no.entur.uttu.model.Ref;
import no.entur.uttu.osrm.OsrmService;
import no.entur.uttu.osrm.RouteGeometry;
import no.entur.uttu.routing.RouteGeometry;
import no.entur.uttu.routing.RoutingService;
import no.entur.uttu.stopplace.spi.StopPlaceRegistry;
import org.rutebanken.netex.model.LinkSequenceProjection;
import org.rutebanken.netex.model.Projections_RelStructure;
Expand All @@ -26,16 +26,16 @@ public class ServiceLinkProducer {

private final NetexObjectFactory objectFactory;
private final StopPlaceRegistry stopPlaceRegistry;
private final OsrmService osrmService;
private final RoutingService routingService;

public ServiceLinkProducer(
NetexObjectFactory objectFactory,
StopPlaceRegistry stopPlaceRegistry,
OsrmService osrmService
RoutingService routingService
) {
this.objectFactory = objectFactory;
this.stopPlaceRegistry = stopPlaceRegistry;
this.osrmService = osrmService;
this.routingService = routingService;
}

public List<ServiceLink> produce(NetexExportContext context) {
Expand All @@ -47,7 +47,7 @@ public List<ServiceLink> produce(NetexExportContext context) {
String quayRefTo = extractQuayRefTo(serviceLinkRef, context);
Quay quayTo = getQuay(quayRefTo);

RouteGeometry routeGeometry = osrmService.getRouteGeometry(
RouteGeometry routeGeometry = routingService.getRouteGeometry(
quayFrom.getCentroid().getLocation().getLongitude(),
quayFrom.getCentroid().getLocation().getLatitude(),
quayTo.getCentroid().getLocation().getLongitude(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import no.entur.uttu.model.Ref;
import no.entur.uttu.model.StopPointInJourneyPattern;
import no.entur.uttu.model.job.SeverityEnumeration;
import no.entur.uttu.osrm.OsrmService;
import no.entur.uttu.routing.RoutingService;
import no.entur.uttu.stopplace.spi.StopPlaceRegistry;
import org.rutebanken.netex.model.BookingAccessEnumeration;
import org.rutebanken.netex.model.BookingArrangementsStructure;
Expand All @@ -57,18 +57,18 @@ public class JourneyPatternProducer {
private final NetexObjectFactory objectFactory;
private final ContactStructureProducer contactStructureProducer;
private final StopPlaceRegistry stopPlaceRegistry;
private final OsrmService osrmService;
private final RoutingService routingService;

public JourneyPatternProducer(
NetexObjectFactory objectFactory,
ContactStructureProducer contactStructureProducer,
StopPlaceRegistry stopPlaceRegistry,
OsrmService osrmService
RoutingService routingService
) {
this.objectFactory = objectFactory;
this.contactStructureProducer = contactStructureProducer;
this.stopPlaceRegistry = stopPlaceRegistry;
this.osrmService = osrmService;
this.routingService = routingService;
}

public org.rutebanken.netex.model.JourneyPattern produce(
Expand Down Expand Up @@ -99,7 +99,7 @@ public org.rutebanken.netex.model.JourneyPattern produce(
context.notices.addAll(local.getNotices());

List<LinkInLinkSequence_VersionedChildStructure> linksInSequence;
if (osrmService != null && osrmService.isEnabled()) {
if (routingService != null && routingService.isEnabled()) {
linksInSequence =
local
.getPointsInSequence()
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/no/entur/uttu/routing/DefaultRoutingService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package no.entur.uttu.routing;

import java.math.BigDecimal;
import java.util.ArrayList;
import org.springframework.stereotype.Component;

/**
* Fallback implementation in case routing profile not specified
*/
@Component
public class DefaultRoutingService implements RoutingService {

public RouteGeometry getRouteGeometry(
BigDecimal longitudeFrom,
BigDecimal latitudeFrom,
BigDecimal longitudeTo,
BigDecimal latitudeTo
) {
return new RouteGeometry(new ArrayList<>(), BigDecimal.ZERO);
}

public boolean isEnabled() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.entur.uttu.osrm;
package no.entur.uttu.routing;

import java.math.BigDecimal;
import java.util.List;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/no/entur/uttu/routing/RoutingService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package no.entur.uttu.routing;

import java.math.BigDecimal;

/**
* For getting the road geometry - resulting in service links and links in sequence in a journey pattern
*/
public interface RoutingService {
RouteGeometry getRouteGeometry(
BigDecimal longitudeFrom,
BigDecimal latitudeFrom,
BigDecimal longitudeTo,
BigDecimal latitudeTo
);
boolean isEnabled();
}
16 changes: 16 additions & 0 deletions src/main/java/no/entur/uttu/routing/osrm/OsrmConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package no.entur.uttu.routing.osrm;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Profile("routing")
public class OsrmConfiguration {

@Bean
OsrmService osrmService(@Value("${uttu.routing.osrm-api}") String osrmApi) {
return new OsrmService(osrmApi);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package no.entur.uttu.osrm;
package no.entur.uttu.routing.osrm;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
Expand All @@ -15,25 +15,21 @@
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import no.entur.uttu.routing.RouteGeometry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;

@Component
@Profile("routing")
public class OsrmService {
public class OsrmService implements no.entur.uttu.routing.RoutingService {

private static final Logger logger = LoggerFactory.getLogger(OsrmService.class);

@Value("${uttu.routing.osrm-api}")
private String osrmApi;
private final String osrmApi;

private final Methanol httpClient;
private final ObjectMapper objectMapper;

public OsrmService() {
public OsrmService(String osrmApi) {
this.osrmApi = osrmApi;
this.objectMapper = initializeObjectMapper();
this.httpClient = initializeHttpClient();
}
Expand Down

0 comments on commit 2464dc9

Please sign in to comment.