use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class ChangeIdentityPermissionTest method testGetTaskByAnotherUser.
@Test
public void testGetTaskByAnotherUser() {
ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
getHelper().waitForResult(null, 1, 1);
configurationService.setValue(APPROVE_BY_SECURITY_ENABLE, "false");
configurationService.setValue(APPROVE_BY_MANAGER_ENABLE, "false");
configurationService.setValue(APPROVE_BY_HELPDESK_ENABLE, "true");
configurationService.setValue(APPROVE_BY_USERMANAGER_ENABLE, "false");
//
loginAsAdmin();
IdmIdentityDto test1 = getHelper().createIdentity();
IdmIdentityDto anotherUser = getHelper().createIdentity();
IdmRoleDto role = getHelper().createRole();
// helpdesk role and identity
IdmRoleDto helpdeskRole = getHelper().createRole();
IdmIdentityDto helpdeskIdentity = getHelper().createIdentity();
// add role directly
getHelper().createIdentityRole(helpdeskIdentity, helpdeskRole);
configurationService.setValue(APPROVE_BY_HELPDESK_ROLE, helpdeskRole.getCode());
IdmIdentityContractDto contract = getHelper().getPrimeContract(test1.getId());
// check task before create request
loginAsAdmin(test1.getUsername());
IdmRoleRequestDto request = createRoleRequest(test1);
request = roleRequestService.save(request);
IdmConceptRoleRequestDto concept = createRoleConcept(role, contract, request);
concept = conceptRoleRequestService.save(concept);
roleRequestService.startRequestInternal(request.getId(), true);
request = roleRequestService.get(request.getId());
assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
WorkflowFilterDto taskFilter = new WorkflowFilterDto();
taskFilter.setCreatedAfter(now);
taskFilter.setCandidateOrAssigned(securityService.getCurrentUsername());
List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(0, tasks.size());
// HELPDESK login
loginAsAdmin(helpdeskIdentity.getUsername());
taskFilter.setCandidateOrAssigned(helpdeskIdentity.getUsername());
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(1, tasks.size());
WorkflowTaskInstanceDto taskInstanceDto = tasks.get(0);
String id = taskInstanceDto.getId();
WorkflowTaskInstanceDto workflowTaskInstanceDto = workflowTaskInstanceService.get(id);
assertNotNull(workflowTaskInstanceDto);
// check task get by id
loginWithout(test1.getUsername(), IdmGroupPermission.APP_ADMIN, CoreGroupPermission.WORKFLOW_TASK_ADMIN);
workflowTaskInstanceDto = workflowTaskInstanceService.get(id);
assertNull(workflowTaskInstanceDto);
loginWithout(anotherUser.getUsername(), IdmGroupPermission.APP_ADMIN, CoreGroupPermission.WORKFLOW_TASK_ADMIN);
workflowTaskInstanceDto = workflowTaskInstanceService.get(id);
assertNull(workflowTaskInstanceDto);
// candidate
loginWithout(helpdeskIdentity.getUsername(), IdmGroupPermission.APP_ADMIN, CoreGroupPermission.WORKFLOW_TASK_ADMIN);
workflowTaskInstanceDto = workflowTaskInstanceService.get(id);
assertNotNull(workflowTaskInstanceDto);
// WF admin
loginWithout(InitTestDataProcessor.TEST_ADMIN_USERNAME, IdmGroupPermission.APP_ADMIN);
workflowTaskInstanceDto = workflowTaskInstanceService.get(id);
assertNotNull(workflowTaskInstanceDto);
// Attacker
loginWithout(anotherUser.getUsername(), IdmGroupPermission.APP_ADMIN, CoreGroupPermission.WORKFLOW_TASK_ADMIN);
taskFilter.setCandidateOrAssigned(helpdeskIdentity.getUsername());
try {
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
fail();
} catch (ResultCodeException ex) {
assertEquals(HttpStatus.FORBIDDEN, ex.getStatus());
} catch (Exception e) {
fail();
}
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class ChangeIdentityPermissionTest method testFindCandidatesWithSubprocess.
@Test
public void testFindCandidatesWithSubprocess() {
ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
getHelper().waitForResult(null, 1, 1);
// approve only by help desk
configurationService.setValue(APPROVE_BY_USERMANAGER_ENABLE, "false");
configurationService.setValue(APPROVE_BY_SECURITY_ENABLE, "false");
configurationService.setValue(APPROVE_BY_MANAGER_ENABLE, "false");
configurationService.setValue(APPROVE_BY_HELPDESK_ENABLE, "true");
loginAsAdmin();
// helpdesk role and identity
IdmRoleDto helpdeskRole = getHelper().createRole();
IdmIdentityDto helpdeskIdentity = getHelper().createIdentity();
// add role directly
getHelper().createIdentityRole(helpdeskIdentity, helpdeskRole);
configurationService.setValue(APPROVE_BY_HELPDESK_ROLE, helpdeskRole.getCode());
IdmIdentityDto identity = identityService.getByUsername(InitTestDataProcessor.TEST_USER_1);
IdmIdentityDto guarantee = identityService.getByUsername(InitTestDataProcessor.TEST_USER_2);
// Guarantee
int priority = 500;
IdmRoleDto adminRole = roleConfiguration.getAdminRole();
adminRole.setPriority(priority);
getHelper().createRoleGuarantee(adminRole, guarantee);
adminRole = roleService.save(adminRole);
configurationService.setValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + priority, APPROVE_ROLE_BY_MANAGER_KEY);
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity.getId());
IdmRoleRequestDto request = createRoleRequest(identity);
request = roleRequestService.save(request);
IdmConceptRoleRequestDto concept = createRoleConcept(adminRole, contract, request);
concept = conceptRoleRequestService.save(concept);
IdmRequestIdentityRoleFilter requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
requestIdentityRoleFilter.setIncludeCandidates(true);
requestIdentityRoleFilter.setRoleRequestId(request.getId());
requestIdentityRoleFilter.setIdentityId(identity.getId());
List<IdmRequestIdentityRoleDto> requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
assertEquals(1, requestIdentityRoles.size());
IdmRequestIdentityRoleDto requestIdentityRoleDto = requestIdentityRoles.get(0);
assertNull(requestIdentityRoleDto.getCandidates());
roleRequestService.startRequestInternal(request.getId(), true);
request = roleRequestService.get(request.getId());
assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
WorkflowFilterDto taskFilter = new WorkflowFilterDto();
taskFilter.setCreatedAfter(now);
taskFilter.setCandidateOrAssigned(securityService.getCurrentUsername());
List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(0, tasks.size());
Set<IdmIdentityDto> candidates = workflowProcessInstanceService.getApproversForProcess(request.getWfProcessId());
assertEquals(1, candidates.size());
candidates = workflowProcessInstanceService.getApproversForSubprocess(request.getWfProcessId());
assertEquals(0, candidates.size());
requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
requestIdentityRoleFilter.setIncludeCandidates(true);
requestIdentityRoleFilter.setRoleRequestId(request.getId());
requestIdentityRoleFilter.setIdentityId(identity.getId());
requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
assertEquals(1, requestIdentityRoles.size());
requestIdentityRoleDto = requestIdentityRoles.get(0);
assertNull(requestIdentityRoleDto.getCandidates());
IdmRoleRequestFilter filter = new IdmRoleRequestFilter();
filter.setIncludeApprovers(true);
IdmRoleRequestDto requestDto = roleRequestService.get(request.getId(), filter);
assertEquals(1, requestDto.getApprovers().size());
// HELPDESK
loginAsAdmin(helpdeskIdentity.getUsername());
taskFilter.setCandidateOrAssigned(helpdeskIdentity.getUsername());
checkAndCompleteOneTask(taskFilter, InitTestDataProcessor.TEST_USER_1, "approve");
filter.setIncludeApprovers(false);
requestDto = roleRequestService.get(request.getId(), filter);
assertNull(requestDto.getApprovers());
// Subprocess - approve by Manager
request = roleRequestService.get(request.getId());
loginAsAdmin(guarantee.getUsername());
taskFilter.setCandidateOrAssigned(InitTestDataProcessor.TEST_USER_2);
tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(1, tasks.size());
concept = conceptRoleRequestService.get(concept.getId());
String conceptWf = concept.getWfProcessId();
assertNotNull(conceptWf);
assertNotNull(workflowProcessInstanceService.get(conceptWf));
candidates = workflowProcessInstanceService.getApproversForProcess(request.getWfProcessId());
assertEquals(1, candidates.size());
IdmIdentityDto approversFromProcess = candidates.stream().findFirst().get();
candidates = workflowProcessInstanceService.getApproversForSubprocess(request.getWfProcessId());
assertEquals(1, candidates.size());
IdmIdentityDto approversFromSubProcess = candidates.stream().findFirst().get();
assertEquals(approversFromProcess.getId(), approversFromSubProcess.getId());
requestIdentityRoleFilter = new IdmRequestIdentityRoleFilter();
requestIdentityRoleFilter.setIncludeCandidates(true);
requestIdentityRoleFilter.setRoleRequestId(request.getId());
requestIdentityRoleFilter.setIdentityId(identity.getId());
requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
assertEquals(1, requestIdentityRoles.size());
requestIdentityRoleDto = requestIdentityRoles.get(0);
assertEquals(1, requestIdentityRoleDto.getCandidates().size());
requestIdentityRoleFilter.setIncludeCandidates(false);
requestIdentityRoles = requestIdentityRoleService.find(requestIdentityRoleFilter, null).getContent();
assertEquals(1, requestIdentityRoles.size());
requestIdentityRoleDto = requestIdentityRoles.get(0);
assertNull(requestIdentityRoleDto.getCandidates());
filter = new IdmRoleRequestFilter();
filter.setIncludeApprovers(true);
requestDto = roleRequestService.get(request.getId(), filter);
assertEquals(1, requestDto.getApprovers().size());
filter.setIncludeApprovers(false);
requestDto = roleRequestService.get(request.getId(), filter);
assertNull(requestDto.getApprovers());
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class HistoryProcessAndTaskTest method completeTasksAndCheckHistory.
private void completeTasksAndCheckHistory() {
WorkflowFilterDto filter = new WorkflowFilterDto();
filter.setProcessDefinitionKey(PROCESS_KEY);
List<WorkflowTaskInstanceDto> tasks = (List<WorkflowTaskInstanceDto>) taskInstanceService.find(filter, null).getContent();
assertEquals(1, tasks.size());
assertEquals("userTaskFirst", tasks.get(0).getName());
String taskId = tasks.get(0).getId();
String processId = tasks.get(0).getProcessInstanceId();
taskInstanceService.completeTask(taskId, null);
// Check task history
checkTaskHistory(taskId, InitTestDataProcessor.TEST_USER_1);
// Second task is for testUser2 (is candidate) for testUser1 must be null
filter.setCandidateOrAssigned(InitTestDataProcessor.TEST_USER_1);
tasks = (List<WorkflowTaskInstanceDto>) taskInstanceService.find(filter, null).getContent();
assertEquals(0, tasks.size());
this.logout();
this.loginAsAdmin(InitTestDataProcessor.TEST_USER_2);
filter.setCandidateOrAssigned(InitTestDataProcessor.TEST_USER_2);
tasks = (List<WorkflowTaskInstanceDto>) taskInstanceService.find(filter, null).getContent();
assertEquals(1, tasks.size());
assertEquals("userTaskSecond", tasks.get(0).getName());
taskId = tasks.get(0).getId();
taskInstanceService.completeTask(taskId, null);
// Check task history
checkTaskHistory(taskId, InitTestDataProcessor.TEST_USER_2);
tasks = (List<WorkflowTaskInstanceDto>) taskInstanceService.find(filter, null).getContent();
assertEquals(0, tasks.size());
// Find history of process. Historic process must exist and must be ended.
WorkflowHistoricProcessInstanceDto historicProcess = historicProcessService.get(processId);
assertNotNull(historicProcess);
assertNotNull(historicProcess.getEndTime());
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class SendNotificationToApplicantAndImplementerTest method requestRejectedByHelpdeskApplicantImplementerNotSameTest.
@Test
public void requestRejectedByHelpdeskApplicantImplementerNotSameTest() {
ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
configurationService.setValue(SENT_TO_APPLICANT, "true");
configurationService.setValue(SENT_TO_IMPLEMENTER, "true");
//
IdmIdentityDto testUser3 = createTestUser();
loginAsAdmin(testUser3.getUsername());
IdmIdentityDto test1 = createTestUser();
IdmRoleDto test_role = createRole();
//
IdmIdentityContractDto contract = identityContractService.getPrimeContract(test1.getId());
IdmRoleRequestDto request = createRoleRequest(test1);
request = roleRequestService.save(request);
IdmConceptRoleRequestDto concept = createRoleConcept(test_role, contract, request);
concept = conceptRoleRequestService.save(concept);
roleRequestService.startRequestInternal(request.getId(), true);
request = roleRequestService.get(request.getId());
assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
WorkflowFilterDto taskFilter = new WorkflowFilterDto();
taskFilter.setCandidateOrAssigned(securityService.getCurrentId().toString());
taskFilter.setCreatedAfter(now);
List<WorkflowTaskInstanceDto> tasks = (List<WorkflowTaskInstanceDto>) workflowTaskInstanceService.find(taskFilter, null, IdmBasePermission.READ).getContent();
assertEquals(0, tasks.size());
loginAsAdmin();
taskFilter.setCandidateOrAssigned(securityService.getCurrentId().toString());
// HELPDESK
checkAndCompleteOneTask(taskFilter, test1.getUsername(), "disapprove");
// test notification to applicant
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setRecipient(test1.getUsername());
filter.setNotificationType(IdmNotificationLog.class);
List<IdmNotificationLogDto> notifications = notificationLogService.find(filter, null).getContent();
assertEquals(1, notifications.size());
assertEquals(CoreModuleDescriptor.TOPIC_DISAPPROVE_IDENTITY_ROLES, notifications.get(0).getTopic());
// test notification to implementer
filter = new IdmNotificationFilter();
filter.setRecipient(testUser3.getUsername());
filter.setNotificationType(IdmNotificationLog.class);
notifications = notificationLogService.find(filter, null).getContent();
assertEquals(1, notifications.size());
assertEquals(CoreModuleDescriptor.TOPIC_DISAPPROVE_IDENTITY_ROLES_IMPLEMENTER, notifications.get(0).getTopic());
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class SendNotificationToApplicantAndImplementerTest method requestRejectedByHelpdeskApplicantSameTest.
@Test
public void requestRejectedByHelpdeskApplicantSameTest() {
Assert.assertFalse(eventConfiguration.isAsynchronous());
ZonedDateTime now = ZonedDateTime.now().truncatedTo(ChronoUnit.MILLIS);
getHelper().setConfigurationValue(SENT_TO_APPLICANT, true);
getHelper().setConfigurationValue(SENT_TO_IMPLEMENTER, false);
//
IdmIdentityDto test1 = createTestUser();
IdmRoleDto test_role = createRole();
loginAsAdmin(test1.getUsername());
IdmIdentityContractDto contract = identityContractService.getPrimeContract(test1.getId());
IdmRoleRequestDto request = createRoleRequest(test1);
request = roleRequestService.save(request);
IdmConceptRoleRequestDto concept = createRoleConcept(test_role, contract, request);
concept = conceptRoleRequestService.save(concept);
request = getHelper().startRequestInternal(request, true, true);
assertEquals(RoleRequestState.IN_PROGRESS, request.getState());
WorkflowFilterDto taskFilter = new WorkflowFilterDto();
taskFilter.setCandidateOrAssigned(securityService.getCurrentId().toString());
taskFilter.setCreatedAfter(now);
List<WorkflowTaskInstanceDto> tasks = (List<WorkflowTaskInstanceDto>) workflowTaskInstanceService.find(taskFilter, null, IdmBasePermission.READ).getContent();
assertEquals(0, tasks.size());
loginAsAdmin();
taskFilter.setCandidateOrAssigned(securityService.getCurrentId().toString());
// HELPDESK
checkAndCompleteOneTask(taskFilter, test1.getUsername(), "disapprove");
// test notification
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setRecipient(test1.getUsername());
filter.setNotificationType(IdmNotificationLog.class);
List<IdmNotificationLogDto> notifications = notificationLogService.find(filter, null).getContent();
assertEquals(1, notifications.size());
assertEquals(CoreModuleDescriptor.TOPIC_DISAPPROVE_IDENTITY_ROLES_IMPLEMENTER, notifications.get(0).getTopic());
}
Aggregations