Search in sources :

Example 21 with IdmDelegationDefinitionDto

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());
}
Also used : DelegationManager(eu.bcvsolutions.idm.core.api.service.DelegationManager) DefaultDelegationType(eu.bcvsolutions.idm.core.model.delegation.type.DefaultDelegationType) Autowired(org.springframework.beans.factory.annotation.Autowired) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) ApproveRoleByManagerDelegationType(eu.bcvsolutions.idm.core.model.delegation.type.ApproveRoleByManagerDelegationType) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) Before(org.junit.Before) IdmDelegationDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IdmDelegationService(eu.bcvsolutions.idm.core.api.service.IdmDelegationService) UUID(java.util.UUID) ChangeIdentityPermissionTest(eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LocalDate(java.time.LocalDate) IdmDelegationDefinitionService(eu.bcvsolutions.idm.core.api.service.IdmDelegationDefinitionService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) Assert(org.junit.Assert) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) ChangeIdentityPermissionTest(eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest)

Example 22 with IdmDelegationDefinitionDto

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);
}
Also used : IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) ChangeIdentityPermissionTest(eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest)

Example 23 with IdmDelegationDefinitionDto

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);
}
Also used : DelegationManager(eu.bcvsolutions.idm.core.api.service.DelegationManager) DefaultDelegationType(eu.bcvsolutions.idm.core.model.delegation.type.DefaultDelegationType) Autowired(org.springframework.beans.factory.annotation.Autowired) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) ApproveRoleByManagerDelegationType(eu.bcvsolutions.idm.core.model.delegation.type.ApproveRoleByManagerDelegationType) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) Before(org.junit.Before) IdmDelegationDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IdmDelegationService(eu.bcvsolutions.idm.core.api.service.IdmDelegationService) UUID(java.util.UUID) ChangeIdentityPermissionTest(eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LocalDate(java.time.LocalDate) IdmDelegationDefinitionService(eu.bcvsolutions.idm.core.api.service.IdmDelegationDefinitionService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) Assert(org.junit.Assert) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) ChangeIdentityPermissionTest(eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest)

Example 24 with IdmDelegationDefinitionDto

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);
}
Also used : IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmDelegationDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) ChangeIdentityPermissionTest(eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest)

Example 25 with IdmDelegationDefinitionDto

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()));
}
Also used : DelegationManager(eu.bcvsolutions.idm.core.api.service.DelegationManager) DefaultDelegationType(eu.bcvsolutions.idm.core.model.delegation.type.DefaultDelegationType) Autowired(org.springframework.beans.factory.annotation.Autowired) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) ApproveRoleByManagerDelegationType(eu.bcvsolutions.idm.core.model.delegation.type.ApproveRoleByManagerDelegationType) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) Before(org.junit.Before) IdmDelegationDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) RoleRequestState(eu.bcvsolutions.idm.core.api.domain.RoleRequestState) IdmDelegationService(eu.bcvsolutions.idm.core.api.service.IdmDelegationService) UUID(java.util.UUID) ChangeIdentityPermissionTest(eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LocalDate(java.time.LocalDate) IdmDelegationDefinitionService(eu.bcvsolutions.idm.core.api.service.IdmDelegationDefinitionService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) Assert(org.junit.Assert) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) ConceptRoleRequestOperation(eu.bcvsolutions.idm.core.api.domain.ConceptRoleRequestOperation) Assert.assertEquals(org.junit.Assert.assertEquals) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) ChangeIdentityPermissionTest(eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest)

Aggregations

IdmDelegationDefinitionDto (eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto)28 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)18 Test (org.junit.Test)14 UUID (java.util.UUID)11 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)10 List (java.util.List)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 IdmDelegationDto (eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto)9 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)8 IdmDelegationDefinitionService (eu.bcvsolutions.idm.core.api.service.IdmDelegationDefinitionService)8 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)8 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)7 DefaultDelegationType (eu.bcvsolutions.idm.core.model.delegation.type.DefaultDelegationType)7 ChangeIdentityPermissionTest (eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest)7 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)7 Assert (org.junit.Assert)7 CoreGroupPermission (eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission)6 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)6 AbstractEvaluatorIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)6