Search in sources :

Example 6 with RptIdentityRoleByRoleDeduplicationDuplicityDto

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

the class IdentityRoleByIdentityDeduplicationXlsxRenderer 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");
        sheet.setDefaultColumnWidth(15);
        XSSFFont headerFont = workbook.createFont();
        headerFont.setBold(true);
        headerFont.setFontHeightInPoints((short) 15);
        XSSFRichTextString headerColumn = new XSSFRichTextString();
        // header
        Row row = sheet.createRow(0);
        Cell cell = row.createCell(0);
        headerColumn = new XSSFRichTextString();
        headerColumn.append(StringUtils.capitalize(IdmIdentity_.username.getName()), headerFont);
        cell.setCellValue(headerColumn);
        headerColumn = new XSSFRichTextString();
        cell = row.createCell(1);
        headerColumn.append("Personal number", headerFont);
        cell.setCellValue(headerColumn);
        headerColumn = new XSSFRichTextString();
        cell = row.createCell(2);
        headerColumn.append(StringUtils.capitalize(IdmIdentity_.lastName.getName()), headerFont);
        cell.setCellValue(headerColumn);
        headerColumn = new XSSFRichTextString();
        cell = row.createCell(3);
        headerColumn.append(StringUtils.capitalize(IdmIdentity_.firstName.getName()), headerFont);
        cell.setCellValue(headerColumn);
        headerColumn = new XSSFRichTextString();
        cell = row.createCell(4);
        headerColumn.append("Contract", headerFont);
        cell.setCellValue(headerColumn);
        headerColumn = new XSSFRichTextString();
        cell = row.createCell(5);
        headerColumn.append("Duplicity", headerFont);
        cell.setCellValue(headerColumn);
        int rowNum = 1;
        // json is array of identities
        if (jParser.nextToken() == JsonToken.START_ARRAY) {
            // write single identity
            while (jParser.nextToken() == JsonToken.START_OBJECT) {
                RptIdentityRoleByRoleDeduplicationDto item = getMapper().readValue(jParser, RptIdentityRoleByRoleDeduplicationDto.class);
                IdmIdentityContractDto identityContract = item.getIdentityContract();
                IdmIdentityDto identity = item.getIdentity();
                StringBuilder duplicityRow = new StringBuilder();
                for (RptIdentityRoleByRoleDeduplicationDuplicityDto duplicity : item.getDuplicity()) {
                    IdmRoleDto roleDto = duplicity.getRole();
                    duplicityRow.append(roleDto.getName());
                    duplicityRow.append(" (");
                    duplicityRow.append(roleDto.getCode());
                    duplicityRow.append(')');
                    duplicityRow.append(" [");
                    duplicityRow.append(ObjectUtils.nullSafeToString(duplicity.getValidFrom()));
                    duplicityRow.append(" - ");
                    duplicityRow.append(ObjectUtils.nullSafeToString(duplicity.getValidTill()));
                    duplicityRow.append(']');
                    duplicityRow.append(System.lineSeparator());
                }
                StringBuilder contract = new StringBuilder();
                contract.append(ObjectUtils.nullSafeToString(identityContract.getPosition()));
                contract.append(" [");
                contract.append(ObjectUtils.nullSafeToString(identityContract.getValidFrom()));
                contract.append(" - ");
                contract.append(ObjectUtils.nullSafeToString(identityContract.getValidTill()));
                contract.append("] ");
                contract.append(System.lineSeparator());
                contract.append(StringUtils.capitalize(IdmIdentityContract_.workPosition.getName()));
                contract.append(": ");
                StringBuilder treeNode = new StringBuilder("null");
                if (item.getWorkPosition() != null) {
                    IdmTreeNodeDto treeNodeDto = item.getWorkPosition();
                    // Just for sure
                    if (treeNodeDto == null) {
                        treeNode = new StringBuilder(identityContract.getWorkPosition().toString());
                    } else {
                        treeNode = new StringBuilder();
                        treeNode.append(treeNodeDto.getName());
                        treeNode.append(" (");
                        treeNode.append(treeNodeDto.getCode());
                        treeNode.append(')');
                    }
                }
                contract.append(treeNode.toString());
                row = sheet.createRow(rowNum++);
                cell = row.createCell(0);
                cell.setCellValue(identity.getUsername());
                cell = row.createCell(1);
                cell.setCellValue(identity.getExternalCode());
                cell = row.createCell(2);
                cell.setCellValue(identity.getLastName());
                cell = row.createCell(3);
                cell.setCellValue(identity.getFirstName());
                cell = row.createCell(4);
                cell.setCellValue(contract.toString());
                cell = row.createCell(5);
                cell.setCellValue(duplicityRow.toString());
            }
        }
        // close json stream
        jParser.close();
        for (int index = 0; index < 6; index++) {
            sheet.autoSizeColumn(index);
        }
        // close and return input stream
        return getInputStream(workbook);
    } catch (IOException ex) {
        throw new ReportRenderException(report.getName(), ex);
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) RptIdentityRoleByRoleDeduplicationDuplicityDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDuplicityDto) ReportRenderException(eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IOException(java.io.IOException) RptIdentityRoleByRoleDeduplicationDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDto) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Row(org.apache.poi.ss.usermodel.Row) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Cell(org.apache.poi.ss.usermodel.Cell) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)6 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)6 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)6 RptIdentityRoleByRoleDeduplicationDto (eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDto)6 RptIdentityRoleByRoleDeduplicationDuplicityDto (eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDuplicityDto)6 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)5 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)4 IdmFormDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto)4 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)4 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)4 RptReportDto (eu.bcvsolutions.idm.rpt.api.dto.RptReportDto)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4 List (java.util.List)4 Test (org.junit.Test)4 JsonParser (com.fasterxml.jackson.core.JsonParser)1 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)1 ReportRenderException (eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Cell (org.apache.poi.ss.usermodel.Cell)1