Преглед на файлове

Mistakenly omitted a few files.

peter_backlund преди 17 години
родител
ревизия
f8258747fc

+ 6
- 1
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/handling/HandlingEvent.java Целия файл

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

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

+ 40
- 0
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/domain/model/handling/OperatorCode.java Целия файл

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 Целия файл

15
     <many-to-one name="cargo" column="cargo_id" not-null="true" cascade="none" foreign-key="cargo_fk"/>
15
     <many-to-one name="cargo" column="cargo_id" not-null="true" cascade="none" foreign-key="cargo_fk"/>
16
     <property name="completionTime" column="completionTime" not-null="true"/>
16
     <property name="completionTime" column="completionTime" not-null="true"/>
17
     <property name="registrationTime" column="registrationTime" not-null="true"/>
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
       <many-to-one name="voyage" column="voyage_id" not-null="false" cascade="none" foreign-key="event_voyage_fk"/>
22
       <many-to-one name="voyage" column="voyage_id" not-null="false" cascade="none" foreign-key="event_voyage_fk"/>
20
       <many-to-one name="location" column="location_id" not-null="true" cascade="none" foreign-key="location_fk"/>
23
       <many-to-one name="location" column="location_id" not-null="true" cascade="none" foreign-key="location_fk"/>
21
       <property name="type" column="type" not-null="true">
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 Целия файл

49
     VoyageNumber voyageNumber = CM001.voyageNumber();
49
     VoyageNumber voyageNumber = CM001.voyageNumber();
50
     UnLocode unLocode = STOCKHOLM.unLocode();
50
     UnLocode unLocode = STOCKHOLM.unLocode();
51
     HandlingEvent handlingEvent = factory.createHandlingEvent(
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
     assertNotNull(handlingEvent);
55
     assertNotNull(handlingEvent);
67
 
67
 
68
     UnLocode unLocode = STOCKHOLM.unLocode();
68
     UnLocode unLocode = STOCKHOLM.unLocode();
69
     HandlingEvent handlingEvent = factory.createHandlingEvent(
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
     assertNotNull(handlingEvent);
73
     assertNotNull(handlingEvent);
86
     UnLocode invalid = new UnLocode("NOEXT");
86
     UnLocode invalid = new UnLocode("NOEXT");
87
     try {
87
     try {
88
       factory.createHandlingEvent(
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
       fail("Expected UnknownLocationException");
91
       fail("Expected UnknownLocationException");
92
     } catch (UnknownLocationException expected) {
92
     } catch (UnknownLocationException expected) {
101
     try {
101
     try {
102
       VoyageNumber invalid = new VoyageNumber("XXX");
102
       VoyageNumber invalid = new VoyageNumber("XXX");
103
       factory.createHandlingEvent(
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
       fail("Expected UnknownVoyageException");
106
       fail("Expected UnknownVoyageException");
107
     } catch (UnknownVoyageException expected) {
107
     } catch (UnknownVoyageException expected) {
115
 
115
 
116
     try {
116
     try {
117
       factory.createHandlingEvent(
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
       fail("Expected UnknownCargoException");
120
       fail("Expected UnknownCargoException");
121
     } catch (UnknownCargoException expected) {
121
     } catch (UnknownCargoException expected) {