|
|
@@ -1,76 +0,0 @@
|
|
1
|
|
-package se.citerus.dddsample.domain.service;
|
|
2
|
|
-
|
|
3
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
4
|
|
-import se.citerus.dddsample.domain.model.cargo.Itinerary;
|
|
5
|
|
-import se.citerus.dddsample.domain.model.cargo.Leg;
|
|
6
|
|
-import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
|
|
7
|
|
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
|
|
8
|
|
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementRepository;
|
|
9
|
|
-import se.citerus.dddsample.domain.model.location.Location;
|
|
10
|
|
-import se.citerus.dddsample.domain.model.location.LocationRepository;
|
|
11
|
|
-import se.citerus.dddsample.domain.model.location.UnLocode;
|
|
12
|
|
-import se.citerus.routingteam.GraphTraversalService;
|
|
13
|
|
-import se.citerus.routingteam.TransitEdge;
|
|
14
|
|
-import se.citerus.routingteam.TransitPath;
|
|
15
|
|
-
|
|
16
|
|
-import java.util.ArrayList;
|
|
17
|
|
-import java.util.List;
|
|
18
|
|
-
|
|
19
|
|
-/**
|
|
20
|
|
- * Our end of the routing service.
|
|
21
|
|
- *
|
|
22
|
|
- */
|
|
23
|
|
-public class RoutingServiceImpl implements RoutingService {
|
|
24
|
|
-
|
|
25
|
|
- private GraphTraversalService graphTraversalService;
|
|
26
|
|
- private LocationRepository locationRepository;
|
|
27
|
|
- private CarrierMovementRepository carrierMovementRepository;
|
|
28
|
|
-
|
|
29
|
|
- @Transactional(readOnly = true)
|
|
30
|
|
- public List<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpecification) {
|
|
31
|
|
- final Location origin = routeSpecification.origin();
|
|
32
|
|
- final Location destination = routeSpecification.destination();
|
|
33
|
|
-
|
|
34
|
|
- final List<TransitPath> transitPaths = graphTraversalService.performHeavyCalculations(
|
|
35
|
|
- origin.unLocode().idString(),
|
|
36
|
|
- destination.unLocode().idString()
|
|
37
|
|
- );
|
|
38
|
|
-
|
|
39
|
|
- final List<Itinerary> itineraries = new ArrayList<Itinerary>(transitPaths.size());
|
|
40
|
|
-
|
|
41
|
|
- for (TransitPath transitPath : transitPaths) {
|
|
42
|
|
- final Itinerary itinerary = toItinerary(transitPath);
|
|
43
|
|
- itineraries.add(itinerary);
|
|
44
|
|
- }
|
|
45
|
|
-
|
|
46
|
|
- return itineraries;
|
|
47
|
|
- }
|
|
48
|
|
-
|
|
49
|
|
- private Itinerary toItinerary(TransitPath transitPath) {
|
|
50
|
|
- List<Leg> legs = new ArrayList(transitPath.getTransitEdges().size());
|
|
51
|
|
- for (TransitEdge edge : transitPath.getTransitEdges()) {
|
|
52
|
|
- legs.add(toLeg(edge));
|
|
53
|
|
- }
|
|
54
|
|
- return new Itinerary(legs);
|
|
55
|
|
- }
|
|
56
|
|
-
|
|
57
|
|
- private Leg toLeg(TransitEdge edge) {
|
|
58
|
|
- return new Leg(
|
|
59
|
|
- carrierMovementRepository.find(new CarrierMovementId(edge.getCarrierMovementId())),
|
|
60
|
|
- locationRepository.find(new UnLocode(edge.getFromUnLocode())),
|
|
61
|
|
- locationRepository.find(new UnLocode(edge.getToUnLocode()))
|
|
62
|
|
- );
|
|
63
|
|
- }
|
|
64
|
|
-
|
|
65
|
|
- public void setGraphTraversalService(GraphTraversalService graphTraversalService) {
|
|
66
|
|
- this.graphTraversalService = graphTraversalService;
|
|
67
|
|
- }
|
|
68
|
|
-
|
|
69
|
|
- public void setLocationRepository(LocationRepository locationRepository) {
|
|
70
|
|
- this.locationRepository = locationRepository;
|
|
71
|
|
- }
|
|
72
|
|
-
|
|
73
|
|
- public void setCarrierMovementRepository(CarrierMovementRepository carrierMovementRepository) {
|
|
74
|
|
- this.carrierMovementRepository = carrierMovementRepository;
|
|
75
|
|
- }
|
|
76
|
|
-}
|