|
|
@@ -3,7 +3,6 @@ package com.partner.pathfinder.internal;
|
|
3
|
3
|
import com.partner.pathfinder.api.GraphTraversalService;
|
|
4
|
4
|
import com.partner.pathfinder.api.TransitEdge;
|
|
5
|
5
|
import com.partner.pathfinder.api.TransitPath;
|
|
6
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
7
|
6
|
|
|
8
|
7
|
import java.util.*;
|
|
9
|
8
|
|
|
|
@@ -17,8 +16,9 @@ public class GraphTraversalServiceImpl implements GraphTraversalService {
|
|
17
|
16
|
this.random = new Random();
|
|
18
|
17
|
}
|
|
19
|
18
|
|
|
20
|
|
- @Transactional(readOnly = true)
|
|
21
|
|
- public List<TransitPath> findShortestPath(String originUnLocode, String destinationUnLocode) {
|
|
|
19
|
+ public List<TransitPath> findShortestPath(final String originUnLocode,
|
|
|
20
|
+ final String destinationUnLocode,
|
|
|
21
|
+ final Properties limitations) {
|
|
22
|
22
|
List<String> allVertices = dao.listLocations();
|
|
23
|
23
|
allVertices.remove(originUnLocode);
|
|
24
|
24
|
allVertices.remove(destinationUnLocode);
|
|
|
@@ -32,18 +32,18 @@ public class GraphTraversalServiceImpl implements GraphTraversalService {
|
|
32
|
32
|
final String firstLegTo = allVertices.get(0);
|
|
33
|
33
|
|
|
34
|
34
|
transitEdges.add(new TransitEdge(
|
|
35
|
|
- getRandomCarrierMovementId(originUnLocode, firstLegTo),
|
|
|
35
|
+ dao.getVoyageNumber(originUnLocode, firstLegTo),
|
|
36
|
36
|
originUnLocode, firstLegTo));
|
|
37
|
37
|
|
|
38
|
38
|
for (int j = 0; j < allVertices.size() - 1; j++) {
|
|
39
|
39
|
final String curr = allVertices.get(j);
|
|
40
|
40
|
final String next = allVertices.get(j + 1);
|
|
41
|
|
- transitEdges.add(new TransitEdge(getRandomCarrierMovementId(curr, next), curr, next));
|
|
|
41
|
+ transitEdges.add(new TransitEdge(dao.getVoyageNumber(curr, next), curr, next));
|
|
42
|
42
|
}
|
|
43
|
43
|
|
|
44
|
44
|
final String lastLegFrom = allVertices.get(allVertices.size() - 1);
|
|
45
|
45
|
transitEdges.add(new TransitEdge(
|
|
46
|
|
- getRandomCarrierMovementId(lastLegFrom, destinationUnLocode),
|
|
|
46
|
+ dao.getVoyageNumber(lastLegFrom, destinationUnLocode),
|
|
47
|
47
|
lastLegFrom, destinationUnLocode));
|
|
48
|
48
|
|
|
49
|
49
|
candidates.add(new TransitPath(transitEdges));
|
|
|
@@ -52,13 +52,6 @@ public class GraphTraversalServiceImpl implements GraphTraversalService {
|
|
52
|
52
|
return candidates;
|
|
53
|
53
|
}
|
|
54
|
54
|
|
|
55
|
|
- private String getRandomCarrierMovementId(String from, String to) {
|
|
56
|
|
- final String random = UUID.randomUUID().toString().toUpperCase();
|
|
57
|
|
- final String cmId = random.substring(0, 4);
|
|
58
|
|
- dao.storeCarrierMovementId(cmId, from, to);
|
|
59
|
|
- return cmId;
|
|
60
|
|
- }
|
|
61
|
|
-
|
|
62
|
55
|
private int getRandomNumberOfCandidates() {
|
|
63
|
56
|
return 1 + random.nextInt(4);
|
|
64
|
57
|
}
|