Search in sources :

Example 1 with WorkflowTaskInstanceDto

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);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) Task(org.activiti.engine.task.Task) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) ArrayList(java.util.ArrayList) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) TaskQuery(org.activiti.engine.task.TaskQuery) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 2 with WorkflowTaskInstanceDto

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());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) Sort(org.springframework.data.domain.Sort) ResourcesWrapper(eu.bcvsolutions.idm.core.api.rest.domain.ResourcesWrapper)

Example 3 with WorkflowTaskInstanceDto

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);
}
Also used : WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)

Example 4 with WorkflowTaskInstanceDto

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());
}
Also used : WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) List(java.util.List) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto)

Example 5 with WorkflowTaskInstanceDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleGuaranteeDto) WorkflowFilterDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmConceptRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) AbstractCoreWorkflowIntegrationTest(eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

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