Search in sources :

Example 76 with WorkflowTaskInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto 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 77 with WorkflowTaskInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto 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)

Example 78 with WorkflowTaskInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.

the class RequestManagerTest method testChangeRoleWithDirectGuaranteeType.

@Test
public void testChangeRoleWithDirectGuaranteeType() {
    // Guarantee type -> set to null (default value).
    getHelper().setConfigurationValue("idm.sec.core.request.idm-role.approval.guarantee-type", null);
    String guaranteeTypeOne = getHelper().createName();
    String guaranteeTypeTwo = getHelper().createName();
    // Create role with guarantee
    IdmIdentityDto guaranteeOne = getHelper().createIdentity();
    IdmIdentityDto guaranteeTwo = getHelper().createIdentity();
    IdmRoleDto changedRole = getHelper().createRole();
    getHelper().createRoleGuarantee(changedRole, guaranteeOne, guaranteeTypeOne);
    getHelper().createRoleGuarantee(changedRole, guaranteeTwo, guaranteeTypeTwo);
    // Create request
    IdmRequestDto request = createRequest(changedRole);
    // Start request
    IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
    Assert.assertNotNull(executedRequest);
    executedRequest = requestService.get(executedRequest.getId());
    // Role has guarantee, approval process must be started
    Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
    WorkflowFilterDto taskFilter = new WorkflowFilterDto();
    taskFilter.setProcessInstanceId(executedRequest.getWfProcessId());
    List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
    Assert.assertEquals(1, tasks.size());
    WorkflowTaskInstanceDto workflowTaskInstanceDto = tasks.get(0);
    List<IdentityLinkDto> candidates = workflowTaskInstanceDto.getIdentityLinks().stream().filter(identityLinkDto -> IdentityLinkType.CANDIDATE.equals(identityLinkDto.getType())).collect(Collectors.toList());
    Assert.assertEquals(2, candidates.size());
    Assert.assertTrue(candidates.stream().anyMatch(candidate -> guaranteeOne.getId().toString().equals(candidate.getUserId())));
    Assert.assertTrue(candidates.stream().anyMatch(candidate -> guaranteeTwo.getId().toString().equals(candidate.getUserId())));
    // Guarantee type -> set to guaranteeTypeOne.
    getHelper().setConfigurationValue("idm.sec.core.request.idm-role.approval.guarantee-type", guaranteeTypeOne);
    // Create request for guarantee type ONE.
    request = createRequest(changedRole);
    // Start request
    executedRequest = requestManager.startRequest(request.getId(), true);
    Assert.assertNotNull(executedRequest);
    executedRequest = requestService.get(executedRequest.getId());
    // Role has guarantee, approval process must be started
    Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
    taskFilter = new WorkflowFilterDto();
    taskFilter.setProcessInstanceId(executedRequest.getWfProcessId());
    tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
    Assert.assertEquals(1, tasks.size());
    workflowTaskInstanceDto = tasks.get(0);
    candidates = workflowTaskInstanceDto.getIdentityLinks().stream().filter(identityLinkDto -> IdentityLinkType.CANDIDATE.equals(identityLinkDto.getType())).collect(Collectors.toList());
    Assert.assertEquals(1, candidates.size());
    Assert.assertTrue(candidates.stream().anyMatch(candidate -> guaranteeOne.getId().toString().equals(candidate.getUserId())));
    // Guarantee type -> set to guaranteeTypeTwo.
    getHelper().setConfigurationValue("idm.sec.core.request.idm-role.approval.guarantee-type", guaranteeTypeTwo);
    // Create request for guarantee type TWO.
    request = createRequest(changedRole);
    // Start request
    executedRequest = requestManager.startRequest(request.getId(), true);
    Assert.assertNotNull(executedRequest);
    executedRequest = requestService.get(executedRequest.getId());
    // Role has guarantee, approval process must be started
    Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
    taskFilter = new WorkflowFilterDto();
    requestService.get(executedRequest.getId());
    taskFilter.setProcessInstanceId(executedRequest.getWfProcessId());
    tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
    Assert.assertEquals(1, tasks.size());
    workflowTaskInstanceDto = tasks.get(0);
    candidates = workflowTaskInstanceDto.getIdentityLinks().stream().filter(identityLinkDto -> IdentityLinkType.CANDIDATE.equals(identityLinkDto.getType())).collect(Collectors.toList());
    Assert.assertEquals(1, candidates.size());
    Assert.assertTrue(candidates.stream().anyMatch(candidate -> guaranteeTwo.getId().toString().equals(candidate.getUserId())));
    // Clear after test:
    // Guarantee type -> set to null (default value).
    getHelper().setConfigurationValue("idm.sec.core.request.idm-role.approval.guarantee-type", null);
}
Also used : RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) Assert.fail(org.junit.Assert.fail) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) Before(org.junit.Before) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) IdmRoleGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmRoleGuaranteeService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) RequestManager(eu.bcvsolutions.idm.core.api.service.RequestManager) Test(org.junit.Test) IdmRequestItemChangesDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemService(eu.bcvsolutions.idm.core.api.service.IdmRequestItemService) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) IdmRoleGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeFilter) Assert(org.junit.Assert) IdmRequestService(eu.bcvsolutions.idm.core.api.service.IdmRequestService) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 79 with WorkflowTaskInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.

the class RequestManagerTest method testChangeRoleWithGuaranteeTypeByRole.

@Test
public void testChangeRoleWithGuaranteeTypeByRole() {
    // Guarantee type -> set to null (default value).
    getHelper().setConfigurationValue("idm.sec.core.request.idm-role.approval.guarantee-type", null);
    String guaranteeTypeOne = getHelper().createName();
    String guaranteeTypeTwo = getHelper().createName();
    // Create role with guarantee
    IdmIdentityDto guaranteeOne = getHelper().createIdentity();
    IdmIdentityDto guaranteeTwo = getHelper().createIdentity();
    IdmRoleDto roleOne = getHelper().createRole();
    IdmRoleDto roleTwo = getHelper().createRole();
    getHelper().createIdentityRole(guaranteeOne, roleOne);
    getHelper().createIdentityRole(guaranteeTwo, roleTwo);
    IdmRoleDto changedRole = getHelper().createRole();
    getHelper().createRoleGuaranteeRole(changedRole, roleOne, guaranteeTypeOne);
    getHelper().createRoleGuaranteeRole(changedRole, roleTwo, guaranteeTypeTwo);
    // Create request
    IdmRequestDto request = createRequest(changedRole);
    // Start request
    IdmRequestDto executedRequest = requestManager.startRequest(request.getId(), true);
    Assert.assertNotNull(executedRequest);
    executedRequest = requestService.get(executedRequest.getId());
    // Role has guarantee, approval process must be started
    Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
    WorkflowFilterDto taskFilter = new WorkflowFilterDto();
    taskFilter.setProcessInstanceId(executedRequest.getWfProcessId());
    List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
    Assert.assertEquals(1, tasks.size());
    WorkflowTaskInstanceDto workflowTaskInstanceDto = tasks.get(0);
    List<IdentityLinkDto> candidates = workflowTaskInstanceDto.getIdentityLinks().stream().filter(identityLinkDto -> IdentityLinkType.CANDIDATE.equals(identityLinkDto.getType())).collect(Collectors.toList());
    Assert.assertEquals(2, candidates.size());
    Assert.assertTrue(candidates.stream().anyMatch(candidate -> guaranteeOne.getId().toString().equals(candidate.getUserId())));
    Assert.assertTrue(candidates.stream().anyMatch(candidate -> guaranteeTwo.getId().toString().equals(candidate.getUserId())));
    // Guarantee type -> set to guaranteeTypeOne.
    getHelper().setConfigurationValue("idm.sec.core.request.idm-role.approval.guarantee-type", guaranteeTypeOne);
    // Create request for guarantee type ONE.
    request = createRequest(changedRole);
    // Start request
    executedRequest = requestManager.startRequest(request.getId(), true);
    Assert.assertNotNull(executedRequest);
    executedRequest = requestService.get(executedRequest.getId());
    // Role has guarantee, approval process must be started
    Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
    taskFilter = new WorkflowFilterDto();
    taskFilter.setProcessInstanceId(executedRequest.getWfProcessId());
    tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
    Assert.assertEquals(1, tasks.size());
    workflowTaskInstanceDto = tasks.get(0);
    candidates = workflowTaskInstanceDto.getIdentityLinks().stream().filter(identityLinkDto -> IdentityLinkType.CANDIDATE.equals(identityLinkDto.getType())).collect(Collectors.toList());
    Assert.assertEquals(1, candidates.size());
    Assert.assertTrue(candidates.stream().anyMatch(candidate -> guaranteeOne.getId().toString().equals(candidate.getUserId())));
    // Guarantee type -> set to guaranteeTypeTwo.
    getHelper().setConfigurationValue("idm.sec.core.request.idm-role.approval.guarantee-type", guaranteeTypeTwo);
    // Create request for guarantee type TWO.
    request = createRequest(changedRole);
    // Start request
    executedRequest = requestManager.startRequest(request.getId(), true);
    Assert.assertNotNull(executedRequest);
    executedRequest = requestService.get(executedRequest.getId());
    // Role has guarantee, approval process must be started
    Assert.assertEquals(RequestState.IN_PROGRESS, executedRequest.getState());
    taskFilter = new WorkflowFilterDto();
    requestService.get(executedRequest.getId());
    taskFilter.setProcessInstanceId(executedRequest.getWfProcessId());
    tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
    Assert.assertEquals(1, tasks.size());
    workflowTaskInstanceDto = tasks.get(0);
    candidates = workflowTaskInstanceDto.getIdentityLinks().stream().filter(identityLinkDto -> IdentityLinkType.CANDIDATE.equals(identityLinkDto.getType())).collect(Collectors.toList());
    Assert.assertEquals(1, candidates.size());
    Assert.assertTrue(candidates.stream().anyMatch(candidate -> guaranteeTwo.getId().toString().equals(candidate.getUserId())));
    // Clear after test:
    // Guarantee type -> set to null (default value).
    getHelper().setConfigurationValue("idm.sec.core.request.idm-role.approval.guarantee-type", null);
}
Also used : RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) WorkflowProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowProcessInstanceDto) Autowired(org.springframework.beans.factory.annotation.Autowired) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdentityLinkType(org.activiti.engine.task.IdentityLinkType) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) After(org.junit.After) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) WorkflowTaskInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) Assert.fail(org.junit.Assert.fail) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) Before(org.junit.Before) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) IdmRoleGuaranteeService(eu.bcvsolutions.idm.core.api.service.IdmRoleGuaranteeService) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) RequestManager(eu.bcvsolutions.idm.core.api.service.RequestManager) Test(org.junit.Test) IdmRequestItemChangesDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRequestItemService(eu.bcvsolutions.idm.core.api.service.IdmRequestItemService) IdmRequestItemAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemAttributeDto) IdmRoleGuaranteeFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleGuaranteeFilter) Assert(org.junit.Assert) IdmRequestService(eu.bcvsolutions.idm.core.api.service.IdmRequestService) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test)

Example 80 with WorkflowTaskInstanceDto

use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.

the class ManualWorkflowTaskDelegationBulkActionTest method testBulkActionCheckDelegateNotification.

@Test
public void testBulkActionCheckDelegateNotification() {
    // 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 subordinate = getHelper().createIdentity();
    IdmIdentityContractDto subordinateContract = getHelper().createContract(subordinate);
    getHelper().createContractGuarantee(subordinateContract, delegator);
    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()));
    IdmBulkActionDto bulkAction = this.findBulkActionForDto(WorkflowTaskInstanceAbstractDto.class, ManualWorkflowTaskDelegationBulkAction.NAME);
    Set<UUID> ids = Sets.newHashSet();
    ids.add(UUID.fromString(tasks.get(0).getId()));
    IdmIdentityDto delegate = getHelper().createIdentity();
    bulkAction.setIdentifiers(ids);
    bulkAction.getProperties().put(ManualWorkflowTaskDelegationBulkAction.DELEGATE_ATTRIBUTE, delegate.getId());
    bulkAction.getProperties().put(ManualWorkflowTaskDelegationBulkAction.CANDIDATE_OR_ASSIGNED_FILTER_FIELD, delegator.getId());
    IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
    checkResultLrt(processAction, 1l, null, null);
    // Notification to the delegate should been sent.
    IdmNotificationFilter filter = new IdmNotificationFilter();
    filter.setRecipient(delegate.getUsername());
    filter.setNotificationType(IdmNotificationLog.class);
    List<IdmNotificationLogDto> notifications = notificationLogService.find(filter, null).getContent();
    assertEquals(1, notifications.size());
    assertEquals(CoreModuleDescriptor.TOPIC_DELEGATION_INSTANCE_CREATED_TO_DELEGATE, notifications.get(0).getTopic());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) IdentityLinkDto(eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test) ChangeIdentityPermissionTest(eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest)

Aggregations

WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)81 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)69 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)63 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)56 Test (org.junit.Test)56 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)55 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)54 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)49 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)48 ZonedDateTime (java.time.ZonedDateTime)43 List (java.util.List)39 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)28 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)28 UUID (java.util.UUID)17 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)12 IdentityLinkDto (eu.bcvsolutions.idm.core.workflow.model.dto.IdentityLinkDto)12 WorkflowTaskInstanceService (eu.bcvsolutions.idm.core.workflow.service.WorkflowTaskInstanceService)12 Autowired (org.springframework.beans.factory.annotation.Autowired)12 IdentityLinkType (org.activiti.engine.task.IdentityLinkType)11 WorkflowHistoricTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)9