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);
}
}
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);
}
}
Aggregations