Search in sources :

Example 1 with NodeInstance

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

the class WorkingMemoryLogger method createNodeInstanceId.

private String createNodeInstanceId(NodeInstance nodeInstance) {
    String nodeInstanceId = "" + nodeInstance.getId();
    NodeInstanceContainer nodeContainer = nodeInstance.getNodeInstanceContainer();
    while (nodeContainer != null) {
        if (nodeContainer instanceof NodeInstance) {
            nodeInstance = (NodeInstance) nodeContainer;
            nodeInstanceId = nodeInstance.getId() + ":" + nodeInstanceId;
            nodeContainer = nodeInstance.getNodeInstanceContainer();
        } else {
            break;
        }
    }
    return nodeInstanceId;
}
Also used : NodeInstanceContainer(org.kie.api.runtime.process.NodeInstanceContainer) NodeInstance(org.kie.api.runtime.process.NodeInstance)

Example 2 with NodeInstance

use of org.kie.api.runtime.process.NodeInstance 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)

Aggregations

NodeInstance (org.kie.api.runtime.process.NodeInstance)2 NodeInstanceContainer (org.kie.api.runtime.process.NodeInstanceContainer)2 Map (java.util.Map)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 ProcessContext (org.kie.api.runtime.process.ProcessContext)1 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)1 WorkflowProcessInstance (org.kie.api.runtime.process.WorkflowProcessInstance)1 EntryPoint (org.kie.api.runtime.rule.EntryPoint)1