Search in sources :

Example 1 with SubProcessFactory

use of org.jbpm.workflow.core.node.SubProcessFactory in project kogito-runtimes by kiegroup.

the class LambdaSubProcessNodeInstance method handleOutMappings.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void handleOutMappings(ProcessInstance processInstance) {
    SubProcessFactory subProcessFactory = getSubProcessNode().getSubProcessFactory();
    org.kie.kogito.process.ProcessInstance<?> pi = ((org.kie.kogito.process.ProcessInstance<?>) processInstance.getMetaData().get("KogitoProcessInstance"));
    if (pi != null) {
        subProcessFactory.unbind(ContextFactory.fromNode(this), pi.variables());
    }
}
Also used : SubProcessFactory(org.jbpm.workflow.core.node.SubProcessFactory)

Example 2 with SubProcessFactory

use of org.jbpm.workflow.core.node.SubProcessFactory in project kogito-runtimes by kiegroup.

the class LambdaSubProcessNodeInstance method internalTrigger.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void internalTrigger(KogitoNodeInstance from, String type) {
    super.internalTrigger(from, type);
    // if node instance was cancelled, abort
    if (getNodeInstanceContainer().getNodeInstance(getStringId()) == null) {
        return;
    }
    if (!Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("A SubProcess node only accepts default incoming connections!");
    }
    KogitoProcessContextImpl context = ContextFactory.fromNode(this);
    SubProcessFactory subProcessFactory = getSubProcessNode().getSubProcessFactory();
    Object o = subProcessFactory.bind(context);
    org.kie.kogito.process.ProcessInstance<?> processInstance = subProcessFactory.createInstance(o);
    org.kie.api.runtime.process.ProcessInstance pi = ((AbstractProcessInstance<?>) processInstance).internalGetProcessInstance();
    ((ProcessInstanceImpl) pi).setMetaData("ParentProcessInstanceId", getProcessInstance().getStringId());
    ((ProcessInstanceImpl) pi).setMetaData("ParentNodeInstanceId", getUniqueId());
    ((ProcessInstanceImpl) pi).setMetaData("ParentNodeId", getSubProcessNode().getUniqueId());
    ((ProcessInstanceImpl) pi).setParentProcessInstanceId(getProcessInstance().getStringId());
    ((ProcessInstanceImpl) pi).setRootProcessInstanceId(StringUtils.isEmpty(getProcessInstance().getRootProcessInstanceId()) ? getProcessInstance().getStringId() : getProcessInstance().getRootProcessInstanceId());
    ((ProcessInstanceImpl) pi).setRootProcessId(StringUtils.isEmpty(getProcessInstance().getRootProcessId()) ? getProcessInstance().getProcessId() : getProcessInstance().getRootProcessId());
    ((ProcessInstanceImpl) pi).setSignalCompletion(getSubProcessNode().isWaitForCompletion());
    processInstance.start();
    this.processInstanceId = processInstance.id();
    this.asyncWaitingNodeInstance = hasAsyncNodeInstance(pi);
    subProcessFactory.unbind(context, processInstance.variables());
    if (!getSubProcessNode().isWaitForCompletion()) {
        triggerCompleted();
    } else if (processInstance.status() == ProcessInstance.STATE_COMPLETED || processInstance.status() == ProcessInstance.STATE_ABORTED) {
        processInstanceCompleted((ProcessInstanceImpl) pi);
    } else {
        addProcessListener();
    }
}
Also used : AbstractProcessInstance(org.kie.kogito.process.impl.AbstractProcessInstance) SubProcessFactory(org.jbpm.workflow.core.node.SubProcessFactory) ProcessInstanceImpl(org.jbpm.process.instance.impl.ProcessInstanceImpl) KogitoProcessContextImpl(org.jbpm.process.instance.KogitoProcessContextImpl)

Aggregations

SubProcessFactory (org.jbpm.workflow.core.node.SubProcessFactory)2 KogitoProcessContextImpl (org.jbpm.process.instance.KogitoProcessContextImpl)1 ProcessInstanceImpl (org.jbpm.process.instance.impl.ProcessInstanceImpl)1 AbstractProcessInstance (org.kie.kogito.process.impl.AbstractProcessInstance)1