use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowTaskInstanceService method internalSearch.
private PageImpl<WorkflowTaskInstanceDto> internalSearch(WorkflowFilterDto filter, Pageable pageable) {
// if currently logged user can read all task continue
if (!canReadAllTask()) {
// if user can't read all task check filter
if (filter.getCandidateOrAssigned() == null) {
filter.setCandidateOrAssigned(securityService.getCurrentId().toString());
} else {
IdmIdentityDto identity = (IdmIdentityDto) lookupService.lookupDto(IdmIdentityDto.class, filter.getCandidateOrAssigned());
if (!identity.getId().equals(securityService.getCurrentId())) {
throw new ResultCodeException(CoreResultCode.FORBIDDEN, "You do not have permission for access to all tasks!");
}
}
// else is filled candidate and it is equals currently logged user
}
String processDefinitionId = filter.getProcessDefinitionId();
Map<String, Object> equalsVariables = filter.getEqualsVariables();
TaskQuery query = taskService.createTaskQuery();
query.active();
query.includeProcessVariables();
if (processDefinitionId != null) {
query.processDefinitionId(processDefinitionId);
}
if (filter.getProcessDefinitionKey() != null) {
query.processDefinitionKey(filter.getProcessDefinitionKey());
}
if (filter.getProcessInstanceId() != null) {
query.processInstanceId(filter.getProcessInstanceId());
}
if (filter.getId() != null) {
query.taskId(filter.getId().toString());
}
if (filter.getCreatedAfter() != null) {
query.taskCreatedAfter(filter.getCreatedAfter().toDate());
}
if (filter.getCreatedBefore() != null) {
query.taskCreatedBefore(filter.getCreatedBefore().toDate());
}
if (equalsVariables != null) {
for (Entry<String, Object> entry : equalsVariables.entrySet()) {
query.processVariableValueEquals(entry.getKey(), entry.getValue());
}
}
if (filter.getCandidateOrAssigned() != null) {
BaseDto dto = lookupService.lookupDto(IdmIdentityDto.class, filter.getCandidateOrAssigned());
Assert.notNull(dto);
query.taskCandidateOrAssigned(String.valueOf(dto.getId()));
}
query.orderByTaskCreateTime();
query.desc();
long count = query.count();
// it's possible that pageable is null
List<Task> tasks = null;
if (pageable == null) {
tasks = query.list();
} else {
tasks = query.listPage((pageable.getPageNumber()) * pageable.getPageSize(), pageable.getPageSize());
}
List<WorkflowTaskInstanceDto> dtos = new ArrayList<>();
if (tasks != null) {
for (Task task : tasks) {
dtos.add(toResource(task));
}
}
return new PageImpl<WorkflowTaskInstanceDto>(dtos, pageable, count);
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowTaskInstanceService method search.
@Override
public ResourcesWrapper<WorkflowTaskInstanceDto> search(WorkflowFilterDto filter) {
Pageable pageable = null;
// get pageable setting from filter - backward compatibility
if (StringUtils.isNotEmpty(filter.getSortByFields())) {
Sort sort = null;
if (filter.isSortAsc()) {
sort = new Sort(Direction.ASC, filter.getSortByFields());
} else {
sort = new Sort(Direction.DESC, filter.getSortByFields());
}
pageable = new PageRequest(filter.getPageNumber(), filter.getPageSize(), sort);
} else {
pageable = new PageRequest(filter.getPageNumber(), filter.getPageSize());
}
filter.setCandidateOrAssigned(securityService.getCurrentId().toString());
Page<WorkflowTaskInstanceDto> page = this.find(filter, pageable);
return new ResourcesWrapper<>(page.getContent(), page.getTotalElements(), page.getTotalPages(), filter.getPageNumber(), filter.getPageSize());
}
use of eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowTaskInstanceService method get.
private WorkflowTaskInstanceDto get(String taskId) {
WorkflowFilterDto filter = new WorkflowFilterDto();
filter.setId(UUID.fromString(taskId));
List<WorkflowTaskInstanceDto> tasks = internalSearch(filter, null).getContent();
return tasks.isEmpty() ? null : tasks.get(0);
}
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.search(filter).getResources();
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, InitTestData.TEST_USER_1);
// Second task is for testUser2 (is candidate) for testUser1 must be null
filter.setCandidateOrAssigned(InitTestData.TEST_USER_1);
tasks = (List<WorkflowTaskInstanceDto>) taskInstanceService.search(filter).getResources();
assertEquals(0, tasks.size());
this.logout();
this.loginAsAdmin(InitTestData.TEST_USER_2);
filter.setCandidateOrAssigned(InitTestData.TEST_USER_2);
tasks = (List<WorkflowTaskInstanceDto>) taskInstanceService.search(filter).getResources();
assertEquals(1, tasks.size());
assertEquals("userTaskSecond", tasks.get(0).getName());
taskId = tasks.get(0).getId();
taskInstanceService.completeTask(taskId, null);
// Check task history
checkTaskHistory(taskId, InitTestData.TEST_USER_2);
tasks = (List<WorkflowTaskInstanceDto>) taskInstanceService.search(filter).getResources();
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 ChangeIdentityPermissionTest method addSuperAdminRoleWithSubprocessManagerTest.
@Test
@Transactional
public void addSuperAdminRoleWithSubprocessManagerTest() {
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
IdmIdentityDto test1 = identityService.getByUsername(InitTestData.TEST_USER_1);
IdmIdentityDto test2 = identityService.getByUsername(InitTestData.TEST_USER_2);
// Guarantee
int priority = 500;
IdmRoleDto adminRole = roleService.getByCode(InitTestData.TEST_ADMIN_ROLE);
adminRole.setPriority(priority);
IdmRoleGuaranteeDto guarantee = new IdmRoleGuaranteeDto();
guarantee.setRole(adminRole.getId());
guarantee.setGuarantee(test2.getId());
adminRole.getGuarantees().add(guarantee);
adminRole = roleService.save(adminRole);
configurationService.setValue(IdmRoleService.WF_BY_ROLE_PRIORITY_PREFIX + priority, APPROVE_ROLE_BY_MANAGER_KEY);
IdmIdentityContractDto contract = identityContractService.getPrimeContract(test1.getId());
IdmRoleRequestDto request = createRoleRequest(test1);
request = roleRequestService.save(request);
IdmConceptRoleRequestDto concept = createRoleConcept(adminRole, 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.getCurrentUsername());
List<WorkflowTaskInstanceDto> tasks = workflowTaskInstanceService.find(taskFilter, null).getContent();
assertEquals(0, tasks.size());
// HELPDESK - must be skipped
// MANAGER
loginAsAdmin(InitTestData.TEST_USER_2);
taskFilter.setCandidateOrAssigned(InitTestData.TEST_USER_2);
checkAndCompleteOneTask(taskFilter, InitTestData.TEST_USER_1, "approve");
// USER MANAGER
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
taskFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskFilter, InitTestData.TEST_USER_1, "approve");
// Subprocess - approve by Manager
request = roleRequestService.get(request.getId());
loginAsAdmin(InitTestData.TEST_USER_2);
taskFilter.setCandidateOrAssigned(InitTestData.TEST_USER_2);
checkAndCompleteOneTask(taskFilter, InitTestData.TEST_USER_1, "approve");
// SECURITY
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
taskFilter.setCandidateOrAssigned(InitTestData.TEST_ADMIN_USERNAME);
checkAndCompleteOneTask(taskFilter, InitTestData.TEST_USER_1, "approve");
request = roleRequestService.get(request.getId());
assertEquals(RoleRequestState.EXECUTED, request.getState());
assertNotNull(request.getWfProcessId());
concept = conceptRoleRequestService.get(concept.getId());
assertNotNull(concept.getWfProcessId());
}
Aggregations