Bläddra i källkod

Introduced Voyage, Schedule and VoyageNumber. CarrierMovement is now a value object, CarrierMovementId is dropped.

Leg now has load/unload location and time, and a reference to a Voyage.

HandlingEvent references a Voyage instead of a CarrierMovement.

DeliveryHistory is renamed to Delivery.

(Yes, it's very broken right now, but it compiles)
peter_backlund 18 år sedan
förälder
incheckning
9b5f0933d0

+ 0
- 21
dddsample/src/main/java/se/citerus/dddsample/application/persistence/CarrierMovementRepositoryHibernate.java Visa fil

@@ -1,21 +0,0 @@
1
-package se.citerus.dddsample.application.persistence;
2
-
3
-import org.springframework.stereotype.Repository;
4
-import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
5
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
6
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementRepository;
7
-
8
-/**
9
- * Hibernate implementation of CarrierMovementRepository.
10
- */
11
-@Repository
12
-public final class CarrierMovementRepositoryHibernate extends HibernateRepository implements CarrierMovementRepository {
13
-
14
-  public CarrierMovement find(final CarrierMovementId carrierMovementId) {
15
-    return (CarrierMovement) getSession().
16
-      createQuery("from CarrierMovement where carrierMovementId = ?").
17
-      setParameter(0, carrierMovementId).
18
-      uniqueResult();
19
-  }
20
-
21
-}

+ 21
- 0
dddsample/src/main/java/se/citerus/dddsample/application/persistence/VoyageRepositoryHibernate.java Visa fil

@@ -0,0 +1,21 @@
1
+package se.citerus.dddsample.application.persistence;
2
+
3
+import org.springframework.stereotype.Repository;
4
+import se.citerus.dddsample.domain.model.carrier.Voyage;
5
+import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
6
+import se.citerus.dddsample.domain.model.carrier.VoyageRepository;
7
+
8
+/**
9
+ * Hibernate implementation of CarrierMovementRepository.
10
+ */
11
+@Repository
12
+public final class VoyageRepositoryHibernate extends HibernateRepository implements VoyageRepository {
13
+
14
+  public Voyage find(final VoyageNumber voyageNumber) {
15
+    return (Voyage) getSession().
16
+      createQuery("from Voyage where voyageNumber = :vn").
17
+      setParameter("vn", voyageNumber).
18
+      uniqueResult();
19
+  }
20
+
21
+}

dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/DeliveryHistory.java → dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/Delivery.java Visa fil

@@ -2,31 +2,31 @@ package se.citerus.dddsample.domain.model.cargo;
2 2
 
3 3
 import se.citerus.dddsample.domain.model.ValueObject;
4 4
 import static se.citerus.dddsample.domain.model.cargo.StatusCode.*;
5
-import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
5
+import se.citerus.dddsample.domain.model.carrier.Voyage;
6 6
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
7 7
 import se.citerus.dddsample.domain.model.location.Location;
8 8
 
9 9
 import java.util.*;
10 10
 
11 11
 /**
12
- * The delivery history of a cargo.
12
+ * The actual result of the cargo transportation, as opposed to
13
+ * the customer requirement (RouteSpecification) and the plan (Itinerary). 
13 14
  *
14
- * This is a value object.
15 15
  */
16
-public final class DeliveryHistory implements ValueObject<DeliveryHistory> {
16
+public final class Delivery implements ValueObject<Delivery> {
17 17
 
18 18
   private Set<HandlingEvent> events;
19 19
 
20
-  public static final DeliveryHistory EMPTY_DELIVERY_HISTORY = new DeliveryHistory(Collections.EMPTY_SET);
20
+  public static final Delivery EMPTY_DELIVERY = new Delivery(Collections.EMPTY_SET);
21 21
 
22
-  DeliveryHistory(final Collection<HandlingEvent> events) {
22
+  Delivery(final Collection<HandlingEvent> events) {
23 23
     this.events = new HashSet<HandlingEvent>(events);
24 24
   }
25 25
 
26 26
   /**
27 27
    * @return An <b>unmodifiable</b> list of handling events, ordered by the time the events occured.
28 28
    */
29
-  public List<HandlingEvent> eventsOrderedByCompletionTime() {
29
+  public List<HandlingEvent> history() {
30 30
     final List<HandlingEvent> eventList = new ArrayList<HandlingEvent>(events);
31 31
     Collections.sort(eventList, HandlingEvent.BY_COMPLETION_TIME_COMPARATOR);
32 32
     return Collections.unmodifiableList(eventList);
@@ -39,11 +39,14 @@ public final class DeliveryHistory implements ValueObject<DeliveryHistory> {
39 39
     if (events.isEmpty()) {
40 40
       return null;
41 41
     } else {
42
-      final List<HandlingEvent> orderedEvents = eventsOrderedByCompletionTime();
42
+      final List<HandlingEvent> orderedEvents = history();
43 43
       return orderedEvents.get(orderedEvents.size() - 1);
44 44
     }
45 45
   }
46 46
 
47
+  /**
48
+   * @return
49
+   */
47 50
   public StatusCode status() {
48 51
     if (lastEvent() == null)
49 52
       return NOT_RECEIVED;
@@ -67,6 +70,9 @@ public final class DeliveryHistory implements ValueObject<DeliveryHistory> {
67 70
     }
68 71
   }
69 72
 
73
+  /**
74
+   * @return
75
+   */
70 76
   public Location currentLocation() {
71 77
     if (status().equals(IN_PORT)) {
72 78
       return lastEvent().location();
@@ -75,24 +81,27 @@ public final class DeliveryHistory implements ValueObject<DeliveryHistory> {
75 81
     }
76 82
   }
77 83
 
78
-  public CarrierMovement currentCarrierMovement() {
84
+  /**
85
+   * @return
86
+   */
87
+  public Voyage currentVoyage() {
79 88
     if (status().equals(ONBOARD_CARRIER)) {
80
-      return lastEvent().carrierMovement();
89
+      return lastEvent().voyage();
81 90
     } else {
82
-      return CarrierMovement.NONE;
91
+      return Voyage.NONE;
83 92
     }
84 93
   }
85 94
 
86 95
   @Override
87
-  public boolean sameValueAs(DeliveryHistory other) {
96
+  public boolean sameValueAs(Delivery other) {
88 97
     return other != null && events.equals(other.events);
89 98
   }
90 99
 
91 100
   @Override
92
-  public DeliveryHistory copy() {
101
+  public Delivery copy() {
93 102
     final Set<HandlingEvent> eventsCopy = new HashSet<HandlingEvent>(events);
94 103
 
95
-    return new DeliveryHistory(eventsCopy);
104
+    return new Delivery(eventsCopy);
96 105
   }
97 106
 
98 107
   @Override
@@ -100,7 +109,7 @@ public final class DeliveryHistory implements ValueObject<DeliveryHistory> {
100 109
     if (this == o) return true;
101 110
     if (o == null || getClass() != o.getClass()) return false;
102 111
 
103
-    final DeliveryHistory other = (DeliveryHistory) o;
112
+    final Delivery other = (Delivery) o;
104 113
 
105 114
     return sameValueAs(other);
106 115
   }
@@ -110,7 +119,7 @@ public final class DeliveryHistory implements ValueObject<DeliveryHistory> {
110 119
     return events.hashCode();
111 120
   }
112 121
 
113
-  DeliveryHistory() {
122
+  Delivery() {
114 123
     // Needed by Hibernate
115 124
   }
116 125
 

+ 0
- 14
dddsample/src/test/java/se/citerus/dddsample/application/persistence/CarrierMovementRepositoryInMem.java Visa fil

@@ -1,14 +0,0 @@
1
-package se.citerus.dddsample.application.persistence;
2
-
3
-import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
4
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
5
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementRepository;
6
-import se.citerus.dddsample.domain.model.carrier.SampleCarrierMovements;
7
-
8
-public final class CarrierMovementRepositoryInMem implements CarrierMovementRepository {
9
-
10
-  public CarrierMovement find(final CarrierMovementId carrierMovementId) {
11
-    return SampleCarrierMovements.lookup(carrierMovementId);
12
-  }
13
-
14
-}

+ 13
- 0
dddsample/src/test/java/se/citerus/dddsample/application/persistence/VoyageRepositoryInMem.java Visa fil

@@ -0,0 +1,13 @@
1
+package se.citerus.dddsample.application.persistence;
2
+
3
+import se.citerus.dddsample.domain.model.carrier.Voyage;
4
+import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
5
+import se.citerus.dddsample.domain.model.carrier.VoyageRepository;
6
+
7
+public final class VoyageRepositoryInMem implements VoyageRepository {
8
+
9
+  public Voyage find(VoyageNumber voyageNumber) {
10
+    throw new UnsupportedOperationException("Implement this!");
11
+  }
12
+  
13
+}

+ 0
- 78
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/DeliveryHistoryTest.java Visa fil

@@ -1,78 +0,0 @@
1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import junit.framework.TestCase;
4
-import se.citerus.dddsample.domain.model.carrier.CarrierMovement;
5
-import se.citerus.dddsample.domain.model.carrier.CarrierMovementId;
6
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
7
-import se.citerus.dddsample.domain.model.location.Location;
8
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
9
-
10
-import java.text.DateFormat;
11
-import java.text.SimpleDateFormat;
12
-import java.util.*;
13
-
14
-public class DeliveryHistoryTest extends TestCase {
15
-
16
-  private Cargo cargo = new Cargo(new TrackingId("XYZ"), HONGKONG, NEWYORK);
17
-
18
-  public void testEvensOrderedByTimeOccured() throws Exception {
19
-
20
-    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
21
-    CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("CAR_001"), HONGKONG, NEWYORK, new Date(), new Date());
22
-    HandlingEvent he1 = new HandlingEvent(cargo, df.parse("2010-01-03"), new Date(), HandlingEvent.Type.RECEIVE, NEWYORK);
23
-    HandlingEvent he2 = new HandlingEvent(cargo, df.parse("2010-01-01"), new Date(), HandlingEvent.Type.LOAD, NEWYORK, carrierMovement);
24
-    HandlingEvent he3 = new HandlingEvent(cargo, df.parse("2010-01-04"), new Date(), HandlingEvent.Type.CLAIM, HONGKONG);
25
-    HandlingEvent he4 = new HandlingEvent(cargo, df.parse("2010-01-02"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, carrierMovement);
26
-    DeliveryHistory dh = new DeliveryHistory(Arrays.asList(he1, he2, he3, he4));
27
-
28
-    List<HandlingEvent> orderEvents = dh.eventsOrderedByCompletionTime();
29
-    assertEquals(4, orderEvents.size());
30
-    assertSame(he2, orderEvents.get(0));
31
-    assertSame(he4, orderEvents.get(1));
32
-    assertSame(he1, orderEvents.get(2));
33
-    assertSame(he3, orderEvents.get(3));
34
-  }
35
-
36
-  public void testCargoStatusFromLastHandlingEvent() {
37
-    Set<HandlingEvent> events = new HashSet<HandlingEvent>();
38
-    DeliveryHistory deliveryHistory = new DeliveryHistory(events);
39
-
40
-    assertEquals(StatusCode.NOT_RECEIVED, deliveryHistory.status());
41
-
42
-    events.add(new HandlingEvent(cargo, new Date(10), new Date(11), HandlingEvent.Type.RECEIVE, HAMBURG));
43
-    deliveryHistory = new DeliveryHistory(events);
44
-    assertEquals(StatusCode.IN_PORT, deliveryHistory.status());
45
-
46
-    CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("ABC"), HAMBURG, HAMBURG, new Date(), new Date());
47
-    events.add(new HandlingEvent(cargo, new Date(20), new Date(21), HandlingEvent.Type.LOAD, HAMBURG, carrierMovement));
48
-    deliveryHistory = new DeliveryHistory(events);
49
-    assertEquals(StatusCode.ONBOARD_CARRIER, deliveryHistory.status());
50
-
51
-    events.add(new HandlingEvent(cargo, new Date(30), new Date(31), HandlingEvent.Type.UNLOAD, HAMBURG, carrierMovement));
52
-    deliveryHistory = new DeliveryHistory(events);
53
-    assertEquals(StatusCode.IN_PORT, deliveryHistory.status());
54
-
55
-    events.add(new HandlingEvent(cargo, new Date(40), new Date(41), HandlingEvent.Type.CLAIM, HAMBURG));
56
-    deliveryHistory = new DeliveryHistory(events);
57
-    assertEquals(StatusCode.CLAIMED, deliveryHistory.status());
58
-  }
59
-
60
-  public void testCurrentLocation() throws Exception {
61
-    Set<HandlingEvent> events = new HashSet<HandlingEvent>();
62
-    DeliveryHistory deliveryHistory = new DeliveryHistory(events);
63
-
64
-    assertEquals(Location.UNKNOWN, deliveryHistory.currentLocation());
65
-
66
-    events.add(new HandlingEvent(cargo, new Date(10), new Date(11), HandlingEvent.Type.RECEIVE, HAMBURG));
67
-    deliveryHistory = new DeliveryHistory(events);
68
-
69
-    assertEquals(HAMBURG, deliveryHistory.currentLocation());
70
-
71
-    CarrierMovement carrierMovement = new CarrierMovement(new CarrierMovementId("ABC"), HAMBURG, HAMBURG, new Date(), new Date());
72
-    events.add(new HandlingEvent(cargo, new Date(20), new Date(21), HandlingEvent.Type.LOAD, HAMBURG, carrierMovement));
73
-    deliveryHistory = new DeliveryHistory(events);
74
-
75
-    assertEquals(Location.UNKNOWN, deliveryHistory.currentLocation());
76
-  }
77
-
78
-}

+ 74
- 0
dddsample/src/test/java/se/citerus/dddsample/domain/model/cargo/DeliveryTest.java Visa fil

@@ -0,0 +1,74 @@
1
+package se.citerus.dddsample.domain.model.cargo;
2
+
3
+import junit.framework.TestCase;
4
+import static se.citerus.dddsample.domain.model.carrier.SampleVoyages.*;
5
+import se.citerus.dddsample.domain.model.handling.HandlingEvent;
6
+import se.citerus.dddsample.domain.model.location.Location;
7
+import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
8
+
9
+import java.text.DateFormat;
10
+import java.text.SimpleDateFormat;
11
+import java.util.*;
12
+
13
+public class DeliveryTest extends TestCase {
14
+
15
+  private Cargo cargo = new Cargo(new TrackingId("XYZ"), HONGKONG, NEWYORK);
16
+
17
+  public void testEvensOrderedByTimeOccured() throws Exception {
18
+
19
+    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
20
+    HandlingEvent he1 = new HandlingEvent(cargo, df.parse("2010-01-03"), new Date(), HandlingEvent.Type.RECEIVE, NEWYORK);
21
+    HandlingEvent he2 = new HandlingEvent(cargo, df.parse("2010-01-01"), new Date(), HandlingEvent.Type.LOAD, NEWYORK, CM003);
22
+    HandlingEvent he3 = new HandlingEvent(cargo, df.parse("2010-01-04"), new Date(), HandlingEvent.Type.CLAIM, HONGKONG);
23
+    HandlingEvent he4 = new HandlingEvent(cargo, df.parse("2010-01-02"), new Date(), HandlingEvent.Type.UNLOAD, HONGKONG, CM004);
24
+    Delivery dh = new Delivery(Arrays.asList(he1, he2, he3, he4));
25
+
26
+    List<HandlingEvent> orderEvents = dh.history();
27
+    assertEquals(4, orderEvents.size());
28
+    assertSame(he2, orderEvents.get(0));
29
+    assertSame(he4, orderEvents.get(1));
30
+    assertSame(he1, orderEvents.get(2));
31
+    assertSame(he3, orderEvents.get(3));
32
+  }
33
+
34
+  public void testCargoStatusFromLastHandlingEvent() {
35
+    Set<HandlingEvent> events = new HashSet<HandlingEvent>();
36
+    Delivery delivery = new Delivery(events);
37
+
38
+    assertEquals(StatusCode.NOT_RECEIVED, delivery.status());
39
+
40
+    events.add(new HandlingEvent(cargo, new Date(10), new Date(11), HandlingEvent.Type.RECEIVE, HAMBURG));
41
+    delivery = new Delivery(events);
42
+    assertEquals(StatusCode.IN_PORT, delivery.status());
43
+
44
+    events.add(new HandlingEvent(cargo, new Date(20), new Date(21), HandlingEvent.Type.LOAD, HAMBURG, CM005));
45
+    delivery = new Delivery(events);
46
+    assertEquals(StatusCode.ONBOARD_CARRIER, delivery.status());
47
+
48
+    events.add(new HandlingEvent(cargo, new Date(30), new Date(31), HandlingEvent.Type.UNLOAD, HAMBURG, CM006));
49
+    delivery = new Delivery(events);
50
+    assertEquals(StatusCode.IN_PORT, delivery.status());
51
+
52
+    events.add(new HandlingEvent(cargo, new Date(40), new Date(41), HandlingEvent.Type.CLAIM, HAMBURG));
53
+    delivery = new Delivery(events);
54
+    assertEquals(StatusCode.CLAIMED, delivery.status());
55
+  }
56
+
57
+  public void testCurrentLocation() throws Exception {
58
+    Set<HandlingEvent> events = new HashSet<HandlingEvent>();
59
+    Delivery delivery = new Delivery(events);
60
+
61
+    assertEquals(Location.UNKNOWN, delivery.currentLocation());
62
+
63
+    events.add(new HandlingEvent(cargo, new Date(10), new Date(11), HandlingEvent.Type.RECEIVE, HAMBURG));
64
+    delivery = new Delivery(events);
65
+
66
+    assertEquals(HAMBURG, delivery.currentLocation());
67
+
68
+    events.add(new HandlingEvent(cargo, new Date(20), new Date(21), HandlingEvent.Type.LOAD, HAMBURG, CM003));
69
+    delivery = new Delivery(events);
70
+
71
+    assertEquals(Location.UNKNOWN, delivery.currentLocation());
72
+  }
73
+
74
+}