소스 검색

Removed repository-delegating list cargos/shipping locations methods from domain service.

peter_backlund 18 년 전
부모
커밋
a6bdccc332

+ 8
- 12
dddsample/src/main/java/se/citerus/dddsample/service/BookingService.java 파일 보기

@@ -13,11 +13,6 @@ import java.util.List;
13 13
 public interface BookingService {
14 14
 
15 15
   /**
16
-   * @return A list of all locations where the company ships cargo to.
17
-   */
18
-  List<UnLocode> listShippingLocations();
19
-
20
-  /**
21 16
    * Registers a new cargo in the tracking system, not yet routed.
22 17
    *
23 18
    * @param origin      cargo origin
@@ -35,18 +30,19 @@ public interface BookingService {
35 30
   Cargo loadCargoForRouting(TrackingId trackingId);
36 31
 
37 32
   /**
38
-   * Assigns a cargo to route.
39
-   *
33
+   * Requests a list of itineraries describing possible routes for this cargo.
34
+   * 
40 35
    * @param trackingId cargo tracking id
41
-   * @param itinerary  the new itinerary describing the route
36
+   * @return A list of possible itineraries for this cargo 
42 37
    */
43
-  void assignCargoToRoute(TrackingId trackingId, Itinerary itinerary);
38
+  List<Itinerary> requestPossibleRoutesForCargo(TrackingId trackingId);
44 39
 
45 40
   /**
46
-   * Lists all cargos.
41
+   * Assigns a cargo to route.
47 42
    *
48
-   * @return All cargos.
43
+   * @param trackingId cargo tracking id
44
+   * @param itinerary  the new itinerary describing the route
49 45
    */
50
-  List<Cargo> listAllCargos();
46
+  void assignCargoToRoute(TrackingId trackingId, Itinerary itinerary);
51 47
 
52 48
 }

+ 13
- 19
dddsample/src/main/java/se/citerus/dddsample/service/BookingServiceImpl.java 파일 보기

@@ -8,13 +8,14 @@ import se.citerus.dddsample.domain.*;
8 8
 import se.citerus.dddsample.repository.CargoRepository;
9 9
 import se.citerus.dddsample.repository.LocationRepository;
10 10
 
11
-import java.util.ArrayList;
11
+import java.util.Date;
12 12
 import java.util.List;
13 13
 
14 14
 public final class BookingServiceImpl implements BookingService {
15 15
 
16 16
   private CargoRepository cargoRepository;
17 17
   private LocationRepository locationRepository;
18
+  private RoutingService routingService;
18 19
 
19 20
   private final Log logger = LogFactory.getLog(getClass());
20 21
 
@@ -35,23 +36,6 @@ public final class BookingServiceImpl implements BookingService {
35 36
   }
36 37
 
37 38
   @Transactional(readOnly = true)
38
-  public List<UnLocode> listShippingLocations() {
39
-    final List<Location> allLocations = locationRepository.findAll();
40
-    final List<UnLocode> unlocodes = new ArrayList<UnLocode>(allLocations.size());
41
-    for (Location location : allLocations) {
42
-      unlocodes.add(location.unLocode());
43
-    }
44
-    return unlocodes;
45
-  }
46
-
47
-  @Transactional(readOnly = true)
48
-  public List<Cargo> listAllCargos() {
49
-    final List<Cargo> allCargos = cargoRepository.findAll();
50
-    // TODO: specification pattern might be useful here, too
51
-    return allCargos;
52
-  }
53
-
54
-  @Transactional(readOnly = true)
55 39
   public Cargo loadCargoForRouting(final TrackingId trackingId) {
56 40
     Validate.notNull(trackingId);
57 41
 
@@ -61,6 +45,14 @@ public final class BookingServiceImpl implements BookingService {
61 45
     return cargo;
62 46
   }
63 47
 
48
+  @Transactional(readOnly = true)
49
+  public List<Itinerary> requestPossibleRoutesForCargo(TrackingId trackingId) {
50
+    final Cargo cargo = loadCargoForRouting(trackingId);
51
+    final RouteSpecification routeSpecification = RouteSpecification.forCargo(cargo, new Date());
52
+
53
+    return routingService.fetchRoutesForSpecification(routeSpecification);
54
+  }
55
+
64 56
   @Transactional(readOnly = false)
65 57
   public void assignCargoToRoute(final TrackingId trackingId, final Itinerary newItinerary) {
66 58
     Validate.notNull(trackingId);
@@ -71,7 +63,6 @@ public final class BookingServiceImpl implements BookingService {
71 63
       throw new IllegalArgumentException("Can't assign itinerary to non-existing cargo " + trackingId);
72 64
     }
73 65
 
74
-    // Assign the new itinerary to the cargo
75 66
     cargo.attachItinerary(newItinerary);
76 67
     cargoRepository.save(cargo);
77 68
 
@@ -88,4 +79,7 @@ public final class BookingServiceImpl implements BookingService {
88 79
     this.locationRepository = locationRepository;
89 80
   }
90 81
 
82
+  public void setRoutingService(RoutingService routingService) {
83
+    this.routingService = routingService;
84
+  }
91 85
 }