|
|
@@ -1,21 +1,19 @@
|
|
1
|
1
|
package se.citerus.dddsample.web;
|
|
2
|
2
|
|
|
3
|
3
|
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
|
|
4
|
|
-import se.citerus.dddsample.domain.*;
|
|
5
|
|
-import se.citerus.dddsample.repository.CarrierMovementRepository;
|
|
6
|
|
-import se.citerus.dddsample.repository.LocationRepository;
|
|
7
|
|
-import se.citerus.dddsample.service.BookingService;
|
|
8
|
|
-import se.citerus.dddsample.service.RoutingService;
|
|
|
4
|
+import se.citerus.dddsample.service.BookingServiceFacade;
|
|
9
|
5
|
import se.citerus.dddsample.service.dto.CargoRoutingDTO;
|
|
10
|
6
|
import se.citerus.dddsample.service.dto.ItineraryCandidateDTO;
|
|
11
|
7
|
import se.citerus.dddsample.service.dto.LegDTO;
|
|
12
|
|
-import se.citerus.dddsample.service.dto.assembler.CargoRoutingDTOAssembler;
|
|
13
|
|
-import se.citerus.dddsample.service.dto.assembler.ItineraryCandidateDTOAssembler;
|
|
|
8
|
+import se.citerus.dddsample.service.dto.LocationDTO;
|
|
14
|
9
|
import se.citerus.dddsample.web.command.RegistrationCommand;
|
|
15
|
10
|
|
|
16
|
11
|
import javax.servlet.http.HttpServletRequest;
|
|
17
|
12
|
import javax.servlet.http.HttpServletResponse;
|
|
18
|
|
-import java.util.*;
|
|
|
13
|
+import java.util.ArrayList;
|
|
|
14
|
+import java.util.HashMap;
|
|
|
15
|
+import java.util.List;
|
|
|
16
|
+import java.util.Map;
|
|
19
|
17
|
|
|
20
|
18
|
/**
|
|
21
|
19
|
* Handles cargo routing and administration.
|
|
|
@@ -23,21 +21,16 @@ import java.util.*;
|
|
23
|
21
|
*/
|
|
24
|
22
|
public final class CargoAdminController extends MultiActionController {
|
|
25
|
23
|
|
|
26
|
|
- private BookingService bookingService;
|
|
27
|
|
- private RoutingService routingService;
|
|
28
|
|
- private LocationRepository locationRepository;
|
|
29
|
|
- private CarrierMovementRepository carrierMovementRepository;
|
|
30
|
|
-
|
|
31
|
|
- // DTO conversion is pushed out to above the service layer for the time being,
|
|
32
|
|
- // pending a dedicated DTO remoting layer
|
|
|
24
|
+ private BookingServiceFacade bookingServiceFacade;
|
|
33
|
25
|
|
|
34
|
26
|
public Map registrationForm(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
|
|
35
|
27
|
final Map<String, Object> map = new HashMap<String, Object>();
|
|
36
|
|
- final List<UnLocode> unLocodes = bookingService.listShippingLocations();
|
|
|
28
|
+ final List<LocationDTO> dtoList = bookingServiceFacade.listShippingLocations();
|
|
|
29
|
+
|
|
37
|
30
|
final List<String> unLocodeStrings = new ArrayList<String>();
|
|
38
|
31
|
|
|
39
|
|
- for (UnLocode unLocode : unLocodes) {
|
|
40
|
|
- unLocodeStrings.add(unLocode.idString());
|
|
|
32
|
+ for (LocationDTO dto : dtoList) {
|
|
|
33
|
+ unLocodeStrings.add(dto.getUnLocode());
|
|
41
|
34
|
}
|
|
42
|
35
|
|
|
43
|
36
|
map.put("unlocodes", unLocodeStrings);
|
|
|
@@ -47,58 +40,40 @@ public final class CargoAdminController extends MultiActionController {
|
|
47
|
40
|
public void register(final HttpServletRequest request, final HttpServletResponse response,
|
|
48
|
41
|
final RegistrationCommand command) throws Exception {
|
|
49
|
42
|
|
|
50
|
|
- final TrackingId trackingId = bookingService.registerNewCargo(
|
|
51
|
|
- new UnLocode(command.getOriginUnlocode()),
|
|
52
|
|
- new UnLocode(command.getDestinationUnlocode())
|
|
|
43
|
+ final String trackingId = bookingServiceFacade.registerNewCargo(
|
|
|
44
|
+ command.getOriginUnlocode(), command.getDestinationUnlocode()
|
|
53
|
45
|
);
|
|
54
|
|
- response.sendRedirect("show.html?trackingId=" + trackingId.idString());
|
|
|
46
|
+ response.sendRedirect("show.html?trackingId=" + trackingId);
|
|
55
|
47
|
}
|
|
56
|
48
|
|
|
57
|
|
- public Map list(HttpServletRequest request, HttpServletResponse response) {
|
|
|
49
|
+ public Map list(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
58
|
50
|
final Map<String, Object> map = new HashMap<String, Object>();
|
|
59
|
|
- final List<Cargo> allCargos = bookingService.listAllCargos();
|
|
|
51
|
+ final List<CargoRoutingDTO> cargoList = bookingServiceFacade.listAllCargos();
|
|
60
|
52
|
|
|
61
|
|
- final CargoRoutingDTOAssembler assembler = new CargoRoutingDTOAssembler();
|
|
62
|
|
- final List<CargoRoutingDTO> dtoList = new ArrayList<CargoRoutingDTO>(allCargos.size());
|
|
63
|
|
-
|
|
64
|
|
- for (Cargo cargo : allCargos) {
|
|
65
|
|
- dtoList.add(assembler.toDTO(cargo));
|
|
66
|
|
- }
|
|
67
|
|
-
|
|
68
|
|
- map.put("cargoList", dtoList);
|
|
|
53
|
+ map.put("cargoList", cargoList);
|
|
69
|
54
|
return map;
|
|
70
|
55
|
}
|
|
71
|
56
|
|
|
72
|
|
- public Map show(final HttpServletRequest request, final HttpServletResponse response) {
|
|
|
57
|
+ public Map show(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
|
|
73
|
58
|
final Map<String, Object> map = new HashMap<String, Object>();
|
|
74
|
|
- final TrackingId trackingId = new TrackingId(request.getParameter("trackingId"));
|
|
75
|
|
- final Cargo cargo = bookingService.loadCargoForRouting(trackingId);
|
|
76
|
|
- final CargoRoutingDTO dto = new CargoRoutingDTOAssembler().toDTO(cargo);
|
|
|
59
|
+ final String trackingId = request.getParameter("trackingId");
|
|
|
60
|
+ final CargoRoutingDTO dto = bookingServiceFacade.loadCargoForRouting(trackingId);
|
|
77
|
61
|
map.put("cargo", dto);
|
|
78
|
62
|
return map;
|
|
79
|
63
|
}
|
|
80
|
64
|
|
|
81
|
|
- public Map selectItinerary(final HttpServletRequest request, final HttpServletResponse response) {
|
|
|
65
|
+ public Map selectItinerary(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
|
|
82
|
66
|
final Map<String, Object> map = new HashMap<String, Object>();
|
|
83
|
|
- final TrackingId trackingId = new TrackingId(request.getParameter("trackingId"));
|
|
84
|
|
-
|
|
85
|
|
- final Cargo cargo = bookingService.loadCargoForRouting(trackingId);
|
|
86
|
|
- final RouteSpecification routeSpecification = RouteSpecification.forCargo(cargo, new Date());
|
|
87
|
|
- final List<Itinerary> itineraries = routingService.requestPossibleRoutes(routeSpecification);
|
|
88
|
|
-
|
|
89
|
|
- final List<ItineraryCandidateDTO> itineraryCandidates = new ArrayList<ItineraryCandidateDTO>(itineraries.size());
|
|
90
|
|
- final ItineraryCandidateDTOAssembler dtoAssembler = new ItineraryCandidateDTOAssembler();
|
|
91
|
|
- for (Itinerary itinerary : itineraries) {
|
|
92
|
|
- itineraryCandidates.add(dtoAssembler.toDTO(itinerary));
|
|
93
|
|
- }
|
|
|
67
|
+ final String trackingId = request.getParameter("trackingId");
|
|
|
68
|
+ final List<ItineraryCandidateDTO> itineraryCandidates = bookingServiceFacade.requestPossibleRoutesForCargo(trackingId);
|
|
94
|
69
|
|
|
95
|
70
|
map.put("itineraryCandidates", itineraryCandidates);
|
|
96
|
|
- map.put("trackingId", trackingId.idString());
|
|
|
71
|
+ map.put("trackingId", trackingId);
|
|
97
|
72
|
return map;
|
|
98
|
73
|
}
|
|
99
|
74
|
|
|
100
|
75
|
public void assignItinerary(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
|
|
101
|
|
- final TrackingId trackingId = new TrackingId(request.getParameter("trackingId"));
|
|
|
76
|
+ final String trackingId = request.getParameter("trackingId");
|
|
102
|
77
|
|
|
103
|
78
|
// TODO: gah, stuck on indexoutofbounds (legs[0].fromUnlocode etc) when trying to bind...
|
|
104
|
79
|
// Revisit and fix this with a proper command object, this is just hideous
|
|
|
@@ -112,26 +87,13 @@ public final class CargoAdminController extends MultiActionController {
|
|
112
|
87
|
}
|
|
113
|
88
|
|
|
114
|
89
|
final ItineraryCandidateDTO selectedItinerary = new ItineraryCandidateDTO(legDTOs);
|
|
115
|
|
- final Itinerary itinerary = new ItineraryCandidateDTOAssembler().fromDTO(selectedItinerary, carrierMovementRepository, locationRepository);
|
|
116
|
90
|
|
|
117
|
|
- bookingService.assignCargoToRoute(trackingId, itinerary);
|
|
|
91
|
+ bookingServiceFacade.assignCargoToRoute(trackingId, selectedItinerary);
|
|
118
|
92
|
|
|
119
|
93
|
response.sendRedirect("list.html");
|
|
120
|
94
|
}
|
|
121
|
95
|
|
|
122
|
|
- public void setBookingService(final BookingService bookingService) {
|
|
123
|
|
- this.bookingService = bookingService;
|
|
124
|
|
- }
|
|
125
|
|
-
|
|
126
|
|
- public void setRoutingService(final RoutingService routingService) {
|
|
127
|
|
- this.routingService = routingService;
|
|
128
|
|
- }
|
|
129
|
|
-
|
|
130
|
|
- public void setLocationRepository(LocationRepository locationRepository) {
|
|
131
|
|
- this.locationRepository = locationRepository;
|
|
132
|
|
- }
|
|
133
|
|
-
|
|
134
|
|
- public void setCarrierMovementRepository(CarrierMovementRepository carrierMovementRepository) {
|
|
135
|
|
- this.carrierMovementRepository = carrierMovementRepository;
|
|
|
96
|
+ public void setBookingServiceFacade(BookingServiceFacade bookingServiceFacade) {
|
|
|
97
|
+ this.bookingServiceFacade = bookingServiceFacade;
|
|
136
|
98
|
}
|
|
137
|
99
|
}
|