Search in sources :

Example 36 with RuntimeService

use of org.activiti.engine.RuntimeService in project carbon-business-process by wso2.

the class BPMNDeploymentService method deleteInstances.

private void deleteInstances(BPMNDeletableInstances bpmnDeletableInstances, ProcessEngine processEngine) {
    List<HistoricProcessInstance> activeHistoricProcessInstance = bpmnDeletableInstances.getActiveHistoricProcessInstance();
    for (HistoricProcessInstance instance : activeHistoricProcessInstance) {
        String instanceId = instance.getId();
        RuntimeService runtimeService = processEngine.getRuntimeService();
        List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().processInstanceTenantId(bpmnDeletableInstances.getTenantId().toString()).processInstanceId(instanceId).list();
        if (!processInstances.isEmpty()) {
            runtimeService.deleteProcessInstance(instance.getId(), "Deleted by user: " + bpmnDeletableInstances.getTenantId());
        }
    }
    List<String> completedProcessDefinitionIds = bpmnDeletableInstances.getCompletedProcessDefinitionIds();
    for (String processId : completedProcessDefinitionIds) {
        HistoricProcessInstanceQuery runtimeQuery = processEngine.getHistoryService().createHistoricProcessInstanceQuery().processInstanceTenantId(bpmnDeletableInstances.getTenantId().toString()).includeProcessVariables().finished().processDefinitionId(processId);
        int completedProcessInstanceCount = (int) runtimeQuery.count();
        if (completedProcessInstanceCount > 0) {
            List<HistoricProcessInstance> instances = runtimeQuery.listPage(0, completedProcessInstanceCount + 1);
            HistoryService historyService = processEngine.getHistoryService();
            for (HistoricProcessInstance instance : instances) {
                String instanceId = instance.getId();
                historyService.deleteHistoricProcessInstance(instanceId);
            }
        }
    }
}
Also used : HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) RuntimeService(org.activiti.engine.RuntimeService) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) HistoryService(org.activiti.engine.HistoryService) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance)

Example 37 with RuntimeService

use of org.activiti.engine.RuntimeService in project carbon-business-process by wso2.

the class BPMNInstanceService method getInstanceCount.

/**
 * Get total instance count
 *
 * @return count int
 * @throws BPSFault
 */
public int getInstanceCount() throws BPSFault {
    if (processInstanceCount == -1) {
        Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
        ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
        RuntimeService runtimeService = engine.getRuntimeService();
        ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId.toString());
        processInstanceCount = (int) query.includeProcessVariables().count();
    }
    return processInstanceCount;
}
Also used : ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) RuntimeService(org.activiti.engine.RuntimeService) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 38 with RuntimeService

use of org.activiti.engine.RuntimeService in project carbon-business-process by wso2.

the class BPMNInstanceService method getProcessInstances.

/**
 * Get All process instances
 *
 * @return list of BPMNInstances
 * @throws BPSFault
 */
public BPMNInstance[] getProcessInstances() throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
    RuntimeService runtimeService = engine.getRuntimeService();
    List<ProcessInstance> instances = runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId.toString()).list();
    BPMNInstance[] bpmnInstances = getTenantBPMNInstances(instances);
    return bpmnInstances;
}
Also used : BPMNInstance(org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance) RuntimeService(org.activiti.engine.RuntimeService) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 39 with RuntimeService

use of org.activiti.engine.RuntimeService in project carbon-business-process by wso2.

the class BPMNInstanceService method getPaginatedInstances.

/**
 * Get paginated instances
 *
 * @param start
 * @param size
 * @return list of BPMNInstances
 * @throws BPSFault
 */
public BPMNInstance[] getPaginatedInstances(int start, int size) throws BPSFault {
    List<BPMNInstance> bpmnInstanceList = new ArrayList<>();
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
    RuntimeService runtimeService = engine.getRuntimeService();
    ProcessInstanceQuery query = runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId.toString());
    HistoricProcessInstanceQuery historicQuery = BPMNServerHolder.getInstance().getEngine().getHistoryService().createHistoricProcessInstanceQuery().processInstanceTenantId(tenantId.toString());
    processInstanceCount = (int) query.count();
    List<ProcessInstance> instances = query.includeProcessVariables().listPage(start, size);
    for (ProcessInstance instance : instances) {
        BPMNInstance bpmnInstance = new BPMNInstance();
        bpmnInstance.setInstanceId(instance.getId());
        bpmnInstance.setProcessId(instance.getProcessDefinitionId());
        bpmnInstance.setSuspended(instance.isSuspended());
        bpmnInstance.setStartTime(historicQuery.processInstanceId(instance.getId()).singleResult().getStartTime());
        bpmnInstance.setVariables(formatVariables(instance.getProcessVariables()));
        bpmnInstanceList.add(bpmnInstance);
    }
    return bpmnInstanceList.toArray(new BPMNInstance[bpmnInstanceList.size()]);
}
Also used : BPMNInstance(org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance) ProcessInstanceQuery(org.activiti.engine.runtime.ProcessInstanceQuery) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) RuntimeService(org.activiti.engine.RuntimeService) ArrayList(java.util.ArrayList) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 40 with RuntimeService

use of org.activiti.engine.RuntimeService in project carbon-business-process by wso2.

the class BPMNInstanceService method getTenantBPMNHistoryInstances.

/**
 * Get tenant history instances from a passed list
 *
 * @param instances
 * @return list of BPMNInstances
 */
private BPMNInstance[] getTenantBPMNHistoryInstances(List<ProcessInstance> instances) {
    BPMNInstance bpmnInstance;
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    List<BPMNInstance> bpmnInstances = new ArrayList<BPMNInstance>();
    RuntimeService runtimeService = BPMNServerHolder.getInstance().getEngine().getRuntimeService();
    HistoricProcessInstanceQuery query = BPMNServerHolder.getInstance().getEngine().getHistoryService().createHistoricProcessInstanceQuery().processInstanceTenantId(tenantId.toString());
    for (ProcessInstance instance : instances) {
        bpmnInstance = new BPMNInstance();
        bpmnInstance.setInstanceId(instance.getId());
        bpmnInstance.setProcessId(instance.getProcessDefinitionId());
        bpmnInstance.setSuspended(instance.isSuspended());
        bpmnInstance.setStartTime(query.processInstanceId(instance.getId()).singleResult().getStartTime());
        bpmnInstance.setVariables(formatVariables(runtimeService.getVariables(instance.getId())));
        bpmnInstances.add(bpmnInstance);
    }
    return bpmnInstances.toArray(new BPMNInstance[bpmnInstances.size()]);
}
Also used : BPMNInstance(org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) RuntimeService(org.activiti.engine.RuntimeService) ArrayList(java.util.ArrayList) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance)

Aggregations

RuntimeService (org.activiti.engine.RuntimeService)92 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)35 Test (org.junit.Test)25 ProcessEngine (org.activiti.engine.ProcessEngine)16 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)15 TaskService (org.activiti.engine.TaskService)14 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)14 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)13 Deployment (org.activiti.engine.test.Deployment)13 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)12 RepositoryService (org.activiti.engine.RepositoryService)10 HashMap (java.util.HashMap)8 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)8 Task (org.activiti.engine.task.Task)8 ArrayList (java.util.ArrayList)7 Path (javax.ws.rs.Path)7 HistoricProcessInstanceQuery (org.activiti.engine.history.HistoricProcessInstanceQuery)7 Execution (org.activiti.engine.runtime.Execution)7 Produces (javax.ws.rs.Produces)6 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)6