Преглед изворни кода

Get registration date from attempt, removed redundant null check.

peter_backlund пре 17 година
родитељ
комит
c13319f3ed

+ 2
- 1
dddsample/src/main/java/se/citerus/dddsample/application/impl/HandlingEventServiceImpl.java Прегледај датотеку

@@ -31,6 +31,7 @@ public final class HandlingEventServiceImpl implements HandlingEventService {
31 31
          it is determined wether the incoming data, the attempt, actually is capable
32 32
          of representing a real handling event. */
33 33
       final HandlingEvent event = handlingEventFactory.createHandlingEvent(
34
+        attempt.getRegistrationTime(),
34 35
         attempt.getCompletionTime(),
35 36
         attempt.getTrackingId(),
36 37
         attempt.getVoyageNumber(),
@@ -44,7 +45,7 @@ public final class HandlingEventServiceImpl implements HandlingEventService {
44 45
        */
45 46
       handlingEventRepository.save(event);
46 47
 
47
-      /* Publish a system event stating that a cargo has been handled. */
48
+      /* Publish an event stating that a cargo has been handled. */
48 49
       applicationEvents.cargoWasHandled(event);
49 50
     } catch (CannotCreateHandlingEventException e) {
50 51
       /* This may be a bogus attempt, for example containing a tracking id

+ 8
- 8
dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactory.java Прегледај датотеку

@@ -22,7 +22,9 @@ public class HandlingEventFactory {
22 22
   private final VoyageRepository voyageRepository;
23 23
   private final LocationRepository locationRepository;
24 24
 
25
-  public HandlingEventFactory(CargoRepository cargoRepository, VoyageRepository voyageRepository, LocationRepository locationRepository) {
25
+  public HandlingEventFactory(final CargoRepository cargoRepository,
26
+                              final VoyageRepository voyageRepository,
27
+                              final LocationRepository locationRepository) {
26 28
     this.cargoRepository = cargoRepository;
27 29
     this.voyageRepository = voyageRepository;
28 30
     this.locationRepository = locationRepository;
@@ -34,26 +36,24 @@ public class HandlingEventFactory {
34 36
    * @param voyageNumber      voyage number
35 37
    * @param unlocode          United Nations Location Code for the location of the event
36 38
    * @param type              type of event
39
+   * @param registrationTime  time when this event was received by the system
37 40
    * @throws UnknownVoyageException
38 41
    *                                    if there's not carrier movement with this id
39 42
    * @throws UnknownCargoException if there's no cargo with this tracking id
40 43
    * @throws UnknownLocationException   if there's no location with this UN Locode
41 44
    * @return A handling event.
42 45
    */
43
-  public HandlingEvent createHandlingEvent(Date completionTime, TrackingId trackingId, VoyageNumber voyageNumber, UnLocode unlocode, HandlingEvent.Type type)
46
+  public HandlingEvent createHandlingEvent(Date registrationTime, Date completionTime, TrackingId trackingId, VoyageNumber voyageNumber, UnLocode unlocode, HandlingEvent.Type type)
44 47
     throws CannotCreateHandlingEventException {
45 48
 
46 49
     // Voyage number may be null for certain event types
47
-    Validate.noNullElements(new Object[]{completionTime, trackingId, unlocode, type});
50
+    Validate.noNullElements(new Object[]
51
+      {registrationTime, completionTime, trackingId, unlocode, type}
52
+    );
48 53
 
49 54
     final Cargo cargo = findCargo(trackingId);
50 55
     final Voyage voyage = findVoyage(voyageNumber);
51 56
     final Location location = findLocation(unlocode);
52
-    
53
-    if (location == null) throw new UnknownLocationException(unlocode);
54
-
55
-    // TODO parameterize
56
-    final Date registrationTime = new Date();
57 57
 
58 58
     if (voyage == null) {
59 59
       return new HandlingEvent(cargo, completionTime, registrationTime, type, location);