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);
}
}
}
}
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;
}
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;
}
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()]);
}
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()]);
}
Aggregations