use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testDontAssingRoleForContractValidInThePast.
@Test
public void testDontAssingRoleForContractValidInThePast() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
//
IdmIdentityContractDto contractD = new IdmIdentityContractDto();
contractD.setIdentity(identity.getId());
contractD.setWorkPosition(nodeD.getId());
contractD.setValidTill(LocalDate.now().minusDays(1));
contractD = service.save(contractD);
//
// create new automatic role
automaticRoleD = new IdmRoleTreeNodeDto();
automaticRoleD.setRecursionType(RecursionType.NO);
automaticRoleD.setRole(roleA.getId());
automaticRoleD.setTreeNode(nodeD.getId());
automaticRoleD = saveAutomaticRole(automaticRoleD, true);
//
// check
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contractD.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto 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.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityRoleServiceIntegrationTest method testDeduplicationWithConceptWithRemovedRole.
@Test
public void testDeduplicationWithConceptWithRemovedRole() {
IdmIdentityDto identity = getHelper().createIdentity(new GuardedString());
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
IdmRoleDto role = getHelper().createRole();
IdmIdentityRoleDto one = getHelper().createIdentityRole(identity, role, null, null);
List<IdmConceptRoleRequestDto> concepts = new ArrayList<IdmConceptRoleRequestDto>();
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setRole(role.getId());
concept.setIdentityContract(contract.getId());
concept.setOperation(ConceptRoleRequestOperation.ADD);
Map<String, BaseDto> embedded = concept.getEmbedded();
embedded.put(IdmConceptRoleRequest_.identityContract.getName(), contract);
concept.setEmbedded(embedded);
concepts.add(concept);
List<IdmConceptRoleRequestDto> removeDuplicities = roleRequestService.removeDuplicities(concepts, identity.getId());
// concept is duplicit with one
assertTrue(removeDuplicities.isEmpty());
concepts = new ArrayList<IdmConceptRoleRequestDto>();
concept.setDuplicate(null);
concept.setDuplicates(null);
concepts.add(concept);
IdmConceptRoleRequestDto conceptWithremove = new IdmConceptRoleRequestDto();
conceptWithremove.setOperation(ConceptRoleRequestOperation.REMOVE);
conceptWithremove.setIdentityContract(contract.getId());
conceptWithremove.setIdentityRole(one.getId());
embedded = conceptWithremove.getEmbedded();
embedded.put(IdmConceptRoleRequest_.identityContract.getName(), contract);
conceptWithremove.setEmbedded(embedded);
concepts.add(conceptWithremove);
removeDuplicities = roleRequestService.removeDuplicities(concepts, identity.getId());
// role will be removed
assertFalse(removeDuplicities.isEmpty());
assertEquals(2, removeDuplicities.size());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityRoleServiceIntegrationTest method testDeduplicationWithConceptAndEav.
@Test
public void testDeduplicationWithConceptAndEav() {
IdmIdentityDto identity = getHelper().createIdentity(new GuardedString());
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
IdmRoleDto role = createRoleWithAttributes(prepareAttributeOne());
IdmIdentityRoleDto one = getHelper().createIdentityRole(identity, role, LocalDate.now().minusDays(10), LocalDate.now().plusDays(10));
IdmIdentityRoleDto two = getHelper().createIdentityRole(identity, role, LocalDate.now().plusDays(15), LocalDate.now().plusDays(40));
one = fillEavs(one);
two = fillEavs(two);
List<IdmFormInstanceDto> formInstances = service.getFormInstances(one);
IdmFormValueDto valueFromOne = formInstances.get(0).getValues().get(0);
IdmFormAttributeDto formAttributeDto = DtoUtils.getEmbedded(valueFromOne, IdmFormValue_.formAttribute, IdmFormAttributeDto.class);
IdmIdentityRoleDto duplicated = service.getDuplicated(one, two, null);
assertNull(duplicated);
List<IdmConceptRoleRequestDto> concepts = new ArrayList<IdmConceptRoleRequestDto>();
IdmConceptRoleRequestDto concept = new IdmConceptRoleRequestDto();
concept.setRole(role.getId());
concept.setIdentityContract(contract.getId());
concept.setValidFrom(LocalDate.now().minusDays(9));
concept.setValidTill(LocalDate.now().plusDays(9));
concept.setOperation(ConceptRoleRequestOperation.ADD);
Map<String, BaseDto> embedded = concept.getEmbedded();
embedded.put(IdmConceptRoleRequest_.identityContract.getName(), contract);
concept.setEmbedded(embedded);
concepts.add(concept);
List<IdmConceptRoleRequestDto> removeDuplicities = roleRequestService.removeDuplicities(concepts, identity.getId());
// EAVs for concept missing
assertFalse(removeDuplicities.isEmpty());
concepts = new ArrayList<IdmConceptRoleRequestDto>();
IdmFormInstanceDto instance = new IdmFormInstanceDto();
IdmFormValueDto value = new IdmFormValueDto(formAttributeDto);
value.setValue(Long.valueOf(System.currentTimeMillis()));
instance.setValues(Lists.newArrayList(value));
concept.setEavs(Lists.newArrayList(instance));
concepts.add(concept);
removeDuplicities = roleRequestService.removeDuplicities(concepts, identity.getId());
// EAVs for concept is different
assertFalse(removeDuplicities.isEmpty());
concepts = new ArrayList<IdmConceptRoleRequestDto>();
value = new IdmFormValueDto(formAttributeDto);
value.setValue(ATTRIBUTE_ONE_DEFAULT_VALUE);
instance.setValues(Lists.newArrayList(value));
concept.setEavs(Lists.newArrayList(instance));
concepts.add(concept);
removeDuplicities = roleRequestService.removeDuplicities(concepts, identity.getId());
// EAVs are same
assertTrue(removeDuplicities.isEmpty());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testChangeContractPositionAndValidityWithAutomaticRolesAssigned.
@Test
public void testChangeContractPositionAndValidityWithAutomaticRolesAssigned() {
prepareAutomaticRoles();
//
// prepare identity and contract
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = new IdmIdentityContractDto();
contract.setIdentity(identity.getId());
contract.setWorkPosition(nodeD.getId());
LocalDate validTill = LocalDate.now().plusDays(1);
contract.setValidTill(validTill);
contract = service.save(contract);
//
// test after create
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
IdmIdentityRoleDto automaticRole = identityRoles.stream().filter(ir -> {
return roleA.getId().equals(ir.getRole());
}).findFirst().orElse(null);
Assert.assertNotNull(automaticRole);
Assert.assertEquals(validTill, automaticRole.getValidTill());
//
// => role A is the same => down recursion
contract.setWorkPosition(nodeB.getId());
LocalDate newValidTill = LocalDate.now().plusDays(3);
contract.setValidTill(newValidTill);
contract = service.save(contract);
//
// test after change
identityRoles = identityRoleService.findAllByContract(contract.getId());
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleA.getId().equals(ir.getRole()) && // prevent drop and create
ir.getId().equals(automaticRole.getId()) && // validity is changed
newValidTill.equals(ir.getValidTill());
}));
}
Aggregations