use of eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto in project CzechIdMng by bcvsolutions.
the class DelegationIntegrationTest method testDefaultTaskDelegationForMoreDelegates.
@Test
public void testDefaultTaskDelegationForMoreDelegates() {
// Enable approving of a role-request by manager.
getHelper().setConfigurationValue(ChangeIdentityPermissionTest.APPROVE_BY_MANAGER_ENABLE, true);
IdmRoleDto roleOne = getHelper().createRole();
IdmIdentityDto delegator = getHelper().createIdentity();
IdmIdentityDto delegateOne = getHelper().createIdentity();
IdmIdentityDto delegateTwo = getHelper().createIdentity();
IdmIdentityDto subordinate = getHelper().createIdentity();
IdmIdentityContractDto subordinateContract = getHelper().createContract(subordinate);
getHelper().createContractGuarantee(subordinateContract, delegator);
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setManagersByContract(subordinateContract.getId());
// Check if delegator is manager for subordinate.
boolean delegatorIsManager = getHelper().getService(IdmIdentityService.class).find(identityFilter, null).getContent().stream().filter(identity -> identity.getId().equals(delegator.getId())).findFirst().isPresent();
assertTrue(delegatorIsManager);
WorkflowFilterDto taskFilter = new WorkflowFilterDto();
taskFilter.setCandidateOrAssigned(delegator.getUsername());
List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(0, tasks.size());
// Assing role -> reuqest will be in progress state.
IdmRoleRequestDto roleRequest = getHelper().createRoleRequest(subordinateContract, ConceptRoleRequestOperation.ADD, roleOne);
roleRequest.setExecuteImmediately(false);
roleRequest = roleRequestService.save(roleRequest);
roleRequest = getHelper().executeRequest(roleRequest, false, true);
assertEquals(RoleRequestState.IN_PROGRESS, roleRequest.getState());
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(1, tasks.size());
List<IdentityLinkDto> identityLinks = tasks.get(0).getIdentityLinks();
assertEquals(1, identityLinks.size());
// Task is assigned to the delegator now.
assertEquals(delegator.getId(), UUID.fromString(identityLinks.get(0).getUserId()));
// Create default delegations.
IdmDelegationDefinitionDto definition = new IdmDelegationDefinitionDto();
definition.setType(DefaultDelegationType.NAME);
definition.setDelegator(delegator.getId());
definition.setDelegate(delegateOne.getId());
delegationDefinitionService.save(definition);
definition = new IdmDelegationDefinitionDto();
definition.setType(DefaultDelegationType.NAME);
definition.setDelegator(delegator.getId());
definition.setDelegate(delegateTwo.getId());
delegationDefinitionService.save(definition);
// Delete previous role-request.
roleRequestService.delete(roleRequest);
// Assing role -> reuqest will be in progress state.
roleRequest = getHelper().createRoleRequest(subordinateContract, ConceptRoleRequestOperation.ADD, roleOne);
roleRequest.setExecuteImmediately(false);
roleRequest = roleRequestService.save(roleRequest);
roleRequest = getHelper().executeRequest(roleRequest, false, true);
assertEquals(RoleRequestState.IN_PROGRESS, roleRequest.getState());
taskFilter.setCandidateOrAssigned(delegator.getUsername());
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
// Should be 0, because task is not assigned to the delegator anymore.
assertEquals(0, tasks.size());
// Login as delegate.
taskFilter.setCandidateOrAssigned(delegateOne.getUsername());
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(1, tasks.size());
taskFilter.setCandidateOrAssigned(delegateTwo.getUsername());
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(1, tasks.size());
identityLinks = tasks.get(0).getIdentityLinks();
assertEquals(3, identityLinks.size());
// Task have to be assigned to the delegate One now.
assertEquals(1, identityLinks.stream().filter(identityLink -> IdentityLinkType.CANDIDATE.equals(identityLink.getType())).filter(identityLink -> delegateOne.getId().equals(UUID.fromString(identityLink.getUserId()))).count());
// Task have to be assigned also to the delegate Two.
assertEquals(1, identityLinks.stream().filter(identityLink -> IdentityLinkType.CANDIDATE.equals(identityLink.getType())).filter(identityLink -> delegateOne.getId().equals(UUID.fromString(identityLink.getUserId()))).count());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto in project CzechIdMng by bcvsolutions.
the class DelegationIntegrationTest method testDelegationDefinitionFindByNotUsedType.
@Test
public void testDelegationDefinitionFindByNotUsedType() {
IdmIdentityDto delegator = getHelper().createIdentity();
IdmIdentityDto delegateOne = getHelper().createIdentity();
// Create default delegations.
IdmDelegationDefinitionDto definitionOne = new IdmDelegationDefinitionDto();
definitionOne.setType(ApproveRoleByManagerDelegationType.NAME);
definitionOne.setDelegator(delegator.getId());
definitionOne.setDelegate(delegateOne.getId());
delegationDefinitionService.save(definitionOne);
IdmDelegationDefinitionDto definitionTwo = new IdmDelegationDefinitionDto();
definitionTwo.setType(ApproveRoleByManagerDelegationType.NAME);
definitionTwo.setDelegator(delegator.getId());
definitionTwo.setDelegate(delegateOne.getId());
delegationDefinitionService.save(definitionTwo);
List<IdmDelegationDefinitionDto> delegations = delegationManager.findDelegation(DefaultDelegationType.NAME, delegator.getId(), null, null);
// No delegations are valid for this delegator and this type.
Assert.assertNull(delegations);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto in project CzechIdMng by bcvsolutions.
the class DelegationIntegrationTest method testApprovingByRoleDirectManagerDelegation.
@Test
public void testApprovingByRoleDirectManagerDelegation() {
int priorityForApprovingByManager = 222;
getHelper().setConfigurationValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + priorityForApprovingByManager, ChangeIdentityPermissionTest.APPROVE_ROLE_BY_MANAGER_KEY);
IdmRoleDto role = getHelper().createRole(priorityForApprovingByManager);
IdmIdentityDto delegator = getHelper().createIdentity();
IdmIdentityContractDto delegatorContract = getHelper().createContract(delegator);
IdmIdentityDto delegateOne = getHelper().createIdentity();
IdmIdentityDto subordinate = getHelper().createIdentity();
IdmIdentityContractDto subordinateContract = getHelper().createContract(subordinate);
getHelper().createContractGuarantee(subordinateContract, delegator);
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setManagersByContract(subordinateContract.getId());
// Check if delegator is manager for subordinate.
boolean delegatorIsManager = getHelper().getService(IdmIdentityService.class).find(identityFilter, null).getContent().stream().filter(identity -> identity.getId().equals(delegator.getId())).findFirst().isPresent();
assertTrue(delegatorIsManager);
WorkflowFilterDto taskFilter = new WorkflowFilterDto();
taskFilter.setCandidateOrAssigned(delegator.getUsername());
List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(0, tasks.size());
// Assing role -> reuqest will be in progress state.
IdmRoleRequestDto roleRequest = getHelper().createRoleRequest(subordinateContract, ConceptRoleRequestOperation.ADD, role);
roleRequest.setExecuteImmediately(false);
roleRequest = roleRequestService.save(roleRequest);
roleRequest = getHelper().executeRequest(roleRequest, false, true);
assertEquals(RoleRequestState.IN_PROGRESS, roleRequest.getState());
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(1, tasks.size());
List<IdentityLinkDto> identityLinks = tasks.get(0).getIdentityLinks();
assertEquals(1, identityLinks.size());
// Task is assigned to the delegator now.
assertEquals(delegator.getId(), UUID.fromString(identityLinks.get(0).getUserId()));
// Create delegation for approving by role manager.
IdmDelegationDefinitionDto definition = new IdmDelegationDefinitionDto();
definition.setType(ApproveRoleByManagerDelegationType.NAME);
definition.setDelegator(delegator.getId());
definition.setDelegatorContract(delegatorContract.getId());
definition.setDelegate(delegateOne.getId());
delegationDefinitionService.save(definition);
// Delete previous role-request.
roleRequestService.delete(roleRequest);
// Assing role -> reuqest will be in progress state.
roleRequest = getHelper().createRoleRequest(subordinateContract, ConceptRoleRequestOperation.ADD, role);
roleRequest.setExecuteImmediately(false);
roleRequest = roleRequestService.save(roleRequest);
roleRequest = getHelper().executeRequest(roleRequest, false, true);
assertEquals(RoleRequestState.IN_PROGRESS, roleRequest.getState());
taskFilter.setCandidateOrAssigned(delegator.getUsername());
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
// Should be 0, because task is not assigned to the delegator anymore.
assertEquals(0, tasks.size());
// Login as delegate.
taskFilter.setCandidateOrAssigned(delegateOne.getUsername());
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(1, tasks.size());
identityLinks = tasks.get(0).getIdentityLinks();
assertEquals(2, identityLinks.size());
// Task have to be assigned to the delegate now.
assertEquals(delegateOne.getId(), UUID.fromString(identityLinks.stream().filter(identityLink -> IdentityLinkType.CANDIDATE.equals(identityLink.getType())).findFirst().get().getUserId()));
// Task must contains original delegator as prticipant (right to the task in the audit).
assertEquals(delegator.getId(), UUID.fromString(identityLinks.stream().filter(identityLink -> IdentityLinkType.PARTICIPANT.equals(identityLink.getType())).findFirst().get().getUserId()));
// Set configuration to null.
getHelper().setConfigurationValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + priorityForApprovingByManager, null);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto in project CzechIdMng by bcvsolutions.
the class DelegationIntegrationTest method testDelegationDefinitionIntegrity.
@Test
public void testDelegationDefinitionIntegrity() {
IdmIdentityDto delegator = getHelper().createIdentity();
IdmIdentityDto delegateOne = getHelper().createIdentity();
// Create default delegations and delegations.
IdmDelegationDefinitionDto definitionOne = new IdmDelegationDefinitionDto();
definitionOne.setType(ApproveRoleByManagerDelegationType.NAME);
definitionOne.setDelegator(delegator.getId());
definitionOne.setDelegate(delegateOne.getId());
definitionOne = delegationDefinitionService.save(definitionOne);
IdmDelegationDto delegationOne = new IdmDelegationDto();
delegationOne.setDefinition(definitionOne.getId());
delegationOne.setOwnerId(UUID.randomUUID());
delegationOne.setOwnerType(WorkflowTaskInstanceDto.class.getCanonicalName());
delegationOne = delegationService.save(delegationOne);
IdmDelegationDto delegationTwo = new IdmDelegationDto();
delegationTwo.setDefinition(definitionOne.getId());
delegationTwo.setOwnerId(UUID.randomUUID());
delegationTwo.setOwnerType(WorkflowTaskInstanceDto.class.getCanonicalName());
delegationTwo = delegationService.save(delegationTwo);
// Delegations shuld be deleted on delete of the definition.
delegationDefinitionService.delete(definitionOne);
IdmDelegationDto delegation = delegationService.get(delegationOne.getId());
Assert.assertNull(delegation);
delegation = delegationService.get(delegationTwo.getId());
Assert.assertNull(delegation);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto in project CzechIdMng by bcvsolutions.
the class DelegationIntegrationTest method testDefaultTaskDelegation.
/**
* Green line test.
*/
@Test
public void testDefaultTaskDelegation() {
// Enable approving of a role-request by manager.
getHelper().setConfigurationValue(ChangeIdentityPermissionTest.APPROVE_BY_MANAGER_ENABLE, true);
IdmRoleDto roleOne = getHelper().createRole();
IdmIdentityDto delegator = getHelper().createIdentity();
IdmIdentityDto delegate = getHelper().createIdentity();
IdmIdentityDto subordinate = getHelper().createIdentity();
IdmIdentityContractDto subordinateContract = getHelper().createContract(subordinate);
getHelper().createContractGuarantee(subordinateContract, delegator);
IdmIdentityFilter identityFilter = new IdmIdentityFilter();
identityFilter.setManagersByContract(subordinateContract.getId());
// Check if delegator is manager for subordinate.
boolean delegatorIsManager = getHelper().getService(IdmIdentityService.class).find(identityFilter, null).getContent().stream().filter(identity -> identity.getId().equals(delegator.getId())).findFirst().isPresent();
assertTrue(delegatorIsManager);
WorkflowFilterDto taskFilter = new WorkflowFilterDto();
taskFilter.setCandidateOrAssigned(delegator.getUsername());
List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(0, tasks.size());
// Assing role -> reuqest will be in progress state.
IdmRoleRequestDto roleRequest = getHelper().createRoleRequest(subordinateContract, ConceptRoleRequestOperation.ADD, roleOne);
roleRequest.setExecuteImmediately(false);
roleRequest = roleRequestService.save(roleRequest);
roleRequest = getHelper().executeRequest(roleRequest, false, true);
assertEquals(RoleRequestState.IN_PROGRESS, roleRequest.getState());
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(1, tasks.size());
List<IdentityLinkDto> identityLinks = tasks.get(0).getIdentityLinks();
assertEquals(1, identityLinks.size());
// Task is assigned to the delegator now.
assertEquals(delegator.getId(), UUID.fromString(identityLinks.get(0).getUserId()));
// Create default delegation.
IdmDelegationDefinitionDto definition = new IdmDelegationDefinitionDto();
definition.setType(DefaultDelegationType.NAME);
definition.setDelegator(delegator.getId());
definition.setDelegate(delegate.getId());
delegationDefinitionService.save(definition);
// Delete previous role-request.
roleRequestService.delete(roleRequest);
// Assing role -> reuqest will be in progress state.
roleRequest = getHelper().createRoleRequest(subordinateContract, ConceptRoleRequestOperation.ADD, roleOne);
roleRequest.setExecuteImmediately(false);
roleRequest = roleRequestService.save(roleRequest);
roleRequest = getHelper().executeRequest(roleRequest, false, true);
assertEquals(RoleRequestState.IN_PROGRESS, roleRequest.getState());
taskFilter.setCandidateOrAssigned(delegator.getUsername());
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
// Should be 0, because task is not assigned to the delegator anymore.
assertEquals(0, tasks.size());
// Login as delegate.
taskFilter.setCandidateOrAssigned(delegate.getUsername());
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(1, tasks.size());
identityLinks = tasks.get(0).getIdentityLinks();
assertEquals(2, identityLinks.size());
// Task have to be assigned to the delegate now.
assertEquals(delegate.getId(), UUID.fromString(identityLinks.stream().filter(identityLink -> IdentityLinkType.CANDIDATE.equals(identityLink.getType())).findFirst().get().getUserId()));
// Task must contains original delegator as prticipant (right to the task in the audit).
assertEquals(delegator.getId(), UUID.fromString(identityLinks.stream().filter(identityLink -> IdentityLinkType.PARTICIPANT.equals(identityLink.getType())).findFirst().get().getUserId()));
}
Aggregations