Bläddra i källkod

Mistakenly omitted a few files.

peter_backlund 17 år sedan
förälder
incheckning
f8258747fc

+ 6
- 1
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/handling/HandlingEvent.java Visa fil

@@ -35,6 +35,7 @@ public final class HandlingEvent implements DomainEvent<HandlingEvent> {
35 35
   private Date completionTime;
36 36
   private Date registrationTime;
37 37
   private Cargo cargo;
38
+  private OperatorCode operatorCode;
38 39
 
39 40
   /**
40 41
    * Handling event type. Either requires or prohibits a carrier movement
@@ -89,6 +90,7 @@ public final class HandlingEvent implements DomainEvent<HandlingEvent> {
89 90
    * @param type             type of event
90 91
    * @param location         where the event took place
91 92
    * @param voyage           the voyage
93
+   * @param operatorCode     operator code for port operator
92 94
    */
93 95
   // TODO make package local
94 96
   public HandlingEvent(final Cargo cargo,
@@ -96,13 +98,15 @@ public final class HandlingEvent implements DomainEvent<HandlingEvent> {
96 98
                        final Date registrationTime,
97 99
                        final Type type,
98 100
                        final Location location,
99
-                       final Voyage voyage) {
101
+                       final Voyage voyage,
102
+                       final OperatorCode operatorCode) {
100 103
     Validate.notNull(cargo, "Cargo is required");
101 104
     Validate.notNull(completionTime, "Completion time is required");
102 105
     Validate.notNull(registrationTime, "Registration time is required");
103 106
     Validate.notNull(type, "Handling event type is required");
104 107
     Validate.notNull(location, "Location is required");
105 108
     Validate.notNull(voyage, "Voyage is required");
109
+    Validate.notNull(operatorCode, "Operator code is required");
106 110
 
107 111
     if (!type.isVoyageRelated()) {
108 112
       throw new IllegalArgumentException("Voyage is not allowed with event type " + type);
@@ -113,6 +117,7 @@ public final class HandlingEvent implements DomainEvent<HandlingEvent> {
113 117
     this.completionTime = new Date(completionTime.getTime());
114 118
     this.registrationTime = new Date(registrationTime.getTime());
115 119
     this.activity = new HandlingActivity(type, location, voyage);
120
+    this.operatorCode = operatorCode;
116 121
   }
117 122
 
118 123
   /**

+ 4
- 2
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/handling/HandlingEventFactory.java Visa fil

@@ -35,13 +35,15 @@ public class HandlingEventFactory {
35 35
    * @param voyageNumber     voyage number
36 36
    * @param unlocode         United Nations Location Code for the location of the event
37 37
    * @param type             type of event
38
+   * @param operatorCode     operator code
38 39
    * @return A handling event.
39 40
    * @throws UnknownVoyageException   if there's no voyage with this number
40 41
    * @throws UnknownCargoException    if there's no cargo with this tracking id
41 42
    * @throws UnknownLocationException if there's no location with this UN Locode
42 43
    */
43 44
   public HandlingEvent createHandlingEvent(final Date completionTime, final TrackingId trackingId,
44
-                                           final VoyageNumber voyageNumber, final UnLocode unlocode, final HandlingEvent.Type type)
45
+                                           final VoyageNumber voyageNumber, final UnLocode unlocode,
46
+                                           final HandlingEvent.Type type, final OperatorCode operatorCode)
45 47
     throws CannotCreateHandlingEventException {
46 48
 
47 49
     final Cargo cargo = findCargo(trackingId);
@@ -53,7 +55,7 @@ public class HandlingEventFactory {
53 55
       if (voyage == null) {
54 56
         return new HandlingEvent(cargo, completionTime, registrationTime, type, location);
55 57
       } else {
56
-        return new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage);
58
+        return new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage, operatorCode);
57 59
       }
58 60
     } catch (Exception e) {
59 61
       throw new CannotCreateHandlingEventException(e);

+ 40
- 0
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/handling/OperatorCode.java Visa fil

@@ -0,0 +1,40 @@
1
+package se.citerus.dddsample.tracking.core.domain.model.handling;
2
+
3
+import org.apache.commons.lang.Validate;
4
+import se.citerus.dddsample.tracking.core.domain.patterns.valueobject.ValueObjectSupport;
5
+
6
+/**
7
+ * Port operators are assigned an operator code.
8
+ */
9
+public class OperatorCode extends ValueObjectSupport<OperatorCode> {
10
+
11
+  private final String code;
12
+
13
+  /**
14
+   * Constructor.
15
+   *
16
+   * @param code code, three letters (ex: "AGH")
17
+   */
18
+  public OperatorCode(final String code) {
19
+    Validate.notEmpty(code, "Code is required");
20
+    Validate.isTrue(code.length() == 5, "Operator codes must be exactly five letters: " + code);
21
+    this.code = code;
22
+  }
23
+
24
+  /**
25
+   * @return The operator code as a String
26
+   */
27
+  public String stringValue() {
28
+    return code;
29
+  }
30
+
31
+  @Override
32
+  public String toString() {
33
+    return stringValue();
34
+  }
35
+
36
+  OperatorCode() {
37
+    // Needed by Hibernate
38
+    code = null;
39
+  }
40
+}

+ 4
- 1
dddsample/tracking/core/src/main/resources/se/citerus/dddsample/tracking/core/infrastructure/persistence/hibernate/HandlingEvent.hbm.xml Visa fil

@@ -15,7 +15,10 @@
15 15
     <many-to-one name="cargo" column="cargo_id" not-null="true" cascade="none" foreign-key="cargo_fk"/>
16 16
     <property name="completionTime" column="completionTime" not-null="true"/>
17 17
     <property name="registrationTime" column="registrationTime" not-null="true"/>
18
-    <component name="activity">
18
+    <component name="operatorCode" update="false">
19
+      <property name="code" column="operator_code" not-null="false" length="3"/>
20
+    </component>
21
+    <component name="activity" update="false">
19 22
       <many-to-one name="voyage" column="voyage_id" not-null="false" cascade="none" foreign-key="event_voyage_fk"/>
20 23
       <many-to-one name="location" column="location_id" not-null="true" cascade="none" foreign-key="location_fk"/>
21 24
       <property name="type" column="type" not-null="true">

+ 5
- 5
dddsample/tracking/core/src/test/java/se/citerus/dddsample/tracking/core/domain/model/handling/HandlingEventFactoryTest.java Visa fil

@@ -49,7 +49,7 @@ public class HandlingEventFactoryTest extends TestCase {
49 49
     VoyageNumber voyageNumber = CM001.voyageNumber();
50 50
     UnLocode unLocode = STOCKHOLM.unLocode();
51 51
     HandlingEvent handlingEvent = factory.createHandlingEvent(
52
-      new Date(100), trackingId, voyageNumber, unLocode, Type.LOAD
52
+      new Date(100), trackingId, voyageNumber, unLocode, Type.LOAD, new OperatorCode("ABCDE")
53 53
     );
54 54
 
55 55
     assertNotNull(handlingEvent);
@@ -67,7 +67,7 @@ public class HandlingEventFactoryTest extends TestCase {
67 67
 
68 68
     UnLocode unLocode = STOCKHOLM.unLocode();
69 69
     HandlingEvent handlingEvent = factory.createHandlingEvent(
70
-      new Date(100), trackingId, null, unLocode, Type.CLAIM
70
+      new Date(100), trackingId, null, unLocode, Type.CLAIM, new OperatorCode("ABCDE")
71 71
     );
72 72
 
73 73
     assertNotNull(handlingEvent);
@@ -86,7 +86,7 @@ public class HandlingEventFactoryTest extends TestCase {
86 86
     UnLocode invalid = new UnLocode("NOEXT");
87 87
     try {
88 88
       factory.createHandlingEvent(
89
-        new Date(100), trackingId, CM001.voyageNumber(), invalid, Type.LOAD
89
+        new Date(100), trackingId, CM001.voyageNumber(), invalid, Type.LOAD, new OperatorCode("ABCDE")
90 90
       );
91 91
       fail("Expected UnknownLocationException");
92 92
     } catch (UnknownLocationException expected) {
@@ -101,7 +101,7 @@ public class HandlingEventFactoryTest extends TestCase {
101 101
     try {
102 102
       VoyageNumber invalid = new VoyageNumber("XXX");
103 103
       factory.createHandlingEvent(
104
-        new Date(100), trackingId, invalid, STOCKHOLM.unLocode(), Type.LOAD
104
+        new Date(100), trackingId, invalid, STOCKHOLM.unLocode(), Type.LOAD, new OperatorCode("ABCDE")
105 105
       );
106 106
       fail("Expected UnknownVoyageException");
107 107
     } catch (UnknownVoyageException expected) {
@@ -115,7 +115,7 @@ public class HandlingEventFactoryTest extends TestCase {
115 115
 
116 116
     try {
117 117
       factory.createHandlingEvent(
118
-        new Date(100), trackingId, CM001.voyageNumber(), STOCKHOLM.unLocode(), Type.LOAD
118
+        new Date(100), trackingId, CM001.voyageNumber(), STOCKHOLM.unLocode(), Type.LOAD, new OperatorCode("ABCDE")
119 119
       );
120 120
       fail("Expected UnknownCargoException");
121 121
     } catch (UnknownCargoException expected) {