Search in sources :

Example 6 with HistoricProcessInstanceQuery

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

the class HistoryServiceTest method testHistoricProcessInstanceQueryByProcessInstanceIds.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/oneTaskProcess2.bpmn20.xml" })
public void testHistoricProcessInstanceQueryByProcessInstanceIds() {
    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());
    // start an instance that will not be part of the query
    runtimeService.startProcessInstanceByKey("oneTaskProcess2", "2");
    HistoricProcessInstanceQuery processInstanceQuery = historyService.createHistoricProcessInstanceQuery().processInstanceIds(processInstanceIds);
    assertEquals(5, processInstanceQuery.count());
    List<HistoricProcessInstance> processInstances = processInstanceQuery.list();
    assertNotNull(processInstances);
    assertEquals(5, processInstances.size());
    for (HistoricProcessInstance historicProcessInstance : processInstances) {
        assertTrue(processInstanceIds.contains(historicProcessInstance.getId()));
    }
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) HashSet(java.util.HashSet) Deployment(org.activiti.engine.test.Deployment)

Example 7 with HistoricProcessInstanceQuery

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

the class HistoryServiceTest method testHistoricProcessInstanceQueryByDeploymentIdIn.

@Deployment(resources = { "org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml", "org/activiti/engine/test/api/runtime/oneTaskProcess2.bpmn20.xml" })
public void testHistoricProcessInstanceQueryByDeploymentIdIn() {
    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());
    List<String> deploymentIds = new ArrayList<String>();
    deploymentIds.add(deployment.getId());
    deploymentIds.add("invalid");
    HistoricProcessInstanceQuery processInstanceQuery = historyService.createHistoricProcessInstanceQuery().deploymentIdIn(deploymentIds);
    assertEquals(5, processInstanceQuery.count());
    List<HistoricProcessInstance> processInstances = processInstanceQuery.list();
    assertNotNull(processInstances);
    assertEquals(5, processInstances.size());
    deploymentIds = new ArrayList<String>();
    deploymentIds.add("invalid");
    processInstanceQuery = historyService.createHistoricProcessInstanceQuery().deploymentIdIn(deploymentIds);
    assertEquals(0, processInstanceQuery.count());
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Deployment(org.activiti.engine.test.Deployment)

Example 8 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();
        assertEquals(6, historicprocessInstanceQuery.list().size());
        assertEquals(6, historicprocessInstanceQuery.count());
        Map<String, Object> variableMap = historicprocessInstanceQuery.list().get(4).getProcessVariables();
        assertEquals(1, variableMap.size());
        assertEquals(123, variableMap.get("anothertest"));
        for (HistoricProcessInstance processInstance : historicprocessInstanceQuery.list()) {
            assertEquals(deploymentId, processInstance.getDeploymentId());
        }
        HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").deploymentId("invalid").endOr().singleResult();
        assertNull(processInstance);
        // ProcessDefinitionName
        processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").processDefinitionName(PROCESS_DEFINITION_NAME_2).endOr().singleResult();
        variableMap = processInstance.getProcessVariables();
        assertEquals(1, variableMap.size());
        assertEquals(123, variableMap.get("anothertest"));
        assertEquals(PROCESS_DEFINITION_NAME_2, processInstance.getProcessDefinitionName());
        processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").processDefinitionName("invalid").endOr().singleResult();
        assertNull(processInstance);
        // ProcessDefinitionCategory
        processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").processDefinitionCategory(PROCESS_DEFINITION_CATEGORY_2).endOr().singleResult();
        variableMap = processInstance.getProcessVariables();
        assertEquals(1, variableMap.size());
        assertEquals(123, variableMap.get("anothertest"));
        processInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().or().variableValueEquals("anothertest", "invalid").processDefinitionCategory("invalid").endOr().singleResult();
        assertNull(processInstance);
    }
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 9 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();
        assertNull(query0.singleResult());
        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();
        assertEquals(1, variableMap.size());
        assertEquals(123, variableMap.get("anothertest"));
        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();
        assertNull(query2.singleResult());
        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();
        assertEquals(1, variableMap.size());
        assertEquals(123, variableMap.get("anothertest"));
    }
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 10 with HistoricProcessInstanceQuery

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

the class HistoricProcessInstanceQueryAndWithExceptionTest method testQueryWithException.

public void testQueryWithException() throws InterruptedException {
    ProcessInstance processNoException = runtimeService.startProcessInstanceByKey(PROCESS_DEFINITION_KEY_NO_EXCEPTION);
    HistoricProcessInstanceQuery queryNoException = historyService.createHistoricProcessInstanceQuery();
    assertEquals(1, queryNoException.count());
    assertEquals(1, queryNoException.list().size());
    assertEquals(processNoException.getId(), queryNoException.list().get(0).getId());
    HistoricProcessInstanceQuery queryWithException = historyService.createHistoricProcessInstanceQuery();
    assertEquals(0, queryWithException.withJobException().count());
    assertEquals(0, queryWithException.withJobException().list().size());
    ProcessInstance processWithException1 = startProcessInstanceWithFailingJob(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_1);
    JobQuery jobQuery1 = managementService.createJobQuery().processInstanceId(processWithException1.getId());
    assertEquals(1, jobQuery1.withException().count());
    assertEquals(1, jobQuery1.withException().list().size());
    assertEquals(1, queryWithException.withJobException().count());
    assertEquals(1, queryWithException.withJobException().list().size());
    assertEquals(processWithException1.getId(), queryWithException.withJobException().list().get(0).getId());
    ProcessInstance processWithException2 = startProcessInstanceWithFailingJob(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_2);
    JobQuery jobQuery2 = managementService.createJobQuery().processInstanceId(processWithException2.getId());
    assertEquals(2, jobQuery2.withException().count());
    assertEquals(2, jobQuery2.withException().list().size());
    assertEquals(2, queryWithException.withJobException().count());
    assertEquals(2, queryWithException.withJobException().list().size());
    assertEquals(processWithException1.getId(), queryWithException.withJobException().processDefinitionKey(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_1).list().get(0).getId());
    assertEquals(processWithException2.getId(), queryWithException.withJobException().processDefinitionKey(PROCESS_DEFINITION_KEY_WITH_EXCEPTION_2).list().get(0).getId());
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) JobQuery(org.activiti.engine.runtime.JobQuery)

Aggregations

HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)11 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)9 Deployment (org.activiti.engine.test.Deployment)6 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)3 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)3 HashMap (java.util.HashMap)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 JobQuery (org.activiti.engine.runtime.JobQuery)1 Test (org.junit.Test)1