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);
}
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()));
}
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);
}
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);
}
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());
}
Aggregations