use of org.drools.core.common.PropagationContextFactory in project drools by kiegroup.
the class StatefulKnowledgeSessionImpl method initInitialFact.
public InternalFactHandle initInitialFact(InternalKnowledgeBase kBase, InternalWorkingMemoryEntryPoint entryPoint, EntryPointId epId, MarshallerReaderContext context) {
InitialFact initialFact = InitialFactImpl.getInstance();
InternalFactHandle handle = new DefaultFactHandle(0, initialFact, 0, entryPoint);
ClassObjectTypeConf otc = (ClassObjectTypeConf) entryPoint.getObjectTypeConfigurationRegistry().getObjectTypeConf(epId, initialFact);
ObjectTypeNode otn = otc.getConcreteObjectTypeNode();
if (otn != null) {
PropagationContextFactory ctxFact = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
PropagationContext pctx = ctxFact.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, handle, epId, context);
otn.assertInitialFact(handle, pctx, this);
}
return handle;
}
use of org.drools.core.common.PropagationContextFactory in project drools by kiegroup.
the class AddRemoveRule method insertFacts.
private static void insertFacts(PathEndNodes endNodes, InternalWorkingMemory[] wms) {
Set<LeftTupleNode> visited = new HashSet<LeftTupleNode>();
for (PathEndNode endNode : endNodes.subjectEndNodes) {
LeftTupleNode[] nodes = endNode.getPathNodes();
for (int i = 0; i < nodes.length; i++) {
LeftTupleNode node = nodes[i];
if (NodeTypeEnums.isBetaNode(node) && node.getAssociationsSize() == 1) {
if (!visited.add(node)) {
// this is to avoid rentering a path, and processing nodes twice. This can happen for nested subnetworks.
continue;
}
BetaNode bn = (BetaNode) node;
if (!bn.isRightInputIsRiaNode()) {
for (int j = 0; j < wms.length; j++) {
PropagationContextFactory pctxFactory = wms[j].getKnowledgeBase().getConfiguration().getComponentFactory().getPropagationContextFactory();
final PropagationContext pctx = pctxFactory.createPropagationContext(wms[j].getNextPropagationIdCounter(), PropagationContext.Type.RULE_ADDITION, null, null, null);
bn.getRightInput().updateSink(bn, pctx, wms[j]);
}
}
}
}
}
}
use of org.drools.core.common.PropagationContextFactory in project drools by kiegroup.
the class AlphaNodeTest method testLiteralConstraintAssertObjectWithoutMemory.
@Test
public void testLiteralConstraintAssertObjectWithoutMemory() throws Exception {
InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
BuildContext buildContext = new BuildContext(kBase);
buildContext.setRule(new RuleImpl("test"));
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
final RuleImpl rule = new RuleImpl("test-rule");
PropagationContextFactory pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
final PropagationContext context = pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null);
final MockObjectSource source = new MockObjectSource(buildContext.getNextId());
final ClassFieldReader extractor = store.getReader(Cheese.class, "type");
final FieldValue field = FieldFactory.getInstance().getFieldValue("cheddar");
final MvelConstraint constraint = new MvelConstraintTestUtil("type == \"cheddar\"", field, extractor);
// With Memory
final AlphaNode alphaNode = new AlphaNode(buildContext.getNextId(), constraint, source, // no memory
buildContext);
final MockObjectSink sink = new MockObjectSink();
alphaNode.addObjectSink(sink);
final Cheese cheddar = new Cheese("cheddar", 5);
final DefaultFactHandle f0 = (DefaultFactHandle) ksession.insert(cheddar);
// check sink is empty
assertLength(0, sink.getAsserted());
// object should assert as it passes text
alphaNode.assertObject(f0, context, ksession);
assertEquals(1, sink.getAsserted().size());
Object[] list = (Object[]) sink.getAsserted().get(0);
assertSame(cheddar, ksession.getObject((DefaultFactHandle) list[0]));
final Cheese stilton = new Cheese("stilton", 6);
final DefaultFactHandle f1 = new DefaultFactHandle(1, stilton);
// object should NOT assert as it does not pass test
alphaNode.assertObject(f1, context, ksession);
assertLength(1, sink.getAsserted());
list = (Object[]) sink.getAsserted().get(0);
assertSame(cheddar, ksession.getObject((DefaultFactHandle) list[0]));
}
Aggregations