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