Search in sources :

Example 36 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);
    assertThat(processInstanceQuery.count()).isEqualTo(5);
    List<HistoricProcessInstance> processInstances = processInstanceQuery.list();
    assertThat(processInstances).isNotNull();
    assertThat(processInstances).hasSize(5);
    deploymentIds = new ArrayList<String>();
    deploymentIds.add("invalid");
    processInstanceQuery = historyService.createHistoricProcessInstanceQuery().deploymentIdIn(deploymentIds);
    assertThat(processInstanceQuery.count()).isEqualTo(0);
}
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 37 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);
    assertThat(processInstanceQuery.count()).isEqualTo(5);
    List<HistoricProcessInstance> processInstances = processInstanceQuery.list();
    assertThat(processInstances).isNotNull();
    assertThat(processInstances).hasSize(5);
    for (HistoricProcessInstance historicProcessInstance : processInstances) {
        assertThat(processInstanceIds.contains(historicProcessInstance.getId())).isTrue();
    }
}
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 38 with HistoricProcessInstanceQuery

use of org.activiti.engine.history.HistoricProcessInstanceQuery in project alfresco-repository by Alfresco.

the class ActivitiWorkflowEngine method getWorkflowsInternal.

@SuppressWarnings("unchecked")
private List<WorkflowInstance> getWorkflowsInternal(WorkflowInstanceQuery workflowInstanceQuery, boolean isActive, int maxItems, int skipCount) {
    // MNT-9074 My Tasks fails to render if tasks quantity is excessive
    HistoricProcessInstanceQuery query = createQuery(workflowInstanceQuery, isActive);
    LinkedList<WorkflowInstance> results = new LinkedList<WorkflowInstance>();
    List<HistoricProcessInstance> completedInstances;
    if (maxItems > 0) {
        completedInstances = query.orderByProcessInstanceDuration().desc().listPage(skipCount, maxItems);
    } else {
        completedInstances = query.list();
    }
    List<WorkflowInstance> completedResults = typeConverter.doSpecialTenantFilterAndSafeConvert(completedInstances, new Function<HistoricProcessInstance, String>() {

        public String apply(HistoricProcessInstance historicProcessInstance) {
            ProcessDefinition procDef = activitiUtil.getProcessDefinition(historicProcessInstance.getProcessDefinitionId());
            return procDef.getKey();
        }
    });
    results.addAll(completedResults);
    return results;
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) ReadOnlyProcessDefinition(org.activiti.engine.impl.pvm.ReadOnlyProcessDefinition) WorkflowInstance(org.alfresco.service.cmr.workflow.WorkflowInstance) LinkedList(java.util.LinkedList)

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