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