Bladeren bron

Removed old tracking web UI

peter_backlund 17 jaren geleden
bovenliggende
commit
fd5869baf2

+ 0
- 74
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/interfaces/tracking/CargoTrackingController.java Bestand weergeven

@@ -1,74 +0,0 @@
1
-package se.citerus.dddsample.tracking.core.interfaces.tracking;
2
-
3
-import org.springframework.context.MessageSource;
4
-import org.springframework.validation.BindException;
5
-import org.springframework.web.servlet.ModelAndView;
6
-import org.springframework.web.servlet.mvc.SimpleFormController;
7
-import org.springframework.web.servlet.support.RequestContextUtils;
8
-import se.citerus.dddsample.tracking.core.domain.model.cargo.Cargo;
9
-import se.citerus.dddsample.tracking.core.domain.model.cargo.CargoRepository;
10
-import se.citerus.dddsample.tracking.core.domain.model.cargo.TrackingId;
11
-import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent;
12
-import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEventRepository;
13
-
14
-import javax.servlet.http.HttpServletRequest;
15
-import javax.servlet.http.HttpServletResponse;
16
-import java.util.HashMap;
17
-import java.util.List;
18
-import java.util.Locale;
19
-import java.util.Map;
20
-
21
-/**
22
- * Controller for tracking cargo. This interface sits immediately on top of the
23
- * domain layer, unlike the booking interface which has a a remote facade and supporting
24
- * DTOs in between.
25
- * <p/>
26
- * An adapter class, designed for the tracking use case, is used to wrap the domain model
27
- * to make it easier to work with in a web page rendering context. We do not want to apply
28
- * view rendering constraints to the design of our domain model, and the adapter
29
- * helps us shield the domain model classes.
30
- * <p/>
31
- *
32
- * @eee se.citerus.dddsample.application.web.CargoTrackingViewAdapter
33
- * @see se.citerus.dddsample.tracking.bookingui.web.CargoAdminController
34
- */
35
-public final class CargoTrackingController extends SimpleFormController {
36
-
37
-  private CargoRepository cargoRepository;
38
-  private HandlingEventRepository handlingEventRepository;
39
-
40
-  public CargoTrackingController() {
41
-    setCommandClass(TrackCommand.class);
42
-  }
43
-
44
-  @Override
45
-  protected ModelAndView onSubmit(final HttpServletRequest request, final HttpServletResponse response,
46
-                                  final Object command, final BindException errors) throws Exception {
47
-
48
-    final TrackCommand trackCommand = (TrackCommand) command;
49
-    final String trackingIdString = trackCommand.getTrackingId();
50
-
51
-    final TrackingId trackingId = new TrackingId(trackingIdString);
52
-    final Cargo cargo = cargoRepository.find(trackingId);
53
-
54
-    final Map<String, CargoTrackingViewAdapter> model = new HashMap<String, CargoTrackingViewAdapter>();
55
-    if (cargo != null) {
56
-      final MessageSource messageSource = getApplicationContext();
57
-      final Locale locale = RequestContextUtils.getLocale(request);
58
-      final List<HandlingEvent> handlingEvents = handlingEventRepository.lookupHandlingHistoryOfCargo(cargo).distinctEventsByCompletionTime();
59
-      model.put("cargo", new CargoTrackingViewAdapter(cargo, messageSource, locale, handlingEvents));
60
-    } else {
61
-      errors.rejectValue("trackingId", "cargo.unknown_id", new Object[]{trackCommand.getTrackingId()}, "Unknown tracking id");
62
-    }
63
-    return showForm(request, response, errors, model);
64
-  }
65
-
66
-  public void setCargoRepository(CargoRepository cargoRepository) {
67
-    this.cargoRepository = cargoRepository;
68
-  }
69
-
70
-  public void setHandlingEventRepository(HandlingEventRepository handlingEventRepository) {
71
-    this.handlingEventRepository = handlingEventRepository;
72
-  }
73
-
74
-}

+ 0
- 231
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/interfaces/tracking/CargoTrackingViewAdapter.java Bestand weergeven

@@ -1,231 +0,0 @@
1
-package se.citerus.dddsample.tracking.core.interfaces.tracking;
2
-
3
-import org.springframework.context.MessageSource;
4
-import se.citerus.dddsample.tracking.core.domain.model.cargo.Cargo;
5
-import se.citerus.dddsample.tracking.core.domain.model.handling.HandlingEvent;
6
-import se.citerus.dddsample.tracking.core.domain.model.location.Location;
7
-import se.citerus.dddsample.tracking.core.domain.model.shared.HandlingActivity;
8
-import se.citerus.dddsample.tracking.core.domain.model.voyage.Voyage;
9
-
10
-import java.text.SimpleDateFormat;
11
-import java.util.*;
12
-
13
-/**
14
- * View adapter for displaying a cargo in a tracking context.
15
- */
16
-public final class CargoTrackingViewAdapter {
17
-
18
-  private final Cargo cargo;
19
-  private final MessageSource messageSource;
20
-  private final Locale locale;
21
-  private final List<HandlingEventViewAdapter> events;
22
-  private final String FORMAT = "yyyy-MM-dd hh:mm z";
23
-
24
-  /**
25
-   * Constructor.
26
-   *
27
-   * @param cargo
28
-   * @param messageSource
29
-   * @param locale
30
-   * @param handlingEvents
31
-   */
32
-  public CargoTrackingViewAdapter(Cargo cargo, MessageSource messageSource, Locale locale, List<HandlingEvent> handlingEvents) {
33
-    this.messageSource = messageSource;
34
-    this.locale = locale;
35
-    this.cargo = cargo;
36
-
37
-    this.events = new ArrayList<HandlingEventViewAdapter>(handlingEvents.size());
38
-    for (HandlingEvent handlingEvent : handlingEvents) {
39
-      events.add(new HandlingEventViewAdapter(handlingEvent));
40
-    }
41
-  }
42
-
43
-  /**
44
-   * @param location a location
45
-   * @return A formatted string for displaying the location.
46
-   */
47
-  private String getDisplayText(Location location) {
48
-    return location.name();
49
-  }
50
-
51
-  /**
52
-   * @return An unmodifiable list of handling event view adapters.
53
-   */
54
-  public List<HandlingEventViewAdapter> getEvents() {
55
-    return Collections.unmodifiableList(events);
56
-  }
57
-
58
-  /**
59
-   * @return A translated string describing the cargo status.
60
-   */
61
-  public String getStatusText() {
62
-    final String code = "cargo.status." + cargo.transportStatus().name();
63
-
64
-    final Object[] args;
65
-    switch (cargo.transportStatus()) {
66
-      case IN_PORT:
67
-        args = new Object[]{getDisplayText(cargo.lastKnownLocation())};
68
-        break;
69
-      case ONBOARD_CARRIER:
70
-        args = new Object[]{cargo.currentVoyage().voyageNumber().stringValue()};
71
-        break;
72
-      case CLAIMED:
73
-      case NOT_RECEIVED:
74
-      case UNKNOWN:
75
-      default:
76
-        args = null;
77
-        break;
78
-    }
79
-
80
-    return messageSource.getMessage(code, args, "[Unknown status]", locale);
81
-  }
82
-
83
-  /**
84
-   * @return Cargo destination location.
85
-   */
86
-  public String getDestination() {
87
-    return getDisplayText(cargo.routeSpecification().destination());
88
-  }
89
-
90
-  /**
91
-   * @return Cargo origin location.
92
-   */
93
-  public String getOrigin() {
94
-    return getDisplayText(cargo.routeSpecification().origin());
95
-  }
96
-
97
-  /**
98
-   * @return Cargo tracking id.
99
-   */
100
-  public String getTrackingId() {
101
-    return cargo.trackingId().stringValue();
102
-  }
103
-
104
-  public String getEta() {
105
-    Date eta = cargo.estimatedTimeOfArrival();
106
-
107
-    if (eta == null) return "?";
108
-    else {
109
-      Location destination = cargo.routeSpecification().destination();
110
-      SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT);
111
-      dateFormat.setTimeZone(destination.timeZone());
112
-      return dateFormat.format(eta);
113
-    }
114
-  }
115
-
116
-  public String getNextExpectedActivity() {
117
-    HandlingActivity activity = cargo.nextExpectedActivity();
118
-    if (activity == null) {
119
-      return "";
120
-    }
121
-
122
-    String text = "Next expected activity is to ";
123
-    HandlingEvent.Type type = activity.type();
124
-    if (type.sameValueAs(HandlingEvent.Type.LOAD)) {
125
-      return
126
-        text + type.name().toLowerCase() + " cargo onto voyage " + activity.voyage().voyageNumber() +
127
-          " in " + activity.location().name();
128
-    } else if (type.sameValueAs(HandlingEvent.Type.UNLOAD)) {
129
-      return
130
-        text + type.name().toLowerCase() + " cargo off of " + activity.voyage().voyageNumber() +
131
-          " in " + activity.location().name();
132
-    } else {
133
-      return text + type.name().toLowerCase() + " cargo in " + activity.location().name();
134
-    }
135
-  }
136
-
137
-  /**
138
-   * @return True if cargo is misdirected.
139
-   */
140
-  public boolean isMisdirected() {
141
-    return cargo.isMisdirected();
142
-  }
143
-
144
-  /**
145
-   * Handling event view adapter component.
146
-   */
147
-  public final class HandlingEventViewAdapter {
148
-
149
-    private final HandlingEvent handlingEvent;
150
-
151
-    /**
152
-     * Constructor.
153
-     *
154
-     * @param handlingEvent handling event
155
-     */
156
-    public HandlingEventViewAdapter(HandlingEvent handlingEvent) {
157
-      this.handlingEvent = handlingEvent;
158
-    }
159
-
160
-    /**
161
-     * @return Location where the event occurred.
162
-     */
163
-    public String getLocation() {
164
-      return handlingEvent.location().name();
165
-    }
166
-
167
-    /**
168
-     * @return Time when the event was completed.
169
-     */
170
-    public String getTime() {
171
-      SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT);
172
-      dateFormat.setTimeZone(handlingEvent.location().timeZone());
173
-
174
-      return dateFormat.format(handlingEvent.completionTime());
175
-    }
176
-
177
-    /**
178
-     * @return Type of event.
179
-     */
180
-    public String getType() {
181
-      return handlingEvent.type().toString();
182
-    }
183
-
184
-    /**
185
-     * @return Voyage number, or empty string if not applicable.
186
-     */
187
-    public String getVoyageNumber() {
188
-      final Voyage voyage = handlingEvent.voyage();
189
-      return voyage.voyageNumber().stringValue();
190
-    }
191
-
192
-    /**
193
-     * @return True if the event was expected, according to the cargo's itinerary.
194
-     */
195
-    public boolean isExpected() {
196
-      return cargo.itinerary().isExpected(handlingEvent.activity());
197
-    }
198
-
199
-    public String getDescription() {
200
-      Object[] args;
201
-
202
-      switch (handlingEvent.type()) {
203
-        case LOAD:
204
-        case UNLOAD:
205
-          args = new Object[]{
206
-            handlingEvent.voyage().voyageNumber().stringValue(),
207
-            handlingEvent.location().name(),
208
-            handlingEvent.completionTime()
209
-          };
210
-          break;
211
-
212
-        case RECEIVE:
213
-        case CLAIM:
214
-          args = new Object[]{
215
-            handlingEvent.location().name(),
216
-            handlingEvent.completionTime()
217
-          };
218
-          break;
219
-
220
-        default:
221
-          args = new Object[]{};
222
-      }
223
-
224
-      String key = "deliveryHistory.eventDescription." + handlingEvent.type().name();
225
-
226
-      return messageSource.getMessage(key, args, locale);
227
-    }
228
-
229
-  }
230
-
231
-}

+ 0
- 25
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/interfaces/tracking/TrackCommand.java Bestand weergeven

@@ -1,25 +0,0 @@
1
-package se.citerus.dddsample.tracking.core.interfaces.tracking;
2
-
3
-import org.apache.commons.lang.builder.ToStringBuilder;
4
-import static org.apache.commons.lang.builder.ToStringStyle.MULTI_LINE_STYLE;
5
-
6
-public final class TrackCommand {
7
-
8
-  /**
9
-   * The tracking id.
10
-   */
11
-  private String trackingId;
12
-
13
-  public String getTrackingId() {
14
-    return trackingId;
15
-  }
16
-
17
-  public void setTrackingId(final String trackingId) {
18
-    this.trackingId = trackingId;
19
-  }
20
-
21
-  @Override
22
-  public String toString() {
23
-    return ToStringBuilder.reflectionToString(this, MULTI_LINE_STYLE);
24
-  }
25
-}

+ 0
- 21
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/interfaces/tracking/TrackCommandValidator.java Bestand weergeven

@@ -1,21 +0,0 @@
1
-package se.citerus.dddsample.tracking.core.interfaces.tracking;
2
-
3
-import org.springframework.validation.Errors;
4
-import org.springframework.validation.ValidationUtils;
5
-import org.springframework.validation.Validator;
6
-
7
-/**
8
- * Validator for {@link TrackCommand}s.
9
- */
10
-public final class TrackCommandValidator implements Validator {
11
-
12
-  public boolean supports(final Class clazz) {
13
-    return TrackCommand.class.isAssignableFrom(clazz);
14
-  }
15
-
16
-  public void validate(final Object object, final Errors errors) {
17
-    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "trackingId", "error.required", "Required");
18
-  }
19
-
20
-}
21
-

+ 0
- 7
dddsample/tracking/core/src/main/java/se/citerus/dddsample/tracking/core/interfaces/tracking/package.html Bestand weergeven

@@ -1,7 +0,0 @@
1
-<html>
2
-<body>
3
-<p>
4
-	Public tracking web interface.
5
-</p>
6
-</body>
7
-</html>