peter_backlund 17 anos atrás
pai
commit
edd8f64628

+ 0
- 140
dddsample/external/reporting/src/main/java/com.reporting/CargoReport.java Ver arquivo

@@ -1,140 +0,0 @@
1
-package com.reporting;
2
-
3
-import javax.xml.bind.annotation.XmlRootElement;
4
-import java.util.Date;
5
-import java.util.List;
6
-
7
-@XmlRootElement(name = "cargo")
8
-public class CargoReport {
9
-
10
-  String trackingId;
11
-  String receivedIn;
12
-  String finalDestination;
13
-  String arrivalDeadline;
14
-  String eta;
15
-  String currentStatus;
16
-  String currentVoyage;
17
-  String currentLocation;
18
-  String lastUpdatedOn;
19
-  List<Handling> handlings;
20
-
21
-  public String getTrackingId() {
22
-    return trackingId;
23
-  }
24
-
25
-  public void setTrackingId(String trackingId) {
26
-    this.trackingId = trackingId;
27
-  }
28
-
29
-  public String getReceivedIn() {
30
-    return receivedIn;
31
-  }
32
-
33
-  public void setReceivedIn(String receivedIn) {
34
-    this.receivedIn = receivedIn;
35
-  }
36
-
37
-  public String getFinalDestination() {
38
-    return finalDestination;
39
-  }
40
-
41
-  public void setFinalDestination(String finalDestination) {
42
-    this.finalDestination = finalDestination;
43
-  }
44
-
45
-  public String getArrivalDeadline() {
46
-    return arrivalDeadline;
47
-  }
48
-
49
-  public void setArrivalDeadline(String arrivalDeadline) {
50
-    this.arrivalDeadline = arrivalDeadline;
51
-  }
52
-
53
-  public String getEta() {
54
-    return eta;
55
-  }
56
-
57
-  public void setEta(String eta) {
58
-    this.eta = eta;
59
-  }
60
-
61
-  public String getCurrentStatus() {
62
-    return currentStatus;
63
-  }
64
-
65
-  public void setCurrentStatus(String currentStatus) {
66
-    this.currentStatus = currentStatus;
67
-  }
68
-
69
-  public String getCurrentVoyage() {
70
-    return currentVoyage;
71
-  }
72
-
73
-  public void setCurrentVoyage(String currentVoyage) {
74
-    this.currentVoyage = currentVoyage;
75
-  }
76
-
77
-  public String getCurrentLocation() {
78
-    return currentLocation;
79
-  }
80
-
81
-  public void setCurrentLocation(String currentLocation) {
82
-    this.currentLocation = currentLocation;
83
-  }
84
-
85
-  public List<Handling> getHandlings() {
86
-    return handlings;
87
-  }
88
-
89
-  public void setHandlings(List<Handling> handlings) {
90
-    this.handlings = handlings;
91
-  }
92
-
93
-  public String getLastUpdatedOn() {
94
-    return lastUpdatedOn;
95
-  }
96
-
97
-  public void setLastUpdatedOn(String lastUpdatedOn) {
98
-    this.lastUpdatedOn = lastUpdatedOn;
99
-  }
100
-
101
-  public static class Handling {
102
-    String type;
103
-    String location;
104
-    String voyage;
105
-    String completedOn;
106
-
107
-    public String getType() {
108
-      return type;
109
-    }
110
-
111
-    public void setType(String type) {
112
-      this.type = type;
113
-    }
114
-
115
-    public String getLocation() {
116
-      return location;
117
-    }
118
-
119
-    public void setLocation(String location) {
120
-      this.location = location;
121
-    }
122
-
123
-    public String getVoyage() {
124
-      return voyage;
125
-    }
126
-
127
-    public void setVoyage(String voyage) {
128
-      this.voyage = voyage;
129
-    }
130
-
131
-    public String getCompletedOn() {
132
-      return completedOn;
133
-    }
134
-
135
-    public void setCompletedOn(String completedOn) {
136
-      this.completedOn = completedOn;
137
-    }
138
-  }
139
-
140
-}

+ 0
- 27
dddsample/external/reporting/src/main/java/com.reporting/CargoReportRowMapper.java Ver arquivo

@@ -1,27 +0,0 @@
1
-package com.reporting;
2
-
3
-import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
4
-
5
-import java.sql.ResultSet;
6
-import java.sql.SQLException;
7
-
8
-import static com.reporting.Constants.*;
9
-
10
-class CargoReportRowMapper implements ParameterizedRowMapper<CargoReport> {
11
-
12
-  @Override
13
-  public CargoReport mapRow(ResultSet rs, int rowNum) throws SQLException {
14
-    CargoReport cargoReport = new CargoReport();
15
-    cargoReport.setTrackingId(rs.getString("cargo_tracking_id"));
16
-    cargoReport.setArrivalDeadline(US_DATETIME.format(rs.getTimestamp("arrival_deadline")));
17
-    cargoReport.setCurrentLocation(rs.getString("current_location"));
18
-    cargoReport.setCurrentStatus(rs.getString("current_status"));
19
-    cargoReport.setCurrentVoyage(rs.getString("current_voyage_number"));
20
-    cargoReport.setEta(US_DATETIME.format(rs.getTimestamp("eta")));
21
-    cargoReport.setFinalDestination(rs.getString("destination"));
22
-    cargoReport.setLastUpdatedOn(US_DATETIME.format(rs.getTimestamp("last_updated_on")));
23
-    cargoReport.setReceivedIn(rs.getString("received_in"));
24
-    return cargoReport;
25
-  }
26
-
27
-}

+ 0
- 10
dddsample/external/reporting/src/main/java/com.reporting/Constants.java Ver arquivo

@@ -1,10 +0,0 @@
1
-package com.reporting;
2
-
3
-import java.text.DateFormat;
4
-import java.util.Locale;
5
-
6
-public interface Constants {
7
-
8
-  DateFormat US_DATETIME = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, Locale.US);
9
-
10
-}

+ 0
- 22
dddsample/external/reporting/src/main/java/com.reporting/HandlingRowMapper.java Ver arquivo

@@ -1,22 +0,0 @@
1
-package com.reporting;
2
-
3
-import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
4
-
5
-import java.sql.ResultSet;
6
-import java.sql.SQLException;
7
-
8
-import static com.reporting.Constants.*;
9
-
10
-class HandlingRowMapper implements ParameterizedRowMapper<CargoReport.Handling> {
11
-
12
-  @Override
13
-  public CargoReport.Handling mapRow(ResultSet rs, int rowNum) throws SQLException {
14
-    CargoReport.Handling handling = new CargoReport.Handling();
15
-    handling.setCompletedOn(US_DATETIME.format(rs.getTimestamp("completed_on")));
16
-    handling.setLocation(rs.getString("location"));
17
-    handling.setType(rs.getString("type"));
18
-    handling.setVoyage(rs.getString("voyage_number"));
19
-    return handling;
20
-  }
21
-
22
-}

+ 0
- 43
dddsample/external/reporting/src/main/java/com.reporting/PDFCargoReportProvider.java Ver arquivo

@@ -1,43 +0,0 @@
1
-package com.reporting;
2
-
3
-import com.lowagie.text.*;
4
-import com.lowagie.text.pdf.PdfPTable;
5
-import static com.lowagie.text.FontFactory.*;
6
-
7
-import javax.ws.rs.ext.Provider;
8
-import javax.ws.rs.Produces;
9
-
10
-@Produces("application/pdf")
11
-@Provider
12
-public class PDFCargoReportProvider extends PDFMessageBodyWriter<CargoReport> {
13
-
14
-  @Override
15
-  protected Class<CargoReport> getSupportedClass() {
16
-    return CargoReport.class;
17
-  }
18
-
19
-  @Override
20
-  protected void buildDocument(CargoReport cargoReport, Document document) {
21
-    try {
22
-      document.add(new Paragraph("Cargo " + cargoReport.getTrackingId(), getFont(HELVETICA_BOLD, 18.0f)));
23
-      document.add(new Paragraph("Status: " + cargoReport.getCurrentStatus()));
24
-      document.add(new Paragraph("Location: " + cargoReport.getCurrentLocation()));
25
-      document.add(new Paragraph("Voyage: " + cargoReport.getCurrentVoyage()));
26
-      document.add(new Paragraph("Destination: " + cargoReport.getFinalDestination()));
27
-      document.add(new Paragraph("Arrival deadline: " + cargoReport.getArrivalDeadline()));
28
-      document.add(new Paragraph("ETA: " + cargoReport.getEta()));
29
-
30
-      document.add(new Paragraph("Handling history", getFont(HELVETICA_BOLD)));
31
-      PdfPTable table = new PdfPTable(4);
32
-      for (CargoReport.Handling handling : cargoReport.getHandlings()) {
33
-        table.addCell(handling.getType());
34
-        table.addCell(handling.getLocation());
35
-        table.addCell(handling.getVoyage());
36
-        table.addCell(handling.getCompletedOn());
37
-      }
38
-    } catch (DocumentException e) {
39
-      throw new RuntimeException(e);
40
-    }
41
-  }
42
-
43
-}

+ 0
- 48
dddsample/external/reporting/src/main/java/com.reporting/PDFMessageBodyWriter.java Ver arquivo

@@ -1,48 +0,0 @@
1
-package com.reporting;
2
-
3
-import com.lowagie.text.Document;
4
-import com.lowagie.text.DocumentException;
5
-import com.lowagie.text.pdf.PdfWriter;
6
-
7
-import javax.ws.rs.ext.MessageBodyWriter;
8
-import javax.ws.rs.core.MediaType;
9
-import javax.ws.rs.core.MultivaluedMap;
10
-import java.lang.reflect.Type;
11
-import java.lang.annotation.Annotation;
12
-import java.io.ByteArrayOutputStream;
13
-import java.io.OutputStream;
14
-import java.io.IOException;
15
-
16
-public abstract class PDFMessageBodyWriter<T> implements MessageBodyWriter<T> {
17
-
18
-  public long getSize(T t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
19
-    ByteArrayOutputStream baos = new ByteArrayOutputStream();
20
-    writeDocumentToStream(t, baos);
21
-    return baos.toByteArray().length;
22
-  }
23
-
24
-  public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mt) {
25
-    return getSupportedClass().isAssignableFrom(type);
26
-  }
27
-
28
-  public void writeTo(T t, Class<?> clazz, Type type, Annotation[] a, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException {
29
-    writeDocumentToStream(t, os);
30
-  }
31
-
32
-  protected void writeDocumentToStream(T t, OutputStream os) {
33
-    Document document = new Document();
34
-    try {
35
-      PdfWriter.getInstance(document, os);
36
-    } catch (DocumentException e) {
37
-      throw new RuntimeException(e);
38
-    }
39
-    document.open();
40
-    buildDocument(t, document);
41
-    document.close();
42
-  }
43
-
44
-  protected abstract void buildDocument(T t, Document document);
45
-
46
-  protected abstract Class<T> getSupportedClass();
47
-
48
-}

+ 0
- 28
dddsample/external/reporting/src/main/java/com.reporting/PDFVoyageReportProvider.java Ver arquivo

@@ -1,28 +0,0 @@
1
-package com.reporting;
2
-
3
-import com.lowagie.text.Document;
4
-import com.lowagie.text.DocumentException;
5
-import com.lowagie.text.Paragraph;
6
-
7
-import javax.ws.rs.Produces;
8
-import javax.ws.rs.ext.Provider;
9
-
10
-@Produces("application/pdf")
11
-@Provider
12
-public class PDFVoyageReportProvider extends PDFMessageBodyWriter<VoyageReport> {
13
-
14
-  @Override
15
-  protected Class<VoyageReport> getSupportedClass() {
16
-    return VoyageReport.class;
17
-  }
18
-
19
-  @Override
20
-  protected void buildDocument(VoyageReport voyageReport, Document document) {
21
-    try {
22
-      document.add(new Paragraph("Voyage " + voyageReport.getVoyageNumber()));
23
-    } catch (DocumentException e) {
24
-      throw new RuntimeException(e);
25
-    }
26
-  }
27
-
28
-}

+ 0
- 129
dddsample/external/reporting/src/main/java/com.reporting/ReportingService.java Ver arquivo

@@ -1,129 +0,0 @@
1
-package com.reporting;
2
-
3
-import static com.reporting.Constants.US_DATETIME;
4
-import org.springframework.dao.EmptyResultDataAccessException;
5
-import org.springframework.jdbc.core.JdbcTemplate;
6
-import org.springframework.jdbc.core.RowCallbackHandler;
7
-import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
8
-import org.springframework.transaction.annotation.Transactional;
9
-
10
-import javax.sql.DataSource;
11
-import javax.ws.rs.GET;
12
-import javax.ws.rs.Path;
13
-import javax.ws.rs.PathParam;
14
-import javax.ws.rs.Produces;
15
-import javax.ws.rs.core.Response;
16
-import java.sql.ResultSet;
17
-import java.sql.SQLException;
18
-import java.text.ParseException;
19
-import java.util.ArrayList;
20
-import java.util.List;
21
-
22
-@Produces({"application/json", "application/pdf"})
23
-@Path("/report")
24
-public class ReportingService {
25
-
26
-  private JdbcTemplate jdbc;
27
-  private HandlingRowMapper handlingRowMapper;
28
-  private CargoReportRowMapper cargoReportRowMapper;
29
-  private VoyageReportRowMapper rowMapper;
30
-
31
-  public ReportingService(DataSource dataSource) {
32
-    this.jdbc = new JdbcTemplate(dataSource);
33
-    this.handlingRowMapper = new HandlingRowMapper();
34
-    this.cargoReportRowMapper = new CargoReportRowMapper();
35
-    this.rowMapper = new VoyageReportRowMapper();
36
-  }
37
-
38
-  @GET
39
-  @Path("/cargo/{trackingId}")
40
-  @Transactional
41
-  public Response getCargoReport(@PathParam("trackingId") String trackingId) throws ParseException {
42
-    CargoReport cargoReport = loadCargoReport(trackingId);
43
-    if (cargoReport == null) return null;
44
-
45
-    cargoReport.setHandlings(loadHandlings(trackingId));
46
-
47
-    return Response.ok(cargoReport).
48
-      lastModified(US_DATETIME.parse(cargoReport.getLastUpdatedOn())).
49
-      build();
50
-  }
51
-
52
-  @GET
53
-  @Path("/voyage/{voyageNumber}")
54
-  @Transactional
55
-  public Response getVoyageReport(@PathParam("voyageNumber") String voyageNumber) throws ParseException {
56
-    VoyageReport voyageReport = loadVoyageReport(voyageNumber);
57
-    if (voyageReport == null) return null;
58
-
59
-    voyageReport.setOnboardCargos(loadOnboardCargos(voyageNumber));
60
-
61
-    return Response.ok(voyageReport).
62
-      lastModified(US_DATETIME.parse(voyageReport.getLastUpdatedOn())).
63
-      build();
64
-  }
65
-
66
-  // --- Private methods ---
67
-
68
-  private CargoReport loadCargoReport(String trackingId) {
69
-    try {
70
-      String[] args = {trackingId};
71
-      String sql = "select * from cargo where cargo_tracking_id = ?";
72
-      return (CargoReport) jdbc.queryForObject(sql, args, cargoReportRowMapper);
73
-    } catch (EmptyResultDataAccessException e) {
74
-      return null;
75
-    }
76
-  }
77
-
78
-  private List<CargoReport.Handling> loadHandlings(String trackingId) {
79
-    final List<CargoReport.Handling> handlings = new ArrayList<CargoReport.Handling>();
80
-    RowCallbackHandler handler = new RowCallbackHandler() {
81
-      @Override
82
-      public void processRow(ResultSet rs) throws SQLException {
83
-        handlings.add(handlingRowMapper.mapRow(rs, rs.getRow()));
84
-      }
85
-    };
86
-    String[] args = {trackingId};
87
-    String sql = "select * from handling where cargo_tracking_id = ?";
88
-    jdbc.query(sql, args, handler);
89
-    return handlings;
90
-  }
91
-
92
-  private List<VoyageReport.Cargo> loadOnboardCargos(String voyageNumber) {
93
-    final List<VoyageReport.Cargo> cargos = new ArrayList<VoyageReport.Cargo>();
94
-    final ParameterizedRowMapper<VoyageReport.Cargo> rowMapper = new ParameterizedRowMapper<VoyageReport.Cargo>() {
95
-      @Override
96
-      public VoyageReport.Cargo mapRow(ResultSet rs, int rowNum) throws SQLException {
97
-        VoyageReport.Cargo cargo = new VoyageReport.Cargo();
98
-        cargo.setTrackingId(rs.getString("cargo_tracking_id"));
99
-        cargo.setFinalDestination(rs.getString("destination"));
100
-        return cargo;
101
-      }
102
-    };
103
-    String[] args = {voyageNumber};
104
-    String sql = "select cargo_tracking_id, destination from cargo where current_voyage_number = ?";
105
-    jdbc.query(sql, args, new RowCallbackHandler() {
106
-      @Override
107
-      public void processRow(ResultSet rs) throws SQLException {
108
-        cargos.add(rowMapper.mapRow(rs, rs.getRow()));
109
-      }
110
-    });
111
-
112
-    return cargos;
113
-  }
114
-
115
-  private VoyageReport loadVoyageReport(String voyageNumber) {
116
-    String[] args = {voyageNumber};
117
-    String sql = "select * from voyage where voyage_number = ?";
118
-    try {
119
-      return (VoyageReport) jdbc.queryForObject(sql, args, rowMapper);
120
-    } catch (EmptyResultDataAccessException e) {
121
-      return null;
122
-    }
123
-  }
124
-
125
-  ReportingService() {
126
-    // Needed by CGLIB
127
-  }
128
-
129
-}

+ 0
- 95
dddsample/external/reporting/src/main/java/com.reporting/VoyageReport.java Ver arquivo

@@ -1,95 +0,0 @@
1
-package com.reporting;
2
-
3
-import javax.xml.bind.annotation.XmlRootElement;
4
-import java.util.List;
5
-import java.util.ArrayList;
6
-
7
-@XmlRootElement(name = "voyage")
8
-public class VoyageReport {
9
-
10
-  private String voyageNumber;
11
-  private String nextStop;
12
-  private String etaNextStop;
13
-  private String currentStatus;
14
-  private int delayedByMinutes;
15
-  private String lastUpdatedOn;
16
-  private List<Cargo> onboardCargos = new ArrayList<Cargo>();
17
-
18
-  public String getVoyageNumber() {
19
-    return voyageNumber;
20
-  }
21
-
22
-  public void setVoyageNumber(String voyageNumber) {
23
-    this.voyageNumber = voyageNumber;
24
-  }
25
-
26
-  public String getNextStop() {
27
-    return nextStop;
28
-  }
29
-
30
-  public void setNextStop(String nextStop) {
31
-    this.nextStop = nextStop;
32
-  }
33
-
34
-  public String getEtaNextStop() {
35
-    return etaNextStop;
36
-  }
37
-
38
-  public void setEtaNextStop(String etaNextStop) {
39
-    this.etaNextStop = etaNextStop;
40
-  }
41
-
42
-  public String getCurrentStatus() {
43
-    return currentStatus;
44
-  }
45
-
46
-  public void setCurrentStatus(String currentStatus) {
47
-    this.currentStatus = currentStatus;
48
-  }
49
-
50
-  public int getDelayedByMinutes() {
51
-    return delayedByMinutes;
52
-  }
53
-
54
-  public void setDelayedByMinutes(int delayedByMinutes) {
55
-    this.delayedByMinutes = delayedByMinutes;
56
-  }
57
-
58
-  public String getLastUpdatedOn() {
59
-    return lastUpdatedOn;
60
-  }
61
-
62
-  public void setLastUpdatedOn(String lastUpdatedOn) {
63
-    this.lastUpdatedOn = lastUpdatedOn;
64
-  }
65
-
66
-  public List<Cargo> getOnboardCargos() {
67
-    return onboardCargos;
68
-  }
69
-
70
-  public void setOnboardCargos(List<Cargo> onboardCargos) {
71
-    this.onboardCargos = onboardCargos;
72
-  }
73
-
74
-  public static class Cargo {
75
-    String trackingId;
76
-    String finalDestination;
77
-
78
-    public String getTrackingId() {
79
-      return trackingId;
80
-    }
81
-
82
-    public void setTrackingId(String trackingId) {
83
-      this.trackingId = trackingId;
84
-    }
85
-
86
-    public String getFinalDestination() {
87
-      return finalDestination;
88
-    }
89
-
90
-    public void setFinalDestination(String finalDestination) {
91
-      this.finalDestination = finalDestination;
92
-    }
93
-  }
94
-
95
-}

+ 0
- 22
dddsample/external/reporting/src/main/java/com.reporting/VoyageReportRowMapper.java Ver arquivo

@@ -1,22 +0,0 @@
1
-package com.reporting;
2
-
3
-import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
4
-
5
-import java.sql.ResultSet;
6
-import java.sql.SQLException;
7
-
8
-import static com.reporting.Constants.*;
9
-
10
-class VoyageReportRowMapper implements ParameterizedRowMapper<VoyageReport> {
11
-  @Override
12
-  public VoyageReport mapRow(ResultSet rs, int rowNum) throws SQLException {
13
-    VoyageReport voyageReport = new VoyageReport();
14
-    voyageReport.setVoyageNumber(rs.getString("voyage_number"));
15
-    voyageReport.setCurrentStatus(rs.getString("current_status"));
16
-    voyageReport.setDelayedByMinutes(rs.getInt("delayed_by_min"));
17
-    voyageReport.setEtaNextStop(US_DATETIME.format(rs.getTimestamp("eta_next_stop")));
18
-    voyageReport.setLastUpdatedOn(US_DATETIME.format(rs.getTimestamp("last_updated_on")));
19
-    voyageReport.setNextStop(rs.getString("next_stop"));
20
-    return voyageReport;
21
-  }
22
-}