Search in sources :

Example 1 with ProcessDefinitionNotFoundException

use of org.jbpm.services.api.ProcessDefinitionNotFoundException in project jbpm by kiegroup.

the class AddDynamicProcessCommand method execute.

@Override
public Long execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
    if (processInstance == null) {
        throw new ProcessInstanceNotFoundException("No process instance found with id " + processInstanceId);
    }
    try {
        CaseFileInstance caseFile = getCaseFile(ksession, caseId);
        FactHandle factHandle = ksession.getFactHandle(caseFile);
        CaseEventSupport caseEventSupport = getCaseEventSupport(context);
        caseEventSupport.fireBeforeDynamicProcessAdded(caseId, caseFile, processInstanceId, processId, parameters);
        long subProcessInstanceId = DynamicUtils.addDynamicSubProcess(processInstance, ksession, processId, parameters);
        ksession.update(factHandle, caseFile);
        triggerRules(ksession);
        caseEventSupport.fireAfterDynamicProcessAdded(caseId, caseFile, processInstanceId, processId, parameters, subProcessInstanceId);
        return subProcessInstanceId;
    } catch (IllegalArgumentException e) {
        throw new ProcessDefinitionNotFoundException(e.getMessage());
    }
}
Also used : CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseEventSupport(org.jbpm.casemgmt.impl.event.CaseEventSupport) FactHandle(org.kie.api.runtime.rule.FactHandle) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException)

Example 2 with ProcessDefinitionNotFoundException

use of org.jbpm.services.api.ProcessDefinitionNotFoundException in project jbpm by kiegroup.

the class AddDynamicProcessToStageCommand method execute.

@Override
public Long execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    ProcessInstance processInstance = ksession.getProcessInstance(processInstanceId);
    if (processInstance == null) {
        throw new ProcessInstanceNotFoundException("No process instance found with id " + processInstanceId);
    }
    DynamicNodeInstance dynamicContext = (DynamicNodeInstance) ((WorkflowProcessInstanceImpl) processInstance).getNodeInstances(true).stream().filter(ni -> (ni instanceof DynamicNodeInstance) && stageId.equals(ni.getNode().getMetaData().get("UniqueId"))).findFirst().orElse(null);
    if (dynamicContext == null) {
        throw new StageNotFoundException("No stage found with id " + stageId);
    }
    try {
        CaseFileInstance caseFile = getCaseFile(ksession, caseId);
        CaseEventSupport caseEventSupport = getCaseEventSupport(context);
        caseEventSupport.fireBeforeDynamicProcessAdded(caseId, caseFile, processInstanceId, processId, parameters);
        long subProcessInstanceId = DynamicUtils.addDynamicSubProcess(dynamicContext, ksession, processId, parameters);
        if (subProcessInstanceId < 0) {
            throw new ProcessDefinitionNotFoundException("No process definition found with id: " + processId);
        }
        caseEventSupport.fireAfterDynamicProcessAdded(caseId, caseFile, processInstanceId, processId, parameters, subProcessInstanceId);
        return subProcessInstanceId;
    } catch (IllegalArgumentException e) {
        throw new ProcessDefinitionNotFoundException(e.getMessage());
    }
}
Also used : IdentityProvider(org.kie.internal.identity.IdentityProvider) RegistryContext(org.drools.core.command.impl.RegistryContext) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstanceImpl(org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl) Context(org.kie.api.runtime.Context) CaseEventSupport(org.jbpm.casemgmt.impl.event.CaseEventSupport) Map(java.util.Map) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) KieSession(org.kie.api.runtime.KieSession) StageNotFoundException(org.jbpm.casemgmt.api.StageNotFoundException) DynamicUtils(org.jbpm.workflow.instance.node.DynamicUtils) CaseFileInstance(org.jbpm.casemgmt.api.model.instance.CaseFileInstance) CaseEventSupport(org.jbpm.casemgmt.impl.event.CaseEventSupport) StageNotFoundException(org.jbpm.casemgmt.api.StageNotFoundException) DynamicNodeInstance(org.jbpm.workflow.instance.node.DynamicNodeInstance) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) ProcessDefinitionNotFoundException(org.jbpm.services.api.ProcessDefinitionNotFoundException) ProcessInstanceNotFoundException(org.jbpm.services.api.ProcessInstanceNotFoundException)

Aggregations

RegistryContext (org.drools.core.command.impl.RegistryContext)2 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)2 CaseEventSupport (org.jbpm.casemgmt.impl.event.CaseEventSupport)2 ProcessDefinitionNotFoundException (org.jbpm.services.api.ProcessDefinitionNotFoundException)2 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)2 KieSession (org.kie.api.runtime.KieSession)2 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)2 Map (java.util.Map)1 StageNotFoundException (org.jbpm.casemgmt.api.StageNotFoundException)1 WorkflowProcessInstanceImpl (org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl)1 DynamicNodeInstance (org.jbpm.workflow.instance.node.DynamicNodeInstance)1 DynamicUtils (org.jbpm.workflow.instance.node.DynamicUtils)1 Context (org.kie.api.runtime.Context)1 FactHandle (org.kie.api.runtime.rule.FactHandle)1 IdentityProvider (org.kie.internal.identity.IdentityProvider)1