Selaa lähdekoodia

Added Checkstyle configuration file that checks the sun coding conventions.

Misc CheckStyle fixes.

Removed magic numbers from HashCodeBuilder.

Created a separate sub package for DTO assemblers.

Minor refactorings to increase readability.
Jesper Hammarbäck 18 vuotta sitten
vanhempi
commit
07e2bd6139
54 muutettua tiedostoa jossa 752 lisäystä ja 441 poistoa
  1. 221
    0
      dddsample/checkstyle.xml
  2. 25
    18
      dddsample/src/main/java/se/citerus/dddsample/domain/Cargo.java
  3. 13
    6
      dddsample/src/main/java/se/citerus/dddsample/domain/CarrierMovement.java
  4. 10
    5
      dddsample/src/main/java/se/citerus/dddsample/domain/CarrierMovementId.java
  5. 8
    8
      dddsample/src/main/java/se/citerus/dddsample/domain/DeliveryHistory.java
  6. 16
    11
      dddsample/src/main/java/se/citerus/dddsample/domain/HandlingEvent.java
  7. 16
    11
      dddsample/src/main/java/se/citerus/dddsample/domain/Itinerary.java
  8. 14
    7
      dddsample/src/main/java/se/citerus/dddsample/domain/Leg.java
  9. 9
    11
      dddsample/src/main/java/se/citerus/dddsample/domain/Location.java
  10. 1
    1
      dddsample/src/main/java/se/citerus/dddsample/domain/Specification.java
  11. 1
    1
      dddsample/src/main/java/se/citerus/dddsample/domain/StatusCode.java
  12. 9
    4
      dddsample/src/main/java/se/citerus/dddsample/domain/TrackingId.java
  13. 12
    7
      dddsample/src/main/java/se/citerus/dddsample/domain/UnLocode.java
  14. 19
    0
      dddsample/src/main/java/se/citerus/dddsample/repository/CargoRepository.java
  15. 13
    11
      dddsample/src/main/java/se/citerus/dddsample/repository/CargoRepositoryInMem.java
  16. 6
    0
      dddsample/src/main/java/se/citerus/dddsample/repository/CarrierMovementRepository.java
  17. 5
    6
      dddsample/src/main/java/se/citerus/dddsample/repository/CarrierMovementRepositoryHibernate.java
  18. 6
    2
      dddsample/src/main/java/se/citerus/dddsample/repository/CarrierMovementRepositoryInMem.java
  19. 2
    3
      dddsample/src/main/java/se/citerus/dddsample/repository/HandlingEventRepository.java
  20. 20
    28
      dddsample/src/main/java/se/citerus/dddsample/repository/HandlingEventRepositoryInMem.java
  21. 2
    3
      dddsample/src/main/java/se/citerus/dddsample/repository/HibernateRepository.java
  22. 11
    0
      dddsample/src/main/java/se/citerus/dddsample/repository/LocationRepository.java
  23. 5
    5
      dddsample/src/main/java/se/citerus/dddsample/repository/LocationRepositoryHibernate.java
  24. 2
    3
      dddsample/src/main/java/se/citerus/dddsample/service/CargoService.java
  25. 35
    39
      dddsample/src/main/java/se/citerus/dddsample/service/CargoServiceImpl.java
  26. 5
    5
      dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventMessageDelegate.java
  27. 9
    10
      dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventService.java
  28. 23
    18
      dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventServiceImpl.java
  29. 6
    6
      dddsample/src/main/java/se/citerus/dddsample/service/JmsEventServiceImpl.java
  30. 1
    1
      dddsample/src/main/java/se/citerus/dddsample/service/RoutingService.java
  31. 7
    8
      dddsample/src/main/java/se/citerus/dddsample/service/RoutingServiceImpl.java
  32. 1
    0
      dddsample/src/main/java/se/citerus/dddsample/service/ThreadBasedEventServiceImpl.java
  33. 3
    3
      dddsample/src/main/java/se/citerus/dddsample/service/UnknownCarrierMovementIdException.java
  34. 2
    2
      dddsample/src/main/java/se/citerus/dddsample/service/UnknownLocationException.java
  35. 4
    4
      dddsample/src/main/java/se/citerus/dddsample/service/UnknownTrackingIdException.java
  36. 11
    8
      dddsample/src/main/java/se/citerus/dddsample/service/dto/CargoRoutingDTO.java
  37. 18
    16
      dddsample/src/main/java/se/citerus/dddsample/service/dto/CargoTrackingDTO.java
  38. 0
    29
      dddsample/src/main/java/se/citerus/dddsample/service/dto/DTOAssembler.java
  39. 3
    2
      dddsample/src/main/java/se/citerus/dddsample/service/dto/HandlingEventDTO.java
  40. 7
    4
      dddsample/src/main/java/se/citerus/dddsample/service/dto/ItineraryCandidateDTO.java
  41. 5
    6
      dddsample/src/main/java/se/citerus/dddsample/service/dto/LegDTO.java
  42. 32
    0
      dddsample/src/main/java/se/citerus/dddsample/service/dto/assembler/DTOAssembler.java
  43. 26
    26
      dddsample/src/main/java/se/citerus/dddsample/util/LocationsImporter.java
  44. 33
    31
      dddsample/src/main/java/se/citerus/dddsample/web/CargoAdminController.java
  45. 8
    5
      dddsample/src/main/java/se/citerus/dddsample/web/CargoTrackingController.java
  46. 4
    3
      dddsample/src/main/java/se/citerus/dddsample/web/command/RegistrationCommand.java
  47. 16
    15
      dddsample/src/main/java/se/citerus/dddsample/web/command/RoutingCommand.java
  48. 1
    1
      dddsample/src/main/java/se/citerus/dddsample/web/command/TrackCommand.java
  49. 3
    3
      dddsample/src/main/java/se/citerus/dddsample/web/command/TrackCommandValidator.java
  50. 4
    5
      dddsample/src/main/java/se/citerus/dddsample/ws/HandlingEventServiceEndpoint.java
  51. 7
    7
      dddsample/src/main/java/se/citerus/dddsample/ws/HandlingEventServiceEndpointImpl.java
  52. 4
    5
      dddsample/src/test/java/se/citerus/dddsample/domain/SampleLocations.java
  53. 4
    4
      dddsample/src/test/java/se/citerus/dddsample/service/RoutingServiceTest.java
  54. 24
    24
      dddsample/src/test/java/se/citerus/dddsample/ws/HandlinEventServiceEndpointTest.java

+ 221
- 0
dddsample/checkstyle.xml Näytä tiedosto

1
+<?xml version="1.0"?>
2
+<!-- 
3
+/*
4
+ * Copyright 2001-2004 The Apache Software Foundation.
5
+ * 
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ * 
10
+ *      http://www.apache.org/licenses/LICENSE-2.0
11
+ * 
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+ -->
19
+
20
+<!DOCTYPE module PUBLIC
21
+    "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
22
+    "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
23
+
24
+<!--
25
+
26
+  Checkstyle configuration that checks the sun coding conventions from:
27
+
28
+    - the Java Language Specification at
29
+      http://java.sun.com/docs/books/jls/second_edition/html/index.html
30
+
31
+    - the Sun Code Conventions at http://java.sun.com/docs/codeconv/
32
+
33
+    - the Javadoc guidelines at
34
+      http://java.sun.com/j2se/javadoc/writingdoccomments/index.html
35
+
36
+    - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html
37
+
38
+    - some best practices
39
+
40
+  Checkstyle is very configurable. Be sure to read the documentation at
41
+  http://checkstyle.sf.net (or in your downloaded distribution).
42
+
43
+  Most Checks are configurable, be sure to consult the documentation.
44
+
45
+  To completely disable a check, just comment it out or delete it from the file.
46
+
47
+  Finally, it is worth reading the documentation.
48
+
49
+-->
50
+
51
+<module name="Checker">
52
+
53
+    <!-- Checks that a package.html file exists for each package.     -->
54
+    <!-- See http://checkstyle.sf.net/config_javadoc.html#PackageHtml -->
55
+    <module name="PackageHtml"/>
56
+
57
+    <!-- Checks whether files end with a new line.                        -->
58
+    <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
59
+    <module name="NewlineAtEndOfFile"/>
60
+
61
+    <!-- Checks that property files contain the same keys.         -->
62
+    <!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
63
+    <module name="Translation"/>
64
+
65
+
66
+    <module name="TreeWalker">
67
+
68
+        <property name="cacheFile" value="${checkstyle.cache.file}"/>
69
+
70
+        <!-- Checks for Javadoc comments.                     -->
71
+        <!-- See http://checkstyle.sf.net/config_javadoc.html -->
72
+        <module name="JavadocMethod"/>
73
+        <module name="JavadocType">
74
+          <property name="scope" value="public"/>
75
+        </module>
76
+        <module name="JavadocVariable">
77
+          <property name="scope" value="public"/>
78
+        </module>
79
+        <module name="JavadocStyle"/>
80
+
81
+        <!-- Checks for Naming Conventions.                  -->
82
+        <!-- See http://checkstyle.sf.net/config_naming.html -->
83
+        <module name="ConstantName"/>
84
+        <module name="LocalFinalVariableName"/>
85
+        <module name="LocalVariableName"/>
86
+        <module name="MemberName"/>
87
+        <module name="MethodName"/>
88
+        <module name="PackageName"/>
89
+        <module name="ParameterName"/>
90
+        <module name="StaticVariableName"/>
91
+        <module name="TypeName"/>
92
+
93
+
94
+        <!-- Checks for Headers                                -->
95
+        <!-- See http://checkstyle.sf.net/config_header.html   -->
96
+        <!-- <module name="Header">                            -->
97
+            <!-- The follow property value demonstrates the ability     -->
98
+            <!-- to have access to ANT properties. In this case it uses -->
99
+            <!-- the ${basedir} property to allow Checkstyle to be run  -->
100
+            <!-- from any directory within a project. See property      -->
101
+            <!-- expansion,                                             -->
102
+            <!-- http://checkstyle.sf.net/config.html#properties        -->
103
+            <!-- <property                                              -->
104
+            <!--     name="headerFile"                                  -->
105
+            <!--     value="${basedir}/java.header"/>                   -->
106
+        <!-- </module> -->
107
+
108
+        <!-- Following interprets the header file as regular expressions. -->
109
+        <!-- <module name="RegexpHeader"/>                                -->
110
+
111
+
112
+        <!-- Checks for imports                              -->
113
+        <!-- See http://checkstyle.sf.net/config_import.html -->
114
+        <module name="AvoidStarImport"/>
115
+        <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
116
+        <module name="RedundantImport"/>
117
+        <module name="UnusedImports"/>
118
+
119
+
120
+        <!-- Checks for Size Violations.                    -->
121
+        <!-- See http://checkstyle.sf.net/config_sizes.html -->
122
+        <module name="FileLength"/>
123
+
124
+        <module name="LineLength">
125
+         <property name="max" value="120"/>
126
+        </module>
127
+
128
+        <module name="MethodLength"/>
129
+        <module name="ParameterNumber"/>
130
+
131
+
132
+        <!-- Checks for whitespace                               -->
133
+        <!-- See http://checkstyle.sf.net/config_whitespace.html -->
134
+        <module name="EmptyForIteratorPad"/>
135
+        <module name="MethodParamPad"/>
136
+
137
+        <module name="NoWhitespaceAfter">
138
+          <!-- Default tokens and additional GENERIC_START -->
139
+          <property name="tokens" value="ARRAY_INIT, BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS, UNARY_PLUS, GENERIC_START"/>
140
+        </module>
141
+        
142
+        <module name="NoWhitespaceBefore">
143
+          <!-- Default tokens and additional GENERIC_START and GENERIC_END -->
144
+          <property name="tokens" value="SEMI, POST_DEC, POST_INC, GENERIC_START, GENERIC_END"/>
145
+        </module>
146
+        
147
+        <module name="WhitespaceAfter">
148
+          <!-- Default tokens and additional GENERIC_END -->
149
+          <property name="tokens" value="COMMA, SEMI, TYPECAST, GENERIC_END"/>
150
+        </module>
151
+        
152
+        <module name="WhitespaceAround">
153
+          <!-- Default tokens without GENERIC_START and GENERIC_END -->
154
+          <property name="tokens" value="ASSIGN, BAND, BAND_ASSIGN,
155
+        BOR, BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON,
156
+        DIV, DIV_ASSIGN, EQUAL, GE, GT, LAND, LCURLY, LE, 
157
+        LITERAL_ASSERT, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, 
158
+        LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
159
+        LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS,
160
+        MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN,
161
+        QUESTION, RCURLY, SL, SLIST, SL_ASSIGN, SR, SR_ASSIGN, STAR, STAR_ASSIGN,
162
+        TYPE_EXTENSION_AND, WILDCARD_TYPE"/>
163
+        </module>
164
+        
165
+        <module name="OperatorWrap"/>
166
+        <module name="ParenPad"/>
167
+        <module name="TypecastParenPad"/>
168
+        <module name="TabCharacter"/>
169
+
170
+
171
+        <!-- Modifier Checks                                    -->
172
+        <!-- See http://checkstyle.sf.net/config_modifiers.html -->
173
+        <module name="ModifierOrder"/>
174
+        <module name="RedundantModifier"/>
175
+
176
+
177
+        <!-- Checks for blocks. You know, those {}'s         -->
178
+        <!-- See http://checkstyle.sf.net/config_blocks.html -->
179
+        <module name="AvoidNestedBlocks"/>
180
+        <module name="EmptyBlock"/>
181
+        <module name="LeftCurly"/>
182
+        <module name="NeedBraces"/>
183
+        <module name="RightCurly"/>
184
+
185
+
186
+        <!-- Checks for common coding problems               -->
187
+        <!-- See http://checkstyle.sf.net/config_coding.html -->
188
+        <module name="DoubleCheckedLocking"/>    <!-- MY FAVOURITE -->
189
+        <module name="EmptyStatement"/>
190
+        <module name="EqualsHashCode"/>
191
+        <module name="IllegalInstantiation"/>
192
+        <module name="InnerAssignment"/>
193
+        <module name="MagicNumber"/>
194
+        <module name="MissingSwitchDefault"/>
195
+        <module name="RedundantThrows"/>
196
+        <module name="SimplifyBooleanExpression"/>
197
+        <module name="SimplifyBooleanReturn"/>
198
+
199
+        <!-- Checks for class design                         -->
200
+        <!-- See http://checkstyle.sf.net/config_design.html -->
201
+        <module name="DesignForExtension"/>
202
+        <module name="FinalClass"/>
203
+        <module name="HideUtilityClassConstructor"/>
204
+        <module name="InterfaceIsType"/>
205
+        <module name="VisibilityModifier"/>
206
+
207
+
208
+        <!-- Miscellaneous other checks.                   -->
209
+        <!-- See http://checkstyle.sf.net/config_misc.html -->
210
+        <module name="ArrayTypeStyle"/>
211
+        <module name="FinalParameters"/>
212
+        <module name="GenericIllegalRegexp">
213
+            <property name="format" value="\s+$"/>
214
+            <property name="message" value="Line has trailing spaces."/>
215
+        </module>
216
+        <module name="TodoComment"/>
217
+        <module name="UpperEll"/>
218
+
219
+    </module>
220
+
221
+</module>

+ 25
- 18
dddsample/src/main/java/se/citerus/dddsample/domain/Cargo.java Näytä tiedosto

4
 
4
 
5
 import javax.persistence.*;
5
 import javax.persistence.*;
6
 
6
 
7
-
8
 /**
7
 /**
9
  * A Cargo.
8
  * A Cargo.
10
  */
9
  */
11
 @Entity
10
 @Entity
12
-public class Cargo {
11
+public final class Cargo {
13
 
12
 
14
   @Id
13
   @Id
15
   @GeneratedValue
14
   @GeneratedValue
25
   private Location destination;
24
   private Location destination;
26
 
25
 
27
   @Transient
26
   @Transient
28
-  private DeliveryHistory deliveryHistory = new DeliveryHistory();
27
+  private final DeliveryHistory deliveryHistory = new DeliveryHistory();
29
 
28
 
30
   @ManyToOne(cascade = CascadeType.ALL)
29
   @ManyToOne(cascade = CascadeType.ALL)
31
   private Itinerary itinerary;
30
   private Itinerary itinerary;
32
 
31
 
33
-  public Cargo(TrackingId trackingId, Location origin, Location destination) {
34
-    Validate.noNullElements(new Object[] {trackingId, origin, destination});
32
+  /**
33
+   * Constructor.
34
+   *
35
+   * @param trackingId
36
+   * @param origin
37
+   * @param destination
38
+   */
39
+  public Cargo(final TrackingId trackingId, final Location origin, final Location destination) {
40
+    Validate.noNullElements(new Object[]{trackingId, origin, destination});
35
     this.trackingId = trackingId;
41
     this.trackingId = trackingId;
36
     this.origin = origin;
42
     this.origin = origin;
37
     this.destination = destination;
43
     this.destination = destination;
51
     return this.origin;
57
     return this.origin;
52
   }
58
   }
53
 
59
 
54
-  public void setOrigin(Location origin) {
60
+  public void setOrigin(final Location origin) {
55
     Validate.notNull(origin);
61
     Validate.notNull(origin);
56
     this.origin = origin;
62
     this.origin = origin;
57
   }
63
   }
58
 
64
 
59
-  public void setDestination(Location destination) {
65
+  public void setDestination(final Location destination) {
60
     Validate.notNull(destination);
66
     Validate.notNull(destination);
61
     this.destination = destination;
67
     this.destination = destination;
62
   }
68
   }
90
    * @return Last known location of the cargo, or Location.UNKNOWN if the delivery history is empty.
96
    * @return Last known location of the cargo, or Location.UNKNOWN if the delivery history is empty.
91
    */
97
    */
92
   public Location lastKnownLocation() {
98
   public Location lastKnownLocation() {
93
-    HandlingEvent lastEvent = deliveryHistory.lastEvent();
99
+    final HandlingEvent lastEvent = deliveryHistory.lastEvent();
94
     if (lastEvent != null) {
100
     if (lastEvent != null) {
95
       return lastEvent.location();
101
       return lastEvent.location();
96
     } else {
102
     } else {
110
    *
116
    *
111
    * @param itinerary an itinerary
117
    * @param itinerary an itinerary
112
    */
118
    */
113
-  public void setItinerary(Itinerary itinerary) {
119
+  public void setItinerary(final Itinerary itinerary) {
114
     Validate.notNull(itinerary);
120
     Validate.notNull(itinerary);
115
     this.itinerary = itinerary;
121
     this.itinerary = itinerary;
116
   }
122
   }
128
    */
134
    */
129
   public boolean isMisdirected() {
135
   public boolean isMisdirected() {
130
     final HandlingEvent lastEvent = deliveryHistory.lastEvent();
136
     final HandlingEvent lastEvent = deliveryHistory.lastEvent();
131
-    if (itinerary == null || lastEvent == null)
137
+    if (itinerary == null || lastEvent == null) {
132
       return false;
138
       return false;
133
-
134
-    return !itinerary.isExpected(lastEvent);
139
+    } else {
140
+      return !itinerary.isExpected(lastEvent);
141
+    }
135
   }
142
   }
136
 
143
 
137
   /**
144
   /**
142
    * @return True if the cargo has been unloaded at the final destination.
149
    * @return True if the cargo has been unloaded at the final destination.
143
    */
150
    */
144
   public boolean isUnloadedAtDestination() {
151
   public boolean isUnloadedAtDestination() {
145
-    Location destination = finalDestination();
152
+    final Location destination = finalDestination();
146
     if (destination == null) {
153
     if (destination == null) {
147
       return false;
154
       return false;
148
     }
155
     }
149
     for (HandlingEvent event : deliveryHistory.eventsOrderedByCompletionTime()) {
156
     for (HandlingEvent event : deliveryHistory.eventsOrderedByCompletionTime()) {
150
-      if (HandlingEvent.Type.UNLOAD.equals(event.type()) &&
151
-          destination.equals(event.location())) {
157
+      if (HandlingEvent.Type.UNLOAD.equals(event.type())
158
+        && destination.equals(event.location())) {
152
         return true;
159
         return true;
153
       }
160
       }
154
     }
161
     }
165
    * @return <code>true</code> if the given cargo's and this cargos's trackingId is the same, regardles of other
172
    * @return <code>true</code> if the given cargo's and this cargos's trackingId is the same, regardles of other
166
    *         attributes.
173
    *         attributes.
167
    */
174
    */
168
-  private boolean sameIdentityAs(Cargo other) {
175
+  private boolean sameIdentityAs(final Cargo other) {
169
     return other != null && trackingId.equals(other.trackingId);
176
     return other != null && trackingId.equals(other.trackingId);
170
   }
177
   }
171
 
178
 
175
    * @see #sameIdentityAs(Cargo)
182
    * @see #sameIdentityAs(Cargo)
176
    */
183
    */
177
   @Override
184
   @Override
178
-  public boolean equals(Object object) {
185
+  public boolean equals(final Object object) {
179
     if (!(object instanceof Cargo)) {
186
     if (!(object instanceof Cargo)) {
180
       return false;
187
       return false;
181
     }
188
     }
182
-    Cargo other = (Cargo) object;
189
+    final Cargo other = (Cargo) object;
183
     return sameIdentityAs(other);
190
     return sameIdentityAs(other);
184
   }
191
   }
185
 
192
 

+ 13
- 6
dddsample/src/main/java/se/citerus/dddsample/domain/CarrierMovement.java Näytä tiedosto

9
  * A carrier movement is a vessel voyage from one location to another.
9
  * A carrier movement is a vessel voyage from one location to another.
10
  */
10
  */
11
 @Entity
11
 @Entity
12
-public class CarrierMovement {
12
+public final class CarrierMovement {
13
 
13
 
14
   @Id
14
   @Id
15
   @GeneratedValue
15
   @GeneratedValue
24
   @ManyToOne
24
   @ManyToOne
25
   private Location to;
25
   private Location to;
26
 
26
 
27
-  public CarrierMovement(CarrierMovementId carrierMovementId, Location from, Location to) {
28
-    Validate.noNullElements(new Object[] {carrierMovementId, from, to});
27
+  /**
28
+   * Constructor.
29
+   *
30
+   * @param carrierMovementId
31
+   * @param from
32
+   * @param to
33
+   */
34
+  public CarrierMovement(final CarrierMovementId carrierMovementId, final Location from, final Location to) {
35
+    Validate.noNullElements(new Object[]{carrierMovementId, from, to});
29
     this.carrierMovementId = carrierMovementId;
36
     this.carrierMovementId = carrierMovementId;
30
     this.from = from;
37
     this.from = from;
31
     this.to = to;
38
     this.to = to;
58
    * @return <code>true</code> if the given carrier movement's and this carrier movement's carrier id are the same,
65
    * @return <code>true</code> if the given carrier movement's and this carrier movement's carrier id are the same,
59
    *         regardles of other attributes.
66
    *         regardles of other attributes.
60
    */
67
    */
61
-  public boolean sameIdentityAs(CarrierMovement other) {
68
+  public boolean sameIdentityAs(final CarrierMovement other) {
62
     return carrierMovementId.equals(other.carrierMovementId);
69
     return carrierMovementId.equals(other.carrierMovementId);
63
   }
70
   }
64
 
71
 
65
   @Override
72
   @Override
66
-  public boolean equals(Object o) {
73
+  public boolean equals(final Object o) {
67
     if (this == o) return true;
74
     if (this == o) return true;
68
     if (o == null || getClass() != o.getClass()) return false;
75
     if (o == null || getClass() != o.getClass()) return false;
69
 
76
 
70
-    CarrierMovement that = (CarrierMovement) o;
77
+    final CarrierMovement that = (CarrierMovement) o;
71
 
78
 
72
     return sameIdentityAs(that);
79
     return sameIdentityAs(that);
73
   }
80
   }

+ 10
- 5
dddsample/src/main/java/se/citerus/dddsample/domain/CarrierMovementId.java Näytä tiedosto

9
 
9
 
10
 /**
10
 /**
11
  * Identifies a particular carrier movement, such as a flight number.
11
  * Identifies a particular carrier movement, such as a flight number.
12
- *
13
  */
12
  */
14
 @Embeddable
13
 @Embeddable
15
-public class CarrierMovementId {
14
+public final class CarrierMovementId {
16
 
15
 
17
   @Column(name = "carrier_movement_id")
16
   @Column(name = "carrier_movement_id")
18
   private String id;
17
   private String id;
19
 
18
 
20
-  public CarrierMovementId(String id) {
19
+  /**
20
+   * Constructor.
21
+   *
22
+   * @param id Id string.
23
+   */
24
+  public CarrierMovementId(final String id) {
21
     Validate.notNull(id);
25
     Validate.notNull(id);
22
     this.id = id;
26
     this.id = id;
23
   }
27
   }
30
   }
34
   }
31
 
35
 
32
   @Override
36
   @Override
33
-  public boolean equals(Object obj) {
37
+  public boolean equals(final Object obj) {
34
     return EqualsBuilder.reflectionEquals(this, obj);
38
     return EqualsBuilder.reflectionEquals(this, obj);
35
   }
39
   }
36
 
40
 
40
   }
44
   }
41
 
45
 
42
   // Needed by hibernate
46
   // Needed by hibernate
43
-  CarrierMovementId() {}
47
+  CarrierMovementId() {
48
+  }
44
 
49
 
45
 }
50
 }

+ 8
- 8
dddsample/src/main/java/se/citerus/dddsample/domain/DeliveryHistory.java Näytä tiedosto

7
 
7
 
8
 /**
8
 /**
9
  * The delivery history of a cargo.
9
  * The delivery history of a cargo.
10
- *
10
+ * <p/>
11
  * Is this an entiy or a value object?
11
  * Is this an entiy or a value object?
12
  */
12
  */
13
-public class DeliveryHistory {
13
+public final class DeliveryHistory {
14
 
14
 
15
-  private Set<HandlingEvent> events = new HashSet<HandlingEvent>();
15
+  private final Set<HandlingEvent> events = new HashSet<HandlingEvent>();
16
 
16
 
17
   /**
17
   /**
18
    * Adds all HandlingEvent to the delivery history.
18
    * Adds all HandlingEvent to the delivery history.
19
    *
19
    *
20
    * @param events events to add
20
    * @param events events to add
21
    */
21
    */
22
-  public void addAllEvents(Collection<HandlingEvent> events) {
22
+  public void addAllEvents(final Collection<HandlingEvent> events) {
23
     this.events.addAll(events);
23
     this.events.addAll(events);
24
   }
24
   }
25
 
25
 
28
    *
28
    *
29
    * @param event event to add.
29
    * @param event event to add.
30
    */
30
    */
31
-  public void addEvent(HandlingEvent event) {
31
+  public void addEvent(final HandlingEvent event) {
32
     this.events.add(event);
32
     this.events.add(event);
33
   }
33
   }
34
 
34
 
36
    * @return An <b>unmodifiable</b> list of handling events, ordered by the time the events occured.
36
    * @return An <b>unmodifiable</b> list of handling events, ordered by the time the events occured.
37
    */
37
    */
38
   public List<HandlingEvent> eventsOrderedByCompletionTime() {
38
   public List<HandlingEvent> eventsOrderedByCompletionTime() {
39
-    List<HandlingEvent> eventList = new ArrayList<HandlingEvent>(events);
39
+    final List<HandlingEvent> eventList = new ArrayList<HandlingEvent>(events);
40
     Collections.sort(eventList, HandlingEvent.BY_COMPLETION_TIME_COMPARATOR);
40
     Collections.sort(eventList, HandlingEvent.BY_COMPLETION_TIME_COMPARATOR);
41
     return Collections.unmodifiableList(eventList);
41
     return Collections.unmodifiableList(eventList);
42
   }
42
   }
48
     if (events.isEmpty()) {
48
     if (events.isEmpty()) {
49
       return null;
49
       return null;
50
     } else {
50
     } else {
51
-      List<HandlingEvent> orderedEvents = eventsOrderedByCompletionTime();
51
+      final List<HandlingEvent> orderedEvents = eventsOrderedByCompletionTime();
52
       return orderedEvents.get(orderedEvents.size() - 1);
52
       return orderedEvents.get(orderedEvents.size() - 1);
53
     }
53
     }
54
   }
54
   }
66
     if (lastEvent() == null)
66
     if (lastEvent() == null)
67
       return StatusCode.NOT_RECEIVED;
67
       return StatusCode.NOT_RECEIVED;
68
 
68
 
69
-    HandlingEvent.Type type = lastEvent().type();
69
+    final HandlingEvent.Type type = lastEvent().type();
70
     if (type == HandlingEvent.Type.LOAD)
70
     if (type == HandlingEvent.Type.LOAD)
71
       return StatusCode.ONBOARD_CARRIER;
71
       return StatusCode.ONBOARD_CARRIER;
72
 
72
 

+ 16
- 11
dddsample/src/main/java/se/citerus/dddsample/domain/HandlingEvent.java Näytä tiedosto

17
  * {@link Type#UNLOAD}. All other events must be of {@link Type#RECEIVE}, {@link Type#CLAIM} or {@link Type#CUSTOMS}.
17
  * {@link Type#UNLOAD}. All other events must be of {@link Type#RECEIVE}, {@link Type#CLAIM} or {@link Type#CUSTOMS}.
18
  */
18
  */
19
 @Entity
19
 @Entity
20
-public class HandlingEvent {
20
+public final class HandlingEvent {
21
 
21
 
22
   /**
22
   /**
23
    * Comparator used to be able to sort HandlingEvents according to their completion time
23
    * Comparator used to be able to sort HandlingEvents according to their completion time
24
    */
24
    */
25
   public static final Comparator<HandlingEvent> BY_COMPLETION_TIME_COMPARATOR = new Comparator<HandlingEvent>() {
25
   public static final Comparator<HandlingEvent> BY_COMPLETION_TIME_COMPARATOR = new Comparator<HandlingEvent>() {
26
-    public int compare(HandlingEvent o1, HandlingEvent o2) {
26
+    public int compare(final HandlingEvent o1, final HandlingEvent o2) {
27
       return o1.completionTime().compareTo(o2.completionTime());
27
       return o1.completionTime().compareTo(o2.completionTime());
28
     }
28
     }
29
   };
29
   };
58
 
58
 
59
     private boolean carrierMovementRequired;
59
     private boolean carrierMovementRequired;
60
 
60
 
61
-    private Type(boolean carrierMovementRequired) {
61
+    /**
62
+     * Private enum constructor.
63
+     *
64
+     * @param carrierMovementRequired Required status.
65
+     */
66
+    private Type(final boolean carrierMovementRequired) {
62
       this.carrierMovementRequired = carrierMovementRequired;
67
       this.carrierMovementRequired = carrierMovementRequired;
63
     }
68
     }
64
 
69
 
77
     }
82
     }
78
   }
83
   }
79
 
84
 
80
-
81
   /**
85
   /**
82
    * @param cargo            cargo
86
    * @param cargo            cargo
83
    * @param completionTime   completion time, the reported time that the event actually happened (e.g. the receive took place).
87
    * @param completionTime   completion time, the reported time that the event actually happened (e.g. the receive took place).
86
    * @param location         where the event took place
90
    * @param location         where the event took place
87
    * @param carrierMovement  carrier movement.
91
    * @param carrierMovement  carrier movement.
88
    */
92
    */
89
-  public HandlingEvent(Cargo cargo, Date completionTime, Date registrationTime, Type type, Location location, CarrierMovement carrierMovement) {
90
-    Validate.noNullElements(new Object[] {cargo, completionTime, registrationTime, type, location});
93
+  public HandlingEvent(final Cargo cargo, final Date completionTime, final Date registrationTime, final Type type,
94
+                       final Location location, final CarrierMovement carrierMovement) {
95
+    Validate.noNullElements(new Object[]{cargo, completionTime, registrationTime, type, location});
91
     this.registrationTime = registrationTime;
96
     this.registrationTime = registrationTime;
92
     this.completionTime = completionTime;
97
     this.completionTime = completionTime;
93
     this.type = type;
98
     this.type = type;
126
     return this.cargo;
131
     return this.cargo;
127
   }
132
   }
128
 
133
 
129
-  public boolean equals(Object o) {
134
+  public boolean equals(final Object o) {
130
     if (this == o) return true;
135
     if (this == o) return true;
131
     if (o == null || getClass() != o.getClass()) return false;
136
     if (o == null || getClass() != o.getClass()) return false;
132
 
137
 
133
-    HandlingEvent event = (HandlingEvent) o;
138
+    final HandlingEvent event = (HandlingEvent) o;
134
 
139
 
135
     return sameEventAs(event);
140
     return sameEventAs(event);
136
   }
141
   }
138
   /**
143
   /**
139
    * Events compare by the attributes that identify the underlying event as opposed to the report of the event.
144
    * Events compare by the attributes that identify the underlying event as opposed to the report of the event.
140
    * Therefore the completion time is part of the comparison but not the registration time.
145
    * Therefore the completion time is part of the comparison but not the registration time.
141
-   *
146
+   * <p/>
142
    * Compare this behavior to the value object {@link se.citerus.dddsample.domain.Leg#sameValueAs(Leg)}
147
    * Compare this behavior to the value object {@link se.citerus.dddsample.domain.Leg#sameValueAs(Leg)}
143
    * Compare this behavior to the entity {@link se.citerus.dddsample.domain.Cargo#sameIdentityAs(Cargo)}
148
    * Compare this behavior to the entity {@link se.citerus.dddsample.domain.Cargo#sameIdentityAs(Cargo)}
144
    *
149
    *
145
    * @param other The other hanling event.
150
    * @param other The other hanling event.
146
    * @return <code>true</code> if the given handling event and this event are regarded as the same.
151
    * @return <code>true</code> if the given handling event and this event are regarded as the same.
147
    */
152
    */
148
-  public boolean sameEventAs(HandlingEvent other) {
153
+  public boolean sameEventAs(final HandlingEvent other) {
149
     return other != null && new EqualsBuilder().
154
     return other != null && new EqualsBuilder().
150
       append(this.cargo, other.cargo).
155
       append(this.cargo, other.cargo).
151
       append(this.carrierMovement, other.carrierMovement).
156
       append(this.carrierMovement, other.carrierMovement).
157
 
162
 
158
   @Override
163
   @Override
159
   public int hashCode() {
164
   public int hashCode() {
160
-    return new HashCodeBuilder(13,41).
165
+    return new HashCodeBuilder().
161
       append(cargo).
166
       append(cargo).
162
       append(carrierMovement).
167
       append(carrierMovement).
163
       append(completionTime).
168
       append(completionTime).

+ 16
- 11
dddsample/src/main/java/se/citerus/dddsample/domain/Itinerary.java Näytä tiedosto

11
  *
11
  *
12
  */
12
  */
13
 @Entity
13
 @Entity
14
-public class Itinerary {
14
+public final class Itinerary {
15
 
15
 
16
   @Id
16
   @Id
17
   @GeneratedValue
17
   @GeneratedValue
23
 
23
 
24
   public static final Itinerary EMPTY_ITINERARY = new Itinerary();
24
   public static final Itinerary EMPTY_ITINERARY = new Itinerary();
25
 
25
 
26
-  public Itinerary(List<Leg> legs) {
26
+  /**
27
+   * Constructor.
28
+   *
29
+   * @param legs List of legs for this itinerary.
30
+   */
31
+  public Itinerary(final List<Leg> legs) {
27
     Validate.notEmpty(legs);
32
     Validate.notEmpty(legs);
28
     Validate.noNullElements(legs);
33
     Validate.noNullElements(legs);
29
     this.legs = legs;
34
     this.legs = legs;
30
   }
35
   }
31
 
36
 
32
-  public Itinerary(Leg... legs) {
37
+  public Itinerary(final Leg... legs) {
33
     this(Arrays.asList(legs));
38
     this(Arrays.asList(legs));
34
   }
39
   }
35
 
40
 
43
    * @param event Event to test.
48
    * @param event Event to test.
44
    * @return <code>true</code> if the event is expected
49
    * @return <code>true</code> if the event is expected
45
    */
50
    */
46
-  public boolean isExpected(HandlingEvent event) {
51
+  public boolean isExpected(final HandlingEvent event) {
47
     if (legs.isEmpty()) {
52
     if (legs.isEmpty()) {
48
       return true;
53
       return true;
49
     }
54
     }
50
 
55
 
51
     if (event.type() == HandlingEvent.Type.RECEIVE) {
56
     if (event.type() == HandlingEvent.Type.RECEIVE) {
52
       //Check that the first leg's origin is the event's location
57
       //Check that the first leg's origin is the event's location
53
-      Leg leg = legs.get(0);
58
+      final Leg leg = legs.get(0);
54
       return (leg.from().equals(event.location()));
59
       return (leg.from().equals(event.location()));
55
     }
60
     }
56
 
61
 
58
       //Check that the there is one leg with same from location and carrier movement
63
       //Check that the there is one leg with same from location and carrier movement
59
       for (Leg leg : legs) {
64
       for (Leg leg : legs) {
60
         if (leg.from().equals(event.location())
65
         if (leg.from().equals(event.location())
61
-           && leg.carrierMovement().equals(event.carrierMovement()))
66
+          && leg.carrierMovement().equals(event.carrierMovement()))
62
           return true;
67
           return true;
63
       }
68
       }
64
       return false;
69
       return false;
68
       //Check that the there is one leg with same to loc and carrier movement
73
       //Check that the there is one leg with same to loc and carrier movement
69
       for (Leg leg : legs) {
74
       for (Leg leg : legs) {
70
         if (leg.to().equals(event.location())
75
         if (leg.to().equals(event.location())
71
-           && leg.carrierMovement().equals(event.carrierMovement()))
76
+          && leg.carrierMovement().equals(event.carrierMovement()))
72
           return true;
77
           return true;
73
       }
78
       }
74
       return false;
79
       return false;
76
 
81
 
77
     if (event.type() == HandlingEvent.Type.CLAIM) {
82
     if (event.type() == HandlingEvent.Type.CLAIM) {
78
       //Check that the last leg's destination is from the event's location
83
       //Check that the last leg's destination is from the event's location
79
-      Leg leg = legs.get(legs.size() - 1);
84
+      final Leg leg = legs.get(legs.size() - 1);
80
       return (leg.to().equals(event.location()));
85
       return (leg.to().equals(event.location()));
81
     }
86
     }
82
 
87
 
88
    * @param other itinerary to compare
93
    * @param other itinerary to compare
89
    * @return <code>true</code> if the legs in this and the other itinerary are all equal.
94
    * @return <code>true</code> if the legs in this and the other itinerary are all equal.
90
    */
95
    */
91
-  public boolean sameValueAs(Itinerary other) {
96
+  public boolean sameValueAs(final Itinerary other) {
92
     return other != null && legs.equals(other.legs);
97
     return other != null && legs.equals(other.legs);
93
   }
98
   }
94
 
99
 
95
   @Override
100
   @Override
96
-  public boolean equals(Object o) {
101
+  public boolean equals(final Object o) {
97
     if (this == o) return true;
102
     if (this == o) return true;
98
     if (o == null || getClass() != o.getClass()) return false;
103
     if (o == null || getClass() != o.getClass()) return false;
99
 
104
 
100
-    Itinerary itinerary = (Itinerary) o;
105
+    final Itinerary itinerary = (Itinerary) o;
101
 
106
 
102
     return sameValueAs(itinerary);
107
     return sameValueAs(itinerary);
103
   }
108
   }

+ 14
- 7
dddsample/src/main/java/se/citerus/dddsample/domain/Leg.java Näytä tiedosto

15
  * An itinerary consists of one or more legs.
15
  * An itinerary consists of one or more legs.
16
  */
16
  */
17
 @Entity
17
 @Entity
18
-public class Leg {
18
+public final class Leg {
19
   @Id
19
   @Id
20
   @GeneratedValue
20
   @GeneratedValue
21
   private Long id;
21
   private Long id;
28
   @ManyToOne
28
   @ManyToOne
29
   private Location to;
29
   private Location to;
30
 
30
 
31
-  public Leg(CarrierMovement carrierMovement, Location from, Location to) {
32
-    Validate.noNullElements(new Object[] {carrierMovement, from, to});
31
+  /**
32
+   * Constructor.
33
+   *
34
+   * @param carrierMovement
35
+   * @param from
36
+   * @param to
37
+   */
38
+  public Leg(final CarrierMovement carrierMovement, final Location from, final Location to) {
39
+    Validate.noNullElements(new Object[]{carrierMovement, from, to});
33
     this.carrierMovement = carrierMovement;
40
     this.carrierMovement = carrierMovement;
34
     this.from = from;
41
     this.from = from;
35
     this.to = to;
42
     this.to = to;
47
     return carrierMovement;
54
     return carrierMovement;
48
   }
55
   }
49
 
56
 
50
-  
57
+
51
   /**
58
   /**
52
    * Value objects compare by value, therefore the id field which must be part of the class in order to support
59
    * Value objects compare by value, therefore the id field which must be part of the class in order to support
53
    * persistence is ignored in the comparison.
60
    * persistence is ignored in the comparison.
57
    * @param other The other leg.
64
    * @param other The other leg.
58
    * @return <code>true</code> if the given leg's and this leg's attributes are the same.
65
    * @return <code>true</code> if the given leg's and this leg's attributes are the same.
59
    */
66
    */
60
-  public boolean sameValueAs(Leg other) {
67
+  public boolean sameValueAs(final Leg other) {
61
     return other != null && new EqualsBuilder().
68
     return other != null && new EqualsBuilder().
62
       append(this.carrierMovement, other.carrierMovement).
69
       append(this.carrierMovement, other.carrierMovement).
63
       append(this.from, other.from).
70
       append(this.from, other.from).
66
   }
73
   }
67
 
74
 
68
   @Override
75
   @Override
69
-  public boolean equals(Object o) {
76
+  public boolean equals(final Object o) {
70
     if (this == o) return true;
77
     if (this == o) return true;
71
     if (o == null || getClass() != o.getClass()) return false;
78
     if (o == null || getClass() != o.getClass()) return false;
72
 
79
 
77
 
84
 
78
   @Override
85
   @Override
79
   public int hashCode() {
86
   public int hashCode() {
80
-    return new HashCodeBuilder(13,17).
87
+    return new HashCodeBuilder().
81
       append(carrierMovement).
88
       append(carrierMovement).
82
       append(from).
89
       append(from).
83
       append(to).
90
       append(to).

+ 9
- 11
dddsample/src/main/java/se/citerus/dddsample/domain/Location.java Näytä tiedosto

8
 import javax.persistence.Id;
8
 import javax.persistence.Id;
9
 
9
 
10
 @Entity
10
 @Entity
11
-public class Location {
11
+public final class Location {
12
 
12
 
13
   @Id
13
   @Id
14
   @GeneratedValue
14
   @GeneratedValue
22
   /**
22
   /**
23
    * Special Location object that marks an unknown location.
23
    * Special Location object that marks an unknown location.
24
    */
24
    */
25
-  public static final Location UNKNOWN = new Location(
26
-     new UnLocode("XXXXX"), "Unknown location"
27
-  );
25
+  public static final Location UNKNOWN = new Location(new UnLocode("XXXXX"), "Unknown location");
28
 
26
 
29
   /**
27
   /**
30
    * Package-level constructor, visible for test only.
28
    * Package-level constructor, visible for test only.
31
-   * 
29
+   *
32
    * @param unLocode UN Locode
30
    * @param unLocode UN Locode
33
    * @param name     location name
31
    * @param name     location name
34
    * @throws IllegalArgumentException if the UN Locode or name is null
32
    * @throws IllegalArgumentException if the UN Locode or name is null
35
    */
33
    */
36
-  Location(UnLocode unLocode, String name) {
37
-    Validate.noNullElements(new Object[] {unLocode, name});
34
+  Location(final UnLocode unLocode, final String name) {
35
+    Validate.noNullElements(new Object[]{unLocode, name});
38
     Validate.notNull(unLocode);
36
     Validate.notNull(unLocode);
39
     Validate.notNull(name);
37
     Validate.notNull(name);
40
     this.unLocode = unLocode;
38
     this.unLocode = unLocode;
60
    * @return Since this is an entiy this will be true iff UN locodes are equal.
58
    * @return Since this is an entiy this will be true iff UN locodes are equal.
61
    */
59
    */
62
   @Override
60
   @Override
63
-  public boolean equals(Object object) {
61
+  public boolean equals(final Object object) {
64
     if (object == null) {
62
     if (object == null) {
65
       return false;
63
       return false;
66
     }
64
     }
77
   /**
75
   /**
78
    * Entities compare by identity, therefore the unLocode field is the only basis of comparison. For persistence we
76
    * Entities compare by identity, therefore the unLocode field is the only basis of comparison. For persistence we
79
    * have an id field, but it is not used for identiy comparison.
77
    * have an id field, but it is not used for identiy comparison.
80
-   *
78
+   * <p/>
81
    * Compare this behavior to the value object {@link se.citerus.dddsample.domain.Leg#sameValueAs(Leg)}
79
    * Compare this behavior to the value object {@link se.citerus.dddsample.domain.Leg#sameValueAs(Leg)}
82
    *
80
    *
83
    * @param other The other location.
81
    * @param other The other location.
84
    * @return <code>true</code> if the given location's and this locations's unLocode is the same, regardles of other
82
    * @return <code>true</code> if the given location's and this locations's unLocode is the same, regardles of other
85
-   * attributes.
83
+   *         attributes.
86
    */
84
    */
87
-  public boolean sameIdentityAs(Location other) {
85
+  public boolean sameIdentityAs(final Location other) {
88
     return this.unLocode.equals(other.unLocode);
86
     return this.unLocode.equals(other.unLocode);
89
   }
87
   }
90
 
88
 

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/domain/Specification.java Näytä tiedosto

1
 package se.citerus.dddsample.domain;
1
 package se.citerus.dddsample.domain;
2
 
2
 
3
 /**
3
 /**
4
- * 
4
+ *
5
  */
5
  */
6
 public interface Specification {
6
 public interface Specification {
7
 }
7
 }

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/domain/StatusCode.java Näytä tiedosto

1
 package se.citerus.dddsample.domain;
1
 package se.citerus.dddsample.domain;
2
 
2
 
3
 /**
3
 /**
4
- * These are the different status codes for a cargo.
4
+ * Represents the different status codes for a cargo.
5
  */
5
  */
6
 public enum StatusCode {
6
 public enum StatusCode {
7
   NOT_RECEIVED, IN_PORT, ONBOARD_CARRIER, CLAIMED
7
   NOT_RECEIVED, IN_PORT, ONBOARD_CARRIER, CLAIMED

+ 9
- 4
dddsample/src/main/java/se/citerus/dddsample/domain/TrackingId.java Näytä tiedosto

9
 
9
 
10
 /**
10
 /**
11
  * Identifies a particular cargo.
11
  * Identifies a particular cargo.
12
- * <p>
12
+ * <p/>
13
  * Make sure to put a constraint in the database to make sure TrackingId is unique.
13
  * Make sure to put a constraint in the database to make sure TrackingId is unique.
14
  */
14
  */
15
 @Embeddable
15
 @Embeddable
16
-public class TrackingId {
16
+public final class TrackingId {
17
 
17
 
18
   @Column(name = "tracking_id")
18
   @Column(name = "tracking_id")
19
   private String id;
19
   private String id;
20
 
20
 
21
-  public TrackingId(String id) {
21
+  /**
22
+   * Constructor.
23
+   *
24
+   * @param id Id string.
25
+   */
26
+  public TrackingId(final String id) {
22
     Validate.notNull(id);
27
     Validate.notNull(id);
23
     this.id = id;
28
     this.id = id;
24
   }
29
   }
31
   }
36
   }
32
 
37
 
33
   @Override
38
   @Override
34
-  public boolean equals(Object obj) {
39
+  public boolean equals(final Object obj) {
35
     return EqualsBuilder.reflectionEquals(this, obj);
40
     return EqualsBuilder.reflectionEquals(this, obj);
36
   }
41
   }
37
 
42
 

+ 12
- 7
dddsample/src/main/java/se/citerus/dddsample/domain/UnLocode.java Näytä tiedosto

9
 
9
 
10
 /**
10
 /**
11
  * United nations location code.
11
  * United nations location code.
12
- *
12
+ * <p/>
13
  * http://www.unece.org/cefact/locode/
13
  * http://www.unece.org/cefact/locode/
14
  * http://www.unece.org/cefact/locode/DocColumnDescription.htm#LOCODE
14
  * http://www.unece.org/cefact/locode/DocColumnDescription.htm#LOCODE
15
  */
15
  */
16
 @Embeddable
16
 @Embeddable
17
-public class UnLocode {
17
+public final class UnLocode {
18
 
18
 
19
   private String unlocode;
19
   private String unlocode;
20
 
20
 
21
   // Country code is exactly two letters.
21
   // Country code is exactly two letters.
22
   // Location code is usually three letters, but may contain the numbers 2-9 as well
22
   // Location code is usually three letters, but may contain the numbers 2-9 as well
23
-  private static final Pattern validPattern = Pattern.compile("[a-zA-Z]{2}[a-zA-Z2-9]{3}");
23
+  private static final Pattern VALID_PATTERN = Pattern.compile("[a-zA-Z]{2}[a-zA-Z2-9]{3}");
24
 
24
 
25
-  public UnLocode(String countryAndLocation) {
25
+  /**
26
+   * Constructor.
27
+   *
28
+   * @param countryAndLocation Location string.
29
+   */
30
+  public UnLocode(final String countryAndLocation) {
26
     Validate.notNull(countryAndLocation);
31
     Validate.notNull(countryAndLocation);
27
-    Validate.isTrue(validPattern.matcher(countryAndLocation).matches());
32
+    Validate.isTrue(VALID_PATTERN.matcher(countryAndLocation).matches());
28
 
33
 
29
     this.unlocode = countryAndLocation.toUpperCase();
34
     this.unlocode = countryAndLocation.toUpperCase();
30
   }
35
   }
31
 
36
 
32
   /**
37
   /**
33
-   * @return country code and location code concatenated
38
+   * @return country code and location code concatenated.
34
    */
39
    */
35
   public String idString() {
40
   public String idString() {
36
     return unlocode;
41
     return unlocode;
37
   }
42
   }
38
 
43
 
39
   @Override
44
   @Override
40
-  public boolean equals(Object obj) {
45
+  public boolean equals(final Object obj) {
41
     return EqualsBuilder.reflectionEquals(this, obj);
46
     return EqualsBuilder.reflectionEquals(this, obj);
42
   }
47
   }
43
 
48
 

+ 19
- 0
dddsample/src/main/java/se/citerus/dddsample/repository/CargoRepository.java Näytä tiedosto

7
 
7
 
8
 public interface CargoRepository {
8
 public interface CargoRepository {
9
 
9
 
10
+  /**
11
+   * Finds a cargo using given id.
12
+   *
13
+   * @param trackingId Id
14
+   * @return Cargo
15
+   */
10
   Cargo find(TrackingId trackingId);
16
   Cargo find(TrackingId trackingId);
11
 
17
 
18
+  /**
19
+   * Finds all cargo.
20
+   *
21
+   * @return All cargo.
22
+   */
12
   List<Cargo> findAll();
23
   List<Cargo> findAll();
13
 
24
 
25
+  /**
26
+   * Saves given cargo.
27
+   *
28
+   * @param cargo Cargo to save.
29
+   */
14
   void save(Cargo cargo);
30
   void save(Cargo cargo);
15
 
31
 
32
+  /**
33
+   * @return A new generated tracking Id.
34
+   */
16
   TrackingId nextTrackingId();
35
   TrackingId nextTrackingId();
17
 
36
 
18
 }
37
 }

+ 13
- 11
dddsample/src/main/java/se/citerus/dddsample/repository/CargoRepositoryInMem.java Näytä tiedosto

12
 /**
12
 /**
13
  * CargoRepositoryInMem implement the CargoRepository interface but is a test
13
  * CargoRepositoryInMem implement the CargoRepository interface but is a test
14
  * class not intended for usage in real application.
14
  * class not intended for usage in real application.
15
- * 
15
+ * <p/>
16
  * It setup a simple local hash with a number of Cargo's with TrackingId as key
16
  * It setup a simple local hash with a number of Cargo's with TrackingId as key
17
  * defined at compile time.
17
  * defined at compile time.
18
- * 
18
+ * <p/>
19
  * To be able to test exceptions, a DataRetrievalFailureException is thrown when finding a Cargo with trackingId "DAE".
19
  * To be able to test exceptions, a DataRetrievalFailureException is thrown when finding a Cargo with trackingId "DAE".
20
- * 
21
  */
20
  */
22
 public class CargoRepositoryInMem implements CargoRepository {
21
 public class CargoRepositoryInMem implements CargoRepository {
22
+
23
   private Map<String, Cargo> cargoDb;
23
   private Map<String, Cargo> cargoDb;
24
   private HandlingEventRepository handlingEventRepository;
24
   private HandlingEventRepository handlingEventRepository;
25
 
25
 
26
-  public CargoRepositoryInMem() throws Exception {
26
+  /**
27
+   * Constructor.
28
+   */
29
+  public CargoRepositoryInMem() {
27
     cargoDb = new HashMap<String, Cargo>();
30
     cargoDb = new HashMap<String, Cargo>();
28
   }
31
   }
29
 
32
 
30
-  public Cargo find(TrackingId trackingId) {
31
-    if (trackingId.idString().equalsIgnoreCase("DAE")){
33
+  public Cargo find(final TrackingId trackingId) {
34
+    if (trackingId.idString().equalsIgnoreCase("DAE")) {
32
       throw new DataRetrievalFailureException("Network failure. Please try again");
35
       throw new DataRetrievalFailureException("Network failure. Please try again");
33
     }
36
     }
34
-    
37
+
35
     return cargoDb.get(trackingId.idString());
38
     return cargoDb.get(trackingId.idString());
36
   }
39
   }
37
-  
38
-  public void save(Cargo cargo) {
40
+
41
+  public void save(final Cargo cargo) {
39
     //No need to save anything with InMem
42
     //No need to save anything with InMem
40
   }
43
   }
41
 
44
 
48
   }
51
   }
49
 
52
 
50
   /**
53
   /**
51
-   * 
52
    * @throws Exception
54
    * @throws Exception
53
    */
55
    */
54
   public void init() throws Exception {
56
   public void init() throws Exception {
79
     */
81
     */
80
   }
82
   }
81
 
83
 
82
-  public void setHandlingEventRepository(HandlingEventRepository handlingEventRepository) {
84
+  public void setHandlingEventRepository(final HandlingEventRepository handlingEventRepository) {
83
     this.handlingEventRepository = handlingEventRepository;
85
     this.handlingEventRepository = handlingEventRepository;
84
   }
86
   }
85
 }
87
 }

+ 6
- 0
dddsample/src/main/java/se/citerus/dddsample/repository/CarrierMovementRepository.java Näytä tiedosto

5
 
5
 
6
 public interface CarrierMovementRepository {
6
 public interface CarrierMovementRepository {
7
 
7
 
8
+  /**
9
+   * Finds a carrier movement using given id.
10
+   *
11
+   * @param carrierMovementId Id
12
+   * @return The carrier movement.
13
+   */
8
   CarrierMovement find(CarrierMovementId carrierMovementId);
14
   CarrierMovement find(CarrierMovementId carrierMovementId);
9
 
15
 
10
 }
16
 }

+ 5
- 6
dddsample/src/main/java/se/citerus/dddsample/repository/CarrierMovementRepositoryHibernate.java Näytä tiedosto

6
 
6
 
7
 /**
7
 /**
8
  * Hibernate implementation of CarrierMovementRepository.
8
  * Hibernate implementation of CarrierMovementRepository.
9
- *
10
  */
9
  */
11
 @Repository
10
 @Repository
12
-public class CarrierMovementRepositoryHibernate extends HibernateRepository implements CarrierMovementRepository {
11
+public final class CarrierMovementRepositoryHibernate extends HibernateRepository implements CarrierMovementRepository {
13
 
12
 
14
-  public CarrierMovement find(CarrierMovementId carrierMovementId) {
13
+  public CarrierMovement find(final CarrierMovementId carrierMovementId) {
15
     return (CarrierMovement) getSession().
14
     return (CarrierMovement) getSession().
16
-            createQuery("from CarrierMovement where carrierMovementId = ?").
17
-            setParameter(0, carrierMovementId).
18
-            uniqueResult();
15
+      createQuery("from CarrierMovement where carrierMovementId = ?").
16
+      setParameter(0, carrierMovementId).
17
+      uniqueResult();
19
   }
18
   }
20
 
19
 
21
 }
20
 }

+ 6
- 2
dddsample/src/main/java/se/citerus/dddsample/repository/CarrierMovementRepositoryInMem.java Näytä tiedosto

6
 import java.util.HashMap;
6
 import java.util.HashMap;
7
 import java.util.Map;
7
 import java.util.Map;
8
 
8
 
9
-public class CarrierMovementRepositoryInMem implements CarrierMovementRepository {
9
+public final class CarrierMovementRepositoryInMem implements CarrierMovementRepository {
10
+
10
   private Map<CarrierMovementId, CarrierMovement> carriers;
11
   private Map<CarrierMovementId, CarrierMovement> carriers;
11
 
12
 
13
+  /**
14
+   * Constructor.
15
+   */
12
   public CarrierMovementRepositoryInMem() {
16
   public CarrierMovementRepositoryInMem() {
13
     carriers = new HashMap<CarrierMovementId, CarrierMovement>();
17
     carriers = new HashMap<CarrierMovementId, CarrierMovement>();
14
     setup();
18
     setup();
35
 */
39
 */
36
   }
40
   }
37
 
41
 
38
-  public CarrierMovement find(CarrierMovementId carrierMovementId) {
42
+  public CarrierMovement find(final CarrierMovementId carrierMovementId) {
39
     return carriers.get(carrierMovementId);
43
     return carriers.get(carrierMovementId);
40
   }
44
   }
41
 
45
 

+ 2
- 3
dddsample/src/main/java/se/citerus/dddsample/repository/HandlingEventRepository.java Näytä tiedosto

7
 
7
 
8
 /**
8
 /**
9
  * Handling event repository.
9
  * Handling event repository.
10
- *
11
  */
10
  */
12
 public interface HandlingEventRepository {
11
 public interface HandlingEventRepository {
13
 
12
 
16
    *
15
    *
17
    * @param event handling event to save
16
    * @param event handling event to save
18
    */
17
    */
19
-  void save(HandlingEvent event);
18
+  void save(final HandlingEvent event);
20
 
19
 
21
   /**
20
   /**
22
    * @param trackingId cargo tracking id
21
    * @param trackingId cargo tracking id
23
    * @return All handling events for this cargo, ordered by completion time.
22
    * @return All handling events for this cargo, ordered by completion time.
24
    */
23
    */
25
-  List<HandlingEvent> findEventsForCargo(TrackingId trackingId);
24
+  List<HandlingEvent> findEventsForCargo(final TrackingId trackingId);
26
 }
25
 }

+ 20
- 28
dddsample/src/main/java/se/citerus/dddsample/repository/HandlingEventRepositoryInMem.java Näytä tiedosto

10
 import java.text.SimpleDateFormat;
10
 import java.text.SimpleDateFormat;
11
 import java.util.*;
11
 import java.util.*;
12
 
12
 
13
-public class HandlingEventRepositoryInMem implements HandlingEventRepository{
14
-  private HashMap<String, HandlingEvent> eventDB;
15
-  private CarrierMovementRepository carrierMovementRepository;
16
-  
13
+public class HandlingEventRepositoryInMem implements HandlingEventRepository {
17
   private final Log logger = LogFactory.getLog(getClass());
14
   private final Log logger = LogFactory.getLog(getClass());
18
-
19
-  public HandlingEventRepositoryInMem() throws ParseException {
20
-    eventDB = new HashMap<String, HandlingEvent>();
21
-  }
15
+  private final HashMap<String, HandlingEvent> eventDB = new HashMap<String, HandlingEvent>();
16
+  private CarrierMovementRepository carrierMovementRepository;
22
 
17
 
23
   /**
18
   /**
24
    * Initilaze the in mem repository.
19
    * Initilaze the in mem repository.
25
-   * 
20
+   * <p/>
26
    * SpringIoC will call this init-method after the bean has bean created and properties has been set.
21
    * SpringIoC will call this init-method after the bean has bean created and properties has been set.
27
-   * 
22
+   *
28
    * @throws ParseException
23
    * @throws ParseException
29
    */
24
    */
30
   public void init() throws ParseException {
25
   public void init() throws ParseException {
70
 */
65
 */
71
   }
66
   }
72
 
67
 
73
-  
74
-  private void registerEvent(Cargo cargo, String date, Type type, CarrierMovement carrierMovement) throws ParseException{
68
+  private void registerEvent(Cargo cargo, String date, Type type, CarrierMovement carrierMovement) throws ParseException {
75
     HandlingEvent event = new HandlingEvent(cargo, getDate(date), new Date(), type, null, carrierMovement);
69
     HandlingEvent event = new HandlingEvent(cargo, getDate(date), new Date(), type, null, carrierMovement);
76
     //cargo.handle(event);
70
     //cargo.handle(event);
77
     String id = cargo.trackingId() + "_" + type + "_" + date;
71
     String id = cargo.trackingId() + "_" + type + "_" + date;
78
-    
72
+
79
     logger.debug("Adding event " + id + "(" + event + ")");
73
     logger.debug("Adding event " + id + "(" + event + ")");
80
     eventDB.put(id, event);
74
     eventDB.put(id, event);
81
   }
75
   }
83
 
77
 
84
   /**
78
   /**
85
    * Parse an ISO 8601 (YYYY-MM-DD) String to Date
79
    * Parse an ISO 8601 (YYYY-MM-DD) String to Date
86
-   * 
87
-   * @param isoFormat
88
-   *            String to parse.
80
+   *
81
+   * @param isoFormat String to parse.
89
    * @return Created date instance.
82
    * @return Created date instance.
90
-   * @throws ParseException
91
-   *             Thrown if parsing fails.
83
+   * @throws ParseException Thrown if parsing fails.
92
    */
84
    */
93
-  private Date getDate(String isoFormat) throws ParseException {
85
+  private Date getDate(final String isoFormat) throws ParseException {
94
     final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
86
     final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
95
     return dateFormat.parse(isoFormat);
87
     return dateFormat.parse(isoFormat);
96
   }
88
   }
97
-  
98
-  public HandlingEvent find(String handlingEventId){
89
+
90
+  public HandlingEvent find(final String handlingEventId) {
99
     return eventDB.get(handlingEventId);
91
     return eventDB.get(handlingEventId);
100
   }
92
   }
101
 
93
 
102
-  public void save(HandlingEvent event) {
94
+  public void save(final HandlingEvent event) {
103
     // Mimmick saving to database
95
     // Mimmick saving to database
104
     /*
96
     /*
105
     for (Cargo cargo : event.registerdCargos()) {
97
     for (Cargo cargo : event.registerdCargos()) {
108
     */
100
     */
109
   }
101
   }
110
 
102
 
111
-  public List<HandlingEvent> findEventsForCargo(TrackingId trackingId) {
103
+  public List<HandlingEvent> findEventsForCargo(final TrackingId trackingId) {
112
     return new ArrayList<HandlingEvent>(eventDB.values());
104
     return new ArrayList<HandlingEvent>(eventDB.values());
113
   }
105
   }
114
 
106
 
115
-  public DeliveryHistory findDeliveryHistory(TrackingId trackingId) {
107
+  public DeliveryHistory findDeliveryHistory(final TrackingId trackingId) {
116
     return null;  //To change body of implemented methods use File | Settings | File Templates.
108
     return null;  //To change body of implemented methods use File | Settings | File Templates.
117
   }
109
   }
118
 
110
 
119
   @SuppressWarnings("unchecked")
111
   @SuppressWarnings("unchecked")
120
   public Set<HandlingEvent> findByTrackingId(final TrackingId trackingId) {
112
   public Set<HandlingEvent> findByTrackingId(final TrackingId trackingId) {
121
-    Set<HandlingEvent> events = new HashSet<HandlingEvent>();
113
+    final Set<HandlingEvent> events = new HashSet<HandlingEvent>();
122
     for (HandlingEvent event : eventDB.values()) {
114
     for (HandlingEvent event : eventDB.values()) {
123
       /*
115
       /*
124
       for (Cargo cargo : event.registerdCargos()) {
116
       for (Cargo cargo : event.registerdCargos()) {
129
       }
121
       }
130
         */
122
         */
131
     }
123
     }
132
-    
124
+
133
     logger.debug("findByTrackingId " + trackingId + " finds " + events);
125
     logger.debug("findByTrackingId " + trackingId + " finds " + events);
134
-    
126
+
135
     return events;
127
     return events;
136
   }
128
   }
137
 
129
 
138
-  public void setCarrierRepository(CarrierMovementRepository carrierMovementRepository) {
130
+  public void setCarrierRepository(final CarrierMovementRepository carrierMovementRepository) {
139
     this.carrierMovementRepository = carrierMovementRepository;
131
     this.carrierMovementRepository = carrierMovementRepository;
140
   }
132
   }
141
 }
133
 }

+ 2
- 3
dddsample/src/main/java/se/citerus/dddsample/repository/HibernateRepository.java Näytä tiedosto

6
 
6
 
7
 /**
7
 /**
8
  * Functionality common to all Hibernate repositories.
8
  * Functionality common to all Hibernate repositories.
9
- *
10
  */
9
  */
11
 public abstract class HibernateRepository {
10
 public abstract class HibernateRepository {
12
 
11
 
13
-  SessionFactory sessionFactory;
12
+  private SessionFactory sessionFactory;
14
 
13
 
15
   @Required
14
   @Required
16
-  public void setSessionFactory(SessionFactory sessionFactory) {
15
+  public void setSessionFactory(final SessionFactory sessionFactory) {
17
     this.sessionFactory = sessionFactory;
16
     this.sessionFactory = sessionFactory;
18
   }
17
   }
19
 
18
 

+ 11
- 0
dddsample/src/main/java/se/citerus/dddsample/repository/LocationRepository.java Näytä tiedosto

7
 
7
 
8
 public interface LocationRepository {
8
 public interface LocationRepository {
9
 
9
 
10
+  /**
11
+   * Finds a location using given unlocode.
12
+   *
13
+   * @param unLocode UNLocode.
14
+   * @return Location.
15
+   */
10
   Location find(UnLocode unLocode);
16
   Location find(UnLocode unLocode);
11
 
17
 
18
+  /**
19
+   * Finds all locations.
20
+   *
21
+   * @return All locations.
22
+   */
12
   List<Location> findAll();
23
   List<Location> findAll();
13
 
24
 
14
 }
25
 }

+ 5
- 5
dddsample/src/main/java/se/citerus/dddsample/repository/LocationRepositoryHibernate.java Näytä tiedosto

5
 
5
 
6
 import java.util.List;
6
 import java.util.List;
7
 
7
 
8
-public class LocationRepositoryHibernate extends HibernateRepository implements LocationRepository {
8
+public final class LocationRepositoryHibernate extends HibernateRepository implements LocationRepository {
9
 
9
 
10
-  public Location find(UnLocode unLocode) {
10
+  public Location find(final UnLocode unLocode) {
11
     return (Location) getSession().
11
     return (Location) getSession().
12
-          createQuery("from Location where unLocode = ?").
13
-          setParameter(0, unLocode).
14
-          uniqueResult();
12
+      createQuery("from Location where unLocode = ?").
13
+      setParameter(0, unLocode).
14
+      uniqueResult();
15
   }
15
   }
16
 
16
 
17
   public List<Location> findAll() {
17
   public List<Location> findAll() {

+ 2
- 3
dddsample/src/main/java/se/citerus/dddsample/service/CargoService.java Näytä tiedosto

10
 
10
 
11
 /**
11
 /**
12
  * Cargo service.
12
  * Cargo service.
13
- *
14
  */
13
  */
15
 public interface CargoService {
14
 public interface CargoService {
16
 
15
 
17
   /**
16
   /**
18
    * Registers a new cargo in the tracking system, not yet routed.
17
    * Registers a new cargo in the tracking system, not yet routed.
19
    *
18
    *
20
-   * @param origin cargo origin
19
+   * @param origin      cargo origin
21
    * @param destination cargo destination
20
    * @param destination cargo destination
22
    * @return Cargo tracking id
21
    * @return Cargo tracking id
23
    */
22
    */
63
    * based on this list of legs.
62
    * based on this list of legs.
64
    *
63
    *
65
    * @param trackingId cargo tracking id
64
    * @param trackingId cargo tracking id
66
-   * @param itinerary the new itinerary, from a selection
65
+   * @param itinerary  the new itinerary, from a selection
67
    */
66
    */
68
   void assignItinerary(TrackingId trackingId, ItineraryCandidateDTO itinerary);
67
   void assignItinerary(TrackingId trackingId, ItineraryCandidateDTO itinerary);
69
 
68
 

+ 35
- 39
dddsample/src/main/java/se/citerus/dddsample/service/CargoServiceImpl.java Näytä tiedosto

13
 import java.util.ArrayList;
13
 import java.util.ArrayList;
14
 import java.util.List;
14
 import java.util.List;
15
 
15
 
16
-public class CargoServiceImpl implements CargoService {
16
+public final class CargoServiceImpl implements CargoService {
17
 
17
 
18
   private CargoRepository cargoRepository;
18
   private CargoRepository cargoRepository;
19
   private LocationRepository locationRepository;
19
   private LocationRepository locationRepository;
20
   private CarrierMovementRepository carrierMovementRepository;
20
   private CarrierMovementRepository carrierMovementRepository;
21
 
21
 
22
-  private static final Log logger = LogFactory.getLog(CargoServiceImpl.class);
22
+  private final Log logger = LogFactory.getLog(getClass());
23
 
23
 
24
   @Transactional(readOnly = false)
24
   @Transactional(readOnly = false)
25
-  public TrackingId registerNew(UnLocode originUnLocode, UnLocode destinationUnLocode) {
25
+  public TrackingId registerNew(final UnLocode originUnLocode, final UnLocode destinationUnLocode) {
26
     Validate.notNull(originUnLocode);
26
     Validate.notNull(originUnLocode);
27
     Validate.notNull(destinationUnLocode);
27
     Validate.notNull(destinationUnLocode);
28
 
28
 
29
-    TrackingId trackingId = cargoRepository.nextTrackingId();
30
-    Location origin = locationRepository.find(originUnLocode);
31
-    Location destination = locationRepository.find(destinationUnLocode);
29
+    final TrackingId trackingId = cargoRepository.nextTrackingId();
30
+    final Location origin = locationRepository.find(originUnLocode);
31
+    final Location destination = locationRepository.find(destinationUnLocode);
32
 
32
 
33
-    Cargo cargo = new Cargo(trackingId,origin,destination);
33
+    final Cargo cargo = new Cargo(trackingId, origin, destination);
34
 
34
 
35
     cargoRepository.save(cargo);
35
     cargoRepository.save(cargo);
36
     logger.info("Registered new cargo with tracking id " + trackingId.idString());
36
     logger.info("Registered new cargo with tracking id " + trackingId.idString());
40
 
40
 
41
   @Transactional(readOnly = true)
41
   @Transactional(readOnly = true)
42
   public List<UnLocode> shippingLocations() {
42
   public List<UnLocode> shippingLocations() {
43
-    List<Location> allLocations = locationRepository.findAll();
44
-    List<UnLocode> unlocodes = new ArrayList<UnLocode>(allLocations.size());
43
+    final List<Location> allLocations = locationRepository.findAll();
44
+    final List<UnLocode> unlocodes = new ArrayList<UnLocode>(allLocations.size());
45
     for (Location location : allLocations) {
45
     for (Location location : allLocations) {
46
       unlocodes.add(location.unLocode());
46
       unlocodes.add(location.unLocode());
47
     }
47
     }
49
   }
49
   }
50
 
50
 
51
   @Transactional(readOnly = true)
51
   @Transactional(readOnly = true)
52
-  public CargoTrackingDTO track(TrackingId trackingId) {
52
+  public CargoTrackingDTO track(final TrackingId trackingId) {
53
     Validate.notNull(trackingId);
53
     Validate.notNull(trackingId);
54
 
54
 
55
     final Cargo cargo = cargoRepository.find(trackingId);
55
     final Cargo cargo = cargoRepository.find(trackingId);
57
       return null;
57
       return null;
58
     }
58
     }
59
 
59
 
60
-    DeliveryHistory deliveryHistory = cargo.deliveryHistory();
60
+    final DeliveryHistory deliveryHistory = cargo.deliveryHistory();
61
 
61
 
62
     // TODO: use DTO assemblers
62
     // TODO: use DTO assemblers
63
-    Location currentLocation = deliveryHistory.currentLocation();
64
-    CarrierMovement currentCarrierMovement = deliveryHistory.currentCarrierMovement();
63
+    final Location currentLocation = deliveryHistory.currentLocation();
64
+    final CarrierMovement currentCarrierMovement = deliveryHistory.currentCarrierMovement();
65
     final CargoTrackingDTO dto = new CargoTrackingDTO(
65
     final CargoTrackingDTO dto = new CargoTrackingDTO(
66
       cargo.trackingId().idString(),
66
       cargo.trackingId().idString(),
67
       cargo.origin().toString(),
67
       cargo.origin().toString(),
74
 
74
 
75
     final List<HandlingEvent> events = deliveryHistory.eventsOrderedByCompletionTime();
75
     final List<HandlingEvent> events = deliveryHistory.eventsOrderedByCompletionTime();
76
     for (HandlingEvent event : events) {
76
     for (HandlingEvent event : events) {
77
-      CarrierMovement cm = event.carrierMovement();
78
-      String carrierIdString = (cm == null) ? "" : cm.carrierMovementId().idString();
77
+      final CarrierMovement cm = event.carrierMovement();
78
+      final String carrierIdString = (cm == null) ? "" : cm.carrierMovementId().idString();
79
       dto.addEvent(new HandlingEventDTO(
79
       dto.addEvent(new HandlingEventDTO(
80
         event.location().toString(),
80
         event.location().toString(),
81
         event.type().toString(),
81
         event.type().toString(),
90
 
90
 
91
   // TODO: move this to another class?
91
   // TODO: move this to another class?
92
   @Transactional(readOnly = true)
92
   @Transactional(readOnly = true)
93
-  public void notify(TrackingId trackingId) {
93
+  public void notify(final TrackingId trackingId) {
94
     Validate.notNull(trackingId);
94
     Validate.notNull(trackingId);
95
 
95
 
96
-    Cargo cargo = cargoRepository.find(trackingId);
96
+    final Cargo cargo = cargoRepository.find(trackingId);
97
     if (cargo == null) {
97
     if (cargo == null) {
98
       logger.warn("Can't notify listeners for non-existing cargo " + trackingId);
98
       logger.warn("Can't notify listeners for non-existing cargo " + trackingId);
99
       return;
99
       return;
102
     // TODO: more elaborate notifications, such as email to affected customer
102
     // TODO: more elaborate notifications, such as email to affected customer
103
     if (cargo.isMisdirected()) {
103
     if (cargo.isMisdirected()) {
104
       logger.info("Cargo " + trackingId + " has been misdirected. " +
104
       logger.info("Cargo " + trackingId + " has been misdirected. " +
105
-                  "Last event was " + cargo.deliveryHistory().lastEvent());
105
+        "Last event was " + cargo.deliveryHistory().lastEvent());
106
     }
106
     }
107
     if (cargo.isUnloadedAtDestination()) {
107
     if (cargo.isUnloadedAtDestination()) {
108
       logger.info("Cargo " + trackingId + " has been unloaded " +
108
       logger.info("Cargo " + trackingId + " has been unloaded " +
109
-                  "at its final destination " + cargo.finalDestination());
109
+        "at its final destination " + cargo.finalDestination());
110
     }
110
     }
111
   }
111
   }
112
 
112
 
113
   @Transactional(readOnly = true)
113
   @Transactional(readOnly = true)
114
   public List<CargoRoutingDTO> loadAllForRouting() {
114
   public List<CargoRoutingDTO> loadAllForRouting() {
115
-    List<Cargo> allCargos = cargoRepository.findAll();
115
+    final List<Cargo> allCargos = cargoRepository.findAll();
116
 
116
 
117
     // TODO: use DTO assembler
117
     // TODO: use DTO assembler
118
-    List<CargoRoutingDTO> dtoList = new ArrayList<CargoRoutingDTO>(allCargos.size());
118
+    final List<CargoRoutingDTO> dtoList = new ArrayList<CargoRoutingDTO>(allCargos.size());
119
     for (Cargo cargo : allCargos) {
119
     for (Cargo cargo : allCargos) {
120
-      CargoRoutingDTO dto = new CargoRoutingDTO(
120
+      final CargoRoutingDTO dto = new CargoRoutingDTO(
121
         cargo.trackingId().idString(),
121
         cargo.trackingId().idString(),
122
         cargo.origin().toString(),
122
         cargo.origin().toString(),
123
         cargo.finalDestination().toString()
123
         cargo.finalDestination().toString()
136
   }
136
   }
137
 
137
 
138
   @Transactional(readOnly = true)
138
   @Transactional(readOnly = true)
139
-  public CargoRoutingDTO loadForRouting(TrackingId trackingId) {
139
+  public CargoRoutingDTO loadForRouting(final TrackingId trackingId) {
140
     Validate.notNull(trackingId);
140
     Validate.notNull(trackingId);
141
-    Cargo cargo = cargoRepository.find(trackingId);
141
+    final Cargo cargo = cargoRepository.find(trackingId);
142
     if (cargo == null) {
142
     if (cargo == null) {
143
       return null;
143
       return null;
144
     }
144
     }
145
 
145
 
146
     // TODO: use DTO assembler
146
     // TODO: use DTO assembler
147
-    CargoRoutingDTO dto = new CargoRoutingDTO(
147
+    final CargoRoutingDTO dto = new CargoRoutingDTO(
148
       cargo.trackingId().idString(),
148
       cargo.trackingId().idString(),
149
       cargo.origin().toString(),
149
       cargo.origin().toString(),
150
       cargo.finalDestination().toString()
150
       cargo.finalDestination().toString()
160
   }
160
   }
161
 
161
 
162
   @Transactional(readOnly = false)
162
   @Transactional(readOnly = false)
163
-  public void assignItinerary(TrackingId trackingId, ItineraryCandidateDTO itinerary) {
163
+  public void assignItinerary(final TrackingId trackingId, final ItineraryCandidateDTO itinerary) {
164
     Validate.notNull(trackingId);
164
     Validate.notNull(trackingId);
165
     Validate.notNull(itinerary);
165
     Validate.notNull(itinerary);
166
 
166
 
167
-    Cargo cargo = cargoRepository.find(trackingId);
167
+    final Cargo cargo = cargoRepository.find(trackingId);
168
     if (cargo == null) {
168
     if (cargo == null) {
169
       throw new IllegalArgumentException("Can't assign itinerary to non-existing cargo " + trackingId);
169
       throw new IllegalArgumentException("Can't assign itinerary to non-existing cargo " + trackingId);
170
     }
170
     }
171
 
171
 
172
-    List<Leg> legs = new ArrayList<Leg>(itinerary.getLegs().size());
172
+    final List<Leg> legs = new ArrayList<Leg>(itinerary.getLegs().size());
173
     for (LegDTO legDTO : itinerary.getLegs()) {
173
     for (LegDTO legDTO : itinerary.getLegs()) {
174
-      legs.add(new Leg(
175
-        carrierMovementRepository.find(
176
-          new CarrierMovementId(legDTO.getCarrierMovementId())),
177
-        locationRepository.find(
178
-          new UnLocode(legDTO.getFrom())),
179
-        locationRepository.find(
180
-          new UnLocode(legDTO.getTo())))
181
-      );
174
+      final CarrierMovementId carrierMovementId = new CarrierMovementId(legDTO.getCarrierMovementId());
175
+      final CarrierMovement carrierMovement = carrierMovementRepository.find(carrierMovementId);
176
+      final Location from = locationRepository.find(new UnLocode(legDTO.getFrom()));
177
+      final Location to = locationRepository.find(new UnLocode(legDTO.getTo()));
178
+      legs.add(new Leg(carrierMovement, from, to));
182
     }
179
     }
183
     // TODO: delete orphaned itineraries.
180
     // TODO: delete orphaned itineraries.
184
     // Can't cascade delete-orphan for many-to-one using mapping directives.
181
     // Can't cascade delete-orphan for many-to-one using mapping directives.
186
     cargoRepository.save(cargo);
183
     cargoRepository.save(cargo);
187
   }
184
   }
188
 
185
 
189
-
190
-  public void setCargoRepository(CargoRepository cargoRepository) {
186
+  public void setCargoRepository(final CargoRepository cargoRepository) {
191
     this.cargoRepository = cargoRepository;
187
     this.cargoRepository = cargoRepository;
192
   }
188
   }
193
 
189
 
194
-  public void setLocationRepository(LocationRepository locationRepository) {
190
+  public void setLocationRepository(final LocationRepository locationRepository) {
195
     this.locationRepository = locationRepository;
191
     this.locationRepository = locationRepository;
196
   }
192
   }
197
 
193
 

+ 5
- 5
dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventMessageDelegate.java Näytä tiedosto

11
 /**
11
 /**
12
  * Consumes JMS messages and delegates notification of misdirected
12
  * Consumes JMS messages and delegates notification of misdirected
13
  * cargo to the cargo service.
13
  * cargo to the cargo service.
14
- *
14
+ * <p/>
15
  * This point of this is to decouple the cargo service from JMS,
15
  * This point of this is to decouple the cargo service from JMS,
16
  * and to allow a thread-based messaging implementation to live in
16
  * and to allow a thread-based messaging implementation to live in
17
- * parallell. 
17
+ * parallell.
18
  */
18
  */
19
 public class HandlingEventMessageDelegate implements MessageListener {
19
 public class HandlingEventMessageDelegate implements MessageListener {
20
 
20
 
21
-  CargoService cargoService;
22
-  private static final Log logger = LogFactory.getLog(HandlingEventMessageDelegate.class);
21
+  private CargoService cargoService;
22
+  private final Log logger = LogFactory.getLog(getClass());
23
 
23
 
24
-  public void onMessage(Message message) {
24
+  public void onMessage(final Message message) {
25
     if (logger.isDebugEnabled()) {
25
     if (logger.isDebugEnabled()) {
26
       logger.debug("Received message " + message);
26
       logger.debug("Received message " + message);
27
     }
27
     }

+ 9
- 10
dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventService.java Näytä tiedosto

10
 
10
 
11
 /**
11
 /**
12
  * Handling event service.
12
  * Handling event service.
13
- *
14
  */
13
  */
15
 public interface HandlingEventService {
14
 public interface HandlingEventService {
16
 
15
 
17
   /**
16
   /**
18
-   * @param completionTime when the event was completed, for example finished loading
19
-   * @param trackingId tracking id
17
+   * @param completionTime    when the event was completed, for example finished loading
18
+   * @param trackingId        tracking id
20
    * @param carrierMovementId carrier movement id, if applicable (may be null)
19
    * @param carrierMovementId carrier movement id, if applicable (may be null)
21
-   * @param unlocode United Nations Location Code for the location of the event
22
-   * @param type type of event
23
-   *
24
-   * @throws UnknownCarrierMovementIdException if there's not carrier movement with this id
20
+   * @param unlocode          United Nations Location Code for the location of the event
21
+   * @param type              type of event
22
+   * @throws UnknownCarrierMovementIdException
23
+   *                                    if there's not carrier movement with this id
25
    * @throws UnknownTrackingIdException if there's no cargo with this tracking id
24
    * @throws UnknownTrackingIdException if there's no cargo with this tracking id
26
-   * @throws UnknownLocationException if there's no location with this UN Locode 
25
+   * @throws UnknownLocationException   if there's no location with this UN Locode
27
    */
26
    */
28
   void register(Date completionTime, TrackingId trackingId, CarrierMovementId carrierMovementId, UnLocode unlocode, HandlingEvent.Type type)
27
   void register(Date completionTime, TrackingId trackingId, CarrierMovementId carrierMovementId, UnLocode unlocode, HandlingEvent.Type type)
29
-  throws UnknownCarrierMovementIdException, UnknownTrackingIdException, UnknownLocationException;
28
+    throws UnknownCarrierMovementIdException, UnknownTrackingIdException, UnknownLocationException;
30
 
29
 
31
-}
30
+}

+ 23
- 18
dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventServiceImpl.java Näytä tiedosto

10
 
10
 
11
 import java.util.Date;
11
 import java.util.Date;
12
 
12
 
13
-public class HandlingEventServiceImpl implements HandlingEventService {
13
+public final class HandlingEventServiceImpl implements HandlingEventService {
14
   private CargoRepository cargoRepository;
14
   private CargoRepository cargoRepository;
15
   private CarrierMovementRepository carrierMovementRepository;
15
   private CarrierMovementRepository carrierMovementRepository;
16
   private HandlingEventRepository handlingEventRepository;
16
   private HandlingEventRepository handlingEventRepository;
18
   private EventService eventService;
18
   private EventService eventService;
19
 
19
 
20
   @Transactional(readOnly = false)
20
   @Transactional(readOnly = false)
21
-  public void register(Date completionTime, TrackingId trackingId, CarrierMovementId carrierMovementId, UnLocode unlocode, HandlingEvent.Type type) throws UnknownCarrierMovementIdException, UnknownTrackingIdException, UnknownLocationException {
21
+  public void register(final Date completionTime, final TrackingId trackingId, final CarrierMovementId carrierMovementId,
22
+                       final UnLocode unlocode, final HandlingEvent.Type type)
23
+    throws UnknownCarrierMovementIdException, UnknownTrackingIdException, UnknownLocationException {
24
+
22
     // Carrier movement may be null for certain event types
25
     // Carrier movement may be null for certain event types
23
-    Validate.noNullElements(new Object[] {trackingId, unlocode, type});
26
+    Validate.noNullElements(new Object[]{trackingId, unlocode, type});
24
 
27
 
25
     Cargo cargo = cargoRepository.find(trackingId);
28
     Cargo cargo = cargoRepository.find(trackingId);
26
     if (cargo == null) throw new UnknownTrackingIdException(trackingId);
29
     if (cargo == null) throw new UnknownTrackingIdException(trackingId);
27
 
30
 
28
-    CarrierMovement carrierMovement = findCarrierMovement(carrierMovementId);
29
-    Location location = findLocation(unlocode);
30
-    Date registrationTime = new Date();
31
+    final CarrierMovement carrierMovement = findCarrierMovement(carrierMovementId);
32
+    final Location location = findLocation(unlocode);
33
+    final Date registrationTime = new Date();
31
 
34
 
32
-    HandlingEvent event = new HandlingEvent(cargo, completionTime, registrationTime, type, location, carrierMovement);
35
+    final HandlingEvent event = new HandlingEvent(cargo, completionTime, registrationTime, type, location, carrierMovement);
33
 
36
 
34
     /*
37
     /*
35
       NOTE:
38
       NOTE:
47
     eventService.fireHandlingEventRegistered(event);
50
     eventService.fireHandlingEventRegistered(event);
48
   }
51
   }
49
 
52
 
50
-  private CarrierMovement findCarrierMovement(CarrierMovementId carrierMovementId) throws UnknownCarrierMovementIdException {
53
+  private CarrierMovement findCarrierMovement(final CarrierMovementId carrierMovementId)
54
+    throws UnknownCarrierMovementIdException {
55
+
51
     if (carrierMovementId == null) {
56
     if (carrierMovementId == null) {
52
       return null;
57
       return null;
53
     }
58
     }
54
-    CarrierMovement carrierMovement = carrierMovementRepository.find(carrierMovementId);
59
+    final CarrierMovement carrierMovement = carrierMovementRepository.find(carrierMovementId);
55
     if (carrierMovement == null) {
60
     if (carrierMovement == null) {
56
       throw new UnknownCarrierMovementIdException(carrierMovementId);
61
       throw new UnknownCarrierMovementIdException(carrierMovementId);
57
     }
62
     }
59
     return carrierMovement;
64
     return carrierMovement;
60
   }
65
   }
61
 
66
 
62
-  private Location findLocation(UnLocode unlocode) throws UnknownLocationException {
67
+  private Location findLocation(final UnLocode unlocode) throws UnknownLocationException {
63
     if (unlocode == null) {
68
     if (unlocode == null) {
64
       return Location.UNKNOWN;
69
       return Location.UNKNOWN;
65
     }
70
     }
66
-    
67
-    Location location = locationRepository.find(unlocode);
71
+
72
+    final Location location = locationRepository.find(unlocode);
68
     if (location == null) {
73
     if (location == null) {
69
       throw new UnknownLocationException(unlocode);
74
       throw new UnknownLocationException(unlocode);
70
     }
75
     }
71
-    
76
+
72
     return location;
77
     return location;
73
   }
78
   }
74
 
79
 
75
-  public void setCargoRepository(CargoRepository cargoRepository) {
80
+  public void setCargoRepository(final CargoRepository cargoRepository) {
76
     this.cargoRepository = cargoRepository;
81
     this.cargoRepository = cargoRepository;
77
   }
82
   }
78
 
83
 
79
-  public void setCarrierMovementRepository(CarrierMovementRepository carrierMovementRepository) {
84
+  public void setCarrierMovementRepository(final CarrierMovementRepository carrierMovementRepository) {
80
     this.carrierMovementRepository = carrierMovementRepository;
85
     this.carrierMovementRepository = carrierMovementRepository;
81
   }
86
   }
82
 
87
 
83
-  public void setHandlingEventRepository(HandlingEventRepository handlingEventRepository) {
88
+  public void setHandlingEventRepository(final HandlingEventRepository handlingEventRepository) {
84
     this.handlingEventRepository = handlingEventRepository;
89
     this.handlingEventRepository = handlingEventRepository;
85
   }
90
   }
86
 
91
 
87
-  public void setLocationRepository(LocationRepository locationRepository) {
92
+  public void setLocationRepository(final LocationRepository locationRepository) {
88
     this.locationRepository = locationRepository;
93
     this.locationRepository = locationRepository;
89
   }
94
   }
90
 
95
 
91
-  public void setEventService(EventService eventService) {
96
+  public void setEventService(final EventService eventService) {
92
     this.eventService = eventService;
97
     this.eventService = eventService;
93
   }
98
   }
94
 }
99
 }

+ 6
- 6
dddsample/src/main/java/se/citerus/dddsample/service/JmsEventServiceImpl.java Näytä tiedosto

10
 /**
10
 /**
11
  * JMS based implementation.
11
  * JMS based implementation.
12
  */
12
  */
13
-public class JmsEventServiceImpl implements EventService {
13
+public final class JmsEventServiceImpl implements EventService {
14
   private JmsOperations jmsOperations;
14
   private JmsOperations jmsOperations;
15
   private Destination destination;
15
   private Destination destination;
16
   public static final String TRACKING_ID_KEY = TrackingId.class.getName() + ".KEY";
16
   public static final String TRACKING_ID_KEY = TrackingId.class.getName() + ".KEY";
18
   public void fireHandlingEventRegistered(final HandlingEvent event) {
18
   public void fireHandlingEventRegistered(final HandlingEvent event) {
19
     jmsOperations.send(destination, new MessageCreator() {
19
     jmsOperations.send(destination, new MessageCreator() {
20
       // TODO: richer message type
20
       // TODO: richer message type
21
-      public Message createMessage(Session session) throws JMSException {
22
-        MapMessage message = session.createMapMessage();
21
+      public Message createMessage(final Session session) throws JMSException {
22
+        final MapMessage message = session.createMapMessage();
23
         message.setStringProperty(TRACKING_ID_KEY, event.cargo().trackingId().idString());
23
         message.setStringProperty(TRACKING_ID_KEY, event.cargo().trackingId().idString());
24
         return message;
24
         return message;
25
       }
25
       }
26
 
26
 
27
     });
27
     });
28
   }
28
   }
29
-  
30
-  public void setJmsOperations(JmsOperations jmsOperations) {
29
+
30
+  public void setJmsOperations(final JmsOperations jmsOperations) {
31
     this.jmsOperations = jmsOperations;
31
     this.jmsOperations = jmsOperations;
32
   }
32
   }
33
 
33
 
34
-  public void setDestination(Destination destination) {
34
+  public void setDestination(final Destination destination) {
35
     this.destination = destination;
35
     this.destination = destination;
36
   }
36
   }
37
 }
37
 }

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/service/RoutingService.java Näytä tiedosto

7
 import java.util.List;
7
 import java.util.List;
8
 
8
 
9
 /**
9
 /**
10
- *  
10
+ *
11
  */
11
  */
12
 public interface RoutingService {
12
 public interface RoutingService {
13
 
13
 

+ 7
- 8
dddsample/src/main/java/se/citerus/dddsample/service/RoutingServiceImpl.java Näytä tiedosto

5
 import se.citerus.dddsample.repository.CargoRepository;
5
 import se.citerus.dddsample.repository.CargoRepository;
6
 import se.citerus.dddsample.repository.CarrierMovementRepository;
6
 import se.citerus.dddsample.repository.CarrierMovementRepository;
7
 import se.citerus.dddsample.repository.LocationRepository;
7
 import se.citerus.dddsample.repository.LocationRepository;
8
-import se.citerus.dddsample.service.dto.DTOAssembler;
8
+import se.citerus.dddsample.service.dto.assembler.DTOAssembler;
9
 import se.citerus.dddsample.service.dto.ItineraryCandidateDTO;
9
 import se.citerus.dddsample.service.dto.ItineraryCandidateDTO;
10
 
10
 
11
 import java.util.ArrayList;
11
 import java.util.ArrayList;
16
 /**
16
 /**
17
  * Simple routing service implementation that randomly creates a number
17
  * Simple routing service implementation that randomly creates a number
18
  * of different itineraries.
18
  * of different itineraries.
19
- *
20
  */
19
  */
21
 public class RoutingServiceImpl implements RoutingService {
20
 public class RoutingServiceImpl implements RoutingService {
22
 
21
 
23
-  LocationRepository locationRepository;
24
-  CargoRepository cargoRepository;
25
-  CarrierMovementRepository carrierMovementRepository;
22
+  private LocationRepository locationRepository;
23
+  private CargoRepository cargoRepository;
24
+  private CarrierMovementRepository carrierMovementRepository;
26
 
25
 
27
   Random random = new Random();
26
   Random random = new Random();
28
 
27
 
49
       CarrierMovement cm1 = carrierMovementRepository.find(new CarrierMovementId("CAR_002"));
48
       CarrierMovement cm1 = carrierMovementRepository.find(new CarrierMovementId("CAR_002"));
50
       legs.add(new Leg(cm1, cargo.origin(), firstLegTo));
49
       legs.add(new Leg(cm1, cargo.origin(), firstLegTo));
51
 
50
 
52
-      for (int j = 0; j < allLocations.size() - 1 ; j++) {
51
+      for (int j = 0; j < allLocations.size() - 1; j++) {
53
         legs.add(new Leg(
52
         legs.add(new Leg(
54
-          getRandomCarrierMovement(),
55
-          allLocations.get(j), allLocations.get(j + 1)));
53
+            getRandomCarrierMovement(),
54
+            allLocations.get(j), allLocations.get(j + 1)));
56
       }
55
       }
57
 
56
 
58
       Location lastLegFrom = allLocations.get(allLocations.size() - 1);
57
       Location lastLegFrom = allLocations.get(allLocations.size() - 1);

+ 1
- 0
dddsample/src/main/java/se/citerus/dddsample/service/ThreadBasedEventServiceImpl.java Näytä tiedosto

6
  * Thread based implementation.
6
  * Thread based implementation.
7
  */
7
  */
8
 public class ThreadBasedEventServiceImpl implements EventService {
8
 public class ThreadBasedEventServiceImpl implements EventService {
9
+
9
   private CargoService cargoService;
10
   private CargoService cargoService;
10
 
11
 
11
   public void fireHandlingEventRegistered(final HandlingEvent event) {
12
   public void fireHandlingEventRegistered(final HandlingEvent event) {

+ 3
- 3
dddsample/src/main/java/se/citerus/dddsample/service/UnknownCarrierMovementIdException.java Näytä tiedosto

4
 
4
 
5
 /**
5
 /**
6
  * Thrown when trying to register an event with an unknown carrier movement id.
6
  * Thrown when trying to register an event with an unknown carrier movement id.
7
- *
8
  */
7
  */
9
 public class UnknownCarrierMovementIdException extends Exception {
8
 public class UnknownCarrierMovementIdException extends Exception {
10
-  private CarrierMovementId carrierMovementId;
11
 
9
 
12
-  public UnknownCarrierMovementIdException(CarrierMovementId carrierMovementId) {
10
+  private final CarrierMovementId carrierMovementId;
11
+
12
+  public UnknownCarrierMovementIdException(final CarrierMovementId carrierMovementId) {
13
     this.carrierMovementId = carrierMovementId;
13
     this.carrierMovementId = carrierMovementId;
14
   }
14
   }
15
 
15
 

+ 2
- 2
dddsample/src/main/java/se/citerus/dddsample/service/UnknownLocationException.java Näytä tiedosto

4
 
4
 
5
 public class UnknownLocationException extends Exception {
5
 public class UnknownLocationException extends Exception {
6
 
6
 
7
-  private UnLocode unlocode;
7
+  private final UnLocode unlocode;
8
 
8
 
9
-  public UnknownLocationException(UnLocode unlocode) {
9
+  public UnknownLocationException(final UnLocode unlocode) {
10
     this.unlocode = unlocode;
10
     this.unlocode = unlocode;
11
   }
11
   }
12
 
12
 

+ 4
- 4
dddsample/src/main/java/se/citerus/dddsample/service/UnknownTrackingIdException.java Näytä tiedosto

4
 
4
 
5
 /**
5
 /**
6
  * Thrown when trying to register an event with an unknown tracking id.
6
  * Thrown when trying to register an event with an unknown tracking id.
7
- *
8
  */
7
  */
9
-public class UnknownTrackingIdException extends Exception {
10
-  private TrackingId trackingId;
8
+public final class UnknownTrackingIdException extends Exception {
11
 
9
 
12
-  public UnknownTrackingIdException(TrackingId trackingId) {
10
+  private final TrackingId trackingId;
11
+
12
+  public UnknownTrackingIdException(final TrackingId trackingId) {
13
     this.trackingId = trackingId;
13
     this.trackingId = trackingId;
14
   }
14
   }
15
 
15
 

+ 11
- 8
dddsample/src/main/java/se/citerus/dddsample/service/dto/CargoRoutingDTO.java Näytä tiedosto

6
 
6
 
7
 /**
7
 /**
8
  * DTO for registering and routing a cargo.
8
  * DTO for registering and routing a cargo.
9
- *
10
  */
9
  */
11
-public class CargoRoutingDTO {
12
-  String trackingId;
13
-  String origin;
14
-  String finalDestination;
15
-  List<LegDTO> legs;
10
+public final class CargoRoutingDTO {
16
 
11
 
17
-  public CargoRoutingDTO(String trackingId, String origin, String finalDestination) {
12
+  private final String trackingId;
13
+  private final String origin;
14
+  private final String finalDestination;
15
+  private final List<LegDTO> legs;
16
+
17
+  public CargoRoutingDTO(final String trackingId, final String origin, final String finalDestination) {
18
     this.trackingId = trackingId;
18
     this.trackingId = trackingId;
19
     this.origin = origin;
19
     this.origin = origin;
20
     this.finalDestination = finalDestination;
20
     this.finalDestination = finalDestination;
33
     return finalDestination;
33
     return finalDestination;
34
   }
34
   }
35
 
35
 
36
-  public void addLeg(String carrierMovementId, String from, String to) {
36
+  public void addLeg(final String carrierMovementId, final String from, final String to) {
37
     legs.add(new LegDTO(carrierMovementId, from, to));
37
     legs.add(new LegDTO(carrierMovementId, from, to));
38
   }
38
   }
39
 
39
 
40
+  /**
41
+   * @return An unmodifiable list DTOs.
42
+   */
40
   public List<LegDTO> getLegs() {
43
   public List<LegDTO> getLegs() {
41
     return Collections.unmodifiableList(legs);
44
     return Collections.unmodifiableList(legs);
42
   }
45
   }

+ 18
- 16
dddsample/src/main/java/se/citerus/dddsample/service/dto/CargoTrackingDTO.java Näytä tiedosto

9
 
9
 
10
 /**
10
 /**
11
  * DTO for a cargo and its delivery history.
11
  * DTO for a cargo and its delivery history.
12
- *
13
  */
12
  */
14
-public class CargoTrackingDTO implements Serializable {
15
-
16
-  String trackingId;
17
-  String origin;
18
-  String finalDestination;
19
-  String currentLocationId;
20
-  List<HandlingEventDTO> events;
21
-  String carrierMovementId;
22
-  StatusCode statusCode;
23
-  boolean misdirected;
24
-
25
-  public CargoTrackingDTO(String trackingId, String origin, String finalDestination,
26
-                             StatusCode statusCode, String currentLocationId, String carrierMovementId,
27
-                             boolean isMisdirected) {
13
+public final class CargoTrackingDTO implements Serializable {
14
+
15
+  private final String trackingId;
16
+  private final String origin;
17
+  private final String finalDestination;
18
+  private final String currentLocationId;
19
+  private final List<HandlingEventDTO> events;
20
+  private final String carrierMovementId;
21
+  private final StatusCode statusCode;
22
+  private final boolean misdirected;
23
+
24
+  public CargoTrackingDTO(final String trackingId, final String origin, final String finalDestination,
25
+                          final StatusCode statusCode, final String currentLocationId, final String carrierMovementId,
26
+                          final boolean isMisdirected) {
28
     this.trackingId = trackingId;
27
     this.trackingId = trackingId;
29
     this.origin = origin;
28
     this.origin = origin;
30
     this.finalDestination = finalDestination;
29
     this.finalDestination = finalDestination;
36
     this.events = new ArrayList<HandlingEventDTO>();
35
     this.events = new ArrayList<HandlingEventDTO>();
37
   }
36
   }
38
 
37
 
39
-  public void addEvent(HandlingEventDTO handlingEvent) {
38
+  public void addEvent(final HandlingEventDTO handlingEvent) {
40
     events.add(handlingEvent);
39
     events.add(handlingEvent);
41
   }
40
   }
42
 
41
 
42
+  /**
43
+   * @return An unmodifiable list DTOs.
44
+   */
43
   public List<HandlingEventDTO> getEvents() {
45
   public List<HandlingEventDTO> getEvents() {
44
     return Collections.unmodifiableList(events);
46
     return Collections.unmodifiableList(events);
45
   }
47
   }

+ 0
- 29
dddsample/src/main/java/se/citerus/dddsample/service/dto/DTOAssembler.java Näytä tiedosto

1
-package se.citerus.dddsample.service.dto;
2
-
3
-import se.citerus.dddsample.domain.Itinerary;
4
-import se.citerus.dddsample.domain.Leg;
5
-
6
-import java.util.ArrayList;
7
-import java.util.List;
8
-
9
-/**
10
- * Handles assembly of DTOs from the domain model.
11
- */
12
-public class DTOAssembler {
13
-
14
-  public static ItineraryCandidateDTO toItineraryCandidateDTO(Itinerary itinerary) {
15
-    List<LegDTO> legDTOs = new ArrayList<LegDTO>(itinerary.legs().size());
16
-    for (Leg leg : itinerary.legs()) {
17
-      legDTOs.add(toLegDTO(leg));
18
-    }
19
-    return new ItineraryCandidateDTO(legDTOs);
20
-  }
21
-
22
-  private static LegDTO toLegDTO(Leg leg) {
23
-    return new LegDTO(
24
-      leg.carrierMovement().carrierMovementId().idString(),
25
-      leg.from().unLocode().idString(),
26
-      leg.to().unLocode().idString()
27
-    );
28
-  }
29
-}

+ 3
- 2
dddsample/src/main/java/se/citerus/dddsample/service/dto/HandlingEventDTO.java Näytä tiedosto

6
 /**
6
 /**
7
  * DTO for a handling event.
7
  * DTO for a handling event.
8
  */
8
  */
9
-public class HandlingEventDTO implements Serializable {
9
+public final class HandlingEventDTO implements Serializable {
10
 
10
 
11
   private final String type;
11
   private final String type;
12
   private final String location;
12
   private final String location;
14
   private final Date time;
14
   private final Date time;
15
   private boolean expected;
15
   private boolean expected;
16
 
16
 
17
-  public HandlingEventDTO(String location, String type, String carrier, Date time, boolean expected) {
17
+  public HandlingEventDTO(final String location, final String type, final String carrier, final Date time,
18
+                          final boolean expected) {
18
     this.location = location;
19
     this.location = location;
19
     this.type = type;
20
     this.type = type;
20
     this.carrier = carrier;
21
     this.carrier = carrier;

+ 7
- 4
dddsample/src/main/java/se/citerus/dddsample/service/dto/ItineraryCandidateDTO.java Näytä tiedosto

5
 
5
 
6
 /**
6
 /**
7
  * DTO for presenting and selecting an itinerary from a collection of candidates.
7
  * DTO for presenting and selecting an itinerary from a collection of candidates.
8
- * 
9
  */
8
  */
10
-public class ItineraryCandidateDTO {
11
-  List<LegDTO> legs;
9
+public final class ItineraryCandidateDTO {
12
 
10
 
13
-  public ItineraryCandidateDTO(List<LegDTO> legs) {
11
+  private final List<LegDTO> legs;
12
+
13
+  public ItineraryCandidateDTO(final List<LegDTO> legs) {
14
     this.legs = legs;
14
     this.legs = legs;
15
   }
15
   }
16
 
16
 
17
+  /**
18
+   * @return An unmodifiable list DTOs.
19
+   */
17
   public List<LegDTO> getLegs() {
20
   public List<LegDTO> getLegs() {
18
     return Collections.unmodifiableList(legs);
21
     return Collections.unmodifiableList(legs);
19
   }
22
   }

+ 5
- 6
dddsample/src/main/java/se/citerus/dddsample/service/dto/LegDTO.java Näytä tiedosto

2
 
2
 
3
 /**
3
 /**
4
  * DTO for a leg in an itinerary.
4
  * DTO for a leg in an itinerary.
5
- *
6
  */
5
  */
7
-public class LegDTO {
6
+public final class LegDTO {
8
 
7
 
9
-  String carrierMovementId;
10
-  String from;
11
-  String to;
8
+  private final String carrierMovementId;
9
+  private final String from;
10
+  private final String to;
12
 
11
 
13
-  public LegDTO(String carrierMovementId, String from, String to) {
12
+  public LegDTO(final String carrierMovementId, final String from, final String to) {
14
     this.carrierMovementId = carrierMovementId;
13
     this.carrierMovementId = carrierMovementId;
15
     this.from = from;
14
     this.from = from;
16
     this.to = to;
15
     this.to = to;

+ 32
- 0
dddsample/src/main/java/se/citerus/dddsample/service/dto/assembler/DTOAssembler.java Näytä tiedosto

1
+package se.citerus.dddsample.service.dto.assembler;
2
+
3
+import se.citerus.dddsample.domain.Itinerary;
4
+import se.citerus.dddsample.domain.Leg;
5
+import se.citerus.dddsample.domain.CarrierMovementId;
6
+import se.citerus.dddsample.domain.UnLocode;
7
+import se.citerus.dddsample.service.dto.ItineraryCandidateDTO;
8
+import se.citerus.dddsample.service.dto.LegDTO;
9
+
10
+import java.util.ArrayList;
11
+import java.util.List;
12
+
13
+/**
14
+ * Handles assembly of DTOs from the domain model.
15
+ */
16
+public class DTOAssembler {
17
+
18
+  public static ItineraryCandidateDTO toItineraryCandidateDTO(final Itinerary itinerary) {
19
+    final List<LegDTO> legDTOs = new ArrayList<LegDTO>(itinerary.legs().size());
20
+    for (Leg leg : itinerary.legs()) {
21
+      legDTOs.add(toLegDTO(leg));
22
+    }
23
+    return new ItineraryCandidateDTO(legDTOs);
24
+  }
25
+
26
+  private static LegDTO toLegDTO(final Leg leg) {
27
+    final CarrierMovementId id = leg.carrierMovement().carrierMovementId();
28
+    final UnLocode from = leg.from().unLocode();
29
+    final UnLocode to = leg.to().unLocode();
30
+    return new LegDTO(id.idString(), from.idString(), to.idString());
31
+  }
32
+}

+ 26
- 26
dddsample/src/main/java/se/citerus/dddsample/util/LocationsImporter.java Näytä tiedosto

27
 
27
 
28
 /**
28
 /**
29
  * Imports about 55 000 locations from an official UN Locode CSV export.
29
  * Imports about 55 000 locations from an official UN Locode CSV export.
30
- *
30
+ * <p/>
31
  * NOTE: not yet used
31
  * NOTE: not yet used
32
- *
33
  */
32
  */
34
 public class LocationsImporter implements ServletContextListener {
33
 public class LocationsImporter implements ServletContextListener {
35
   private static final String ZIP_FILE_NAME = "unlocodes.zip";
34
   private static final String ZIP_FILE_NAME = "unlocodes.zip";
36
   private static final String ZIP_ENTRY_NAME = "2006-2 UNLOCODE CodeList.txt";
35
   private static final String ZIP_ENTRY_NAME = "2006-2 UNLOCODE CodeList.txt";
37
   private static final int BATCH_SIZE = 1000;
36
   private static final int BATCH_SIZE = 1000;
38
-  private static final Log logger = LogFactory.getLog(LocationsImporter.class);
37
+  private final Log logger = LogFactory.getLog(getClass());
39
 
38
 
40
-  protected int importLocations(JdbcTemplate jt) throws IOException {
41
-    ZipFile zipFile = new ZipFile(new ClassPathResource(ZIP_FILE_NAME).getFile());
42
-    ZipEntry zipEntry = zipFile.getEntry(ZIP_ENTRY_NAME);
43
-    InputStream inputStream = zipFile.getInputStream(zipEntry);
44
-    LineIterator iterator = IOUtils.lineIterator(inputStream, "ISO-8859-1");
39
+  protected int importLocations(final JdbcTemplate jt) throws IOException {
40
+    final ZipFile zipFile = new ZipFile(new ClassPathResource(ZIP_FILE_NAME).getFile());
41
+    final ZipEntry zipEntry = zipFile.getEntry(ZIP_ENTRY_NAME);
42
+    final InputStream inputStream = zipFile.getInputStream(zipEntry);
43
+    final LineIterator iterator = IOUtils.lineIterator(inputStream, "ISO-8859-1");
45
 
44
 
46
     int count = 0;
45
     int count = 0;
47
-    String sql = "INSERT INTO Location (unlocode,name) VALUES (?,?)";
46
+    final String sql = "INSERT INTO Location (unlocode,name) VALUES (?,?)";
48
 
47
 
49
     final String[][] batchArgs = new String[BATCH_SIZE][2];
48
     final String[][] batchArgs = new String[BATCH_SIZE][2];
50
     while (iterator.hasNext()) {
49
     while (iterator.hasNext()) {
51
-      String line = iterator.nextLine();
52
-      String[] args = parseLocation(line);
50
+      final String line = iterator.nextLine();
51
+      final String[] args = parseLocation(line);
53
       if (args != null) {
52
       if (args != null) {
54
         int pos = count % BATCH_SIZE;
53
         int pos = count % BATCH_SIZE;
55
         batchArgs[pos][0] = args[0];
54
         batchArgs[pos][0] = args[0];
61
               ps.setString(1, batchArgs[i][0]);
60
               ps.setString(1, batchArgs[i][0]);
62
               ps.setString(2, batchArgs[i][1]);
61
               ps.setString(2, batchArgs[i][1]);
63
             }
62
             }
63
+
64
             public int getBatchSize() {
64
             public int getBatchSize() {
65
               return BATCH_SIZE;
65
               return BATCH_SIZE;
66
             }
66
             }
74
     return count;
74
     return count;
75
   }
75
   }
76
 
76
 
77
-  private String[] parseLocation(String line) {
78
-    String countryCode = line.substring(3, 5);
79
-    String locationCode = line.substring(6, 9);
77
+  private String[] parseLocation(final String line) {
78
+    final String countryCode = line.substring(3, 5);
79
+    final String locationCode = line.substring(6, 9);
80
     if (locationCode.trim().length() == 3) {
80
     if (locationCode.trim().length() == 3) {
81
-      String name = line.substring(10, 46).trim();
82
-      return new String[] {countryCode + locationCode, name};
81
+      final String name = line.substring(10, 46).trim();
82
+      return new String[]{countryCode + locationCode, name};
83
     } else {
83
     } else {
84
       return null;
84
       return null;
85
     }
85
     }
86
   }
86
   }
87
 
87
 
88
-  public void contextInitialized(ServletContextEvent event) {
89
-    WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext());
90
-    PlatformTransactionManager ptm = (PlatformTransactionManager) BeanFactoryUtils.beanOfType(context, PlatformTransactionManager.class);
91
-    TransactionTemplate tt = new TransactionTemplate(ptm);
92
-    DataSource dataSource = (DataSource) BeanFactoryUtils.beanOfType(context, DataSource.class);
88
+  public void contextInitialized(final ServletContextEvent event) {
89
+    final WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(event.getServletContext());
90
+    final PlatformTransactionManager ptm = (PlatformTransactionManager) BeanFactoryUtils.beanOfType(context, PlatformTransactionManager.class);
91
+    final TransactionTemplate tt = new TransactionTemplate(ptm);
92
+    final DataSource dataSource = (DataSource) BeanFactoryUtils.beanOfType(context, DataSource.class);
93
     final JdbcTemplate jt = new JdbcTemplate(dataSource);
93
     final JdbcTemplate jt = new JdbcTemplate(dataSource);
94
 
94
 
95
-
96
-    long t = System.currentTimeMillis();
97
-    Integer count = (Integer) tt.execute(new TransactionCallback() {
95
+    final long t = System.currentTimeMillis();
96
+    final Integer count = (Integer) tt.execute(new TransactionCallback() {
98
       public Object doInTransaction(TransactionStatus status) {
97
       public Object doInTransaction(TransactionStatus status) {
99
         try {
98
         try {
100
           return importLocations(jt);
99
           return importLocations(jt);
103
         }
102
         }
104
       }
103
       }
105
     });
104
     });
106
-    logger.info("Imported " + count + " locations in " + (System.currentTimeMillis() - t)/1000.0 + " seconds.");
105
+    logger.info("Imported " + count + " locations in " + (System.currentTimeMillis() - t) / 1000.0 + " seconds.");
107
   }
106
   }
108
 
107
 
109
-  public void contextDestroyed(ServletContextEvent event) {}
108
+  public void contextDestroyed(final ServletContextEvent event) {
109
+  }
110
 }
110
 }

+ 33
- 31
dddsample/src/main/java/se/citerus/dddsample/web/CargoAdminController.java Näytä tiedosto

19
 
19
 
20
 /**
20
 /**
21
  * Handles cargo routing and administration.
21
  * Handles cargo routing and administration.
22
- *
23
  */
22
  */
24
-public class CargoAdminController extends MultiActionController {
23
+public final class CargoAdminController extends MultiActionController {
25
 
24
 
26
   private CargoService cargoService;
25
   private CargoService cargoService;
27
   private RoutingService routingService;
26
   private RoutingService routingService;
28
 
27
 
29
-  public Map registrationForm(HttpServletRequest request, HttpServletResponse response) throws Exception {
30
-    Map map = new HashMap();
31
-    List<UnLocode> unLocodes = cargoService.shippingLocations();
32
-    List<String> unLocodeStrings = new ArrayList<String>();
28
+  public Map registrationForm(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
29
+    final Map<String, Object> map = new HashMap<String, Object>();
30
+    final List<UnLocode> unLocodes = cargoService.shippingLocations();
31
+    final List<String> unLocodeStrings = new ArrayList<String>();
32
+
33
     for (UnLocode unLocode : unLocodes) {
33
     for (UnLocode unLocode : unLocodes) {
34
       unLocodeStrings.add(unLocode.idString());
34
       unLocodeStrings.add(unLocode.idString());
35
     }
35
     }
36
+
36
     map.put("unlocodes", unLocodeStrings);
37
     map.put("unlocodes", unLocodeStrings);
37
     return map;
38
     return map;
38
   }
39
   }
39
 
40
 
40
-  public void register(HttpServletRequest request, HttpServletResponse response, RegistrationCommand command) throws Exception {
41
-    TrackingId trackingId = cargoService.registerNew(
41
+  public void register(final HttpServletRequest request, final HttpServletResponse response,
42
+                       final RegistrationCommand command) throws Exception {
43
+
44
+    final TrackingId trackingId = cargoService.registerNew(
42
       new UnLocode(command.getOriginUnlocode()),
45
       new UnLocode(command.getOriginUnlocode()),
43
       new UnLocode(command.getDestinationUnlocode())
46
       new UnLocode(command.getDestinationUnlocode())
44
     );
47
     );
46
   }
49
   }
47
 
50
 
48
   public Map list(HttpServletRequest request, HttpServletResponse response) {
51
   public Map list(HttpServletRequest request, HttpServletResponse response) {
49
-    Map map = new HashMap();
52
+    final Map<String, Object> map = new HashMap<String, Object>();
50
     map.put("cargoList", cargoService.loadAllForRouting());
53
     map.put("cargoList", cargoService.loadAllForRouting());
51
     return map;
54
     return map;
52
   }
55
   }
53
 
56
 
54
-  public Map show(HttpServletRequest request, HttpServletResponse response) {
55
-    Map map = new HashMap();
56
-    String param = request.getParameter("trackingId");
57
-    TrackingId trackingId = new TrackingId(param);
57
+  public Map show(final HttpServletRequest request, final HttpServletResponse response) {
58
+    final Map<String, Object> map = new HashMap<String, Object>();
59
+    final TrackingId trackingId = new TrackingId(request.getParameter("trackingId"));
58
     map.put("cargo", cargoService.loadForRouting(trackingId));
60
     map.put("cargo", cargoService.loadForRouting(trackingId));
59
     return map;
61
     return map;
60
   }
62
   }
61
 
63
 
62
-  public Map selectItinerary(HttpServletRequest request, HttpServletResponse response) {
63
-    Map map = new HashMap();
64
-    TrackingId trackingId = new TrackingId(request.getParameter("trackingId"));
65
-
66
-    List<ItineraryCandidateDTO> itineraries = routingService.calculatePossibleRoutes(trackingId, null);
67
-
68
-    List<RoutingCommand.ItineraryCandidateCommand> itineraryCandidates = new ArrayList<RoutingCommand.ItineraryCandidateCommand>();
64
+  public Map selectItinerary(final HttpServletRequest request, final HttpServletResponse response) {
65
+    final Map<String, Object> map = new HashMap<String, Object>();
66
+    final TrackingId trackingId = new TrackingId(request.getParameter("trackingId"));
67
+    final List<ItineraryCandidateDTO> itineraries = routingService.calculatePossibleRoutes(trackingId, null);
68
+    final List<RoutingCommand.ItineraryCandidateCommand> itineraryCandidates =
69
+      new ArrayList<RoutingCommand.ItineraryCandidateCommand>();
69
 
70
 
70
     // TODO: eliminate the routing command altogether, use the DTOs in the view
71
     // TODO: eliminate the routing command altogether, use the DTOs in the view
71
     for (ItineraryCandidateDTO itinerary : itineraries) {
72
     for (ItineraryCandidateDTO itinerary : itineraries) {
72
-      RoutingCommand.ItineraryCandidateCommand itineraryCandidateCommand = new RoutingCommand.ItineraryCandidateCommand();
73
+      final RoutingCommand.ItineraryCandidateCommand itineraryCandidateCommand =
74
+        new RoutingCommand.ItineraryCandidateCommand();
73
       itineraryCandidateCommand.setTrackingId(trackingId.idString());
75
       itineraryCandidateCommand.setTrackingId(trackingId.idString());
74
       itineraryCandidates.add(itineraryCandidateCommand);
76
       itineraryCandidates.add(itineraryCandidateCommand);
75
       for (LegDTO leg : itinerary.getLegs()) {
77
       for (LegDTO leg : itinerary.getLegs()) {
76
-        RoutingCommand.LegCommand legCommand = new RoutingCommand.LegCommand();
78
+        final RoutingCommand.LegCommand legCommand = new RoutingCommand.LegCommand();
77
         legCommand.setCarrierMovementId(leg.getCarrierMovementId());
79
         legCommand.setCarrierMovementId(leg.getCarrierMovementId());
78
         legCommand.setFromUnlocode(leg.getFrom());
80
         legCommand.setFromUnlocode(leg.getFrom());
79
         legCommand.setToUnlocode(leg.getTo());
81
         legCommand.setToUnlocode(leg.getTo());
86
     return map;
88
     return map;
87
   }
89
   }
88
 
90
 
89
-  public void assignItinerary(HttpServletRequest request, HttpServletResponse response) throws Exception {
90
-    TrackingId trackingId = new TrackingId(request.getParameter("trackingId"));
91
+  public void assignItinerary(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
92
+    final TrackingId trackingId = new TrackingId(request.getParameter("trackingId"));
91
 
93
 
92
     // TODO:  gah, stuck on indexoutofbounds (legs[0].fromUnlocode etc) when trying to bind...
94
     // TODO:  gah, stuck on indexoutofbounds (legs[0].fromUnlocode etc) when trying to bind...
93
     // Revisit and fix this with a proper command object, this is just hideous
95
     // Revisit and fix this with a proper command object, this is just hideous
94
-    String[] cmIds = (String[]) request.getParameterMap().get("legs.carrierMovementId");
95
-    String[] fromUnlocodes = (String[]) request.getParameterMap().get("legs.fromUnlocode");
96
-    String[] toUnlocodes = (String[]) request.getParameterMap().get("legs.toUnlocode");
96
+    final String[] cmIds = (String[]) request.getParameterMap().get("legs.carrierMovementId");
97
+    final String[] fromUnlocodes = (String[]) request.getParameterMap().get("legs.fromUnlocode");
98
+    final String[] toUnlocodes = (String[]) request.getParameterMap().get("legs.toUnlocode");
97
 
99
 
98
-    List<LegDTO> legDTOs = new ArrayList<LegDTO>(cmIds.length);
100
+    final List<LegDTO> legDTOs = new ArrayList<LegDTO>(cmIds.length);
99
     for (int i = 0; i < cmIds.length; i++) {
101
     for (int i = 0; i < cmIds.length; i++) {
100
       legDTOs.add(new LegDTO(cmIds[i], fromUnlocodes[i], toUnlocodes[i]));
102
       legDTOs.add(new LegDTO(cmIds[i], fromUnlocodes[i], toUnlocodes[i]));
101
     }
103
     }
102
 
104
 
103
-    ItineraryCandidateDTO selectedItinerary = new ItineraryCandidateDTO(legDTOs);
105
+    final ItineraryCandidateDTO selectedItinerary = new ItineraryCandidateDTO(legDTOs);
104
     cargoService.assignItinerary(trackingId, selectedItinerary);
106
     cargoService.assignItinerary(trackingId, selectedItinerary);
105
 
107
 
106
     response.sendRedirect("list.html");
108
     response.sendRedirect("list.html");
107
   }
109
   }
108
 
110
 
109
-  public void setCargoService(CargoService cargoService) {
111
+  public void setCargoService(final CargoService cargoService) {
110
     this.cargoService = cargoService;
112
     this.cargoService = cargoService;
111
   }
113
   }
112
 
114
 
113
-  public void setRoutingService(RoutingService routingService) {
115
+  public void setRoutingService(final RoutingService routingService) {
114
     this.routingService = routingService;
116
     this.routingService = routingService;
115
   }
117
   }
116
 
118
 

+ 8
- 5
dddsample/src/main/java/se/citerus/dddsample/web/CargoTrackingController.java Näytä tiedosto

16
 /**
16
 /**
17
  * Controller for tracking cargo.
17
  * Controller for tracking cargo.
18
  */
18
  */
19
-public class CargoTrackingController extends SimpleFormController {
19
+public final class CargoTrackingController extends SimpleFormController {
20
 
20
 
21
   /**
21
   /**
22
    * Service instance.
22
    * Service instance.
28
   }
28
   }
29
 
29
 
30
   @Override
30
   @Override
31
-  protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
31
+  protected ModelAndView onSubmit(final HttpServletRequest request, final HttpServletResponse response,
32
+                                  final Object command, final BindException errors) throws Exception {
33
+
32
     final TrackCommand trackCommand = (TrackCommand) command;
34
     final TrackCommand trackCommand = (TrackCommand) command;
33
     final String tidStr = trackCommand.getTrackingId();
35
     final String tidStr = trackCommand.getTrackingId();
34
     final CargoTrackingDTO cargo = cargoService.track(new TrackingId(tidStr));
36
     final CargoTrackingDTO cargo = cargoService.track(new TrackingId(tidStr));
37
     if (cargo != null) {
39
     if (cargo != null) {
38
       model.put("cargo", cargo);
40
       model.put("cargo", cargo);
39
     } else {
41
     } else {
40
-      errors.rejectValue("trackingId", "cargo.unknown_id", new Object[] {trackCommand.getTrackingId()}, "Unknown tracking id");
42
+      errors.rejectValue("trackingId", "cargo.unknown_id", new Object[]{trackCommand.getTrackingId()},
43
+        "Unknown tracking id");
41
     }
44
     }
42
     return showForm(request, response, errors, model);
45
     return showForm(request, response, errors, model);
43
   }
46
   }
44
-   
47
+
45
 
48
 
46
   /**
49
   /**
47
    * Sets the cargo service instance.
50
    * Sets the cargo service instance.
51
   public void setCargoService(final CargoService cargoService) {
54
   public void setCargoService(final CargoService cargoService) {
52
     this.cargoService = cargoService;
55
     this.cargoService = cargoService;
53
   }
56
   }
54
-  
57
+
55
 }
58
 }

+ 4
- 3
dddsample/src/main/java/se/citerus/dddsample/web/command/RegistrationCommand.java Näytä tiedosto

3
 /**
3
 /**
4
  *
4
  *
5
  */
5
  */
6
-public class RegistrationCommand {
6
+public final class RegistrationCommand {
7
+
7
   private String originUnlocode;
8
   private String originUnlocode;
8
   private String destinationUnlocode;
9
   private String destinationUnlocode;
9
 
10
 
11
     return originUnlocode;
12
     return originUnlocode;
12
   }
13
   }
13
 
14
 
14
-  public void setOriginUnlocode(String originUnlocode) {
15
+  public void setOriginUnlocode(final String originUnlocode) {
15
     this.originUnlocode = originUnlocode;
16
     this.originUnlocode = originUnlocode;
16
   }
17
   }
17
 
18
 
19
     return destinationUnlocode;
20
     return destinationUnlocode;
20
   }
21
   }
21
 
22
 
22
-  public void setDestinationUnlocode(String destinationUnlocode) {
23
+  public void setDestinationUnlocode(final String destinationUnlocode) {
23
     this.destinationUnlocode = destinationUnlocode;
24
     this.destinationUnlocode = destinationUnlocode;
24
   }
25
   }
25
 
26
 

+ 16
- 15
dddsample/src/main/java/se/citerus/dddsample/web/command/RoutingCommand.java Näytä tiedosto

3
 import java.util.ArrayList;
3
 import java.util.ArrayList;
4
 import java.util.List;
4
 import java.util.List;
5
 
5
 
6
-public class RoutingCommand {
7
-  List<ItineraryCandidateCommand> itineraryCandidates = new ArrayList<ItineraryCandidateCommand>();
6
+public final class RoutingCommand {
7
+
8
+  private List<ItineraryCandidateCommand> itineraryCandidates = new ArrayList<ItineraryCandidateCommand>();
8
 
9
 
9
   public List<ItineraryCandidateCommand> getItineraryCandidates() {
10
   public List<ItineraryCandidateCommand> getItineraryCandidates() {
10
     return itineraryCandidates;
11
     return itineraryCandidates;
11
   }
12
   }
12
 
13
 
13
-  public void setItineraryCandidates(List<ItineraryCandidateCommand> itineraryCandidates) {
14
+  public void setItineraryCandidates(final List<ItineraryCandidateCommand> itineraryCandidates) {
14
     this.itineraryCandidates = itineraryCandidates;
15
     this.itineraryCandidates = itineraryCandidates;
15
   }
16
   }
16
 
17
 
17
-  public static class ItineraryCandidateCommand {
18
-    String trackingId;
19
-    List<LegCommand> legs = new ArrayList<LegCommand>();
18
+  public static final class ItineraryCandidateCommand {
19
+    private String trackingId;
20
+    private List<LegCommand> legs = new ArrayList<LegCommand>();
20
 
21
 
21
     public String getTrackingId() {
22
     public String getTrackingId() {
22
       return trackingId;
23
       return trackingId;
23
     }
24
     }
24
 
25
 
25
-    public void setTrackingId(String trackingId) {
26
+    public void setTrackingId(final String trackingId) {
26
       this.trackingId = trackingId;
27
       this.trackingId = trackingId;
27
     }
28
     }
28
 
29
 
30
       return legs;
31
       return legs;
31
     }
32
     }
32
 
33
 
33
-    public void setLegs(List<LegCommand> legs) {
34
+    public void setLegs(final List<LegCommand> legs) {
34
       this.legs = legs;
35
       this.legs = legs;
35
     }
36
     }
36
   }
37
   }
37
 
38
 
38
-  public static class LegCommand {
39
-    String carrierMovementId;
40
-    String fromUnlocode;
41
-    String toUnlocode;
39
+  public static final class LegCommand {
40
+    private String carrierMovementId;
41
+    private String fromUnlocode;
42
+    private String toUnlocode;
42
 
43
 
43
     public String getCarrierMovementId() {
44
     public String getCarrierMovementId() {
44
       return carrierMovementId;
45
       return carrierMovementId;
45
     }
46
     }
46
 
47
 
47
-    public void setCarrierMovementId(String carrierMovementId) {
48
+    public void setCarrierMovementId(final String carrierMovementId) {
48
       this.carrierMovementId = carrierMovementId;
49
       this.carrierMovementId = carrierMovementId;
49
     }
50
     }
50
 
51
 
52
       return fromUnlocode;
53
       return fromUnlocode;
53
     }
54
     }
54
 
55
 
55
-    public void setFromUnlocode(String fromUnlocode) {
56
+    public void setFromUnlocode(final String fromUnlocode) {
56
       this.fromUnlocode = fromUnlocode;
57
       this.fromUnlocode = fromUnlocode;
57
     }
58
     }
58
 
59
 
60
       return toUnlocode;
61
       return toUnlocode;
61
     }
62
     }
62
 
63
 
63
-    public void setToUnlocode(String toUnlocode) {
64
+    public void setToUnlocode(final String toUnlocode) {
64
       this.toUnlocode = toUnlocode;
65
       this.toUnlocode = toUnlocode;
65
     }
66
     }
66
   }
67
   }

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/web/command/TrackCommand.java Näytä tiedosto

3
 import org.apache.commons.lang.builder.ToStringBuilder;
3
 import org.apache.commons.lang.builder.ToStringBuilder;
4
 import static org.apache.commons.lang.builder.ToStringStyle.MULTI_LINE_STYLE;
4
 import static org.apache.commons.lang.builder.ToStringStyle.MULTI_LINE_STYLE;
5
 
5
 
6
-public class TrackCommand {
6
+public final class TrackCommand {
7
 
7
 
8
   /**
8
   /**
9
    * The tracking id.
9
    * The tracking id.

+ 3
- 3
dddsample/src/main/java/se/citerus/dddsample/web/command/TrackCommandValidator.java Näytä tiedosto

7
 /**
7
 /**
8
  * Validator for {@link se.citerus.dddsample.web.command.TrackCommand}s.
8
  * Validator for {@link se.citerus.dddsample.web.command.TrackCommand}s.
9
  */
9
  */
10
-public class TrackCommandValidator implements Validator {
10
+public final class TrackCommandValidator implements Validator {
11
 
11
 
12
-  public boolean supports(Class clazz) {
12
+  public boolean supports(final Class clazz) {
13
     return TrackCommand.class.isAssignableFrom(clazz);
13
     return TrackCommand.class.isAssignableFrom(clazz);
14
   }
14
   }
15
 
15
 
16
-  public void validate(Object object, Errors errors) {
16
+  public void validate(final Object object, final Errors errors) {
17
     ValidationUtils.rejectIfEmptyOrWhitespace(errors, "trackingId", "error.required", "Required");
17
     ValidationUtils.rejectIfEmptyOrWhitespace(errors, "trackingId", "error.required", "Required");
18
   }
18
   }
19
 
19
 

+ 4
- 5
dddsample/src/main/java/se/citerus/dddsample/ws/HandlingEventServiceEndpoint.java Näytä tiedosto

4
 
4
 
5
 /**
5
 /**
6
  * Web service endpoint for handling event registration.
6
  * Web service endpoint for handling event registration.
7
- *
8
  */
7
  */
9
 @WebService
8
 @WebService
10
 public interface HandlingEventServiceEndpoint {
9
 public interface HandlingEventServiceEndpoint {
12
   /**
11
   /**
13
    * Register an cargo handling event.
12
    * Register an cargo handling event.
14
    *
13
    *
15
-   * @param completionTime time when event occured, for example a the loading of cargo was completed
16
-   * @param trackingId tracking id of the cargo
14
+   * @param completionTime    time when event occured, for example a the loading of cargo was completed
15
+   * @param trackingId        tracking id of the cargo
17
    * @param carrierMovementId carrier movement id, if applicable
16
    * @param carrierMovementId carrier movement id, if applicable
18
-   * @param unlocode United Nations Location Code for the location where the event occured
19
-   * @param eventType type of event
17
+   * @param unlocode          United Nations Location Code for the location where the event occured
18
+   * @param eventType         type of event
20
    */
19
    */
21
   void register(String completionTime, String trackingId, String carrierMovementId, String unlocode, String eventType);
20
   void register(String completionTime, String trackingId, String carrierMovementId, String unlocode, String eventType);
22
 
21
 

+ 7
- 7
dddsample/src/main/java/se/citerus/dddsample/ws/HandlingEventServiceEndpointImpl.java Näytä tiedosto

21
 public class HandlingEventServiceEndpointImpl implements HandlingEventServiceEndpoint {
21
 public class HandlingEventServiceEndpointImpl implements HandlingEventServiceEndpoint {
22
 
22
 
23
   private HandlingEventService handlingEventService;
23
   private HandlingEventService handlingEventService;
24
-  private static final Log logger = LogFactory.getLog(HandlingEventServiceEndpointImpl.class);
24
+  private final Log logger = LogFactory.getLog(getClass());
25
   protected static final String ISO_8601_FORMAT = "yyyy-mm-dd HH:MM:SS.SSS";
25
   protected static final String ISO_8601_FORMAT = "yyyy-mm-dd HH:MM:SS.SSS";
26
 
26
 
27
-  public void register(String completionTime, String trackingId, String carrierMovementId,
28
-                       String unlocode, String eventType) {
27
+  public void register(final String completionTime, final String trackingId, final String carrierMovementId,
28
+                       final String unlocode, final String eventType) {
29
     try {
29
     try {
30
       Date date = parseIso8601Date(completionTime);
30
       Date date = parseIso8601Date(completionTime);
31
       TrackingId tid = new TrackingId(trackingId);
31
       TrackingId tid = new TrackingId(trackingId);
54
     // TODO: possibly handle "Duplicate event" exceptions due to unique constraint violations
54
     // TODO: possibly handle "Duplicate event" exceptions due to unique constraint violations
55
   }
55
   }
56
 
56
 
57
-  private HandlingEvent.Type parseEventType(String eventType) throws InvalidEventTypeException {
57
+  private HandlingEvent.Type parseEventType(final String eventType) throws InvalidEventTypeException {
58
     try {
58
     try {
59
       return HandlingEvent.Type.valueOf(eventType);
59
       return HandlingEvent.Type.valueOf(eventType);
60
-    } catch(IllegalArgumentException e) {
60
+    } catch (IllegalArgumentException e) {
61
       throw new InvalidEventTypeException(eventType);
61
       throw new InvalidEventTypeException(eventType);
62
     }
62
     }
63
   }
63
   }
67
     // TODO: actually place in a retry queue
67
     // TODO: actually place in a retry queue
68
   }
68
   }
69
 
69
 
70
-  private Date parseIso8601Date(String completionTime) throws ParseException {
70
+  private Date parseIso8601Date(final String completionTime) throws ParseException {
71
     return new SimpleDateFormat(ISO_8601_FORMAT).parse(completionTime);
71
     return new SimpleDateFormat(ISO_8601_FORMAT).parse(completionTime);
72
   }
72
   }
73
 
73
 
74
-  public void setHandlingEventService(HandlingEventService handlingEventService) {
74
+  public void setHandlingEventService(final HandlingEventService handlingEventService) {
75
     this.handlingEventService = handlingEventService;
75
     this.handlingEventService = handlingEventService;
76
   }
76
   }
77
 }
77
 }

+ 4
- 5
dddsample/src/test/java/se/citerus/dddsample/domain/SampleLocations.java Näytä tiedosto

6
 
6
 
7
 /**
7
 /**
8
  * A few locations for easy testing.
8
  * A few locations for easy testing.
9
- *
10
  */
9
  */
11
 public class SampleLocations {
10
 public class SampleLocations {
12
 
11
 
23
   public static final Location HANGZOU = new Location(new UnLocode("CNHGH"), "Hangzhou");
22
   public static final Location HANGZOU = new Location(new UnLocode("CNHGH"), "Hangzhou");
24
   public static final Location NEWYORK = new Location(new UnLocode("USNYC"), "New York");
23
   public static final Location NEWYORK = new Location(new UnLocode("USNYC"), "New York");
25
 
24
 
26
-  public static final List<Location> all = new ArrayList<Location>();
25
+  public static final List<Location> ALL = new ArrayList<Location>();
27
 
26
 
28
   static {
27
   static {
29
     for (Field field : SampleLocations.class.getDeclaredFields()) {
28
     for (Field field : SampleLocations.class.getDeclaredFields()) {
30
       if (field.getType().equals(Location.class)) {
29
       if (field.getType().equals(Location.class)) {
31
         try {
30
         try {
32
-          all.add((Location) field.get(null));
31
+          ALL.add((Location) field.get(null));
33
         } catch (IllegalAccessException e) {
32
         } catch (IllegalAccessException e) {
34
           throw new RuntimeException(e);
33
           throw new RuntimeException(e);
35
         }
34
         }
38
   }
37
   }
39
 
38
 
40
   public static List<Location> getAll() {
39
   public static List<Location> getAll() {
41
-    return all;
40
+    return ALL;
42
   }
41
   }
43
-  
42
+
44
 }
43
 }

+ 4
- 4
dddsample/src/test/java/se/citerus/dddsample/service/RoutingServiceTest.java Näytä tiedosto

17
 
17
 
18
 public class RoutingServiceTest extends TestCase {
18
 public class RoutingServiceTest extends TestCase {
19
 
19
 
20
-  RoutingServiceImpl routingService;
21
-  LocationRepository locationRepository;
22
-  CargoRepository cargoRepository;
23
-  CarrierMovementRepository carrierMovementRepository;
20
+  private RoutingServiceImpl routingService;
21
+  private LocationRepository locationRepository;
22
+  private CargoRepository cargoRepository;
23
+  private CarrierMovementRepository carrierMovementRepository;
24
 
24
 
25
   protected void setUp() throws Exception {
25
   protected void setUp() throws Exception {
26
     routingService = new RoutingServiceImpl();
26
     routingService = new RoutingServiceImpl();

+ 24
- 24
dddsample/src/test/java/se/citerus/dddsample/ws/HandlinEventServiceEndpointTest.java Näytä tiedosto

15
 
15
 
16
 public class HandlinEventServiceEndpointTest extends TestCase {
16
 public class HandlinEventServiceEndpointTest extends TestCase {
17
 
17
 
18
-  HandlingEventServiceEndpointImpl endpoint;
19
-  HandlingEventService handlingEventService;
20
-  SimpleDateFormat sdf;
18
+  private HandlingEventServiceEndpointImpl endpoint;
19
+  private HandlingEventService handlingEventService;
20
+  private SimpleDateFormat sdf;
21
 
21
 
22
   protected void setUp() throws Exception {
22
   protected void setUp() throws Exception {
23
     endpoint = new HandlingEventServiceEndpointImpl();
23
     endpoint = new HandlingEventServiceEndpointImpl();
52
   }
52
   }
53
 
53
 
54
   public void testRegisterUnknownCarrierMovementId() throws Exception {
54
   public void testRegisterUnknownCarrierMovementId() throws Exception {
55
-      Date date = new Date(100);
55
+    Date date = new Date(100);
56
 
56
 
57
-      TrackingId trackingId = new TrackingId("XYZ");
58
-      CarrierMovementId carrierMovementId = new CarrierMovementId("NOTFOUND");
57
+    TrackingId trackingId = new TrackingId("XYZ");
58
+    CarrierMovementId carrierMovementId = new CarrierMovementId("NOTFOUND");
59
 
59
 
60
-      handlingEventService.register(date, trackingId, carrierMovementId, new UnLocode("AUMEL"), HandlingEvent.Type.UNLOAD);
61
-      expectLastCall().andThrow(new UnknownCarrierMovementIdException(carrierMovementId));
62
-      replay(handlingEventService);
60
+    handlingEventService.register(date, trackingId, carrierMovementId, new UnLocode("AUMEL"), HandlingEvent.Type.UNLOAD);
61
+    expectLastCall().andThrow(new UnknownCarrierMovementIdException(carrierMovementId));
62
+    replay(handlingEventService);
63
 
63
 
64
-      // Tested call
65
-      endpoint.register(sdf.format(date), "XYZ", "NOTFOUND", "AUMEL", "UNLOAD");
64
+    // Tested call
65
+    endpoint.register(sdf.format(date), "XYZ", "NOTFOUND", "AUMEL", "UNLOAD");
66
   }
66
   }
67
 
67
 
68
   public void testRegisterInvalidEventType() throws Exception {
68
   public void testRegisterInvalidEventType() throws Exception {
69
-      Date date = new Date(100);
70
-      
71
-      replay(handlingEventService);
69
+    Date date = new Date(100);
70
+
71
+    replay(handlingEventService);
72
 
72
 
73
-      // Tested call
74
-      // Note: currently, every error is silently swallowed.
75
-      endpoint.register(sdf.format(date), "XYZ", "CAR_333", "AUMEL", "NO_SUCH_EVENT_TYPE");
73
+    // Tested call
74
+    // Note: currently, every error is silently swallowed.
75
+    endpoint.register(sdf.format(date), "XYZ", "CAR_333", "AUMEL", "NO_SUCH_EVENT_TYPE");
76
   }
76
   }
77
 
77
 
78
-    public void testRegisterInvalidDateFormat() throws Exception {
79
-        Date date = new Date(100);
78
+  public void testRegisterInvalidDateFormat() throws Exception {
79
+    Date date = new Date(100);
80
 
80
 
81
-        replay(handlingEventService);
81
+    replay(handlingEventService);
82
 
82
 
83
-        // Tested call
84
-        // Note: currently, every error is silently swallowed.
85
-        endpoint.register("1 2 3 4", "XYZ", "CAR_333", "AUMEL", "LOAD");
86
-    }
83
+    // Tested call
84
+    // Note: currently, every error is silently swallowed.
85
+    endpoint.register("1 2 3 4", "XYZ", "CAR_333", "AUMEL", "LOAD");
86
+  }
87
 
87
 
88
 
88
 
89
   protected void tearDown() throws Exception {
89
   protected void tearDown() throws Exception {