1 package se.citerus.dddsample.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 se.citerus.dddsample.application.ApplicationEvents;
10 import se.citerus.dddsample.domain.model.cargo.TrackingId;
11 import se.citerus.dddsample.domain.model.handling.HandlingEvent;
12 import se.citerus.dddsample.domain.model.location.UnLocode;
13 import se.citerus.dddsample.domain.model.voyage.VoyageNumber;
14 import se.citerus.dddsample.interfaces.handling.HandlingEventRegistrationAttempt;
15 import static se.citerus.dddsample.interfaces.handling.HandlingReportParser.*;
16
17 import javax.jws.WebParam;
18 import javax.jws.WebService;
19 import java.util.ArrayList;
20 import java.util.Date;
21 import java.util.List;
22
23
24
25
26
27
28
29 @WebService(endpointInterface = "com.aggregator.HandlingReportService")
30 public class HandlingReportServiceImpl implements HandlingReportService {
31
32 private ApplicationEvents applicationEvents;
33 private final static Log logger = LogFactory.getLog(HandlingReportServiceImpl.class);
34
35 @Override
36 public void submitReport(@WebParam(name = "arg0", targetNamespace = "") HandlingReport handlingReport) throws HandlingReportErrors_Exception {
37 final List<String> errors = new ArrayList<String>();
38
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);
43
44 for (String trackingIdStr : handlingReport.getTrackingIds()) {
45 final TrackingId trackingId = parseTrackingId(trackingIdStr, errors);
46
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);
54 } else {
55 logger.error("Parse error in handling report: " + errors);
56 final HandlingReportErrors faultInfo = new HandlingReportErrors();
57 throw new HandlingReportErrors_Exception(errors.toString(), faultInfo);
58 }
59 }
60
61 }
62
63 public void setApplicationEvents(ApplicationEvents applicationEvents) {
64 this.applicationEvents = applicationEvents;
65 }
66
67 }