peter_backlund 17 лет назад
Родитель
Сommit
d032c94a7b

+ 5
- 3
dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/CannotCreateHandlingEventException.java Просмотреть файл

1
 package se.citerus.dddsample.domain.model.handling;
1
 package se.citerus.dddsample.domain.model.handling;
2
 
2
 
3
 /**
3
 /**
4
+ * If a {@link se.citerus.dddsample.domain.model.handling.HandlingEvent} can't be
5
+ * created from an incoming {@link #se.citerus.dddsample.application.HandlingEventRegistrationAttempt},
4
  *
6
  *
7
+ * It is a checked exception because it's not a programming error, but rather a
8
+ * special case that the application is built to handle. It can occur during normal
9
+ * program execution.
5
  */
10
  */
6
 public class CannotCreateHandlingEventException extends Exception {
11
 public class CannotCreateHandlingEventException extends Exception {
7
-
8
-
9
-
10
 }
12
 }

+ 35
- 25
dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingEvent.java Просмотреть файл

3
 import org.apache.commons.lang.Validate;
3
 import org.apache.commons.lang.Validate;
4
 import org.apache.commons.lang.builder.EqualsBuilder;
4
 import org.apache.commons.lang.builder.EqualsBuilder;
5
 import org.apache.commons.lang.builder.HashCodeBuilder;
5
 import org.apache.commons.lang.builder.HashCodeBuilder;
6
+import org.apache.commons.lang.builder.ToStringBuilder;
7
+import org.apache.commons.lang.builder.ToStringStyle;
6
 import se.citerus.dddsample.domain.model.DomainEvent;
8
 import se.citerus.dddsample.domain.model.DomainEvent;
7
 import se.citerus.dddsample.domain.model.ValueObject;
9
 import se.citerus.dddsample.domain.model.ValueObject;
8
 import se.citerus.dddsample.domain.model.cargo.Cargo;
10
 import se.citerus.dddsample.domain.model.cargo.Cargo;
9
-import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
10
 import se.citerus.dddsample.domain.model.carrier.Voyage;
11
 import se.citerus.dddsample.domain.model.carrier.Voyage;
11
 import se.citerus.dddsample.domain.model.location.Location;
12
 import se.citerus.dddsample.domain.model.location.Location;
12
 import se.citerus.dddsample.domain.shared.DomainObjectUtils;
13
 import se.citerus.dddsample.domain.shared.DomainObjectUtils;
21
  * The HandlingEvent's are sent from different Incident Logging Applications
22
  * The HandlingEvent's are sent from different Incident Logging Applications
22
  * some time after the event occured and contain information about the
23
  * some time after the event occured and contain information about the
23
  * {@link se.citerus.dddsample.domain.model.cargo.TrackingId}, {@link se.citerus.dddsample.domain.model.location.Location}, timestamp of the completion of the event,
24
  * {@link se.citerus.dddsample.domain.model.cargo.TrackingId}, {@link se.citerus.dddsample.domain.model.location.Location}, timestamp of the completion of the event,
24
- * and possibly, if applicable a {@link se.citerus.dddsample.domain.model.carrier.CarrierMovement}.
25
+ * and possibly, if applicable a {@link se.citerus.dddsample.domain.model.carrier.Voyage}.
25
  * <p/>
26
  * <p/>
26
  * This class is the only member, and consequently the root, of the HandlingEvent aggregate. 
27
  * This class is the only member, and consequently the root, of the HandlingEvent aggregate. 
27
  * <p/>
28
  * <p/>
28
- * HandlingEvent's could contain information about a {@link CarrierMovement} and if so,
29
+ * HandlingEvent's could contain information about a {@link Voyage} and if so,
29
  * the event type must be either {@link Type#LOAD} or {@link Type#UNLOAD}.
30
  * the event type must be either {@link Type#LOAD} or {@link Type#UNLOAD}.
30
  * <p/>
31
  * <p/>
31
  * All other events must be of {@link Type#RECEIVE}, {@link Type#CLAIM} or {@link Type#CUSTOMS}.
32
  * All other events must be of {@link Type#RECEIVE}, {@link Type#CLAIM} or {@link Type#CUSTOMS}.
35
   /**
36
   /**
36
    * Comparator used to be able to sort HandlingEvents according to their completion time
37
    * Comparator used to be able to sort HandlingEvents according to their completion time
37
    */
38
    */
38
-  public static final Comparator<HandlingEvent> BY_COMPLETION_TIME_COMPARATOR = new Comparator<HandlingEvent>() {
39
-    public int compare(final HandlingEvent o1, final HandlingEvent o2) {
40
-      return o1.completionTime().compareTo(o2.completionTime());
41
-    }
42
-  };
39
+  public static final Comparator<HandlingEvent> BY_COMPLETION_TIME_COMPARATOR =
40
+    new Comparator<HandlingEvent>() {
41
+      public int compare(final HandlingEvent he1, final HandlingEvent he2) {
42
+        return he1.completionTime().compareTo(he2.completionTime());
43
+      }
44
+    };
43
 
45
 
44
   private Type type;
46
   private Type type;
45
   private Voyage voyage;
47
   private Voyage voyage;
59
     CLAIM(false),
61
     CLAIM(false),
60
     CUSTOMS(false);
62
     CUSTOMS(false);
61
 
63
 
62
-    private boolean carrierMovementRequired;
64
+    private final boolean voyageRequired;
63
 
65
 
64
     /**
66
     /**
65
      * Private enum constructor.
67
      * Private enum constructor.
66
      *
68
      *
67
-     * @param carrierMovementRequired whether or not a carrier movement is associated with this event type
69
+     * @param voyageRequired whether or not a voyage is associated with this event type
68
      */
70
      */
69
-    private Type(final boolean carrierMovementRequired) {
70
-      this.carrierMovementRequired = carrierMovementRequired;
71
+    private Type(final boolean voyageRequired) {
72
+      this.voyageRequired = voyageRequired;
71
     }
73
     }
72
 
74
 
73
     /**
75
     /**
74
-     * @return True if a carrier movement association is required for this event type.
76
+     * @return True if a voyage association is required for this event type.
75
      */
77
      */
76
-    public boolean requiresCarrierMovement() {
77
-      return carrierMovementRequired;
78
+    public boolean requiresVoyage() {
79
+      return voyageRequired;
78
     }
80
     }
79
 
81
 
80
     /**
82
     /**
81
-     * @return True if a carrier movement association is prohibited for this event type.
83
+     * @return True if a voyage association is prohibited for this event type.
82
      */
84
      */
83
-    public boolean prohibitsCarrierMovement() {
84
-      return !requiresCarrierMovement();
85
+    public boolean prohibitsVoyage() {
86
+      return !requiresVoyage();
85
     }
87
     }
86
 
88
 
89
+    @Override
87
     public boolean sameValueAs(Type other) {
90
     public boolean sameValueAs(Type other) {
88
-      return false;  //To change body of implemented methods use File | Settings | File Templates.
91
+      return other != null && this.equals(other);
89
     }
92
     }
90
 
93
 
94
+    @Override
91
     public Type copy() {
95
     public Type copy() {
92
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
96
+      return this;
93
     }
97
     }
94
   }
98
   }
95
 
99
 
104
   public HandlingEvent(Cargo cargo, Date completionTime, Date registrationTime, Type type,
108
   public HandlingEvent(Cargo cargo, Date completionTime, Date registrationTime, Type type,
105
                        Location location, Voyage voyage) {
109
                        Location location, Voyage voyage) {
106
     Validate.noNullElements(new Object[] {cargo, completionTime, registrationTime, type, location, voyage});
110
     Validate.noNullElements(new Object[] {cargo, completionTime, registrationTime, type, location, voyage});
107
-    if (type.prohibitsCarrierMovement()) {
108
-      throw new IllegalArgumentException("Carrier movement is not allowed with event type " + type);
111
+    if (type.prohibitsVoyage()) {
112
+      throw new IllegalArgumentException("Voyage is not allowed with event type " + type);
109
     }
113
     }
110
 
114
 
111
     this.voyage = voyage;
115
     this.voyage = voyage;
125
    */
129
    */
126
   public HandlingEvent(Cargo cargo, Date completionTime, Date registrationTime, Type type, Location location) {
130
   public HandlingEvent(Cargo cargo, Date completionTime, Date registrationTime, Type type, Location location) {
127
     Validate.noNullElements(new Object[] {cargo, completionTime, registrationTime, type, location});
131
     Validate.noNullElements(new Object[] {cargo, completionTime, registrationTime, type, location});
128
-    if (type.requiresCarrierMovement()) {
129
-      throw new IllegalArgumentException("Carrier movement is required for event type " + type);
132
+    if (type.requiresVoyage()) {
133
+      throw new IllegalArgumentException("Voyage is required for event type " + type);
130
     }
134
     }
131
 
135
 
132
     this.completionTime = completionTime;
136
     this.completionTime = completionTime;
171
     return sameEventAs(event);
175
     return sameEventAs(event);
172
   }
176
   }
173
 
177
 
178
+  @Override
174
   public boolean sameEventAs(final HandlingEvent other) {
179
   public boolean sameEventAs(final HandlingEvent other) {
175
     return other != null && new EqualsBuilder().
180
     return other != null && new EqualsBuilder().
176
       append(this.cargo, other.cargo).
181
       append(this.cargo, other.cargo).
192
       toHashCode();
197
       toHashCode();
193
   }
198
   }
194
 
199
 
195
-  // Needed by Hibernate
200
+  @Override
201
+  public String toString() {
202
+    return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
203
+  }
204
+
196
   HandlingEvent() {
205
   HandlingEvent() {
206
+    // Needed by Hibernate
197
   }
207
   }
198
 
208
 
199
 
209
 

+ 1
- 0
dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactory.java Просмотреть файл

52
     
52
     
53
     if (location == null) throw new UnknownLocationException(unlocode);
53
     if (location == null) throw new UnknownLocationException(unlocode);
54
 
54
 
55
+    // TODO parameterize
55
     final Date registrationTime = new Date();
56
     final Date registrationTime = new Date();
56
 
57
 
57
     if (voyage == null) {
58
     if (voyage == null) {

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactoryTest.java Просмотреть файл

39
 
39
 
40
     trackingId = new TrackingId("ABC");
40
     trackingId = new TrackingId("ABC");
41
     RouteSpecification routeSpecification = new RouteSpecification(TOKYO, HELSINKI, new Date());
41
     RouteSpecification routeSpecification = new RouteSpecification(TOKYO, HELSINKI, new Date());
42
-    cargo = new Cargo(trackingId, routeSpecification);
42
+    cargo = new Cargo(trackingId, TOKYO, routeSpecification);
43
   }
43
   }
44
 
44
 
45
   public void testCreateHandlingEventWithCarrierMovement() throws Exception {
45
   public void testCreateHandlingEventWithCarrierMovement() throws Exception {

+ 1
- 1
dddsample/src/test/java/se/citerus/dddsample/domain/model/handling/HandlingEventTest.java Просмотреть файл

19
   protected void setUp() throws Exception {
19
   protected void setUp() throws Exception {
20
     TrackingId trackingId = new TrackingId("XYZ");
20
     TrackingId trackingId = new TrackingId("XYZ");
21
     RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, NEWYORK, new Date());
21
     RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, NEWYORK, new Date());
22
-    cargo = new Cargo(trackingId, routeSpecification);
22
+    cargo = new Cargo(trackingId, HONGKONG, routeSpecification);
23
   }
23
   }
24
 
24
 
25
   public void testNewWithCarrierMovement() throws Exception {
25
   public void testNewWithCarrierMovement() throws Exception {