Quellcode durchsuchen

"Assign cargo to route" is now a use case with a matching application service method and transaction (was previously directly behind the RMI facade).

Various minor fixes for the JFokus presentation.
peter_backlund vor 17 Jahren
Ursprung
Commit
1a79f4e395
25 geänderte Dateien mit 166 neuen und 100 gelöschten Zeilen
  1. 12
    10
      dddsample/src/main/java/com/partner/pathfinder/internal/GraphDAO.java
  2. 5
    0
      dddsample/src/main/java/se/citerus/dddsample/application/BookingService.java
  3. 8
    0
      dddsample/src/main/java/se/citerus/dddsample/application/HandlingEventRegistrationAttempt.java
  4. 19
    2
      dddsample/src/main/java/se/citerus/dddsample/application/impl/BookingServiceImpl.java
  5. 5
    0
      dddsample/src/main/java/se/citerus/dddsample/application/impl/HandlingEventServiceImpl.java
  6. 2
    0
      dddsample/src/main/java/se/citerus/dddsample/application/impl/TrackingServiceImpl.java
  7. 7
    0
      dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/CannotCreateHandlingEventException.java
  8. 8
    4
      dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactory.java
  9. 26
    17
      dddsample/src/main/java/se/citerus/dddsample/infrastructure/messaging/jms/JmsApplicationEventsImpl.java
  10. 1
    1
      dddsample/src/main/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryHibernate.java
  11. 1
    1
      dddsample/src/main/java/se/citerus/dddsample/infrastructure/routing/ExternalRoutingService.java
  12. 3
    10
      dddsample/src/main/java/se/citerus/dddsample/interfaces/booking/facade/internal/BookingServiceFacadeImpl.java
  13. 6
    6
      dddsample/src/main/java/se/citerus/dddsample/interfaces/booking/web/CargoAdminController.java
  14. 6
    6
      dddsample/src/main/java/se/citerus/dddsample/interfaces/booking/web/RouteAssignmentCommand.java
  15. 11
    0
      dddsample/src/main/java/se/citerus/dddsample/interfaces/handling/HandlingReportParser.java
  16. 13
    9
      dddsample/src/main/java/se/citerus/dddsample/interfaces/handling/ws/HandlingReportErrors.java
  17. 0
    2
      dddsample/src/main/java/se/citerus/dddsample/interfaces/handling/ws/HandlingReportService.java
  18. 1
    1
      dddsample/src/main/java/se/citerus/dddsample/interfaces/handling/ws/impl/HandlingReportServiceImpl.java
  19. 9
    9
      dddsample/src/main/resources/context-infrastructure.xml
  20. 3
    2
      dddsample/src/main/resources/context-interfaces.xml
  21. 1
    1
      dddsample/src/main/resources/se/citerus/dddsample/infrastructure/persistence/hibernate/Cargo.hbm.xml
  22. 1
    1
      dddsample/src/main/webapp/WEB-INF/jsp/admin/registrationForm.jsp
  23. 3
    16
      dddsample/src/main/webapp/WEB-INF/jsp/admin/selectItinerary.jsp
  24. 13
    0
      dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryTest.java
  25. 2
    2
      dddsample/src/test/java/se/citerus/dddsample/interfaces/booking/web/ItinerarySelectionCommandTest.java

+ 12
- 10
dddsample/src/main/java/com/partner/pathfinder/internal/GraphDAO.java Datei anzeigen

@@ -1,23 +1,25 @@
1 1
 package com.partner.pathfinder.internal;
2 2
 
3
+import java.util.ArrayList;
3 4
 import java.util.Arrays;
4 5
 import java.util.List;
5
-import java.util.UUID;
6
+import java.util.Random;
6 7
 
7 8
 public class GraphDAO {
8 9
 
10
+  private static final Random random = new Random();
11
+
9 12
   public List<String> listLocations() {
10
-    return Arrays.asList(
11
-      "CNHKG", "AUMEL", "SESTO", "FIHEL", "USCHI", "JNTKO", "DEHAM",
12
-      "CNSHA", "NLRTM", "SEGOT", "CNHGH", "USNYC", "USDAL"
13
-    );
13
+    return new ArrayList<String>(Arrays.asList(
14
+      "CNHKG", "AUMEL", "SESTO", "FIHEL", "USCHI", "JPTOK", "DEHAM"
15
+    ));
14 16
   }
15 17
 
16 18
   public String getVoyageNumber(String from, String to) {
17
-    // TODO return only those that are in the database
18
-    final String random = UUID.randomUUID().toString().toUpperCase();
19
-    final String cmId =  random.substring(0, 4);
20
-    //dao.storeCarrierMovementId(cmId, from, to);
21
-    return cmId;
19
+    final int i = random.nextInt(3);
20
+    if (i == 0) return "0101";
21
+    if (i == 1) return "0202";
22
+    return "0303";
22 23
   }
24
+  
23 25
 }

+ 5
- 0
dddsample/src/main/java/se/citerus/dddsample/application/BookingService.java Datei anzeigen

@@ -30,4 +30,9 @@ public interface BookingService {
30 30
    */
31 31
   List<Itinerary> requestPossibleRoutesForCargo(TrackingId trackingId);
32 32
 
33
+  /**
34
+   * @param itinerary itinerary describing the selected route
35
+   * @param trackingId tracking id
36
+   */
37
+  void assignCargoToRoute(Itinerary itinerary, TrackingId trackingId);
33 38
 }

+ 8
- 0
dddsample/src/main/java/se/citerus/dddsample/application/HandlingEventRegistrationAttempt.java Datei anzeigen

@@ -1,5 +1,7 @@
1 1
 package se.citerus.dddsample.application;
2 2
 
3
+import org.apache.commons.lang.builder.ToStringBuilder;
4
+import org.apache.commons.lang.builder.ToStringStyle;
3 5
 import se.citerus.dddsample.domain.model.cargo.TrackingId;
4 6
 import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
5 7
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
@@ -61,4 +63,10 @@ public final class HandlingEventRegistrationAttempt implements Serializable {
61 63
   public Date getRegistrationTime() {
62 64
     return registrationTime;
63 65
   }
66
+
67
+  @Override
68
+  public String toString() {
69
+    return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
70
+  }
71
+  
64 72
 }

+ 19
- 2
dddsample/src/main/java/se/citerus/dddsample/application/impl/BookingServiceImpl.java Datei anzeigen

@@ -56,14 +56,31 @@ public final class BookingServiceImpl implements BookingService {
56 56
   @Transactional
57 57
   public List<Itinerary> requestPossibleRoutesForCargo(final TrackingId trackingId) {
58 58
     Validate.notNull(trackingId);
59
-    
59
+
60 60
     final Cargo cargo = cargoRepository.find(trackingId);
61 61
 
62 62
     if (cargo == null) {
63
-      return Collections.EMPTY_LIST;
63
+      return Collections.emptyList();
64 64
     }
65 65
 
66 66
     return routingService.fetchRoutesForSpecification(cargo.routeSpecification());
67 67
   }
68 68
 
69
+  @Override
70
+  @Transactional
71
+  public void assignCargoToRoute(final Itinerary itinerary, final TrackingId trackingId) {
72
+    Validate.notNull(itinerary);
73
+    Validate.notNull(trackingId);
74
+
75
+    final Cargo cargo = cargoRepository.find(trackingId);
76
+    if (cargo == null) {
77
+      throw new IllegalArgumentException("Can't assign itinerary to non-existing cargo " + trackingId);
78
+    }
79
+
80
+    cargo.assignToRoute(itinerary);
81
+    cargoRepository.store(cargo);
82
+
83
+    logger.info("Assigned cargo " + trackingId + " to new route");
84
+  }
85
+  
69 86
 }

+ 5
- 0
dddsample/src/main/java/se/citerus/dddsample/application/impl/HandlingEventServiceImpl.java Datei anzeigen

@@ -1,5 +1,7 @@
1 1
 package se.citerus.dddsample.application.impl;
2 2
 
3
+import org.apache.commons.logging.Log;
4
+import org.apache.commons.logging.LogFactory;
3 5
 import org.springframework.transaction.annotation.Transactional;
4 6
 import se.citerus.dddsample.application.ApplicationEvents;
5 7
 import se.citerus.dddsample.application.HandlingEventRegistrationAttempt;
@@ -14,6 +16,7 @@ public final class HandlingEventServiceImpl implements HandlingEventService {
14 16
   private final ApplicationEvents applicationEvents;
15 17
   private final HandlingEventRepository handlingEventRepository;
16 18
   private final HandlingEventFactory handlingEventFactory;
19
+  private static final Log logger = LogFactory.getLog(HandlingEventServiceImpl.class);
17 20
 
18 21
   public HandlingEventServiceImpl(final HandlingEventRepository handlingEventRepository,
19 22
                                   final ApplicationEvents applicationEvents,
@@ -47,6 +50,8 @@ public final class HandlingEventServiceImpl implements HandlingEventService {
47 50
 
48 51
       /* Publish an event stating that a cargo has been handled. */
49 52
       applicationEvents.cargoWasHandled(event);
53
+
54
+      logger.info("Registered handling event");
50 55
     } catch (CannotCreateHandlingEventException e) {
51 56
       /* This may be a bogus attempt, for example containing a tracking id
52 57
          that doesn't match any cargo that we're tracking. */

+ 2
- 0
dddsample/src/main/java/se/citerus/dddsample/application/impl/TrackingServiceImpl.java Datei anzeigen

@@ -43,6 +43,8 @@ public class TrackingServiceImpl implements TrackingService {
43 43
     final List<HandlingEvent> deliveryHistory = handlingEventRepository.findEventsForCargo(trackingId);
44 44
     cargo.updateStatus(deliveryHistory);
45 45
 
46
+    cargoRepository.store(cargo);
47
+
46 48
     if (cargo.isMisdirected()) {
47 49
       applicationEvents.cargoWasMisdirected(cargo);
48 50
     }

+ 7
- 0
dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/CannotCreateHandlingEventException.java Datei anzeigen

@@ -9,4 +9,11 @@ package se.citerus.dddsample.domain.model.handling;
9 9
  * program execution.
10 10
  */
11 11
 public class CannotCreateHandlingEventException extends Exception {
12
+  public CannotCreateHandlingEventException(Exception e) {
13
+    super(e);
14
+  }
15
+
16
+  public CannotCreateHandlingEventException() {
17
+    super();
18
+  }
12 19
 }

+ 8
- 4
dddsample/src/main/java/se/citerus/dddsample/domain/model/handling/HandlingEventFactory.java Datei anzeigen

@@ -54,10 +54,14 @@ public class HandlingEventFactory {
54 54
     final Voyage voyage = findVoyage(voyageNumber);
55 55
     final Location location = findLocation(unlocode);
56 56
 
57
-    if (voyage == null) {
58
-      return new HandlingEvent(cargo, completionTime, registrationTime, type, location);   
59
-    } else {
60
-      return new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage);
57
+    try {
58
+      if (voyage == null) {
59
+        return new HandlingEvent(cargo, completionTime, registrationTime, type, location);
60
+      } else {
61
+        return new HandlingEvent(cargo, completionTime, registrationTime, type, location, voyage);
62
+      }
63
+    } catch (Exception e) {
64
+      throw new CannotCreateHandlingEventException(e);
61 65
     }
62 66
   }
63 67
 

+ 26
- 17
dddsample/src/main/java/se/citerus/dddsample/infrastructure/messaging/jms/JmsApplicationEventsImpl.java Datei anzeigen

@@ -1,5 +1,7 @@
1 1
 package se.citerus.dddsample.infrastructure.messaging.jms;
2 2
 
3
+import org.apache.commons.logging.Log;
4
+import org.apache.commons.logging.LogFactory;
3 5
 import org.springframework.jms.core.JmsOperations;
4 6
 import org.springframework.jms.core.MessageCreator;
5 7
 import se.citerus.dddsample.application.ApplicationEvents;
@@ -19,16 +21,19 @@ import javax.jms.Session;
19 21
 public final class JmsApplicationEventsImpl implements ApplicationEvents {
20 22
 
21 23
   private JmsOperations jmsOperations;
22
-  private Destination cargoHandledTopic;
23
-  private Destination misdirectedCargoTopic;
24
-  private Destination deliveredCargoTopic;
24
+  private Destination cargoHandledQueue;
25
+  private Destination misdirectedCargoQueue;
26
+  private Destination deliveredCargoQueue;
25 27
   private Destination rejectedRegistrationAttemptsQueue;
26 28
   private Destination handlingEventQueue;
27 29
 
30
+  private static final Log logger = LogFactory.getLog(JmsApplicationEventsImpl.class);
31
+
28 32
   @Override
29 33
   public void cargoWasHandled(final HandlingEvent event) {
30 34
     final Cargo cargo = event.cargo();
31
-    jmsOperations.send(cargoHandledTopic, new MessageCreator() {
35
+    logger.info("Cargo was handled " + cargo);
36
+    jmsOperations.send(cargoHandledQueue, new MessageCreator() {
32 37
       public Message createMessage(final Session session) throws JMSException {
33 38
         return session.createTextMessage(cargo.trackingId().idString());
34 39
       }
@@ -37,7 +42,8 @@ public final class JmsApplicationEventsImpl implements ApplicationEvents {
37 42
 
38 43
   @Override
39 44
   public void cargoWasMisdirected(final Cargo cargo) {
40
-    jmsOperations.send(misdirectedCargoTopic, new MessageCreator() {
45
+    logger.info("Cargo was misdirected " + cargo);
46
+    jmsOperations.send(misdirectedCargoQueue, new MessageCreator() {
41 47
       public Message createMessage(Session session) throws JMSException {
42 48
         return session.createTextMessage(cargo.trackingId().idString());
43 49
       }
@@ -46,7 +52,8 @@ public final class JmsApplicationEventsImpl implements ApplicationEvents {
46 52
 
47 53
   @Override
48 54
   public void cargoHasArrived(final Cargo cargo) {
49
-    jmsOperations.send(deliveredCargoTopic, new MessageCreator() {
55
+    logger.info("Cargo has arrived " + cargo);
56
+    jmsOperations.send(deliveredCargoQueue, new MessageCreator() {
50 57
       public Message createMessage(Session session) throws JMSException {
51 58
         return session.createTextMessage(cargo.trackingId().idString());
52 59
       }
@@ -56,6 +63,7 @@ public final class JmsApplicationEventsImpl implements ApplicationEvents {
56 63
   @Override
57 64
   public void rejectedHandlingEventRegistrationAttempt(final HandlingEventRegistrationAttempt attempt, CannotCreateHandlingEventException problem) {
58 65
     // TODO include error message in JMS message
66
+    logger.info("Rejected handling event registration attempt " + attempt + ", " + problem);
59 67
     jmsOperations.send(rejectedRegistrationAttemptsQueue, new MessageCreator() {
60 68
       public Message createMessage(Session session) throws JMSException {
61 69
         return session.createObjectMessage(attempt);
@@ -65,6 +73,7 @@ public final class JmsApplicationEventsImpl implements ApplicationEvents {
65 73
 
66 74
   @Override
67 75
   public void receivedHandlingEventRegistrationAttempt(final HandlingEventRegistrationAttempt attempt) {
76
+    logger.info("Received handling event registration attempt " + attempt);
68 77
     jmsOperations.send(handlingEventQueue, new MessageCreator() {
69 78
       public Message createMessage(Session session) throws JMSException {
70 79
         return session.createObjectMessage(attempt);
@@ -72,27 +81,27 @@ public final class JmsApplicationEventsImpl implements ApplicationEvents {
72 81
     });
73 82
   }
74 83
 
75
-  public void setJmsOperations(final JmsOperations jmsOperations) {
84
+  public void setJmsOperations(JmsOperations jmsOperations) {
76 85
     this.jmsOperations = jmsOperations;
77 86
   }
78 87
 
79
-  public void setCargoHandledTopic(final Destination cargoHandledTopic) {
80
-    this.cargoHandledTopic = cargoHandledTopic;
88
+  public void setCargoHandledQueue(Destination destination) {
89
+    this.cargoHandledQueue = destination;
81 90
   }
82 91
 
83
-  public void setMisdirectedCargoTopic(Destination misdirectedCargoTopic) {
84
-    this.misdirectedCargoTopic = misdirectedCargoTopic;
92
+  public void setMisdirectedCargoQueue(Destination destination) {
93
+    this.misdirectedCargoQueue = destination;
85 94
   }
86 95
 
87
-  public void setDeliveredCargoTopic(Destination deliveredCargoTopic) {
88
-    this.deliveredCargoTopic = deliveredCargoTopic;
96
+  public void setDeliveredCargoQueue(Destination destination) {
97
+    this.deliveredCargoQueue = destination;
89 98
   }
90 99
 
91
-  public void setRejectedRegistrationAttemptsQueue(Destination rejectedRegistrationAttemptsQueue) {
92
-    this.rejectedRegistrationAttemptsQueue = rejectedRegistrationAttemptsQueue;
100
+  public void setRejectedRegistrationAttemptsQueue(Destination destination) {
101
+    this.rejectedRegistrationAttemptsQueue = destination;
93 102
   }
94 103
 
95
-  public void setHandlingEventQueue(Destination handlingEventQueue) {
96
-    this.handlingEventQueue = handlingEventQueue;
104
+  public void setHandlingEventQueue(Destination destination) {
105
+    this.handlingEventQueue = destination;
97 106
   }
98 107
 }

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryHibernate.java Datei anzeigen

@@ -22,7 +22,7 @@ public class CargoRepositoryHibernate extends HibernateRepository implements Car
22 22
   }
23 23
 
24 24
   public void store(Cargo cargo) {
25
-    getSession().persist(cargo);
25
+    getSession().saveOrUpdate(cargo);
26 26
     getSession().createSQLQuery("delete from Leg where cargo_id = null").executeUpdate();
27 27
   }
28 28
 

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/infrastructure/routing/ExternalRoutingService.java Datei anzeigen

@@ -75,7 +75,7 @@ public class ExternalRoutingService implements RoutingService {
75 75
   }
76 76
 
77 77
   private Itinerary toItinerary(TransitPath transitPath) {
78
-    List<Leg> legs = new ArrayList(transitPath.getTransitEdges().size());
78
+    List<Leg> legs = new ArrayList<Leg>(transitPath.getTransitEdges().size());
79 79
     for (TransitEdge edge : transitPath.getTransitEdges()) {
80 80
       legs.add(toLeg(edge));
81 81
     }

+ 3
- 10
dddsample/src/main/java/se/citerus/dddsample/interfaces/booking/facade/internal/BookingServiceFacadeImpl.java Datei anzeigen

@@ -59,18 +59,11 @@ public class BookingServiceFacadeImpl implements BookingServiceFacade {
59 59
     return assembler.toDTO(cargo);
60 60
   }
61 61
 
62
-  public void assignCargoToRoute(String trackingId, ItineraryCandidateDTO itineraryCandidateDTO) {
62
+  public void assignCargoToRoute(String trackingIdStr, ItineraryCandidateDTO itineraryCandidateDTO) {
63 63
     final Itinerary itinerary = new ItineraryCandidateDTOAssembler().fromDTO(itineraryCandidateDTO, voyageRepository, locationRepository);
64
+    final TrackingId trackingId = new TrackingId(trackingIdStr);
64 65
 
65
-    final Cargo cargo = cargoRepository.find(new TrackingId(trackingId));
66
-    if (cargo == null) {
67
-      throw new IllegalArgumentException("Can't assign itinerary to non-existing cargo " + trackingId);
68
-    }
69
-
70
-    cargo.assignToRoute(itinerary);
71
-    cargoRepository.store(cargo);
72
-
73
-    logger.info("Assigned cargo " + trackingId + " to new route");
66
+    bookingService.assignCargoToRoute(itinerary, trackingId);
74 67
   }
75 68
 
76 69
   public List<CargoRoutingDTO> listAllCargos() {

+ 6
- 6
dddsample/src/main/java/se/citerus/dddsample/interfaces/booking/web/CargoAdminController.java Datei anzeigen

@@ -9,6 +9,7 @@ import se.citerus.dddsample.interfaces.booking.facade.dto.LocationDTO;
9 9
 
10 10
 import javax.servlet.http.HttpServletRequest;
11 11
 import javax.servlet.http.HttpServletResponse;
12
+import java.text.SimpleDateFormat;
12 13
 import java.util.*;
13 14
 
14 15
 /**
@@ -43,9 +44,9 @@ public final class CargoAdminController extends MultiActionController {
43 44
 
44 45
   public void register(final HttpServletRequest request, final HttpServletResponse response,
45 46
                        final RegistrationCommand command) throws Exception {
46
-    // TODO get date from command    
47
+    final Date arrivalDeadline = new SimpleDateFormat("M/dd/yyyy").parse(command.getArrivalDeadline());
47 48
     final String trackingId = bookingServiceFacade.bookNewCargo(
48
-      command.getOriginUnlocode(), command.getDestinationUnlocode(), new Date()
49
+      command.getOriginUnlocode(), command.getDestinationUnlocode(), arrivalDeadline
49 50
     );
50 51
     response.sendRedirect("show.html?trackingId=" + trackingId);
51 52
   }
@@ -70,22 +71,21 @@ public final class CargoAdminController extends MultiActionController {
70 71
     final Map<String, Object> map = new HashMap<String, Object>();
71 72
     final String trackingId = request.getParameter("trackingId");
72 73
     final List<ItineraryCandidateDTO> itineraryCandidates = bookingServiceFacade.requestPossibleRoutesForCargo(trackingId);
74
+    map.put("itineraryCandidates", itineraryCandidates);
73 75
 
74
-    if (request.getParameter("spec") != null) {
75
-      map.put("itineraryCandidates", itineraryCandidates);
76
-    }
77 76
 
78 77
     final CargoRoutingDTO cargoDTO = bookingServiceFacade.loadCargoForRouting(trackingId);
79 78
     map.put("origin", cargoDTO.getOrigin());
80 79
     map.put("destination", cargoDTO.getFinalDestination());
81 80
     map.put("trackingId", trackingId);
81
+    
82 82
     return map;
83 83
   }
84 84
 
85 85
   public void assignItinerary(final HttpServletRequest request, final HttpServletResponse response, RouteAssignmentCommand command) throws Exception {
86 86
     final List<LegDTO> legDTOs = new ArrayList<LegDTO>(command.getLegs().size());
87 87
     for (RouteAssignmentCommand.LegCommand leg : command.getLegs()) {
88
-      legDTOs.add(new LegDTO(leg.getCarrierMovementId(), leg.getFromUnLocode(), leg.getToUnLocode()));
88
+      legDTOs.add(new LegDTO(leg.getVoyageNumber(), leg.getFromUnLocode(), leg.getToUnLocode()));
89 89
     }
90 90
 
91 91
     final ItineraryCandidateDTO selectedItinerary = new ItineraryCandidateDTO(legDTOs);

+ 6
- 6
dddsample/src/main/java/se/citerus/dddsample/interfaces/booking/web/RouteAssignmentCommand.java Datei anzeigen

@@ -30,16 +30,16 @@ public class RouteAssignmentCommand {
30 30
   }
31 31
 
32 32
   public static final class LegCommand {
33
-    private String carrierMovementId;
33
+    private String voyageNumber;
34 34
     private String fromUnLocode;
35 35
     private String toUnLocode;
36 36
 
37
-    public String getCarrierMovementId() {
38
-      return carrierMovementId;
37
+    public String getVoyageNumber() {
38
+      return voyageNumber;
39 39
     }
40 40
 
41
-    public void setCarrierMovementId(final String carrierMovementId) {
42
-      this.carrierMovementId = carrierMovementId;
41
+    public void setVoyageNumber(final String voyageNumber) {
42
+      this.voyageNumber = voyageNumber;
43 43
     }
44 44
 
45 45
     public String getFromUnLocode() {
@@ -65,6 +65,6 @@ public class RouteAssignmentCommand {
65 65
         }
66 66
       };
67 67
     }
68
-    
68
+
69 69
   }
70 70
 }

+ 11
- 0
dddsample/src/main/java/se/citerus/dddsample/interfaces/handling/HandlingReportParser.java Datei anzeigen

@@ -5,7 +5,9 @@ import se.citerus.dddsample.domain.model.cargo.TrackingId;
5 5
 import se.citerus.dddsample.domain.model.carrier.VoyageNumber;
6 6
 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
7 7
 import se.citerus.dddsample.domain.model.location.UnLocode;
8
+import se.citerus.dddsample.interfaces.handling.ws.HandlingReport;
8 9
 
10
+import javax.xml.datatype.XMLGregorianCalendar;
9 11
 import java.text.ParseException;
10 12
 import java.text.SimpleDateFormat;
11 13
 import java.util.Arrays;
@@ -73,4 +75,13 @@ public class HandlingReportParser {
73 75
     }
74 76
   }
75 77
 
78
+  public static Date parseCompletionTime(HandlingReport handlingReport, List<String> errors) {
79
+    final XMLGregorianCalendar completionTime = handlingReport.getCompletionTime();
80
+    if (completionTime == null) {
81
+      errors.add("Completion time is required");
82
+      return null;
83
+    }
84
+
85
+    return completionTime.toGregorianCalendar().getTime();
86
+  }
76 87
 }

+ 13
- 9
dddsample/src/main/java/se/citerus/dddsample/interfaces/handling/ws/HandlingReportErrors.java Datei anzeigen

@@ -1,34 +1,38 @@
1 1
 package se.citerus.dddsample.interfaces.handling.ws;
2 2
 
3 3
 import javax.xml.bind.annotation.XmlElement;
4
-import java.util.Arrays;
4
+import javax.xml.bind.annotation.XmlRootElement;
5
+import java.util.ArrayList;
5 6
 import java.util.List;
6 7
 
8
+@XmlRootElement
7 9
 public class HandlingReportErrors extends Exception {
8 10
 
9
-  private String[] errors;
11
+  @XmlElement
12
+  List<String> errors;
10 13
 
11 14
   public HandlingReportErrors() {
12 15
   }
13 16
 
14
-  public HandlingReportErrors(final List<String> errors) {
15
-    this.errors = errors.toArray(new String[errors.size()]);
17
+  public HandlingReportErrors(List<String> errors) {
18
+    setErrors(errors);
16 19
   }
17 20
 
18
-  @XmlElement(required = true)
19
-  public String[] getErrors() {
21
+  public List<String> getErrors() {
20 22
     return errors;
21 23
   }
22 24
 
23
-  public void setErrors(String[] errors) {
25
+  public void setErrors(List<String> errors) {
26
+    if (errors == null) {
27
+      errors = new ArrayList<String>();
28
+    }
24 29
     this.errors = errors;
25 30
   }
26 31
 
27
-
28 32
   @Override
29 33
   @XmlElement(required = true)
30 34
   public String getMessage() {
31
-    return "Reistration failure: " + Arrays.toString(errors);
35
+    return "Report errors: " + errors;
32 36
   }
33 37
   
34 38
 }

+ 0
- 2
dddsample/src/main/java/se/citerus/dddsample/interfaces/handling/ws/HandlingReportService.java Datei anzeigen

@@ -1,6 +1,5 @@
1 1
 package se.citerus.dddsample.interfaces.handling.ws;
2 2
 
3
-import javax.jws.WebMethod;
4 3
 import javax.jws.WebParam;
5 4
 import javax.jws.WebService;
6 5
 
@@ -21,7 +20,6 @@ public interface HandlingReportService {
21 20
    * @param handlingReport handling report
22 21
    * @throws HandlingReportErrors if there are formatting errors in the handling report
23 22
    */
24
-  @WebMethod
25 23
   void submitReport(@WebParam HandlingReport handlingReport) throws HandlingReportErrors;
26 24
 
27 25
 }

+ 1
- 1
dddsample/src/main/java/se/citerus/dddsample/interfaces/handling/ws/impl/HandlingReportServiceImpl.java Datei anzeigen

@@ -34,7 +34,7 @@ public class HandlingReportServiceImpl implements HandlingReportService {
34 34
   public void submitReport(HandlingReport handlingReport) throws HandlingReportErrors {
35 35
     final List<String> errors = new ArrayList<String>();
36 36
 
37
-    final Date completionTime = handlingReport.getCompletionTime().toGregorianCalendar().getTime();
37
+    final Date completionTime = parseCompletionTime(handlingReport, errors);
38 38
     final VoyageNumber voyageNumber = parseVoyageNumber(handlingReport.getVoyageNumber(), errors);
39 39
     final HandlingEvent.Type type = parseEventType(handlingReport.getType(), errors);
40 40
     final UnLocode unLocode = parseUnLocode(handlingReport.getUnLocode(), errors);

+ 9
- 9
dddsample/src/main/resources/context-infrastructure.xml Datei anzeigen

@@ -15,17 +15,17 @@
15 15
 
16 16
   <amq:connectionFactory id="jmsConnectionFactory" brokerURL="vm://localhost?broker.persistent=false&amp;broker.useJmx=false"/>
17 17
 
18
-  <amq:topic id="cargoHandledTopic" name="CargoHandledTopic" physicalName="CargoHandledTopic"/>
19
-  <amq:topic id="misdirectedCargoTopic" name="MisdirectedCargoTopic" physicalName="MisdirectedCargoTopic"/>
20
-  <amq:topic id="deliveredCargoTopic" name="DeliveredCargoTopic" physicalName="DeliveredCargoTopic"/>
18
+  <amq:queue id="cargoHandledQueue" name="CargoHandledQueue" physicalName="CargoHandledQueue"/>
19
+  <amq:queue id="misdirectedCargoQueue" name="MisdirectedCargoQueue" physicalName="MisdirectedCargoQueue"/>
20
+  <amq:queue id="deliveredCargoQueue" name="DeliveredCargoQueue" physicalName="DeliveredCargoQueue"/>
21 21
   <amq:queue id="handlingEventRegistrationAttemptQueue" name="HandlingEventRegistrationAttemptQueue" physicalName="HandlingEventRegistrationAttemptQueue"/>
22 22
   <amq:queue id="rejectedRegistrationAttemptsQueue" name="RejectedRegistrationAttemptsQueue" physicalName="RejectedRegistrationAttemptsQueue"/>
23 23
 
24 24
   <jms:listener-container connection-factory="jmsConnectionFactory">
25
-    <jms:listener destination="CargoHandledTopic" ref="cargoHandledConsumer" />
25
+    <jms:listener destination="CargoHandledQueue" ref="cargoHandledConsumer" />
26 26
     <jms:listener destination="HandlingEventRegistrationAttemptQueue" ref="handlingEventRegistrationAttemptConsumer" />
27
-    <jms:listener destination="MisdirectedCargoTopic" ref="simpleLoggingConsumer"/>
28
-    <jms:listener destination="DeliveredCargoTopic" ref="simpleLoggingConsumer"/>
27
+    <jms:listener destination="MisdirectedCargoQueue" ref="simpleLoggingConsumer"/>
28
+    <jms:listener destination="DeliveredCargoQueue" ref="simpleLoggingConsumer"/>
29 29
     <jms:listener destination="RejectedRegistrationAttemptsQueue" ref="simpleLoggingConsumer"/>
30 30
   </jms:listener-container>
31 31
 
@@ -35,9 +35,9 @@
35 35
 
36 36
   <bean id="applicationEvents" class="se.citerus.dddsample.infrastructure.messaging.jms.JmsApplicationEventsImpl">
37 37
     <property name="jmsOperations" ref="jmsOperations"/>
38
-    <property name="cargoHandledTopic" ref="cargoHandledTopic"/>
39
-    <property name="misdirectedCargoTopic" ref="misdirectedCargoTopic"/>
40
-    <property name="deliveredCargoTopic" ref="deliveredCargoTopic"/>
38
+    <property name="cargoHandledQueue" ref="cargoHandledQueue"/>
39
+    <property name="misdirectedCargoQueue" ref="misdirectedCargoQueue"/>
40
+    <property name="deliveredCargoQueue" ref="deliveredCargoQueue"/>
41 41
     <property name="rejectedRegistrationAttemptsQueue" ref="rejectedRegistrationAttemptsQueue"/>
42 42
     <property name="handlingEventQueue" ref="handlingEventRegistrationAttemptQueue"/>
43 43
   </bean>

+ 3
- 2
dddsample/src/main/resources/context-interfaces.xml Datei anzeigen

@@ -7,14 +7,15 @@
7 7
                            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
8 8
 
9 9
   <import resource="classpath:META-INF/cxf/cxf.xml"/>
10
-  <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
11 10
   <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
11
+  <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>
12
+  <import resource="classpath:META-INF/cxf/cxf-extension-jaxws.xml"/>
12 13
 
13 14
 
14 15
   <!-- Handling report web service -->
15 16
 
16 17
 
17
-  <jaxws:endpoint id="jax-ws.http" implementor="#handlingReportService" address="/ws/RegisterEvent"/>
18
+  <jaxws:endpoint id="jax-ws.http" implementor="#handlingReportService" address="/RegisterEvent"/>
18 19
 
19 20
   <bean id="handlingReportService" class="se.citerus.dddsample.interfaces.handling.ws.impl.HandlingReportServiceImpl">
20 21
     <property name="applicationEvents" ref="applicationEvents"/>

+ 1
- 1
dddsample/src/main/resources/se/citerus/dddsample/infrastructure/persistence/hibernate/Cargo.hbm.xml Datei anzeigen

@@ -26,7 +26,7 @@
26 26
       <property name="id" column="tracking_id"/>
27 27
     </component>
28 28
 
29
-    <component name="delivery" lazy="true" update="false">
29
+    <component name="delivery" lazy="true">
30 30
       <property name="transportStatus" column="transport_status" not-null="true">
31 31
         <type name="org.hibernate.type.EnumType">
32 32
           <param name="enumClass">se.citerus.dddsample.domain.model.cargo.TransportStatus</param>

+ 1
- 1
dddsample/src/main/webapp/WEB-INF/jsp/admin/registrationForm.jsp Datei anzeigen

@@ -43,7 +43,7 @@
43 43
         <tr>
44 44
           <td>Arrival deadline:</td>
45 45
           <td>
46
-            <input name="spec" type="text" size="10" id="cal1" value="${param.spec}"/>&nbsp;
46
+            <input name="arrivalDeadline" type="text" size="10" id="cal1" value="${param.arrivalDeadline}"/>&nbsp;
47 47
             <img alt="" src="<c:url value="/images/calendarTrigger.gif"/>" class="calendarTrigger" onclick="calendar.toggle( event, this, 'cal1')"/>
48 48
           </td>
49 49
         </tr>

+ 3
- 16
dddsample/src/main/webapp/WEB-INF/jsp/admin/selectItinerary.jsp Datei anzeigen

@@ -11,7 +11,6 @@
11 11
 </head>
12 12
 <body>
13 13
 <div id="container">
14
-  <form action="selectItinerary.html" method="GET">
15 14
   <table>
16 15
     <caption>Select route for cargo ${trackingId}</caption>
17 16
     <tr>
@@ -22,19 +21,7 @@
22 21
       <td><strong>Destination:</strong></td>
23 22
       <td>${destination}</td>
24 23
     </tr>
25
-    <tr>
26
-      <td><strong>Arrival deadline:</strong></td>
27
-      <td>
28
-        <input name="spec" type="text" size="10" id="cal1" value="${param.spec}"/>&nbsp;
29
-        <img alt="" src="<c:url value="/images/calendarTrigger.gif"/>" class="calendarTrigger" onclick="calendar.toggle( event, this, 'cal1')"/>
30
-      </td>
31
-    </tr>
32 24
   </table>
33
-    <p>
34
-      <input type="hidden" name="trackingId" value="${trackingId}"/>
35
-      <input type="submit" value="Find routes"/>
36
-    </p>
37
-  </form>
38 25
   <c:url value="/admin/assignItinerary.html" var="postUrl"/>
39 26
 
40 27
   <c:forEach items="${itineraryCandidates}" var="it" varStatus="itStatus">
@@ -44,18 +31,18 @@
44 31
           <caption>Route ${itStatus.index + 1}</caption>
45 32
           <thead>
46 33
             <tr>
47
-              <td>Carrier Movement</td>
34
+              <td>Voyage</td>
48 35
               <td>From</td>
49 36
               <td>To</td>
50 37
             </tr>
51 38
           </thead>
52 39
           <tbody>
53 40
             <c:forEach items="${it.legs}" var="leg" varStatus="legStatus">
54
-              <input type="hidden" name="legs[${legStatus.index}].carrierMovementId" value="${leg.carrierMovementId}"/>
41
+              <input type="hidden" name="legs[${legStatus.index}].voyageNumber" value="${leg.voyageNumber}"/>
55 42
               <input type="hidden" name="legs[${legStatus.index}].fromUnLocode" value="${leg.from}"/>
56 43
               <input type="hidden" name="legs[${legStatus.index}].toUnLocode" value="${leg.to}"/>
57 44
               <tr>
58
-                <td>${leg.carrierMovementId}</td>
45
+                <td>${leg.voyageNumber}</td>
59 46
                 <td>${leg.from}</td>
60 47
                 <td>${leg.to}</td>
61 48
               </tr>

+ 13
- 0
dddsample/src/test/java/se/citerus/dddsample/infrastructure/persistence/hibernate/CargoRepositoryTest.java Datei anzeigen

@@ -114,6 +114,14 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
114 114
     Cargo cargo = new Cargo(trackingId, origin, new RouteSpecification(origin, destination, new Date()));
115 115
     cargoRepository.store(cargo);
116 116
 
117
+    cargo.assignToRoute(new Itinerary(Arrays.asList(
118
+      new Leg(
119
+        voyageRepository.find(new VoyageNumber("0101")),
120
+        locationRepository.find(STOCKHOLM.unLocode()),
121
+        locationRepository.find(MELBOURNE.unLocode()),
122
+        new Date(), new Date())
123
+    )));
124
+    
117 125
     flush();
118 126
 
119 127
     Map<String, Object> map = sjt.queryForMap(
@@ -126,6 +134,11 @@ public class CargoRepositoryTest extends AbstractRepositoryTest {
126 134
 
127 135
     Long destinationId = getLongId(destination);
128 136
     assertEquals(destinationId, map.get("SPEC_DESTINATION_ID"));
137
+
138
+    getSession().clear();
139
+
140
+    final Cargo loadedCargo = cargoRepository.find(trackingId);
141
+    assertEquals(1, loadedCargo.itinerary().legs().size());
129 142
   }
130 143
 
131 144
   public void testReplaceItinerary() {

+ 2
- 2
dddsample/src/test/java/se/citerus/dddsample/interfaces/booking/web/ItinerarySelectionCommandTest.java Datei anzeigen

@@ -32,12 +32,12 @@ public class ItinerarySelectionCommandTest extends TestCase {
32 32
     assertEquals(2, legs.size());
33 33
 
34 34
     RouteAssignmentCommand.LegCommand leg = legs.get(0);
35
-    assertEquals("CM01", leg.getCarrierMovementId());
35
+    assertEquals("CM01", leg.getVoyageNumber());
36 36
     assertEquals("AAAAA", leg.getFromUnLocode());
37 37
     assertEquals("BBBBB", leg.getToUnLocode());
38 38
 
39 39
     leg = legs.get(1);
40
-    assertEquals("CM02", leg.getCarrierMovementId());
40
+    assertEquals("CM02", leg.getVoyageNumber());
41 41
     assertEquals("CCCCC", leg.getFromUnLocode());
42 42
     assertEquals("DDDDD", leg.getToUnLocode());
43 43