Search in sources :

Example 1 with RptRenderedReportDto

use of eu.bcvsolutions.idm.rpt.api.dto.RptRenderedReportDto in project CzechIdMng by bcvsolutions.

the class RptReportController method renderReport.

@ResponseBody
@RequestMapping(value = "/{backendId}/render", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> renderReport(@ApiParam(value = "Report's uuid identifier.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Renderer's identifier.", required = true) @RequestParam(required = true, name = "renderer") @NotNull String rendererName) {
    // 
    RptReportDto report = getDto(backendId);
    if (report == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    try {
        RptRenderedReportDto result = reportManager.render(report, rendererName);
        InputStream is = result.getRenderedReport();
        // 
        String reportName = report.getExecutorName() + "-" + report.getCreated().toString("yyyyMMddHHmmss");
        return ResponseEntity.ok().contentLength(is.available()).contentType(result.getRenderer().getFormat()).header(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=\"%s.%s\"", reportName, result.getRenderer().getExtension())).body(new InputStreamResource(is));
    } catch (Exception ex) {
        throw new ResultCodeException(CoreResultCode.INTERNAL_SERVER_ERROR, ex);
    }
}
Also used : RptRenderedReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptRenderedReportDto) InputStream(java.io.InputStream) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) InputStreamResource(org.springframework.core.io.InputStreamResource) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with RptRenderedReportDto

use of eu.bcvsolutions.idm.rpt.api.dto.RptRenderedReportDto in project CzechIdMng by bcvsolutions.

the class DefaultReportManager method render.

@Override
public RptRenderedReportDto render(RptReportDto report, String rendererName) {
    Assert.notNull(report);
    Assert.hasLength(rendererName);
    // 
    ReportRenderer renderer = reportRendererRegistry.getPluginFor(rendererName);
    if (renderer == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("reportRenderer", rendererName));
    }
    // 
    RptRenderedReportDto result = new RptRenderedReportDto();
    result.setInputReport(report);
    result.setRenderer(toDto(renderer));
    result.setRenderedReport(renderer.render(report));
    return result;
}
Also used : RptRenderedReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptRenderedReportDto) ReportRenderer(eu.bcvsolutions.idm.rpt.api.renderer.ReportRenderer) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Example 3 with RptRenderedReportDto

use of eu.bcvsolutions.idm.rpt.api.dto.RptRenderedReportDto in project CzechIdMng by bcvsolutions.

the class DefaultRptReportManagerIntegrationTest method testRenderReportAsJson.

@Test
public void testRenderReportAsJson() throws IOException {
    TestReportExecutor testReportExecutor = context.getAutowireCapableBeanFactory().createBean(TestReportExecutor.class);
    RptReportDto report = testReportExecutor.generate(new RptReportDto(UUID.randomUUID()));
    RptRenderedReportDto renderedData = manager.render(report, TestReportRenderer.RENDERER_NAME);
    // 
    Assert.assertEquals(mapper.writeValueAsString(TestReportExecutor.identities), IOUtils.toString(renderedData.getRenderedReport()));
}
Also used : RptRenderedReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptRenderedReportDto) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

RptRenderedReportDto (eu.bcvsolutions.idm.rpt.api.dto.RptRenderedReportDto)3 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 RptReportDto (eu.bcvsolutions.idm.rpt.api.dto.RptReportDto)2 ReportRenderer (eu.bcvsolutions.idm.rpt.api.renderer.ReportRenderer)1 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)1 InputStream (java.io.InputStream)1 Test (org.junit.Test)1 InputStreamResource (org.springframework.core.io.InputStreamResource)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1