Search in sources :

Example 6 with HistoricTaskInstanceQuery

use of org.activiti.engine.history.HistoricTaskInstanceQuery in project Activiti by Activiti.

the class HistoryServiceTest method testHistoricTaskInstanceQueryByDeploymentId.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/oneTaskProcess2.bpmn20.xml" })
public void testHistoricTaskInstanceQueryByDeploymentId() {
    org.activiti.engine.repository.Deployment deployment = repositoryService.createDeploymentQuery().singleResult();
    HashSet<String> processInstanceIds = new HashSet<String>();
    for (int i = 0; i < 4; i++) {
        processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess", i + "").getId());
    }
    processInstanceIds.add(runtimeService.startProcessInstanceByKey("oneTaskProcess2", "1").getId());
    HistoricTaskInstanceQuery taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().deploymentId(deployment.getId());
    assertEquals(5, taskInstanceQuery.count());
    List<HistoricTaskInstance> taskInstances = taskInstanceQuery.list();
    assertNotNull(taskInstances);
    assertEquals(5, taskInstances.size());
    taskInstanceQuery = historyService.createHistoricTaskInstanceQuery().deploymentId("invalid");
    assertEquals(0, taskInstanceQuery.count());
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) HashSet(java.util.HashSet) Deployment(org.activiti.engine.test.Deployment)

Example 7 with HistoricTaskInstanceQuery

use of org.activiti.engine.history.HistoricTaskInstanceQuery in project CzechIdMng by bcvsolutions.

the class DefaultWorkflowHistoricTaskInstanceService method find.

@Override
public Page<WorkflowHistoricTaskInstanceDto> find(WorkflowFilterDto filter, Pageable pageable, BasePermission... permission) {
    String processDefinitionId = filter.getProcessDefinitionId();
    String processInstanceId = filter.getProcessInstanceId();
    HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery();
    query.includeProcessVariables();
    if (filter.getId() != null) {
        query.taskId(filter.getId().toString());
    }
    if (processInstanceId != null) {
        query.processInstanceId(processInstanceId);
    }
    if (processDefinitionId != null) {
        query.processDefinitionId(processDefinitionId);
    }
    if (filter.getProcessDefinitionKey() != null) {
        query.processDefinitionKey(filter.getProcessDefinitionKey());
    }
    // historic task instance ... admin can see all historic tasks every time
    if (!securityService.isAdmin()) {
        // TODO Now we don't have detail for historic task. When we need detail, then we will need create different projection (detail can't be read by applicant)
        String loggedUserId = securityService.getCurrentId().toString();
        query.taskInvolvedUser(loggedUserId);
    }
    String fieldForSort = null;
    boolean ascSort = false;
    boolean descSort = false;
    if (pageable != null) {
        Sort sort = pageable.getSort();
        if (sort != null) {
            for (Order order : sort) {
                if (!StringUtils.isEmpty(order.getProperty())) {
                    // TODO: now is implemented only one property sort
                    fieldForSort = order.getProperty();
                    if (order.getDirection() == Direction.ASC) {
                        ascSort = true;
                    } else if (order.getDirection() == Direction.DESC) {
                        descSort = true;
                    }
                    break;
                }
            }
        }
    }
    if (WorkflowHistoricTaskInstanceService.SORT_BY_CREATE_TIME.equals(fieldForSort)) {
        query.orderByTaskCreateTime();
    } else if (WorkflowHistoricTaskInstanceService.SORT_BY_END_TIME.equals(fieldForSort)) {
        query.orderByHistoricTaskInstanceEndTime();
    } else {
        query.orderByProcessDefinitionId();
        // there must be default order
        query.asc();
    }
    if (ascSort) {
        query.asc();
    }
    if (descSort) {
        query.desc();
    }
    long count = query.count();
    List<HistoricTaskInstance> processInstances = null;
    if (pageable == null) {
        processInstances = query.list();
    } else {
        processInstances = query.listPage((pageable.getPageNumber()) * pageable.getPageSize(), pageable.getPageSize());
    }
    List<WorkflowHistoricTaskInstanceDto> dtos = new ArrayList<>();
    if (processInstances != null) {
        for (HistoricTaskInstance instance : processInstances) {
            dtos.add(toResource(instance));
        }
    }
    return new PageImpl<WorkflowHistoricTaskInstanceDto>(dtos, pageable, count);
}
Also used : Order(org.springframework.data.domain.Sort.Order) PageImpl(org.springframework.data.domain.PageImpl) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) ArrayList(java.util.ArrayList) Sort(org.springframework.data.domain.Sort) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) WorkflowHistoricTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)

Aggregations

HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)7 HistoricTaskInstanceQuery (org.activiti.engine.history.HistoricTaskInstanceQuery)7 Deployment (org.activiti.engine.test.Deployment)5 HashSet (java.util.HashSet)4 ArrayList (java.util.ArrayList)3 WorkflowHistoricTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricTaskInstanceDto)1 HashMap (java.util.HashMap)1 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)1 RestVariableScope (org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope)1 PageImpl (org.springframework.data.domain.PageImpl)1 Sort (org.springframework.data.domain.Sort)1 Order (org.springframework.data.domain.Sort.Order)1