Просмотр исходного кода

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 лет назад
Родитель
Сommit
07e2bd6139
54 измененных файлов: 752 добавлений и 441 удалений
  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 Просмотреть файл

@@ -0,0 +1,221 @@
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 Просмотреть файл

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

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

@@ -9,7 +9,7 @@ import javax.persistence.*;
9 9
  * A carrier movement is a vessel voyage from one location to another.
10 10
  */
11 11
 @Entity
12
-public class CarrierMovement {
12
+public final class CarrierMovement {
13 13
 
14 14
   @Id
15 15
   @GeneratedValue
@@ -24,8 +24,15 @@ public class CarrierMovement {
24 24
   @ManyToOne
25 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 36
     this.carrierMovementId = carrierMovementId;
30 37
     this.from = from;
31 38
     this.to = to;
@@ -58,16 +65,16 @@ public class CarrierMovement {
58 65
    * @return <code>true</code> if the given carrier movement's and this carrier movement's carrier id are the same,
59 66
    *         regardles of other attributes.
60 67
    */
61
-  public boolean sameIdentityAs(CarrierMovement other) {
68
+  public boolean sameIdentityAs(final CarrierMovement other) {
62 69
     return carrierMovementId.equals(other.carrierMovementId);
63 70
   }
64 71
 
65 72
   @Override
66
-  public boolean equals(Object o) {
73
+  public boolean equals(final Object o) {
67 74
     if (this == o) return true;
68 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 79
     return sameIdentityAs(that);
73 80
   }

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

@@ -9,15 +9,19 @@ import javax.persistence.Embeddable;
9 9
 
10 10
 /**
11 11
  * Identifies a particular carrier movement, such as a flight number.
12
- *
13 12
  */
14 13
 @Embeddable
15
-public class CarrierMovementId {
14
+public final class CarrierMovementId {
16 15
 
17 16
   @Column(name = "carrier_movement_id")
18 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 25
     Validate.notNull(id);
22 26
     this.id = id;
23 27
   }
@@ -30,7 +34,7 @@ public class CarrierMovementId {
30 34
   }
31 35
 
32 36
   @Override
33
-  public boolean equals(Object obj) {
37
+  public boolean equals(final Object obj) {
34 38
     return EqualsBuilder.reflectionEquals(this, obj);
35 39
   }
36 40
 
@@ -40,6 +44,7 @@ public class CarrierMovementId {
40 44
   }
41 45
 
42 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 Просмотреть файл

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

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

@@ -17,13 +17,13 @@ import java.util.Date;
17 17
  * {@link Type#UNLOAD}. All other events must be of {@link Type#RECEIVE}, {@link Type#CLAIM} or {@link Type#CUSTOMS}.
18 18
  */
19 19
 @Entity
20
-public class HandlingEvent {
20
+public final class HandlingEvent {
21 21
 
22 22
   /**
23 23
    * Comparator used to be able to sort HandlingEvents according to their completion time
24 24
    */
25 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 27
       return o1.completionTime().compareTo(o2.completionTime());
28 28
     }
29 29
   };
@@ -58,7 +58,12 @@ public class HandlingEvent {
58 58
 
59 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 67
       this.carrierMovementRequired = carrierMovementRequired;
63 68
     }
64 69
 
@@ -77,7 +82,6 @@ public class HandlingEvent {
77 82
     }
78 83
   }
79 84
 
80
-
81 85
   /**
82 86
    * @param cargo            cargo
83 87
    * @param completionTime   completion time, the reported time that the event actually happened (e.g. the receive took place).
@@ -86,8 +90,9 @@ public class HandlingEvent {
86 90
    * @param location         where the event took place
87 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 96
     this.registrationTime = registrationTime;
92 97
     this.completionTime = completionTime;
93 98
     this.type = type;
@@ -126,11 +131,11 @@ public class HandlingEvent {
126 131
     return this.cargo;
127 132
   }
128 133
 
129
-  public boolean equals(Object o) {
134
+  public boolean equals(final Object o) {
130 135
     if (this == o) return true;
131 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 140
     return sameEventAs(event);
136 141
   }
@@ -138,14 +143,14 @@ public class HandlingEvent {
138 143
   /**
139 144
    * Events compare by the attributes that identify the underlying event as opposed to the report of the event.
140 145
    * Therefore the completion time is part of the comparison but not the registration time.
141
-   *
146
+   * <p/>
142 147
    * Compare this behavior to the value object {@link se.citerus.dddsample.domain.Leg#sameValueAs(Leg)}
143 148
    * Compare this behavior to the entity {@link se.citerus.dddsample.domain.Cargo#sameIdentityAs(Cargo)}
144 149
    *
145 150
    * @param other The other hanling event.
146 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 154
     return other != null && new EqualsBuilder().
150 155
       append(this.cargo, other.cargo).
151 156
       append(this.carrierMovement, other.carrierMovement).
@@ -157,7 +162,7 @@ public class HandlingEvent {
157 162
 
158 163
   @Override
159 164
   public int hashCode() {
160
-    return new HashCodeBuilder(13,41).
165
+    return new HashCodeBuilder().
161 166
       append(cargo).
162 167
       append(carrierMovement).
163 168
       append(completionTime).

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

@@ -11,7 +11,7 @@ import java.util.List;
11 11
  *
12 12
  */
13 13
 @Entity
14
-public class Itinerary {
14
+public final class Itinerary {
15 15
 
16 16
   @Id
17 17
   @GeneratedValue
@@ -23,13 +23,18 @@ public class Itinerary {
23 23
 
24 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 32
     Validate.notEmpty(legs);
28 33
     Validate.noNullElements(legs);
29 34
     this.legs = legs;
30 35
   }
31 36
 
32
-  public Itinerary(Leg... legs) {
37
+  public Itinerary(final Leg... legs) {
33 38
     this(Arrays.asList(legs));
34 39
   }
35 40
 
@@ -43,14 +48,14 @@ public class Itinerary {
43 48
    * @param event Event to test.
44 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 52
     if (legs.isEmpty()) {
48 53
       return true;
49 54
     }
50 55
 
51 56
     if (event.type() == HandlingEvent.Type.RECEIVE) {
52 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 59
       return (leg.from().equals(event.location()));
55 60
     }
56 61
 
@@ -58,7 +63,7 @@ public class Itinerary {
58 63
       //Check that the there is one leg with same from location and carrier movement
59 64
       for (Leg leg : legs) {
60 65
         if (leg.from().equals(event.location())
61
-           && leg.carrierMovement().equals(event.carrierMovement()))
66
+          && leg.carrierMovement().equals(event.carrierMovement()))
62 67
           return true;
63 68
       }
64 69
       return false;
@@ -68,7 +73,7 @@ public class Itinerary {
68 73
       //Check that the there is one leg with same to loc and carrier movement
69 74
       for (Leg leg : legs) {
70 75
         if (leg.to().equals(event.location())
71
-           && leg.carrierMovement().equals(event.carrierMovement()))
76
+          && leg.carrierMovement().equals(event.carrierMovement()))
72 77
           return true;
73 78
       }
74 79
       return false;
@@ -76,7 +81,7 @@ public class Itinerary {
76 81
 
77 82
     if (event.type() == HandlingEvent.Type.CLAIM) {
78 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 85
       return (leg.to().equals(event.location()));
81 86
     }
82 87
 
@@ -88,16 +93,16 @@ public class Itinerary {
88 93
    * @param other itinerary to compare
89 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 97
     return other != null && legs.equals(other.legs);
93 98
   }
94 99
 
95 100
   @Override
96
-  public boolean equals(Object o) {
101
+  public boolean equals(final Object o) {
97 102
     if (this == o) return true;
98 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 107
     return sameValueAs(itinerary);
103 108
   }

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

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

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

@@ -8,7 +8,7 @@ import javax.persistence.GeneratedValue;
8 8
 import javax.persistence.Id;
9 9
 
10 10
 @Entity
11
-public class Location {
11
+public final class Location {
12 12
 
13 13
   @Id
14 14
   @GeneratedValue
@@ -22,19 +22,17 @@ public class Location {
22 22
   /**
23 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 28
    * Package-level constructor, visible for test only.
31
-   * 
29
+   *
32 30
    * @param unLocode UN Locode
33 31
    * @param name     location name
34 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 36
     Validate.notNull(unLocode);
39 37
     Validate.notNull(name);
40 38
     this.unLocode = unLocode;
@@ -60,7 +58,7 @@ public class Location {
60 58
    * @return Since this is an entiy this will be true iff UN locodes are equal.
61 59
    */
62 60
   @Override
63
-  public boolean equals(Object object) {
61
+  public boolean equals(final Object object) {
64 62
     if (object == null) {
65 63
       return false;
66 64
     }
@@ -77,14 +75,14 @@ public class Location {
77 75
   /**
78 76
    * Entities compare by identity, therefore the unLocode field is the only basis of comparison. For persistence we
79 77
    * have an id field, but it is not used for identiy comparison.
80
-   *
78
+   * <p/>
81 79
    * Compare this behavior to the value object {@link se.citerus.dddsample.domain.Leg#sameValueAs(Leg)}
82 80
    *
83 81
    * @param other The other location.
84 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 86
     return this.unLocode.equals(other.unLocode);
89 87
   }
90 88
 

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

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

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/domain/StatusCode.java Просмотреть файл

@@ -1,7 +1,7 @@
1 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 6
 public enum StatusCode {
7 7
   NOT_RECEIVED, IN_PORT, ONBOARD_CARRIER, CLAIMED

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

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

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

@@ -9,35 +9,40 @@ import java.util.regex.Pattern;
9 9
 
10 10
 /**
11 11
  * United nations location code.
12
- *
12
+ * <p/>
13 13
  * http://www.unece.org/cefact/locode/
14 14
  * http://www.unece.org/cefact/locode/DocColumnDescription.htm#LOCODE
15 15
  */
16 16
 @Embeddable
17
-public class UnLocode {
17
+public final class UnLocode {
18 18
 
19 19
   private String unlocode;
20 20
 
21 21
   // Country code is exactly two letters.
22 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 31
     Validate.notNull(countryAndLocation);
27
-    Validate.isTrue(validPattern.matcher(countryAndLocation).matches());
32
+    Validate.isTrue(VALID_PATTERN.matcher(countryAndLocation).matches());
28 33
 
29 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 40
   public String idString() {
36 41
     return unlocode;
37 42
   }
38 43
 
39 44
   @Override
40
-  public boolean equals(Object obj) {
45
+  public boolean equals(final Object obj) {
41 46
     return EqualsBuilder.reflectionEquals(this, obj);
42 47
   }
43 48
 

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

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

+ 13
- 11
dddsample/src/main/java/se/citerus/dddsample/repository/CargoRepositoryInMem.java Просмотреть файл

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

+ 6
- 0
dddsample/src/main/java/se/citerus/dddsample/repository/CarrierMovementRepository.java Просмотреть файл

@@ -5,6 +5,12 @@ import se.citerus.dddsample.domain.CarrierMovementId;
5 5
 
6 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 14
   CarrierMovement find(CarrierMovementId carrierMovementId);
9 15
 
10 16
 }

+ 5
- 6
dddsample/src/main/java/se/citerus/dddsample/repository/CarrierMovementRepositoryHibernate.java Просмотреть файл

@@ -6,16 +6,15 @@ import se.citerus.dddsample.domain.CarrierMovementId;
6 6
 
7 7
 /**
8 8
  * Hibernate implementation of CarrierMovementRepository.
9
- *
10 9
  */
11 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 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 Просмотреть файл

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

+ 2
- 3
dddsample/src/main/java/se/citerus/dddsample/repository/HandlingEventRepository.java Просмотреть файл

@@ -7,7 +7,6 @@ import java.util.List;
7 7
 
8 8
 /**
9 9
  * Handling event repository.
10
- *
11 10
  */
12 11
 public interface HandlingEventRepository {
13 12
 
@@ -16,11 +15,11 @@ public interface HandlingEventRepository {
16 15
    *
17 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 21
    * @param trackingId cargo tracking id
23 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 Просмотреть файл

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

+ 2
- 3
dddsample/src/main/java/se/citerus/dddsample/repository/HibernateRepository.java Просмотреть файл

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

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

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

+ 5
- 5
dddsample/src/main/java/se/citerus/dddsample/repository/LocationRepositoryHibernate.java Просмотреть файл

@@ -5,13 +5,13 @@ import se.citerus.dddsample.domain.UnLocode;
5 5
 
6 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 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 17
   public List<Location> findAll() {

+ 2
- 3
dddsample/src/main/java/se/citerus/dddsample/service/CargoService.java Просмотреть файл

@@ -10,14 +10,13 @@ import java.util.List;
10 10
 
11 11
 /**
12 12
  * Cargo service.
13
- *
14 13
  */
15 14
 public interface CargoService {
16 15
 
17 16
   /**
18 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 20
    * @param destination cargo destination
22 21
    * @return Cargo tracking id
23 22
    */
@@ -63,7 +62,7 @@ public interface CargoService {
63 62
    * based on this list of legs.
64 63
    *
65 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 67
   void assignItinerary(TrackingId trackingId, ItineraryCandidateDTO itinerary);
69 68
 

+ 35
- 39
dddsample/src/main/java/se/citerus/dddsample/service/CargoServiceImpl.java Просмотреть файл

@@ -13,24 +13,24 @@ import se.citerus.dddsample.service.dto.*;
13 13
 import java.util.ArrayList;
14 14
 import java.util.List;
15 15
 
16
-public class CargoServiceImpl implements CargoService {
16
+public final class CargoServiceImpl implements CargoService {
17 17
 
18 18
   private CargoRepository cargoRepository;
19 19
   private LocationRepository locationRepository;
20 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 24
   @Transactional(readOnly = false)
25
-  public TrackingId registerNew(UnLocode originUnLocode, UnLocode destinationUnLocode) {
25
+  public TrackingId registerNew(final UnLocode originUnLocode, final UnLocode destinationUnLocode) {
26 26
     Validate.notNull(originUnLocode);
27 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 35
     cargoRepository.save(cargo);
36 36
     logger.info("Registered new cargo with tracking id " + trackingId.idString());
@@ -40,8 +40,8 @@ public class CargoServiceImpl implements CargoService {
40 40
 
41 41
   @Transactional(readOnly = true)
42 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 45
     for (Location location : allLocations) {
46 46
       unlocodes.add(location.unLocode());
47 47
     }
@@ -49,7 +49,7 @@ public class CargoServiceImpl implements CargoService {
49 49
   }
50 50
 
51 51
   @Transactional(readOnly = true)
52
-  public CargoTrackingDTO track(TrackingId trackingId) {
52
+  public CargoTrackingDTO track(final TrackingId trackingId) {
53 53
     Validate.notNull(trackingId);
54 54
 
55 55
     final Cargo cargo = cargoRepository.find(trackingId);
@@ -57,11 +57,11 @@ public class CargoServiceImpl implements CargoService {
57 57
       return null;
58 58
     }
59 59
 
60
-    DeliveryHistory deliveryHistory = cargo.deliveryHistory();
60
+    final DeliveryHistory deliveryHistory = cargo.deliveryHistory();
61 61
 
62 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 65
     final CargoTrackingDTO dto = new CargoTrackingDTO(
66 66
       cargo.trackingId().idString(),
67 67
       cargo.origin().toString(),
@@ -74,8 +74,8 @@ public class CargoServiceImpl implements CargoService {
74 74
 
75 75
     final List<HandlingEvent> events = deliveryHistory.eventsOrderedByCompletionTime();
76 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 79
       dto.addEvent(new HandlingEventDTO(
80 80
         event.location().toString(),
81 81
         event.type().toString(),
@@ -90,10 +90,10 @@ public class CargoServiceImpl implements CargoService {
90 90
 
91 91
   // TODO: move this to another class?
92 92
   @Transactional(readOnly = true)
93
-  public void notify(TrackingId trackingId) {
93
+  public void notify(final TrackingId trackingId) {
94 94
     Validate.notNull(trackingId);
95 95
 
96
-    Cargo cargo = cargoRepository.find(trackingId);
96
+    final Cargo cargo = cargoRepository.find(trackingId);
97 97
     if (cargo == null) {
98 98
       logger.warn("Can't notify listeners for non-existing cargo " + trackingId);
99 99
       return;
@@ -102,22 +102,22 @@ public class CargoServiceImpl implements CargoService {
102 102
     // TODO: more elaborate notifications, such as email to affected customer
103 103
     if (cargo.isMisdirected()) {
104 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 107
     if (cargo.isUnloadedAtDestination()) {
108 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 113
   @Transactional(readOnly = true)
114 114
   public List<CargoRoutingDTO> loadAllForRouting() {
115
-    List<Cargo> allCargos = cargoRepository.findAll();
115
+    final List<Cargo> allCargos = cargoRepository.findAll();
116 116
 
117 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 119
     for (Cargo cargo : allCargos) {
120
-      CargoRoutingDTO dto = new CargoRoutingDTO(
120
+      final CargoRoutingDTO dto = new CargoRoutingDTO(
121 121
         cargo.trackingId().idString(),
122 122
         cargo.origin().toString(),
123 123
         cargo.finalDestination().toString()
@@ -136,15 +136,15 @@ public class CargoServiceImpl implements CargoService {
136 136
   }
137 137
 
138 138
   @Transactional(readOnly = true)
139
-  public CargoRoutingDTO loadForRouting(TrackingId trackingId) {
139
+  public CargoRoutingDTO loadForRouting(final TrackingId trackingId) {
140 140
     Validate.notNull(trackingId);
141
-    Cargo cargo = cargoRepository.find(trackingId);
141
+    final Cargo cargo = cargoRepository.find(trackingId);
142 142
     if (cargo == null) {
143 143
       return null;
144 144
     }
145 145
 
146 146
     // TODO: use DTO assembler
147
-    CargoRoutingDTO dto = new CargoRoutingDTO(
147
+    final CargoRoutingDTO dto = new CargoRoutingDTO(
148 148
       cargo.trackingId().idString(),
149 149
       cargo.origin().toString(),
150 150
       cargo.finalDestination().toString()
@@ -160,25 +160,22 @@ public class CargoServiceImpl implements CargoService {
160 160
   }
161 161
 
162 162
   @Transactional(readOnly = false)
163
-  public void assignItinerary(TrackingId trackingId, ItineraryCandidateDTO itinerary) {
163
+  public void assignItinerary(final TrackingId trackingId, final ItineraryCandidateDTO itinerary) {
164 164
     Validate.notNull(trackingId);
165 165
     Validate.notNull(itinerary);
166 166
 
167
-    Cargo cargo = cargoRepository.find(trackingId);
167
+    final Cargo cargo = cargoRepository.find(trackingId);
168 168
     if (cargo == null) {
169 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 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 180
     // TODO: delete orphaned itineraries.
184 181
     // Can't cascade delete-orphan for many-to-one using mapping directives.
@@ -186,12 +183,11 @@ public class CargoServiceImpl implements CargoService {
186 183
     cargoRepository.save(cargo);
187 184
   }
188 185
 
189
-
190
-  public void setCargoRepository(CargoRepository cargoRepository) {
186
+  public void setCargoRepository(final CargoRepository cargoRepository) {
191 187
     this.cargoRepository = cargoRepository;
192 188
   }
193 189
 
194
-  public void setLocationRepository(LocationRepository locationRepository) {
190
+  public void setLocationRepository(final LocationRepository locationRepository) {
195 191
     this.locationRepository = locationRepository;
196 192
   }
197 193
 

+ 5
- 5
dddsample/src/main/java/se/citerus/dddsample/service/HandlingEventMessageDelegate.java Просмотреть файл

@@ -11,17 +11,17 @@ import javax.jms.MessageListener;
11 11
 /**
12 12
  * Consumes JMS messages and delegates notification of misdirected
13 13
  * cargo to the cargo service.
14
- *
14
+ * <p/>
15 15
  * This point of this is to decouple the cargo service from JMS,
16 16
  * and to allow a thread-based messaging implementation to live in
17
- * parallell. 
17
+ * parallell.
18 18
  */
19 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 25
     if (logger.isDebugEnabled()) {
26 26
       logger.debug("Received message " + message);
27 27
     }

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

@@ -10,22 +10,21 @@ import java.util.Date;
10 10
 
11 11
 /**
12 12
  * Handling event service.
13
- *
14 13
  */
15 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 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 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 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 Просмотреть файл

@@ -10,7 +10,7 @@ import se.citerus.dddsample.repository.LocationRepository;
10 10
 
11 11
 import java.util.Date;
12 12
 
13
-public class HandlingEventServiceImpl implements HandlingEventService {
13
+public final class HandlingEventServiceImpl implements HandlingEventService {
14 14
   private CargoRepository cargoRepository;
15 15
   private CarrierMovementRepository carrierMovementRepository;
16 16
   private HandlingEventRepository handlingEventRepository;
@@ -18,18 +18,21 @@ public class HandlingEventServiceImpl implements HandlingEventService {
18 18
   private EventService eventService;
19 19
 
20 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 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 28
     Cargo cargo = cargoRepository.find(trackingId);
26 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 38
       NOTE:
@@ -47,11 +50,13 @@ public class HandlingEventServiceImpl implements HandlingEventService {
47 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 56
     if (carrierMovementId == null) {
52 57
       return null;
53 58
     }
54
-    CarrierMovement carrierMovement = carrierMovementRepository.find(carrierMovementId);
59
+    final CarrierMovement carrierMovement = carrierMovementRepository.find(carrierMovementId);
55 60
     if (carrierMovement == null) {
56 61
       throw new UnknownCarrierMovementIdException(carrierMovementId);
57 62
     }
@@ -59,36 +64,36 @@ public class HandlingEventServiceImpl implements HandlingEventService {
59 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 68
     if (unlocode == null) {
64 69
       return Location.UNKNOWN;
65 70
     }
66
-    
67
-    Location location = locationRepository.find(unlocode);
71
+
72
+    final Location location = locationRepository.find(unlocode);
68 73
     if (location == null) {
69 74
       throw new UnknownLocationException(unlocode);
70 75
     }
71
-    
76
+
72 77
     return location;
73 78
   }
74 79
 
75
-  public void setCargoRepository(CargoRepository cargoRepository) {
80
+  public void setCargoRepository(final CargoRepository cargoRepository) {
76 81
     this.cargoRepository = cargoRepository;
77 82
   }
78 83
 
79
-  public void setCarrierMovementRepository(CarrierMovementRepository carrierMovementRepository) {
84
+  public void setCarrierMovementRepository(final CarrierMovementRepository carrierMovementRepository) {
80 85
     this.carrierMovementRepository = carrierMovementRepository;
81 86
   }
82 87
 
83
-  public void setHandlingEventRepository(HandlingEventRepository handlingEventRepository) {
88
+  public void setHandlingEventRepository(final HandlingEventRepository handlingEventRepository) {
84 89
     this.handlingEventRepository = handlingEventRepository;
85 90
   }
86 91
 
87
-  public void setLocationRepository(LocationRepository locationRepository) {
92
+  public void setLocationRepository(final LocationRepository locationRepository) {
88 93
     this.locationRepository = locationRepository;
89 94
   }
90 95
 
91
-  public void setEventService(EventService eventService) {
96
+  public void setEventService(final EventService eventService) {
92 97
     this.eventService = eventService;
93 98
   }
94 99
 }

+ 6
- 6
dddsample/src/main/java/se/citerus/dddsample/service/JmsEventServiceImpl.java Просмотреть файл

@@ -10,7 +10,7 @@ import javax.jms.*;
10 10
 /**
11 11
  * JMS based implementation.
12 12
  */
13
-public class JmsEventServiceImpl implements EventService {
13
+public final class JmsEventServiceImpl implements EventService {
14 14
   private JmsOperations jmsOperations;
15 15
   private Destination destination;
16 16
   public static final String TRACKING_ID_KEY = TrackingId.class.getName() + ".KEY";
@@ -18,20 +18,20 @@ public class JmsEventServiceImpl implements EventService {
18 18
   public void fireHandlingEventRegistered(final HandlingEvent event) {
19 19
     jmsOperations.send(destination, new MessageCreator() {
20 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 23
         message.setStringProperty(TRACKING_ID_KEY, event.cargo().trackingId().idString());
24 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 31
     this.jmsOperations = jmsOperations;
32 32
   }
33 33
 
34
-  public void setDestination(Destination destination) {
34
+  public void setDestination(final Destination destination) {
35 35
     this.destination = destination;
36 36
   }
37 37
 }

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

@@ -7,7 +7,7 @@ import se.citerus.dddsample.service.dto.ItineraryCandidateDTO;
7 7
 import java.util.List;
8 8
 
9 9
 /**
10
- *  
10
+ *
11 11
  */
12 12
 public interface RoutingService {
13 13
 

+ 7
- 8
dddsample/src/main/java/se/citerus/dddsample/service/RoutingServiceImpl.java Просмотреть файл

@@ -5,7 +5,7 @@ import se.citerus.dddsample.domain.*;
5 5
 import se.citerus.dddsample.repository.CargoRepository;
6 6
 import se.citerus.dddsample.repository.CarrierMovementRepository;
7 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 9
 import se.citerus.dddsample.service.dto.ItineraryCandidateDTO;
10 10
 
11 11
 import java.util.ArrayList;
@@ -16,13 +16,12 @@ import java.util.Random;
16 16
 /**
17 17
  * Simple routing service implementation that randomly creates a number
18 18
  * of different itineraries.
19
- *
20 19
  */
21 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 26
   Random random = new Random();
28 27
 
@@ -49,10 +48,10 @@ public class RoutingServiceImpl implements RoutingService {
49 48
       CarrierMovement cm1 = carrierMovementRepository.find(new CarrierMovementId("CAR_002"));
50 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 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 57
       Location lastLegFrom = allLocations.get(allLocations.size() - 1);

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

@@ -6,6 +6,7 @@ import se.citerus.dddsample.domain.HandlingEvent;
6 6
  * Thread based implementation.
7 7
  */
8 8
 public class ThreadBasedEventServiceImpl implements EventService {
9
+
9 10
   private CargoService cargoService;
10 11
 
11 12
   public void fireHandlingEventRegistered(final HandlingEvent event) {

+ 3
- 3
dddsample/src/main/java/se/citerus/dddsample/service/UnknownCarrierMovementIdException.java Просмотреть файл

@@ -4,12 +4,12 @@ import se.citerus.dddsample.domain.CarrierMovementId;
4 4
 
5 5
 /**
6 6
  * Thrown when trying to register an event with an unknown carrier movement id.
7
- *
8 7
  */
9 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 13
     this.carrierMovementId = carrierMovementId;
14 14
   }
15 15
 

+ 2
- 2
dddsample/src/main/java/se/citerus/dddsample/service/UnknownLocationException.java Просмотреть файл

@@ -4,9 +4,9 @@ import se.citerus.dddsample.domain.UnLocode;
4 4
 
5 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 10
     this.unlocode = unlocode;
11 11
   }
12 12
 

+ 4
- 4
dddsample/src/main/java/se/citerus/dddsample/service/UnknownTrackingIdException.java Просмотреть файл

@@ -4,12 +4,12 @@ import se.citerus.dddsample.domain.TrackingId;
4 4
 
5 5
 /**
6 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 13
     this.trackingId = trackingId;
14 14
   }
15 15
 

+ 11
- 8
dddsample/src/main/java/se/citerus/dddsample/service/dto/CargoRoutingDTO.java Просмотреть файл

@@ -6,15 +6,15 @@ import java.util.List;
6 6
 
7 7
 /**
8 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 18
     this.trackingId = trackingId;
19 19
     this.origin = origin;
20 20
     this.finalDestination = finalDestination;
@@ -33,10 +33,13 @@ public class CargoRoutingDTO {
33 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 37
     legs.add(new LegDTO(carrierMovementId, from, to));
38 38
   }
39 39
 
40
+  /**
41
+   * @return An unmodifiable list DTOs.
42
+   */
40 43
   public List<LegDTO> getLegs() {
41 44
     return Collections.unmodifiableList(legs);
42 45
   }

+ 18
- 16
dddsample/src/main/java/se/citerus/dddsample/service/dto/CargoTrackingDTO.java Просмотреть файл

@@ -9,22 +9,21 @@ import java.util.List;
9 9
 
10 10
 /**
11 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 27
     this.trackingId = trackingId;
29 28
     this.origin = origin;
30 29
     this.finalDestination = finalDestination;
@@ -36,10 +35,13 @@ public class CargoTrackingDTO implements Serializable {
36 35
     this.events = new ArrayList<HandlingEventDTO>();
37 36
   }
38 37
 
39
-  public void addEvent(HandlingEventDTO handlingEvent) {
38
+  public void addEvent(final HandlingEventDTO handlingEvent) {
40 39
     events.add(handlingEvent);
41 40
   }
42 41
 
42
+  /**
43
+   * @return An unmodifiable list DTOs.
44
+   */
43 45
   public List<HandlingEventDTO> getEvents() {
44 46
     return Collections.unmodifiableList(events);
45 47
   }

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

@@ -1,29 +0,0 @@
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 Просмотреть файл

@@ -6,7 +6,7 @@ import java.util.Date;
6 6
 /**
7 7
  * DTO for a handling event.
8 8
  */
9
-public class HandlingEventDTO implements Serializable {
9
+public final class HandlingEventDTO implements Serializable {
10 10
 
11 11
   private final String type;
12 12
   private final String location;
@@ -14,7 +14,8 @@ public class HandlingEventDTO implements Serializable {
14 14
   private final Date time;
15 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 19
     this.location = location;
19 20
     this.type = type;
20 21
     this.carrier = carrier;

+ 7
- 4
dddsample/src/main/java/se/citerus/dddsample/service/dto/ItineraryCandidateDTO.java Просмотреть файл

@@ -5,15 +5,18 @@ import java.util.List;
5 5
 
6 6
 /**
7 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 14
     this.legs = legs;
15 15
   }
16 16
 
17
+  /**
18
+   * @return An unmodifiable list DTOs.
19
+   */
17 20
   public List<LegDTO> getLegs() {
18 21
     return Collections.unmodifiableList(legs);
19 22
   }

+ 5
- 6
dddsample/src/main/java/se/citerus/dddsample/service/dto/LegDTO.java Просмотреть файл

@@ -2,15 +2,14 @@ package se.citerus.dddsample.service.dto;
2 2
 
3 3
 /**
4 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 13
     this.carrierMovementId = carrierMovementId;
15 14
     this.from = from;
16 15
     this.to = to;

+ 32
- 0
dddsample/src/main/java/se/citerus/dddsample/service/dto/assembler/DTOAssembler.java Просмотреть файл

@@ -0,0 +1,32 @@
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 Просмотреть файл

@@ -27,29 +27,28 @@ import java.util.zip.ZipFile;
27 27
 
28 28
 /**
29 29
  * Imports about 55 000 locations from an official UN Locode CSV export.
30
- *
30
+ * <p/>
31 31
  * NOTE: not yet used
32
- *
33 32
  */
34 33
 public class LocationsImporter implements ServletContextListener {
35 34
   private static final String ZIP_FILE_NAME = "unlocodes.zip";
36 35
   private static final String ZIP_ENTRY_NAME = "2006-2 UNLOCODE CodeList.txt";
37 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 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 48
     final String[][] batchArgs = new String[BATCH_SIZE][2];
50 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 52
       if (args != null) {
54 53
         int pos = count % BATCH_SIZE;
55 54
         batchArgs[pos][0] = args[0];
@@ -61,6 +60,7 @@ public class LocationsImporter implements ServletContextListener {
61 60
               ps.setString(1, batchArgs[i][0]);
62 61
               ps.setString(2, batchArgs[i][1]);
63 62
             }
63
+
64 64
             public int getBatchSize() {
65 65
               return BATCH_SIZE;
66 66
             }
@@ -74,27 +74,26 @@ public class LocationsImporter implements ServletContextListener {
74 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 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 83
     } else {
84 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 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 97
       public Object doInTransaction(TransactionStatus status) {
99 98
         try {
100 99
           return importLocations(jt);
@@ -103,8 +102,9 @@ public class LocationsImporter implements ServletContextListener {
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 Просмотреть файл

@@ -19,26 +19,29 @@ import java.util.Map;
19 19
 
20 20
 /**
21 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 25
   private CargoService cargoService;
27 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 33
     for (UnLocode unLocode : unLocodes) {
34 34
       unLocodeStrings.add(unLocode.idString());
35 35
     }
36
+
36 37
     map.put("unlocodes", unLocodeStrings);
37 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 45
       new UnLocode(command.getOriginUnlocode()),
43 46
       new UnLocode(command.getDestinationUnlocode())
44 47
     );
@@ -46,34 +49,33 @@ public class CargoAdminController extends MultiActionController {
46 49
   }
47 50
 
48 51
   public Map list(HttpServletRequest request, HttpServletResponse response) {
49
-    Map map = new HashMap();
52
+    final Map<String, Object> map = new HashMap<String, Object>();
50 53
     map.put("cargoList", cargoService.loadAllForRouting());
51 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 60
     map.put("cargo", cargoService.loadForRouting(trackingId));
59 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 71
     // TODO: eliminate the routing command altogether, use the DTOs in the view
71 72
     for (ItineraryCandidateDTO itinerary : itineraries) {
72
-      RoutingCommand.ItineraryCandidateCommand itineraryCandidateCommand = new RoutingCommand.ItineraryCandidateCommand();
73
+      final RoutingCommand.ItineraryCandidateCommand itineraryCandidateCommand =
74
+        new RoutingCommand.ItineraryCandidateCommand();
73 75
       itineraryCandidateCommand.setTrackingId(trackingId.idString());
74 76
       itineraryCandidates.add(itineraryCandidateCommand);
75 77
       for (LegDTO leg : itinerary.getLegs()) {
76
-        RoutingCommand.LegCommand legCommand = new RoutingCommand.LegCommand();
78
+        final RoutingCommand.LegCommand legCommand = new RoutingCommand.LegCommand();
77 79
         legCommand.setCarrierMovementId(leg.getCarrierMovementId());
78 80
         legCommand.setFromUnlocode(leg.getFrom());
79 81
         legCommand.setToUnlocode(leg.getTo());
@@ -86,31 +88,31 @@ public class CargoAdminController extends MultiActionController {
86 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 94
     // TODO:  gah, stuck on indexoutofbounds (legs[0].fromUnlocode etc) when trying to bind...
93 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 101
     for (int i = 0; i < cmIds.length; i++) {
100 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 106
     cargoService.assignItinerary(trackingId, selectedItinerary);
105 107
 
106 108
     response.sendRedirect("list.html");
107 109
   }
108 110
 
109
-  public void setCargoService(CargoService cargoService) {
111
+  public void setCargoService(final CargoService cargoService) {
110 112
     this.cargoService = cargoService;
111 113
   }
112 114
 
113
-  public void setRoutingService(RoutingService routingService) {
115
+  public void setRoutingService(final RoutingService routingService) {
114 116
     this.routingService = routingService;
115 117
   }
116 118
 

+ 8
- 5
dddsample/src/main/java/se/citerus/dddsample/web/CargoTrackingController.java Просмотреть файл

@@ -16,7 +16,7 @@ import java.util.Map;
16 16
 /**
17 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 22
    * Service instance.
@@ -28,7 +28,9 @@ public class CargoTrackingController extends SimpleFormController {
28 28
   }
29 29
 
30 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 34
     final TrackCommand trackCommand = (TrackCommand) command;
33 35
     final String tidStr = trackCommand.getTrackingId();
34 36
     final CargoTrackingDTO cargo = cargoService.track(new TrackingId(tidStr));
@@ -37,11 +39,12 @@ public class CargoTrackingController extends SimpleFormController {
37 39
     if (cargo != null) {
38 40
       model.put("cargo", cargo);
39 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 45
     return showForm(request, response, errors, model);
43 46
   }
44
-   
47
+
45 48
 
46 49
   /**
47 50
    * Sets the cargo service instance.
@@ -51,5 +54,5 @@ public class CargoTrackingController extends SimpleFormController {
51 54
   public void setCargoService(final CargoService cargoService) {
52 55
     this.cargoService = cargoService;
53 56
   }
54
-  
57
+
55 58
 }

+ 4
- 3
dddsample/src/main/java/se/citerus/dddsample/web/command/RegistrationCommand.java Просмотреть файл

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

+ 16
- 15
dddsample/src/main/java/se/citerus/dddsample/web/command/RoutingCommand.java Просмотреть файл

@@ -3,26 +3,27 @@ package se.citerus.dddsample.web.command;
3 3
 import java.util.ArrayList;
4 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 10
   public List<ItineraryCandidateCommand> getItineraryCandidates() {
10 11
     return itineraryCandidates;
11 12
   }
12 13
 
13
-  public void setItineraryCandidates(List<ItineraryCandidateCommand> itineraryCandidates) {
14
+  public void setItineraryCandidates(final List<ItineraryCandidateCommand> itineraryCandidates) {
14 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 22
     public String getTrackingId() {
22 23
       return trackingId;
23 24
     }
24 25
 
25
-    public void setTrackingId(String trackingId) {
26
+    public void setTrackingId(final String trackingId) {
26 27
       this.trackingId = trackingId;
27 28
     }
28 29
 
@@ -30,21 +31,21 @@ public class RoutingCommand {
30 31
       return legs;
31 32
     }
32 33
 
33
-    public void setLegs(List<LegCommand> legs) {
34
+    public void setLegs(final List<LegCommand> legs) {
34 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 44
     public String getCarrierMovementId() {
44 45
       return carrierMovementId;
45 46
     }
46 47
 
47
-    public void setCarrierMovementId(String carrierMovementId) {
48
+    public void setCarrierMovementId(final String carrierMovementId) {
48 49
       this.carrierMovementId = carrierMovementId;
49 50
     }
50 51
 
@@ -52,7 +53,7 @@ public class RoutingCommand {
52 53
       return fromUnlocode;
53 54
     }
54 55
 
55
-    public void setFromUnlocode(String fromUnlocode) {
56
+    public void setFromUnlocode(final String fromUnlocode) {
56 57
       this.fromUnlocode = fromUnlocode;
57 58
     }
58 59
 
@@ -60,7 +61,7 @@ public class RoutingCommand {
60 61
       return toUnlocode;
61 62
     }
62 63
 
63
-    public void setToUnlocode(String toUnlocode) {
64
+    public void setToUnlocode(final String toUnlocode) {
64 65
       this.toUnlocode = toUnlocode;
65 66
     }
66 67
   }

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/web/command/TrackCommand.java Просмотреть файл

@@ -3,7 +3,7 @@ package se.citerus.dddsample.web.command;
3 3
 import org.apache.commons.lang.builder.ToStringBuilder;
4 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 9
    * The tracking id.

+ 3
- 3
dddsample/src/main/java/se/citerus/dddsample/web/command/TrackCommandValidator.java Просмотреть файл

@@ -7,13 +7,13 @@ import org.springframework.validation.Validator;
7 7
 /**
8 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 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 17
     ValidationUtils.rejectIfEmptyOrWhitespace(errors, "trackingId", "error.required", "Required");
18 18
   }
19 19
 

+ 4
- 5
dddsample/src/main/java/se/citerus/dddsample/ws/HandlingEventServiceEndpoint.java Просмотреть файл

@@ -4,7 +4,6 @@ import javax.jws.WebService;
4 4
 
5 5
 /**
6 6
  * Web service endpoint for handling event registration.
7
- *
8 7
  */
9 8
 @WebService
10 9
 public interface HandlingEventServiceEndpoint {
@@ -12,11 +11,11 @@ public interface HandlingEventServiceEndpoint {
12 11
   /**
13 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 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 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 Просмотреть файл

@@ -21,11 +21,11 @@ import java.util.Date;
21 21
 public class HandlingEventServiceEndpointImpl implements HandlingEventServiceEndpoint {
22 22
 
23 23
   private HandlingEventService handlingEventService;
24
-  private static final Log logger = LogFactory.getLog(HandlingEventServiceEndpointImpl.class);
24
+  private final Log logger = LogFactory.getLog(getClass());
25 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 29
     try {
30 30
       Date date = parseIso8601Date(completionTime);
31 31
       TrackingId tid = new TrackingId(trackingId);
@@ -54,10 +54,10 @@ public class HandlingEventServiceEndpointImpl implements HandlingEventServiceEnd
54 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 58
     try {
59 59
       return HandlingEvent.Type.valueOf(eventType);
60
-    } catch(IllegalArgumentException e) {
60
+    } catch (IllegalArgumentException e) {
61 61
       throw new InvalidEventTypeException(eventType);
62 62
     }
63 63
   }
@@ -67,11 +67,11 @@ public class HandlingEventServiceEndpointImpl implements HandlingEventServiceEnd
67 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 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 75
     this.handlingEventService = handlingEventService;
76 76
   }
77 77
 }

+ 4
- 5
dddsample/src/test/java/se/citerus/dddsample/domain/SampleLocations.java Просмотреть файл

@@ -6,7 +6,6 @@ import java.util.List;
6 6
 
7 7
 /**
8 8
  * A few locations for easy testing.
9
- *
10 9
  */
11 10
 public class SampleLocations {
12 11
 
@@ -23,13 +22,13 @@ public class SampleLocations {
23 22
   public static final Location HANGZOU = new Location(new UnLocode("CNHGH"), "Hangzhou");
24 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 27
   static {
29 28
     for (Field field : SampleLocations.class.getDeclaredFields()) {
30 29
       if (field.getType().equals(Location.class)) {
31 30
         try {
32
-          all.add((Location) field.get(null));
31
+          ALL.add((Location) field.get(null));
33 32
         } catch (IllegalAccessException e) {
34 33
           throw new RuntimeException(e);
35 34
         }
@@ -38,7 +37,7 @@ public class SampleLocations {
38 37
   }
39 38
 
40 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 Просмотреть файл

@@ -17,10 +17,10 @@ import java.util.List;
17 17
 
18 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 25
   protected void setUp() throws Exception {
26 26
     routingService = new RoutingServiceImpl();

+ 24
- 24
dddsample/src/test/java/se/citerus/dddsample/ws/HandlinEventServiceEndpointTest.java Просмотреть файл

@@ -15,9 +15,9 @@ import java.util.Date;
15 15
 
16 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 22
   protected void setUp() throws Exception {
23 23
     endpoint = new HandlingEventServiceEndpointImpl();
@@ -52,38 +52,38 @@ public class HandlinEventServiceEndpointTest extends TestCase {
52 52
   }
53 53
 
54 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 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 89
   protected void tearDown() throws Exception {