Get fact type returning null
by kavita
Hi,
I am a beginner to drools and am trying to integrate drools rules to java .
Am doing this using changeset.
Here's my piece of code:
package edu.arizona;
import org.drools.KnowledgeBase;
import org.drools.agent.KnowledgeAgent;
import org.drools.agent.KnowledgeAgentFactory;
import org.drools.definition.type.FactType;
import org.drools.io.Resource;
import org.drools.io.ResourceFactory;
import org.drools.runtime.StatefulKnowledgeSession;
public class TestRest {
public static void main(String[] args) throws
InstantiationException,IllegalAccessException {
StatefulKnowledgeSession ksession = null;
KnowledgeBase kbase = readKnowledgeBase();
FactType factType = kbase.getFactType("edu.arizona", "result");
System.out.println (factType);
Object obj = factType.newInstance();
factType.set(obj,"rawConcentration",150);
ksession = kbase.newStatefulKnowledgeSession();
ksession.insert(obj);
ksession.fireAllRules();
System.out.println(factType.get(obj,"rescode"));
}
private static KnowledgeBase readKnowledgeBase() {
KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent("LabAgent");
Resource changeset = ResourceFactory.newClassPathResource(
"edu.arizona/lab-changeset.xml");
kagent.applyChangeSet(changeset);
KnowledgeBase kbase = kagent.getKnowledgeBase();
kagent.dispose();
return kbase;
}
}
When i run the application the System.out.println (factType) is printing as
null. and getting
Exception in thread "main" java.lang.NullPointerException
at edu.arizona.TestRest.main(TestRest.java:20)
What am i missing? Please help.
Thanks,
Kavitha.
--
View this message in context: http://drools.46999.n3.nabble.com/Get-fact-type-returning-null-tp3667266p...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
cannot import function
by xdyl
HI,all:
i want import an function in another drools file. but when i use "import
function " in drools 5.3.0.Final
compile give me a error message:
Rule Compilation error : [Rule name='start']
room/Rule_start.java (2:279) : Only a type can be imported.
util.convertString2Set resolves to a package
room/Rule_start.java (9:629) : The method convertString2Set(String) is
undefined for the type Rule_start
and i search in google not find any help .
--
View this message in context: http://drools.46999.n3.nabble.com/cannot-import-function-tp3668460p366846...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
APIs to create rules
by bobbi_80
public static class CpuTracker{
private String machinename;
private String averageCPU;
}
Consider the following rule :
rule first_rule
@ID(“1”)
when
averageCPU > 80
then
syso("do something");
end
I have the following requirements to let the user change the rules.
1) Create an app that will accept user input for rule Name, LHS , RHS of
rule.
2) Add/remove rules from the knowledge base at runtime.
3) Display all compiled rules .
For task(1) I am unable to figure out the exact APIs to programmatically
create rules . Have gone through number of posts in user forums and docs but
got nothing conclusive.
For Task(3) I could get rule name and any other meta data information but
not LHS,RHS info. Does that mean that rules will have to be persisted and
there are no APIs to fetch LHS/RHS at run time?
What are my options here?
Many Thanks,
Dumb programmer!
--
View this message in context: http://drools.46999.n3.nabble.com/APIs-to-create-rules-tp3662689p3662689....
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
drools5.2 integrate with JMS
by DroolersEye
Hi, I would like to integrate JMS with drools 5.2. I have a confusion over
selecting right approach.
I noticed from the mailing list drools pipeline is depricated so I assume
that not recomended now. So ignored it than look for another option but not
using spring? when i check the user forum I not getting any right direction
insted more confusion selecting rigt tool. Can some one help me to provide
me some info about integration JMS with drools without using spring?i am
using drools5.2
thanks lot,
-----
with kind regards,
--
View this message in context: http://drools.46999.n3.nabble.com/drools5-2-integrate-with-JMS-tp3546100p...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
ArrayIndexOutOfBounds exception when predicate parameter is varArgs
by Martin A
Hello, guys,
I've got a rule which states:
rule "quest_reach_level_1_in_any_category_accomplished"
when
$gsc : GameStateController(hasEventOccurred("eventId") &&
!hasEventOccurred("otherEventId") && hasAnyEventOccurred("param1",
"param2", "param3", "param4", "param5", "param6", "param7", "param8",
"param9", "param10", "param11", "param12"))
$response : Response()
then
... some business logic
end
which ends up with:
Caused by: org.drools.RuntimeDroolsException: Exception executing predicate
hasA
nyEventOccurred("level1_love", "level1_friendship", "level1_prosperity",
"level1
_charisma", "level1_willpower", "level1_wisdom", "level1_entertainment",
"level1
_adventure", "level1_inspiration", "level1_harmony",
"level1_lightheartedness",
"level1_confidence")
at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:298)
at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:145)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateModifyObject(SingleObjectSinkAdapter.java:68)
at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:149)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateModifyObject(SingleObjectSinkAdapter.java:68)
at org.drools.reteoo.AlphaNode.modifyObject(AlphaNode.java:149)
at
org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateModifyObject(CompositeObjectSinkAdapter.java:468)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateModifyObject(CompositeObjectSinkAdapter.java:436)
at
org.drools.reteoo.ObjectTypeNode.modifyObject(ObjectTypeNode.java:288)
at
org.drools.reteoo.EntryPointNode.modifyObject(EntryPointNode.java:271)
at
org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:459)
at
org.drools.common.NamedEntryPoint.update(NamedEntryPoint.java:363)
at
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:298)
at
org.drools.base.DefaultKnowledgeHelper.update(DefaultKnowledgeHelper.java:306)
at
org.drools.base.ModifyInterceptor.doAfter(ModifyInterceptor.java:59)
at
org.mvel2.ast.InterceptorWrapper.getReducedValueAccelerated(InterceptorWrapper.java:38)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:87)
at
org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:122)
at org.mvel2.MVEL.executeExpression(MVEL.java:930)
at
org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:105)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1091)
... 47 more
Caused by: java.lang.RuntimeException: cannot invoke method:
hasAnyEventOccurred
at
org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:62)
at
org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:106)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:87)
at
org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:122)
at org.mvel2.MVEL.executeExpression(MVEL.java:930)
at
org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.java:100)
at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:291)
... 67 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 12
at
org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.executeAll(MethodAccessor.java:148)
at
org.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:47)
... 73 more
I'm using Drools 5.3.0.Final and it fails when it comes to evaluating the
predicate hasAnyEventOccurred(String... varArgs).
Thanks,
Martin
12 years, 10 months
Multiple conditions in a single BRL
by srinivasasanda
Hi,
Please suggest me in achieving my requirement.My requirement is.
When
Person age is equal to 25,Print 25 and return 25..else if Person age is
equal to 30,Print 30 and return 30,else if Person age is equal to 50,print
50 return 50..
How can I write these nested type of if-else statements in a single
BRL.Please suggest me.I tried by verifying docs bt couldnt find solution...
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/Multiple-conditions-in-a-single-BRL-tp3...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
Insert and Retract from drools server in one call?
by dunnlow
Hi. I've got a stateful session running in drools-server. A separate client
is inserting facts using a batchexecutioncommand and reading/using the
result returned from the service call. I need a stateful session because
when I insert the facts from the client, some of the rules that trigger
insert new facts. However, once those main facts are inserted, and the
relevant rules fire, the initial facts can be retracted.
Can anyone tell me the best way to do this. Basically, I'd like to do
something like an insertLogical (I suppose) to the server so that the fact
is retracted once all the rules have fired.
I realize I can get the facthandle from the result and then send another
command to retract that fact handle. However, this means two calls to the
server for every event; I'd like to make this happen in a single call.
Does anyone have any ideas?
Thanks,
-J
--
View this message in context: http://drools.46999.n3.nabble.com/Insert-and-Retract-from-drools-server-i...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months