peter_backlund 17 лет назад
Родитель
Сommit
9e09bbb94c
100 измененных файлов: 0 добавлений и 5319 удалений
  1. 0
    160
      dddsample/src/main/java/com/aggregator/HandlingReport.java
  2. 0
    29
      dddsample/src/main/java/com/aggregator/HandlingReportErrors.java
  3. 0
    46
      dddsample/src/main/java/com/aggregator/HandlingReportErrors_Exception.java
  4. 0
    36
      dddsample/src/main/java/com/aggregator/HandlingReportService.java
  5. 0
    78
      dddsample/src/main/java/com/aggregator/HandlingReportService.wsdl
  6. 0
    58
      dddsample/src/main/java/com/aggregator/HandlingReportServiceService.java
  7. 0
    87
      dddsample/src/main/java/com/aggregator/ObjectFactory.java
  8. 0
    53
      dddsample/src/main/java/com/aggregator/SubmitReport.java
  9. 0
    29
      dddsample/src/main/java/com/aggregator/SubmitReportResponse.java
  10. 0
    1
      dddsample/src/main/java/com/aggregator/package-info.java
  11. 0
    7
      dddsample/src/main/java/com/aggregator/package.html
  12. 0
    25
      dddsample/src/main/java/com/pathfinder/api/GraphTraversalService.java
  13. 0
    58
      dddsample/src/main/java/com/pathfinder/api/TransitEdge.java
  14. 0
    29
      dddsample/src/main/java/com/pathfinder/api/TransitPath.java
  15. 0
    7
      dddsample/src/main/java/com/pathfinder/api/package.html
  16. 0
    27
      dddsample/src/main/java/com/pathfinder/internal/GraphDAO.java
  17. 0
    83
      dddsample/src/main/java/com/pathfinder/internal/GraphTraversalServiceImpl.java
  18. 0
    7
      dddsample/src/main/java/com/pathfinder/internal/package.html
  19. 0
    15
      dddsample/src/main/java/com/pathfinder/package.html
  20. 0
    57
      dddsample/src/main/java/se/citerus/dddsample/application/booking/BookingService.java
  21. 0
    90
      dddsample/src/main/java/se/citerus/dddsample/application/booking/BookingServiceImpl.java
  22. 0
    7
      dddsample/src/main/java/se/citerus/dddsample/application/booking/package.html
  23. 0
    59
      dddsample/src/main/java/se/citerus/dddsample/application/event/CargoUpdater.java
  24. 0
    43
      dddsample/src/main/java/se/citerus/dddsample/application/event/ItineraryUpdater.java
  25. 0
    37
      dddsample/src/main/java/se/citerus/dddsample/application/event/MisdirectedNotifier.java
  26. 0
    40
      dddsample/src/main/java/se/citerus/dddsample/application/event/ReadyToClaimNotfier.java
  27. 0
    29
      dddsample/src/main/java/se/citerus/dddsample/application/event/SystemEvents.java
  28. 0
    7
      dddsample/src/main/java/se/citerus/dddsample/application/event/package.html
  29. 0
    35
      dddsample/src/main/java/se/citerus/dddsample/application/handling/HandlingEventService.java
  30. 0
    60
      dddsample/src/main/java/se/citerus/dddsample/application/handling/HandlingEventServiceImpl.java
  31. 0
    7
      dddsample/src/main/java/se/citerus/dddsample/application/handling/package.html
  32. 0
    18
      dddsample/src/main/java/se/citerus/dddsample/application/package.html
  33. 0
    38
      dddsample/src/main/java/se/citerus/dddsample/application/util/DateTestUtil.java
  34. 0
    334
      dddsample/src/main/java/se/citerus/dddsample/application/util/SampleDataGenerator.java
  35. 0
    7
      dddsample/src/main/java/se/citerus/dddsample/application/util/package.html
  36. 0
    220
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/Cargo.java
  37. 0
    34
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/CargoFactory.java
  38. 0
    38
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/CargoRepository.java
  39. 0
    177
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/Delivery.java
  40. 0
    250
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/Itinerary.java
  41. 0
    133
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/Leg.java
  42. 0
    167
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/Projections.java
  43. 0
    128
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/RouteSpecification.java
  44. 0
    28
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/RoutingStatus.java
  45. 0
    66
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/TrackingId.java
  46. 0
    10
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/TrackingIdGenerator.java
  47. 0
    35
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/TransportStatus.java
  48. 0
    7
      dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/package.html
  49. 0
    19
      dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/CannotCreateHandlingEventException.java
  50. 0
    227
      dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingEvent.java
  51. 0
    89
      dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactory.java
  52. 0
    36
      dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingEventRepository.java
  53. 0
    136
      dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingHistory.java
  54. 0
    26
      dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/UnknownCargoException.java
  55. 0
    17
      dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/UnknownLocationException.java
  56. 0
    20
      dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/UnknownVoyageException.java
  57. 0
    7
      dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/package.html
  58. 0
    124
      dddsample/src/main/java/se/citerus/dddsample/domain/model/location/CustomsZone.java
  59. 0
    117
      dddsample/src/main/java/se/citerus/dddsample/domain/model/location/Location.java
  60. 0
    22
      dddsample/src/main/java/se/citerus/dddsample/domain/model/location/LocationRepository.java
  61. 0
    64
      dddsample/src/main/java/se/citerus/dddsample/domain/model/location/SampleLocations.java
  62. 0
    71
      dddsample/src/main/java/se/citerus/dddsample/domain/model/location/UnLocode.java
  63. 0
    7
      dddsample/src/main/java/se/citerus/dddsample/domain/model/location/package.html
  64. 0
    9
      dddsample/src/main/java/se/citerus/dddsample/domain/model/package.html
  65. 0
    51
      dddsample/src/main/java/se/citerus/dddsample/domain/model/shared/EventSequenceNumber.java
  66. 0
    94
      dddsample/src/main/java/se/citerus/dddsample/domain/model/shared/HandlingActivity.java
  67. 0
    7
      dddsample/src/main/java/se/citerus/dddsample/domain/model/shared/package.html
  68. 0
    125
      dddsample/src/main/java/se/citerus/dddsample/domain/model/voyage/CarrierMovement.java
  69. 0
    137
      dddsample/src/main/java/se/citerus/dddsample/domain/model/voyage/SampleVoyages.java
  70. 0
    85
      dddsample/src/main/java/se/citerus/dddsample/domain/model/voyage/Schedule.java
  71. 0
    132
      dddsample/src/main/java/se/citerus/dddsample/domain/model/voyage/Voyage.java
  72. 0
    53
      dddsample/src/main/java/se/citerus/dddsample/domain/model/voyage/VoyageNumber.java
  73. 0
    13
      dddsample/src/main/java/se/citerus/dddsample/domain/model/voyage/VoyageRepository.java
  74. 0
    7
      dddsample/src/main/java/se/citerus/dddsample/domain/model/voyage/package.html
  75. 0
    15
      dddsample/src/main/java/se/citerus/dddsample/domain/package.html
  76. 0
    19
      dddsample/src/main/java/se/citerus/dddsample/domain/service/RoutingService.java
  77. 0
    9
      dddsample/src/main/java/se/citerus/dddsample/domain/service/package.html
  78. 0
    35
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/AbstractSpecification.java
  79. 0
    28
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/AndSpecification.java
  80. 0
    17
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/DomainEvent.java
  81. 0
    29
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/DomainObjectUtils.java
  82. 0
    16
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/Entity.java
  83. 0
    25
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/NotSpecification.java
  84. 0
    28
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/OrSpecification.java
  85. 0
    42
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/Specification.java
  86. 0
    18
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/ValueObject.java
  87. 0
    17
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/experimental/DomainEvent.java
  88. 0
    23
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/experimental/Entity.java
  89. 0
    29
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/experimental/EntitySupport.java
  90. 0
    15
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/experimental/Identity.java
  91. 0
    23
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/experimental/ValueObject.java
  92. 0
    60
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/experimental/ValueObjectSupport.java
  93. 0
    8
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/experimental/package.html
  94. 0
    7
      dddsample/src/main/java/se/citerus/dddsample/domain/shared/package.html
  95. 0
    54
      dddsample/src/main/java/se/citerus/dddsample/infrastructure/messaging/jms/JmsSystemEventsImpl.java
  96. 0
    7
      dddsample/src/main/java/se/citerus/dddsample/infrastructure/messaging/jms/package.html
  97. 0
    32
      dddsample/src/main/java/se/citerus/dddsample/infrastructure/persistence/DatabaseTrackingIdGenerator.java
  98. 0
    23
      dddsample/src/main/java/se/citerus/dddsample/infrastructure/persistence/TrackingIdGeneratorInMem.java
  99. 0
    49
      dddsample/src/main/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryHibernate.java
  100. 0
    0
      dddsample/src/main/java/se/citerus/dddsample/infrastructure/persistence/hibernate/HandlingEventRepositoryHibernate.java

+ 0
- 160
dddsample/src/main/java/com/aggregator/HandlingReport.java Просмотреть файл

@@ -1,160 +0,0 @@
1
-package com.aggregator;
2
-
3
-import javax.xml.bind.annotation.XmlAccessType;
4
-import javax.xml.bind.annotation.XmlAccessorType;
5
-import javax.xml.bind.annotation.XmlElement;
6
-import javax.xml.bind.annotation.XmlType;
7
-import javax.xml.datatype.XMLGregorianCalendar;
8
-import java.util.ArrayList;
9
-import java.util.List;
10
-
11
-
12
-/**
13
- * <p>Java class for handlingReport complex type.
14
- * <p/>
15
- * <p>The following schema fragment specifies the expected content contained within this class.
16
- * <p/>
17
- * <pre>
18
- * &lt;complexType name="handlingReport">
19
- *   &lt;complexContent>
20
- *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
21
- *       &lt;sequence>
22
- *         &lt;element name="completionTime" type="{http://www.w3.org/2001/XMLSchema}dateTime"/>
23
- *         &lt;element name="trackingIds" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded"/>
24
- *         &lt;element name="type" type="{http://www.w3.org/2001/XMLSchema}string"/>
25
- *         &lt;element name="unLocode" type="{http://www.w3.org/2001/XMLSchema}string"/>
26
- *         &lt;element name="voyageNumber" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
27
- *       &lt;/sequence>
28
- *     &lt;/restriction>
29
- *   &lt;/complexContent>
30
- * &lt;/complexType>
31
- * </pre>
32
- */
33
-@XmlAccessorType(XmlAccessType.FIELD)
34
-@XmlType(name = "handlingReport", propOrder = {
35
-  "completionTime",
36
-  "trackingIds",
37
-  "type",
38
-  "unLocode",
39
-  "voyageNumber"
40
-})
41
-public class HandlingReport {
42
-
43
-  @XmlElement(required = true)
44
-  protected XMLGregorianCalendar completionTime;
45
-  @XmlElement(required = true)
46
-  protected List<String> trackingIds;
47
-  @XmlElement(required = true)
48
-  protected String type;
49
-  @XmlElement(required = true)
50
-  protected String unLocode;
51
-  protected String voyageNumber;
52
-
53
-  /**
54
-   * Gets the value of the completionTime property.
55
-   *
56
-   * @return possible object is
57
-   *         {@link XMLGregorianCalendar }
58
-   */
59
-  public XMLGregorianCalendar getCompletionTime() {
60
-    return completionTime;
61
-  }
62
-
63
-  /**
64
-   * Sets the value of the completionTime property.
65
-   *
66
-   * @param value allowed object is
67
-   *              {@link XMLGregorianCalendar }
68
-   */
69
-  public void setCompletionTime(XMLGregorianCalendar value) {
70
-    this.completionTime = value;
71
-  }
72
-
73
-  /**
74
-   * Gets the value of the trackingIds property.
75
-   * <p/>
76
-   * <p/>
77
-   * This accessor method returns a reference to the live list,
78
-   * not a snapshot. Therefore any modification you make to the
79
-   * returned list will be present inside the JAXB object.
80
-   * This is why there is not a <CODE>set</CODE> method for the trackingIds property.
81
-   * <p/>
82
-   * <p/>
83
-   * For example, to add a new item, do as follows:
84
-   * <pre>
85
-   *    getTrackingIds().add(newItem);
86
-   * </pre>
87
-   * <p/>
88
-   * <p/>
89
-   * <p/>
90
-   * Objects of the following type(s) are allowed in the list
91
-   * {@link String }
92
-   */
93
-  public List<String> getTrackingIds() {
94
-    if (trackingIds == null) {
95
-      trackingIds = new ArrayList<String>();
96
-    }
97
-    return this.trackingIds;
98
-  }
99
-
100
-  /**
101
-   * Gets the value of the type property.
102
-   *
103
-   * @return possible object is
104
-   *         {@link String }
105
-   */
106
-  public String getType() {
107
-    return type;
108
-  }
109
-
110
-  /**
111
-   * Sets the value of the type property.
112
-   *
113
-   * @param value allowed object is
114
-   *              {@link String }
115
-   */
116
-  public void setType(String value) {
117
-    this.type = value;
118
-  }
119
-
120
-  /**
121
-   * Gets the value of the unLocode property.
122
-   *
123
-   * @return possible object is
124
-   *         {@link String }
125
-   */
126
-  public String getUnLocode() {
127
-    return unLocode;
128
-  }
129
-
130
-  /**
131
-   * Sets the value of the unLocode property.
132
-   *
133
-   * @param value allowed object is
134
-   *              {@link String }
135
-   */
136
-  public void setUnLocode(String value) {
137
-    this.unLocode = value;
138
-  }
139
-
140
-  /**
141
-   * Gets the value of the voyageNumber property.
142
-   *
143
-   * @return possible object is
144
-   *         {@link String }
145
-   */
146
-  public String getVoyageNumber() {
147
-    return voyageNumber;
148
-  }
149
-
150
-  /**
151
-   * Sets the value of the voyageNumber property.
152
-   *
153
-   * @param value allowed object is
154
-   *              {@link String }
155
-   */
156
-  public void setVoyageNumber(String value) {
157
-    this.voyageNumber = value;
158
-  }
159
-
160
-}

+ 0
- 29
dddsample/src/main/java/com/aggregator/HandlingReportErrors.java Просмотреть файл

@@ -1,29 +0,0 @@
1
-package com.aggregator;
2
-
3
-import javax.xml.bind.annotation.XmlAccessType;
4
-import javax.xml.bind.annotation.XmlAccessorType;
5
-import javax.xml.bind.annotation.XmlType;
6
-
7
-
8
-/**
9
- * <p>Java class for HandlingReportErrors complex type.
10
- * <p/>
11
- * <p>The following schema fragment specifies the expected content contained within this class.
12
- * <p/>
13
- * <pre>
14
- * &lt;complexType name="HandlingReportErrors">
15
- *   &lt;complexContent>
16
- *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
17
- *       &lt;sequence>
18
- *       &lt;/sequence>
19
- *     &lt;/restriction>
20
- *   &lt;/complexContent>
21
- * &lt;/complexType>
22
- * </pre>
23
- */
24
-@XmlAccessorType(XmlAccessType.FIELD)
25
-@XmlType(name = "HandlingReportErrors")
26
-public class HandlingReportErrors {
27
-
28
-
29
-}

+ 0
- 46
dddsample/src/main/java/com/aggregator/HandlingReportErrors_Exception.java Просмотреть файл

@@ -1,46 +0,0 @@
1
-package com.aggregator;
2
-
3
-import javax.xml.ws.WebFault;
4
-
5
-
6
-/**
7
- * This class was generated by the JAX-WS RI.
8
- * JAX-WS RI 2.1.1 in JDK 6
9
- * Generated source version: 2.1
10
- */
11
-@WebFault(name = "HandlingReportErrors", targetNamespace = "http://ws.handling.interfaces.dddsample.citerus.se/")
12
-public class HandlingReportErrors_Exception
13
-  extends Exception {
14
-
15
-  /**
16
-   * Java type that goes as soapenv:Fault detail element.
17
-   */
18
-  private HandlingReportErrors faultInfo;
19
-
20
-  /**
21
-   * @param message
22
-   * @param faultInfo
23
-   */
24
-  public HandlingReportErrors_Exception(String message, HandlingReportErrors faultInfo) {
25
-    super(message);
26
-    this.faultInfo = faultInfo;
27
-  }
28
-
29
-  /**
30
-   * @param message
31
-   * @param faultInfo
32
-   * @param cause
33
-   */
34
-  public HandlingReportErrors_Exception(String message, HandlingReportErrors faultInfo, Throwable cause) {
35
-    super(message, cause);
36
-    this.faultInfo = faultInfo;
37
-  }
38
-
39
-  /**
40
-   * @return returns fault bean: com.aggregator.HandlingReportErrors
41
-   */
42
-  public HandlingReportErrors getFaultInfo() {
43
-    return faultInfo;
44
-  }
45
-
46
-}

+ 0
- 36
dddsample/src/main/java/com/aggregator/HandlingReportService.java Просмотреть файл

@@ -1,36 +0,0 @@
1
-package com.aggregator;
2
-
3
-import javax.jws.WebMethod;
4
-import javax.jws.WebParam;
5
-import javax.jws.WebService;
6
-import javax.xml.bind.annotation.XmlSeeAlso;
7
-import javax.xml.ws.RequestWrapper;
8
-import javax.xml.ws.ResponseWrapper;
9
-
10
-
11
-/**
12
- * This class was generated by the JAX-WS RI.
13
- * JAX-WS RI 2.1.1 in JDK 6
14
- * Generated source version: 2.1
15
- */
16
-@WebService(name = "HandlingReportService", targetNamespace = "http://ws.handling.interfaces.dddsample.citerus.se/")
17
-@XmlSeeAlso({
18
-  ObjectFactory.class
19
-})
20
-public interface HandlingReportService {
21
-
22
-
23
-  /**
24
-   * @param arg0
25
-   * @throws HandlingReportErrors_Exception
26
-   */
27
-  @WebMethod
28
-  @RequestWrapper(localName = "submitReport", targetNamespace = "http://ws.handling.interfaces.dddsample.citerus.se/", className = "com.aggregator.SubmitReport")
29
-  @ResponseWrapper(localName = "submitReportResponse", targetNamespace = "http://ws.handling.interfaces.dddsample.citerus.se/", className = "com.aggregator.SubmitReportResponse")
30
-  public void submitReport(
31
-    @WebParam(name = "arg0", targetNamespace = "")
32
-    HandlingReport arg0)
33
-    throws HandlingReportErrors_Exception
34
-    ;
35
-
36
-}

+ 0
- 78
dddsample/src/main/java/com/aggregator/HandlingReportService.wsdl Просмотреть файл

@@ -1,78 +0,0 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
2
-<wsdl:definitions name="HandlingReportServiceService"
3
-                  targetNamespace="http://ws.handling.interfaces.dddsample.citerus.se/"
4
-                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
5
-                  xmlns:tns="http://ws.handling.interfaces.dddsample.citerus.se/"
6
-                  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
7
-  <wsdl:types>
8
-    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
9
-               xmlns:tns="http://ws.handling.interfaces.dddsample.citerus.se/" attributeFormDefault="unqualified"
10
-               elementFormDefault="unqualified" targetNamespace="http://ws.handling.interfaces.dddsample.citerus.se/">
11
-      <xs:element name="submitReport" type="tns:submitReport"/>
12
-      <xs:element name="submitReportResponse" type="tns:submitReportResponse"/>
13
-      <xs:complexType name="submitReport">
14
-        <xs:sequence>
15
-          <xs:element minOccurs="0" name="arg0" type="tns:handlingReport"/>
16
-        </xs:sequence>
17
-      </xs:complexType>
18
-      <xs:complexType name="handlingReport">
19
-        <xs:sequence>
20
-          <xs:element name="completionTime" type="xs:dateTime"/>
21
-          <xs:element maxOccurs="unbounded" name="trackingIds" type="xs:string"/>
22
-          <xs:element name="type" type="xs:string"/>
23
-          <xs:element name="unLocode" type="xs:string"/>
24
-          <xs:element minOccurs="0" name="voyageNumber" type="xs:string"/>
25
-        </xs:sequence>
26
-      </xs:complexType>
27
-      <xs:complexType name="submitReportResponse">
28
-        <xs:sequence/>
29
-      </xs:complexType>
30
-      <xs:element name="HandlingReportErrors" type="tns:HandlingReportErrors"/>
31
-      <xs:complexType name="HandlingReportErrors">
32
-        <xs:sequence/>
33
-      </xs:complexType>
34
-    </xs:schema>
35
-  </wsdl:types>
36
-  <wsdl:message name="HandlingReportErrors">
37
-    <wsdl:part name="HandlingReportErrors" element="tns:HandlingReportErrors">
38
-    </wsdl:part>
39
-  </wsdl:message>
40
-  <wsdl:message name="submitReport">
41
-    <wsdl:part name="parameters" element="tns:submitReport">
42
-    </wsdl:part>
43
-  </wsdl:message>
44
-  <wsdl:message name="submitReportResponse">
45
-    <wsdl:part name="parameters" element="tns:submitReportResponse">
46
-    </wsdl:part>
47
-  </wsdl:message>
48
-  <wsdl:portType name="HandlingReportService">
49
-    <wsdl:operation name="submitReport">
50
-      <wsdl:input name="submitReport" message="tns:submitReport">
51
-      </wsdl:input>
52
-      <wsdl:output name="submitReportResponse" message="tns:submitReportResponse">
53
-      </wsdl:output>
54
-      <wsdl:fault name="HandlingReportErrors" message="tns:HandlingReportErrors">
55
-      </wsdl:fault>
56
-    </wsdl:operation>
57
-  </wsdl:portType>
58
-  <wsdl:binding name="HandlingReportServiceServiceSoapBinding" type="tns:HandlingReportService">
59
-    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
60
-    <wsdl:operation name="submitReport">
61
-      <soap:operation soapAction="" style="document"/>
62
-      <wsdl:input name="submitReport">
63
-        <soap:body use="literal"/>
64
-      </wsdl:input>
65
-      <wsdl:output name="submitReportResponse">
66
-        <soap:body use="literal"/>
67
-      </wsdl:output>
68
-      <wsdl:fault name="HandlingReportErrors">
69
-        <soap:fault name="HandlingReportErrors" use="literal"/>
70
-      </wsdl:fault>
71
-    </wsdl:operation>
72
-  </wsdl:binding>
73
-  <wsdl:service name="HandlingReportServiceService">
74
-    <wsdl:port name="HandlingReportServicePort" binding="tns:HandlingReportServiceServiceSoapBinding">
75
-      <soap:address location="http://localhost:9090/HandlingReportServicePort"/>
76
-    </wsdl:port>
77
-  </wsdl:service>
78
-</wsdl:definitions>

+ 0
- 58
dddsample/src/main/java/com/aggregator/HandlingReportServiceService.java Просмотреть файл

@@ -1,58 +0,0 @@
1
-package com.aggregator;
2
-
3
-import javax.xml.namespace.QName;
4
-import javax.xml.ws.Service;
5
-import javax.xml.ws.WebEndpoint;
6
-import javax.xml.ws.WebServiceClient;
7
-import javax.xml.ws.WebServiceFeature;
8
-import java.net.MalformedURLException;
9
-import java.net.URL;
10
-
11
-
12
-/**
13
- * This class was generated by the JAX-WS RI.
14
- * JAX-WS RI 2.1.1 in JDK 6
15
- * Generated source version: 2.1
16
- */
17
-@WebServiceClient(name = "HandlingReportServiceService", targetNamespace = "http://ws.handling.interfaces.dddsample.citerus.se/", wsdlLocation = "file:///Users/peter/src/dddsample/src/main/resources/HandlingReportService.wsdl")
18
-public class HandlingReportServiceService
19
-  extends Service {
20
-
21
-  private final static URL HANDLINGREPORTSERVICESERVICE_WSDL_LOCATION;
22
-
23
-  static {
24
-    URL url = null;
25
-    try {
26
-      url = new URL("file:/Users/peter/src/dddsample/src/main/resources/HandlingReportService.wsdl");
27
-    } catch (MalformedURLException e) {
28
-      e.printStackTrace();
29
-    }
30
-    HANDLINGREPORTSERVICESERVICE_WSDL_LOCATION = url;
31
-  }
32
-
33
-  public HandlingReportServiceService(URL wsdlLocation, QName serviceName) {
34
-    super(wsdlLocation, serviceName);
35
-  }
36
-
37
-  public HandlingReportServiceService() {
38
-    super(HANDLINGREPORTSERVICESERVICE_WSDL_LOCATION, new QName("http://ws.handling.interfaces.dddsample.citerus.se/", "HandlingReportServiceService"));
39
-  }
40
-
41
-  /**
42
-   * @return returns HandlingReportService
43
-   */
44
-  @WebEndpoint(name = "HandlingReportServicePort")
45
-  public HandlingReportService getHandlingReportServicePort() {
46
-    return (HandlingReportService) super.getPort(new QName("http://ws.handling.interfaces.dddsample.citerus.se/", "HandlingReportServicePort"), HandlingReportService.class);
47
-  }
48
-
49
-  /**
50
-   * @param features A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
51
-   * @return returns HandlingReportService
52
-   */
53
-  @WebEndpoint(name = "HandlingReportServicePort")
54
-  public HandlingReportService getHandlingReportServicePort(WebServiceFeature... features) {
55
-    return (HandlingReportService) super.getPort(new QName("http://ws.handling.interfaces.dddsample.citerus.se/", "HandlingReportServicePort"), HandlingReportService.class, features);
56
-  }
57
-
58
-}

+ 0
- 87
dddsample/src/main/java/com/aggregator/ObjectFactory.java Просмотреть файл

@@ -1,87 +0,0 @@
1
-package com.aggregator;
2
-
3
-import javax.xml.bind.JAXBElement;
4
-import javax.xml.bind.annotation.XmlElementDecl;
5
-import javax.xml.bind.annotation.XmlRegistry;
6
-import javax.xml.namespace.QName;
7
-
8
-
9
-/**
10
- * This object contains factory methods for each
11
- * Java content interface and Java element interface
12
- * generated in the com.aggregator package.
13
- * <p>An ObjectFactory allows you to programatically
14
- * construct new instances of the Java representation
15
- * for XML content. The Java representation of XML
16
- * content can consist of schema derived interfaces
17
- * and classes representing the binding of schema
18
- * type definitions, element declarations and model
19
- * groups.  Factory methods for each of these are
20
- * provided in this class.
21
- */
22
-@XmlRegistry
23
-public class ObjectFactory {
24
-
25
-  private final static QName _SubmitReport_QNAME = new QName("http://ws.handling.interfaces.dddsample.citerus.se/", "submitReport");
26
-  private final static QName _HandlingReportErrors_QNAME = new QName("http://ws.handling.interfaces.dddsample.citerus.se/", "HandlingReportErrors");
27
-  private final static QName _SubmitReportResponse_QNAME = new QName("http://ws.handling.interfaces.dddsample.citerus.se/", "submitReportResponse");
28
-
29
-  /**
30
-   * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.aggregator
31
-   */
32
-  public ObjectFactory() {
33
-  }
34
-
35
-  /**
36
-   * Create an instance of {@link HandlingReportErrors }
37
-   */
38
-  public HandlingReportErrors createHandlingReportErrors() {
39
-    return new HandlingReportErrors();
40
-  }
41
-
42
-  /**
43
-   * Create an instance of {@link SubmitReportResponse }
44
-   */
45
-  public SubmitReportResponse createSubmitReportResponse() {
46
-    return new SubmitReportResponse();
47
-  }
48
-
49
-  /**
50
-   * Create an instance of {@link HandlingReport }
51
-   */
52
-  public HandlingReport createHandlingReport() {
53
-    return new HandlingReport();
54
-  }
55
-
56
-  /**
57
-   * Create an instance of {@link SubmitReport }
58
-   */
59
-  public SubmitReport createSubmitReport() {
60
-    return new SubmitReport();
61
-  }
62
-
63
-  /**
64
-   * Create an instance of {@link JAXBElement }{@code <}{@link SubmitReport }{@code >}}
65
-   */
66
-  @XmlElementDecl(namespace = "http://ws.handling.interfaces.dddsample.citerus.se/", name = "submitReport")
67
-  public JAXBElement<SubmitReport> createSubmitReport(SubmitReport value) {
68
-    return new JAXBElement<SubmitReport>(_SubmitReport_QNAME, SubmitReport.class, null, value);
69
-  }
70
-
71
-  /**
72
-   * Create an instance of {@link JAXBElement }{@code <}{@link HandlingReportErrors }{@code >}}
73
-   */
74
-  @XmlElementDecl(namespace = "http://ws.handling.interfaces.dddsample.citerus.se/", name = "HandlingReportErrors")
75
-  public JAXBElement<HandlingReportErrors> createHandlingReportErrors(HandlingReportErrors value) {
76
-    return new JAXBElement<HandlingReportErrors>(_HandlingReportErrors_QNAME, HandlingReportErrors.class, null, value);
77
-  }
78
-
79
-  /**
80
-   * Create an instance of {@link JAXBElement }{@code <}{@link SubmitReportResponse }{@code >}}
81
-   */
82
-  @XmlElementDecl(namespace = "http://ws.handling.interfaces.dddsample.citerus.se/", name = "submitReportResponse")
83
-  public JAXBElement<SubmitReportResponse> createSubmitReportResponse(SubmitReportResponse value) {
84
-    return new JAXBElement<SubmitReportResponse>(_SubmitReportResponse_QNAME, SubmitReportResponse.class, null, value);
85
-  }
86
-
87
-}

+ 0
- 53
dddsample/src/main/java/com/aggregator/SubmitReport.java Просмотреть файл

@@ -1,53 +0,0 @@
1
-package com.aggregator;
2
-
3
-import javax.xml.bind.annotation.XmlAccessType;
4
-import javax.xml.bind.annotation.XmlAccessorType;
5
-import javax.xml.bind.annotation.XmlType;
6
-
7
-
8
-/**
9
- * <p>Java class for submitReport complex type.
10
- * <p/>
11
- * <p>The following schema fragment specifies the expected content contained within this class.
12
- * <p/>
13
- * <pre>
14
- * &lt;complexType name="submitReport">
15
- *   &lt;complexContent>
16
- *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
17
- *       &lt;sequence>
18
- *         &lt;element name="arg0" type="{http://ws.handling.interfaces.dddsample.citerus.se/}handlingReport" minOccurs="0"/>
19
- *       &lt;/sequence>
20
- *     &lt;/restriction>
21
- *   &lt;/complexContent>
22
- * &lt;/complexType>
23
- * </pre>
24
- */
25
-@XmlAccessorType(XmlAccessType.FIELD)
26
-@XmlType(name = "submitReport", propOrder = {
27
-  "arg0"
28
-})
29
-public class SubmitReport {
30
-
31
-  protected HandlingReport arg0;
32
-
33
-  /**
34
-   * Gets the value of the arg0 property.
35
-   *
36
-   * @return possible object is
37
-   *         {@link HandlingReport }
38
-   */
39
-  public HandlingReport getArg0() {
40
-    return arg0;
41
-  }
42
-
43
-  /**
44
-   * Sets the value of the arg0 property.
45
-   *
46
-   * @param value allowed object is
47
-   *              {@link HandlingReport }
48
-   */
49
-  public void setArg0(HandlingReport value) {
50
-    this.arg0 = value;
51
-  }
52
-
53
-}

+ 0
- 29
dddsample/src/main/java/com/aggregator/SubmitReportResponse.java Просмотреть файл

@@ -1,29 +0,0 @@
1
-package com.aggregator;
2
-
3
-import javax.xml.bind.annotation.XmlAccessType;
4
-import javax.xml.bind.annotation.XmlAccessorType;
5
-import javax.xml.bind.annotation.XmlType;
6
-
7
-
8
-/**
9
- * <p>Java class for submitReportResponse complex type.
10
- * <p/>
11
- * <p>The following schema fragment specifies the expected content contained within this class.
12
- * <p/>
13
- * <pre>
14
- * &lt;complexType name="submitReportResponse">
15
- *   &lt;complexContent>
16
- *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
17
- *       &lt;sequence>
18
- *       &lt;/sequence>
19
- *     &lt;/restriction>
20
- *   &lt;/complexContent>
21
- * &lt;/complexType>
22
- * </pre>
23
- */
24
-@XmlAccessorType(XmlAccessType.FIELD)
25
-@XmlType(name = "submitReportResponse")
26
-public class SubmitReportResponse {
27
-
28
-
29
-}

+ 0
- 1
dddsample/src/main/java/com/aggregator/package-info.java Просмотреть файл

@@ -1 +0,0 @@
1
-@javax.xml.bind.annotation.XmlSchema(namespace = "http://ws.handling.interfaces.dddsample.citerus.se/") package com.aggregator;

+ 0
- 7
dddsample/src/main/java/com/aggregator/package.html Просмотреть файл

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	Generated from the upstream Aggregation Service WSDL
5
-</p>
6
-</body>
7
-</html>

+ 0
- 25
dddsample/src/main/java/com/pathfinder/api/GraphTraversalService.java Просмотреть файл

@@ -1,25 +0,0 @@
1
-package com.pathfinder.api;
2
-
3
-import java.rmi.Remote;
4
-import java.rmi.RemoteException;
5
-import java.util.List;
6
-import java.util.Properties;
7
-
8
-/**
9
- * Part of the external graph traversal API exposed by the routing team
10
- * and used by us (booking and tracking team).
11
- */
12
-public interface GraphTraversalService extends Remote {
13
-
14
-  /**
15
-   * @param originUnLocode      origin UN Locode
16
-   * @param destinationUnLocode destination UN Locode
17
-   * @param limitations         restrictions on the path selection, as key-value according to some API specification
18
-   * @return A list of transit paths
19
-   * @throws RemoteException RMI problem
20
-   */
21
-  List<TransitPath> findShortestPath(String originUnLocode,
22
-                                     String destinationUnLocode,
23
-                                     Properties limitations) throws RemoteException;
24
-
25
-}

+ 0
- 58
dddsample/src/main/java/com/pathfinder/api/TransitEdge.java Просмотреть файл

@@ -1,58 +0,0 @@
1
-package com.pathfinder.api;
2
-
3
-import java.io.Serializable;
4
-import java.util.Date;
5
-
6
-/**
7
- * Represents an edge in a path through a graph,
8
- * describing the route of a cargo.
9
- */
10
-public final class TransitEdge implements Serializable {
11
-
12
-  private final String voyageNumber;
13
-  private final String fromUnLocode;
14
-  private final String toUnLocode;
15
-  private final Date fromDate;
16
-  private final Date toDate;
17
-
18
-  /**
19
-   * Constructor.
20
-   *
21
-   * @param voyageNumber
22
-   * @param fromUnLocode
23
-   * @param toUnLocode
24
-   * @param fromDate
25
-   * @param toDate
26
-   */
27
-  public TransitEdge(final String voyageNumber,
28
-                     final String fromUnLocode,
29
-                     final String toUnLocode,
30
-                     final Date fromDate,
31
-                     final Date toDate) {
32
-    this.voyageNumber = voyageNumber;
33
-    this.fromUnLocode = fromUnLocode;
34
-    this.toUnLocode = toUnLocode;
35
-    this.fromDate = fromDate;
36
-    this.toDate = toDate;
37
-  }
38
-
39
-  public String getVoyageNumber() {
40
-    return voyageNumber;
41
-  }
42
-
43
-  public String getFromUnLocode() {
44
-    return fromUnLocode;
45
-  }
46
-
47
-  public String getToUnLocode() {
48
-    return toUnLocode;
49
-  }
50
-
51
-  public Date getFromDate() {
52
-    return fromDate;
53
-  }
54
-
55
-  public Date getToDate() {
56
-    return toDate;
57
-  }
58
-}

+ 0
- 29
dddsample/src/main/java/com/pathfinder/api/TransitPath.java Просмотреть файл

@@ -1,29 +0,0 @@
1
-package com.pathfinder.api;
2
-
3
-import java.io.Serializable;
4
-import java.util.Collections;
5
-import java.util.List;
6
-
7
-/**
8
- *
9
- */
10
-public final class TransitPath implements Serializable {
11
-
12
-  private final List<TransitEdge> transitEdges;
13
-
14
-  /**
15
-   * Constructor.
16
-   *
17
-   * @param transitEdges The legs for this itinerary.
18
-   */
19
-  public TransitPath(final List<TransitEdge> transitEdges) {
20
-    this.transitEdges = transitEdges;
21
-  }
22
-
23
-  /**
24
-   * @return An unmodifiable list DTOs.
25
-   */
26
-  public List<TransitEdge> getTransitEdges() {
27
-    return Collections.unmodifiableList(transitEdges);
28
-  }
29
-}

+ 0
- 7
dddsample/src/main/java/com/pathfinder/api/package.html Просмотреть файл

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	Public API for the pathfinder application.
5
-</p>
6
-</body>
7
-</html>

+ 0
- 27
dddsample/src/main/java/com/pathfinder/internal/GraphDAO.java Просмотреть файл

@@ -1,27 +0,0 @@
1
-package com.pathfinder.internal;
2
-
3
-import java.util.ArrayList;
4
-import java.util.Arrays;
5
-import java.util.List;
6
-import java.util.Random;
7
-
8
-public class GraphDAO {
9
-
10
-  private static final Random random = new Random();
11
-
12
-  public List<String> listLocations() {
13
-    return new ArrayList<String>(Arrays.asList(
14
-      "CNHKG", "AUMEL", "SESTO", "FIHEL", "USCHI", "JNTKO", "DEHAM", "CNSHA", "NLRTM", "SEGOT", "CNHGH", "USNYC", "USDAL"
15
-    ));
16
-  }
17
-
18
-  public String getVoyageNumber(String from, String to) {
19
-    final int i = random.nextInt(5);
20
-    if (i == 0) return "0100S";
21
-    if (i == 1) return "0200T";
22
-    if (i == 2) return "0300A";
23
-    if (i == 3) return "0301S";
24
-    return "0400S";
25
-  }
26
-
27
-}

+ 0
- 83
dddsample/src/main/java/com/pathfinder/internal/GraphTraversalServiceImpl.java Просмотреть файл

@@ -1,83 +0,0 @@
1
-package com.pathfinder.internal;
2
-
3
-import com.pathfinder.api.GraphTraversalService;
4
-import com.pathfinder.api.TransitEdge;
5
-import com.pathfinder.api.TransitPath;
6
-
7
-import java.util.*;
8
-
9
-public class GraphTraversalServiceImpl implements GraphTraversalService {
10
-
11
-  private GraphDAO dao;
12
-  private Random random;
13
-  private static final long ONE_MIN_MS = 1000 * 60;
14
-  private static final long ONE_DAY_MS = ONE_MIN_MS * 60 * 24;
15
-
16
-  public GraphTraversalServiceImpl(GraphDAO dao) {
17
-    this.dao = dao;
18
-    this.random = new Random();
19
-  }
20
-
21
-  public List<TransitPath> findShortestPath(final String originUnLocode,
22
-                                            final String destinationUnLocode,
23
-                                            final Properties limitations) {
24
-    Date date = nextDate(new Date());
25
-
26
-    List<String> allVertices = dao.listLocations();
27
-    allVertices.remove(originUnLocode);
28
-    allVertices.remove(destinationUnLocode);
29
-
30
-    final int candidateCount = getRandomNumberOfCandidates();
31
-    final List<TransitPath> candidates = new ArrayList<TransitPath>(candidateCount);
32
-
33
-    for (int i = 0; i < candidateCount; i++) {
34
-      allVertices = getRandomChunkOfLocations(allVertices);
35
-      final List<TransitEdge> transitEdges = new ArrayList<TransitEdge>(allVertices.size() - 1);
36
-      final String firstLegTo = allVertices.get(0);
37
-
38
-      Date fromDate = nextDate(date);
39
-      Date toDate = nextDate(fromDate);
40
-      date = nextDate(toDate);
41
-
42
-      transitEdges.add(new TransitEdge(
43
-        dao.getVoyageNumber(originUnLocode, firstLegTo),
44
-        originUnLocode, firstLegTo, fromDate, toDate));
45
-
46
-      for (int j = 0; j < allVertices.size() - 1; j++) {
47
-        final String curr = allVertices.get(j);
48
-        final String next = allVertices.get(j + 1);
49
-        fromDate = nextDate(date);
50
-        toDate = nextDate(fromDate);
51
-        date = nextDate(toDate);
52
-        transitEdges.add(new TransitEdge(dao.getVoyageNumber(curr, next), curr, next, fromDate, toDate));
53
-      }
54
-
55
-      final String lastLegFrom = allVertices.get(allVertices.size() - 1);
56
-      fromDate = nextDate(date);
57
-      toDate = nextDate(fromDate);
58
-      transitEdges.add(new TransitEdge(
59
-        dao.getVoyageNumber(lastLegFrom, destinationUnLocode),
60
-        lastLegFrom, destinationUnLocode, fromDate, toDate));
61
-
62
-      candidates.add(new TransitPath(transitEdges));
63
-    }
64
-
65
-    return candidates;
66
-  }
67
-
68
-  private Date nextDate(Date date) {
69
-    return new Date(date.getTime() + ONE_DAY_MS + (random.nextInt(1000) - 500) * ONE_MIN_MS);
70
-  }
71
-
72
-  private int getRandomNumberOfCandidates() {
73
-    return 3 + random.nextInt(3);
74
-  }
75
-
76
-  private List<String> getRandomChunkOfLocations(List<String> allLocations) {
77
-    Collections.shuffle(allLocations);
78
-    final int total = allLocations.size();
79
-    final int chunk = total > 4 ? 1 + new Random().nextInt(5) : total;
80
-    return allLocations.subList(0, chunk);
81
-  }
82
-
83
-}

+ 0
- 7
dddsample/src/main/java/com/pathfinder/internal/package.html Просмотреть файл

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	Internal parts of the pathfinder application.
5
-</p>
6
-</body>
7
-</html>

+ 0
- 15
dddsample/src/main/java/com/pathfinder/package.html Просмотреть файл

@@ -1,15 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	This is the pathfinder application context, which is separate from "our" application and context.
5
-	Our domain model with cargo, itinerary, handling event etc does not exist here.
6
-	The routing domain service implementation works against the API exposed by
7
-	this context.
8
-</p>
9
-
10
-<p>
11
-	It is not related to the core application at all, and is only part of this source tree for
12
-	developer convenience.
13
-</p>
14
-</body>
15
-</html>

+ 0
- 57
dddsample/src/main/java/se/citerus/dddsample/application/booking/BookingService.java Просмотреть файл

@@ -1,57 +0,0 @@
1
-package se.citerus.dddsample.application.booking;
2
-
3
-import se.citerus.dddsample.domain.model.cargo.Cargo;
4
-import se.citerus.dddsample.domain.model.cargo.Itinerary;
5
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
6
-import se.citerus.dddsample.domain.model.location.UnLocode;
7
-
8
-import java.util.Date;
9
-import java.util.List;
10
-
11
-/**
12
- * Cargo booking service.
13
- */
14
-public interface BookingService {
15
-
16
-  /**
17
-   * Registers a new cargo in the tracking system, not yet routed.
18
-   *
19
-   * @param origin          cargo origin
20
-   * @param destination     cargo destination
21
-   * @param arrivalDeadline arrival deadline
22
-   * @return Cargo tracking id
23
-   */
24
-  TrackingId bookNewCargo(UnLocode origin, UnLocode destination, Date arrivalDeadline);
25
-
26
-  /**
27
-   * Requests a list of itineraries describing possible routes for this cargo.
28
-   *
29
-   * @param trackingId cargo tracking id
30
-   * @return A list of possible itineraries for this cargo
31
-   */
32
-  List<Itinerary> requestPossibleRoutesForCargo(TrackingId trackingId);
33
-
34
-  /**
35
-   * @param itinerary  itinerary describing the selected route
36
-   * @param trackingId cargo tracking id
37
-   */
38
-  void assignCargoToRoute(Itinerary itinerary, TrackingId trackingId);
39
-
40
-  /**
41
-   * Changes the destination of a cargo.
42
-   *
43
-   * @param trackingId cargo tracking id
44
-   * @param unLocode   UN locode of new destination
45
-   */
46
-  void changeDestination(TrackingId trackingId, UnLocode unLocode);
47
-
48
-  /**
49
-   * Loads a cargo for (re-) routing.
50
-   * Locks the cargo for exclusive modification.
51
-   *
52
-   * @param trackingId tracking id
53
-   * @return The cargo.
54
-   */
55
-  Cargo loadCargoForRouting(TrackingId trackingId);
56
-
57
-}

+ 0
- 90
dddsample/src/main/java/se/citerus/dddsample/application/booking/BookingServiceImpl.java Просмотреть файл

@@ -1,90 +0,0 @@
1
-package se.citerus.dddsample.application.booking;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import org.apache.commons.logging.Log;
5
-import org.apache.commons.logging.LogFactory;
6
-import org.springframework.transaction.annotation.Transactional;
7
-import se.citerus.dddsample.domain.model.cargo.*;
8
-import se.citerus.dddsample.domain.model.location.Location;
9
-import se.citerus.dddsample.domain.model.location.LocationRepository;
10
-import se.citerus.dddsample.domain.model.location.UnLocode;
11
-import se.citerus.dddsample.domain.service.RoutingService;
12
-
13
-import java.util.Collections;
14
-import java.util.Date;
15
-import java.util.List;
16
-
17
-public final class BookingServiceImpl implements BookingService {
18
-
19
-  private final RoutingService routingService;
20
-  private final CargoFactory cargoFactory;
21
-  private final CargoRepository cargoRepository;
22
-  private final LocationRepository locationRepository;
23
-  private final Log logger = LogFactory.getLog(getClass());
24
-
25
-  public BookingServiceImpl(final RoutingService routingService,
26
-                            final CargoFactory cargoFactory,
27
-                            final CargoRepository cargoRepository,
28
-                            final LocationRepository locationRepository) {
29
-    this.routingService = routingService;
30
-    this.cargoFactory = cargoFactory;
31
-    this.cargoRepository = cargoRepository;
32
-    this.locationRepository = locationRepository;
33
-  }
34
-
35
-  @Override
36
-  @Transactional
37
-  public TrackingId bookNewCargo(final UnLocode originUnLocode,
38
-                                 final UnLocode destinationUnLocode,
39
-                                 final Date arrivalDeadline) {
40
-    final Cargo cargo = cargoFactory.newCargo(originUnLocode, destinationUnLocode, arrivalDeadline);
41
-    cargoRepository.store(cargo);
42
-    logger.info("Booked new cargo with tracking id " + cargo.trackingId().stringValue());
43
-
44
-    return cargo.trackingId();
45
-  }
46
-
47
-  @Override
48
-  @Transactional(readOnly = true)
49
-  public List<Itinerary> requestPossibleRoutesForCargo(final TrackingId trackingId) {
50
-    final Cargo cargo = cargoRepository.find(trackingId);
51
-
52
-    if (cargo == null) {
53
-      return Collections.emptyList();
54
-    }
55
-
56
-    return routingService.fetchRoutesForSpecification(cargo.routeSpecification());
57
-  }
58
-
59
-  @Override
60
-  @Transactional
61
-  public void assignCargoToRoute(final Itinerary itinerary, final TrackingId trackingId) {
62
-    final Cargo cargo = cargoRepository.find(trackingId);
63
-    Validate.notNull(cargo, "Can't assign itinerary to non-existing cargo " + trackingId);
64
-    cargo.assignToRoute(itinerary);
65
-    cargoRepository.store(cargo);
66
-
67
-    logger.info("Assigned cargo " + trackingId + " to new route");
68
-  }
69
-
70
-  @Override
71
-  @Transactional
72
-  public void changeDestination(final TrackingId trackingId, final UnLocode unLocode) {
73
-    final Cargo cargo = cargoRepository.find(trackingId);
74
-    Validate.notNull(cargo, "Can't change destination of non-existing cargo " + trackingId);
75
-    final Location newDestination = locationRepository.find(unLocode);
76
-
77
-    final RouteSpecification routeSpecification = cargo.routeSpecification().withDestination(newDestination);
78
-    cargo.specifyNewRoute(routeSpecification);
79
-
80
-    cargoRepository.store(cargo);
81
-    logger.info("Changed destination for cargo " + trackingId + " to " + routeSpecification.destination());
82
-  }
83
-
84
-  @Override
85
-  @Transactional(readOnly = true)
86
-  public Cargo loadCargoForRouting(final TrackingId trackingId) {
87
-    return cargoRepository.find(trackingId);
88
-  }
89
-
90
-}

+ 0
- 7
dddsample/src/main/java/se/citerus/dddsample/application/booking/package.html Просмотреть файл

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	Booking use cases.
5
-</p>
6
-</body>
7
-</html>

+ 0
- 59
dddsample/src/main/java/se/citerus/dddsample/application/event/CargoUpdater.java Просмотреть файл

@@ -1,59 +0,0 @@
1
-package se.citerus.dddsample.application.event;
2
-
3
-import org.apache.commons.logging.Log;
4
-import org.apache.commons.logging.LogFactory;
5
-import org.springframework.transaction.annotation.Transactional;
6
-import se.citerus.dddsample.domain.model.cargo.Cargo;
7
-import se.citerus.dddsample.domain.model.cargo.CargoRepository;
8
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
9
-import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
10
-import se.citerus.dddsample.domain.model.shared.EventSequenceNumber;
11
-import se.citerus.dddsample.domain.model.shared.HandlingActivity;
12
-
13
-public class CargoUpdater {
14
-
15
-  private SystemEvents systemEvents;
16
-  private CargoRepository cargoRepository;
17
-  private HandlingEventRepository handlingEventRepository;
18
-  private final Log logger = LogFactory.getLog(getClass());
19
-
20
-  public CargoUpdater(final SystemEvents systemEvents,
21
-                      final CargoRepository cargoRepository,
22
-                      final HandlingEventRepository handlingEventRepository) {
23
-    this.systemEvents = systemEvents;
24
-    this.cargoRepository = cargoRepository;
25
-    this.handlingEventRepository = handlingEventRepository;
26
-  }
27
-
28
-  @Transactional
29
-  public void updateCargo(final EventSequenceNumber eventSequenceNumber) {
30
-    final HandlingEvent handlingEvent = handlingEventRepository.find(eventSequenceNumber);
31
-    final HandlingActivity activity = handlingEvent.activity();
32
-    final Cargo cargo = handlingEvent.cargo();
33
-
34
-    cargo.handled(activity);
35
-
36
-    // TODO create domain events and deal with them as a result of the handling
37
-    /*
38
-    Here's an idea:
39
-
40
-    ResultOfHandling result = cargo.effectOf(activity);
41
-    cargo.apply(result);
42
-
43
-    or
44
-
45
-    cargo.handled(activity);
46
-    Delivery delivery = cargo.currentDelivery();
47
-    send all delivery.events();
48
-
49
-    */
50
-
51
-    cargoRepository.store(cargo);
52
-    systemEvents.notifyOfCargoUpdate(cargo);
53
-    logger.info("Updated cargo " + cargo);
54
-  }
55
-
56
-  CargoUpdater() {
57
-  }
58
-
59
-}

+ 0
- 43
dddsample/src/main/java/se/citerus/dddsample/application/event/ItineraryUpdater.java Просмотреть файл

@@ -1,43 +0,0 @@
1
-/**
2
- * Purpose
3
- * @author peter
4
- * @created 2009-aug-04
5
- * $Id$
6
- */
7
-package se.citerus.dddsample.application.event;
8
-
9
-import org.apache.commons.logging.Log;
10
-import org.apache.commons.logging.LogFactory;
11
-import org.springframework.transaction.annotation.Transactional;
12
-import se.citerus.dddsample.domain.model.cargo.Cargo;
13
-import se.citerus.dddsample.domain.model.cargo.CargoRepository;
14
-import se.citerus.dddsample.domain.model.cargo.Itinerary;
15
-import se.citerus.dddsample.domain.model.voyage.Voyage;
16
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
17
-import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
18
-
19
-import java.util.List;
20
-
21
-public final class ItineraryUpdater {
22
-
23
-  private VoyageRepository voyageRepository;
24
-  private CargoRepository cargoRepository;
25
-  private static final Log LOG = LogFactory.getLog(ItineraryUpdater.class);
26
-
27
-  public ItineraryUpdater(final VoyageRepository voyageRepository, final CargoRepository cargoRepository) {
28
-    this.voyageRepository = voyageRepository;
29
-    this.cargoRepository = cargoRepository;
30
-  }
31
-
32
-  @Transactional
33
-  public void updateItineraries(final VoyageNumber voyageNumber) {
34
-    final Voyage voyage = voyageRepository.find(voyageNumber);
35
-    final List<Cargo> affectedCargos = cargoRepository.findCargosOnVoyage(voyage);
36
-    for (final Cargo cargo : affectedCargos) {
37
-      final Itinerary newItinerary = cargo.itinerary().withRescheduledVoyage(voyage);
38
-      cargo.assignToRoute(newItinerary);
39
-      LOG.info("Updated itinerary of cargo " + cargo);
40
-    }
41
-  }
42
-
43
-}

+ 0
- 37
dddsample/src/main/java/se/citerus/dddsample/application/event/MisdirectedNotifier.java Просмотреть файл

@@ -1,37 +0,0 @@
1
-/**
2
- * Purpose
3
- * @author peter
4
- * @created 2009-aug-03
5
- * $Id$
6
- */
7
-package se.citerus.dddsample.application.event;
8
-
9
-import org.apache.commons.logging.Log;
10
-import org.apache.commons.logging.LogFactory;
11
-import org.springframework.transaction.annotation.Transactional;
12
-import se.citerus.dddsample.domain.model.cargo.Cargo;
13
-import se.citerus.dddsample.domain.model.cargo.CargoRepository;
14
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
15
-
16
-public class MisdirectedNotifier {
17
-
18
-  private CargoRepository cargoRepository;
19
-
20
-  private static final Log LOG = LogFactory.getLog(MisdirectedNotifier.class);
21
-
22
-  public MisdirectedNotifier(final CargoRepository cargoRepository) {
23
-    this.cargoRepository = cargoRepository;
24
-  }
25
-
26
-  @Transactional
27
-  public void alertIfMisdirected(final TrackingId trackingId) {
28
-    final Cargo cargo = cargoRepository.find(trackingId);
29
-
30
-    if (cargo.isMisdirected()) {
31
-      LOG.info("Cargo " + cargo + " is misdirected!");
32
-    }
33
-  }
34
-
35
-  MisdirectedNotifier() {
36
-  }
37
-}

+ 0
- 40
dddsample/src/main/java/se/citerus/dddsample/application/event/ReadyToClaimNotfier.java Просмотреть файл

@@ -1,40 +0,0 @@
1
-/**
2
- * Purpose
3
- * @author peter
4
- * @created 2009-aug-03
5
- * $Id$
6
- */
7
-package se.citerus.dddsample.application.event;
8
-
9
-import org.apache.commons.logging.Log;
10
-import org.apache.commons.logging.LogFactory;
11
-import org.springframework.transaction.annotation.Transactional;
12
-import se.citerus.dddsample.domain.model.cargo.Cargo;
13
-import se.citerus.dddsample.domain.model.cargo.CargoRepository;
14
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
15
-
16
-public class ReadyToClaimNotfier {
17
-
18
-  private CargoRepository cargoRepository;
19
-  private static final Log LOG = LogFactory.getLog(ReadyToClaimNotfier.class);
20
-
21
-  public ReadyToClaimNotfier(final CargoRepository cargoRepository) {
22
-    this.cargoRepository = cargoRepository;
23
-  }
24
-
25
-  @Transactional
26
-  public void alertIfReadyToClaim(final TrackingId trackingId) {
27
-    final Cargo cargo = cargoRepository.find(trackingId);
28
-                                                      
29
-    if (cargo.isReadyToClaim()) {
30
-      /**
31
-       * At this point, a real system would probably send an email or SMS
32
-       * or something, but we simply log a message.
33
-       */
34
-      LOG.info("Cargo " + cargo + " is ready to be claimed");
35
-    }
36
-  }
37
-
38
-  ReadyToClaimNotfier() {
39
-  }
40
-}

+ 0
- 29
dddsample/src/main/java/se/citerus/dddsample/application/event/SystemEvents.java Просмотреть файл

@@ -1,29 +0,0 @@
1
-package se.citerus.dddsample.application.event;
2
-
3
-import se.citerus.dddsample.domain.model.cargo.Cargo;
4
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
5
-
6
-/**
7
- * This interface provides a way to let other parts
8
- * of the system know about events that have occurred.
9
- * <p/>
10
- * It may be implemented synchronously or asynchronously, using
11
- * for example JMS.
12
- */
13
-public interface SystemEvents {
14
-
15
-  /**
16
-   * A cargo has been handled.
17
-   *
18
-   * @param event handling event
19
-   */
20
-  void notifyOfHandlingEvent(HandlingEvent event);
21
-
22
-  /**
23
-   * Cargo delivery has been updated.
24
-   *
25
-   * @param cargo cargo
26
-   */
27
-  void notifyOfCargoUpdate(Cargo cargo);
28
-
29
-}

+ 0
- 7
dddsample/src/main/java/se/citerus/dddsample/application/event/package.html Просмотреть файл

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	Event/message driven application services.
5
-</p>
6
-</body>
7
-</html>

+ 0
- 35
dddsample/src/main/java/se/citerus/dddsample/application/handling/HandlingEventService.java Просмотреть файл

@@ -1,35 +0,0 @@
1
-package se.citerus.dddsample.application.handling;
2
-
3
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
4
-import se.citerus.dddsample.domain.model.handling.CannotCreateHandlingEventException;
5
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
6
-import se.citerus.dddsample.domain.model.location.UnLocode;
7
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
8
-
9
-import java.util.Date;
10
-
11
-/**
12
- * Handling event service.
13
- */
14
-public interface HandlingEventService {
15
-
16
-  /**
17
-   * Registers a handling event in the system, and notifies interested
18
-   * parties that a cargo has been handled.
19
-   *
20
-   * @param completionTime when the event was completed
21
-   * @param trackingId     cargo tracking id
22
-   * @param voyageNumber   voyage number
23
-   * @param unLocode       UN locode for the location where the event occurred
24
-   * @param type           type of event
25
-   * @throws se.citerus.dddsample.domain.model.handling.CannotCreateHandlingEventException
26
-   *          if a handling event that represents an actual event that's relevant to a cargo we're tracking
27
-   *          can't be created from the parameters
28
-   */
29
-  void registerHandlingEvent(Date completionTime,
30
-                             TrackingId trackingId,
31
-                             VoyageNumber voyageNumber,
32
-                             UnLocode unLocode,
33
-                             HandlingEvent.Type type) throws CannotCreateHandlingEventException;
34
-
35
-}

+ 0
- 60
dddsample/src/main/java/se/citerus/dddsample/application/handling/HandlingEventServiceImpl.java Просмотреть файл

@@ -1,60 +0,0 @@
1
-package se.citerus.dddsample.application.handling;
2
-
3
-import org.apache.commons.logging.Log;
4
-import org.apache.commons.logging.LogFactory;
5
-import org.springframework.transaction.annotation.Transactional;
6
-import se.citerus.dddsample.application.event.SystemEvents;
7
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
8
-import se.citerus.dddsample.domain.model.handling.CannotCreateHandlingEventException;
9
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
10
-import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
11
-import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
12
-import se.citerus.dddsample.domain.model.location.UnLocode;
13
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
14
-
15
-import java.util.Date;
16
-
17
-public final class HandlingEventServiceImpl implements HandlingEventService {
18
-
19
-  private final SystemEvents systemEvents;
20
-  private final HandlingEventRepository handlingEventRepository;
21
-  private final HandlingEventFactory handlingEventFactory;
22
-  private final Log logger = LogFactory.getLog(HandlingEventServiceImpl.class);
23
-
24
-  public HandlingEventServiceImpl(final HandlingEventRepository handlingEventRepository,
25
-                                  final SystemEvents systemEvents,
26
-                                  final HandlingEventFactory handlingEventFactory) {
27
-    this.handlingEventRepository = handlingEventRepository;
28
-    this.systemEvents = systemEvents;
29
-    this.handlingEventFactory = handlingEventFactory;
30
-  }
31
-
32
-  @Override
33
-  @Transactional(rollbackFor = CannotCreateHandlingEventException.class)
34
-  public void registerHandlingEvent(final Date completionTime,
35
-                                    final TrackingId trackingId,
36
-                                    final VoyageNumber voyageNumber,
37
-                                    final UnLocode unLocode,
38
-                                    final HandlingEvent.Type type) throws CannotCreateHandlingEventException {
39
-
40
-    final Date registrationTime = new Date();
41
-    /* Using a factory to create a HandlingEvent (aggregate). This is where
42
-       it is determined wether the incoming data, the attempt, actually is capable
43
-       of representing a real handling event. */
44
-    final HandlingEvent event = handlingEventFactory.createHandlingEvent(
45
-      registrationTime, completionTime, trackingId, voyageNumber, unLocode, type
46
-    );
47
-
48
-    /* Store the new handling event, which updates the persistent
49
-       state of the handling event aggregate (but not the cargo aggregate -
50
-       that happens asynchronously!)
51
-     */
52
-    handlingEventRepository.store(event);
53
-
54
-    /* Publish an event stating that a cargo has been handled. */
55
-    systemEvents.notifyOfHandlingEvent(event);
56
-
57
-    logger.info("Registered handling event");
58
-  }
59
-
60
-}

+ 0
- 7
dddsample/src/main/java/se/citerus/dddsample/application/handling/package.html Просмотреть файл

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	Handling use cases.
5
-</p>
6
-</body>
7
-</html>

+ 0
- 18
dddsample/src/main/java/se/citerus/dddsample/application/package.html Просмотреть файл

@@ -1,18 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	This is the application layer: code that's needed for the application to
5
-	performs its tasks. It defines, or is defined by, use cases.
6
-</p>
7
-
8
-<p>
9
-	It is thin in terms of knowledge of domain business logic,
10
-	although it may be large in terms of lines of code.
11
-	It coordinates the domain layer objects to perform the actual tasks.
12
-</p>
13
-
14
-<p>
15
-	This layer is suitable for spanning transactions, security checks and high-level logging.
16
-</p>
17
-</body>
18
-</html>

+ 0
- 38
dddsample/src/main/java/se/citerus/dddsample/application/util/DateTestUtil.java Просмотреть файл

@@ -1,38 +0,0 @@
1
-package se.citerus.dddsample.application.util;
2
-
3
-import java.text.ParseException;
4
-import java.text.SimpleDateFormat;
5
-import java.util.Date;
6
-
7
-/**
8
- * A few utils for working with Date in tests.
9
- */
10
-public final class DateTestUtil {
11
-
12
-  /**
13
-   * @param date date string as yyyy-MM-dd
14
-   * @return Date representation
15
-   */
16
-  public static Date toDate(final String date) {
17
-    return toDate(date, "00:00.00.000");
18
-  }
19
-
20
-  /**
21
-   * @param date date string as yyyy-MM-dd
22
-   * @param time time string as HH:mm
23
-   * @return Date representation
24
-   */
25
-  public static Date toDate(final String date, final String time) {
26
-    try {
27
-      return new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(date + " " + time);
28
-    } catch (ParseException e) {
29
-      throw new RuntimeException(e);
30
-    }
31
-  }
32
-
33
-  /**
34
-   * Prevent instantiation.
35
-   */
36
-  private DateTestUtil() {
37
-  }
38
-}

+ 0
- 334
dddsample/src/main/java/se/citerus/dddsample/application/util/SampleDataGenerator.java Просмотреть файл

@@ -1,334 +0,0 @@
1
-package se.citerus.dddsample.application.util;
2
-
3
-import org.hibernate.SessionFactory;
4
-import org.hibernate.classic.Session;
5
-import org.springframework.beans.factory.BeanFactoryUtils;
6
-import org.springframework.jdbc.core.JdbcTemplate;
7
-import org.springframework.transaction.PlatformTransactionManager;
8
-import org.springframework.transaction.TransactionStatus;
9
-import org.springframework.transaction.support.TransactionCallbackWithoutResult;
10
-import org.springframework.transaction.support.TransactionTemplate;
11
-import org.springframework.web.context.WebApplicationContext;
12
-import org.springframework.web.context.support.WebApplicationContextUtils;
13
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
14
-import se.citerus.dddsample.domain.model.cargo.*;
15
-import se.citerus.dddsample.domain.model.handling.CannotCreateHandlingEventException;
16
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
17
-import se.citerus.dddsample.domain.model.handling.HandlingEventFactory;
18
-import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
19
-import se.citerus.dddsample.domain.model.location.Location;
20
-import se.citerus.dddsample.domain.model.location.LocationRepository;
21
-import se.citerus.dddsample.domain.model.location.SampleLocations;
22
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
23
-import static se.citerus.dddsample.domain.model.voyage.SampleVoyages.*;
24
-import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
25
-
26
-import javax.servlet.ServletContextEvent;
27
-import javax.servlet.ServletContextListener;
28
-import java.sql.Timestamp;
29
-import java.text.ParseException;
30
-import java.text.SimpleDateFormat;
31
-import static java.util.Arrays.asList;
32
-import java.util.Date;
33
-
34
-/**
35
- * Provides sample data.
36
- */
37
-public class SampleDataGenerator implements ServletContextListener {
38
-
39
-  private static final Timestamp base;
40
-
41
-  static {
42
-    try {
43
-      Date date = new SimpleDateFormat("yyyy-MM-dd").parse("2008-01-01");
44
-      base = new Timestamp(date.getTime() - 1000L * 60 * 60 * 24 * 100);
45
-    } catch (ParseException e) {
46
-      throw new RuntimeException(e);
47
-    }
48
-  }
49
-
50
-  private static void loadHandlingEventData(JdbcTemplate jdbcTemplate) {
51
-    String handlingEventSql =
52
-      "insert into HandlingEvent (sequence_number, completionTime, registrationTime, type, location_id, voyage_id, cargo_id) " +
53
-        "values (?, ?, ?, ?, ?, ?, ?)";
54
-
55
-    Object[][] handlingEventArgs = {
56
-      //XYZ (SESTO-FIHEL-DEHAM-CNHKG-JPTOK-AUMEL)
57
-      {1, ts(0), ts((0)), "RECEIVE", 1, null, 1},
58
-      {2, ts((4)), ts((5)), "LOAD", 1, 1, 1},
59
-      {3, ts((14)), ts((14)), "UNLOAD", 5, 1, 1},
60
-      {4, ts((15)), ts((15)), "LOAD", 5, 1, 1},
61
-      {5, ts((30)), ts((30)), "UNLOAD", 6, 1, 1},
62
-      {6, ts((33)), ts((33)), "LOAD", 6, 1, 1},
63
-      {7, ts((34)), ts((34)), "UNLOAD", 3, 1, 1},
64
-      {8, ts((60)), ts((60)), "LOAD", 3, 1, 1},
65
-      {9, ts((70)), ts((71)), "UNLOAD", 4, 1, 1},
66
-      {10, ts((75)), ts((75)), "LOAD", 4, 1, 1},
67
-      {11, ts((88)), ts((88)), "UNLOAD", 2, 1, 1},
68
-      {12, ts((100)), ts((102)), "CLAIM", 2, null, 1},
69
-
70
-      //ZYX (AUMEL - USCHI - DEHAM -)
71
-      {13, ts((200)), ts((201)), "RECEIVE", 2, null, 3},
72
-      {14, ts((202)), ts((202)), "LOAD", 2, 2, 3},
73
-      {15, ts((208)), ts((208)), "UNLOAD", 7, 2, 3},
74
-      {16, ts((212)), ts((212)), "LOAD", 7, 2, 3},
75
-      {17, ts((230)), ts((230)), "UNLOAD", 6, 2, 3},
76
-      {18, ts((235)), ts((235)), "LOAD", 6, 2, 3},
77
-
78
-      //ABC
79
-      {19, ts((20)), ts((21)), "CLAIM", 2, null, 2},
80
-
81
-      //CBA
82
-      {20, ts((0)), ts((1)), "RECEIVE", 2, null, 4},
83
-      {21, ts((10)), ts((11)), "LOAD", 2, 2, 4},
84
-      {22, ts((20)), ts((21)), "UNLOAD", 7, 2, 4},
85
-
86
-      //FGH
87
-      {23, ts(100), ts(160), "RECEIVE", 3, null, 5},
88
-      {24, ts(150), ts(110), "LOAD", 3, 3, 5},
89
-
90
-      // JKL
91
-      {25, ts(200), ts(220), "RECEIVE", 6, null, 6},
92
-      {26, ts(300), ts(330), "LOAD", 6, 3, 6},
93
-      {27, ts(400), ts(440), "UNLOAD", 5, 3, 6}  // Unexpected event
94
-    };
95
-    executeUpdate(jdbcTemplate, handlingEventSql, handlingEventArgs);
96
-  }
97
-
98
-  private static void loadCarrierMovementData(JdbcTemplate jdbcTemplate) {
99
-    String voyageSql =
100
-      "insert into Voyage (id, voyage_number) values (?, ?)";
101
-    Object[][] voyageArgs = {
102
-      {1, "0101"},
103
-      {2, "0202"},
104
-      {3, "0303"}
105
-    };
106
-    executeUpdate(jdbcTemplate, voyageSql, voyageArgs);
107
-
108
-    String carrierMovementSql =
109
-      "insert into CarrierMovement (id, voyage_id, departure_location_id, arrival_location_id, departure_time, arrival_time, cm_index) " +
110
-        "values (?,?,?,?,?,?,?)";
111
-
112
-    Object[][] carrierMovementArgs = {
113
-      // SESTO - FIHEL - DEHAM - CNHKG - JPTOK - AUMEL (voyage 0101)
114
-      {1, 1, 1, 5, ts(1), ts(2), 0},
115
-      {2, 1, 5, 6, ts(1), ts(2), 1},
116
-      {3, 1, 6, 3, ts(1), ts(2), 2},
117
-      {4, 1, 3, 4, ts(1), ts(2), 3},
118
-      {5, 1, 4, 2, ts(1), ts(2), 4},
119
-
120
-      // AUMEL - USCHI - DEHAM - SESTO - FIHEL (voyage 0202)
121
-      {7, 2, 2, 7, ts(1), ts(2), 0},
122
-      {8, 2, 7, 6, ts(1), ts(2), 1},
123
-      {9, 2, 6, 1, ts(1), ts(2), 2},
124
-      {6, 2, 1, 5, ts(1), ts(2), 3},
125
-
126
-      // CNHKG - AUMEL - FIHEL - DEHAM - SESTO - USCHI - JPTKO (voyage 0303)
127
-      {10, 3, 3, 2, ts(1), ts(2), 0},
128
-      {11, 3, 2, 5, ts(1), ts(2), 1},
129
-      {12, 3, 6, 1, ts(1), ts(2), 2},
130
-      {13, 3, 1, 7, ts(1), ts(2), 3},
131
-      {14, 3, 7, 4, ts(1), ts(2), 4}
132
-    };
133
-    executeUpdate(jdbcTemplate, carrierMovementSql, carrierMovementArgs);
134
-  }
135
-
136
-  private static void loadCargoData(JdbcTemplate jdbcTemplate) {
137
-    String cargoSql =
138
-      "insert into Cargo (id, tracking_id, spec_origin_id, spec_destination_id, spec_arrival_deadline, calculated_at) " +
139
-        "values (?, ?, ?, ?, ?, ?)";
140
-
141
-    Object[][] cargoArgs = {
142
-      {1, "XYZ", 1, 2, ts(10), ts(100)},
143
-      {2, "ABC", 1, 5, ts(20), ts(100)},
144
-      {3, "ZYX", 2, 1, ts(30), ts(100)},
145
-      {4, "CBA", 5, 1, ts(40), ts(100)},
146
-      {5, "FGH", 3, 5, ts(50), ts(100)},  // Cargo origin differs from spec origin
147
-      {6, "JKL", 6, 4, ts(60), ts(100)}
148
-    };
149
-    executeUpdate(jdbcTemplate, cargoSql, cargoArgs);
150
-  }
151
-
152
-  private static void loadLocationData(JdbcTemplate jdbcTemplate) {
153
-    String locationSql =
154
-      "insert into Location (id, unlocode, name) " +
155
-        "values (?, ?, ?)";
156
-
157
-    Object[][] locationArgs = {
158
-      {1, "SESTO", "Stockholm"},
159
-      {2, "AUMEL", "Melbourne"},
160
-      {3, "CNHKG", "Hongkong"},
161
-      {4, "JPTOK", "Tokyo"},
162
-      {5, "FIHEL", "Helsinki"},
163
-      {6, "DEHAM", "Hamburg"},
164
-      {7, "USCHI", "Chicago"}
165
-    };
166
-    executeUpdate(jdbcTemplate, locationSql, locationArgs);
167
-  }
168
-
169
-  private static void loadItineraryData(JdbcTemplate jdbcTemplate) {
170
-    String legSql =
171
-      "insert into Leg (id, cargo_id, voyage_id, load_location_id, unload_location_id, load_time, unload_time, leg_index) " +
172
-        "values (?,?,?,?,?,?,?,?)";
173
-
174
-    Object[][] legArgs = {
175
-      // Cargo 5: Hongkong - Melbourne - Stockholm - Helsinki
176
-      {1, 5, 1, 3, 2, ts(1), ts(2), 0},
177
-      {2, 5, 1, 2, 1, ts(3), ts(4), 1},
178
-      {3, 5, 1, 1, 5, ts(4), ts(5), 2},
179
-      // Cargo 6: Hamburg - Stockholm - Chicago - Tokyo
180
-      {4, 6, 2, 6, 1, ts(1), ts(2), 0},
181
-      {5, 6, 2, 1, 7, ts(3), ts(4), 1},
182
-      {6, 6, 2, 7, 4, ts(5), ts(6), 2}
183
-    };
184
-    executeUpdate(jdbcTemplate, legSql, legArgs);
185
-  }
186
-
187
-  public void contextInitialized(ServletContextEvent event) {
188
-    WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext());
189
-    PlatformTransactionManager transactionManager = (PlatformTransactionManager) BeanFactoryUtils.beanOfType(context, PlatformTransactionManager.class);
190
-    TransactionTemplate tt = new TransactionTemplate(transactionManager);
191
-    //loadSampleData(new JdbcTemplate(dataSource), tt);
192
-
193
-
194
-    SessionFactory sf = (SessionFactory) BeanFactoryUtils.beanOfType(context, SessionFactory.class);
195
-    HandlingEventFactory handlingEventFactory = new HandlingEventFactory(
196
-      getBean(context, CargoRepository.class),
197
-      getBean(context, VoyageRepository.class),
198
-      getBean(context, LocationRepository.class));
199
-    loadHibernateData(tt, sf, handlingEventFactory, getBean(context, HandlingEventRepository.class));
200
-  }
201
-
202
-  private <T> T getBean(WebApplicationContext context, Class<T> cls) {
203
-    //noinspection unchecked
204
-    return (T) BeanFactoryUtils.beanOfType(context, cls);
205
-  }
206
-
207
-  public static void loadHibernateData(TransactionTemplate tt, final SessionFactory sf, final HandlingEventFactory handlingEventFactory, final HandlingEventRepository handlingEventRepository) {
208
-    tt.execute(new TransactionCallbackWithoutResult() {
209
-      @Override
210
-      protected void doInTransactionWithoutResult(TransactionStatus status) {
211
-        Session session = sf.getCurrentSession();
212
-
213
-        for (Location location : SampleLocations.getAll()) {
214
-          session.save(location);
215
-        }
216
-
217
-        session.save(HONGKONG_TO_NEW_YORK);
218
-        session.save(NEW_YORK_TO_DALLAS);
219
-        session.save(DALLAS_TO_HELSINKI);
220
-        session.save(HELSINKI_TO_HONGKONG);
221
-        session.save(DALLAS_TO_HELSINKI_ALT);
222
-
223
-        RouteSpecification routeSpecification = new RouteSpecification(HONGKONG, HELSINKI, toDate("2009-03-15"));
224
-        TrackingId trackingId = new TrackingId("ABC123");
225
-        Cargo abc123 = new Cargo(trackingId, routeSpecification);
226
-
227
-        Itinerary itinerary = new Itinerary(asList(
228
-          new Leg(HONGKONG_TO_NEW_YORK, HONGKONG, NEWYORK, toDate("2009-03-02"), toDate("2009-03-05")),
229
-          new Leg(NEW_YORK_TO_DALLAS, NEWYORK, DALLAS, toDate("2009-03-06"), toDate("2009-03-08")),
230
-          new Leg(DALLAS_TO_HELSINKI, DALLAS, HELSINKI, toDate("2009-03-09"), toDate("2009-03-12"))
231
-        ));
232
-        abc123.assignToRoute(itinerary);
233
-
234
-        session.save(abc123);
235
-
236
-        try {
237
-          HandlingEvent event1 = handlingEventFactory.createHandlingEvent(
238
-            new Date(), toDate("2009-03-01"), trackingId, null, HONGKONG.unLocode(), HandlingEvent.Type.RECEIVE
239
-          );
240
-          session.save(event1);
241
-
242
-          HandlingEvent event2 = handlingEventFactory.createHandlingEvent(
243
-            new Date(), toDate("2009-03-02"), trackingId, HONGKONG_TO_NEW_YORK.voyageNumber(), HONGKONG.unLocode(), HandlingEvent.Type.LOAD
244
-          );
245
-          session.save(event2);
246
-
247
-          HandlingEvent event3 = handlingEventFactory.createHandlingEvent(
248
-            new Date(), toDate("2009-03-05"), trackingId, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.UNLOAD
249
-          );
250
-          session.save(event3);
251
-        } catch (CannotCreateHandlingEventException e) {
252
-          throw new RuntimeException(e);
253
-        }
254
-
255
-        final HandlingEvent handlingEvent = handlingEventRepository.mostRecentHandling(abc123);
256
-        abc123.handled(handlingEvent.activity());
257
-        session.update(abc123);
258
-
259
-        // Cargo JKL567
260
-
261
-        RouteSpecification routeSpecification1 = new RouteSpecification(HANGZOU, STOCKHOLM, toDate("2009-03-18"));
262
-        TrackingId trackingId1 = new TrackingId("JKL567");
263
-        Cargo jkl567 = new Cargo(trackingId1, routeSpecification1);
264
-
265
-        Itinerary itinerary1 = new Itinerary(asList(
266
-          new Leg(HONGKONG_TO_NEW_YORK, HANGZOU, NEWYORK, toDate("2009-03-03"), toDate("2009-03-05")),
267
-          new Leg(NEW_YORK_TO_DALLAS, NEWYORK, DALLAS, toDate("2009-03-06"), toDate("2009-03-08")),
268
-          new Leg(DALLAS_TO_HELSINKI, DALLAS, STOCKHOLM, toDate("2009-03-09"), toDate("2009-03-11"))
269
-        ));
270
-        jkl567.assignToRoute(itinerary1);
271
-
272
-        session.save(jkl567);
273
-
274
-        try {
275
-          HandlingEvent event1 = handlingEventFactory.createHandlingEvent(
276
-            new Date(), toDate("2009-03-01"), trackingId1, null, HANGZOU.unLocode(), HandlingEvent.Type.RECEIVE
277
-          );
278
-          session.save(event1);
279
-
280
-          HandlingEvent event2 = handlingEventFactory.createHandlingEvent(
281
-            new Date(), toDate("2009-03-03"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), HANGZOU.unLocode(), HandlingEvent.Type.LOAD
282
-          );
283
-          session.save(event2);
284
-
285
-          HandlingEvent event3 = handlingEventFactory.createHandlingEvent(
286
-            new Date(), toDate("2009-03-05"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.UNLOAD
287
-          );
288
-          session.save(event3);
289
-
290
-          HandlingEvent event4 = handlingEventFactory.createHandlingEvent(
291
-            new Date(), toDate("2009-03-06"), trackingId1, HONGKONG_TO_NEW_YORK.voyageNumber(), NEWYORK.unLocode(), HandlingEvent.Type.LOAD
292
-          );
293
-          session.save(event4);
294
-
295
-        } catch (CannotCreateHandlingEventException e) {
296
-          throw new RuntimeException(e);
297
-        }
298
-
299
-        HandlingEvent handlingEvent1 = handlingEventRepository.mostRecentHandling(jkl567);
300
-        jkl567.handled(handlingEvent1.activity());
301
-        session.update(jkl567);
302
-      }
303
-    });
304
-  }
305
-
306
-  public void contextDestroyed(ServletContextEvent event) {
307
-  }
308
-
309
-  public static void loadSampleData(final JdbcTemplate jdbcTemplate, TransactionTemplate transactionTemplate) {
310
-    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
311
-      protected void doInTransactionWithoutResult(TransactionStatus status) {
312
-        loadLocationData(jdbcTemplate);
313
-        loadCarrierMovementData(jdbcTemplate);
314
-        loadCargoData(jdbcTemplate);
315
-        loadItineraryData(jdbcTemplate);
316
-        loadHandlingEventData(jdbcTemplate);
317
-      }
318
-    });
319
-  }
320
-
321
-  private static void executeUpdate(JdbcTemplate jdbcTemplate, String sql, Object[][] args) {
322
-    for (Object[] arg : args) {
323
-      jdbcTemplate.update(sql, arg);
324
-    }
325
-  }
326
-
327
-  private static Timestamp ts(int hours) {
328
-    return new Timestamp(base.getTime() + 1000L * 60 * 60 * hours);
329
-  }
330
-
331
-  public static Date offset(int hours) {
332
-    return new Date(ts(hours).getTime());
333
-  }
334
-}

+ 0
- 7
dddsample/src/main/java/se/citerus/dddsample/application/util/package.html Просмотреть файл

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	Various utilities.
5
-</p>
6
-</body>
7
-</html>

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

@@ -1,220 +0,0 @@
1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
5
-import se.citerus.dddsample.domain.model.location.CustomsZone;
6
-import se.citerus.dddsample.domain.model.location.Location;
7
-import se.citerus.dddsample.domain.model.shared.HandlingActivity;
8
-import se.citerus.dddsample.domain.model.voyage.Voyage;
9
-import se.citerus.dddsample.domain.shared.DomainObjectUtils;
10
-import se.citerus.dddsample.domain.shared.Entity;
11
-
12
-import java.util.Date;
13
-
14
-/**
15
- * A Cargo. This is the central class in the domain model,
16
- * and it is the root of the Cargo-Itinerary-Leg-Delivery-RouteSpecification aggregate.
17
- * <p/>
18
- * A cargo is identified by a unique tracking id, and it always has an origin
19
- * and a route specification. The life cycle of a cargo begins with the booking procedure,
20
- * when the tracking id is assigned. During a (short) period of time, between booking
21
- * and initial routing, the cargo has no itinerary.
22
- * <p/>
23
- * The booking clerk requests a list of possible routes, matching the route specification,
24
- * and assigns the cargo to one route. The route to which a cargo is assigned is described
25
- * by an itinerary.
26
- * <p/>
27
- * A cargo can be re-routed during transport, on demand of the customer, in which case
28
- * a new route is specified for the cargo and a new route is requested. The old itinerary,
29
- * being a value object, is discarded and a new one is attached.
30
- * <p/>
31
- * It may also happen that a cargo is accidentally misrouted, which should notify the proper
32
- * personnel and also trigger a re-routing procedure.
33
- * <p/>
34
- * When a cargo is handled, the status of the delivery changes. Everything about the delivery
35
- * of the cargo is contained in the Delivery value object, which is replaced whenever a cargo
36
- * is handled by an asynchronous event triggered by the registration of the handling event.
37
- * <p/>
38
- * The delivery can also be affected by routing changes, i.e. when a the route specification
39
- * changes, or the cargo is assigned to a new route. In that case, the delivery update is performed
40
- * synchronously within the cargo aggregate.
41
- * <p/>
42
- * The life cycle of a cargo ends when the cargo is claimed by the customer.
43
- * <p/>
44
- * The cargo aggregate, and the entre domain model, is built to solve the problem
45
- * of booking and tracking cargo. All important business rules for determining whether
46
- * or not a cargo is misdirected, what the current status of the cargo is (on board carrier,
47
- * in port etc), are captured in this aggregate.
48
- */
49
-public class Cargo implements Entity<Cargo> {
50
-
51
-  private TrackingId trackingId;
52
-  private RouteSpecification routeSpecification;
53
-  private Itinerary itinerary;
54
-  private Delivery delivery;
55
-  private Projections projections;
56
-
57
-  public Cargo(final TrackingId trackingId, final RouteSpecification routeSpecification) {
58
-    Validate.notNull(trackingId, "Tracking ID is required");
59
-    Validate.notNull(routeSpecification, "Route specification is required");
60
-
61
-    this.trackingId = trackingId;
62
-    this.routeSpecification = routeSpecification;
63
-    this.delivery = Delivery.initial();
64
-    this.projections = new Projections(delivery, itinerary, routeSpecification);
65
-  }
66
-
67
-  /**
68
-   * The tracking id is the identity of this entity, and is unique.
69
-   *
70
-   * @return Tracking id.
71
-   */
72
-  public TrackingId trackingId() {
73
-    return trackingId;
74
-  }
75
-
76
-  /**
77
-   * @return The itinerary. Never null.
78
-   */
79
-  public Itinerary itinerary() {
80
-    return DomainObjectUtils.nullSafe(this.itinerary, Itinerary.EMPTY_ITINERARY);
81
-  }
82
-
83
-  /**
84
-   * @return The route specification.
85
-   */
86
-  public RouteSpecification routeSpecification() {
87
-    return routeSpecification;
88
-  }
89
-
90
-  public Date estimatedTimeOfArrival() {
91
-    return projections.estimatedTimeOfArrival();
92
-  }
93
-
94
-  public HandlingActivity nextExpectedActivity() {
95
-    return projections.nextExpectedActivity();
96
-  }
97
-
98
-  public boolean isMisdirected() {
99
-    return delivery.isMisdirected(itinerary, routeSpecification);
100
-  }
101
-
102
-  public TransportStatus transportStatus() {
103
-    return delivery.transportStatus();
104
-  }
105
-
106
-  public RoutingStatus routingStatus() {
107
-    return delivery.routingStatus(itinerary, routeSpecification);
108
-  }
109
-
110
-  public Voyage currentVoyage() {
111
-    return delivery.currentVoyage();
112
-  }
113
-
114
-  public Location lastKnownLocation() {
115
-    return delivery.lastKnownLocation();
116
-  }
117
-
118
-  /**
119
-   * Specifies a new route for this cargo.
120
-   *
121
-   * @param routeSpecification route specification.
122
-   */
123
-  public void specifyNewRoute(final RouteSpecification routeSpecification) {
124
-    Validate.notNull(routeSpecification, "Route specification is required");
125
-
126
-    this.routeSpecification = routeSpecification;
127
-    // Handling consistency within the Cargo aggregate synchronously
128
-    this.projections = new Projections(delivery, itinerary, routeSpecification);
129
-  }
130
-
131
-  /**
132
-   * Attach a new itinerary to this cargo.
133
-   *
134
-   * @param itinerary an itinerary. May not be null.
135
-   */
136
-  public void assignToRoute(final Itinerary itinerary) {
137
-    Validate.notNull(itinerary, "Itinerary is required");
138
-
139
-    this.itinerary = itinerary;
140
-    // Handling consistency within the Cargo aggregate synchronously
141
-    this.projections = new Projections(delivery, itinerary, routeSpecification);
142
-  }
143
-
144
-  public CustomsZone customsZone() {
145
-    return routeSpecification.destination().customsZone();
146
-  }
147
-
148
-
149
-  public Location customsClearancePoint() {
150
-    return customsZone().entryPoint(itinerary.locations());
151
-  }
152
-
153
-  public boolean isReadyToClaim() {
154
-    return delivery.isUnloadedAtDestination(routeSpecification);
155
-  }
156
-
157
-  /**
158
-   * Updates all aspects of the cargo aggregate status
159
-   * based on the current route specification, itinerary and handling of the cargo.
160
-   * <p/>
161
-   * When either of those three changes, i.e. when a new route is specified for the cargo,
162
-   * the cargo is assigned to a route or when the cargo is handled, the status must be
163
-   * re-calculated.
164
-   * <p/>
165
-   * {@link RouteSpecification} and {@link Itinerary} are both inside the Cargo
166
-   * aggregate, so changes to them cause the status to be updated <b>synchronously</b>,
167
-   * but handling cause the status update to happen <b>asynchronously</b>
168
-   * since {@link HandlingEvent} is in a different aggregate.
169
-   *
170
-   * @param handlingActivity handling activity
171
-   */
172
-  public void handled(final HandlingActivity handlingActivity) {
173
-    Validate.notNull(handlingActivity, "Handling activity is required");
174
-
175
-    // Delivery and Projections are value object, so they are replaced with new or derived ones
176
-    this.delivery = Delivery.whenHandled(handlingActivity);
177
-    this.projections = new Projections(delivery, itinerary, routeSpecification);
178
-  }
179
-
180
-  @Override
181
-  public boolean sameAs(final Cargo other) {
182
-    return other != null && trackingId().sameValueAs(other.trackingId());
183
-  }
184
-
185
-  /**
186
-   * @param object to compare
187
-   * @return True if they have the same identity
188
-   * @see #sameAs(Cargo)
189
-   */
190
-  @Override
191
-  public boolean equals(final Object object) {
192
-    if (this == object) return true;
193
-    if (object == null || getClass() != object.getClass()) return false;
194
-
195
-    final Cargo other = (Cargo) object;
196
-    return sameAs(other);
197
-  }
198
-
199
-  /**
200
-   * @return Hash code of tracking id.
201
-   */
202
-  @Override
203
-  public int hashCode() {
204
-    return trackingId.hashCode();
205
-  }
206
-
207
-  @Override
208
-  public String toString() {
209
-    return trackingId + " (" + routeSpecification + ")";
210
-  }
211
-
212
-  Cargo() {
213
-    // Needed by Hibernate
214
-  }
215
-
216
-  // Auto-generated surrogate key
217
-  @SuppressWarnings("UnusedDeclaration")
218
-  private Long id;
219
-
220
-}

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

@@ -1,34 +0,0 @@
1
-/**
2
- * Purpose
3
- * @author peter
4
- * @created 2009-jun-14
5
- * $Id$
6
- */
7
-package se.citerus.dddsample.domain.model.cargo;
8
-
9
-import se.citerus.dddsample.domain.model.location.Location;
10
-import se.citerus.dddsample.domain.model.location.LocationRepository;
11
-import se.citerus.dddsample.domain.model.location.UnLocode;
12
-
13
-import java.util.Date;
14
-
15
-public class CargoFactory {
16
-
17
-  private final LocationRepository locationRepository;
18
-  private final TrackingIdGenerator trackingIdGenerator;
19
-
20
-  public CargoFactory(LocationRepository locationRepository, TrackingIdGenerator trackingIdGenerator) {
21
-    this.locationRepository = locationRepository;
22
-    this.trackingIdGenerator = trackingIdGenerator;
23
-  }
24
-
25
-  public Cargo newCargo(UnLocode originUnLocode, UnLocode destinationUnLocode, Date arrivalDeadline) {
26
-    final TrackingId trackingId = trackingIdGenerator.nextTrackingId();
27
-    final Location origin = locationRepository.find(originUnLocode);
28
-    final Location destination = locationRepository.find(destinationUnLocode);
29
-    final RouteSpecification routeSpecification = new RouteSpecification(origin, destination, arrivalDeadline);
30
-
31
-    return new Cargo(trackingId, routeSpecification);
32
-  }
33
-
34
-}

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

@@ -1,38 +0,0 @@
1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import se.citerus.dddsample.domain.model.voyage.Voyage;
4
-
5
-import java.util.List;
6
-
7
-public interface CargoRepository {
8
-
9
-  /**
10
-   * Finds a cargo using given id.
11
-   *
12
-   * @param trackingId Id
13
-   * @return Cargo if found, else {@code null}
14
-   */
15
-  Cargo find(TrackingId trackingId);
16
-
17
-  /**
18
-   *
19
-   * @param voyage
20
-   * @return
21
-   */
22
-  List<Cargo> findCargosOnVoyage(Voyage voyage);
23
-
24
-  /**
25
-   * Finds all cargo.
26
-   *
27
-   * @return All cargo.
28
-   */
29
-  List<Cargo> findAll();
30
-
31
-  /**
32
-   * Saves given cargo.
33
-   *
34
-   * @param cargo cargo to save
35
-   */
36
-  void store(Cargo cargo);
37
-
38
-}

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

@@ -1,177 +0,0 @@
1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import org.apache.commons.lang.builder.EqualsBuilder;
5
-import org.apache.commons.lang.builder.HashCodeBuilder;
6
-import static se.citerus.dddsample.domain.model.cargo.RoutingStatus.*;
7
-import static se.citerus.dddsample.domain.model.cargo.TransportStatus.ONBOARD_CARRIER;
8
-import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
9
-import se.citerus.dddsample.domain.model.location.Location;
10
-import se.citerus.dddsample.domain.model.shared.HandlingActivity;
11
-import se.citerus.dddsample.domain.model.voyage.Voyage;
12
-import se.citerus.dddsample.domain.shared.ValueObject;
13
-
14
-import java.util.Date;
15
-
16
-/**
17
- * Everything about the delivery of the cargo, i.e. where the cargo is
18
- * right now, whether or not it's routed, misdirected and so on.
19
- */
20
-public class Delivery implements ValueObject<Delivery> {
21
-
22
-  private HandlingActivity mostRecentHandlingActivity;
23
-  private Date calculatedAt;
24
-
25
-  /**
26
-   * Derives a new delivery when a cargo has been handled.
27
-   *
28
-   * @param handlingActivity  handling activity
29
-   * @return An up to date delivery
30
-   */
31
-  static Delivery whenHandled(final HandlingActivity handlingActivity) {
32
-    Validate.notNull(handlingActivity, "Handling activity is required");
33
-
34
-    return new Delivery(handlingActivity);
35
-  }
36
-
37
-  /**
38
-   * @return Initial delivery, before any handling has taken place
39
-   */
40
-  static Delivery initial() {
41
-    return new Delivery(null);
42
-  }
43
-
44
-  Delivery(final HandlingActivity mostRecentHandlingActivity) {
45
-    this.mostRecentHandlingActivity = mostRecentHandlingActivity;
46
-    this.calculatedAt = new Date();
47
-  }
48
-
49
-  /**
50
-   * @return Transport status
51
-   */
52
-  TransportStatus transportStatus() {
53
-    return TransportStatus.derivedFrom(mostRecentHandlingActivity);
54
-  }
55
-
56
-  /**
57
-   * @return Last known location of the cargo, or Location.UNKNOWN if the delivery history is empty.
58
-   */
59
-  Location lastKnownLocation() {
60
-    if (mostRecentHandlingActivity != null) {
61
-      return mostRecentHandlingActivity.location();
62
-    } else {
63
-      return Location.UNKNOWN;
64
-    }
65
-  }
66
-
67
-  /**
68
-   * @return Current voyage.
69
-   */
70
-  Voyage currentVoyage() {
71
-    if (mostRecentHandlingActivity != null && transportStatus().equals(ONBOARD_CARRIER)) {
72
-      return mostRecentHandlingActivity.voyage();
73
-    } else {
74
-      return Voyage.NONE;
75
-    }
76
-  }
77
-
78
-  /**
79
-   * Check if cargo is misdirected.
80
-   * <p/>
81
-   * <ul>
82
-   * <li>A cargo is misdirected if it is in a location that's not in the itinerary.
83
-   * <li>A cargo with no itinerary can not be misdirected.
84
-   * <li>A cargo that has received no handling events can not be misdirected.
85
-   * </ul>
86
-   *
87
-   * @return <code>true</code> if the cargo has been misdirected,
88
-   * @param itinerary itinerary
89
-   * @param routeSpecification route specification
90
-   */
91
-  boolean isMisdirected(final Itinerary itinerary, final RouteSpecification routeSpecification) {
92
-    if (mostRecentHandlingActivity == null) {
93
-      return false;
94
-    }
95
-
96
-    if (CUSTOMS.sameValueAs(mostRecentHandlingActivity.type())) {
97
-      return !routeSpecification.destination().sameAs(mostRecentHandlingActivity.location());
98
-    } else {
99
-      return !itinerary.isExpected(mostRecentHandlingActivity);
100
-    }
101
-  }
102
-
103
-  /**
104
-   * @return True if the cargo has been unloaded at the final destination.
105
-   * @param routeSpecification route specification
106
-   */
107
-  boolean isUnloadedAtDestination(final RouteSpecification routeSpecification) {
108
-    return mostRecentHandlingActivity != null &&
109
-          (CLAIM.sameValueAs(mostRecentHandlingActivity.type()) || UNLOAD.sameValueAs(mostRecentHandlingActivity.type()) &&
110
-           routeSpecification.destination().sameAs(mostRecentHandlingActivity.location()));
111
-  }
112
-
113
-  /**
114
-   * @return Routing status.
115
-   * @param itinerary itinerary
116
-   * @param routeSpecification route specification
117
-   */
118
-  RoutingStatus routingStatus(final Itinerary itinerary, final RouteSpecification routeSpecification) {
119
-    if (itinerary == null) {
120
-      return NOT_ROUTED;
121
-    } else {
122
-      if (routeSpecification.isSatisfiedBy(itinerary)) {
123
-        return ROUTED;
124
-      } else {
125
-        return MISROUTED;
126
-      }
127
-    }
128
-  }
129
-
130
-  /**
131
-   * @return When this delivery was calculated.
132
-   */
133
-  Date calculatedAt() {
134
-    return new Date(calculatedAt.getTime());
135
-  }
136
-
137
-  /**
138
-   * @return True if the cargo is routed and not misdirected  @param itinerary
139
-   * @param itinerary itinerary
140
-   * @param routeSpecification route specification
141
-   */
142
-  boolean onTrack(final Itinerary itinerary, final RouteSpecification routeSpecification) {
143
-    return routingStatus(itinerary, routeSpecification).sameValueAs(ROUTED) && 
144
-           !isMisdirected(itinerary, routeSpecification);
145
-  }
146
-
147
-  @Override
148
-  public boolean sameValueAs(final Delivery other) {
149
-    return other != null && new EqualsBuilder().
150
-      append(this.mostRecentHandlingActivity, other.mostRecentHandlingActivity).
151
-      append(this.calculatedAt, other.calculatedAt).
152
-      isEquals();
153
-  }
154
-
155
-  @Override
156
-  public boolean equals(final Object o) {
157
-    if (this == o) return true;
158
-    if (o == null || getClass() != o.getClass()) return false;
159
-
160
-    final Delivery other = (Delivery) o;
161
-
162
-    return sameValueAs(other);
163
-  }
164
-
165
-  @Override
166
-  public int hashCode() {
167
-    return new HashCodeBuilder().
168
-      append(mostRecentHandlingActivity).
169
-      append(calculatedAt).
170
-      toHashCode();
171
-  }
172
-
173
-  Delivery() {
174
-    // Needed by Hibernate
175
-  }
176
-
177
-}

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

@@ -1,250 +0,0 @@
1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import org.apache.commons.lang.StringUtils;
4
-import org.apache.commons.lang.Validate;
5
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
6
-import se.citerus.dddsample.domain.model.location.Location;
7
-import se.citerus.dddsample.domain.model.shared.HandlingActivity;
8
-import se.citerus.dddsample.domain.model.voyage.Voyage;
9
-import se.citerus.dddsample.domain.shared.ValueObject;
10
-
11
-import java.util.*;
12
-
13
-/**
14
- * An itinerary.
15
- */
16
-public class Itinerary implements ValueObject<Itinerary> {
17
-
18
-  private List<Leg> legs = Collections.emptyList();
19
-
20
-  static final Itinerary EMPTY_ITINERARY = new Itinerary();
21
-  private static final Date END_OF_DAYS = new Date(Long.MAX_VALUE);
22
-
23
-  /**
24
-   * Constructor.
25
-   *
26
-   * @param legs List of legs for this itinerary.
27
-   */
28
-  public Itinerary(final List<Leg> legs) {
29
-    Validate.notEmpty(legs);
30
-    Validate.noNullElements(legs);
31
-
32
-    // TODO
33
-    // Validate that legs are in proper order, connected
34
-    // and that load/unload times are doable?
35
-
36
-    this.legs = legs;
37
-  }
38
-
39
-  public Itinerary(final Leg... legs) {
40
-    this(Arrays.asList(legs));
41
-  }
42
-
43
-  /**
44
-   * @return the legs of this itinerary, as an <b>immutable</b> list.
45
-   */
46
-  public List<Leg> legs() {
47
-    return Collections.unmodifiableList(legs);
48
-  }
49
-
50
-  /**
51
-   * Test if the given handling event is expected when executing this itinerary.
52
-   *
53
-   * @param handlingActivity Event to test.
54
-   * @return <code>true</code> if the event is expected
55
-   */
56
-  public boolean isExpected(final HandlingActivity handlingActivity) {
57
-    if (isEmpty()) {
58
-      return false;
59
-    }
60
-
61
-    if (handlingActivity.type() == HandlingEvent.Type.RECEIVE) {
62
-      return (firstLeg().loadLocation().equals(handlingActivity.location()));
63
-    }
64
-
65
-    if (handlingActivity.type() == HandlingEvent.Type.LOAD) {
66
-      //Check that the there is a leg with same load location and voyage
67
-      for (Leg leg : legs) {
68
-        if (leg.loadLocation().sameAs(handlingActivity.location()) &&
69
-          leg.voyage().sameAs(handlingActivity.voyage()))
70
-          return true;
71
-      }
72
-      return false;
73
-    }
74
-
75
-    if (handlingActivity.type() == HandlingEvent.Type.UNLOAD) {
76
-      //Check that the there is a leg with same unload location and voyage
77
-      for (Leg leg : legs) {
78
-        if (leg.unloadLocation().sameAs(handlingActivity.location()) &&
79
-          leg.voyage().sameAs(handlingActivity.voyage()))
80
-          return true;
81
-      }
82
-      return false;
83
-    }
84
-
85
-    if (handlingActivity.type() == HandlingEvent.Type.CLAIM) {
86
-      //Check that the last leg's destination is from the handling activity's location
87
-      final Leg leg = lastLeg();
88
-      return (leg.unloadLocation().equals(handlingActivity.location()));
89
-    }
90
-
91
-    if (handlingActivity.type() == HandlingEvent.Type.CUSTOMS) {
92
-      //Check that the customs location fits the rule of the customs zone
93
-      //TODO Answering this properly requires Cargo's destination. Can't be answered at itinerary level.
94
-    }
95
-    return false;
96
-
97
-  }
98
-
99
-  /**
100
-   * @return The initial departure location.
101
-   */
102
-  Location initialLoadLocation() {
103
-    if (isEmpty()) {
104
-      return Location.UNKNOWN;
105
-    } else {
106
-      return legs.get(0).loadLocation();
107
-    }
108
-  }
109
-
110
-  /**
111
-   * @return The final arrival location.
112
-   */
113
-  Location finalUnloadLocation() {
114
-    if (isEmpty()) {
115
-      return Location.UNKNOWN;
116
-    } else {
117
-      return lastLeg().unloadLocation();
118
-    }
119
-  }
120
-
121
-  /**
122
-   * @return Date when cargo arrives at final destination.
123
-   */
124
-  Date finalUnloadTime() {
125
-    if (isEmpty()) return new Date(END_OF_DAYS.getTime());
126
-    return new Date(lastLeg().unloadTime().getTime());
127
-  }
128
-
129
-  private boolean isEmpty() {
130
-    return legs.isEmpty();
131
-  }
132
-
133
-  /**
134
-   * @return The first leg on the itinerary.
135
-   */
136
-  public Leg firstLeg() {
137
-    if (isEmpty()) return null;
138
-    return legs.get(0);
139
-  }
140
-
141
-  /**
142
-   * @return The last leg on the itinerary.
143
-   */
144
-  public Leg lastLeg() {
145
-    if (isEmpty()) return null;
146
-    return legs.get(legs.size() - 1);
147
-  }
148
-
149
-  /**
150
-   * @param rescheduledVoyage the voyage that has been rescheduled
151
-   * @return A new itinerary which is a copy of the old one, adjusted for the delay of the given voyage.
152
-   */
153
-  public Itinerary withRescheduledVoyage(final Voyage rescheduledVoyage) {
154
-    final List<Leg> newLegsList = new ArrayList<Leg>(this.legs.size());
155
-
156
-    Leg lastAdded = null;
157
-    for (Leg leg : this.legs) {
158
-      if (leg.voyage().sameAs(rescheduledVoyage)) {
159
-        Leg modifiedLeg = leg.withRescheduledVoyage(rescheduledVoyage);
160
-        // This truncates the itinerary if the voyage rescheduling makes
161
-        // it impossible to maintain the old unload-load chain.
162
-        if (lastAdded != null && modifiedLeg.loadTime().before(lastAdded.unloadTime())) {
163
-          break;
164
-        }
165
-        newLegsList.add(modifiedLeg);
166
-      } else {
167
-        newLegsList.add(leg);
168
-      }
169
-      lastAdded = leg;
170
-    }
171
-
172
-    return new Itinerary(newLegsList);
173
-  }
174
-
175
-  /**
176
-   * @return A list of all locations on this itinerary.
177
-   */
178
-  public List<Location> locations() {
179
-    final List<Location> result = new ArrayList<Location>(legs.size() + 1);
180
-    result.add(firstLeg().loadLocation());
181
-    for (Leg leg : legs) {
182
-      result.add(leg.unloadLocation());
183
-    }
184
-    return result;
185
-  }
186
-
187
-  /**
188
-   * @param location a location
189
-   * @return Load time at this location, or null if the location isn't on this itinerary.
190
-   */
191
-  public Date loadTimeAt(final Location location) {
192
-    for (Leg leg : legs) {
193
-      if (leg.loadLocation().sameAs(location)) {
194
-        return leg.loadTime();
195
-      }
196
-    }
197
-    return null;
198
-  }
199
-
200
-  /**
201
-   * @param location a location
202
-   * @return Unload time at this location, or null if the location isn't on this itinerary.
203
-   */
204
-  public Date unloadTimeAt(final Location location) {
205
-    for (Leg leg : legs) {
206
-      if (leg.unloadLocation().sameAs(location)) {
207
-        return leg.unloadTime();
208
-      }
209
-    }
210
-    return null;
211
-  }
212
-
213
-
214
-  /**
215
-   * @param other itinerary to compare
216
-   * @return <code>true</code> if the legs in this and the other itinerary are all equal.
217
-   */
218
-  @Override
219
-  public boolean sameValueAs(final Itinerary other) {
220
-    return other != null && legs.equals(other.legs);
221
-  }
222
-
223
-  @Override
224
-  public boolean equals(final Object o) {
225
-    if (this == o) return true;
226
-    if (o == null || getClass() != o.getClass()) return false;
227
-
228
-    final Itinerary itinerary = (Itinerary) o;
229
-
230
-    return sameValueAs(itinerary);
231
-  }
232
-
233
-  @Override
234
-  public int hashCode() {
235
-    return legs.hashCode();
236
-  }
237
-
238
-  @Override
239
-  public String toString() {
240
-    return StringUtils.join(legs, "\n");
241
-  }
242
-
243
-  Itinerary() {
244
-    // Needed by Hibernate
245
-  }
246
-
247
-  // Auto-generated surrogate key
248
-  @SuppressWarnings("UnusedDeclaration")
249
-  private Long id;
250
-}

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

@@ -1,133 +0,0 @@
1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import org.apache.commons.lang.builder.EqualsBuilder;
5
-import org.apache.commons.lang.builder.HashCodeBuilder;
6
-import se.citerus.dddsample.domain.model.location.Location;
7
-import se.citerus.dddsample.domain.model.voyage.Voyage;
8
-import se.citerus.dddsample.domain.shared.ValueObject;
9
-
10
-import java.util.Date;
11
-
12
-/**
13
- * An itinerary consists of one or more legs.
14
- */
15
-public class Leg implements ValueObject<Leg> {
16
-
17
-  private Voyage voyage;
18
-  private Location loadLocation;
19
-  private Location unloadLocation;
20
-  private Date loadTime;
21
-  private Date unloadTime;
22
-
23
-  // TODO hide this, use factory
24
-  public Leg(Voyage voyage, Location loadLocation, Location unloadLocation, Date loadTime, Date unloadTime) {
25
-    Validate.notNull(voyage, "Voyage is required");
26
-    Validate.notNull(loadLocation, "Load location is required");
27
-    Validate.notNull(unloadLocation, "Unload location is required");
28
-    Validate.notNull(loadTime, "Load time is required");
29
-    Validate.notNull(unloadTime, "Unload time is required");
30
-    Validate.isTrue(!loadLocation.sameAs(unloadLocation));
31
-    // TODO use a minimum time between unloading and loading?
32
-    //Validate.isTrue(unloadTime.after(loadTime));
33
-
34
-    this.voyage = voyage;
35
-    this.loadLocation = loadLocation;
36
-    this.unloadLocation = unloadLocation;
37
-    this.loadTime = loadTime;
38
-    this.unloadTime = unloadTime;
39
-  }
40
-
41
-  /**
42
-   * This simple factory takes the Leg's times from the state of the
43
-   * Voyage as of the time of construction.
44
-   * A fuller version might also factor operational time
45
-   * in the port. For example, average unload time of the
46
-   * unloadLocation could be added to the eta of the vessel
47
-   * schedule, providing an estimated unload time.
48
-   * In a real system, the estimation of the unload time
49
-   * might be more complex.
50
-   *
51
-   * @param voyage         voyage
52
-   * @param loadLocation   load location
53
-   * @param unloadLocation unload location
54
-   * @return A leg on this voyage between the given locations.
55
-   */
56
-  public static Leg deriveLeg(Voyage voyage, Location loadLocation, Location unloadLocation) {
57
-    return new Leg(voyage, loadLocation, unloadLocation, voyage.schedule().departureTimeAt(loadLocation), voyage.schedule().arrivalTimeAt(unloadLocation));
58
-  }
59
-
60
-  public Voyage voyage() {
61
-    return voyage;
62
-  }
63
-
64
-  public Location loadLocation() {
65
-    return loadLocation;
66
-  }
67
-
68
-  public Location unloadLocation() {
69
-    return unloadLocation;
70
-  }
71
-
72
-  public Date loadTime() {
73
-    return new Date(loadTime.getTime());
74
-  }
75
-
76
-  public Date unloadTime() {
77
-    return new Date(unloadTime.getTime());
78
-  }
79
-
80
-  /**
81
-   * @param voyage voyage
82
-   * @return A new leg with the same load and unload locations, but with updated load/unload times.
83
-   */
84
-  Leg withRescheduledVoyage(final Voyage voyage) {
85
-    return Leg.deriveLeg(voyage, loadLocation, unloadLocation);
86
-  }
87
-
88
-  @Override
89
-  public boolean sameValueAs(final Leg other) {
90
-    return other != null && new EqualsBuilder().
91
-      append(this.voyage, other.voyage).
92
-      append(this.loadLocation, other.loadLocation).
93
-      append(this.unloadLocation, other.unloadLocation).
94
-      append(this.loadTime, other.loadTime).
95
-      append(this.unloadTime, other.unloadTime).
96
-      isEquals();
97
-  }
98
-
99
-  @Override
100
-  public boolean equals(final Object o) {
101
-    if (this == o) return true;
102
-    if (o == null || getClass() != o.getClass()) return false;
103
-
104
-    Leg leg = (Leg) o;
105
-
106
-    return sameValueAs(leg);
107
-  }
108
-
109
-  @Override
110
-  public int hashCode() {
111
-    return new HashCodeBuilder().
112
-      append(voyage).
113
-      append(loadLocation).
114
-      append(unloadLocation).
115
-      append(loadTime).
116
-      append(unloadTime).
117
-      toHashCode();
118
-  }
119
-
120
-  @Override
121
-  public String toString() {
122
-    return "Load in " + loadLocation + " at " + loadTime +
123
-      " --- Unload in " + unloadLocation + " at " + unloadTime;
124
-  }
125
-
126
-  Leg() {
127
-    // Needed by Hibernate
128
-  }
129
-
130
-  // Auto-generated surrogate key
131
-  private Long id;
132
-
133
-}

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

@@ -1,167 +0,0 @@
1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import org.apache.commons.lang.builder.EqualsBuilder;
4
-import org.apache.commons.lang.builder.HashCodeBuilder;
5
-import static se.citerus.dddsample.domain.model.handling.HandlingEvent.Type.*;
6
-import se.citerus.dddsample.domain.model.location.Location;
7
-import se.citerus.dddsample.domain.model.shared.HandlingActivity;
8
-import se.citerus.dddsample.domain.shared.ValueObject;
9
-
10
-import java.util.Date;
11
-import java.util.Iterator;
12
-
13
-/**
14
- * These are projections about the future handling of the cargo,
15
- * when it will arrive and what the next step is.
16
- * <p/>
17
- * It is updated on routing changes as well as handling.
18
- */
19
-class Projections implements ValueObject<Projections> {
20
-
21
-  private Date estimatedTimeOfArrival;
22
-  private HandlingActivity nextExpectedActivity;
23
-
24
-  private static final Date ETA_UNKOWN = null;
25
-  private static final HandlingActivity NO_ACTIVITY = null;
26
-
27
-  Projections(final Delivery delivery, final Itinerary itinerary, final RouteSpecification routeSpecification) {
28
-    this.estimatedTimeOfArrival = calculateEstimatedTimeOfArrival(delivery, itinerary, routeSpecification);
29
-    this.nextExpectedActivity = calculateNextExpectedActivity(delivery, itinerary, routeSpecification);
30
-  }
31
-
32
-  /**
33
-   * @return Estimated time of arrival, or null if not known.
34
-   */
35
-  Date estimatedTimeOfArrival() {
36
-    if (estimatedTimeOfArrival != ETA_UNKOWN) {
37
-      return new Date(estimatedTimeOfArrival.getTime());
38
-    } else {
39
-      return ETA_UNKOWN;
40
-    }
41
-  }
42
-
43
-  /**
44
-   * @return The next expected handling activity.
45
-   */
46
-  HandlingActivity nextExpectedActivity() {
47
-    return nextExpectedActivity;
48
-  }
49
-
50
-  private Date calculateEstimatedTimeOfArrival(final Delivery delivery, final Itinerary itinerary, final RouteSpecification routeSpecification) {
51
-    if (delivery.onTrack(itinerary, routeSpecification)) {
52
-      return itinerary.finalUnloadTime();
53
-    } else {
54
-      return ETA_UNKOWN;
55
-    }
56
-  }
57
-
58
-  private HandlingActivity calculateNextExpectedActivity(final Delivery delivery, final Itinerary itinerary, final RouteSpecification routeSpecification) {
59
-
60
-    /*
61
-     TODO Capture:
62
-
63
-     Cargo is misdirected but has been rerouted. Next expected acivity should be to load according to first leg
64
-     of new itinerary.
65
-
66
-     and
67
-
68
-     even if a cargo is misdirected, we expect it to be unloaded at next stop.
69
-
70
-    */
71
-    if (!delivery.onTrack(itinerary, routeSpecification)) {
72
-      return NO_ACTIVITY;
73
-    }
74
-
75
-    final Location lastKnownLocation = delivery.lastKnownLocation();
76
-    switch (delivery.transportStatus()) {
77
-      case IN_PORT:
78
-        if (itinerary.firstLeg().loadLocation().sameAs(lastKnownLocation)) {
79
-          return loadInFirstLocation(itinerary);
80
-        } else {
81
-          return loadOrClaimInNextLocation(itinerary, lastKnownLocation);
82
-        }
83
-
84
-      case NOT_RECEIVED:
85
-        return receiveInFirstLocation(itinerary);
86
-
87
-      case ONBOARD_CARRIER:
88
-        return unloadInNextLocation(itinerary, lastKnownLocation);
89
-
90
-      case CLAIMED:
91
-      default:
92
-        return NO_ACTIVITY;
93
-    }
94
-  }
95
-
96
-  private HandlingActivity receiveInFirstLocation(final Itinerary itinerary) {
97
-    final Leg leg = itinerary.firstLeg();
98
-    return new HandlingActivity(RECEIVE, leg.loadLocation());
99
-  }
100
-
101
-  private HandlingActivity loadInFirstLocation(final Itinerary itinerary) {
102
-    final Leg leg = itinerary.firstLeg();
103
-    return new HandlingActivity(LOAD, leg.loadLocation(), leg.voyage());
104
-  }
105
-
106
-  private HandlingActivity loadOrClaimInNextLocation(final Itinerary itinerary, final Location activityLocation) {
107
-    for (final Iterator<Leg> it = itinerary.legs().iterator(); it.hasNext();) {
108
-      final Leg leg = it.next();
109
-      if (leg.unloadLocation().sameAs(activityLocation)) {
110
-        if (it.hasNext()) {
111
-          final Leg nextLeg = it.next();
112
-
113
-          //return leg.loadActivity(); { return new HandlingActivity(voyage, loadLocation); }
114
-
115
-          //return HandlingActivity.loadOnto(nextLeg.voyage()).in(nextLeg.loadLocation());
116
-
117
-          return new HandlingActivity(LOAD, nextLeg.loadLocation(), nextLeg.voyage());
118
-        } else {
119
-          return new HandlingActivity(CLAIM, leg.unloadLocation());
120
-        }
121
-      }
122
-    }
123
-
124
-    return NO_ACTIVITY;
125
-  }
126
-
127
-  private HandlingActivity unloadInNextLocation(final Itinerary itinerary, final Location activityLocation) {
128
-    for (final Leg leg : itinerary.legs()) {
129
-      if (leg.loadLocation().sameAs(activityLocation)) {
130
-        return new HandlingActivity(UNLOAD, leg.unloadLocation(), leg.voyage());
131
-      }
132
-    }
133
-
134
-    return NO_ACTIVITY;
135
-  }
136
-
137
-
138
-  @Override
139
-  public boolean sameValueAs(final Projections other) {
140
-    return other != null && new EqualsBuilder().
141
-      append(this.estimatedTimeOfArrival, other.estimatedTimeOfArrival).
142
-      append(this.nextExpectedActivity, other.nextExpectedActivity).
143
-      isEquals();
144
-  }
145
-
146
-  @Override
147
-  public boolean equals(final Object o) {
148
-    if (this == o) return true;
149
-    if (o == null || getClass() != o.getClass()) return false;
150
-
151
-    final Projections other = (Projections) o;
152
-    return sameValueAs(other);
153
-  }
154
-
155
-  @Override
156
-  public int hashCode() {
157
-    return new HashCodeBuilder().
158
-      append(estimatedTimeOfArrival).
159
-      append(nextExpectedActivity).
160
-      toHashCode();
161
-  }
162
-
163
-  Projections() {
164
-    // Needed by Hibernate
165
-  }
166
-
167
-}

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

@@ -1,128 +0,0 @@
1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import org.apache.commons.lang.builder.EqualsBuilder;
5
-import org.apache.commons.lang.builder.HashCodeBuilder;
6
-import se.citerus.dddsample.domain.model.location.Location;
7
-import se.citerus.dddsample.domain.shared.AbstractSpecification;
8
-import se.citerus.dddsample.domain.shared.ValueObject;
9
-
10
-import java.util.Date;
11
-
12
-/**
13
- * Route specification. Describes where a cargo orign and destination is,
14
- * and the arrival deadline.
15
- */
16
-public class RouteSpecification extends AbstractSpecification<Itinerary> implements ValueObject<RouteSpecification> {
17
-
18
-  private Location origin;
19
-  private Location destination;
20
-  private Date arrivalDeadline;
21
-
22
-  /**
23
-   * @param origin          origin location - can't be the same as the destination
24
-   * @param destination     destination location - can't be the same as the origin
25
-   * @param arrivalDeadline arrival deadline
26
-   */
27
-  public RouteSpecification(final Location origin, final Location destination, final Date arrivalDeadline) {
28
-    Validate.notNull(origin, "Origin is required");
29
-    Validate.notNull(destination, "Destination is required");
30
-    Validate.notNull(arrivalDeadline, "Arrival deadline is required");
31
-    Validate.isTrue(!origin.sameAs(destination), "Origin and destination can't be the same: " + origin);
32
-
33
-    this.origin = origin;
34
-    this.destination = destination;
35
-    this.arrivalDeadline = new Date(arrivalDeadline.getTime());
36
-  }
37
-
38
-  /**
39
-   * @return Specified origin location.
40
-   */
41
-  public Location origin() {
42
-    return origin;
43
-  }
44
-
45
-  /**
46
-   * @return Specfied destination location.
47
-   */
48
-  public Location destination() {
49
-    return destination;
50
-  }
51
-
52
-  /**
53
-   * @return Arrival deadline.
54
-   */
55
-  public Date arrivalDeadline() {
56
-    return new Date(arrivalDeadline.getTime());
57
-  }
58
-
59
-  /**
60
-   * @param newDestination destination of new route specification
61
-   * @return A copy of this route specification but with new destination
62
-   */
63
-  public RouteSpecification withDestination(final Location newDestination) {
64
-    return new RouteSpecification(origin, newDestination, arrivalDeadline);
65
-  }
66
-
67
-  /**
68
-   * @param newOrigin origin of new route specification
69
-   * @return A copy of this route specification but with the new origin
70
-   */
71
-  public RouteSpecification withOrigin(final Location newOrigin) {
72
-    return new RouteSpecification(newOrigin, destination, arrivalDeadline);
73
-  }
74
-
75
-  /**
76
-   * @param newArrivalDeadline arrival deadline of new route specification
77
-   * @return A copy of this route specification but with the new arrival deadline
78
-   */
79
-  public RouteSpecification withArrivalDeadline(final Date newArrivalDeadline) {
80
-    return new RouteSpecification(origin, destination, newArrivalDeadline);
81
-  }
82
-
83
-  @Override
84
-  public boolean isSatisfiedBy(final Itinerary itinerary) {
85
-    return itinerary != null &&
86
-      origin().sameAs(itinerary.initialLoadLocation()) &&
87
-      destination().sameAs(itinerary.finalUnloadLocation()) &&
88
-      arrivalDeadline().after(itinerary.finalUnloadTime());
89
-  }
90
-
91
-  @Override
92
-  public boolean sameValueAs(final RouteSpecification other) {
93
-    return other != null && new EqualsBuilder().
94
-      append(this.origin, other.origin).
95
-      append(this.destination, other.destination).
96
-      append(this.arrivalDeadline, other.arrivalDeadline).
97
-      isEquals();
98
-  }
99
-
100
-  @Override
101
-  public boolean equals(final Object o) {
102
-    if (this == o) return true;
103
-    if (o == null || getClass() != o.getClass()) return false;
104
-
105
-    final RouteSpecification that = (RouteSpecification) o;
106
-
107
-    return sameValueAs(that);
108
-  }
109
-
110
-  @Override
111
-  public int hashCode() {
112
-    return new HashCodeBuilder().
113
-      append(this.origin).
114
-      append(this.destination).
115
-      append(this.arrivalDeadline).
116
-      toHashCode();
117
-  }
118
-
119
-  @Override
120
-  public String toString() {
121
-    return origin + " to " + destination + " by " + arrivalDeadline;
122
-  }
123
-
124
-  RouteSpecification() {
125
-    // Needed by Hibernate
126
-  }
127
-
128
-}

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

@@ -1,28 +0,0 @@
1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import se.citerus.dddsample.domain.shared.ValueObject;
4
-
5
-/**
6
- * The different routing statuses of a cargo.
7
- */
8
-public enum RoutingStatus implements ValueObject<RoutingStatus> {
9
-  NOT_ROUTED, ROUTED, MISROUTED;
10
-
11
-  @Override
12
-  public boolean sameValueAs(final RoutingStatus other) {
13
-    return this.equals(other);
14
-  }
15
-
16
-  public static RoutingStatus derivedFrom(final Itinerary itinerary, final RouteSpecification routeSpecification) {
17
-    if (itinerary == null) {
18
-      return NOT_ROUTED;
19
-    } else {
20
-      if (routeSpecification.isSatisfiedBy(itinerary)) {
21
-        return ROUTED;
22
-      } else {
23
-        return MISROUTED;
24
-      }
25
-    }
26
-  }
27
-
28
-}

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

@@ -1,66 +0,0 @@
1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import org.apache.commons.lang.StringUtils;
4
-import org.apache.commons.lang.Validate;
5
-import se.citerus.dddsample.domain.shared.ValueObject;
6
-
7
-import java.io.Serializable;
8
-
9
-/**
10
- * Uniquely identifies a particular cargo. Automatically generated by the application.
11
- */
12
-public final class TrackingId implements ValueObject<TrackingId>, Serializable {
13
-
14
-  private String id;
15
-
16
-  /**
17
-   * Constructor.
18
-   *
19
-   * @param id Id string.
20
-   */
21
-  public TrackingId(final String id) {
22
-    Validate.notNull(id);
23
-    this.id = id;
24
-  }
25
-
26
-  public TrackingId(final long sequenceValue) {
27
-    Validate.isTrue(sequenceValue > 0, "Sequence value must be larger than 0");
28
-    this.id = "C" + StringUtils.leftPad(String.valueOf(sequenceValue), 8, "0");
29
-  }
30
-
31
-  /**
32
-   * @return String representation of this tracking id.
33
-   */
34
-  public String stringValue() {
35
-    return id;
36
-  }
37
-
38
-  @Override
39
-  public boolean equals(Object o) {
40
-    if (this == o) return true;
41
-    if (o == null || getClass() != o.getClass()) return false;
42
-
43
-    TrackingId other = (TrackingId) o;
44
-
45
-    return sameValueAs(other);
46
-  }
47
-
48
-  @Override
49
-  public int hashCode() {
50
-    return id.hashCode();
51
-  }
52
-
53
-  @Override
54
-  public boolean sameValueAs(TrackingId other) {
55
-    return other != null && this.id.equals(other.id);
56
-  }
57
-
58
-  @Override
59
-  public String toString() {
60
-    return id;
61
-  }
62
-
63
-  TrackingId() {
64
-    // Needed by Hibernate
65
-  }
66
-}

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

@@ -1,10 +0,0 @@
1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-/**
4
- * Generates tracking ids for cargos. This is a domain service.
5
- */
6
-public interface TrackingIdGenerator {
7
-
8
-  TrackingId nextTrackingId();
9
-
10
-}

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

@@ -1,35 +0,0 @@
1
-package se.citerus.dddsample.domain.model.cargo;
2
-
3
-import se.citerus.dddsample.domain.shared.ValueObject;
4
-import se.citerus.dddsample.domain.model.shared.HandlingActivity;
5
-
6
-/**
7
- * Represents the different transport statuses for a cargo.
8
- */
9
-public enum TransportStatus implements ValueObject<TransportStatus> {
10
-  NOT_RECEIVED, IN_PORT, ONBOARD_CARRIER, CLAIMED, UNKNOWN;
11
-
12
-  @Override
13
-  public boolean sameValueAs(final TransportStatus other) {
14
-    return this.equals(other);
15
-  }
16
-
17
-  public static TransportStatus derivedFrom(HandlingActivity handlingActivity) {
18
-    if (handlingActivity == null) {
19
-      return NOT_RECEIVED;
20
-    }
21
-
22
-    switch (handlingActivity.type()) {
23
-      case LOAD:
24
-        return ONBOARD_CARRIER;
25
-      case UNLOAD:
26
-      case RECEIVE:
27
-        return IN_PORT;
28
-      case CLAIM:
29
-        return CLAIMED;
30
-      default:
31
-        return UNKNOWN;
32
-    }
33
-  }
34
-
35
-}

+ 0
- 7
dddsample/src/main/java/se/citerus/dddsample/domain/model/cargo/package.html Просмотреть файл

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	The cargo aggregate. Cargo is the aggregate root.
5
-</p>
6
-</body>
7
-</html>

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

@@ -1,19 +0,0 @@
1
-package se.citerus.dddsample.domain.model.handling;
2
-
3
-/**
4
- * If a {@link se.citerus.dddsample.domain.model.handling.HandlingEvent} can't be
5
- * created from a given set of parameters.
6
- * <p/>
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.
10
- */
11
-public class CannotCreateHandlingEventException extends Exception {
12
-  public CannotCreateHandlingEventException(Exception e) {
13
-    super(e);
14
-  }
15
-
16
-  public CannotCreateHandlingEventException() {
17
-    super();
18
-  }
19
-}

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

@@ -1,227 +0,0 @@
1
-package se.citerus.dddsample.domain.model.handling;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import org.apache.commons.lang.builder.EqualsBuilder;
5
-import org.apache.commons.lang.builder.HashCodeBuilder;
6
-import se.citerus.dddsample.domain.model.cargo.Cargo;
7
-import se.citerus.dddsample.domain.model.location.Location;
8
-import se.citerus.dddsample.domain.model.shared.EventSequenceNumber;
9
-import se.citerus.dddsample.domain.model.shared.HandlingActivity;
10
-import se.citerus.dddsample.domain.model.voyage.Voyage;
11
-import se.citerus.dddsample.domain.shared.DomainEvent;
12
-import se.citerus.dddsample.domain.shared.DomainObjectUtils;
13
-import se.citerus.dddsample.domain.shared.ValueObject;
14
-
15
-import java.util.Date;
16
-
17
-/**
18
- * A HandlingEvent is used to register the event when, for instance,
19
- * a cargo is unloaded from a carrier at a some loacation at a given time.
20
- * <p/>
21
- * The HandlingEvent's are sent from different Incident Logging Applications
22
- * 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
- * and possibly, if applicable a {@link se.citerus.dddsample.domain.model.voyage.Voyage}.
25
- * <p/>
26
- * This class is the only member, and consequently the root, of the HandlingEvent aggregate.
27
- * <p/>
28
- * 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
- * <p/>
31
- * All other events must be of {@link Type#RECEIVE}, {@link Type#CLAIM} or {@link Type#CUSTOMS}.
32
- */
33
-public final class HandlingEvent implements DomainEvent<HandlingEvent> {
34
-
35
-  private EventSequenceNumber sequenceNumber;
36
-  private HandlingActivity activity;
37
-  private Date completionTime;
38
-  private Date registrationTime;
39
-  private Cargo cargo;
40
-
41
-  /**
42
-   * Handling event type. Either requires or prohibits a carrier movement
43
-   * association, it's never optional.
44
-   */
45
-  public enum Type implements ValueObject<Type> {
46
-    LOAD(true, true),
47
-    UNLOAD(true, true),
48
-    RECEIVE(false, true),
49
-    CLAIM(false, true),
50
-    CUSTOMS(false, false);
51
-
52
-    private final boolean voyageRelated;
53
-    private final boolean physical;
54
-
55
-    /**
56
-     * Private enum constructor.
57
-     *
58
-     * @param voyageRelated whether or not a voyage is associated with this event type
59
-     * @param physical whether or not this event type is physical
60
-     */
61
-    private Type(final boolean voyageRelated, final boolean physical) {
62
-      this.voyageRelated = voyageRelated;
63
-      this.physical = physical;
64
-    }
65
-
66
-    /**
67
-     * @return True if a voyage association is required for this event type.
68
-     */
69
-    public boolean isVoyageRelated() {
70
-      return voyageRelated;
71
-    }
72
-
73
-    /**
74
-     * @return True if this is a physical handling.
75
-     */
76
-    public boolean isPhysical() {
77
-      return physical;
78
-    }
79
-
80
-    @Override
81
-    public boolean sameValueAs(Type other) {
82
-      return other != null && this.equals(other);
83
-    }
84
-
85
-  }
86
-
87
-  /**
88
-   * @param cargo            cargo
89
-   * @param completionTime   completion time, the reported time that the event actually happened (e.g. the receive took place).
90
-   * @param registrationTime registration time, the time the message is received
91
-   * @param type             type of event
92
-   * @param location         where the event took place
93
-   * @param voyage           the voyage
94
-   */
95
-  // TODO make package local
96
-  public HandlingEvent(final Cargo cargo,
97
-                       final Date completionTime,
98
-                       final Date registrationTime,
99
-                       final Type type,
100
-                       final Location location,
101
-                       final Voyage voyage) {
102
-    Validate.notNull(cargo, "Cargo is required");
103
-    Validate.notNull(completionTime, "Completion time is required");
104
-    Validate.notNull(registrationTime, "Registration time is required");
105
-    Validate.notNull(type, "Handling event type is required");
106
-    Validate.notNull(location, "Location is required");
107
-    Validate.notNull(voyage, "Voyage is required");
108
-
109
-    if (!type.isVoyageRelated()) {
110
-      throw new IllegalArgumentException("Voyage is not allowed with event type " + type);
111
-    }
112
-
113
-    this.sequenceNumber = EventSequenceNumber.next();
114
-    this.cargo = cargo;
115
-    this.completionTime = new Date(completionTime.getTime());
116
-    this.registrationTime = new Date(registrationTime.getTime());
117
-    this.activity = new HandlingActivity(type, location, voyage);
118
-  }
119
-
120
-  /**
121
-   * @param cargo            cargo
122
-   * @param completionTime   completion time, the reported time that the event actually happened (e.g. the receive took place).
123
-   * @param registrationTime registration time, the time the message is received
124
-   * @param type             type of event
125
-   * @param location         where the event took place
126
-   */
127
-  // TODO make package local
128
-  public HandlingEvent(final Cargo cargo,
129
-                       final Date completionTime,
130
-                       final Date registrationTime,
131
-                       final Type type,
132
-                       final Location location) {
133
-    Validate.notNull(cargo, "Cargo is required");
134
-    Validate.notNull(completionTime, "Completion time is required");
135
-    Validate.notNull(registrationTime, "Registration time is required");
136
-    Validate.notNull(type, "Handling event type is required");
137
-    Validate.notNull(location, "Location is required");
138
-
139
-    if (type.isVoyageRelated()) {
140
-      throw new IllegalArgumentException("Voyage is required for event type " + type);
141
-    }
142
-
143
-    this.sequenceNumber = EventSequenceNumber.next();
144
-    this.completionTime = new Date(completionTime.getTime());
145
-    this.registrationTime = new Date(registrationTime.getTime());
146
-    this.cargo = cargo;
147
-    this.activity = new HandlingActivity(type, location);
148
-  }
149
-
150
-  public EventSequenceNumber sequenceNumber() {
151
-    return sequenceNumber;
152
-  }
153
-
154
-  public HandlingActivity activity() {
155
-    return activity;
156
-  }
157
-
158
-  public Type type() {
159
-    return activity.type();
160
-  }
161
-
162
-  public Voyage voyage() {
163
-    return DomainObjectUtils.nullSafe(activity.voyage(), Voyage.NONE);
164
-  }
165
-
166
-  public Date completionTime() {
167
-    return new Date(this.completionTime.getTime());
168
-  }
169
-
170
-  public Date registrationTime() {
171
-    return new Date(this.registrationTime.getTime());
172
-  }
173
-
174
-  public Location location() {
175
-    return activity.location();
176
-  }
177
-
178
-  public Cargo cargo() {
179
-    return this.cargo;
180
-  }
181
-
182
-  @Override
183
-  public boolean equals(final Object o) {
184
-    if (this == o) return true;
185
-    if (o == null || getClass() != o.getClass()) return false;
186
-
187
-    final HandlingEvent event = (HandlingEvent) o;
188
-
189
-    return sameEventAs(event);
190
-  }
191
-
192
-  @Override
193
-  public boolean sameEventAs(final HandlingEvent other) {
194
-    return other != null && new EqualsBuilder().
195
-      append(this.cargo, other.cargo).
196
-      append(this.completionTime, other.completionTime).
197
-      append(this.activity, other.activity).
198
-      isEquals();
199
-  }
200
-
201
-  @Override
202
-  public int hashCode() {
203
-    return new HashCodeBuilder().
204
-      append(cargo).
205
-      append(completionTime).
206
-      append(activity).
207
-      toHashCode();
208
-  }
209
-
210
-  @Override
211
-  public String toString() {
212
-    return "Cargo: " + cargo +
213
-      "\nActivity: " + activity +
214
-      "\nCompleted on: " + completionTime +
215
-      "\nRegistered on: " + registrationTime;
216
-  }
217
-
218
-  HandlingEvent() {
219
-    // Needed by Hibernate
220
-  }
221
-
222
-
223
-  // Auto-generated surrogate key
224
-  @SuppressWarnings("UnusedDeclaration")
225
-  private Long id;
226
-
227
-}

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

@@ -1,89 +0,0 @@
1
-package se.citerus.dddsample.domain.model.handling;
2
-
3
-import se.citerus.dddsample.domain.model.cargo.Cargo;
4
-import se.citerus.dddsample.domain.model.cargo.CargoRepository;
5
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
6
-import se.citerus.dddsample.domain.model.location.Location;
7
-import se.citerus.dddsample.domain.model.location.LocationRepository;
8
-import se.citerus.dddsample.domain.model.location.UnLocode;
9
-import se.citerus.dddsample.domain.model.voyage.Voyage;
10
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
11
-import se.citerus.dddsample.domain.model.voyage.VoyageRepository;
12
-
13
-import java.util.Date;
14
-
15
-/**
16
- * Creates handling events.
17
- */
18
-public class HandlingEventFactory {
19
-
20
-  private final CargoRepository cargoRepository;
21
-  private final VoyageRepository voyageRepository;
22
-  private final LocationRepository locationRepository;
23
-
24
-  public HandlingEventFactory(final CargoRepository cargoRepository,
25
-                              final VoyageRepository voyageRepository,
26
-                              final LocationRepository locationRepository) {
27
-    this.cargoRepository = cargoRepository;
28
-    this.voyageRepository = voyageRepository;
29
-    this.locationRepository = locationRepository;
30
-  }
31
-
32
-  /**
33
-   * @param registrationTime time when this event was received by the system
34
-   * @param completionTime   when the event was completed, for example finished loading
35
-   * @param trackingId       cargo tracking id
36
-   * @param voyageNumber     voyage number
37
-   * @param unlocode         United Nations Location Code for the location of the event
38
-   * @param type             type of event
39
-   * @return A handling event.
40
-   * @throws UnknownVoyageException   if there's no voyage with this number
41
-   * @throws UnknownCargoException    if there's no cargo with this tracking id
42
-   * @throws UnknownLocationException if there's no location with this UN Locode
43
-   */
44
-  public HandlingEvent createHandlingEvent(Date registrationTime, Date completionTime, TrackingId trackingId, VoyageNumber voyageNumber, UnLocode unlocode, HandlingEvent.Type type)
45
-    throws CannotCreateHandlingEventException {
46
-    final Cargo cargo = findCargo(trackingId);
47
-    final Voyage voyage = findVoyage(voyageNumber);
48
-    final Location location = findLocation(unlocode);
49
-
50
-    try {
51
-      if (voyage == null) {
52
-        return new HandlingEvent(cargo, completionTime, registrationTime, type, location);
53
-      } else {
54
-        return new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage);
55
-      }
56
-    } catch (Exception e) {
57
-      throw new CannotCreateHandlingEventException(e);
58
-    }
59
-  }
60
-
61
-  private Cargo findCargo(TrackingId trackingId) throws UnknownCargoException {
62
-    final Cargo cargo = cargoRepository.find(trackingId);
63
-    if (cargo == null) throw new UnknownCargoException(trackingId);
64
-    return cargo;
65
-  }
66
-
67
-  private Voyage findVoyage(VoyageNumber voyageNumber) throws UnknownVoyageException {
68
-    if (voyageNumber == null) {
69
-      return null;
70
-    }
71
-
72
-    final Voyage voyage = voyageRepository.find(voyageNumber);
73
-    if (voyage == null) {
74
-      throw new UnknownVoyageException(voyageNumber);
75
-    }
76
-
77
-    return voyage;
78
-  }
79
-
80
-  private Location findLocation(final UnLocode unlocode) throws UnknownLocationException {
81
-    final Location location = locationRepository.find(unlocode);
82
-    if (location == null) {
83
-      throw new UnknownLocationException(unlocode);
84
-    }
85
-
86
-    return location;
87
-  }
88
-
89
-}

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

@@ -1,36 +0,0 @@
1
-package se.citerus.dddsample.domain.model.handling;
2
-
3
-import se.citerus.dddsample.domain.model.cargo.Cargo;
4
-import se.citerus.dddsample.domain.model.shared.EventSequenceNumber;
5
-
6
-/**
7
- * Handling event repository.
8
- */
9
-public interface HandlingEventRepository {
10
-
11
-  /**
12
-   * @param eventSequenceNumber event sequence number
13
-   * @return The handling event with this sequence number, or null if not found
14
-   */
15
-  HandlingEvent find(EventSequenceNumber eventSequenceNumber);
16
-
17
-  /**
18
-   * Stores a (new) handling event.
19
-   *
20
-   * @param event handling event to save
21
-   */
22
-  void store(HandlingEvent event);
23
-
24
-  /**
25
-   * @param cargo cargo
26
-   * @return The handling history of this cargo
27
-   */
28
-  HandlingHistory lookupHandlingHistoryOfCargo(Cargo cargo);
29
-
30
-  /**
31
-   *
32
-   * @param cargo cargo
33
-   * @return The most recent handling of the cargo, or null if it has never been handled.
34
-   */
35
-  HandlingEvent mostRecentHandling(Cargo cargo);
36
-}

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

@@ -1,136 +0,0 @@
1
-package se.citerus.dddsample.domain.model.handling;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import se.citerus.dddsample.domain.model.cargo.Cargo;
5
-import se.citerus.dddsample.domain.shared.ValueObject;
6
-
7
-import java.util.*;
8
-import static java.util.Collections.sort;
9
-
10
-/**
11
- * The handling history of a cargo.
12
- */
13
-public class HandlingHistory implements ValueObject<HandlingHistory> {
14
-
15
-  private final List<HandlingEvent> handlingEvents;
16
-  private final Cargo cargo;
17
-
18
-  public static HandlingHistory emptyForCargo(final Cargo cargo) {
19
-    return new HandlingHistory(cargo);
20
-  }
21
-
22
-  public static HandlingHistory fromEvents(final Collection<HandlingEvent> handlingEvents) {
23
-    return new HandlingHistory(handlingEvents);
24
-  }
25
-
26
-  private HandlingHistory(final Cargo cargo) {
27
-    Validate.notNull(cargo, "Cargo is required");
28
-    this.cargo = cargo;
29
-    handlingEvents = Collections.emptyList();
30
-  }
31
-
32
-  private HandlingHistory(final Collection<HandlingEvent> handlingEvents) {
33
-    Validate.notEmpty(handlingEvents, "Handling events are required");
34
-
35
-    this.cargo = uniqueCargo(handlingEvents);
36
-    this.handlingEvents = new ArrayList<HandlingEvent>(handlingEvents);
37
-  }
38
-
39
-  private Cargo uniqueCargo(final Collection<HandlingEvent> handlingEvents) {
40
-    final Iterator<HandlingEvent> it = handlingEvents.iterator();
41
-    final Cargo firstCargo = it.next().cargo();
42
-    Validate.notNull(firstCargo, "Cargo is required");
43
-
44
-    while (it.hasNext()) {
45
-      final Cargo nextCargo = it.next().cargo();
46
-      Validate.isTrue(firstCargo.sameAs(nextCargo),
47
-        "A handling history can only contain handling events for a unique cargo. " +
48
-          "First event is for cargo " + firstCargo + ", also discovered cargo " + nextCargo
49
-      );
50
-    }
51
-
52
-    return firstCargo;
53
-  }
54
-
55
-  /**
56
-   * @return A distinct list (no duplicate registrations) of handling events, ordered by completion time.
57
-   */
58
-  public List<HandlingEvent> distinctEventsByCompletionTime() {
59
-    final List<HandlingEvent> ordered = new ArrayList<HandlingEvent>(
60
-      new HashSet<HandlingEvent>(handlingEvents)
61
-    );
62
-    sort(ordered, BY_COMPLETION_TIME_COMPARATOR);
63
-    return Collections.unmodifiableList(ordered);
64
-  }
65
-
66
-  /**
67
-   * @return Filter a list of handling events, returning only the LOAD and UNLOAD events.
68
-   */
69
-  public List<HandlingEvent> physicalHandlingEvents(List<HandlingEvent> unfilteredEvents) {
70
-    final List<HandlingEvent> filtered = new ArrayList<HandlingEvent>();
71
-    for (HandlingEvent event : unfilteredEvents) {
72
-      if (event.type().equals(HandlingEvent.Type.RECEIVE)) filtered.add(event);
73
-      if (event.type().equals(HandlingEvent.Type.LOAD)) filtered.add(event);
74
-      if (event.type().equals(HandlingEvent.Type.UNLOAD)) filtered.add(event);
75
-      if (event.type().equals(HandlingEvent.Type.CLAIM)) filtered.add(event);
76
-    }
77
-    return Collections.unmodifiableList(filtered);
78
-  }
79
-
80
-  /**
81
-   * @return Most recently completed event, or null if the handling history is empty.
82
-   */
83
-  public HandlingEvent mostRecentlyCompletedEvent() {
84
-    final List<HandlingEvent> distinctEvents = distinctEventsByCompletionTime();
85
-    if (distinctEvents.isEmpty()) {
86
-      return null;
87
-    } else {
88
-      return distinctEvents.get(distinctEvents.size() - 1);
89
-    }
90
-  }
91
-
92
-  /**
93
-   * @return Most recently completed load or unload, or null if there have been none.
94
-   */
95
-  public HandlingEvent mostRecentPhysicalHandling() {
96
-    final List<HandlingEvent> loadsAndUnloads = physicalHandlingEvents(distinctEventsByCompletionTime());
97
-    if (loadsAndUnloads.isEmpty()) {
98
-      return null;
99
-    } else {
100
-      return loadsAndUnloads.get(loadsAndUnloads.size() - 1);
101
-    }
102
-  }
103
-
104
-  /**
105
-   * @return The cargo to which this handling history refers.
106
-   */
107
-  public Cargo cargo() {
108
-    return cargo;
109
-  }
110
-
111
-  @Override
112
-  public boolean sameValueAs(HandlingHistory other) {
113
-    return other != null && this.handlingEvents.equals(other.handlingEvents);
114
-  }
115
-
116
-  @Override
117
-  public boolean equals(Object o) {
118
-    if (this == o) return true;
119
-    if (o == null || getClass() != o.getClass()) return false;
120
-
121
-    final HandlingHistory other = (HandlingHistory) o;
122
-    return sameValueAs(other);
123
-  }
124
-
125
-  @Override
126
-  public int hashCode() {
127
-    return handlingEvents.hashCode();
128
-  }
129
-
130
-  private static final Comparator<HandlingEvent> BY_COMPLETION_TIME_COMPARATOR =
131
-    new Comparator<HandlingEvent>() {
132
-      public int compare(final HandlingEvent he1, final HandlingEvent he2) {
133
-        return he1.completionTime().compareTo(he2.completionTime());
134
-      }
135
-    };
136
-}

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

@@ -1,26 +0,0 @@
1
-package se.citerus.dddsample.domain.model.handling;
2
-
3
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
4
-
5
-/**
6
- * Thrown when trying to register an event with an unknown tracking id.
7
- */
8
-public final class UnknownCargoException extends CannotCreateHandlingEventException {
9
-
10
-  private final TrackingId trackingId;
11
-
12
-  /**
13
-   * @param trackingId cargo tracking id
14
-   */
15
-  public UnknownCargoException(final TrackingId trackingId) {
16
-    this.trackingId = trackingId;
17
-  }
18
-
19
-  /**
20
-   * {@inheritDoc}
21
-   */
22
-  @Override
23
-  public String getMessage() {
24
-    return "No cargo with tracking id " + trackingId.stringValue() + " exists in the system";
25
-  }
26
-}

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

@@ -1,17 +0,0 @@
1
-package se.citerus.dddsample.domain.model.handling;
2
-
3
-import se.citerus.dddsample.domain.model.location.UnLocode;
4
-
5
-public class UnknownLocationException extends CannotCreateHandlingEventException {
6
-
7
-  private final UnLocode unlocode;
8
-
9
-  public UnknownLocationException(final UnLocode unlocode) {
10
-    this.unlocode = unlocode;
11
-  }
12
-
13
-  @Override
14
-  public String getMessage() {
15
-    return "No location with UN locode " + unlocode.stringValue() + " exists in the system";
16
-  }
17
-}

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

@@ -1,20 +0,0 @@
1
-package se.citerus.dddsample.domain.model.handling;
2
-
3
-import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
4
-
5
-/**
6
- * Thrown when trying to register an event with an unknown carrier movement id.
7
- */
8
-public class UnknownVoyageException extends CannotCreateHandlingEventException {
9
-
10
-  private final VoyageNumber voyageNumber;
11
-
12
-  public UnknownVoyageException(VoyageNumber voyageNumber) {
13
-    this.voyageNumber = voyageNumber;
14
-  }
15
-
16
-  @Override
17
-  public String getMessage() {
18
-    return "No voyage with number " + voyageNumber.stringValue() + " exists in the system";
19
-  }
20
-}

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

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	The handling aggregate. HandlingEvent is the aggregate root.
5
-</p>
6
-</body>
7
-</html>

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

@@ -1,124 +0,0 @@
1
-package se.citerus.dddsample.domain.model.location;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import se.citerus.dddsample.domain.shared.Entity;
5
-
6
-import java.util.Arrays;
7
-import java.util.List;
8
-import java.util.regex.Pattern;
9
-
10
-/**
11
- * A geographical zone within which there are no customs restrictions or checks.
12
- */
13
-public class CustomsZone implements Entity<CustomsZone> {
14
-
15
-  private String code;
16
-  private String name;
17
-
18
-  // TODO: Find out what the standards are for this, if any. For now:
19
-  // For CustomsZone code, we are using the "country code" portion of the UnLocode,
20
-  // except within economic areas that are not countries, such as the EU. Then we make one up.
21
-  // Country code is exactly two letters, so we'll use 2 letters.
22
-  private static final Pattern VALID_PATTERN = Pattern.compile("[a-zA-Z]{2}");
23
-
24
-  /**
25
-   * Constructor.
26
-   *
27
-   * @param code code
28
-   * @param name name
29
-   */
30
-  public CustomsZone(final String code, final String name) {
31
-    Validate.notNull(code, "Code is required");
32
-    Validate.isTrue(VALID_PATTERN.matcher(code).matches(),
33
-      code + " is not a valid CustomsZone code (does not match pattern)");
34
-    Validate.notNull(name, "Name is required");
35
-    this.code = code.toUpperCase();
36
-    this.name = name;
37
-  }
38
-
39
-  /**
40
-   * Where would a Cargo enter this CustomsZone if it were
41
-   * following this route. Note that specific voyages, etc do not
42
-   * matter, only the sequence of Locations.
43
-   *
44
-   * @param route
45
-   * @return
46
-   */
47
-  public Location entryPoint(List<Location> route) {
48
-    for (Location location : route) {
49
-      if (this.includes(location)) return location;
50
-    }
51
-    return null; //The route does not enter this CustomsZone
52
-  }
53
-
54
-  /**
55
-   * Convenience method for testing. Usage in application would be
56
-   * entryPoint(List<Location) route)
57
-   *
58
-   * @param route
59
-   * @return
60
-   */
61
-  public Location entryPoint(Location... route) {
62
-    return entryPoint(Arrays.asList(route));
63
-  }
64
-
65
-  /**
66
-   * If the rules of the CustomsZone were different or more complex,
67
-   * this is where that rule would be expressed. For the example, we'll
68
-   * just use the basic rule -- customs clearance is at the entry point.
69
-   *
70
-   * @param route
71
-   * @return
72
-   */
73
-//   public Location clearancePoint(List<Location> route) {
74
-//     return entryPoint(route);
75
-//   }
76
-
77
-  /**
78
-   * Convenience method for testing. Usage in application would be
79
-   * clearancePoint(List<Location) route)
80
-   *
81
-   * @param route
82
-   * @return
83
-   */
84
-//   @SuppressWarnings("unchecked")
85
-//   public Location clearancePoint(Location ... route) {
86
-//     return clearancePoint(Arrays.asList(route));
87
-//   }
88
-//
89
-
90
-
91
-  /**
92
-   * @return Code, always upper case.
93
-   */
94
-  public String code() {
95
-    return code;
96
-  }
97
-
98
-  /**
99
-   * @return The name.
100
-   */
101
-  public String name() {
102
-    return name;
103
-  }
104
-
105
-  @Override
106
-  public String toString() {
107
-    return code + "[" + name + "]";
108
-  }
109
-
110
-  @Override
111
-  public boolean sameAs(CustomsZone other) {
112
-    return code.equals(other.code);
113
-  }
114
-
115
-  CustomsZone() {
116
-    // Needed by Hibernate
117
-  }
118
-
119
-  public boolean includes(Location location) {
120
-    return this.sameAs(location.customsZone());
121
-  }
122
-
123
-
124
-}

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

@@ -1,117 +0,0 @@
1
-package se.citerus.dddsample.domain.model.location;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import se.citerus.dddsample.domain.shared.Entity;
5
-
6
-import java.util.TimeZone;
7
-
8
-/**
9
- * A location is our model is stops on a journey, such as cargo
10
- * origin or destination, or carrier movement endpoints.
11
- * <p/>
12
- * It is uniquely identified by a UN Locode.
13
- */
14
-public final class Location implements Entity<Location> {
15
-
16
-  private UnLocode unLocode;
17
-  private String name;
18
-  private TimeZone timeZone;
19
-  private CustomsZone customsZone;
20
-
21
-  /**
22
-   * Special Location object that marks an unknown location.
23
-   */
24
-  public static final Location UNKNOWN = new Location(
25
-    new UnLocode("XXXXX"), "Unknown location", TimeZone.getTimeZone("Zulu"), null
26
-  );
27
-
28
-  /**
29
-   * Package-level constructor, visible for test only.
30
-   *
31
-   * @param unLocode    UN Locode
32
-   * @param name        location name
33
-   * @param timeZone
34
-   * @param customsZone
35
-   * @throws IllegalArgumentException if the UN Locode or name is null
36
-   */
37
-  Location(final UnLocode unLocode, final String name, final TimeZone timeZone, final CustomsZone customsZone) {
38
-    Validate.notNull(unLocode);
39
-    Validate.notNull(name);
40
-    Validate.notNull(timeZone);
41
-//    Validate.notNull(customsZone);
42
-
43
-    this.unLocode = unLocode;
44
-    this.name = name;
45
-    this.timeZone = timeZone;
46
-    this.customsZone = customsZone;
47
-  }
48
-
49
-  /**
50
-   * @return UN Locode for this location.
51
-   */
52
-  public UnLocode unLocode() {
53
-    return unLocode;
54
-  }
55
-
56
-  /**
57
-   * @return Actual name of this location, e.g. "Stockholm".
58
-   */
59
-  public String name() {
60
-    return name;
61
-  }
62
-
63
-  /**
64
-   * @return Customs zone of this location.
65
-   */
66
-  public CustomsZone customsZone() {
67
-    return customsZone;
68
-  }
69
-
70
-  /**
71
-   * @param object to compare
72
-   * @return Since this is an entity this will be true iff UN locodes are equal.
73
-   */
74
-  @Override
75
-  public boolean equals(final Object object) {
76
-    if (object == null) {
77
-      return false;
78
-    }
79
-    if (this == object) {
80
-      return true;
81
-    }
82
-    if (!(object instanceof Location)) {
83
-      return false;
84
-    }
85
-    Location other = (Location) object;
86
-    return sameAs(other);
87
-  }
88
-
89
-  @Override
90
-  public boolean sameAs(final Location other) {
91
-    return this.unLocode.sameValueAs(other.unLocode);
92
-  }
93
-
94
-  /**
95
-   * @return Hash code of UN locode.
96
-   */
97
-  @Override
98
-  public int hashCode() {
99
-    return unLocode.hashCode();
100
-  }
101
-
102
-  @Override
103
-  public String toString() {
104
-    return name + " [" + unLocode + "]";
105
-  }
106
-
107
-  Location() {
108
-    // Needed by Hibernate
109
-  }
110
-
111
-  private Long id;
112
-
113
-  public TimeZone timeZone() {
114
-    return timeZone;
115
-  }
116
-
117
-}

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

@@ -1,22 +0,0 @@
1
-package se.citerus.dddsample.domain.model.location;
2
-
3
-import java.util.List;
4
-
5
-public interface LocationRepository {
6
-
7
-  /**
8
-   * Finds a location using given unlocode.
9
-   *
10
-   * @param unLocode UNLocode.
11
-   * @return Location.
12
-   */
13
-  Location find(UnLocode unLocode);
14
-
15
-  /**
16
-   * Finds all locations.
17
-   *
18
-   * @return All locations.
19
-   */
20
-  List<Location> findAll();
21
-
22
-}

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

@@ -1,64 +0,0 @@
1
-package se.citerus.dddsample.domain.model.location;
2
-
3
-import java.lang.reflect.Field;
4
-import java.util.*;
5
-
6
-/**
7
- * Sample locations, for test purposes.
8
- */
9
-public class SampleLocations {
10
-  private static final TimeZone CHINA = TimeZone.getTimeZone("Asia/Shanghai");
11
-  private static final TimeZone CENTRAL_EUROPE = TimeZone.getTimeZone("Europe/Stockholm");
12
-  private static final TimeZone JAPAN = TimeZone.getTimeZone("Asia/Tokyo");
13
-  private static final TimeZone EASTERN = TimeZone.getTimeZone("America/New_York");
14
-  private static final TimeZone CENTRAL = TimeZone.getTimeZone("America/Chicago");
15
-  private static final TimeZone PACIFIC = TimeZone.getTimeZone("America/Los_Angeles");
16
-  private static final TimeZone EASTERN_AUSTRALIA = TimeZone.getTimeZone("Australia/Melbourne");
17
-
18
-  public static final CustomsZone US = new CustomsZone("US", "United States");
19
-  public static final CustomsZone EU = new CustomsZone("EU", "European Union");
20
-  public static final CustomsZone CN = new CustomsZone("CN", "United States");
21
-  public static final CustomsZone AU = new CustomsZone("AU", "Australia");
22
-  public static final CustomsZone JN = new CustomsZone("JN", "Japan");
23
-
24
-  public static final Location HONGKONG = new Location(new UnLocode("CNHKG"), "Hongkong", CHINA, CN);
25
-  public static final Location MELBOURNE = new Location(new UnLocode("AUMEL"), "Melbourne", EASTERN_AUSTRALIA, AU);
26
-  public static final Location STOCKHOLM = new Location(new UnLocode("SESTO"), "Stockholm", CENTRAL_EUROPE, EU);
27
-  public static final Location HELSINKI = new Location(new UnLocode("FIHEL"), "Helsinki", CENTRAL_EUROPE, EU);
28
-  public static final Location CHICAGO = new Location(new UnLocode("USCHI"), "Chicago", CENTRAL, US);
29
-  public static final Location LONGBEACH = new Location(new UnLocode("USLBG"), "Long Beach", PACIFIC, US);
30
-  public static final Location OAKLAND = new Location(new UnLocode("USOAK"), "Oakland", PACIFIC, US);
31
-  public static final Location SEATTLE = new Location(new UnLocode("USSEA"), "Seattle", PACIFIC, US);
32
-  public static final Location TOKYO = new Location(new UnLocode("JNTKO"), "Tokyo", JAPAN, JN);
33
-  public static final Location HAMBURG = new Location(new UnLocode("DEHAM"), "Hamburg", CENTRAL_EUROPE, EU);
34
-  public static final Location SHANGHAI = new Location(new UnLocode("CNSHA"), "Shanghai", CHINA, CN);
35
-  public static final Location ROTTERDAM = new Location(new UnLocode("NLRTM"), "Rotterdam", CENTRAL_EUROPE, EU);
36
-  public static final Location GOTHENBURG = new Location(new UnLocode("SEGOT"), "Göteborg", CENTRAL_EUROPE, EU);
37
-  public static final Location HANGZOU = new Location(new UnLocode("CNHGH"), "Hangzhou", CHINA, CN);
38
-  public static final Location NEWYORK = new Location(new UnLocode("USNYC"), "New York", EASTERN, US);
39
-  public static final Location DALLAS = new Location(new UnLocode("USDAL"), "Dallas", CENTRAL, US);
40
-
41
-  public static final Map<UnLocode, Location> ALL = new HashMap<UnLocode, Location>();
42
-
43
-  static {
44
-    for (Field field : SampleLocations.class.getDeclaredFields()) {
45
-      if (field.getType().equals(Location.class)) {
46
-        try {
47
-          Location location = (Location) field.get(null);
48
-          ALL.put(location.unLocode(), location);
49
-        } catch (IllegalAccessException e) {
50
-          throw new RuntimeException(e);
51
-        }
52
-      }
53
-    }
54
-  }
55
-
56
-  public static List<Location> getAll() {
57
-    return new ArrayList<Location>(ALL.values());
58
-  }
59
-
60
-  public static Location lookup(UnLocode unLocode) {
61
-    return ALL.get(unLocode);
62
-  }
63
-
64
-}

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

@@ -1,71 +0,0 @@
1
-package se.citerus.dddsample.domain.model.location;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import se.citerus.dddsample.domain.shared.ValueObject;
5
-
6
-import java.util.regex.Pattern;
7
-
8
-/**
9
- * United nations location code.
10
- * <p/>
11
- * http://www.unece.org/cefact/locode/
12
- * http://www.unece.org/cefact/locode/DocColumnDescription.htm#LOCODE
13
- */
14
-public final class UnLocode implements ValueObject<UnLocode> {
15
-
16
-  private String unlocode;
17
-
18
-  // Country code is exactly two letters.
19
-  // Location code is usually three letters, but may contain the numbers 2-9 as well
20
-  private static final Pattern VALID_PATTERN = Pattern.compile("[a-zA-Z]{2}[a-zA-Z2-9]{3}");
21
-
22
-  /**
23
-   * Constructor.
24
-   *
25
-   * @param countryAndLocation Location string.
26
-   */
27
-  public UnLocode(final String countryAndLocation) {
28
-    Validate.notNull(countryAndLocation, "Country and location may not be null");
29
-    Validate.isTrue(VALID_PATTERN.matcher(countryAndLocation).matches(),
30
-      countryAndLocation + " is not a valid UN/LOCODE (does not match pattern)");
31
-
32
-    this.unlocode = countryAndLocation.toUpperCase();
33
-  }
34
-
35
-  /**
36
-   * @return country code and location code concatenated, always upper case.
37
-   */
38
-  public String stringValue() {
39
-    return unlocode;
40
-  }
41
-
42
-  @Override
43
-  public boolean equals(final Object o) {
44
-    if (this == o) return true;
45
-    if (o == null || getClass() != o.getClass()) return false;
46
-
47
-    UnLocode other = (UnLocode) o;
48
-
49
-    return sameValueAs(other);
50
-  }
51
-
52
-  @Override
53
-  public int hashCode() {
54
-    return unlocode.hashCode();
55
-  }
56
-
57
-  @Override
58
-  public boolean sameValueAs(UnLocode other) {
59
-    return other != null && this.unlocode.equals(other.unlocode);
60
-  }
61
-
62
-  @Override
63
-  public String toString() {
64
-    return stringValue();
65
-  }
66
-
67
-  UnLocode() {
68
-    // Needed by Hibernate
69
-  }
70
-
71
-}

+ 0
- 7
dddsample/src/main/java/se/citerus/dddsample/domain/model/location/package.html Просмотреть файл

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	The location aggregate. Location is the aggregate root.
5
-</p>
6
-</body>
7
-</html>

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

@@ -1,9 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	The domain model. This is the heart of the application. Each aggregate is contained in
5
-	its own subpackage, along with the repository interface, factories and exceptions where
6
-	applicable.
7
-</p>
8
-</body>
9
-</html>

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

@@ -1,51 +0,0 @@
1
-package se.citerus.dddsample.domain.model.shared;
2
-
3
-import se.citerus.dddsample.domain.shared.ValueObject;
4
-
5
-import java.util.concurrent.atomic.AtomicLong;
6
-
7
-public class EventSequenceNumber implements ValueObject<EventSequenceNumber> {
8
-
9
-  private long value;
10
-  private static final AtomicLong SEQUENCE = new AtomicLong(System.currentTimeMillis());
11
-
12
-  private EventSequenceNumber(final long value) {
13
-    this.value = value;
14
-  }
15
-
16
-  public static EventSequenceNumber next() {
17
-    return new EventSequenceNumber(SEQUENCE.getAndIncrement());
18
-  }
19
-
20
-  public long longValue() {
21
-    return value;
22
-  }
23
-
24
-  @Override
25
-  public boolean sameValueAs(final EventSequenceNumber other) {
26
-    return false;
27
-  }
28
-
29
-  @Override
30
-  public boolean equals(Object o) {
31
-    if (this == o) return true;
32
-    if (o == null || getClass() != o.getClass()) return false;
33
-
34
-    return sameValueAs((EventSequenceNumber) o);
35
-  }
36
-
37
-  @Override
38
-  public int hashCode() {
39
-    return Long.valueOf(value).hashCode();
40
-  }
41
-
42
-  @Override
43
-  public String toString() {
44
-    return String.valueOf(value);
45
-  }
46
-
47
-  EventSequenceNumber() {
48
-    // Needed by Hibernate
49
-  }
50
-
51
-}

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

@@ -1,94 +0,0 @@
1
-package se.citerus.dddsample.domain.model.shared;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import org.apache.commons.lang.builder.EqualsBuilder;
5
-import org.apache.commons.lang.builder.HashCodeBuilder;
6
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
7
-import se.citerus.dddsample.domain.model.location.Location;
8
-import se.citerus.dddsample.domain.model.voyage.Voyage;
9
-import se.citerus.dddsample.domain.shared.ValueObject;
10
-
11
-/**
12
- * A handling activity represents how and where a cargo can be handled,
13
- * and can be used to express predictions about what is expected to
14
- * happen to a cargo in the future.
15
- */
16
-public class HandlingActivity implements ValueObject<HandlingActivity> {
17
-
18
-  // TODO introduce something like this (?):
19
-  // HandlingActivity.loadOnto(voyage).in(location)
20
-  // HandlingActivity.claimIn(location)
21
-
22
-  private HandlingEvent.Type type;
23
-  private Location location;
24
-  private Voyage voyage;
25
-
26
-  public HandlingActivity(final HandlingEvent.Type type, final Location location) {
27
-    Validate.notNull(type, "Handling event type is required");
28
-    Validate.notNull(location, "Location is required");
29
-
30
-    this.type = type;
31
-    this.location = location;
32
-  }
33
-
34
-  public HandlingActivity(final HandlingEvent.Type type, final Location location, final Voyage voyage) {
35
-    Validate.notNull(type, "Handling event type is required");
36
-    Validate.notNull(location, "Location is required");
37
-    Validate.notNull(location, "Voyage is required");
38
-
39
-    this.type = type;
40
-    this.location = location;
41
-    this.voyage = voyage;
42
-  }
43
-
44
-  public HandlingEvent.Type type() {
45
-    return type;
46
-  }
47
-
48
-  public Location location() {
49
-    return location;
50
-  }
51
-
52
-  public Voyage voyage() {
53
-    return voyage;
54
-  }
55
-
56
-  @Override
57
-  public boolean sameValueAs(final HandlingActivity other) {
58
-    return other != null && new EqualsBuilder().
59
-      append(this.type, other.type).
60
-      append(this.location, other.location).
61
-      append(this.voyage, other.voyage).
62
-      isEquals();
63
-  }
64
-
65
-  @Override
66
-  public int hashCode() {
67
-    return new HashCodeBuilder().
68
-      append(this.type).
69
-      append(this.location).
70
-      append(this.voyage).
71
-      toHashCode();
72
-  }
73
-
74
-  @Override
75
-  public boolean equals(final Object obj) {
76
-    if (obj == this) return true;
77
-    if (obj == null) return false;
78
-    if (obj.getClass() != this.getClass()) return false;
79
-
80
-    HandlingActivity other = (HandlingActivity) obj;
81
-
82
-    return sameValueAs(other);
83
-  }
84
-
85
-  @Override
86
-  public String toString() {
87
-    return type + " in " + location + (voyage != null ? ", " + voyage : "");
88
-  }
89
-
90
-  HandlingActivity() {
91
-    // Needed by Hibernate
92
-  }
93
-
94
-}

+ 0
- 7
dddsample/src/main/java/se/citerus/dddsample/domain/model/shared/package.html Просмотреть файл

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	Value objects that are shared between several aggregates.
5
-</p>
6
-</body>
7
-</html>

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

@@ -1,125 +0,0 @@
1
-package se.citerus.dddsample.domain.model.voyage;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import org.apache.commons.lang.builder.EqualsBuilder;
5
-import org.apache.commons.lang.builder.HashCodeBuilder;
6
-import se.citerus.dddsample.domain.model.location.Location;
7
-import se.citerus.dddsample.domain.shared.ValueObject;
8
-
9
-import java.util.Date;
10
-
11
-
12
-/**
13
- * A carrier movement is a vessel voyage from one location to another.
14
- */
15
-public final class CarrierMovement implements ValueObject<CarrierMovement> {
16
-
17
-  private Location departureLocation;
18
-  private Location arrivalLocation;
19
-  private Date departureTime;
20
-  private Date arrivalTime;
21
-
22
-  // Null object pattern 
23
-  public static final CarrierMovement NONE = new CarrierMovement(
24
-    Location.UNKNOWN, Location.UNKNOWN,
25
-    new Date(0), new Date(0)
26
-  );
27
-
28
-  /**
29
-   * Constructor.
30
-   *
31
-   * @param departureLocation location of departure
32
-   * @param arrivalLocation   location of arrival
33
-   * @param departureTime     time of departure
34
-   * @param arrivalTime       time of arrival
35
-   */
36
-  // TODO make package local
37
-  public CarrierMovement(Location departureLocation,
38
-                         Location arrivalLocation,
39
-                         Date departureTime,
40
-                         Date arrivalTime) {
41
-    Validate.noNullElements(new Object[]{departureLocation, arrivalLocation, departureTime, arrivalTime});
42
-    this.departureTime = departureTime;
43
-    this.arrivalTime = arrivalTime;
44
-    this.departureLocation = departureLocation;
45
-    this.arrivalLocation = arrivalLocation;
46
-  }
47
-
48
-  /**
49
-   * @return Departure location.
50
-   */
51
-  public Location departureLocation() {
52
-    return departureLocation;
53
-  }
54
-
55
-  /**
56
-   * @return Arrival location.
57
-   */
58
-  public Location arrivalLocation() {
59
-    return arrivalLocation;
60
-  }
61
-
62
-  /**
63
-   * @return Time of departure.
64
-   */
65
-  public Date departureTime() {
66
-    return new Date(departureTime.getTime());
67
-  }
68
-
69
-  /**
70
-   * @return Time of arrival.
71
-   */
72
-  public Date arrivalTime() {
73
-    return new Date(arrivalTime.getTime());
74
-  }
75
-
76
-  /**
77
-   * @param newDepartureTime new departure time
78
-   * @return A new CarrierMovement which is a copy of the old one but with a new departure time
79
-   */
80
-  CarrierMovement withDepartureTime(final Date newDepartureTime) {
81
-    return new CarrierMovement(
82
-      departureLocation,
83
-      arrivalLocation,
84
-      newDepartureTime,
85
-      arrivalTime
86
-    );
87
-  }
88
-
89
-  @Override
90
-  public boolean equals(final Object o) {
91
-    if (this == o) return true;
92
-    if (o == null || getClass() != o.getClass()) return false;
93
-
94
-    final CarrierMovement that = (CarrierMovement) o;
95
-
96
-    return sameValueAs(that);
97
-  }
98
-
99
-  @Override
100
-  public int hashCode() {
101
-    return new HashCodeBuilder().
102
-      append(this.departureLocation).
103
-      append(this.departureTime).
104
-      append(this.arrivalLocation).
105
-      append(this.arrivalTime).
106
-      toHashCode();
107
-  }
108
-
109
-  @Override
110
-  public boolean sameValueAs(CarrierMovement other) {
111
-    return other != null && new EqualsBuilder().
112
-      append(this.departureLocation, other.departureLocation).
113
-      append(this.departureTime, other.departureTime).
114
-      append(this.arrivalLocation, other.arrivalLocation).
115
-      append(this.arrivalTime, other.arrivalTime).
116
-      isEquals();
117
-  }
118
-
119
-  CarrierMovement() {
120
-    // Needed by Hibernate
121
-  }
122
-
123
-  // Auto-generated surrogate key
124
-  private Long id;
125
-}

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

@@ -1,137 +0,0 @@
1
-package se.citerus.dddsample.domain.model.voyage;
2
-
3
-import static se.citerus.dddsample.application.util.DateTestUtil.toDate;
4
-import se.citerus.dddsample.domain.model.location.Location;
5
-import static se.citerus.dddsample.domain.model.location.SampleLocations.*;
6
-
7
-import java.lang.reflect.Field;
8
-import java.util.*;
9
-
10
-/**
11
- * Sample carrier movements, for test purposes.
12
- */
13
-public class SampleVoyages {
14
-
15
-  public static final Voyage CM001 = createVoyage("CM001", STOCKHOLM, HAMBURG);
16
-  public static final Voyage CM002 = createVoyage("CM002", HAMBURG, HONGKONG);
17
-  public static final Voyage CM003 = createVoyage("CM003", HONGKONG, NEWYORK);
18
-  public static final Voyage CM004 = createVoyage("CM004", NEWYORK, CHICAGO);
19
-  public static final Voyage CM005 = createVoyage("CM005", CHICAGO, HAMBURG);
20
-  public static final Voyage CM006 = createVoyage("CM006", HAMBURG, HANGZOU);
21
-
22
-  private static Voyage createVoyage(String id, Location from, Location to) {
23
-    return new Voyage(new VoyageNumber(id), new Schedule(Arrays.asList(
24
-      new CarrierMovement(from, to, new Date(), new Date())
25
-    )));
26
-  }
27
-
28
-  // TODO CM00[1-6] and createVoyage are deprecated. Remove and refactor tests.
29
-
30
-  public final static Voyage v100 = new Voyage.Builder(new VoyageNumber("V100"), HONGKONG).
31
-    addMovement(TOKYO, toDate("2009-03-03"), toDate("2009-03-05")).
32
-    addMovement(LONGBEACH, toDate("2009-03-06"), toDate("2009-03-09")).
33
-    build();
34
-  public final static Voyage v200 = new Voyage.Builder(new VoyageNumber("V200"), SHANGHAI).
35
-    addMovement(NEWYORK, toDate("2009-03-06"), toDate("2009-03-08")).
36
-    addMovement(ROTTERDAM, toDate("2009-03-10"), toDate("2009-03-14")).
37
-    addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-16")).
38
-    build();
39
-  public final static Voyage v250 = new Voyage.Builder(new VoyageNumber("V250"), LONGBEACH).
40
-    addMovement(DALLAS, toDate("2009-03-06"), toDate("2009-03-08")).
41
-    addMovement(NEWYORK, toDate("2009-03-10"), toDate("2009-03-14")).
42
-    build();
43
-  public final static Voyage v300 = new Voyage.Builder(new VoyageNumber("V300"), TOKYO).
44
-    addMovement(ROTTERDAM, toDate("2009-03-08"), toDate("2009-03-11")).
45
-    addMovement(HAMBURG, toDate("2009-03-11"), toDate("2009-03-12")).
46
-    addMovement(MELBOURNE, toDate("2009-03-14"), toDate("2009-03-18")).
47
-    addMovement(TOKYO, toDate("2009-03-19"), toDate("2009-03-21")).
48
-    build();
49
-  public final static Voyage v400 = new Voyage.Builder(new VoyageNumber("V400"), HAMBURG).
50
-    addMovement(STOCKHOLM, toDate("2009-03-14"), toDate("2009-03-15")).
51
-    addMovement(HELSINKI, toDate("2009-03-15"), toDate("2009-03-16")).
52
-    addMovement(HAMBURG, toDate("2009-03-20"), toDate("2009-03-22")).
53
-    build();
54
-
55
-  /**
56
-   * Voyage number 0100S (by ship)
57
-   * <p/>
58
-   * Hongkong - Hangzou - Tokyo - Melbourne - New York
59
-   */
60
-  public static final Voyage HONGKONG_TO_NEW_YORK =
61
-    new Voyage.Builder(new VoyageNumber("0100S"), HONGKONG).
62
-      addMovement(HANGZOU, toDate("2008-10-01", "12:00"), toDate("2008-10-03", "14:30")).
63
-      addMovement(TOKYO, toDate("2008-10-03", "21:00"), toDate("2008-10-06", "06:15")).
64
-      addMovement(MELBOURNE, toDate("2008-10-06", "11:00"), toDate("2008-10-12", "11:30")).
65
-      addMovement(NEWYORK, toDate("2008-10-14", "12:00"), toDate("2008-10-23", "23:10")).
66
-      build();
67
-
68
-
69
-  /**
70
-   * Voyage number 0200T (by train)
71
-   * <p/>
72
-   * New York - Chicago - Dallas
73
-   */
74
-  public static final Voyage NEW_YORK_TO_DALLAS =
75
-    new Voyage.Builder(new VoyageNumber("0200T"), NEWYORK).
76
-      addMovement(CHICAGO, toDate("2008-10-24", "07:00"), toDate("2008-10-24", "17:45")).
77
-      addMovement(DALLAS, toDate("2008-10-24", "21:25"), toDate("2008-10-25", "19:30")).
78
-      build();
79
-
80
-  /**
81
-   * Voyage number 0300A (by airplane)
82
-   * <p/>
83
-   * Dallas - Hamburg - Stockholm - Helsinki
84
-   */
85
-  public static final Voyage DALLAS_TO_HELSINKI =
86
-    new Voyage.Builder(new VoyageNumber("0300A"), DALLAS).
87
-      addMovement(HAMBURG, toDate("2008-10-29", "03:30"), toDate("2008-10-31", "14:00")).
88
-      addMovement(STOCKHOLM, toDate("2008-11-01", "15:20"), toDate("2008-11-01", "18:40")).
89
-      addMovement(HELSINKI, toDate("2008-11-02", "09:00"), toDate("2008-11-02", "11:15")).
90
-      build();
91
-
92
-  /**
93
-   * Voyage number 0301S (by ship)
94
-   * <p/>
95
-   * Dallas - Hamburg - Stockholm - Helsinki, alternate route
96
-   */
97
-  public static final Voyage DALLAS_TO_HELSINKI_ALT =
98
-    new Voyage.Builder(new VoyageNumber("0301S"), DALLAS).
99
-      addMovement(HELSINKI, toDate("2008-10-29", "03:30"), toDate("2008-11-05", "15:45")).
100
-      build();
101
-
102
-  /**
103
-   * Voyage number 0400S (by ship)
104
-   * <p/>
105
-   * Helsinki - Rotterdam - Shanghai - Hongkong
106
-   */
107
-  public static final Voyage HELSINKI_TO_HONGKONG =
108
-    new Voyage.Builder(new VoyageNumber("0400S"), HELSINKI).
109
-      addMovement(ROTTERDAM, toDate("2008-11-04", "05:50"), toDate("2008-11-06", "14:10")).
110
-      addMovement(SHANGHAI, toDate("2008-11-10", "21:45"), toDate("2008-11-22", "16:40")).
111
-      addMovement(HONGKONG, toDate("2008-11-24", "07:00"), toDate("2008-11-28", "13:37")).
112
-      build();
113
-
114
-  public static final Map<VoyageNumber, Voyage> ALL = new HashMap();
115
-
116
-  static {
117
-    for (Field field : SampleVoyages.class.getDeclaredFields()) {
118
-      if (field.getType().equals(Voyage.class)) {
119
-        try {
120
-          Voyage voyage = (Voyage) field.get(null);
121
-          ALL.put(voyage.voyageNumber(), voyage);
122
-        } catch (IllegalAccessException e) {
123
-          throw new RuntimeException(e);
124
-        }
125
-      }
126
-    }
127
-  }
128
-
129
-  public static List<Voyage> getAll() {
130
-    return new ArrayList<Voyage>(ALL.values());
131
-  }
132
-
133
-  public static Voyage lookup(VoyageNumber voyageNumber) {
134
-    return ALL.get(voyageNumber);
135
-  }
136
-
137
-}

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

@@ -1,85 +0,0 @@
1
-package se.citerus.dddsample.domain.model.voyage;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import org.apache.commons.lang.builder.HashCodeBuilder;
5
-import se.citerus.dddsample.domain.model.location.Location;
6
-import se.citerus.dddsample.domain.shared.ValueObject;
7
-
8
-import java.util.Collections;
9
-import java.util.Date;
10
-import java.util.List;
11
-
12
-/**
13
- * A voyage schedule.
14
- */
15
-public class Schedule implements ValueObject<Schedule> {
16
-
17
-  private List<CarrierMovement> carrierMovements;
18
-
19
-  public static final Schedule EMPTY = new Schedule();
20
-
21
-  Schedule(final List<CarrierMovement> carrierMovements) {
22
-    Validate.notNull(carrierMovements);
23
-    Validate.noNullElements(carrierMovements);
24
-    Validate.notEmpty(carrierMovements);
25
-
26
-    this.carrierMovements = carrierMovements;
27
-  }
28
-
29
-  /**
30
-   * @return Carrier movements.
31
-   */
32
-  public List<CarrierMovement> carrierMovements() {
33
-    return Collections.unmodifiableList(carrierMovements);
34
-  }
35
-
36
-  /**
37
-   * @param location location of departure
38
-   * @return Date of departure from this location, or null if it's not part of the voyage.
39
-   */
40
-  public Date departureTimeAt(final Location location) {
41
-    for (CarrierMovement movement : carrierMovements) {
42
-      if (movement.departureLocation().sameAs(location)) {
43
-        return movement.departureTime();
44
-      }
45
-    }
46
-    return null;
47
-  }
48
-
49
-  /**
50
-   * @param location location of arrival
51
-   * @return Date of arrival at this location, or null if it's not part of the voyage.
52
-   */
53
-  public Date arrivalTimeAt(final Location location) {
54
-    for (CarrierMovement movement : carrierMovements) {
55
-      if (movement.arrivalLocation().sameAs(location)) {
56
-        return movement.arrivalTime();
57
-      }
58
-    }
59
-    return null;
60
-  }
61
-
62
-  @Override
63
-  public boolean sameValueAs(final Schedule other) {
64
-    return other != null && this.carrierMovements.equals(other.carrierMovements);
65
-  }
66
-
67
-  @Override
68
-  public boolean equals(final Object o) {
69
-    if (this == o) return true;
70
-    if (o == null || getClass() != o.getClass()) return false;
71
-
72
-    final Schedule that = (Schedule) o;
73
-
74
-    return sameValueAs(that);
75
-  }
76
-
77
-  @Override
78
-  public int hashCode() {
79
-    return new HashCodeBuilder().append(this.carrierMovements).toHashCode();
80
-  }
81
-
82
-  Schedule() {
83
-    // Needed by Hibernate
84
-  }
85
-}

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

@@ -1,132 +0,0 @@
1
-package se.citerus.dddsample.domain.model.voyage;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import se.citerus.dddsample.domain.model.location.Location;
5
-import se.citerus.dddsample.domain.shared.Entity;
6
-
7
-import java.util.ArrayList;
8
-import java.util.Date;
9
-import java.util.List;
10
-
11
-/**
12
- * A Voyage.
13
- */
14
-public class Voyage implements Entity<Voyage> {
15
-
16
-  private VoyageNumber voyageNumber;
17
-  private Schedule schedule;
18
-
19
-  // Null object pattern
20
-  public static final Voyage NONE = new Voyage(
21
-    new VoyageNumber(""), Schedule.EMPTY
22
-  );
23
-
24
-  public Voyage(final VoyageNumber voyageNumber, final Schedule schedule) {
25
-    Validate.notNull(voyageNumber, "Voyage number is required");
26
-    Validate.notNull(schedule, "Schedule is required");
27
-
28
-    this.voyageNumber = voyageNumber;
29
-    this.schedule = schedule;
30
-  }
31
-
32
-  /**
33
-   * @return Voyage number.
34
-   */
35
-  public VoyageNumber voyageNumber() {
36
-    return voyageNumber;
37
-  }
38
-
39
-  /**
40
-   * @return Schedule.
41
-   */
42
-  public Schedule schedule() {
43
-    return schedule;
44
-  }
45
-
46
-  /**
47
-   * @param location         location from where the rescheduled departure happens.
48
-   * @param newDepartureTime new departure time
49
-   */
50
-  public void departureRescheduled(final Location location, final Date newDepartureTime) {
51
-    // TODO Change departure/arrival by diffs instead of absolute times
52
-
53
-    final int size = schedule.carrierMovements().size();
54
-    final List<CarrierMovement> carrierMovements = new ArrayList<CarrierMovement>(size);
55
-
56
-    for (CarrierMovement carrierMovement : schedule.carrierMovements()) {
57
-      if (carrierMovement.departureLocation().sameAs(location)) {
58
-        carrierMovements.add(carrierMovement.withDepartureTime(newDepartureTime));
59
-      } else {
60
-        carrierMovements.add(carrierMovement);
61
-      }
62
-    }
63
-
64
-    this.schedule = new Schedule(carrierMovements);
65
-  }
66
-
67
-  @Override
68
-  public int hashCode() {
69
-    return voyageNumber.hashCode();
70
-  }
71
-
72
-  @Override
73
-  public boolean equals(Object o) {
74
-    if (this == o) return true;
75
-    if (o == null) return false;
76
-    if (!(o instanceof Voyage)) return false;
77
-
78
-    final Voyage that = (Voyage) o;
79
-
80
-    return sameAs(that);
81
-  }
82
-
83
-  @Override
84
-  public boolean sameAs(Voyage other) {
85
-    return other != null && this.voyageNumber().sameValueAs(other.voyageNumber());
86
-  }
87
-
88
-  @Override
89
-  public String toString() {
90
-    return "Voyage " + voyageNumber;
91
-  }
92
-
93
-  Voyage() {
94
-    // Needed by Hibernate
95
-  }
96
-
97
-  // Needed by Hibernate
98
-  private Long id;
99
-
100
-
101
-  /**
102
-   * Builder pattern is used for incremental construction
103
-   * of a Voyage aggregate. This serves as an aggregate factory.
104
-   */
105
-  public static final class Builder {
106
-
107
-    private final List<CarrierMovement> carrierMovements = new ArrayList<CarrierMovement>();
108
-    private final VoyageNumber voyageNumber;
109
-    private Location departureLocation;
110
-
111
-    public Builder(final VoyageNumber voyageNumber, final Location departureLocation) {
112
-      Validate.notNull(voyageNumber, "Voyage number is required");
113
-      Validate.notNull(departureLocation, "Departure location is required");
114
-
115
-      this.voyageNumber = voyageNumber;
116
-      this.departureLocation = departureLocation;
117
-    }
118
-
119
-    public Builder addMovement(Location arrivalLocation, Date departureTime, Date arrivalTime) {
120
-      carrierMovements.add(new CarrierMovement(departureLocation, arrivalLocation, departureTime, arrivalTime));
121
-      // Next departure location is the same as this arrival location
122
-      this.departureLocation = arrivalLocation;
123
-      return this;
124
-    }
125
-
126
-    public Voyage build() {
127
-      return new Voyage(voyageNumber, new Schedule(carrierMovements));
128
-    }
129
-
130
-  }
131
-
132
-}

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

@@ -1,53 +0,0 @@
1
-package se.citerus.dddsample.domain.model.voyage;
2
-
3
-import org.apache.commons.lang.Validate;
4
-import se.citerus.dddsample.domain.shared.ValueObject;
5
-
6
-/**
7
- * Identifies a voyage.
8
- */
9
-public class VoyageNumber implements ValueObject<VoyageNumber> {
10
-
11
-  private String number;
12
-
13
-  public VoyageNumber(String number) {
14
-    Validate.notNull(number);
15
-
16
-    this.number = number;
17
-  }
18
-
19
-  @Override
20
-  public boolean equals(Object o) {
21
-    if (this == o) return true;
22
-    if (o == null) return false;
23
-    if (!(o instanceof VoyageNumber)) return false;
24
-
25
-    final VoyageNumber other = (VoyageNumber) o;
26
-
27
-    return sameValueAs(other);
28
-  }
29
-
30
-  @Override
31
-  public int hashCode() {
32
-    return number.hashCode();
33
-  }
34
-
35
-  @Override
36
-  public boolean sameValueAs(VoyageNumber other) {
37
-    return other != null && this.number.equals(other.number);
38
-  }
39
-
40
-  @Override
41
-  public String toString() {
42
-    return number;
43
-  }
44
-
45
-  public String stringValue() {
46
-    return number;
47
-  }
48
-
49
-  VoyageNumber() {
50
-    // Needed by Hibernate
51
-  }
52
-
53
-}

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

@@ -1,13 +0,0 @@
1
-package se.citerus.dddsample.domain.model.voyage;
2
-
3
-public interface VoyageRepository {
4
-
5
-  /**
6
-   * Finds a voyage using voyage number.
7
-   *
8
-   * @param voyageNumber voyage number
9
-   * @return The voyage, or null if not found.
10
-   */
11
-  Voyage find(VoyageNumber voyageNumber);
12
-
13
-}

+ 0
- 7
dddsample/src/main/java/se/citerus/dddsample/domain/model/voyage/package.html Просмотреть файл

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	The voyage aggregate. Voyage is the aggregate root.
5
-</p>
6
-</body>
7
-</html>

+ 0
- 15
dddsample/src/main/java/se/citerus/dddsample/domain/package.html Просмотреть файл

@@ -1,15 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	The domain model, services and repository interfaces. This is the central part of the
5
-	application. The ubiquitous language is used in classes, interfaces and method signatures,
6
-	and every concept in here is familiar to a expert in the cargo shiping domain.
7
-</p>
8
-
9
-<p>
10
-	There is no infrastructure or user interface related code here, except for things like
11
-	transactional and security metadata which is likely to be relevant to a domain expert
12
-	("Either all of foo succeeds or none of it does", "In order to do bar you need to be a Supervisor", and so on).
13
-</p>
14
-</body>
15
-</html>

+ 0
- 19
dddsample/src/main/java/se/citerus/dddsample/domain/service/RoutingService.java Просмотреть файл

@@ -1,19 +0,0 @@
1
-package se.citerus.dddsample.domain.service;
2
-
3
-import se.citerus.dddsample.domain.model.cargo.Itinerary;
4
-import se.citerus.dddsample.domain.model.cargo.RouteSpecification;
5
-
6
-import java.util.List;
7
-
8
-/**
9
- * Routing service.
10
- */
11
-public interface RoutingService {
12
-
13
-  /**
14
-   * @param routeSpecification route specification
15
-   * @return A list of itineraries that satisfy the specification. May be an empty list if no route is found.
16
-   */
17
-  List<Itinerary> fetchRoutesForSpecification(RouteSpecification routeSpecification);
18
-
19
-}

+ 0
- 9
dddsample/src/main/java/se/citerus/dddsample/domain/service/package.html Просмотреть файл

@@ -1,9 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	Domain services. Those services that may be implemented purely using the domain layer
5
-	have their implementations here, other implementations may be part of the aplication
6
-	or infrastructure layers.
7
-</p>
8
-</body>
9
-</html>

+ 0
- 35
dddsample/src/main/java/se/citerus/dddsample/domain/shared/AbstractSpecification.java Просмотреть файл

@@ -1,35 +0,0 @@
1
-package se.citerus.dddsample.domain.shared;
2
-
3
-
4
-/**
5
- * Abstract base implementation of composite {@link Specification} with default
6
- * implementations for {@code and}, {@code or} and {@code not}.
7
- */
8
-public abstract class AbstractSpecification<T> implements Specification<T> {
9
-
10
-  /**
11
-   * {@inheritDoc}
12
-   */
13
-  public abstract boolean isSatisfiedBy(T t);
14
-
15
-  /**
16
-   * {@inheritDoc}
17
-   */
18
-  public Specification<T> and(final Specification<T> specification) {
19
-    return new AndSpecification<T>(this, specification);
20
-  }
21
-
22
-  /**
23
-   * {@inheritDoc}
24
-   */
25
-  public Specification<T> or(final Specification<T> specification) {
26
-    return new OrSpecification<T>(this, specification);
27
-  }
28
-
29
-  /**
30
-   * {@inheritDoc}
31
-   */
32
-  public Specification<T> not(final Specification<T> specification) {
33
-    return new NotSpecification<T>(specification);
34
-  }
35
-}

+ 0
- 28
dddsample/src/main/java/se/citerus/dddsample/domain/shared/AndSpecification.java Просмотреть файл

@@ -1,28 +0,0 @@
1
-package se.citerus.dddsample.domain.shared;
2
-
3
-/**
4
- * AND specification, used to create a new specifcation that is the AND of two other specifications.
5
- */
6
-public class AndSpecification<T> extends AbstractSpecification<T> {
7
-
8
-  private Specification<T> spec1;
9
-  private Specification<T> spec2;
10
-
11
-  /**
12
-   * Create a new AND specification based on two other spec.
13
-   *
14
-   * @param spec1 Specification one.
15
-   * @param spec2 Specification two.
16
-   */
17
-  public AndSpecification(final Specification<T> spec1, final Specification<T> spec2) {
18
-    this.spec1 = spec1;
19
-    this.spec2 = spec2;
20
-  }
21
-
22
-  /**
23
-   * {@inheritDoc}
24
-   */
25
-  public boolean isSatisfiedBy(final T t) {
26
-    return spec1.isSatisfiedBy(t) && spec2.isSatisfiedBy(t);
27
-  }
28
-}

+ 0
- 17
dddsample/src/main/java/se/citerus/dddsample/domain/shared/DomainEvent.java Просмотреть файл

@@ -1,17 +0,0 @@
1
-package se.citerus.dddsample.domain.shared;
2
-
3
-/**
4
- * A domain event is something that is unique, but does not have a lifecycle.
5
- * The identity may be explicit, for example the sequence number of a payment,
6
- * or it could be derived from various aspects of the event such as where, when and what
7
- * has happened.
8
- */
9
-public interface DomainEvent<T> {
10
-
11
-  /**
12
-   * @param other The other domain event.
13
-   * @return <code>true</code> if the given domain event and this event are regarded as being the same event.
14
-   */
15
-  boolean sameEventAs(T other);
16
-
17
-}

+ 0
- 29
dddsample/src/main/java/se/citerus/dddsample/domain/shared/DomainObjectUtils.java Просмотреть файл

@@ -1,29 +0,0 @@
1
-package se.citerus.dddsample.domain.shared;
2
-
3
-/**
4
- * Utility code for domain classes.
5
- */
6
-public class DomainObjectUtils {
7
-
8
-  /**
9
-   * @param actual actual value
10
-   * @param safe   a null-safe value
11
-   * @param <T>    type
12
-   * @return actual value, if it's not null, or safe value if the actual value is null.
13
-   */
14
-  public static <T> T nullSafe(T actual, T safe) {
15
-    return actual == null ? safe : actual;
16
-  }
17
-
18
-  // TODO wrappers for some of the commons-lang code:
19
-  //
20
-  // EqualsBuilder that uses sameIdentity/sameValue,
21
-  // better validation (varargs etc) 
22
-
23
-  /**
24
-   * Prevent instantiation.
25
-   */
26
-  private DomainObjectUtils() {
27
-  }
28
-
29
-}

+ 0
- 16
dddsample/src/main/java/se/citerus/dddsample/domain/shared/Entity.java Просмотреть файл

@@ -1,16 +0,0 @@
1
-package se.citerus.dddsample.domain.shared;
2
-
3
-/**
4
- * An entity, as explained in the DDD book.
5
- */
6
-public interface Entity<T> {
7
-
8
-  /**
9
-   * Entities compare by identity, not by attributes.
10
-   *
11
-   * @param other The other entity.
12
-   * @return true if the identities are the same, regardles of other attributes.
13
-   */
14
-  boolean sameAs(T other);
15
-
16
-}

+ 0
- 25
dddsample/src/main/java/se/citerus/dddsample/domain/shared/NotSpecification.java Просмотреть файл

@@ -1,25 +0,0 @@
1
-package se.citerus.dddsample.domain.shared;
2
-
3
-/**
4
- * NOT decorator, used to create a new specifcation that is the inverse (NOT) of the given spec.
5
- */
6
-public class NotSpecification<T> extends AbstractSpecification<T> {
7
-
8
-  private Specification<T> spec1;
9
-
10
-  /**
11
-   * Create a new NOT specification based on another spec.
12
-   *
13
-   * @param spec1 Specification instance to not.
14
-   */
15
-  public NotSpecification(final Specification<T> spec1) {
16
-    this.spec1 = spec1;
17
-  }
18
-
19
-  /**
20
-   * {@inheritDoc}
21
-   */
22
-  public boolean isSatisfiedBy(final T t) {
23
-    return !spec1.isSatisfiedBy(t);
24
-  }
25
-}

+ 0
- 28
dddsample/src/main/java/se/citerus/dddsample/domain/shared/OrSpecification.java Просмотреть файл

@@ -1,28 +0,0 @@
1
-package se.citerus.dddsample.domain.shared;
2
-
3
-/**
4
- * OR specification, used to create a new specifcation that is the OR of two other specifications.
5
- */
6
-public class OrSpecification<T> extends AbstractSpecification<T> {
7
-
8
-  private Specification<T> spec1;
9
-  private Specification<T> spec2;
10
-
11
-  /**
12
-   * Create a new OR specification based on two other spec.
13
-   *
14
-   * @param spec1 Specification one.
15
-   * @param spec2 Specification two.
16
-   */
17
-  public OrSpecification(final Specification<T> spec1, final Specification<T> spec2) {
18
-    this.spec1 = spec1;
19
-    this.spec2 = spec2;
20
-  }
21
-
22
-  /**
23
-   * {@inheritDoc}
24
-   */
25
-  public boolean isSatisfiedBy(final T t) {
26
-    return spec1.isSatisfiedBy(t) || spec2.isSatisfiedBy(t);
27
-  }
28
-}

+ 0
- 42
dddsample/src/main/java/se/citerus/dddsample/domain/shared/Specification.java Просмотреть файл

@@ -1,42 +0,0 @@
1
-package se.citerus.dddsample.domain.shared;
2
-
3
-/**
4
- * Specificaiton interface.
5
- * <p/>
6
- * Use {@link se.citerus.dddsample.domain.shared.AbstractSpecification} as base for creating specifications, and
7
- * only the method {@link #isSatisfiedBy(Object)} must be implemented.
8
- */
9
-public interface Specification<T> {
10
-
11
-  /**
12
-   * Check if {@code t} is satisfied by the specification.
13
-   *
14
-   * @param t Object to test.
15
-   * @return {@code true} if {@code t} satisfies the specification.
16
-   */
17
-  boolean isSatisfiedBy(T t);
18
-
19
-  /**
20
-   * Create a new specification that is the AND operation of {@code this} specification and another specification.
21
-   *
22
-   * @param specification Specification to AND.
23
-   * @return A new specification.
24
-   */
25
-  Specification<T> and(Specification<T> specification);
26
-
27
-  /**
28
-   * Create a new specification that is the OR operation of {@code this} specification and another specification.
29
-   *
30
-   * @param specification Specification to OR.
31
-   * @return A new specification.
32
-   */
33
-  Specification<T> or(Specification<T> specification);
34
-
35
-  /**
36
-   * Create a new specification that is the NOT operation of {@code this} specification.
37
-   *
38
-   * @param specification Specification to NOT.
39
-   * @return A new specification.
40
-   */
41
-  Specification<T> not(Specification<T> specification);
42
-}

+ 0
- 18
dddsample/src/main/java/se/citerus/dddsample/domain/shared/ValueObject.java Просмотреть файл

@@ -1,18 +0,0 @@
1
-package se.citerus.dddsample.domain.shared;
2
-
3
-import java.io.Serializable;
4
-
5
-/**
6
- * A value object, as described in the DDD book.
7
- */
8
-public interface ValueObject<T> extends Serializable {
9
-
10
-  /**
11
-   * Value objects compare by the values of their attributes, they don't have an identity.
12
-   *
13
-   * @param other The other value object.
14
-   * @return <code>true</code> if the given value object's and this value object's attributes are the same.
15
-   */
16
-  boolean sameValueAs(T other);
17
-
18
-}

+ 0
- 17
dddsample/src/main/java/se/citerus/dddsample/domain/shared/experimental/DomainEvent.java Просмотреть файл

@@ -1,17 +0,0 @@
1
-package se.citerus.dddsample.domain.shared.experimental;
2
-
3
-/**
4
- * A domain event is something that is unique, but does not have a lifecycle.
5
- * The identity may be explicit, for example the sequence number of a payment,
6
- * or it could be derived from various aspects of the event such as where, when and what
7
- * has happened.
8
- */
9
-public interface DomainEvent<T> {
10
-
11
-  /**
12
-   * @param other The other domain event.
13
-   * @return <code>true</code> if the given domain event and this event are regarded as being the same event.
14
-   */
15
-  boolean sameEventAs(T other);
16
-
17
-}

+ 0
- 23
dddsample/src/main/java/se/citerus/dddsample/domain/shared/experimental/Entity.java Просмотреть файл

@@ -1,23 +0,0 @@
1
-package se.citerus.dddsample.domain.shared.experimental;
2
-
3
-/**
4
- * An entity, as explained in the DDD book.
5
- */
6
-public interface Entity<T, ID> {
7
-
8
-  /**
9
-   * Entities have an identity.
10
-   *
11
-   * @return The identity of this entity.
12
-   */
13
-  ID identity();
14
-
15
-  /**
16
-   * Entities compare by identity, not by attributes.
17
-   *
18
-   * @param other The other entity.
19
-   * @return true if the identities are the same, regardles of other attributes.
20
-   */
21
-  boolean sameAs(T other);
22
-
23
-}

+ 0
- 29
dddsample/src/main/java/se/citerus/dddsample/domain/shared/experimental/EntitySupport.java Просмотреть файл

@@ -1,29 +0,0 @@
1
-package se.citerus.dddsample.domain.shared.experimental;
2
-
3
-/**
4
- * Base class for entities.
5
- */
6
-public abstract class EntitySupport<T extends Entity, ID> implements Entity<T, ID> {
7
-
8
-  @Override
9
-  public final boolean sameAs(final T other) {
10
-    return other != null && this.identity().equals(other.identity());
11
-  }
12
-
13
-  @Override
14
-  public abstract ID identity();
15
-
16
-  @Override
17
-  public final int hashCode() {
18
-    return identity().hashCode();
19
-  }
20
-
21
-  @Override
22
-  public final boolean equals(final Object o) {
23
-    if (this == o) return true;
24
-    if (o == null || getClass() != o.getClass()) return false;
25
-
26
-    return sameAs((T) o);
27
-  }
28
-
29
-}

+ 0
- 15
dddsample/src/main/java/se/citerus/dddsample/domain/shared/experimental/Identity.java Просмотреть файл

@@ -1,15 +0,0 @@
1
-package se.citerus.dddsample.domain.shared.experimental;
2
-
3
-import java.lang.annotation.ElementType;
4
-import java.lang.annotation.Retention;
5
-import java.lang.annotation.RetentionPolicy;
6
-import java.lang.annotation.Target;
7
-
8
-/**
9
- * Every class that inherits from {@link se.citerus.dddsample.domain.shared.experimental.EntitySupport}
10
- * must have exactly one field annotated with this annotation.
11
- */
12
-@Retention(RetentionPolicy.RUNTIME)
13
-@Target(ElementType.FIELD)
14
-public @interface Identity {
15
-}

+ 0
- 23
dddsample/src/main/java/se/citerus/dddsample/domain/shared/experimental/ValueObject.java Просмотреть файл

@@ -1,23 +0,0 @@
1
-package se.citerus.dddsample.domain.shared.experimental;
2
-
3
-/**
4
- * A value object.
5
- */
6
-public interface ValueObject<T> {
7
-
8
-  /**
9
-   * Value objects compare by the values of their attributes, they don't have an identity.
10
-   *
11
-   * @param other The other value object.
12
-   * @return <code>true</code> if the given value object's and this value object's attributes are the same.
13
-   */
14
-  boolean sameValueAs(T other);
15
-
16
-  /**
17
-   * Value objects can be freely copied.
18
-   *
19
-   * @return A safe, deep copy of this value object.
20
-   */
21
-  T copy();
22
-
23
-}

+ 0
- 60
dddsample/src/main/java/se/citerus/dddsample/domain/shared/experimental/ValueObjectSupport.java Просмотреть файл

@@ -1,60 +0,0 @@
1
-package se.citerus.dddsample.domain.shared.experimental;
2
-
3
-import org.apache.commons.lang.builder.EqualsBuilder;
4
-import org.apache.commons.lang.builder.HashCodeBuilder;
5
-import se.citerus.dddsample.domain.shared.ValueObject;
6
-
7
-/**
8
- * Base class for value objects.
9
- *
10
- * @param <T>
11
- */
12
-public abstract class ValueObjectSupport<T extends ValueObject> implements ValueObject<T> {
13
-
14
-  private transient int cachedHashCode = 0;
15
-
16
-  /**
17
-   * @param other The other value object.
18
-   * @return True if all non-transient fields are equal.
19
-   */
20
-  @Override
21
-  public final boolean sameValueAs(final T other) {
22
-    return other != null && EqualsBuilder.reflectionEquals(this, other, false);
23
-  }
24
-
25
-  /**
26
-   * @return Hash code built from all non-transient fields.
27
-   */
28
-  @Override
29
-  public final int hashCode() {
30
-    // Using a local variable to ensure that we only do a single read
31
-    // of the cachedHashCode field, to avoid race conditions.
32
-    // It doesn't matter if several threads compute the hash code and overwrite
33
-    // each other, but it's important that we never return 0, which could happen
34
-    // with multiple reads of the cachedHashCode field.
35
-    //
36
-    // See java.lang.String.hashCode()
37
-    int h = cachedHashCode;
38
-    if (h == 0) {
39
-      // Lazy initialization of hash code.
40
-      // Value objects are immutable, so the hash code never changes.
41
-      h = HashCodeBuilder.reflectionHashCode(this, false);
42
-      cachedHashCode = h;
43
-    }
44
-
45
-    return h;
46
-  }
47
-
48
-  /**
49
-   * @param o other object
50
-   * @return True if other object has the same value as this value object.
51
-   */
52
-  @Override
53
-  public final boolean equals(final Object o) {
54
-    if (this == o) return true;
55
-    if (o == null || getClass() != o.getClass()) return false;
56
-
57
-    return sameValueAs((T) o);
58
-  }
59
-
60
-}

+ 0
- 8
dddsample/src/main/java/se/citerus/dddsample/domain/shared/experimental/package.html Просмотреть файл

@@ -1,8 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	Experimental versions of pattern interfaces and support code for the domain layer.
5
-	Not used in the application.
6
-</p>
7
-</body>
8
-</html>

+ 0
- 7
dddsample/src/main/java/se/citerus/dddsample/domain/shared/package.html Просмотреть файл

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	Pattern interfaces and support code for the domain layer.
5
-</p>
6
-</body>
7
-</html>

+ 0
- 54
dddsample/src/main/java/se/citerus/dddsample/infrastructure/messaging/jms/JmsSystemEventsImpl.java Просмотреть файл

@@ -1,54 +0,0 @@
1
-package se.citerus.dddsample.infrastructure.messaging.jms;
2
-
3
-import org.springframework.jms.core.JmsOperations;
4
-import org.springframework.jms.core.MessageCreator;
5
-import se.citerus.dddsample.application.event.SystemEvents;
6
-import se.citerus.dddsample.domain.model.cargo.Cargo;
7
-import se.citerus.dddsample.domain.model.handling.HandlingEvent;
8
-
9
-import javax.jms.Destination;
10
-import javax.jms.JMSException;
11
-import javax.jms.Message;
12
-import javax.jms.Session;
13
-
14
-/**
15
- * JMS based implementation.
16
- */
17
-public final class JmsSystemEventsImpl implements SystemEvents {
18
-
19
-  private JmsOperations jmsOperations;
20
-  private Destination cargoHandledDestination;
21
-  private Destination cargoUpdateDestination;
22
-
23
-  @Override
24
-  public void notifyOfHandlingEvent(final HandlingEvent event) {
25
-    final Cargo cargo = event.cargo();
26
-    jmsOperations.send(cargoHandledDestination, new MessageCreator() {
27
-      public Message createMessage(final Session session) throws JMSException {
28
-        return session.createObjectMessage(cargo.trackingId());
29
-      }
30
-    });
31
-  }
32
-
33
-  @Override
34
-  public void notifyOfCargoUpdate(final Cargo cargo) {
35
-    jmsOperations.send(cargoUpdateDestination, new MessageCreator() {
36
-      public Message createMessage(Session session) throws JMSException {
37
-        return session.createObjectMessage(cargo.trackingId());
38
-      }
39
-    });
40
-  }
41
-
42
-  public void setJmsOperations(JmsOperations jmsOperations) {
43
-    this.jmsOperations = jmsOperations;
44
-  }
45
-
46
-  public void setCargoHandledDestination(Destination cargoHandledDestination) {
47
-    this.cargoHandledDestination = cargoHandledDestination;
48
-  }
49
-
50
-  public void setCargoUpdateDestination(Destination cargoUpdateDestination) {
51
-    this.cargoUpdateDestination = cargoUpdateDestination;
52
-  }
53
-
54
-}

+ 0
- 7
dddsample/src/main/java/se/citerus/dddsample/infrastructure/messaging/jms/package.html Просмотреть файл

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	Asynchronous messaging implemented using JMS. This is part of the infrastructure.
5
-</p>
6
-</body>
7
-</html>

+ 0
- 32
dddsample/src/main/java/se/citerus/dddsample/infrastructure/persistence/DatabaseTrackingIdGenerator.java Просмотреть файл

@@ -1,32 +0,0 @@
1
-/**
2
- * Purpose
3
- * @author peter
4
- * @created 2009-sep-17
5
- * $Id$
6
- */
7
-package se.citerus.dddsample.infrastructure.persistence;
8
-
9
-import org.hibernate.SessionFactory;
10
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
11
-import se.citerus.dddsample.domain.model.cargo.TrackingIdGenerator;
12
-
13
-public class DatabaseTrackingIdGenerator implements TrackingIdGenerator {
14
-
15
-  private final SessionFactory sessionFactory;
16
-  private static final String SEQUENCE_NAME = "TRACKING_ID_SEQ";
17
-
18
-  public DatabaseTrackingIdGenerator(final SessionFactory sessionFactory) {
19
-    this.sessionFactory = sessionFactory;
20
-  }
21
-
22
-  @Override
23
-  public TrackingId nextTrackingId() {
24
-    final Long seq = (Long) sessionFactory.getCurrentSession().
25
-      createSQLQuery("select next_value from system_sequences where sequence_name = ?").
26
-      setParameter(1, SEQUENCE_NAME).
27
-      uniqueResult();
28
-
29
-    return new TrackingId(seq);
30
-  }
31
-
32
-}

+ 0
- 23
dddsample/src/main/java/se/citerus/dddsample/infrastructure/persistence/TrackingIdGeneratorInMem.java Просмотреть файл

@@ -1,23 +0,0 @@
1
-/**
2
- * Purpose
3
- * @author peter
4
- * @created 2009-sep-07
5
- * $Id$
6
- */
7
-package se.citerus.dddsample.infrastructure.persistence;
8
-
9
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
10
-import se.citerus.dddsample.domain.model.cargo.TrackingIdGenerator;
11
-
12
-import java.util.concurrent.atomic.AtomicLong;
13
-
14
-public class TrackingIdGeneratorInMem implements TrackingIdGenerator {
15
-
16
-  private static final AtomicLong SEQ = new AtomicLong(1);
17
-
18
-  @Override
19
-  public TrackingId nextTrackingId() {
20
-    return new TrackingId(SEQ.getAndIncrement());
21
-  }
22
-
23
-}

+ 0
- 49
dddsample/src/main/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryHibernate.java Просмотреть файл

@@ -1,49 +0,0 @@
1
-package se.citerus.dddsample.infrastructure.persistence.hibernate;
2
-
3
-import org.springframework.stereotype.Repository;
4
-import se.citerus.dddsample.domain.model.cargo.Cargo;
5
-import se.citerus.dddsample.domain.model.cargo.CargoRepository;
6
-import se.citerus.dddsample.domain.model.cargo.TrackingId;
7
-import se.citerus.dddsample.domain.model.voyage.Voyage;
8
-
9
-import java.util.List;
10
-
11
-/**
12
- * Hibernate implementation of CargoRepository.
13
- */
14
-@Repository
15
-public class CargoRepositoryHibernate extends HibernateRepository implements CargoRepository {
16
-
17
-  @Override
18
-  public Cargo find(TrackingId tid) {
19
-    return (Cargo) getSession().
20
-      createQuery("from Cargo where trackingId = :tid").
21
-      setParameter("tid", tid).
22
-      uniqueResult();
23
-  }
24
-
25
-  @SuppressWarnings("unchecked")
26
-  @Override
27
-  public List<Cargo> findCargosOnVoyage(Voyage voyage) {
28
-    return getSession().createQuery(
29
-      "select cargo from Cargo as cargo " +
30
-        "left join cargo.itinerary.legs as leg " +
31
-        "where leg.voyage = :voyage").
32
-      setParameter("voyage", voyage).
33
-      list();
34
-  }
35
-
36
-  @Override
37
-  public void store(Cargo cargo) {
38
-    getSession().saveOrUpdate(cargo);
39
-    // Delete-orphan does not seem to work correctly when the parent is a component
40
-    getSession().createSQLQuery("delete from Leg where cargo_id = null").executeUpdate();
41
-  }
42
-
43
-  @SuppressWarnings("unchecked")
44
-  @Override
45
-  public List<Cargo> findAll() {
46
-    return getSession().createQuery("from Cargo").list();
47
-  }
48
-
49
-}

+ 0
- 0
dddsample/src/main/java/se/citerus/dddsample/infrastructure/persistence/hibernate/HandlingEventRepositoryHibernate.java Просмотреть файл


Некоторые файлы не были показаны из-за большого количества измененных файлов