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