use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testSkipAndAssignAutomaticRoleOnPositionAfterChange.
@Test
public void testSkipAndAssignAutomaticRoleOnPositionAfterChange() {
IdmTreeNodeDto otherNode = getHelper().createTreeNode();
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.NO, true);
// create identity with contract on node
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmContractPositionDto position = getHelper().createContractPosition(getHelper().getPrimeContract(identity), otherNode);
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
position.setWorkPosition(node.getId());
EntityEvent<IdmContractPositionDto> event = new ContractPositionEvent(ContractPositionEventType.UPDATE, position);
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
position = contractPositionService.publish(event).getContent();
UUID positionId = position.getId();
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
filter.setOwnerType(entityStateManager.getOwnerType(IdmContractPositionDto.class));
List<IdmEntityStateDto> skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertTrue(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(positionId)));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
// recount skipped automatic roles
longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor());
skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(automaticRole.getId())));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testChangeContractValidityWithAssignedRoles.
@Test
public void testChangeContractValidityWithAssignedRoles() {
getHelper().setConfigurationValue(EventConfiguration.PROPERTY_EVENT_ASYNCHRONOUS_ENABLED, false);
prepareAutomaticRoles();
//
// prepare identity and contract
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = new IdmIdentityContractDto();
contract.setIdentity(identity.getId());
contract.setValidFrom(LocalDate.now().minusDays(1));
contract.setValidTill(LocalDate.now().plusMonths(1));
contract.setWorkPosition(nodeD.getId());
contract = service.save(contract);
//
// test after create
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
assertEquals(3, identityRoles.size());
for (IdmIdentityRoleDto identityRole : identityRoles) {
assertEquals(contract.getValidFrom(), identityRole.getValidFrom());
assertEquals(contract.getValidTill(), identityRole.getValidTill());
}
;
// test after change
contract.setValidFrom(LocalDate.now().minusDays(2));
contract.setValidTill(LocalDate.now().plusMonths(4));
contract = service.save(contract);
identityRoles = identityRoleService.findAllByContract(contract.getId());
assertEquals(3, identityRoles.size());
for (IdmIdentityRoleDto identityRole : identityRoles) {
assertEquals(contract.getValidFrom(), identityRole.getValidFrom());
assertEquals(contract.getValidTill(), identityRole.getValidTill());
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testSkipAndAssignAutomaticRoleOnContractAfterChange.
@Test
public void testSkipAndAssignAutomaticRoleOnContractAfterChange() {
IdmTreeNodeDto otherNode = getHelper().createTreeNode();
IdmTreeNodeDto node = getHelper().createTreeNode();
// define automatic role for parent
IdmRoleDto role = getHelper().createRole();
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(role, node, RecursionType.NO, true);
// create identity with contract on node
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().createContract(identity, otherNode);
// no role should be assigned now
List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
contract.setWorkPosition(node.getId());
EntityEvent<IdmIdentityContractDto> event = new IdentityContractEvent(IdentityContractEventType.UPDATE, contract);
event.getProperties().put(AutomaticRoleManager.SKIP_RECALCULATION, Boolean.TRUE);
contract = service.publish(event).getContent();
UUID contractId = contract.getId();
IdmEntityStateFilter filter = new IdmEntityStateFilter();
filter.setStates(Lists.newArrayList(OperationState.BLOCKED));
filter.setResultCode(CoreResultCode.AUTOMATIC_ROLE_SKIPPED.getCode());
filter.setOwnerType(entityStateManager.getOwnerType(IdmIdentityContractDto.class));
List<IdmEntityStateDto> skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.isEmpty());
Assert.assertTrue(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(contractId)));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertTrue(assignedRoles.isEmpty());
//
// recount skipped automatic roles
longRunningTaskManager.execute(new ProcessSkippedAutomaticRoleByTreeForContractTaskExecutor());
skippedStates = entityStateManager.findStates(filter, null).getContent();
Assert.assertFalse(skippedStates.stream().anyMatch(s -> s.getOwnerId().equals(automaticRole.getId())));
//
assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
Assert.assertEquals(1, assignedRoles.size());
Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testChangeContractPositionWithAutomaticRolesAssigned.
@Test
public void testChangeContractPositionWithAutomaticRolesAssigned() {
prepareAutomaticRoles();
//
// prepare identity and contract
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = new IdmIdentityContractDto();
contract.setIdentity(identity.getId());
contract.setWorkPosition(nodeD.getId());
contract = service.save(contract);
//
// test after create
List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contract.getId());
assertEquals(3, identityRoles.size());
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleA.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleB.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleC.getId().equals(ir.getRole());
}));
//
contract.setWorkPosition(nodeE.getId());
contract = service.save(contract);
//
// test after change
identityRoles = identityRoleService.findAllByContract(contract.getId());
assertEquals(3, identityRoles.size());
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleA.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleB.getId().equals(ir.getRole());
}));
Assert.assertTrue(identityRoles.stream().anyMatch(ir -> {
return roleD.getId().equals(ir.getRole());
}));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmIdentityContractServiceIntegrationTest method testAssingRoleForContractValidInTheFuture.
@Test
public void testAssingRoleForContractValidInTheFuture() {
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
//
IdmIdentityContractDto contractD = new IdmIdentityContractDto();
contractD.setIdentity(identity.getId());
contractD.setWorkPosition(nodeD.getId());
contractD.setValidFrom(LocalDate.now().plusDays(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(1, identityRoles.size());
assertEquals(automaticRoleD.getId(), identityRoles.get(0).getAutomaticRole());
}
Aggregations