Search in sources :

Example 31 with HistoricProcessInstanceQuery

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

the class DefaultWorkflowHistoricProcessInstanceService method find.

@Override
public Page<WorkflowHistoricProcessInstanceDto> find(WorkflowFilterDto filter, Pageable pageable, BasePermission... permission) {
    HistoricProcessInstanceQuery query = this.getQuery(filter, pageable, permission);
    if (pageable == null) {
        pageable = PageRequest.of(0, Integer.MAX_VALUE);
    }
    long count = query.count();
    List<HistoricProcessInstance> processInstances = query.listPage((pageable.getPageNumber()) * pageable.getPageSize(), pageable.getPageSize());
    String processInstanceId = filter.getProcessInstanceId();
    boolean trimmed = true;
    if (processInstanceId != null) {
        // Process variables will be included only for get by instance ID
        trimmed = false;
        query.includeProcessVariables();
        query.processInstanceId(processInstanceId);
    }
    List<WorkflowHistoricProcessInstanceDto> dtos = new ArrayList<>();
    if (processInstances != null) {
        for (HistoricProcessInstance instance : processInstances) {
            dtos.add(toDto(instance, trimmed));
        }
    }
    return new PageImpl<>(dtos, pageable, count);
}
Also used : PageImpl(org.springframework.data.domain.PageImpl) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) WorkflowHistoricProcessInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowHistoricProcessInstanceDto)

Example 32 with HistoricProcessInstanceQuery

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

the class DeleteWorkflowHistoricInstanceTaskExecutor method process.

@Override
public Boolean process() {
    Assert.notNull(processDefinitionKey, "Workflow definition key is requred.");
    // 
    HistoricProcessInstanceQuery query = processEngine.getHistoryService().createHistoricProcessInstanceQuery().processDefinitionKey(processDefinitionKey).finished().excludeSubprocesses(true);
    if (numberOfDays > 0) {
        query.finishedBefore(DateTime.now().withTimeAtStartOfDay().minusDays(numberOfDays).toDate());
    }
    List<HistoricProcessInstance> historicInstances = query.list();
    count = (long) historicInstances.size();
    counter = 0L;
    // 
    for (HistoricProcessInstance processInstance : historicInstances) {
        TransactionTemplate template = new TransactionTemplate(platformTransactionManager);
        template.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
        // 
        // delete historic instance in new transaction => large data support or if task is ended with exception, then prevent to rollback
        template.execute(new TransactionCallback<OperationResult>() {

            public OperationResult doInTransaction(TransactionStatus transactionStatus) {
                processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
                // 
                return new OperationResult(OperationState.EXECUTED);
            }
        });
        ++counter;
        // 
        boolean canContinue = updateState();
        if (!canContinue) {
            break;
        }
    }
    return Boolean.TRUE;
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult)

Example 33 with HistoricProcessInstanceQuery

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

the class HistoricProcessInstanceAndVariablesQueryTest method testOrQueryMultipleVariableValues.

public void testOrQueryMultipleVariableValues() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        HistoricProcessInstanceQuery query0 = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or();
        for (int i = 0; i < 20; i++) {
            query0 = query0.variableValueEquals("anothertest", i);
        }
        query0 = query0.processDefinitionId("undefined").endOr();
        assertThat(query0.singleResult()).isNull();
        HistoricProcessInstanceQuery query1 = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", 123);
        for (int i = 0; i < 20; i++) {
            query1 = query1.variableValueEquals("anothertest", i);
        }
        query1 = query1.processDefinitionId("undefined").endOr();
        HistoricProcessInstance processInstance = query1.singleResult();
        Map<String, Object> variableMap = processInstance.getProcessVariables();
        assertThat(variableMap).hasSize(1);
        assertThat(variableMap.get("anothertest")).isEqualTo(123);
        HistoricProcessInstanceQuery query2 = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or();
        for (int i = 0; i < 20; i++) {
            query2 = query2.variableValueEquals("anothertest", i);
        }
        query2 = query2.processDefinitionId("undefined").endOr().or().processDefinitionKey(PROCESS_DEFINITION_KEY_2).processDefinitionId("undefined").endOr();
        assertThat(query2.singleResult()).isNull();
        HistoricProcessInstanceQuery query3 = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", 123);
        for (int i = 0; i < 20; i++) {
            query3 = query3.variableValueEquals("anothertest", i);
        }
        query3 = query3.processDefinitionId("undefined").endOr().or().processDefinitionKey(PROCESS_DEFINITION_KEY_2).processDefinitionId("undefined").endOr();
        variableMap = query3.singleResult().getProcessVariables();
        assertThat(variableMap).hasSize(1);
        assertThat(variableMap.get("anothertest")).isEqualTo(123);
    }
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 34 with HistoricProcessInstanceQuery

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

the class HistoricProcessInstanceAndVariablesQueryTest method testOrQueryByprocessDefinition.

public void testOrQueryByprocessDefinition() {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        // DeploymentId
        String deploymentId = repositoryService.createDeploymentQuery().list().get(0).getId();
        HistoricProcessInstanceQuery historicprocessInstanceQuery = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").deploymentId(deploymentId).endOr();
        assertThat(historicprocessInstanceQuery.list()).hasSize(6);
        assertThat(historicprocessInstanceQuery.count()).isEqualTo(6);
        Map<String, Object> variableMap = historicprocessInstanceQuery.list().get(4).getProcessVariables();
        assertThat(variableMap).hasSize(1);
        assertThat(variableMap.get("anothertest")).isEqualTo(123);
        for (HistoricProcessInstance processInstance : historicprocessInstanceQuery.list()) {
            assertThat(processInstance.getDeploymentId()).isEqualTo(deploymentId);
        }
        HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").deploymentId("invalid").endOr().singleResult();
        assertThat(processInstance).isNull();
        // ProcessDefinitionName
        processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").processDefinitionName(PROCESS_DEFINITION_NAME_2).endOr().singleResult();
        variableMap = processInstance.getProcessVariables();
        assertThat(variableMap).hasSize(1);
        assertThat(variableMap.get("anothertest")).isEqualTo(123);
        assertThat(processInstance.getProcessDefinitionName()).isEqualTo(PROCESS_DEFINITION_NAME_2);
        processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").processDefinitionName("invalid").endOr().singleResult();
        assertThat(processInstance).isNull();
        // ProcessDefinitionCategory
        processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").processDefinitionCategory(PROCESS_DEFINITION_CATEGORY_2).endOr().singleResult();
        variableMap = processInstance.getProcessVariables();
        assertThat(variableMap).hasSize(1);
        assertThat(variableMap.get("anothertest")).isEqualTo(123);
        processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").processDefinitionCategory("invalid").endOr().singleResult();
        assertThat(processInstance).isNull();
    }
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 35 with HistoricProcessInstanceQuery

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

the class HistoricProcessInstanceQueryAndWithExceptionTest method testQueryWithException.

public void testQueryWithException() throws InterruptedException {
    if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
        ProcessInstance processNoException = runtimeService.startProcessInstanceByKey(PROCESS_DEFINITION_KEY_NO_EXCEPTION);
        HistoricProcessInstanceQuery queryNoException = historyService.createHistoricProcessInstanceQuery();
        assertThat(queryNoException.count()).isEqualTo(1);
        assertThat(queryNoException.list()).hasSize(1);
        assertThat(queryNoException.list().get(0).getId()).isEqualTo(processNoException.getId());
        HistoricProcessInstanceQuery queryWithException = historyService.createHistoricProcessInstanceQuery();
        assertThat(queryWithException.withJobException().count()).isEqualTo(0);
        assertThat(queryWithException.withJobException().list()).hasSize(0);
        ProcessInstance processWithException1 = startProcessInstanceWithFailingJob(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_1);
        TimerJobQuery jobQuery1 = managementService.createTimerJobQuery().processInstanceId(processWithException1.getId());
        assertThat(jobQuery1.withException().count()).isEqualTo(1);
        assertThat(jobQuery1.withException().list()).hasSize(1);
        assertThat(queryWithException.withJobException().count()).isEqualTo(1);
        assertThat(queryWithException.withJobException().list()).hasSize(1);
        assertThat(queryWithException.withJobException().list().get(0).getId()).isEqualTo(processWithException1.getId());
        ProcessInstance processWithException2 = startProcessInstanceWithFailingJob(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_2);
        TimerJobQuery jobQuery2 = managementService.createTimerJobQuery().processInstanceId(processWithException2.getId());
        assertThat(jobQuery2.withException().count()).isEqualTo(2);
        assertThat(jobQuery2.withException().list()).hasSize(2);
        assertThat(queryWithException.withJobException().count()).isEqualTo(2);
        assertThat(queryWithException.withJobException().list()).hasSize(2);
        assertThat(queryWithException.withJobException().processDefinitionKey(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_1).list().get(0).getId()).isEqualTo(processWithException1.getId());
        assertThat(queryWithException.withJobException().processDefinitionKey(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_2).list().get(0).getId()).isEqualTo(processWithException2.getId());
    }
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) TimerJobQuery(org.activiti.engine.runtime.TimerJobQuery)

Aggregations

HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)38 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)30 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)8 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)7 InOrder (org.mockito.InOrder)7 HistoryService (org.activiti.engine.HistoryService)6 RuntimeService (org.activiti.engine.RuntimeService)6 Deployment (org.activiti.engine.test.Deployment)6 JobStatusEnum (org.finra.herd.model.api.xml.JobStatusEnum)6 DateTime (org.joda.time.DateTime)6 BPMNInstance (org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance)6 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 ProcessEngine (org.activiti.engine.ProcessEngine)3 ProcessInstanceQuery (org.activiti.engine.runtime.ProcessInstanceQuery)3 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2