Search in sources :

Example 1 with DuplicateRolesDto

use of eu.bcvsolutions.idm.core.api.dto.DuplicateRolesDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityRoleServiceIntegrationTest method testMarkDuplicatesOneConceptOneIdentityRole.

@Test
public void testMarkDuplicatesOneConceptOneIdentityRole() {
    IdmIdentityDto identity = this.getHelper().createIdentity((GuardedString) null);
    IdmRoleDto role = this.getHelper().createRole();
    IdmIdentityContractDto contract = this.getHelper().getPrimeContract(identity);
    IdmIdentityRoleDto identityRole = this.getHelper().createIdentityRole(contract, role, null, LocalDate.now().plusDays(5));
    IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
    concept.setRole(role.getId());
    concept.setIdentityContract(contract.getId());
    Map<String, BaseDto> embedded = concept.getEmbedded();
    embedded.put(IdmConceptRoleRequest_.identityContract.getName(), contract);
    concept.setEmbedded(embedded);
    concept.setOperation(ConceptRoleRequestOperation.ADD);
    List<IdmConceptRoleRequestDto> duplicates = roleRequestService.markDuplicates(Lists.newArrayList(concept), Lists.newArrayList(identityRole));
    assertEquals(1, duplicates.size());
    DuplicateRolesDto duplicateWithRoles = duplicates.get(0).getDuplicates();
    assertFalse(concept.getDuplicate());
    assertTrue(duplicateWithRoles.getIdentityRoles().isEmpty());
    assertTrue(duplicateWithRoles.getConcepts().isEmpty());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) DuplicateRolesDto(eu.bcvsolutions.idm.core.api.dto.DuplicateRolesDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 2 with DuplicateRolesDto

use of eu.bcvsolutions.idm.core.api.dto.DuplicateRolesDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityRoleServiceIntegrationTest method testMarkDuplicatesBothSame.

@Test
public void testMarkDuplicatesBothSame() {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmRoleDto role = getHelper().createRole();
    IdmIdentityContractDto contract = getHelper().createContract(identity);
    UUID roleId = role.getId();
    UUID contractId = contract.getId();
    IdmConceptRoleRequestDto conceptOne = new IdmConceptRoleRequestDto();
    conceptOne.setId(UUID.randomUUID());
    conceptOne.setRole(roleId);
    conceptOne.setIdentityContract(contractId);
    Map<String, BaseDto> embedded = conceptOne.getEmbedded();
    embedded.put(IdmConceptRoleRequest_.identityContract.getName(), contract);
    conceptOne.setEmbedded(embedded);
    conceptOne.setOperation(ConceptRoleRequestOperation.ADD);
    IdmConceptRoleRequestDto conceptTwo = new IdmConceptRoleRequestDto();
    conceptTwo.setId(UUID.randomUUID());
    conceptTwo.setRole(roleId);
    embedded = conceptTwo.getEmbedded();
    embedded.put(IdmConceptRoleRequest_.identityContract.getName(), contract);
    conceptTwo.setEmbedded(embedded);
    conceptTwo.setIdentityContract(contractId);
    conceptTwo.setOperation(ConceptRoleRequestOperation.ADD);
    List<IdmConceptRoleRequestDto> duplicates = roleRequestService.markDuplicates(Lists.newArrayList(conceptOne, conceptTwo), Lists.newArrayList());
    assertEquals(2, duplicates.size());
    // Both concepts are same. Duplicates is controlled by order in list
    for (IdmConceptRoleRequestDto concept : duplicates) {
        if (concept.getId().equals(conceptOne.getId())) {
            assertFalse(concept.getDuplicate());
        } else if (concept.getId().equals(conceptTwo.getId())) {
            DuplicateRolesDto duplicateWithRoles = concept.getDuplicates();
            assertTrue(concept.getDuplicate());
            assertTrue(duplicateWithRoles.getIdentityRoles().isEmpty());
            assertFalse(duplicateWithRoles.getConcepts().isEmpty());
            assertEquals(1, duplicateWithRoles.getConcepts().size());
            UUID duplicatedId = duplicateWithRoles.getConcepts().get(0);
            assertEquals(conceptOne.getId(), duplicatedId);
        } else {
            fail();
        }
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) DuplicateRolesDto(eu.bcvsolutions.idm.core.api.dto.DuplicateRolesDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with DuplicateRolesDto

use of eu.bcvsolutions.idm.core.api.dto.DuplicateRolesDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityRoleServiceIntegrationTest method testMarkDuplicatesBetweenConcepts.

@Test
public void testMarkDuplicatesBetweenConcepts() {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmRoleDto role = getHelper().createRole();
    IdmRoleDto secondRole = getHelper().createRole();
    IdmIdentityContractDto contract = getHelper().createContract(identity);
    UUID roleId = role.getId();
    UUID contractId = contract.getId();
    IdmConceptRoleRequestDto conceptOne = new IdmConceptRoleRequestDto();
    conceptOne.setId(UUID.randomUUID());
    conceptOne.setRole(roleId);
    conceptOne.setIdentityContract(contractId);
    Map<String, BaseDto> embedded = conceptOne.getEmbedded();
    embedded.put(IdmConceptRoleRequest_.identityContract.getName(), contract);
    conceptOne.setEmbedded(embedded);
    conceptOne.setOperation(ConceptRoleRequestOperation.ADD);
    conceptOne.setValidFrom(LocalDate.now().minusDays(20));
    conceptOne.setValidTill(LocalDate.now().plusDays(20));
    IdmConceptRoleRequestDto conceptTwo = new IdmConceptRoleRequestDto();
    conceptTwo.setId(UUID.randomUUID());
    conceptTwo.setRole(roleId);
    embedded = conceptTwo.getEmbedded();
    embedded.put(IdmConceptRoleRequest_.identityContract.getName(), contract);
    conceptTwo.setEmbedded(embedded);
    conceptTwo.setIdentityContract(contractId);
    conceptTwo.setOperation(ConceptRoleRequestOperation.ADD);
    conceptTwo.setValidFrom(LocalDate.now().minusDays(5));
    conceptTwo.setValidTill(LocalDate.now().plusDays(15));
    IdmConceptRoleRequestDto conceptThrid = new IdmConceptRoleRequestDto();
    conceptThrid.setId(UUID.randomUUID());
    conceptThrid.setRole(roleId);
    embedded = conceptThrid.getEmbedded();
    embedded.put(IdmConceptRoleRequest_.identityContract.getName(), contract);
    conceptThrid.setEmbedded(embedded);
    conceptThrid.setIdentityContract(contractId);
    conceptThrid.setOperation(ConceptRoleRequestOperation.ADD);
    conceptThrid.setValidFrom(LocalDate.now().plusDays(50));
    conceptThrid.setValidTill(LocalDate.now().plusDays(100));
    IdmConceptRoleRequestDto conceptFour = new IdmConceptRoleRequestDto();
    conceptFour.setId(UUID.randomUUID());
    conceptFour.setRole(secondRole.getId());
    embedded = conceptFour.getEmbedded();
    embedded.put(IdmConceptRoleRequest_.identityContract.getName(), contract);
    conceptFour.setEmbedded(embedded);
    conceptFour.setIdentityContract(contractId);
    conceptFour.setOperation(ConceptRoleRequestOperation.ADD);
    conceptFour.setValidFrom(LocalDate.now().minusDays(10));
    conceptFour.setValidTill(LocalDate.now().plusDays(2));
    List<IdmConceptRoleRequestDto> duplicates = roleRequestService.markDuplicates(Lists.newArrayList(conceptOne, conceptTwo, conceptThrid, conceptFour), Lists.newArrayList());
    assertEquals(4, duplicates.size());
    for (IdmConceptRoleRequestDto concept : duplicates) {
        if (concept.getId().equals(conceptOne.getId())) {
            assertFalse(concept.getDuplicate());
        } else if (concept.getId().equals(conceptTwo.getId())) {
            DuplicateRolesDto duplicateWithRoles = concept.getDuplicates();
            assertTrue(concept.getDuplicate());
            assertTrue(duplicateWithRoles.getIdentityRoles().isEmpty());
            assertFalse(duplicateWithRoles.getConcepts().isEmpty());
            assertEquals(1, duplicateWithRoles.getConcepts().size());
            UUID duplicatedId = duplicateWithRoles.getConcepts().get(0);
            assertEquals(conceptOne.getId(), duplicatedId);
        } else if (concept.getId().equals(conceptThrid.getId())) {
            assertFalse(concept.getDuplicate());
        } else if (concept.getId().equals(conceptFour.getId())) {
            assertFalse(concept.getDuplicate());
        } else {
            fail();
        }
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) DuplicateRolesDto(eu.bcvsolutions.idm.core.api.dto.DuplicateRolesDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with DuplicateRolesDto

use of eu.bcvsolutions.idm.core.api.dto.DuplicateRolesDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleRequestService method markDuplicatesInConcepts.

private void markDuplicatesInConcepts(List<IdmConceptRoleRequestDto> concepts) {
    // Compare conceptOne with conceptTwo
    for (IdmConceptRoleRequestDto conceptOne : concepts) {
        // Only add or modification will be processed
        if (conceptOne.getOperation() == ConceptRoleRequestOperation.REMOVE) {
            // REMOVE concept can't be duplicated
            conceptOne.setDuplicate(Boolean.FALSE);
            continue;
        }
        // role and contract can be removed in the mean time
        if (conceptOne.getRole() == null || conceptOne.getIdentityContract() == null) {
            conceptOne.setDuplicate(Boolean.FALSE);
            continue;
        }
        if (BooleanUtils.isTrue(conceptOne.getDuplicate())) {
            continue;
        }
        IdmIdentityRoleDto identityRoleOne = this.createTempIdentityRole(conceptOne);
        // check duplicates for concept
        for (IdmConceptRoleRequestDto conceptTwo : concepts) {
            // Only add or modification will be processed
            if (conceptTwo.getOperation() == ConceptRoleRequestOperation.REMOVE) {
                // REMOVE concept can be duplicated
                conceptTwo.setDuplicate(Boolean.FALSE);
                continue;
            }
            if (BooleanUtils.isTrue(conceptTwo.getDuplicate())) {
                continue;
            }
            // concept.
            if (conceptOne == conceptTwo) {
                continue;
            }
            IdmIdentityRoleDto identityRoleTwo = this.createTempIdentityRole(conceptTwo);
            // Get duplicated must be quick, because the method doesn't made query to
            // database
            IdmIdentityRoleDto duplicated = identityRoleService.getDuplicated(identityRoleOne, identityRoleTwo, Boolean.FALSE);
            if (duplicated == identityRoleOne) {
                // When is duplicate same as identityRoleOne set ID of concept two
                DuplicateRolesDto duplicates = conceptOne.getDuplicates();
                duplicates.getConcepts().add(conceptTwo.getId());
                conceptOne.setDuplicate(Boolean.TRUE);
                conceptOne.setDuplicates(duplicates);
            } else if (duplicated == identityRoleTwo) {
                // When is duplicate same as identityRoleTwo set ID of concept one
                DuplicateRolesDto duplicates = conceptTwo.getDuplicates();
                duplicates.getConcepts().add(conceptOne.getId());
                conceptTwo.setDuplicate(Boolean.TRUE);
                conceptTwo.setDuplicates(duplicates);
            }
        }
        // If concept isn't marked as duplicated set him false
        if (BooleanUtils.isNotTrue(conceptOne.getDuplicate())) {
            conceptOne.setDuplicate(Boolean.FALSE);
        }
    }
}
Also used : DuplicateRolesDto(eu.bcvsolutions.idm.core.api.dto.DuplicateRolesDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)

Example 5 with DuplicateRolesDto

use of eu.bcvsolutions.idm.core.api.dto.DuplicateRolesDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleRequestService method markDuplicates.

@Override
public List<IdmConceptRoleRequestDto> markDuplicates(List<IdmConceptRoleRequestDto> concepts, List<IdmIdentityRoleDto> allByIdentity) {
    Assert.notNull(concepts, "Role request concepts are required.");
    // Check duplicates between concepts
    markDuplicatesInConcepts(concepts);
    // Split by role UUID
    Map<UUID, List<IdmIdentityRoleDto>> identityRolesByRole = allByIdentity.stream().collect(// Group identity roles by role
    Collectors.groupingBy(// 
    IdmIdentityRoleDto::getRole));
    // TODO: create hashMap with used roles (simple cache)
    for (IdmConceptRoleRequestDto concept : concepts) {
        // Only add or modification will be processed
        if (concept.getOperation() == ConceptRoleRequestOperation.REMOVE) {
            continue;
        }
        UUID roleId = concept.getRole();
        // Get all identity roles by role
        List<IdmIdentityRoleDto> identityRoles = identityRolesByRole.get(roleId);
        if (identityRoles == null) {
            continue;
        }
        // Create temporary identity role
        IdmIdentityRoleDto tempIdentityRole = createTempIdentityRole(concept);
        // Iterate over all identity roles, but only with same roles.
        for (IdmIdentityRoleDto identityRole : identityRoles) {
            // We must get eavs by service. This is expensive operation. But we need it.
            IdmFormInstanceDto instanceDto = identityRoleService.getRoleAttributeValues(identityRole);
            if (instanceDto != null) {
                identityRole.setEavs(Lists.newArrayList(instanceDto));
            }
            IdmIdentityRoleDto duplicated = identityRoleService.getDuplicated(tempIdentityRole, identityRole, Boolean.FALSE);
            // Duplicated is only when is object not null and hasn't filled ID. Identity role can't be duplicated with concept.
            if (duplicated != null && duplicated.getId() == null) {
                DuplicateRolesDto duplicates = concept.getDuplicates();
                duplicates.getIdentityRoles().add(identityRole.getId());
                concept.setDuplicates(duplicates);
                concept.setDuplicate(Boolean.TRUE);
            }
        }
    }
    return concepts;
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) DuplicateRolesDto(eu.bcvsolutions.idm.core.api.dto.DuplicateRolesDto) ArrayList(java.util.ArrayList) List(java.util.List) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) UUID(java.util.UUID) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)

Aggregations

DuplicateRolesDto (eu.bcvsolutions.idm.core.api.dto.DuplicateRolesDto)6 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)6 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)4 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)4 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4 Test (org.junit.Test)4 UUID (java.util.UUID)3 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1