Search in sources :

Example 1 with RptIdentityRoleByRoleDeduplicationDto

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

the class IdentityRoleByIdentityDeduplicationExecutorTest method testExecuteReportOneContractMoreRolesWithValidity.

@Test
public void testExecuteReportOneContractMoreRolesWithValidity() 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, LocalDate.now().minusDays(40), LocalDate.now().plusDays(40));
    getHelper().createIdentityRole(contact, role, LocalDate.now().minusDays(30), LocalDate.now().plusDays(30));
    getHelper().createIdentityRole(contact, role, LocalDate.now().minusDays(20), LocalDate.now().plusDays(20));
    getHelper().createIdentityRole(contact, role, LocalDate.now().minusDays(10), LocalDate.now().plusDays(10));
    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());
        if (duplicity.getValidTill().isEqual(duplicity.getValidFrom())) {
            fail();
        }
        if (!duplicity.getValidTill().isBefore(LocalDate.now().plusDays(35))) {
            fail();
        }
        if (!duplicity.getValidFrom().isAfter(LocalDate.now().minusDays(35))) {
            fail();
        }
    }
    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 2 with RptIdentityRoleByRoleDeduplicationDto

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

the class IdentityRoleByIdentityDeduplicationExecutorTest method testExecuteReportTwoContractNoDuplicity.

@Test
public void testExecuteReportTwoContractNoDuplicity() 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(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(0, reportItems.size());
    attachmentManager.deleteAttachments(report);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) 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 3 with RptIdentityRoleByRoleDeduplicationDto

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

the class IdentityRoleByIdentityDeduplicationExecutorTest method testExecuteReportOneContract.

@Test
public void testExecuteReportOneContract() 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);
    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);
    assertNotNull(item.getIdentity());
    assertEquals(identity.getId(), item.getIdentity().getId());
    assertNotNull(item.getWorkPosition());
    assertEquals(treeNode.getId(), item.getWorkPosition().getId());
    assertNotNull(item.getIdentityContract());
    assertEquals(contact.getId(), item.getIdentityContract().getId());
    List<RptIdentityRoleByRoleDeduplicationDuplicityDto> duplicities = item.getDuplicity();
    assertEquals(1, duplicities.size());
    RptIdentityRoleByRoleDeduplicationDuplicityDto duplicity = duplicities.get(0);
    assertNotNull(duplicity.getRole());
    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 4 with RptIdentityRoleByRoleDeduplicationDto

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

the class IdentityRoleByIdentityDeduplicationExecutor method createRecordForContracts.

/**
 * Create new record to report for given contract.
 *
 * @param contract
 * @return
 */
private RptIdentityRoleByRoleDeduplicationDto createRecordForContracts(IdmIdentityContractDto contract) {
    List<IdmIdentityRoleDto> duplicityIdentityRoles = deduplicationBulkAction.getDuplicatesIdentityRoleForContract(contract);
    if (duplicityIdentityRoles.isEmpty()) {
        return null;
    }
    List<RptIdentityRoleByRoleDeduplicationDuplicityDto> duplicity = new ArrayList<>(duplicityIdentityRoles.size());
    for (IdmIdentityRoleDto duplicityIdentityRole : duplicityIdentityRoles) {
        RptIdentityRoleByRoleDeduplicationDuplicityDto dupl = new RptIdentityRoleByRoleDeduplicationDuplicityDto();
        dupl.setValidFrom(duplicityIdentityRole.getValidFrom());
        dupl.setValidTill(duplicityIdentityRole.getValidTill());
        IdmRoleDto roleDto = DtoUtils.getEmbedded(duplicityIdentityRole, IdmIdentityRole_.role, IdmRoleDto.class, null);
        dupl.setRole(roleDto);
        duplicity.add(dupl);
    }
    RptIdentityRoleByRoleDeduplicationDto item = new RptIdentityRoleByRoleDeduplicationDto();
    IdmTreeNodeDto treeNodeDto = DtoUtils.getEmbedded(contract, IdmIdentityContract_.workPosition, IdmTreeNodeDto.class, null);
    IdmIdentityDto identityDto = DtoUtils.getEmbedded(contract, IdmIdentityContract_.identity, IdmIdentityDto.class, null);
    item.setIdentity(identityDto);
    item.setWorkPosition(treeNodeDto);
    item.setIdentityContract(contract);
    item.setDuplicity(duplicity);
    return item;
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) RptIdentityRoleByRoleDeduplicationDuplicityDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDuplicityDto) ArrayList(java.util.ArrayList) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) RptIdentityRoleByRoleDeduplicationDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDto)

Example 5 with RptIdentityRoleByRoleDeduplicationDto

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

the class IdentityRoleByIdentityDeduplicationExecutor method generateData.

@Override
protected IdmAttachmentDto generateData(RptReportDto report) {
    IdmIdentityFilter filter = new IdmIdentityFilter();
    UUID treeNode = getTreeNode(report);
    if (treeNode != null) {
        filter.setTreeNode(treeNode);
        filter.setRecursively(true);
    } else {
        LOG.info("Tree node id isn't filled. Report will be done for all identities.");
    }
    // prepare temp file for json stream
    File temp = getAttachmentManager().createTempFile();
    try (FileOutputStream outputStream = new FileOutputStream(temp)) {
        // write into json stream
        JsonGenerator jGenerator = getMapper().getFactory().createGenerator(outputStream, JsonEncoding.UTF8);
        try {
            // json will be array of identities
            jGenerator.writeStartArray();
            counter = 0L;
            List<UUID> identities = identityService.findIds(filter, null, IdmBasePermission.READ).getContent();
            if (count == null) {
                count = Long.valueOf(identities.size());
            }
            boolean canContinue = true;
            for (UUID identityId : identities) {
                List<IdmIdentityContractDto> contracts = identityContractService.findAllValidForDate(identityId, LocalDate.now(), null);
                for (IdmIdentityContractDto contract : contracts) {
                    RptIdentityRoleByRoleDeduplicationDto newRecord = createRecordForContracts(contract);
                    if (newRecord != null) {
                        getMapper().writeValue(jGenerator, newRecord);
                    }
                }
                ++counter;
                canContinue = updateState();
                if (!canContinue) {
                    break;
                }
            }
            // close array of identities
            jGenerator.writeEndArray();
        } finally {
            // close json stream
            jGenerator.close();
        }
        // save create temp file with array of identities in json as attachment
        return createAttachment(report, new FileInputStream(temp));
    } catch (IOException ex) {
        throw new ReportGenerateException(report.getName(), ex);
    } finally {
        FileUtils.deleteQuietly(temp);
    }
}
Also used : IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IOException(java.io.IOException) ReportGenerateException(eu.bcvsolutions.idm.rpt.api.exception.ReportGenerateException) RptIdentityRoleByRoleDeduplicationDto(eu.bcvsolutions.idm.rpt.dto.RptIdentityRoleByRoleDeduplicationDto) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) UUID(java.util.UUID) File(java.io.File) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

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