BAEL-617: final checks and fixes
This commit is contained in:
parent
89f55177f4
commit
74c9c3f6f1
|
@ -11,27 +11,26 @@ import org.springframework.boot.WebApplicationType;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@SpringBootApplication
|
@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}")
|
@Value("${reports.relative.path}")
|
||||||
private String REPORTS_FOLDER;
|
private String REPORTS_FOLDER;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
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 {
|
@Override public void run(String... args) throws Exception {
|
||||||
buildReport();
|
buildReport();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buildReport() throws IOException, BirtException {
|
private void buildReport() throws IOException, BirtException {
|
||||||
final DesignConfig config = new DesignConfig();
|
final DesignConfig config = new DesignConfig();
|
||||||
|
|
||||||
final IDesignEngine engine;
|
final IDesignEngine engine;
|
||||||
|
@ -63,40 +62,30 @@ public class ReportDesignHelper implements CommandLineRunner {
|
||||||
DesignElementHandle element = factory.newSimpleMasterPage("Page Master"); //$NON-NLS-1$
|
DesignElementHandle element = factory.newSimpleMasterPage("Page Master"); //$NON-NLS-1$
|
||||||
design.getMasterPages().add(element);
|
design.getMasterPages().add(element);
|
||||||
|
|
||||||
// Create a grid and add it to the "body" slot of the report
|
// Create a grid
|
||||||
// design.
|
|
||||||
|
|
||||||
GridHandle grid = factory.newGridItem(null, 2 /* cols */, 1 /* row */);
|
GridHandle grid = factory.newGridItem(null, 2 /* cols */, 1 /* row */);
|
||||||
design.getBody().add(grid);
|
design.getBody().add(grid);
|
||||||
|
grid.setWidth("100%");
|
||||||
// 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.
|
|
||||||
|
|
||||||
RowHandle row0 = (RowHandle) grid.getRows().get(0);
|
RowHandle row0 = (RowHandle) grid.getRows().get(0);
|
||||||
|
|
||||||
// Create an image and add it to the first cell.
|
// Create an image and add it to the first cell.
|
||||||
|
|
||||||
ImageHandle image = factory.newImage(null);
|
ImageHandle image = factory.newImage(null);
|
||||||
CellHandle cell = (CellHandle) row0.getCells().get(0);
|
CellHandle cell = (CellHandle) row0.getCells().get(0);
|
||||||
cell.getContent().add(image);
|
cell.getContent().add(image);
|
||||||
image.setURL("\"https://www.baeldung.com/wp-content/themes/baeldung/favicon/favicon-96x96.png\"");
|
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);
|
LabelHandle label = factory.newLabel(null);
|
||||||
cell = (CellHandle) row0.getCells().get(1);
|
cell = (CellHandle) row0.getCells().get(1);
|
||||||
cell.getContent().add(label);
|
cell.getContent().add(label);
|
||||||
label.setText("Hello, Baeldung world!");
|
label.setText("Hello, Baeldung world!");
|
||||||
|
|
||||||
|
|
||||||
// Save the design and close it.
|
// Save the design and close it.
|
||||||
File report = new File(REPORTS_FOLDER);
|
File report = new File(REPORTS_FOLDER);
|
||||||
report.mkdirs();
|
report.mkdirs();
|
||||||
|
|
||||||
design.saveAs(new File(report, "simple_static.rptdesign").getAbsolutePath());
|
design.saveAs(new File(report, "static_report.rptdesign").getAbsolutePath());
|
||||||
design.close();
|
design.close();
|
||||||
log.info("Report generated");
|
log.info("Report generated");
|
||||||
}
|
}
|
|
@ -12,7 +12,6 @@ import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
|
@ -22,9 +21,6 @@ public class BirtReportController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private BirtReportService reportService;
|
private BirtReportService reportService;
|
||||||
|
|
||||||
/**
|
|
||||||
* generate list of reports
|
|
||||||
*/
|
|
||||||
@RequestMapping(produces = "application/json", method = RequestMethod.GET, value = "/report")
|
@RequestMapping(produces = "application/json", method = RequestMethod.GET, value = "/report")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public List<Report> listReports() {
|
public List<Report> listReports() {
|
||||||
|
@ -44,16 +40,12 @@ public class BirtReportController {
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate full report
|
|
||||||
*/
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = "/report/{name}")
|
@RequestMapping(method = RequestMethod.GET, value = "/report/{name}")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public void generateFullReport(HttpServletResponse response, HttpServletRequest request,
|
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);
|
log.info("Generating full report: " + name);
|
||||||
OutputType format = OutputType.from(output);
|
OutputType format = OutputType.from(output);
|
||||||
reportService.generateMainReport(name, format, response, request);
|
reportService.generateMainReport(name, format, response, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,7 @@ package com.baeldung.birt.engine.dto;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +32,6 @@ public class Report {
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ParameterType {
|
public enum ParameterType {
|
||||||
INT, STRING;
|
INT, STRING
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ public class BirtReportService implements ApplicationContextAware, DisposableBea
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a report as html
|
* Generate a report as HTML
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private void generateHTMLReport(IReportRunnable report, HttpServletResponse response, HttpServletRequest request) {
|
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) {
|
private void generatePDFReport(IReportRunnable report, HttpServletResponse response, HttpServletRequest request) {
|
||||||
IRunAndRenderTask runAndRenderTask = birtEngine.createRunAndRenderTask(report);
|
IRunAndRenderTask runAndRenderTask = birtEngine.createRunAndRenderTask(report);
|
||||||
response.setContentType(birtEngine.getMIMEType("pdf"));
|
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();
|
birtEngine.destroy();
|
||||||
Platform.shutdown();
|
Platform.shutdown();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,5 +2,5 @@ log4j.rootLogger=DEBUG, STDOUT
|
||||||
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
|
log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender
|
||||||
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
|
log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout
|
||||||
log4j.appender.STDOUT.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
|
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
|
log4j.logger.org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener=info
|
Loading…
Reference in New Issue