Bladeren bron

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

peter_backlund 18 jaren geleden
bovenliggende
commit
a6bdccc332

+ 8
- 12
dddsample/src/main/java/se/citerus/dddsample/service/BookingService.java Bestand weergeven

13
 public interface BookingService {
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
    * Registers a new cargo in the tracking system, not yet routed.
16
    * Registers a new cargo in the tracking system, not yet routed.
22
    *
17
    *
23
    * @param origin      cargo origin
18
    * @param origin      cargo origin
35
   Cargo loadCargoForRouting(TrackingId trackingId);
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
    * @param trackingId cargo tracking id
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 Bestand weergeven

8
 import se.citerus.dddsample.repository.CargoRepository;
8
 import se.citerus.dddsample.repository.CargoRepository;
9
 import se.citerus.dddsample.repository.LocationRepository;
9
 import se.citerus.dddsample.repository.LocationRepository;
10
 
10
 
11
-import java.util.ArrayList;
11
+import java.util.Date;
12
 import java.util.List;
12
 import java.util.List;
13
 
13
 
14
 public final class BookingServiceImpl implements BookingService {
14
 public final class BookingServiceImpl implements BookingService {
15
 
15
 
16
   private CargoRepository cargoRepository;
16
   private CargoRepository cargoRepository;
17
   private LocationRepository locationRepository;
17
   private LocationRepository locationRepository;
18
+  private RoutingService routingService;
18
 
19
 
19
   private final Log logger = LogFactory.getLog(getClass());
20
   private final Log logger = LogFactory.getLog(getClass());
20
 
21
 
35
   }
36
   }
36
 
37
 
37
   @Transactional(readOnly = true)
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
   public Cargo loadCargoForRouting(final TrackingId trackingId) {
39
   public Cargo loadCargoForRouting(final TrackingId trackingId) {
56
     Validate.notNull(trackingId);
40
     Validate.notNull(trackingId);
57
 
41
 
61
     return cargo;
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
   @Transactional(readOnly = false)
56
   @Transactional(readOnly = false)
65
   public void assignCargoToRoute(final TrackingId trackingId, final Itinerary newItinerary) {
57
   public void assignCargoToRoute(final TrackingId trackingId, final Itinerary newItinerary) {
66
     Validate.notNull(trackingId);
58
     Validate.notNull(trackingId);
71
       throw new IllegalArgumentException("Can't assign itinerary to non-existing cargo " + trackingId);
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
     cargo.attachItinerary(newItinerary);
66
     cargo.attachItinerary(newItinerary);
76
     cargoRepository.save(cargo);
67
     cargoRepository.save(cargo);
77
 
68
 
88
     this.locationRepository = locationRepository;
79
     this.locationRepository = locationRepository;
89
   }
80
   }
90
 
81
 
82
+  public void setRoutingService(RoutingService routingService) {
83
+    this.routingService = routingService;
84
+  }
91
 }
85
 }