Skip to content

Commit 2e4661a

Browse files
committed
Lots of minor fixes to booking ui, added interface for reporting voyage delay (only stubbed at the backend right now), using jQuery instead of YUI.
1 parent 1f65afe commit 2e4661a

File tree

52 files changed

+5474
-665
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+5474
-665
lines changed

dddsample/tracking/booking-api/src/main/java/se/citerus/dddsample/tracking/booking/api/BookingServiceFacade.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ public interface BookingServiceFacade extends Remote {
2525

2626
List<CargoRoutingDTO> listAllCargos() throws RemoteException;
2727

28+
List<VoyageDTO> listAllVoyages() throws RemoteException;
29+
30+
void departureDelayed(VoyageDelayDTO delay) throws RemoteException;
31+
32+
void arrivalDelayed(VoyageDelayDTO delay) throws RemoteException;
33+
2834
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package se.citerus.dddsample.tracking.booking.api;
2+
3+
import java.io.Serializable;
4+
5+
public class CarrierMovementDTO implements Serializable {
6+
7+
private final LocationDTO departureLocation;
8+
private final LocationDTO arrivalLocation;
9+
10+
public CarrierMovementDTO(LocationDTO departureLocation, LocationDTO arrivalLocation) {
11+
this.departureLocation = departureLocation;
12+
this.arrivalLocation = arrivalLocation;
13+
}
14+
15+
public LocationDTO getDepartureLocation() {
16+
return departureLocation;
17+
}
18+
19+
public LocationDTO getArrivalLocation() {
20+
return arrivalLocation;
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package se.citerus.dddsample.tracking.booking.api;
2+
3+
import java.io.Serializable;
4+
import java.util.List;
5+
6+
public class VoyageDTO implements Serializable {
7+
private final String voyageNumber;
8+
private final List<CarrierMovementDTO> movements;
9+
10+
public VoyageDTO(String voyageNumber, List<CarrierMovementDTO> movements) {
11+
this.voyageNumber = voyageNumber;
12+
this.movements = movements;
13+
}
14+
15+
public String getVoyageNumber() {
16+
return voyageNumber;
17+
}
18+
19+
public List<CarrierMovementDTO> getMovements() {
20+
return movements;
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package se.citerus.dddsample.tracking.booking.api;
2+
3+
import java.io.Serializable;
4+
5+
public class VoyageDelayDTO implements Serializable {
6+
7+
private final String voyageNumber;
8+
private final int minutesOfDelay;
9+
10+
public VoyageDelayDTO(String voyageNumber, int minutesOfDelay) {
11+
this.voyageNumber = voyageNumber;
12+
this.minutesOfDelay = minutesOfDelay;
13+
}
14+
15+
public String getVoyageNumber() {
16+
return voyageNumber;
17+
}
18+
19+
public int getMinutesOfDelay() {
20+
return minutesOfDelay;
21+
}
22+
}

dddsample/tracking/bookingui/src/main/java/se/citerus/dddsample/tracking/bookingui/web/BookingDispatcherServlet.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

dddsample/tracking/bookingui/src/main/java/se/citerus/dddsample/tracking/bookingui/web/CargoAdminController.java

Lines changed: 84 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package se.citerus.dddsample.tracking.bookingui.web;
22

3+
import org.codehaus.jettison.AbstractXMLStreamWriter;
4+
import org.codehaus.jettison.mapped.MappedNamespaceConvention;
5+
import org.codehaus.jettison.mapped.MappedXMLStreamWriter;
36
import org.springframework.beans.propertyeditors.CustomDateEditor;
47
import org.springframework.web.bind.ServletRequestDataBinder;
58
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
69
import se.citerus.dddsample.tracking.booking.api.*;
710

811
import javax.servlet.http.HttpServletRequest;
912
import javax.servlet.http.HttpServletResponse;
13+
import javax.xml.stream.XMLStreamException;
14+
import java.io.StringWriter;
1015
import java.text.SimpleDateFormat;
1116
import java.util.*;
1217

@@ -19,35 +24,35 @@
1924
* this approach is generally preferred to the one taken in the tracking controller. However,
2025
* there is never any one perfect solution for all situations, so we've chosen to demonstrate
2126
* two polarized ways to build user interfaces.
22-
*
2327
*/
2428
public final class CargoAdminController extends MultiActionController {
2529

2630
private BookingServiceFacade bookingServiceFacade;
31+
private static final CustomDateEditor DATE_EDITOR = new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm"), false);
32+
private static final UnLocodeComparator UN_LOCODE_COMPARATOR = new UnLocodeComparator();
33+
34+
public CargoAdminController(BookingServiceFacade bookingServiceFacade) {
35+
this.bookingServiceFacade = bookingServiceFacade;
36+
}
2737

2838
@Override
2939
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
3040
super.initBinder(request, binder);
31-
binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd HH:mm"), false));
41+
binder.registerCustomEditor(Date.class, DATE_EDITOR);
3242
}
3343

34-
public Map registrationForm(HttpServletRequest request, HttpServletResponse response) throws Exception {
44+
public Map cargoBookingForm(HttpServletRequest request, HttpServletResponse response) throws Exception {
3545
Map<String, Object> map = new HashMap<String, Object>();
36-
List<LocationDTO> dtoList = bookingServiceFacade.listShippingLocations();
3746

38-
List<String> unLocodeStrings = new ArrayList<String>();
39-
40-
for (LocationDTO dto : dtoList) {
41-
unLocodeStrings.add(dto.getUnLocode());
42-
}
43-
44-
map.put("unlocodes", unLocodeStrings);
47+
List<LocationDTO> dtoList = bookingServiceFacade.listShippingLocations();
48+
Collections.sort(dtoList, UN_LOCODE_COMPARATOR);
49+
4550
map.put("locations", dtoList);
4651
return map;
4752
}
4853

49-
public void register(HttpServletRequest request, HttpServletResponse response,
50-
RegistrationCommand command) throws Exception {
54+
public void bookCargo(HttpServletRequest request, HttpServletResponse response,
55+
CargoBookingCommand command) throws Exception {
5156
Date arrivalDeadline = new SimpleDateFormat("M/dd/yyyy").parse(command.getArrivalDeadline());
5257
String trackingId = bookingServiceFacade.bookNewCargo(
5358
command.getOriginUnlocode(), command.getDestinationUnlocode(), arrivalDeadline
@@ -101,7 +106,6 @@ public void assignItinerary(HttpServletRequest request, HttpServletResponse resp
101106
bookingServiceFacade.assignCargoToRoute(command.getTrackingId(), selectedRoute);
102107

103108
response.sendRedirect("show.html?trackingId=" + command.getTrackingId());
104-
//response.sendRedirect("list.html");
105109
}
106110

107111
public Map pickNewDestination(HttpServletRequest request, HttpServletResponse response) throws Exception {
@@ -124,7 +128,71 @@ public void changeDestination(HttpServletRequest request, HttpServletResponse re
124128
response.sendRedirect("show.html?trackingId=" + trackingId);
125129
}
126130

127-
public void setBookingServiceFacade(BookingServiceFacade bookingServiceFacade) {
128-
this.bookingServiceFacade = bookingServiceFacade;
131+
public Map voyageDelayedForm(HttpServletRequest request, HttpServletResponse response) throws Exception {
132+
Map<String, List<String>> departures = new HashMap<String, List<String>>();
133+
Map<String, List<String>> arrivals = new HashMap<String, List<String>>();
134+
135+
List<VoyageDTO> voyages = bookingServiceFacade.listAllVoyages();
136+
137+
for (VoyageDTO voyage : voyages) {
138+
List<String> departureLocations = getLocationsList(departures, voyage);
139+
List<String> arrivalLocations = getLocationsList(arrivals, voyage);
140+
for (CarrierMovementDTO dto : voyage.getMovements()) {
141+
departureLocations.add(dto.getDepartureLocation().getUnLocode());
142+
arrivalLocations.add(dto.getArrivalLocation().getUnLocode());
143+
}
144+
}
145+
146+
Map<String, Object> model = new HashMap<String, Object>();
147+
148+
model.put("departures", toJSON(departures));
149+
model.put("arrivals", toJSON(arrivals));
150+
model.put("voyages", voyages);
151+
152+
return model;
153+
}
154+
155+
public void voyageDelayed(HttpServletRequest request, HttpServletResponse response, VoyageDelayCommand command) throws Exception {
156+
if (command.getType() == VoyageDelayCommand.DelayType.DEPT) {
157+
bookingServiceFacade.departureDelayed(new VoyageDelayDTO(command.getVoyageNumber(), command.getHours() * 60));
158+
} else if (command.getType() == VoyageDelayCommand.DelayType.ARR) {
159+
bookingServiceFacade.arrivalDelayed(new VoyageDelayDTO(command.getVoyageNumber(), command.getHours() * 60));
160+
}
161+
162+
response.sendRedirect("list.html");
163+
}
164+
165+
private String toJSON(Map<String, List<String>> locationMap) throws XMLStreamException {
166+
StringWriter stringWriter = new StringWriter();
167+
MappedNamespaceConvention con = new MappedNamespaceConvention();
168+
AbstractXMLStreamWriter w = new MappedXMLStreamWriter(con, stringWriter);
169+
170+
w.writeStartDocument();
171+
for (Map.Entry<String, List<String>> e : locationMap.entrySet()) {
172+
for (String location : e.getValue()) {
173+
w.writeStartElement(e.getKey());
174+
w.writeCharacters(location);
175+
w.writeEndElement();
176+
}
177+
}
178+
w.writeEndDocument();
179+
180+
return stringWriter.toString();
181+
}
182+
183+
private List<String> getLocationsList(Map<String, List<String>> map, VoyageDTO voyage) {
184+
List<String> locations = map.get(voyage.getVoyageNumber());
185+
if (locations == null) {
186+
locations = new ArrayList<String>();
187+
map.put(voyage.getVoyageNumber(), locations);
188+
}
189+
return locations;
190+
}
191+
192+
private static class UnLocodeComparator implements Comparator<LocationDTO> {
193+
@Override
194+
public int compare(LocationDTO o1, LocationDTO o2) {
195+
return o1.getUnLocode().compareTo(o2.getUnLocode());
196+
}
129197
}
130198
}
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package se.citerus.dddsample.tracking.bookingui.web;
22

3-
/**
4-
*
5-
*/
6-
public final class RegistrationCommand {
3+
public final class CargoBookingCommand {
74

85
private String originUnlocode;
96
private String destinationUnlocode;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package se.citerus.dddsample.tracking.bookingui.web;
2+
3+
public class VoyageDelayCommand {
4+
5+
private DelayType type;
6+
private String voyageNumber;
7+
private int hours;
8+
9+
public DelayType getType() {
10+
return type;
11+
}
12+
13+
public String getVoyageNumber() {
14+
return voyageNumber;
15+
}
16+
17+
public int getHours() {
18+
return hours;
19+
}
20+
21+
public static enum DelayType {
22+
DEPT, ARR
23+
}
24+
}

dddsample/tracking/bookingui/src/main/resources/context-backend.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
55

66
<bean id="remoteBookingService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
7+
<property name="lookupStubOnStartup" value="false"/>
78
<property name="serviceUrl" value="rmi://localhost:1099/BookingService"/>
89
<property name="serviceInterface" value="se.citerus.dddsample.tracking.booking.api.BookingServiceFacade"/>
910
</bean>

dddsample/tracking/bookingui/src/main/webapp/WEB-INF/booking-servlet.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@
55

66
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
77
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
8-
<property name="prefix" value="/WEB-INF/jsp/admin/"/>
8+
<property name="prefix" value="/WEB-INF/jsp/"/>
99
<property name="suffix" value=".jsp"/>
1010
<property name="requestContextAttribute" value="rc"/>
1111
<property name="cache" value="false"/>
1212
</bean>
1313

14+
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
15+
<property name="exceptionMappings">
16+
<map>
17+
<entry key="java.rmi.RemoteException" value="backend_error"/>
18+
<entry key="org.springframework.remoting.RemoteAccessException" value="backend_error"/>
19+
</map>
20+
</property>
21+
</bean>
22+
1423
<bean name="/*" class="se.citerus.dddsample.tracking.bookingui.web.CargoAdminController">
15-
<property name="bookingServiceFacade" ref="remoteBookingService"/>
24+
<constructor-arg ref="remoteBookingService"/>
1625
</bean>
1726

1827
</beans>

0 commit comments

Comments
 (0)