-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #507 from solita-sabinaf/TIS-898/fetch_routing_data
Fetcher to for getting a single service link
- Loading branch information
Showing
4 changed files
with
155 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/no/entur/uttu/graphql/fetchers/RoutingFetcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package no.entur.uttu.graphql.fetchers; | ||
|
||
import graphql.schema.DataFetcher; | ||
import graphql.schema.DataFetchingEnvironment; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import no.entur.uttu.graphql.model.ServiceLink; | ||
import no.entur.uttu.routing.RouteGeometry; | ||
import no.entur.uttu.routing.RoutingService; | ||
import no.entur.uttu.stopplace.spi.StopPlaceRegistry; | ||
import org.rutebanken.netex.model.Quay; | ||
import org.rutebanken.netex.model.StopPlace; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service("routingFetcher") | ||
public class RoutingFetcher implements DataFetcher<ServiceLink> { | ||
|
||
private final RoutingService routingService; | ||
private final StopPlaceRegistry stopPlaceRegistry; | ||
|
||
public RoutingFetcher( | ||
RoutingService routingService, | ||
StopPlaceRegistry stopPlaceRegistry | ||
) { | ||
this.routingService = routingService; | ||
this.stopPlaceRegistry = stopPlaceRegistry; | ||
} | ||
|
||
@Override | ||
public ServiceLink get(DataFetchingEnvironment environment) { | ||
String quayRefFrom = environment.getArgument("quayRefFrom"); | ||
String quayRefTo = environment.getArgument("quayRefTo"); | ||
Quay quayFrom = getQuay(quayRefFrom); | ||
Quay quayTo = getQuay(quayRefTo); | ||
|
||
if (quayFrom == null || quayTo == null) { | ||
return new ServiceLink(quayRefFrom + "_" + quayRefTo, null, null, null); | ||
} | ||
|
||
RouteGeometry routeGeometry = routingService.getRouteGeometry( | ||
quayFrom.getCentroid().getLocation().getLongitude(), | ||
quayFrom.getCentroid().getLocation().getLatitude(), | ||
quayTo.getCentroid().getLocation().getLongitude(), | ||
quayTo.getCentroid().getLocation().getLatitude() | ||
); | ||
|
||
return new ServiceLink( | ||
quayRefFrom + "_" + quayRefTo, | ||
quayRefFrom, | ||
quayRefTo, | ||
routeGeometry | ||
); | ||
} | ||
|
||
Quay getQuay(String quayRef) { | ||
if (quayRef == null) { | ||
return null; | ||
} | ||
Optional<StopPlace> stopPlaceOptional = stopPlaceRegistry.getStopPlaceByQuayRef( | ||
quayRef | ||
); | ||
if (stopPlaceOptional.isEmpty()) { | ||
return null; | ||
} | ||
StopPlace stopPlaceFrom = stopPlaceOptional.get(); | ||
List<Quay> stopPlaceFromQuays = stopPlaceFrom | ||
.getQuays() | ||
.getQuayRefOrQuay() | ||
.stream() | ||
.map(jaxbElement -> (org.rutebanken.netex.model.Quay) jaxbElement.getValue()) | ||
.toList(); | ||
return stopPlaceFromQuays | ||
.stream() | ||
.filter(quay -> quay.getId().equals(quayRef)) | ||
.toList() | ||
.get(0); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/no/entur/uttu/graphql/model/ServiceLink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package no.entur.uttu.graphql.model; | ||
|
||
import no.entur.uttu.routing.RouteGeometry; | ||
|
||
public record ServiceLink( | ||
String serviceLinkRef, | ||
String quayRefFrom, | ||
String quayRefTo, | ||
RouteGeometry routeGeometry | ||
) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters