BAEL-617: final checks and fixes

This commit is contained in:
Gian Mario Contessa 2019-03-31 12:18:14 +01:00
parent 89f55177f4
commit 74c9c3f6f1
7 changed files with 18 additions and 34 deletions

View File

@ -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");
}

View File

@ -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<Report> 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);
}
}

View File

@ -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
}
}

View File

@ -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();
}

View File

@ -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