org.kie.api.runtime.ObjectFilter Java Examples
The following examples show how to use
org.kie.api.runtime.ObjectFilter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FactFinder.java From qzr with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") public List<T> findFacts(final KieSession session) { ObjectFilter filter = new ObjectFilter() { @Override public boolean accept(Object object) { return object.getClass().equals(classToFind); } }; Collection<FactHandle> factHandles = session.getFactHandles(filter); List<T> facts = new ArrayList<T>(); for (FactHandle handle : factHandles) { facts.add((T) session.getObject(handle)); } return facts; }
Example #2
Source File: FactFinder.java From qzr with Apache License 2.0 | 6 votes |
/** * An assertion that a fact of the expected class with specified properties * is in working memory. * * @param session * A {@link KnowledgeSession} in which we are looking for the * fact. * @param factClass * The simple name of the class of the fact we're looking for. * @param expectedProperties * A sequence of expected property name/value pairs. * @throws IllegalAccessException * @throws InvocationTargetException * @throws NoSuchMethodException */ @SuppressWarnings("unchecked") public List<T> findFacts(final KieSession session, final BeanPropertyFilter... expectedProperties) { ObjectFilter filter = new ObjectFilter() { @Override public boolean accept(Object object) { return object.getClass().equals(classToFind) && beanMatcher.matches(object, expectedProperties); } }; Collection<FactHandle> factHandles = session.getFactHandles(filter); List<T> facts = new ArrayList<T>(); for (FactHandle handle : factHandles) { facts.add((T) session.getObject(handle)); } return facts; }
Example #3
Source File: IsAEvaluatorDefinition.java From kogito-runtimes with Apache License 2.0 | 6 votes |
protected TraitableBean lookForWrapper( final Object objectValue, InternalWorkingMemory workingMemory) { Iterator iter = workingMemory.getObjectStore().iterateObjects( new ObjectFilter() { public boolean accept(Object object) { if ( object instanceof TraitProxy ) { Object core = ((TraitProxy) object).getObject(); if ( core instanceof CoreWrapper ) { core = ((CoreWrapper) core).getCore(); } return core == objectValue; } else { return false; } } }); if ( iter.hasNext() ) { return ((TraitProxy) iter.next()).getObject(); } else { return null; // throw new RuntimeException(" Error : the isA operator must be used on a trait-type, was applied to " + objectValue ); } }
Example #4
Source File: DroolsRulesEngineImpl.java From hawkular-alerts with Apache License 2.0 | 6 votes |
@Override public void removeFacts(Predicate<Object> factFilter) { Collection<FactHandle> handles = kSession.getFactHandles(new ObjectFilter() { @Override public boolean accept(Object object) { return factFilter.test(object); } }); if (null == handles) { return; } for (FactHandle h : handles) { removeFact(h); } }
Example #5
Source File: BusPassService.java From buspass-ws with Apache License 2.0 | 6 votes |
/** * Search the {@link KieSession} for bus passes. */ private BusPass findBusPass(KieSession kieSession) { // Find all BusPass facts and 1st generation child classes of BusPass. ObjectFilter busPassFilter = new ObjectFilter() { @Override public boolean accept(Object object) { if (BusPass.class.equals(object.getClass())) return true; if (BusPass.class.equals(object.getClass().getSuperclass())) return true; return false; } }; // printFactsMessage(kieSession); List<BusPass> facts = new ArrayList<BusPass>(); for (FactHandle handle : kieSession.getFactHandles(busPassFilter)) { facts.add((BusPass) kieSession.getObject(handle)); } if (facts.size() == 0) { return null; } // Assumes that the rules will always be generating a single bus pass. return facts.get(0); }
Example #6
Source File: StatelessKnowledgeSessionImpl.java From kogito-runtimes with Apache License 2.0 | 6 votes |
public List executeWithResults(Iterable objects, ObjectFilter filter) { List list = new ArrayList(); StatefulKnowledgeSession ksession = newWorkingMemory(); try { for ( Object object : objects ) { ksession.insert( object ); } ksession.fireAllRules(); for (FactHandle fh : ksession.getFactHandles(filter)) { list.add(((InternalFactHandle) fh).getObject()); } } finally { dispose(ksession); } return list; }
Example #7
Source File: ClassAwareObjectStore.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public Iterator<InternalFactHandle> iterateNegFactHandles(ObjectFilter filter) { if (filter instanceof ClassObjectFilter) { return getOrCreateClassStore(((ClassObjectFilter) filter).getFilteredClass()).factHandlesIterator(false); } return new CompositeFactHandleIterator(concreteStores, false, filter); }
Example #8
Source File: FactFinder.java From qzr with Apache License 2.0 | 5 votes |
public void deleteFacts(final KieSession session, final BeanPropertyFilter... expectedProperties) { ObjectFilter filter = new ObjectFilter() { @Override public boolean accept(Object object) { return object.getClass().equals(classToFind) && beanMatcher.matches(object, expectedProperties); } }; Collection<FactHandle> factHandles = session.getFactHandles(filter); for (FactHandle handle : factHandles) { session.delete(handle); } }
Example #9
Source File: JavaIteratorAdapter.java From kogito-runtimes with Apache License 2.0 | 5 votes |
public JavaIteratorAdapter(Iterator iterator, int type, ObjectFilter filter) { this.iterator = iterator; this.filter = filter; this.type = type; setNext(); }
Example #10
Source File: ClassAwareObjectStore.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public Iterator<Object> iterateObjects(ObjectFilter filter) { if (filter instanceof ClassObjectFilter) { return getOrCreateClassStore(((ClassObjectFilter) filter).getFilteredClass()).objectsIterator(true); } return new CompositeObjectIterator(concreteStores, true, filter); }
Example #11
Source File: ClassAwareObjectStore.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public Iterator<InternalFactHandle> iterateFactHandles(ObjectFilter filter) { if (filter instanceof ClassObjectFilter) { return getOrCreateClassStore(((ClassObjectFilter) filter).getFilteredClass()).factHandlesIterator(true); } return new CompositeFactHandleIterator(concreteStores, true, filter); }
Example #12
Source File: ClassAwareObjectStore.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public Iterator<Object> iterateNegObjects(ObjectFilter filter) { if (filter instanceof ClassObjectFilter) { return getOrCreateClassStore(((ClassObjectFilter) filter).getFilteredClass()).objectsIterator(false); } return new CompositeObjectIterator(concreteStores, false, filter); }
Example #13
Source File: ProcessActionTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testActionContextMVEL() { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); Reader source = new StringReader( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.actions\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " <imports>\n" + " <import name=\"org.jbpm.integrationtests.test.Message\" />\n" + " </imports>\n" + " <globals>\n" + " <global identifier=\"list\" type=\"java.util.List\" />\n" + " </globals>\n" + " <variables>\n" + " <variable name=\"variable\" >\n" + " <type name=\"org.jbpm.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>SomeText</value>\n" + " </variable>\n" + " </variables>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <actionNode id=\"2\" name=\"MyActionNode\" >\n" + " <action type=\"expression\" dialect=\"mvel\" >System.out.println(\"Triggered\");\n" + "System.out.println(kcontext.getKnowledgeRuntime());\n" + "String myVariable = (String) kcontext.getVariable(\"variable\");\n" + "list.add(myVariable);\n" + "String nodeName = kcontext.getNodeInstance().getNodeName();\n" + "list.add(nodeName);\n" + "insert( new Message() );\n" + "</action>\n" + " </actionNode>\n" + " <end id=\"3\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"2\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " </connections>\n" + "\n" + "</process>"); kbuilder.add(new ReaderResource(source), ResourceType.DRF); if ( kbuilder.hasErrors() ) { fail( kbuilder.getErrors().toString() ); } KieBase kbase = kbuilder.newKieBase(); KieSession ksession = kbase.newKieSession(); List<String> list = new ArrayList<String>(); ksession.setGlobal("list", list); ProcessInstance processInstance = ksession.startProcess("org.drools.actions"); assertEquals(2, list.size()); assertEquals("SomeText", list.get(0)); assertEquals("MyActionNode", list.get(1)); Collection<FactHandle> factHandles = ksession.getFactHandles(new ObjectFilter() { public boolean accept(Object object) { return object instanceof Message; } }); assertFalse(factHandles.isEmpty()); assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState()); }
Example #14
Source File: CommandFactory.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public static Command newGetObjects(ObjectFilter filter, String outIdentifier ) { return getCommandFactoryProvider().newGetObjects( filter, outIdentifier ); }
Example #15
Source File: MockKieSession.java From pnc with Apache License 2.0 | 4 votes |
@Override public Collection<? extends Object> getObjects(ObjectFilter objectFilter) { return null; }
Example #16
Source File: MockKieSession.java From pnc with Apache License 2.0 | 4 votes |
@Override public <T extends FactHandle> Collection<T> getFactHandles(ObjectFilter objectFilter) { return null; }
Example #17
Source File: ProcessActionTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Test public void testActionContextJavaBackwardCheck() { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); Reader source = new StringReader( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<process xmlns=\"http://drools.org/drools-5.0/process\"\n" + " xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" + " type=\"RuleFlow\" name=\"flow\" id=\"org.drools.actions\" package-name=\"org.drools\" version=\"1\" >\n" + "\n" + " <header>\n" + " <imports>\n" + " <import name=\"org.jbpm.integrationtests.test.Message\" />\n" + " </imports>\n" + " <globals>\n" + " <global identifier=\"list\" type=\"java.util.List\" />\n" + " </globals>\n" + " <variables>\n" + " <variable name=\"variable\" >\n" + " <type name=\"org.drools.core.process.core.datatype.impl.type.StringDataType\" />\n" + " <value>SomeText</value>\n" + " </variable>\n" + " </variables>\n" + " </header>\n" + "\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" />\n" + " <actionNode id=\"2\" name=\"MyActionNode\" >\n" + " <action type=\"expression\" dialect=\"java\" >System.out.println(\"Triggered\");\n" + "String myVariable = (String) kcontext.getVariable(\"variable\");\n" + "list.add(myVariable);\n" + "String nodeName = kcontext.getNodeInstance().getNodeName();\n" + "list.add(nodeName);\n" + "insert( new Message() );\n" + "</action>\n" + " </actionNode>\n" + " <end id=\"3\" name=\"End\" />\n" + " </nodes>\n" + "\n" + " <connections>\n" + " <connection from=\"1\" to=\"2\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " </connections>\n" + "\n" + "</process>"); kbuilder.add(new ReaderResource(source), ResourceType.DRF); KieBase kbase = kbuilder.newKieBase(); KieSession ksession = kbase.newKieSession(); List<String> list = new ArrayList<String>(); ksession.setGlobal("list", list); ProcessInstance processInstance = ksession.startProcess("org.drools.actions"); assertEquals(2, list.size()); assertEquals("SomeText", list.get(0)); assertEquals("MyActionNode", list.get(1)); Collection<FactHandle> factHandles = ksession.getFactHandles(new ObjectFilter() { public boolean accept(Object object) { return object instanceof Message; } }); assertFalse(factHandles.isEmpty()); assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState()); }
Example #18
Source File: CommandBasedEntryPoint.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Override public Collection<? extends Object> getObjects(ObjectFilter filter) { return runner.execute( new GetObjectsInEntryPointCommand(filter, entryPoint) ); }
Example #19
Source File: CommandBasedStatefulKnowledgeSession.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public Collection<? extends Object> getObjects(ObjectFilter filter) { Collection result = runner.execute( new GetObjectsCommand( filter ) ); return result; }
Example #20
Source File: CommandBasedStatefulKnowledgeSession.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public <T extends FactHandle> Collection<T> getFactHandles(ObjectFilter filter) { return (Collection<T>) this.runner.execute( new GetFactHandlesCommand( filter ) ); }
Example #21
Source File: FluentCommandFactoryServiceImpl.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public FluentCommandFactoryServiceImpl newGetObjects(ObjectFilter filter, String outIdentifier) { commands.add( factory.newGetObjects( filter, outIdentifier ) ); return this; }
Example #22
Source File: FluentCommandFactoryServiceImpl.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public FluentCommandFactoryServiceImpl newGetObjects(ObjectFilter filter) { commands.add( factory.newGetObjects( filter ) ); return this; }
Example #23
Source File: CommandFactoryServiceImpl.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Override public Command newGetFactHandles(ObjectFilter filter, String outIdentifier) { GetFactHandlesCommand factHandlesCommand = new GetFactHandlesCommand(filter); factHandlesCommand.setOutIdentifier(outIdentifier); return factHandlesCommand; }
Example #24
Source File: CommandFactoryServiceImpl.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Override public Command newGetFactHandles(ObjectFilter filter) { return new GetFactHandlesCommand(filter); }
Example #25
Source File: CommandFactoryServiceImpl.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public Command newGetObjects(ObjectFilter filter, String outIdentifier) { return new GetObjectsCommand(filter, outIdentifier); }
Example #26
Source File: CommandFactoryServiceImpl.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public Command newGetObjects(ObjectFilter filter) { return new GetObjectsCommand(filter); }
Example #27
Source File: CommandFactoryServiceImpl.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public Command newGetObjects() { return newGetObjects((ObjectFilter) null); }
Example #28
Source File: GetObjectsCommand.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public ObjectFilter getFilter() { if( this.filter == null ) { this.filter = this.classObjectFilter; } return this.filter; }
Example #29
Source File: GetObjectsCommand.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public void setFilter(ObjectFilter filter) { this.filter = filter; if( filter instanceof ClassObjectFilter ) { this.classObjectFilter = new ClassObjectSerializationFilter((ClassObjectFilter)filter); } }
Example #30
Source File: CommandBasedEntryPoint.java From kogito-runtimes with Apache License 2.0 | 4 votes |
@Override public <T extends FactHandle> Collection<T> getFactHandles(ObjectFilter filter) { return (Collection<T>) runner.execute( new GetFactHandlesInEntryPointCommand(entryPoint, filter) ); }