use of org.kie.api.runtime.process.NodeInstanceContainer 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;
}
use of org.kie.api.runtime.process.NodeInstanceContainer 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;
}
Aggregations