Search in sources :

Example 66 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance 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 67 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-business-process by wso2.

the class BPMNInstanceService method deleteProcessInstance.

/**
 * Delete process instance by passing instance ID
 *
 * @param instanceId
 * @throws BPSFault
 */
public void deleteProcessInstance(String instanceId) throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    RuntimeService runtimeService = BPMNServerHolder.getInstance().getEngine().getRuntimeService();
    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId.toString()).processInstanceId(instanceId).list();
    if (processInstances.isEmpty()) {
        HistoryService historyService = BPMNServerHolder.getInstance().getEngine().getHistoryService();
        List<HistoricProcessInstance> historicProcessInstances = historyService.createHistoricProcessInstanceQuery().processInstanceTenantId(tenantId.toString()).processInstanceId(instanceId).list();
        if (historicProcessInstances.isEmpty()) {
            String msg = "No process instances with the ID: " + instanceId;
            log.error(msg);
            throw new BPSFault(msg);
        }
        historyService.deleteHistoricProcessInstance(instanceId);
        return;
    }
    runtimeService.deleteProcessInstance(instanceId, "Deleted by user: " + tenantId);
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) BPSFault(org.wso2.carbon.bpmn.core.BPSFault) HistoryService(org.activiti.engine.HistoryService) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance)

Example 68 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance 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)

Example 69 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-business-process by wso2.

the class BPMNInstanceService method suspendProcessInstance.

/**
 * Suspend process instance by instance ID
 *
 * @param instanceId
 * @throws BPSFault
 */
public void suspendProcessInstance(String instanceId) throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    RuntimeService runtimeService = BPMNServerHolder.getInstance().getEngine().getRuntimeService();
    List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId.toString()).processInstanceId(instanceId).list();
    if (processInstances.isEmpty()) {
        String msg = "No process instances with the ID: " + instanceId;
        log.error(msg);
        throw new BPSFault(msg);
    }
    runtimeService.suspendProcessInstanceById(instanceId);
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) BPSFault(org.wso2.carbon.bpmn.core.BPSFault) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance)

Example 70 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance 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()]);
}
Also used : BPMNInstance(org.wso2.carbon.bpmn.core.mgt.model.BPMNInstance) HistoricProcessInstanceQuery(org.activiti.engine.history.HistoricProcessInstanceQuery) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ArrayList(java.util.ArrayList) HistoryService(org.activiti.engine.HistoryService)

Aggregations

ArrayList (java.util.ArrayList)28 Test (org.junit.Test)23 Response (javax.ws.rs.core.Response)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)20 HashMap (java.util.HashMap)15 Path (javax.ws.rs.Path)15 RuntimeService (org.activiti.engine.RuntimeService)15 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)15 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)14 Produces (javax.ws.rs.Produces)13 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)13 IOException (java.io.IOException)12 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)12 GET (javax.ws.rs.GET)11 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)11 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8