Search in sources :

Example 11 with ProcessInstance

use of org.kie.api.runtime.process.ProcessInstance in project drools by kiegroup.

the class DefaultKnowledgeHelper method getContext.

@SuppressWarnings("unchecked")
public <T> T getContext(Class<T> contextClass) {
    if (ProcessContext.class.equals(contextClass)) {
        String ruleflowGroupName = getMatch().getRule().getRuleFlowGroup();
        if (ruleflowGroupName != null) {
            Map<Long, String> nodeInstances = ((InternalRuleFlowGroup) workingMemory.getAgenda().getRuleFlowGroup(ruleflowGroupName)).getNodeInstances();
            if (!nodeInstances.isEmpty()) {
                if (nodeInstances.size() > 1) {
                    // TODO
                    throw new UnsupportedOperationException("Not supporting multiple node instances for the same ruleflow group");
                }
                Map.Entry<Long, String> entry = nodeInstances.entrySet().iterator().next();
                ProcessInstance processInstance = workingMemory.getProcessInstance(entry.getKey());
                org.drools.core.spi.ProcessContext context = new org.drools.core.spi.ProcessContext(workingMemory.getKnowledgeRuntime());
                context.setProcessInstance(processInstance);
                String nodeInstance = entry.getValue();
                String[] nodeInstanceIds = nodeInstance.split(":");
                NodeInstanceContainer container = (WorkflowProcessInstance) processInstance;
                for (int i = 0; i < nodeInstanceIds.length; i++) {
                    for (NodeInstance subNodeInstance : container.getNodeInstances()) {
                        if (subNodeInstance.getId() == new Long(nodeInstanceIds[i])) {
                            if (i == nodeInstanceIds.length - 1) {
                                context.setNodeInstance(subNodeInstance);
                                break;
                            } else {
                                container = (NodeInstanceContainer) subNodeInstance;
                            }
                        }
                    }
                }
                return (T) context;
            }
        }
    }
    return null;
}
Also used : NodeInstanceContainer(org.kie.api.runtime.process.NodeInstanceContainer) ProcessContext(org.kie.api.runtime.process.ProcessContext) WorkingMemoryEntryPoint(org.drools.core.WorkingMemoryEntryPoint) NamedEntryPoint(org.drools.core.common.NamedEntryPoint) InternalWorkingMemoryEntryPoint(org.drools.core.common.InternalWorkingMemoryEntryPoint) EntryPoint(org.kie.api.runtime.rule.EntryPoint) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance) Map(java.util.Map) NodeInstance(org.kie.api.runtime.process.NodeInstance) InternalRuleFlowGroup(org.drools.core.common.InternalRuleFlowGroup) WorkflowProcessInstance(org.kie.api.runtime.process.WorkflowProcessInstance)

Example 12 with ProcessInstance

use of org.kie.api.runtime.process.ProcessInstance in project drools by kiegroup.

the class CreateCorrelatedProcessInstanceCommand method execute.

public ProcessInstance execute(Context context) {
    KieSession ksession = ((RegistryContext) context).lookup(KieSession.class);
    if (data != null) {
        for (Object o : data) {
            ksession.insert(o);
        }
    }
    ProcessInstance processInstance = ((CorrelationAwareProcessRuntime) ksession).createProcessInstance(processId, correlationKey, parameters);
    if (this.outIdentifier != null) {
        ((RegistryContext) context).lookup(ExecutionResultImpl.class).setResult(this.outIdentifier, processInstance.getId());
    }
    return processInstance;
}
Also used : CorrelationAwareProcessRuntime(org.kie.internal.process.CorrelationAwareProcessRuntime) ExecutionResultImpl(org.drools.core.runtime.impl.ExecutionResultImpl) KieSession(org.kie.api.runtime.KieSession) RegistryContext(org.drools.core.command.impl.RegistryContext) ProcessInstance(org.kie.api.runtime.process.ProcessInstance)

Aggregations

ProcessInstance (org.kie.api.runtime.process.ProcessInstance)12 RegistryContext (org.drools.core.command.impl.RegistryContext)7 KieSession (org.kie.api.runtime.KieSession)7 ExecutionResultImpl (org.drools.core.runtime.impl.ExecutionResultImpl)4 WorkItem (org.drools.core.process.instance.WorkItem)3 Map (java.util.Map)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 PersistenceContext (org.drools.persistence.api.PersistenceContext)2 WorkItemInfo (org.drools.persistence.info.WorkItemInfo)2 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)2 CorrelationAwareProcessRuntime (org.kie.internal.process.CorrelationAwareProcessRuntime)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 WorkingMemoryEntryPoint (org.drools.core.WorkingMemoryEntryPoint)1 InternalRuleFlowGroup (org.drools.core.common.InternalRuleFlowGroup)1 InternalWorkingMemoryEntryPoint (org.drools.core.common.InternalWorkingMemoryEntryPoint)1 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)1 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)1 NodeInstance (org.kie.api.runtime.process.NodeInstance)1 NodeInstanceContainer (org.kie.api.runtime.process.NodeInstanceContainer)1