Search in sources :

Example 6 with RptIdentityRoleByRoleDeduplicationDto

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

the class IdentityRoleByIdentityDeduplicationExecutorTest method testExecuteReportOneContractMoreRoles.

@Test
public void testExecuteReportOneContractMoreRoles() throws JsonParseException, JsonMappingException, IOException {
    String roleCode = "test-" + System.currentTimeMillis();
    IdmTreeNodeDto treeNode = getHelper().createTreeNode();
    IdmIdentityDto identity = getHelper().createIdentity(new GuardedString());
    IdmIdentityContractDto contact = getHelper().createContract(identity, treeNode);
    IdmRoleDto role = getHelper().createRole(roleCode);
    getHelper().createIdentityRole(contact, role);
    getHelper().createIdentityRole(contact, role);
    getHelper().createIdentityRole(contact, role);
    getHelper().createIdentityRole(contact, role);
    RptReportDto report = new RptReportDto(UUID.randomUUID());
    report.setExecutorName(reportExecutor.getName());
    IdmFormDto filter = new IdmFormDto();
    IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
    IdmFormValueDto treeNodeParameter = new IdmFormValueDto(definition.getMappedAttributeByCode(IdentityRoleByIdentityDeduplicationExecutor.PARAMETER_TREE_NODE));
    treeNodeParameter.setValue(treeNode.getId());
    filter.getValues().add(treeNodeParameter);
    filter.setFormDefinition(definition.getId());
    report.setFilter(filter);
    report = reportExecutor.generate(report);
    Assert.assertNotNull(report.getData());
    List<RptIdentityRoleByRoleDeduplicationDto> reportItems = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<RptIdentityRoleByRoleDeduplicationDto>>() {
    });
    assertEquals(1, reportItems.size());
    RptIdentityRoleByRoleDeduplicationDto item = reportItems.get(0);
    List<RptIdentityRoleByRoleDeduplicationDuplicityDto> duplicities = item.getDuplicity();
    assertEquals(3, duplicities.size());
    for (RptIdentityRoleByRoleDeduplicationDuplicityDto duplicity : duplicities) {
        assertEquals(role.getId(), duplicity.getRole().getId());
    }
    attachmentManager.deleteAttachments(report);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) RptIdentityRoleByRoleDeduplicationDuplicityDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDuplicityDto) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) RptIdentityRoleByRoleDeduplicationDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) List(java.util.List) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 7 with RptIdentityRoleByRoleDeduplicationDto

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

the class IdentityRoleByIdentityDeduplicationExecutorTest method testExecuteReportTwoContract.

@Test
public void testExecuteReportTwoContract() throws JsonParseException, JsonMappingException, IOException {
    String roleCode = "test-" + System.currentTimeMillis();
    IdmTreeNodeDto treeNode = getHelper().createTreeNode();
    IdmIdentityDto identity = getHelper().createIdentity(new GuardedString());
    IdmIdentityContractDto contactOne = getHelper().createContract(identity, treeNode);
    IdmIdentityContractDto contactTwo = getHelper().createContract(identity, treeNode);
    IdmRoleDto role = getHelper().createRole(roleCode);
    getHelper().createIdentityRole(contactOne, role);
    getHelper().createIdentityRole(contactOne, role);
    getHelper().createIdentityRole(contactTwo, role);
    getHelper().createIdentityRole(contactTwo, role);
    RptReportDto report = new RptReportDto(UUID.randomUUID());
    report.setExecutorName(reportExecutor.getName());
    IdmFormDto filter = new IdmFormDto();
    IdmFormDefinitionDto definition = reportExecutor.getFormDefinition();
    IdmFormValueDto treeNodeParameter = new IdmFormValueDto(definition.getMappedAttributeByCode(IdentityRoleByIdentityDeduplicationExecutor.PARAMETER_TREE_NODE));
    treeNodeParameter.setValue(treeNode.getId());
    filter.getValues().add(treeNodeParameter);
    filter.setFormDefinition(definition.getId());
    report.setFilter(filter);
    report = reportExecutor.generate(report);
    Assert.assertNotNull(report.getData());
    List<RptIdentityRoleByRoleDeduplicationDto> reportItems = mapper.readValue(attachmentManager.getAttachmentData(report.getData()), new TypeReference<List<RptIdentityRoleByRoleDeduplicationDto>>() {
    });
    assertEquals(2, reportItems.size());
    for (RptIdentityRoleByRoleDeduplicationDto item : reportItems) {
        assertNotNull(item.getIdentity());
        assertEquals(identity.getId(), item.getIdentity().getId());
        assertNotNull(item.getWorkPosition());
        assertEquals(treeNode.getId(), item.getWorkPosition().getId());
        assertNotNull(item.getIdentityContract());
        if (item.getIdentityContract().getId().equals(contactOne.getId())) {
        // Success
        } else if (item.getIdentityContract().getId().equals(contactTwo.getId())) {
        // Success
        } else {
            fail();
        }
        List<RptIdentityRoleByRoleDeduplicationDuplicityDto> duplicities = item.getDuplicity();
        assertEquals(1, duplicities.size());
    }
    attachmentManager.deleteAttachments(report);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) RptIdentityRoleByRoleDeduplicationDuplicityDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDuplicityDto) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) RptIdentityRoleByRoleDeduplicationDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) List(java.util.List) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 8 with RptIdentityRoleByRoleDeduplicationDto

use of eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDto 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

RptIdentityRoleByRoleDeduplicationDto (eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDto)8 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)7 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)7 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)7 RptIdentityRoleByRoleDeduplicationDuplicityDto (eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDuplicityDto)6 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)5 IdmFormDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto)5 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)5 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)5 RptReportDto (eu.bcvsolutions.idm.rpt.api.dto.RptReportDto)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 List (java.util.List)5 Test (org.junit.Test)5 IOException (java.io.IOException)2 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 JsonParser (com.fasterxml.jackson.core.JsonParser)1 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)1 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)1 ReportGenerateException (eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException)1