|
|
@@ -6,62 +6,72 @@ import com.aggregator.HandlingReportErrors_Exception;
|
|
6
|
6
|
import com.aggregator.HandlingReportService;
|
|
7
|
7
|
import org.apache.commons.logging.Log;
|
|
8
|
8
|
import org.apache.commons.logging.LogFactory;
|
|
9
|
|
-import se.citerus.dddsample.application.ApplicationEvents;
|
|
|
9
|
+import se.citerus.dddsample.application.HandlingEventService;
|
|
10
|
10
|
import se.citerus.dddsample.domain.model.cargo.TrackingId;
|
|
|
11
|
+import se.citerus.dddsample.domain.model.handling.CannotCreateHandlingEventException;
|
|
11
|
12
|
import se.citerus.dddsample.domain.model.handling.HandlingEvent;
|
|
12
|
13
|
import se.citerus.dddsample.domain.model.location.UnLocode;
|
|
13
|
14
|
import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
|
|
14
|
|
-import se.citerus.dddsample.interfaces.handling.HandlingEventRegistrationAttempt;
|
|
15
|
15
|
import static se.citerus.dddsample.interfaces.handling.HandlingReportParser.*;
|
|
16
|
16
|
|
|
17
|
17
|
import javax.jws.WebParam;
|
|
18
|
18
|
import javax.jws.WebService;
|
|
19
|
|
-import java.util.ArrayList;
|
|
20
|
|
-import java.util.Date;
|
|
21
|
|
-import java.util.List;
|
|
|
19
|
+import java.util.*;
|
|
22
|
20
|
|
|
23
|
21
|
/**
|
|
24
|
22
|
* This web service endpoint implementation performs basic validation and parsing
|
|
25
|
|
- * of incoming data, and in case of a valid registration attempt, sends an asynchronous message
|
|
26
|
|
- * with the informtion to the handling event registration system for proper registration.
|
|
27
|
|
- *
|
|
|
23
|
+ * of an incoming handling report, and attempts to register proper handling events
|
|
|
24
|
+ * by calling the application layer.
|
|
28
|
25
|
*/
|
|
29
|
26
|
@WebService(endpointInterface = "com.aggregator.HandlingReportService")
|
|
30
|
27
|
public class HandlingReportServiceImpl implements HandlingReportService {
|
|
31
|
28
|
|
|
32
|
|
- private ApplicationEvents applicationEvents;
|
|
|
29
|
+ private HandlingEventService handlingEventService;
|
|
33
|
30
|
private final static Log logger = LogFactory.getLog(HandlingReportServiceImpl.class);
|
|
34
|
31
|
|
|
35
|
32
|
@Override
|
|
36
|
33
|
public void submitReport(@WebParam(name = "arg0", targetNamespace = "") HandlingReport handlingReport) throws HandlingReportErrors_Exception {
|
|
37
|
|
- final List<String> errors = new ArrayList<String>();
|
|
|
34
|
+ final List<String> validationErrors = new ArrayList<String>();
|
|
38
|
35
|
|
|
39
|
|
- final Date completionTime = parseCompletionTime(handlingReport, errors);
|
|
40
|
|
- final VoyageNumber voyageNumber = parseVoyageNumber(handlingReport.getVoyageNumber(), errors);
|
|
41
|
|
- final HandlingEvent.Type type = parseEventType(handlingReport.getType(), errors);
|
|
42
|
|
- final UnLocode unLocode = parseUnLocode(handlingReport.getUnLocode(), errors);
|
|
|
36
|
+ final Date completionTime = parseCompletionTime(handlingReport, validationErrors);
|
|
|
37
|
+ final VoyageNumber voyageNumber = parseVoyageNumber(handlingReport.getVoyageNumber(), validationErrors);
|
|
|
38
|
+ final HandlingEvent.Type type = parseEventType(handlingReport.getType(), validationErrors);
|
|
|
39
|
+ final UnLocode unLocode = parseUnLocode(handlingReport.getUnLocode(), validationErrors);
|
|
43
|
40
|
|
|
|
41
|
+ final Map<String,String> allErrors = new HashMap<String, String>();
|
|
44
|
42
|
for (String trackingIdStr : handlingReport.getTrackingIds()) {
|
|
45
|
|
- final TrackingId trackingId = parseTrackingId(trackingIdStr, errors);
|
|
|
43
|
+ final TrackingId trackingId = parseTrackingId(trackingIdStr, validationErrors);
|
|
46
|
44
|
|
|
47
|
|
- if (errors.isEmpty()) {
|
|
48
|
|
- final Date registrationTime = new Date();
|
|
49
|
|
- final HandlingEventRegistrationAttempt attempt = new HandlingEventRegistrationAttempt(
|
|
50
|
|
- registrationTime, completionTime, trackingId, voyageNumber, type, unLocode
|
|
51
|
|
- );
|
|
52
|
|
-
|
|
53
|
|
- applicationEvents.receivedHandlingEventRegistrationAttempt(attempt);
|
|
|
45
|
+ if (validationErrors.isEmpty()) {
|
|
|
46
|
+ try {
|
|
|
47
|
+ handlingEventService.registerHandlingEvent(completionTime, trackingId, voyageNumber, unLocode, type);
|
|
|
48
|
+ } catch (CannotCreateHandlingEventException e) {
|
|
|
49
|
+ logger.error(e, e);
|
|
|
50
|
+ allErrors.put(trackingIdStr, e.getMessage());
|
|
|
51
|
+ }
|
|
54
|
52
|
} else {
|
|
55
|
|
- logger.error("Parse error in handling report: " + errors);
|
|
56
|
|
- final HandlingReportErrors faultInfo = new HandlingReportErrors();
|
|
57
|
|
- throw new HandlingReportErrors_Exception(errors.toString(), faultInfo);
|
|
|
53
|
+ logger.error("Parse error in handling report: " + validationErrors);
|
|
|
54
|
+ allErrors.put(trackingIdStr, validationErrors.toString());
|
|
58
|
55
|
}
|
|
59
|
56
|
}
|
|
60
|
57
|
|
|
|
58
|
+ if (!allErrors.isEmpty()) {
|
|
|
59
|
+ final HandlingReportErrors faultInfo = new HandlingReportErrors();
|
|
|
60
|
+ throw new HandlingReportErrors_Exception(createErrorMessage(allErrors), faultInfo);
|
|
|
61
|
+ }
|
|
|
62
|
+ }
|
|
|
63
|
+
|
|
|
64
|
+ private String createErrorMessage(final Map<String, String> allErrors) {
|
|
|
65
|
+ final StringBuilder sb = new StringBuilder("--- BEGIN HANDLING REPORT ERRORS ---\n");
|
|
|
66
|
+ for (Map.Entry<String, String> e : allErrors.entrySet()) {
|
|
|
67
|
+ sb.append(e.getKey()).append(" : ").append(e.getValue()).append("\n");
|
|
|
68
|
+ }
|
|
|
69
|
+ sb.append("--- END HANDLING REPORT ERRORS ---");
|
|
|
70
|
+ return sb.toString();
|
|
61
|
71
|
}
|
|
62
|
72
|
|
|
63
|
|
- public void setApplicationEvents(ApplicationEvents applicationEvents) {
|
|
64
|
|
- this.applicationEvents = applicationEvents;
|
|
|
73
|
+ public void setHandlingEventService(final HandlingEventService handlingEventService) {
|
|
|
74
|
+ this.handlingEventService = handlingEventService;
|
|
65
|
75
|
}
|
|
66
|
76
|
|
|
67
|
77
|
}
|