Search in sources :

Example 1 with ReportRenderException

use of eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException in project CzechIdMng by bcvsolutions.

the class IdentityReportRenderer method render.

@Override
public InputStream render(RptReportDto report) {
    try {
        // read json stream
        JsonParser jParser = getMapper().getFactory().createParser(getReportData(report));
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("Report");
        // header
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellValue("Id");
        cell = row.createCell(1);
        cell.setCellValue("Username");
        cell = row.createCell(2);
        cell.setCellValue("First name");
        cell = row.createCell(3);
        cell.setCellValue("Last name");
        cell = row.createCell(4);
        cell.setCellValue("Disabled");
        int rowNum = 1;
        // json is array of identities
        if (jParser.nextToken() == JsonToken.START_ARRAY) {
            // write single identity
            while (jParser.nextToken() == JsonToken.START_OBJECT) {
                IdmIdentityDto identity = getMapper().readValue(jParser, IdmIdentityDto.class);
                row = sheet.createRow(rowNum++);
                cell = row.createCell(0);
                cell.setCellValue(identity.getId().toString());
                cell = row.createCell(1);
                cell.setCellValue(identity.getUsername());
                cell = row.createCell(2);
                cell.setCellValue(identity.getFirstName());
                cell = row.createCell(3);
                cell.setCellValue(identity.getLastName());
                cell = row.createCell(4);
                cell.setCellValue(identity.isDisabled());
            }
        }
        // close json stream
        jParser.close();
        // close and return input stream
        return getInputStream(workbook);
    } catch (IOException ex) {
        throw new ReportRenderException(report.getName(), ex);
    }
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ReportRenderException(eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException) Row(org.apache.poi.ss.usermodel.Row) IOException(java.io.IOException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Cell(org.apache.poi.ss.usermodel.Cell) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 2 with ReportRenderException

use of eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException in project CzechIdMng by bcvsolutions.

the class IdentityReportXlsxRenderer method render.

@Override
public InputStream render(RptReportDto report) {
    try {
        // read json stream
        JsonParser jParser = getMapper().getFactory().createParser(getReportData(report));
        XSSFWorkbook workbook = new XSSFWorkbook();
        CreationHelper createHelper = workbook.getCreationHelper();
        XSSFSheet sheet = workbook.createSheet("Report");
        // header
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);
        cell.setCellValue("Username");
        cell = row.createCell(1);
        cell.setCellValue("First name");
        cell = row.createCell(2);
        cell.setCellValue("Last name");
        cell = row.createCell(3);
        cell.setCellValue("Disabled");
        int rowNum = 1;
        // json is array of identities
        if (jParser.nextToken() == JsonToken.START_ARRAY) {
            // write single identity
            while (jParser.nextToken() == JsonToken.START_OBJECT) {
                IdmIdentityDto identity = getMapper().readValue(jParser, IdmIdentityDto.class);
                row = sheet.createRow(rowNum++);
                cell = row.createCell(0);
                cell.setCellValue(identity.getUsername());
                cell = row.createCell(1);
                cell.setCellValue(identity.getFirstName());
                cell = row.createCell(2);
                cell.setCellValue(identity.getLastName());
                cell = row.createCell(3);
                cell.setCellValue(identity.isDisabled());
            }
        }
        // close json stream
        jParser.close();
        // 
        // footer info about more available reports
        rowNum++;
        rowNum++;
        row = sheet.createRow(rowNum++);
        cell = row.createCell(0);
        cell.setCellValue("More reports are available in reports module:");
        row = sheet.createRow(rowNum++);
        cell = row.createCell(0);
        cell.setCellValue("https://wiki.czechidm.com/devel/documentation/modules_reports");
        Hyperlink link = createHelper.createHyperlink(XSSFHyperlink.LINK_URL);
        link.setAddress("https://wiki.czechidm.com/devel/documentation/modules_reports");
        cell.setHyperlink(link);
        // close and return input stream
        return getInputStream(workbook);
    } catch (IOException ex) {
        throw new ReportRenderException(report.getName(), ex);
    }
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) ReportRenderException(eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException) Row(org.apache.poi.ss.usermodel.Row) IOException(java.io.IOException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Cell(org.apache.poi.ss.usermodel.Cell) JsonParser(com.fasterxml.jackson.core.JsonParser) XSSFHyperlink(org.apache.poi.xssf.usermodel.XSSFHyperlink) Hyperlink(org.apache.poi.ss.usermodel.Hyperlink)

Aggregations

JsonParser (com.fasterxml.jackson.core.JsonParser)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 ReportRenderException (eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException)2 IOException (java.io.IOException)2 Cell (org.apache.poi.ss.usermodel.Cell)2 Row (org.apache.poi.ss.usermodel.Row)2 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)2 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)2 CreationHelper (org.apache.poi.ss.usermodel.CreationHelper)1 Hyperlink (org.apache.poi.ss.usermodel.Hyperlink)1 XSSFHyperlink (org.apache.poi.xssf.usermodel.XSSFHyperlink)1