Search in sources :

Example 1 with StartProcessInstanceWithParentCommand

use of org.jbpm.kie.services.impl.cmd.StartProcessInstanceWithParentCommand in project jbpm by kiegroup.

the class AdHocProcessServiceImpl method startProcess.

@Override
public Long startProcess(String deploymentId, String processId, CorrelationKey correlationKey, Map<String, Object> params, Long parentProcessInstanceId) {
    DeployedUnit deployedUnit = deploymentService.getDeployedUnit(deploymentId);
    if (deployedUnit == null) {
        throw new DeploymentNotFoundException("No deployments available for " + deploymentId);
    }
    if (!deployedUnit.isActive()) {
        throw new DeploymentNotFoundException("Deployments " + deploymentId + " is not active");
    }
    RuntimeManager manager = deployedUnit.getRuntimeManager();
    params = process(params, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
    RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = engine.getKieSession();
    ProcessInstance pi = null;
    try {
        pi = ((CorrelationAwareProcessRuntime) ksession).createProcessInstance(processId, correlationKey, params);
        pi = ksession.execute(new StartProcessInstanceWithParentCommand(pi.getId(), parentProcessInstanceId));
        return pi.getId();
    } finally {
        disposeRuntimeEngine(manager, engine);
    }
}
Also used : DeploymentNotFoundException(org.jbpm.services.api.DeploymentNotFoundException) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) DeployedUnit(org.jbpm.services.api.model.DeployedUnit) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) StartProcessInstanceWithParentCommand(org.jbpm.kie.services.impl.cmd.StartProcessInstanceWithParentCommand)

Aggregations

StartProcessInstanceWithParentCommand (org.jbpm.kie.services.impl.cmd.StartProcessInstanceWithParentCommand)1 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)1 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)1 KieSession (org.kie.api.runtime.KieSession)1 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)1 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)1