|
|
@@ -1,9 +1,12 @@
|
|
1
|
1
|
package se.citerus.dddsample.interfaces.tracking;
|
|
2
|
2
|
|
|
3
|
3
|
import org.springframework.context.MessageSource;
|
|
|
4
|
+import org.springframework.stereotype.Controller;
|
|
4
|
5
|
import org.springframework.validation.BindException;
|
|
5
|
|
-import org.springframework.web.servlet.ModelAndView;
|
|
6
|
|
-import org.springframework.web.servlet.mvc.SimpleFormController;
|
|
|
6
|
+import org.springframework.validation.BindingResult;
|
|
|
7
|
+import org.springframework.validation.Errors;
|
|
|
8
|
+import org.springframework.web.bind.WebDataBinder;
|
|
|
9
|
+import org.springframework.web.bind.annotation.*;
|
|
7
|
10
|
import org.springframework.web.servlet.support.RequestContextUtils;
|
|
8
|
11
|
import se.citerus.dddsample.domain.model.cargo.Cargo;
|
|
9
|
12
|
import se.citerus.dddsample.domain.model.cargo.CargoRepository;
|
|
|
@@ -12,7 +15,6 @@ import se.citerus.dddsample.domain.model.handling.HandlingEvent;
|
|
12
|
15
|
import se.citerus.dddsample.domain.model.handling.HandlingEventRepository;
|
|
13
|
16
|
|
|
14
|
17
|
import javax.servlet.http.HttpServletRequest;
|
|
15
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
16
|
18
|
import java.util.HashMap;
|
|
17
|
19
|
import java.util.List;
|
|
18
|
20
|
import java.util.Locale;
|
|
|
@@ -33,35 +35,36 @@ import java.util.Map;
|
|
33
|
35
|
* @see se.citerus.dddsample.interfaces.booking.web.CargoAdminController
|
|
34
|
36
|
*
|
|
35
|
37
|
*/
|
|
36
|
|
-public final class CargoTrackingController extends SimpleFormController {
|
|
|
38
|
+@Controller
|
|
|
39
|
+public final class CargoTrackingController {
|
|
37
|
40
|
|
|
38
|
41
|
private CargoRepository cargoRepository;
|
|
39
|
42
|
private HandlingEventRepository handlingEventRepository;
|
|
|
43
|
+ private MessageSource messageSource;
|
|
40
|
44
|
|
|
41
|
|
- public CargoTrackingController() {
|
|
42
|
|
- setCommandClass(TrackCommand.class);
|
|
|
45
|
+ @RequestMapping(method = RequestMethod.GET)
|
|
|
46
|
+ public Map<String, CargoTrackingViewAdapter> get(final TrackCommand trackCommand) {
|
|
|
47
|
+ return new HashMap<>();
|
|
43
|
48
|
}
|
|
44
|
49
|
|
|
45
|
|
- @Override
|
|
46
|
|
- protected ModelAndView onSubmit(final HttpServletRequest request, final HttpServletResponse response,
|
|
47
|
|
- final Object command, final BindException errors) throws Exception {
|
|
|
50
|
+ @RequestMapping(method = RequestMethod.POST)
|
|
|
51
|
+ protected Map<String, CargoTrackingViewAdapter> onSubmit(final HttpServletRequest request,
|
|
|
52
|
+ final TrackCommand command,
|
|
|
53
|
+ final BindingResult bindingResult) {
|
|
|
54
|
+ new TrackCommandValidator().validate(command, bindingResult);
|
|
48
|
55
|
|
|
49
|
|
- final TrackCommand trackCommand = (TrackCommand) command;
|
|
50
|
|
- final String trackingIdString = trackCommand.getTrackingId();
|
|
51
|
|
-
|
|
52
|
|
- final TrackingId trackingId = new TrackingId(trackingIdString);
|
|
|
56
|
+ final TrackingId trackingId = new TrackingId(command.getTrackingId());
|
|
53
|
57
|
final Cargo cargo = cargoRepository.find(trackingId);
|
|
54
|
58
|
|
|
55
|
59
|
final Map<String, CargoTrackingViewAdapter> model = new HashMap<String, CargoTrackingViewAdapter>();
|
|
56
|
60
|
if (cargo != null) {
|
|
57
|
|
- final MessageSource messageSource = getApplicationContext();
|
|
58
|
61
|
final Locale locale = RequestContextUtils.getLocale(request);
|
|
59
|
62
|
final List<HandlingEvent> handlingEvents = handlingEventRepository.lookupHandlingHistoryOfCargo(trackingId).distinctEventsByCompletionTime();
|
|
60
|
63
|
model.put("cargo", new CargoTrackingViewAdapter(cargo, messageSource, locale, handlingEvents));
|
|
61
|
64
|
} else {
|
|
62
|
|
- errors.rejectValue("trackingId", "cargo.unknown_id", new Object[]{trackCommand.getTrackingId()}, "Unknown tracking id");
|
|
|
65
|
+ bindingResult.rejectValue("trackingId", "cargo.unknown_id", new Object[]{command.getTrackingId()}, "Unknown tracking id");
|
|
63
|
66
|
}
|
|
64
|
|
- return showForm(request, response, errors, model);
|
|
|
67
|
+ return model;
|
|
65
|
68
|
}
|
|
66
|
69
|
|
|
67
|
70
|
public void setCargoRepository(CargoRepository cargoRepository) {
|
|
|
@@ -72,4 +75,8 @@ public final class CargoTrackingController extends SimpleFormController {
|
|
72
|
75
|
this.handlingEventRepository = handlingEventRepository;
|
|
73
|
76
|
}
|
|
74
|
77
|
|
|
|
78
|
+ public void setMessageSource(MessageSource messageSource) {
|
|
|
79
|
+ this.messageSource = messageSource;
|
|
|
80
|
+ }
|
|
|
81
|
+
|
|
75
|
82
|
}
|