|
|
@@ -5,6 +5,7 @@ import org.apache.commons.lang.builder.EqualsBuilder;
|
|
5
|
5
|
import org.apache.commons.lang.builder.HashCodeBuilder;
|
|
6
|
6
|
import se.citerus.dddsample.domain.model.cargo.Cargo;
|
|
7
|
7
|
import se.citerus.dddsample.domain.model.location.Location;
|
|
|
8
|
+import se.citerus.dddsample.domain.model.shared.HandlingActivity;
|
|
8
|
9
|
import se.citerus.dddsample.domain.model.voyage.Voyage;
|
|
9
|
10
|
import se.citerus.dddsample.domain.shared.DomainEvent;
|
|
10
|
11
|
import se.citerus.dddsample.domain.shared.DomainObjectUtils;
|
|
|
@@ -30,9 +31,7 @@ import java.util.Date;
|
|
30
|
31
|
*/
|
|
31
|
32
|
public final class HandlingEvent implements DomainEvent<HandlingEvent> {
|
|
32
|
33
|
|
|
33
|
|
- private Type type;
|
|
34
|
|
- private Voyage voyage;
|
|
35
|
|
- private Location location;
|
|
|
34
|
+ private HandlingActivity handlingActivity;
|
|
36
|
35
|
private Date completionTime;
|
|
37
|
36
|
private Date registrationTime;
|
|
38
|
37
|
private Cargo cargo;
|
|
|
@@ -105,12 +104,10 @@ public final class HandlingEvent implements DomainEvent<HandlingEvent> {
|
|
105
|
104
|
throw new IllegalArgumentException("Voyage is not allowed with event type " + type);
|
|
106
|
105
|
}
|
|
107
|
106
|
|
|
108
|
|
- this.voyage = voyage;
|
|
109
|
107
|
this.completionTime = (Date) completionTime.clone();
|
|
110
|
108
|
this.registrationTime = (Date) registrationTime.clone();
|
|
111
|
|
- this.type = type;
|
|
112
|
|
- this.location = location;
|
|
113
|
109
|
this.cargo = cargo;
|
|
|
110
|
+ this.handlingActivity = new HandlingActivity(type, location, voyage);
|
|
114
|
111
|
}
|
|
115
|
112
|
|
|
116
|
113
|
/**
|
|
|
@@ -137,18 +134,16 @@ public final class HandlingEvent implements DomainEvent<HandlingEvent> {
|
|
137
|
134
|
|
|
138
|
135
|
this.completionTime = (Date) completionTime.clone();
|
|
139
|
136
|
this.registrationTime = (Date) registrationTime.clone();
|
|
140
|
|
- this.type = type;
|
|
141
|
|
- this.location = location;
|
|
142
|
137
|
this.cargo = cargo;
|
|
143
|
|
- this.voyage = null;
|
|
|
138
|
+ this.handlingActivity = new HandlingActivity(type, location);
|
|
144
|
139
|
}
|
|
145
|
140
|
|
|
146
|
141
|
public Type type() {
|
|
147
|
|
- return this.type;
|
|
|
142
|
+ return handlingActivity.type();
|
|
148
|
143
|
}
|
|
149
|
144
|
|
|
150
|
145
|
public Voyage voyage() {
|
|
151
|
|
- return DomainObjectUtils.nullSafe(this.voyage, Voyage.NONE);
|
|
|
146
|
+ return DomainObjectUtils.nullSafe(handlingActivity.voyage(), Voyage.NONE);
|
|
152
|
147
|
}
|
|
153
|
148
|
|
|
154
|
149
|
public Date completionTime() {
|
|
|
@@ -160,7 +155,7 @@ public final class HandlingEvent implements DomainEvent<HandlingEvent> {
|
|
160
|
155
|
}
|
|
161
|
156
|
|
|
162
|
157
|
public Location location() {
|
|
163
|
|
- return this.location;
|
|
|
158
|
+ return handlingActivity.location();
|
|
164
|
159
|
}
|
|
165
|
160
|
|
|
166
|
161
|
public Cargo cargo() {
|
|
|
@@ -181,10 +176,8 @@ public final class HandlingEvent implements DomainEvent<HandlingEvent> {
|
|
181
|
176
|
public boolean sameEventAs(final HandlingEvent other) {
|
|
182
|
177
|
return other != null && new EqualsBuilder().
|
|
183
|
178
|
append(this.cargo, other.cargo).
|
|
184
|
|
- append(this.voyage, other.voyage).
|
|
185
|
179
|
append(this.completionTime, other.completionTime).
|
|
186
|
|
- append(this.location, other.location).
|
|
187
|
|
- append(this.type, other.type).
|
|
|
180
|
+ append(this.handlingActivity, other.handlingActivity).
|
|
188
|
181
|
isEquals();
|
|
189
|
182
|
}
|
|
190
|
183
|
|
|
|
@@ -192,27 +185,17 @@ public final class HandlingEvent implements DomainEvent<HandlingEvent> {
|
|
192
|
185
|
public int hashCode() {
|
|
193
|
186
|
return new HashCodeBuilder().
|
|
194
|
187
|
append(cargo).
|
|
195
|
|
- append(voyage).
|
|
196
|
188
|
append(completionTime).
|
|
197
|
|
- append(location).
|
|
198
|
|
- append(type).
|
|
|
189
|
+ append(handlingActivity).
|
|
199
|
190
|
toHashCode();
|
|
200
|
191
|
}
|
|
201
|
192
|
|
|
202
|
193
|
@Override
|
|
203
|
194
|
public String toString() {
|
|
204
|
|
- final StringBuilder builder = new StringBuilder("\n--- Handling event ---\n").
|
|
205
|
|
- append("Cargo: ").append(cargo.trackingId()).append("\n").
|
|
206
|
|
- append("Type: ").append(type).append("\n").
|
|
207
|
|
- append("Location: ").append(location.name()).append("\n").
|
|
208
|
|
- append("Completed on: ").append(completionTime).append("\n").
|
|
209
|
|
- append("Registered on: ").append(registrationTime).append("\n");
|
|
210
|
|
-
|
|
211
|
|
- if (voyage != null) {
|
|
212
|
|
- builder.append("Voyage: ").append(voyage.voyageNumber()).append("\n");
|
|
213
|
|
- }
|
|
214
|
|
-
|
|
215
|
|
- return builder.toString();
|
|
|
195
|
+ return "Cargo: " + cargo +
|
|
|
196
|
+ "\nActivity: " + handlingActivity +
|
|
|
197
|
+ "\nCompleted on: " + completionTime +
|
|
|
198
|
+ "\nRegistered on: " + registrationTime;
|
|
216
|
199
|
}
|
|
217
|
200
|
|
|
218
|
201
|
HandlingEvent() {
|