Ver código fonte

Restructured the reporting context.

peter_backlund 17 anos atrás
pai
commit
07bec5a73c
27 arquivos alterados com 4965 adições e 42 exclusões
  1. 5
    0
      dddsample/external/reporting/pom.xml
  2. 10
    0
      dddsample/external/reporting/src/main/java/com/reporting2/Constants.java
  3. 28
    0
      dddsample/external/reporting/src/main/java/com/reporting2/Fixture.java
  4. 65
    0
      dddsample/external/reporting/src/main/java/com/reporting2/ReportingService.java
  5. 30
    0
      dddsample/external/reporting/src/main/java/com/reporting2/db/CargoReportRowMapper.java
  6. 22
    0
      dddsample/external/reporting/src/main/java/com/reporting2/db/HandlingRowMapper.java
  7. 90
    0
      dddsample/external/reporting/src/main/java/com/reporting2/db/ReportDAO.java
  8. 17
    0
      dddsample/external/reporting/src/main/java/com/reporting2/db/VoyageCargoRowMapper.java
  9. 25
    0
      dddsample/external/reporting/src/main/java/com/reporting2/db/VoyageReportRowMapper.java
  10. 50
    0
      dddsample/external/reporting/src/main/java/com/reporting2/pdf/PDFCargoReportProvider.java
  11. 48
    0
      dddsample/external/reporting/src/main/java/com/reporting2/pdf/PDFMessageBodyWriter.java
  12. 29
    0
      dddsample/external/reporting/src/main/java/com/reporting2/pdf/PDFVoyageReportProvider.java
  13. 31
    0
      dddsample/external/reporting/src/main/java/com/reporting2/reports/CargoReport.java
  14. 32
    0
      dddsample/external/reporting/src/main/java/com/reporting2/reports/VoyageReport.java
  15. 3
    0
      dddsample/external/reporting/src/main/resources/app.properties
  16. 9
    3
      dddsample/external/reporting/src/main/resources/context-cxf.xml
  17. 2
    2
      dddsample/external/reporting/src/main/resources/context-test-setup.xml
  18. 5
    1
      dddsample/external/reporting/src/main/resources/context.xml
  19. 1
    1
      dddsample/external/reporting/src/main/resources/log4j.properties
  20. 24
    1
      dddsample/external/reporting/src/main/resources/sample_data.sql
  21. 2
    1
      dddsample/external/reporting/src/main/webapp/WEB-INF/web.xml
  22. 53
    0
      dddsample/external/reporting/src/main/webapp/index.jsp
  23. 4376
    0
      dddsample/external/reporting/src/main/webapp/jquery-1.3.2.js
  24. 1
    1
      dddsample/external/reporting/src/test/java/temp/pkg/Fixture.java
  25. 4
    5
      dddsample/external/reporting/src/test/java/temp/pkg/ReportServiceTest.java
  26. 3
    0
      dddsample/external/reporting/src/test/resources/app.properties
  27. 0
    27
      dddsample/external/reporting/src/test/resources/context-cxf.xml

+ 5
- 0
dddsample/external/reporting/pom.xml Ver arquivo

@@ -14,6 +14,11 @@
14 14
   <description>Reporting context</description>
15 15
   <dependencies>
16 16
     <dependency>
17
+      <groupId>se.citerus.dddsample.external</groupId>
18
+      <artifactId>reporting-api</artifactId>
19
+      <version>1.2-SNAPSHOT</version>
20
+    </dependency>
21
+    <dependency>
17 22
       <groupId>org.springframework</groupId>
18 23
       <artifactId>spring</artifactId>
19 24
     </dependency>

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

@@ -0,0 +1,10 @@
1
+package com.reporting2;
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
+}

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

@@ -0,0 +1,28 @@
1
+package com.reporting2;
2
+
3
+import org.apache.commons.io.IOUtils;
4
+import org.springframework.beans.factory.InitializingBean;
5
+import org.springframework.core.io.Resource;
6
+import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
7
+
8
+import javax.sql.DataSource;
9
+
10
+public class Fixture implements InitializingBean {
11
+
12
+  private SimpleJdbcTemplate jdbc;
13
+  private Resource schema;
14
+  private Resource testdata;
15
+
16
+  public Fixture(DataSource dataSource, Resource schema, Resource testdata) {
17
+    this.jdbc = new SimpleJdbcTemplate(dataSource);
18
+    this.testdata = testdata;
19
+    this.schema = schema;
20
+  }
21
+
22
+  @Override
23
+  public void afterPropertiesSet() throws Exception {
24
+    jdbc.update(IOUtils.toString(schema.getInputStream()));
25
+    jdbc.update(IOUtils.toString(testdata.getInputStream()));
26
+  }
27
+
28
+}

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

@@ -0,0 +1,65 @@
1
+package com.reporting2;
2
+
3
+import static com.reporting2.Constants.US_DATETIME;
4
+import com.reporting2.db.ReportDAO;
5
+import com.reporting2.reports.CargoReport;
6
+import com.reporting2.reports.VoyageReport;
7
+import se.citerus.dddsample.reporting.api.CargoDetails;
8
+import se.citerus.dddsample.reporting.api.Handling;
9
+
10
+import javax.ws.rs.*;
11
+import javax.ws.rs.core.Response;
12
+import static javax.ws.rs.core.Response.ok;
13
+import static javax.ws.rs.core.Response.status;
14
+import java.text.ParseException;
15
+
16
+@Produces({"application/json", "application/pdf"})
17
+@Consumes("application/json")
18
+@Path("/")
19
+public class ReportingService {
20
+
21
+  private ReportDAO reportDAO;
22
+
23
+  public ReportingService(ReportDAO reportDAO) {
24
+    this.reportDAO = reportDAO;
25
+  }
26
+
27
+  @GET
28
+  @Path("/cargo/{trackingId}")
29
+  public Response getCargoReport(@PathParam("trackingId") String trackingId) throws ParseException {
30
+    CargoReport cargoReport = reportDAO.loadCargoReport(trackingId);
31
+    if (cargoReport == null) return status(404).build();
32
+
33
+    return ok(cargoReport).
34
+      lastModified(US_DATETIME.parse(cargoReport.getCargo().getLastUpdatedOn())).
35
+      build();
36
+  }
37
+
38
+  @GET
39
+  @Path("/voyage/{voyageNumber}")
40
+  public Response getVoyageReport(@PathParam("voyageNumber") String voyageNumber) throws ParseException {
41
+    VoyageReport voyageReport = reportDAO.loadVoyageReport(voyageNumber);
42
+    if (voyageReport == null) return status(404).build();
43
+
44
+    return ok(voyageReport).
45
+      lastModified(US_DATETIME.parse(voyageReport.getVoyage().getLastUpdatedOn())).
46
+      build();
47
+  }
48
+
49
+  @PUT
50
+  @Path("/cargo")
51
+  public void reportCargoDetails(CargoDetails cargoDetails) {
52
+    // TODO
53
+  }
54
+
55
+  @PUT
56
+  @Path("/cargo/{trackingId}/handled")
57
+  public void reportHandling(@PathParam("trackingId") String trackingId, Handling handling) {
58
+    // TODO
59
+  }
60
+
61
+  ReportingService() {
62
+    // Needed by CGLIB
63
+  }
64
+
65
+}

+ 30
- 0
dddsample/external/reporting/src/main/java/com/reporting2/db/CargoReportRowMapper.java Ver arquivo

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

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

@@ -0,0 +1,22 @@
1
+package com.reporting2.db;
2
+
3
+import static com.reporting2.Constants.US_DATETIME;
4
+import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
5
+import se.citerus.dddsample.reporting.api.Handling;
6
+
7
+import java.sql.ResultSet;
8
+import java.sql.SQLException;
9
+
10
+public class HandlingRowMapper implements ParameterizedRowMapper<Handling> {
11
+
12
+  @Override
13
+  public Handling mapRow(ResultSet rs, int rowNum) throws SQLException {
14
+    Handling handling = new 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
+}

+ 90
- 0
dddsample/external/reporting/src/main/java/com/reporting2/db/ReportDAO.java Ver arquivo

@@ -0,0 +1,90 @@
1
+package com.reporting2.db;
2
+
3
+import com.reporting2.reports.CargoReport;
4
+import com.reporting2.reports.VoyageReport;
5
+import org.springframework.dao.EmptyResultDataAccessException;
6
+import org.springframework.jdbc.core.JdbcTemplate;
7
+import org.springframework.jdbc.core.RowCallbackHandler;
8
+import org.springframework.transaction.annotation.Transactional;
9
+import se.citerus.dddsample.reporting.api.Handling;
10
+import se.citerus.dddsample.reporting.api.OnboardCargo;
11
+
12
+import javax.sql.DataSource;
13
+import java.sql.ResultSet;
14
+import java.sql.SQLException;
15
+import java.util.ArrayList;
16
+import java.util.List;
17
+
18
+public class ReportDAO {
19
+  
20
+  private JdbcTemplate jdbc;
21
+  private HandlingRowMapper handlingRowMapper;
22
+  private CargoReportRowMapper cargoReportRowMapper;
23
+  private VoyageReportRowMapper rowMapper;
24
+  private VoyageCargoRowMapper voyageCargoRowMapper;
25
+
26
+  public ReportDAO(DataSource dataSource) {
27
+    this.jdbc = new JdbcTemplate(dataSource);
28
+    this.handlingRowMapper = new HandlingRowMapper();
29
+    this.cargoReportRowMapper = new CargoReportRowMapper();
30
+    this.rowMapper = new VoyageReportRowMapper();
31
+    this.voyageCargoRowMapper = new VoyageCargoRowMapper();
32
+  }
33
+
34
+  @Transactional(readOnly = true)
35
+  public CargoReport loadCargoReport(String trackingId) {
36
+    try {
37
+      String[] args = {trackingId};
38
+      String sql = "select * from cargo where cargo_tracking_id = ?";
39
+      CargoReport cargoReport = (CargoReport) jdbc.queryForObject(sql, args, cargoReportRowMapper);
40
+      cargoReport.setHandlings(loadHandlings(trackingId));
41
+      return cargoReport;
42
+    } catch (EmptyResultDataAccessException e) {
43
+      return null;
44
+    }
45
+  }
46
+
47
+  @Transactional(readOnly = true)
48
+  public VoyageReport loadVoyageReport(String voyageNumber) {
49
+    String[] args = {voyageNumber};
50
+    String sql = "select * from voyage where voyage_number = ?";
51
+    try {
52
+      VoyageReport voyageReport = (VoyageReport) jdbc.queryForObject(sql, args, rowMapper);
53
+      voyageReport.setOnboardCargos(loadOnboardCargos(voyageNumber));
54
+      return voyageReport;
55
+    } catch (EmptyResultDataAccessException e) {
56
+      return null;
57
+    }
58
+  }
59
+
60
+  private List<Handling> loadHandlings(String trackingId) {
61
+    final List<Handling> handlings = new ArrayList<Handling>();
62
+    RowCallbackHandler handler = new RowCallbackHandler() {
63
+      @Override
64
+      public void processRow(ResultSet rs) throws SQLException {
65
+        handlings.add(handlingRowMapper.mapRow(rs, rs.getRow()));
66
+      }
67
+    };
68
+    String[] args = {trackingId};
69
+    String sql = "select * from handling where cargo_tracking_id = ?";
70
+    jdbc.query(sql, args, handler);
71
+    return handlings;
72
+  }
73
+
74
+  private List<OnboardCargo> loadOnboardCargos(String voyageNumber) {
75
+    final List<OnboardCargo> onboardCargos = new ArrayList<OnboardCargo>();
76
+    String[] args = {voyageNumber};
77
+    String sql = "select cargo_tracking_id, destination from cargo where current_voyage_number = ?";
78
+    jdbc.query(sql, args, new RowCallbackHandler() {
79
+      @Override
80
+      public void processRow(ResultSet rs) throws SQLException {
81
+        onboardCargos.add(voyageCargoRowMapper.mapRow(rs, rs.getRow()));
82
+      }
83
+    });
84
+
85
+    return onboardCargos;
86
+  }
87
+
88
+  ReportDAO() {
89
+  }
90
+}

+ 17
- 0
dddsample/external/reporting/src/main/java/com/reporting2/db/VoyageCargoRowMapper.java Ver arquivo

@@ -0,0 +1,17 @@
1
+package com.reporting2.db;
2
+
3
+import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
4
+import se.citerus.dddsample.reporting.api.OnboardCargo;
5
+
6
+import java.sql.ResultSet;
7
+import java.sql.SQLException;
8
+
9
+public class VoyageCargoRowMapper implements ParameterizedRowMapper<OnboardCargo> {
10
+  @Override
11
+    public OnboardCargo mapRow(ResultSet rs, int rowNum) throws SQLException {
12
+    OnboardCargo onboardCargo = new OnboardCargo();
13
+    onboardCargo.setTrackingId(rs.getString("cargo_tracking_id"));
14
+    onboardCargo.setFinalDestination(rs.getString("destination"));
15
+    return onboardCargo;
16
+  }
17
+}

+ 25
- 0
dddsample/external/reporting/src/main/java/com/reporting2/db/VoyageReportRowMapper.java Ver arquivo

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

+ 50
- 0
dddsample/external/reporting/src/main/java/com/reporting2/pdf/PDFCargoReportProvider.java Ver arquivo

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

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

@@ -0,0 +1,48 @@
1
+package com.reporting2.pdf;
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.core.MediaType;
8
+import javax.ws.rs.core.MultivaluedMap;
9
+import javax.ws.rs.ext.MessageBodyWriter;
10
+import java.io.ByteArrayOutputStream;
11
+import java.io.IOException;
12
+import java.io.OutputStream;
13
+import java.lang.annotation.Annotation;
14
+import java.lang.reflect.Type;
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
+}

+ 29
- 0
dddsample/external/reporting/src/main/java/com/reporting2/pdf/PDFVoyageReportProvider.java Ver arquivo

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

+ 31
- 0
dddsample/external/reporting/src/main/java/com/reporting2/reports/CargoReport.java Ver arquivo

@@ -0,0 +1,31 @@
1
+package com.reporting2.reports;
2
+
3
+import se.citerus.dddsample.reporting.api.CargoDetails;
4
+import se.citerus.dddsample.reporting.api.Handling;
5
+
6
+import javax.xml.bind.annotation.XmlRootElement;
7
+import java.util.List;
8
+
9
+@XmlRootElement
10
+public class CargoReport {
11
+
12
+  CargoDetails cargoDetails;
13
+  List<Handling> handlings;
14
+
15
+  public CargoDetails getCargo() {
16
+    return cargoDetails;
17
+  }
18
+
19
+  public void setCargo(CargoDetails cargoDetails) {
20
+    this.cargoDetails = cargoDetails;
21
+  }
22
+
23
+  public List<Handling> getHandlings() {
24
+    return handlings;
25
+  }
26
+
27
+  public void setHandlings(List<Handling> handlings) {
28
+    this.handlings = handlings;
29
+  }
30
+
31
+}

+ 32
- 0
dddsample/external/reporting/src/main/java/com/reporting2/reports/VoyageReport.java Ver arquivo

@@ -0,0 +1,32 @@
1
+package com.reporting2.reports;
2
+
3
+import se.citerus.dddsample.reporting.api.OnboardCargo;
4
+import se.citerus.dddsample.reporting.api.VoyageDetails;
5
+
6
+import javax.xml.bind.annotation.XmlRootElement;
7
+import java.util.ArrayList;
8
+import java.util.List;
9
+
10
+@XmlRootElement
11
+public class VoyageReport {
12
+
13
+  private VoyageDetails voyage;
14
+  private List<OnboardCargo> onboardOnboardCargos = new ArrayList<OnboardCargo>();
15
+
16
+  public List<OnboardCargo> getOnboardCargos() {
17
+    return onboardOnboardCargos;
18
+  }
19
+
20
+  public void setOnboardCargos(List<OnboardCargo> onboardOnboardCargos) {
21
+    this.onboardOnboardCargos = onboardOnboardCargos;
22
+  }
23
+
24
+  public VoyageDetails getVoyage() {
25
+    return voyage;
26
+  }
27
+
28
+  public void setVoyage(VoyageDetails voyage) {
29
+    this.voyage = voyage;
30
+  }
31
+
32
+}

+ 3
- 0
dddsample/external/reporting/src/main/resources/app.properties Ver arquivo

@@ -0,0 +1,3 @@
1
+db.url=jdbc:hsqldb:mem:reporting
2
+server.address=/
3
+http.extension=cxf-extension-http.xml

+ 9
- 3
dddsample/external/reporting/src/main/resources/context-cxf.xml Ver arquivo

@@ -3,21 +3,27 @@
3 3
 <beans xmlns="http://www.springframework.org/schema/beans"
4 4
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5 5
        xmlns:jaxrs="http://cxf.apache.org/jaxrs"
6
-       xmlns:tx="http://www.springframework.org/schema/tx"
6
+       xmlns:util="http://www.springframework.org/schema/util"
7 7
        xsi:schemaLocation="
8 8
         http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
9
-        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
9
+        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
10 10
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
11 11
 
12
+  <util:properties id="cfg" location="classpath:app.properties"/>
13
+
12 14
   <import resource="classpath:META-INF/cxf/cxf.xml"/>
13 15
   <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
14 16
   <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/>
15
-  <import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
17
+  <import resource="classpath:META-INF/cxf/cxf-extension-http.xml"/>
16 18
 
17 19
   <jaxrs:server address="/">
18 20
     <jaxrs:serviceBeans>
19 21
       <ref bean="reportingService"/>
20 22
     </jaxrs:serviceBeans>
23
+    <jaxrs:providers>
24
+      <bean class="com.reporting2.pdf.PDFCargoReportProvider"/>
25
+      <bean class="com.reporting2.pdf.PDFVoyageReportProvider"/>
26
+    </jaxrs:providers>
21 27
   </jaxrs:server>
22 28
 
23 29
 </beans>

dddsample/external/reporting/src/test/resources/context-test-setup.xml → dddsample/external/reporting/src/main/resources/context-test-setup.xml Ver arquivo

@@ -4,10 +4,10 @@
4 4
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5 5
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
6 6
 
7
-  <bean class="com.reporting.Fixture">
7
+  <bean class="com.reporting2.Fixture">
8 8
     <constructor-arg ref="dataSource"/>
9 9
     <constructor-arg value="classpath:schema.sql"/>
10
-    <constructor-arg value="classpath:testdata.sql"/>
10
+    <constructor-arg value="classpath:sample_data.sql"/>
11 11
   </bean>
12 12
 
13 13
 </beans>

+ 5
- 1
dddsample/external/reporting/src/main/resources/context.xml Ver arquivo

@@ -15,10 +15,14 @@
15 15
 
16 16
   <tx:annotation-driven transaction-manager="transactionManager"/>
17 17
 
18
-  <bean id="reportingService" class="com.reporting.ReportingService">
18
+  <bean id="reportDAO" class="com.reporting2.db.ReportDAO">
19 19
     <constructor-arg ref="dataSource"/>
20 20
   </bean>
21 21
 
22
+  <bean id="reportingService" class="com.reporting2.ReportingService">
23
+    <constructor-arg ref="reportDAO"/>
24
+  </bean>
25
+
22 26
   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
23 27
     <property name="url" value="jdbc:hsqldb:mem:reporting"/>
24 28
     <property name="driverClassName" value="org.hsqldb.jdbcDriver"/>

+ 1
- 1
dddsample/external/reporting/src/main/resources/log4j.properties Ver arquivo

@@ -3,4 +3,4 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
3 3
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
4 4
 log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
5 5
 
6
-log4j.logger.com.reporting=INFO
6
+log4j.logger.com.reporting2=INFO

dddsample/external/reporting/src/test/resources/testdata.sql → dddsample/external/reporting/src/main/resources/sample_data.sql Ver arquivo

@@ -16,7 +16,7 @@ insert into cargo (
16 16
   '2009-06-12 18:30:00.000',
17 17
   'Onboard voyage',
18 18
   'V0100',
19
-  'Tokyo',
19
+  null,
20 20
   '2009-06-08 14:23:12.123'
21 21
 );
22 22
 
@@ -32,6 +32,29 @@ values ('ABC','Unload', 'Long Beach','V0100','2009-06-04 19:01:00.000');
32 32
 insert into handling (cargo_tracking_id, type,location,voyage_number,completed_on)
33 33
 values ('ABC','Load',   'Long Beach','V0200','2009-06-06 22:50:00.000');
34 34
 
35
+insert into cargo (
36
+  cargo_tracking_id,
37
+  received_in,
38
+  destination,
39
+  arrival_deadline,
40
+  eta,
41
+  current_status,
42
+  current_voyage_number,
43
+  current_location,
44
+  last_updated_on
45
+) values (
46
+  'DEF',
47
+  'Hongkong',
48
+  'Stockholm',
49
+  '2009-06-15 12:00:00.000',
50
+  '2009-06-12 18:30:00.000',
51
+  'In port',
52
+  null,
53
+  'Tokyo',
54
+  '2009-06-08 14:23:12.123'
55
+);
56
+
57
+
35 58
 insert into voyage (
36 59
   voyage_number,
37 60
   next_stop,

+ 2
- 1
dddsample/external/reporting/src/main/webapp/WEB-INF/web.xml Ver arquivo

@@ -24,6 +24,7 @@
24 24
     <param-value>
25 25
       classpath:context.xml
26 26
       classpath:context-cxf.xml
27
+      classpath:context-test-setup.xml
27 28
     </param-value>
28 29
   </context-param>
29 30
 
@@ -35,7 +36,7 @@
35 36
 
36 37
   <servlet-mapping>
37 38
     <servlet-name>cxf</servlet-name>
38
-    <url-pattern>/*</url-pattern>
39
+    <url-pattern>/rest/*</url-pattern>
39 40
   </servlet-mapping>
40 41
 
41 42
 </web-app>

+ 53
- 0
dddsample/external/reporting/src/main/webapp/index.jsp Ver arquivo

@@ -0,0 +1,53 @@
1
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+
3
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+<head>
5
+  <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
6
+  <script type="text/javascript" src="jquery-1.3.2.js"></script>
7
+  <title>Reporting</title>
8
+</head>
9
+<body>
10
+  <h1 id="apa">Reporting</h1>
11
+  <div>
12
+    <form action="" method="get" onsubmit="search(); return false;">
13
+      Search:
14
+      <input id="query" name="query" type="text"/>
15
+      <input id="submit" name="submit" type="submit" value="Search"/>
16
+    </form>
17
+  </div>
18
+  <div id="result"></div>
19
+  <script type="text/javascript">
20
+    $('#query').focus();
21
+
22
+    function search() {
23
+      $.ajax({
24
+          url: "http://localhost:8080/reporting/rest/cargo/" + $("#query").val(),
25
+          type: 'GET',
26
+          contentType: 'application/json',
27
+          success: function(response) {
28
+            var json = eval('(' + response + ')');
29
+            var cargo = json.cargoReport.cargo;
30
+            $('#result').empty();
31
+            $('#result').
32
+              append('<h2>Cargo ' + cargo.trackingId + '</h2>').
33
+              append('<p>Destination: ' + cargo.finalDestination + ' (at ' + cargo.arrivalDeadline + ')</p>')
34
+
35
+            if (cargo.currentLocation) {
36
+              $('#result').append('<p>Status: ' + cargo.currentStatus + ' ' + cargo.currentLocation + '</p>');
37
+            } else if (cargo.currentVoyage) {
38
+              $('#result').append('<p>Status: ' + cargo.currentStatus + ' ' + cargo.currentVoyage + '</p>');
39
+            }
40
+
41
+            $('#result').append('<p>Updated on: ' + cargo.lastUpdatedOn + '</p>');
42
+          },
43
+          error: function(response) {
44
+            if (response.status == 404) {
45
+              $('#result').text('No cargo with tracking id ' + $("#query").val());
46
+            }
47
+          }
48
+      });
49
+    }
50
+  </script>
51
+</body>
52
+</html>
53
+

+ 4376
- 0
dddsample/external/reporting/src/main/webapp/jquery-1.3.2.js
Diferenças do arquivo suprimidas por serem muito extensas
Ver arquivo


dddsample/external/reporting/src/test/java/com/reporting/Fixture.java → dddsample/external/reporting/src/test/java/temp/pkg/Fixture.java Ver arquivo

@@ -4,7 +4,7 @@
4 4
  * @created 2009-okt-03
5 5
  * $Id$
6 6
  */
7
-package com.reporting;
7
+package temp.pkg;
8 8
 
9 9
 import org.apache.commons.io.IOUtils;
10 10
 import org.springframework.context.ApplicationEvent;

dddsample/external/reporting/src/test/java/com/reporting/ReportServiceTest.java → dddsample/external/reporting/src/test/java/temp/pkg/ReportServiceTest.java Ver arquivo

@@ -1,19 +1,18 @@
1
-package com.reporting;
1
+package temp.pkg;
2 2
 
3 3
 import org.apache.commons.io.IOUtils;
4
-import org.codehaus.jettison.json.JSONObject;
5
-import org.codehaus.jettison.json.JSONException;
6 4
 import org.codehaus.jettison.json.JSONArray;
7
-import static org.junit.Assert.assertEquals;
5
+import org.codehaus.jettison.json.JSONException;
6
+import org.codehaus.jettison.json.JSONObject;
8 7
 import static org.junit.Assert.*;
9 8
 import org.junit.Test;
10 9
 import org.junit.runner.RunWith;
11 10
 import org.springframework.test.context.ContextConfiguration;
12 11
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
13 12
 
13
+import java.io.IOException;
14 14
 import java.net.URL;
15 15
 import java.net.URLConnection;
16
-import java.io.IOException;
17 16
 
18 17
 @RunWith(SpringJUnit4ClassRunner.class)
19 18
 @ContextConfiguration(locations={"/context.xml", "/context-cxf.xml", "/context-test-setup.xml"})

+ 3
- 0
dddsample/external/reporting/src/test/resources/app.properties Ver arquivo

@@ -0,0 +1,3 @@
1
+db.url=jdbc:hsqldb:mem:reporting
2
+server.address=http://localhost:14000
3
+http.extension=classpath:META-INF/cxf/cxf-extension-http-jetty.xml

+ 0
- 27
dddsample/external/reporting/src/test/resources/context-cxf.xml Ver arquivo

@@ -1,27 +0,0 @@
1
-<?xml version="1.0"?>
2
-
3
-<beans xmlns="http://www.springframework.org/schema/beans"
4
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
-       xmlns:jaxrs="http://cxf.apache.org/jaxrs"
6
-       xmlns:tx="http://www.springframework.org/schema/tx"
7
-       xsi:schemaLocation="
8
-        http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
9
-        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
10
-        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
11
-
12
-  <import resource="classpath:META-INF/cxf/cxf.xml"/>
13
-  <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
14
-  <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml"/>
15
-  <import resource="classpath:META-INF/cxf/cxf-extension-http-jetty.xml" />
16
-
17
-  <jaxrs:server address="http://localhost:14000" id="jaxRsService">
18
-    <jaxrs:serviceBeans>
19
-      <ref bean="reportingService"/>
20
-    </jaxrs:serviceBeans>
21
-    <jaxrs:providers>
22
-      <bean class="com.reporting.PDFCargoReportProvider"/>
23
-      <bean class="com.reporting.PDFVoyageReportProvider"/>
24
-    </jaxrs:providers>
25
-  </jaxrs:server>
26
-
27
-</beans>