Search in sources :

Example 41 with RuntimeService

use of org.activiti.engine.RuntimeService 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 42 with RuntimeService

use of org.activiti.engine.RuntimeService 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 43 with RuntimeService

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

the class BPMNInstanceService method startProcess.

/**
 * Start process by process ID
 *
 * @param processID
 * @throws BPSFault
 */
public void startProcess(String processID) throws BPSFault {
    ProcessEngine engine = BPMNServerHolder.getInstance().getEngine();
    RuntimeService runtimeService = engine.getRuntimeService();
    runtimeService.startProcessInstanceById(processID);
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) ProcessEngine(org.activiti.engine.ProcessEngine)

Example 44 with RuntimeService

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

the class BPMNInstanceService method getProcessInstanceDiagram.

/**
 * Get process instance diagram as a byte stream by passing the instance ID
 *
 * @param instanceId
 * @return Byte array String
 * @throws BPSFault
 */
public String getProcessInstanceDiagram(String instanceId) throws BPSFault {
    Integer tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    try {
        RuntimeService runtimeService = BPMNServerHolder.getInstance().getEngine().getRuntimeService();
        RepositoryService repositoryService = BPMNServerHolder.getInstance().getEngine().getRepositoryService();
        List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId.toString()).processInstanceId(instanceId).list();
        if (processInstances.isEmpty()) {
            String msg = "No process instance diagram for ID: " + instanceId;
            log.info(msg);
            return null;
        }
        ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) ((RepositoryServiceImpl) repositoryService).getDeployedProcessDefinition(processInstances.get(0).getProcessDefinitionId());
        if (processDefinition != null && processDefinition.isGraphicalNotationDefined()) {
            InputStream diagramStream = new DefaultProcessDiagramGenerator().generateDiagram(repositoryService.getBpmnModel(processDefinition.getId()), "png", runtimeService.getActiveActivityIds(instanceId));
            BufferedImage bufferedImage = ImageIO.read(diagramStream);
            return encodeToString(bufferedImage, "png");
        } else {
            String msg = "Process definition graphical notations doesn't exists: " + instanceId;
            log.debug(msg);
        }
    } catch (IOException e) {
        String msg = "Failed to get the process instance.";
        log.error(msg, e);
    }
    return null;
}
Also used : RuntimeService(org.activiti.engine.RuntimeService) InputStream(java.io.InputStream) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) DefaultProcessDiagramGenerator(org.activiti.image.impl.DefaultProcessDiagramGenerator) ProcessDefinitionEntity(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntity) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) RepositoryService(org.activiti.engine.RepositoryService)

Example 45 with RuntimeService

use of org.activiti.engine.RuntimeService in project crnk-framework by crnk-project.

the class ActivitiModule method setupModule.

@Override
public void setupModule(ModuleContext context) {
    this.moduleContext = context;
    TaskService taskService = processEngine.getTaskService();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    FormService formService = processEngine.getFormService();
    resourceMapper = new ActivitiResourceMapper(context.getTypeParser(), config.getDateTimeMapper());
    HistoryService historyService = processEngine.getHistoryService();
    for (ProcessInstanceConfig processInstanceConfig : config.getProcessInstances().values()) {
        context.addRepository(new ProcessInstanceResourceRepository(runtimeService, historyService, resourceMapper, processInstanceConfig.getProcessInstanceClass(), processInstanceConfig.getBaseFilters()));
        Class<? extends HistoricProcessInstanceResource> historyClass = processInstanceConfig.getHistoryClass();
        if (historyClass != null) {
            context.addRepository(new HistoricProcessInstanceResourceRepository(historyService, resourceMapper, historyClass, processInstanceConfig.getBaseFilters()));
        }
        for (ProcessInstanceConfig.TaskRelationshipConfig taskRel : processInstanceConfig.getTaskRelationships().values()) {
            context.addRepository(new TaskRelationshipRepository(processInstanceConfig.getProcessInstanceClass(), taskRel.getTaskClass(), taskRel.getRelationshipName(), taskRel.getTaskDefinitionKey()));
        }
    }
    for (TaskRepositoryConfig taskConfig : config.getTasks().values()) {
        context.addRepository(new TaskResourceRepository(taskService, resourceMapper, taskConfig.getTaskClass(), taskConfig.getBaseFilters()));
        Class<? extends TaskResource> historyClass = taskConfig.getHistoryClass();
        if (historyClass != null) {
            context.addRepository(new HistoricTaskResourceRepository(historyService, resourceMapper, historyClass, taskConfig.getBaseFilters()));
        }
        Class<? extends FormResource> formClass = taskConfig.getFormClass();
        if (formClass != null) {
            context.addRepository(new FormResourceRepository(formService, taskService, resourceMapper, formClass));
        }
    }
    context.addRepository(new FormRelationshipRepository());
}
Also used : HistoricProcessInstanceResourceRepository(io.crnk.data.activiti.internal.repository.HistoricProcessInstanceResourceRepository) RuntimeService(org.activiti.engine.RuntimeService) ActivitiResourceMapper(io.crnk.data.activiti.mapper.ActivitiResourceMapper) TaskService(org.activiti.engine.TaskService) FormService(org.activiti.engine.FormService) HistoryService(org.activiti.engine.HistoryService) HistoricProcessInstanceResourceRepository(io.crnk.data.activiti.internal.repository.HistoricProcessInstanceResourceRepository) ProcessInstanceResourceRepository(io.crnk.data.activiti.internal.repository.ProcessInstanceResourceRepository) HistoricTaskResourceRepository(io.crnk.data.activiti.internal.repository.HistoricTaskResourceRepository) TaskResourceRepository(io.crnk.data.activiti.internal.repository.TaskResourceRepository) HistoricTaskResourceRepository(io.crnk.data.activiti.internal.repository.HistoricTaskResourceRepository) FormResourceRepository(io.crnk.data.activiti.internal.repository.FormResourceRepository) FormRelationshipRepository(io.crnk.data.activiti.internal.repository.FormRelationshipRepository) TaskRelationshipRepository(io.crnk.data.activiti.internal.repository.TaskRelationshipRepository)

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