Pārlūkot izejas kodu

Slight method name and documentation improvements

peter_backlund 17 gadus atpakaļ
vecāks
revīzija
3c6e89e51f

+ 8
- 8
dddsample/src/main/java/se/citerus/dddsample/application/HandlingEventRegistrationAttempt.java Parādīt failu

@@ -15,8 +15,8 @@ import java.util.Date;
15 15
  */
16 16
 public final class HandlingEventRegistrationAttempt implements Serializable {
17 17
 
18
-  private final Date registrationDate;
19
-  private final Date date;
18
+  private final Date registrationTime;
19
+  private final Date completionTime;
20 20
   private final TrackingId trackingId;
21 21
   private final VoyageNumber voyageNumber;
22 22
   private final HandlingEvent.Type type;
@@ -28,16 +28,16 @@ public final class HandlingEventRegistrationAttempt implements Serializable {
28 28
                                           final VoyageNumber voyageNumber,
29 29
                                           final HandlingEvent.Type type,
30 30
                                           final UnLocode unLocode) {
31
-    this.registrationDate = registrationDate;
32
-    this.date = completionDate;
31
+    this.registrationTime = registrationDate;
32
+    this.completionTime = completionDate;
33 33
     this.trackingId = trackingId;
34 34
     this.voyageNumber = voyageNumber;
35 35
     this.type = type;
36 36
     this.unLocode = unLocode;
37 37
   }
38 38
 
39
-  public Date getDate() {
40
-    return new Date(date.getTime());
39
+  public Date getCompletionTime() {
40
+    return new Date(completionTime.getTime());
41 41
   }
42 42
 
43 43
   public TrackingId getTrackingId() {
@@ -56,7 +56,7 @@ public final class HandlingEventRegistrationAttempt implements Serializable {
56 56
     return unLocode;
57 57
   }
58 58
 
59
-  public Date getRegistrationDate() {
60
-    return new Date(registrationDate.getTime());
59
+  public Date getRegistrationTime() {
60
+    return new Date(registrationTime.getTime());
61 61
   }
62 62
 }

+ 2
- 2
dddsample/src/main/java/se/citerus/dddsample/application/HandlingEventService.java Parādīt failu

@@ -7,10 +7,10 @@ public interface HandlingEventService {
7 7
 
8 8
   /**
9 9
    * Registers a handling event in the system, and notifies interested
10
-   * parties that an event has been registered.
10
+   * parties that a cargo has been handled.
11 11
    *
12 12
    * @param attempt handling event registration attempt
13 13
    */
14
-  void register(HandlingEventRegistrationAttempt attempt);
14
+  void registerHandlingEvent(HandlingEventRegistrationAttempt attempt);
15 15
 
16 16
 }

+ 22
- 19
dddsample/src/main/java/se/citerus/dddsample/application/impl/HandlingEventServiceImpl.java Parādīt failu

@@ -1,9 +1,9 @@
1 1
 package se.citerus.dddsample.application.impl;
2 2
 
3 3
 import org.springframework.transaction.annotation.Transactional;
4
+import se.citerus.dddsample.application.ApplicationEvents;
4 5
 import se.citerus.dddsample.application.HandlingEventRegistrationAttempt;
5 6
 import se.citerus.dddsample.application.HandlingEventService;
6
-import se.citerus.dddsample.application.SystemEvents;
7 7
 import se.citerus.dddsample.domain.model.handling.CannotCreateHandlingEventException;
8 8
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
9 9
 import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
@@ -11,42 +11,45 @@ import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
11 11
 
12 12
 public final class HandlingEventServiceImpl implements HandlingEventService {
13 13
 
14
+  private final ApplicationEvents applicationEvents;
14 15
   private final HandlingEventRepository handlingEventRepository;
15
-  private final SystemEvents systemEvents;
16 16
   private final HandlingEventFactory handlingEventFactory;
17 17
 
18
-  public HandlingEventServiceImpl(HandlingEventRepository handlingEventRepository, SystemEvents systemEvents, HandlingEventFactory handlingEventFactory) {
18
+  public HandlingEventServiceImpl(final HandlingEventRepository handlingEventRepository,
19
+                                  final ApplicationEvents applicationEvents,
20
+                                  final HandlingEventFactory handlingEventFactory) {
19 21
     this.handlingEventRepository = handlingEventRepository;
20
-    this.systemEvents = systemEvents;
22
+    this.applicationEvents = applicationEvents;
21 23
     this.handlingEventFactory = handlingEventFactory;
22 24
   }
23 25
 
24
-  /*
25
-   NOTE:
26
-     The cargo instance that's loaded and associated with the handling event is
27
-     in an inconsitent state, because the cargo delivery history's collection of
28
-     events does not contain the event created here. However, this is not a problem,
29
-     because cargo is in a different aggregate from handling event.
30
-
31
-     The rules of an aggregate dictate that all consistency rules within the aggregate
32
-     are enforced synchronously in the transaction, but consistency rules of other aggregates
33
-     are enforced by asynchronous updates, after the commit of this transaction.
34
-  */
35 26
   @Override
36 27
   @Transactional
37
-  public void register(HandlingEventRegistrationAttempt attempt) {
28
+  public void registerHandlingEvent(final HandlingEventRegistrationAttempt attempt) {
38 29
     try {
30
+      /* Using a factory to create a HandlingEvent (aggregate). This is where
31
+         it is determined wether the incoming data, the attempt, actually is capable
32
+         of representing a real handling event. */
39 33
       final HandlingEvent event = handlingEventFactory.createHandlingEvent(
40
-        attempt.getDate(),
34
+        attempt.getCompletionTime(),
41 35
         attempt.getTrackingId(),
42 36
         attempt.getVoyageNumber(),
43 37
         attempt.getUnLocode(),
44 38
         attempt.getType()
45 39
       );
40
+
41
+      /* Store the new handling event, which updates the persistent
42
+         state of the handling event aggregate (but not the cargo aggregate -
43
+         that happens asynchronously!)
44
+       */
46 45
       handlingEventRepository.save(event);
47
-      systemEvents.cargoWasHandled(event);
46
+
47
+      /* Publish a system event stating that a cargo has been handled. */
48
+      applicationEvents.cargoWasHandled(event);
48 49
     } catch (CannotCreateHandlingEventException e) {
49
-      systemEvents.rejectHandlingEventRegistrationAttempt(attempt, e);
50
+      /* This may be a bogus attempt, for example containing a tracking id
51
+         that doesn't match any cargo that we're tracking. */
52
+      applicationEvents.rejectedHandlingEventRegistrationAttempt(attempt, e);
50 53
     }
51 54
   }
52 55