use of org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance 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.wso2.carbon.bpmn.core.mgt.model.BPMNInstance 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.wso2.carbon.bpmn.core.mgt.model.BPMNInstance 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()]);
}
use of org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance in project carbon-business-process by wso2.
the class BPMNInstanceService method getPaginatedHistoryInstances.
/**
* Get paginated history instances
*
* @param start
* @param size
* @return list of BPMNInstances
*/
public BPMNInstance[] getPaginatedHistoryInstances(int start, int size) {
BPMNInstance bpmnInstance;
Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
List<BPMNInstance> bpmnInstances = new ArrayList<>();
HistoryService historyService = BPMNServerHolder.getInstance().getEngine().getHistoryService();
HistoricProcessInstanceQuery query = historyService.createHistoricProcessInstanceQuery().processInstanceTenantId(tenantId.toString()).finished().includeProcessVariables();
historyInstanceCount = (int) query.count();
List<HistoricProcessInstance> historicProcessInstances = query.listPage(start, size);
for (HistoricProcessInstance instance : historicProcessInstances) {
bpmnInstance = new BPMNInstance();
bpmnInstance.setInstanceId(instance.getId());
bpmnInstance.setProcessId(instance.getProcessDefinitionId());
bpmnInstance.setStartTime(instance.getStartTime());
bpmnInstance.setEndTime(instance.getEndTime());
bpmnInstance.setVariables(formatVariables(instance.getProcessVariables()));
bpmnInstances.add(bpmnInstance);
}
return bpmnInstances.toArray(new BPMNInstance[bpmnInstances.size()]);
}
use of org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance in project carbon-business-process by wso2.
the class WorkflowServiceClient method deleteAllProcessInstances.
public void deleteAllProcessInstances() throws Exception {
BPMNInstance[] instances = getPaginatedInstanceByFilter(true, null, null, null, null, true, null, 0, 100);
List<String> instanceIds = new ArrayList<String>();
for (BPMNInstance instance : instances) {
instanceIds.add(instance.getInstanceId());
}
instanceServiceStub.deleteProcessInstanceSet(instanceIds.toArray(new String[instanceIds.size()]));
}
Aggregations