diff --git a/spring-boot-mvc-birt/reports/static_data_report.rptdesign b/spring-boot-mvc-birt/reports/csv_data_report.rptdesign similarity index 100% rename from spring-boot-mvc-birt/reports/static_data_report.rptdesign rename to spring-boot-mvc-birt/reports/csv_data_report.rptdesign diff --git a/spring-boot-mvc-birt/reports/simple_static.rptdesign b/spring-boot-mvc-birt/reports/static_report.rptdesign similarity index 100% rename from spring-boot-mvc-birt/reports/simple_static.rptdesign rename to spring-boot-mvc-birt/reports/static_report.rptdesign diff --git a/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/designer/ReportDesignHelper.java b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/designer/ReportDesignApplication.java similarity index 82% rename from spring-boot-mvc-birt/src/main/java/com/baeldung/birt/designer/ReportDesignHelper.java rename to spring-boot-mvc-birt/src/main/java/com/baeldung/birt/designer/ReportDesignApplication.java index 3f9df78de1..f1e1619a58 100644 --- a/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/designer/ReportDesignHelper.java +++ b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/designer/ReportDesignApplication.java @@ -11,27 +11,26 @@ import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import javax.annotation.PostConstruct; import java.io.File; import java.io.IOException; @SpringBootApplication -public class ReportDesignHelper implements CommandLineRunner { +public class ReportDesignApplication implements CommandLineRunner { - private static final Logger log = Logger.getLogger(ReportDesignHelper.class); + private static final Logger log = Logger.getLogger(ReportDesignApplication.class); @Value("${reports.relative.path}") private String REPORTS_FOLDER; public static void main(String[] args) { - new SpringApplicationBuilder(ReportDesignHelper.class).web(WebApplicationType.NONE).build().run(args); + new SpringApplicationBuilder(ReportDesignApplication.class).web(WebApplicationType.NONE).build().run(args); } @Override public void run(String... args) throws Exception { buildReport(); } - public void buildReport() throws IOException, BirtException { + private void buildReport() throws IOException, BirtException { final DesignConfig config = new DesignConfig(); final IDesignEngine engine; @@ -63,40 +62,30 @@ public class ReportDesignHelper implements CommandLineRunner { DesignElementHandle element = factory.newSimpleMasterPage("Page Master"); //$NON-NLS-1$ design.getMasterPages().add(element); - // Create a grid and add it to the "body" slot of the report - // design. - + // Create a grid GridHandle grid = factory.newGridItem(null, 2 /* cols */, 1 /* row */); design.getBody().add(grid); - - // Note: Set the table width to 100% to prevent the label - // from appearing too narrow in the layout view. - - grid.setWidth("100%"); //$NON-NLS-1$ - - // Get the first row. + grid.setWidth("100%"); RowHandle row0 = (RowHandle) grid.getRows().get(0); // Create an image and add it to the first cell. - ImageHandle image = factory.newImage(null); CellHandle cell = (CellHandle) row0.getCells().get(0); cell.getContent().add(image); image.setURL("\"https://www.baeldung.com/wp-content/themes/baeldung/favicon/favicon-96x96.png\""); - // Create a label and add it to the second cell. + // Create a label and add it to the second cell. LabelHandle label = factory.newLabel(null); cell = (CellHandle) row0.getCells().get(1); cell.getContent().add(label); label.setText("Hello, Baeldung world!"); - // Save the design and close it. File report = new File(REPORTS_FOLDER); report.mkdirs(); - design.saveAs(new File(report, "simple_static.rptdesign").getAbsolutePath()); + design.saveAs(new File(report, "static_report.rptdesign").getAbsolutePath()); design.close(); log.info("Report generated"); } diff --git a/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/controller/BirtReportController.java b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/controller/BirtReportController.java index 10c0dce45c..ab225f1b6e 100644 --- a/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/controller/BirtReportController.java +++ b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/controller/BirtReportController.java @@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; import java.util.List; @Controller @@ -22,9 +21,6 @@ public class BirtReportController { @Autowired private BirtReportService reportService; - /** - * generate list of reports - */ @RequestMapping(produces = "application/json", method = RequestMethod.GET, value = "/report") @ResponseBody public List listReports() { @@ -44,16 +40,12 @@ public class BirtReportController { return ResponseEntity.ok().build(); } - /** - * Generate full report - */ @RequestMapping(method = RequestMethod.GET, value = "/report/{name}") @ResponseBody public void generateFullReport(HttpServletResponse response, HttpServletRequest request, - @PathVariable("name") String name, @RequestParam("output") String output) throws EngineException, IOException { + @PathVariable("name") String name, @RequestParam("output") String output) { log.info("Generating full report: " + name); OutputType format = OutputType.from(output); reportService.generateMainReport(name, format, response, request); } - } diff --git a/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/dto/Report.java b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/dto/Report.java index 3a022e3b4c..a2d2444b80 100644 --- a/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/dto/Report.java +++ b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/dto/Report.java @@ -3,9 +3,7 @@ package com.baeldung.birt.engine.dto; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import lombok.RequiredArgsConstructor; -import java.util.ArrayList; import java.util.List; /** @@ -34,6 +32,6 @@ public class Report { } public enum ParameterType { - INT, STRING; + INT, STRING } } diff --git a/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/service/BirtReportService.java b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/service/BirtReportService.java index 9d0c9e8196..540bbbb530 100644 --- a/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/service/BirtReportService.java +++ b/spring-boot-mvc-birt/src/main/java/com/baeldung/birt/engine/service/BirtReportService.java @@ -112,7 +112,7 @@ public class BirtReportService implements ApplicationContextAware, DisposableBea } /** - * Generate a report as html + * Generate a report as HTML */ @SuppressWarnings("unchecked") private void generateHTMLReport(IReportRunnable report, HttpServletResponse response, HttpServletRequest request) { @@ -137,6 +137,10 @@ public class BirtReportService implements ApplicationContextAware, DisposableBea } } + /** + * Generate a report as PDF + */ + @SuppressWarnings("unchecked") private void generatePDFReport(IReportRunnable report, HttpServletResponse response, HttpServletRequest request) { IRunAndRenderTask runAndRenderTask = birtEngine.createRunAndRenderTask(report); response.setContentType(birtEngine.getMIMEType("pdf")); @@ -156,7 +160,8 @@ public class BirtReportService implements ApplicationContextAware, DisposableBea } } - @Override public void destroy() { + @Override + public void destroy() { birtEngine.destroy(); Platform.shutdown(); } diff --git a/spring-boot-mvc-birt/src/main/resources/log4j.properties b/spring-boot-mvc-birt/src/main/resources/log4j.properties index e311956c2f..60d6bdd765 100644 --- a/spring-boot-mvc-birt/src/main/resources/log4j.properties +++ b/spring-boot-mvc-birt/src/main/resources/log4j.properties @@ -2,5 +2,5 @@ log4j.rootLogger=DEBUG, STDOUT log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout log4j.appender.STDOUT.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n -log4j.logger.org.springframework=debug +log4j.logger.org.springframework=info log4j.logger.org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener=info \ No newline at end of file