Inserting Facts from Json Format
by ihabo01
Hello to all,
I have the following simple rule:
declare FlatData
param1 : String
param2 : String
end
rule "Test"
when
a:FlatData(param1=="something")
then
a.setParam2("hi");
end
And I have the following code to load the rule:
KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kBuilder.add(ResourceFactory.newFileResource("myRule.drl"),ResourceType.DRL);
KnowledgeBaseConfiguration kBaseConfig = KnowledgeBaseFactory
.newKnowledgeBaseConfiguration();
KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase(kBaseConfig);
kBase.addKnowledgePackages(kBuilder.getKnowledgePackages());
StatefulKnowledgeSession session = kBase.newStatefulKnowledgeSession();
session.fireAllRules();
And I have also the following object (in Json) that I would like to insert
as a fact just before firing the rules:
{"object":{" FlatData ":{"param1":"value1","param2":”value2”}}}}
How can I achieve that?
Many thanks in advance for your help
Ihab
--
View this message in context: http://drools.46999.n3.nabble.com/Inserting-Facts-from-Json-Format-tp3570...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 4 months
Performance issue
by Ini
Hi All,
I have written a code to check the properties of a bean using drools based
rules.
I have created the different rules file where different properties of the
bean will be checked.
The code i have written is a as below:
public static void check(Object details,String rule){
long methodStartTime=System.currentTimeMillis();
Resource resource = new ClassPathResource(RULE_CLASSPATH+rule);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
long startTime=System.currentTimeMillis();
kbuilder.add(resource, ResourceType.DRL );
long endTime=System.currentTimeMillis();
System.out.println("Time taken in add resource in milli seconds
is::"+(endTime-startTime));
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.err.println(error);
}
}
StatelessKnowledgeSession ksession =
kbase.newStatelessKnowledgeSession();
ksession.execute(details);
long methodEndTime=System.currentTimeMillis();
System.out.println("Time taken in Method check in milli seconds
is::"+(methodEndTime-methodStartTime));
}
Here in the check method we have three parameters details this is the bean
whose properties need to be checked in rules file, rule this is the name of
rules file which contains all the rules.
Here the issue is that it takes around 4 seconds for the first time and 1
second for all consecutive requests, and 4 second looks too much time for
validating the rules file that has only 10 rules.
Please let me know we have some better way of doing it in drools
--
View this message in context: http://drools.46999.n3.nabble.com/Performance-issue-tp4017688.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 4 months
KnowledgeAgent custom class loader not working for PKG resources
by Hrumph
I believe there may be a bug when trying to use a custom class loader with
the KnowledgeAgent and the KnowledgeBuilderConfiguration, and when the
ChangeSet is a PKG resource.
I have been trying to get the knowledge-agent-classloader sample from the
new Drools Cookbook to work with a PKG resource. The sample works fine for
a DRL resource, but when I convert it to use my fact jar, and a PKG resource
containing my rules, which I downloaded from Guvnor, it throws a
ClassNotFoundException for my fact model. If I put my fact model in the
classpath, the error goes away and my rules can be added to the
KnowledgeAgent and run correctly. Following is the code from the sample
that I have converted, and I have attached a zip file with a complete
project demonstrating the problem. Also, I can get my rules and fact
model to work if I use a DRL ChangeSet.knowledge-agent-classloader.zip
URL modelJarURL = getClass().getResource("Patient-1.0.jar");
URLClassLoader customURLClassloader = new URLClassLoader(new URL[]
{modelJarURL });
KnowledgeBuilderConfiguration kbuilderConfig =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null,
customURLClassloader);
KnowledgeBaseConfiguration kbaseConfig =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null,
customURLClassloader);
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase(kbaseConfig);
KnowledgeAgentConfiguration aconf =
KnowledgeAgentFactory.newKnowledgeAgentConfiguration();
KnowledgeAgent kagent =
KnowledgeAgentFactory.newKnowledgeAgent("test", kbase, aconf,
kbuilderConfig);
// kagent.applyChangeSet(new ClassPathResource("change-set.xml",
getClass())); // this goes with model.jar
// kagent.applyChangeSet(new ClassPathResource("drl-change-set.xml",
getClass())); // this goes with Patient.jar
kagent.applyChangeSet(new ClassPathResource("pkg-change-set.xml",
getClass())); // this goes with Patient.jar
return kagent.getKnowledgeBase();
Following is the stack trace from the error:
java.lang.NullPointerException
at
org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:148)
at
org.drools.agent.impl.KnowledgeAgentImpl.addResourcesToKnowledgeBase(KnowledgeAgentImpl.java:1016)
at
org.drools.agent.impl.KnowledgeAgentImpl.rebuildResources(KnowledgeAgentImpl.java:785)
at
org.drools.agent.impl.KnowledgeAgentImpl.buildKnowledgeBase(KnowledgeAgentImpl.java:657)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:190)
at
org.drools.agent.impl.KnowledgeAgentImpl.applyChangeSet(KnowledgeAgentImpl.java:169)
at
drools.cookbook.chapter02.KnowledgeAgentClassloaderTest.createKnowledgeBase(KnowledgeAgentClassloaderTest.java:59)
at
drools.cookbook.chapter02.KnowledgeAgentClassloaderTest.customClassloaderTest(KnowledgeAgentClassloaderTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at
org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at
org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at
org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at
org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
I have been having the exact same problem when trying to use a custom class
loader with just a KnowldegeBuilder and no KnowledgeAgent.
http://drools.46999.n3.nabble.com/file/n3746456/knowledge-agent-classload...
knowledge-agent-classloader.zip
--
View this message in context: http://drools.46999.n3.nabble.com/KnowledgeAgent-custom-class-loader-not-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 4 months
Guvnor jackrabbit session issue?
by drdaveg
I am moving some working Eclipse-developed code to Guvnor and am seeing a
huge number of messages logged for jackrabbit "session that has already been
closed". This happens nearly continuously, with the session number
ascending:
11:18:01,889 WARN [org.apache.jackrabbit.core.session.SessionState]
(Finalizer) Attempt to close session-guest-45 after it has alre
ady been closed. Please review your code for proper session management.:
java.lang.Exception: Stack trace of the duplicate attempt t
o close session-guest-45
Trying to debug the working code moved from my local system Guvnor that say
to check the log. These session messages consume thousands of lines of
warnings (at dozens per button press) that finding any "real" error messages
seems impossible (even with automated searches).
This issue has been posted on other forums but I don't see anything here.
Is there a work around this issue - hopefully correcting the session
persistence, as opposed to changing the logging level? I am guessing
leaving Guvnor ungracefully causes an endless stream of these (forever).
Thanks!
--
View this message in context: http://drools.46999.n3.nabble.com/Guvnor-jackrabbit-session-issue-tp38680...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 5 months
The rule language. More about the agenda-group and ruleflow-group attributes
by Maxim Kolchin
Hi,
I've only been working with drools about couple of months. I've read the
documentation and some articles about drools.
But, I've not found the detail information about the agenda-group and
ruleflow-group attributes, or examples showing how to work with them.
Have I missed something? Will be grateful for any useful information.
Regards,
Maxim Kolchin,
Laboratory of Intellectual Systems,
National Research University ITMO,
Saint-Petersburg.
http://ailab.ifmo.ru/
Email: kolchinmax(a)gmail.com
12 years, 5 months
traits - don more than 3 pojos, got IllegalArgumentException
by Michal Bali
Hi all,
I came across this issue when trying out 'traits' with POJOs (not declared
types). An IllegalArgumentException is being thrown when I apply the third
'don'. Here is how to reproduce:
as the POJO I am using the Message class that comes with the project
created by the Eclipse plugin.
now the rule file:
declare Message
@Traitable
end
declare NiceMessage
@format(trait)
end
rule load
when
then
Message message = new Message();
message.setMessage("Hello World");
insert(message);
don(message, NiceMessage.class);
Message unreadMessage = new Message();
unreadMessage.setMessage("unread");
insert(unreadMessage);
don(unreadMessage, NiceMessage.class);
Message oldMessage = new Message();
oldMessage.setMessage("old");
insert(oldMessage);
System.out.println("don " + oldMessage);
don(oldMessage, NiceMessage.class); //*<--- exception happens here*
System.out.println("wont reach this point");
end
When I run this and rule 'load' fires the third 'don' will throw the
following exception:
Exception executing consequence for rule "load" in com.mycompany.app:
java.lang.IllegalArgumentException: argument type mismatch
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1101)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1029)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1251)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:709)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:673)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:221)
at com.mycompany.app.DroolsTest.main(DroolsTest.java:44)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
at
org.drools.factmodel.traits.TraitFactory.getProxy(TraitFactory.java:92)
at
org.drools.base.DefaultKnowledgeHelper.don(DefaultKnowledgeHelper.java:502)
at
org.drools.base.DefaultKnowledgeHelper.don(DefaultKnowledgeHelper.java:522)
at
com.mycompany.app.Rule_load_86ecf966a4c14d8486844cfae2e1e0d8.defaultConsequence(Rule_load_86ecf966a4c14d8486844cfae2e1e0d8.java:21)
at
com.mycompany.app.Rule_load_86ecf966a4c14d8486844cfae2e1e0d8DefaultConsequenceInvokerGenerated.evaluate(Unknown
Source)
at
com.mycompany.app.Rule_load_86ecf966a4c14d8486844cfae2e1e0d8DefaultConsequenceInvoker.evaluate(Unknown
Source)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1091)
... 6 more
Am I doing something wrong or is this a bug. I am running with 5.4.0.Beta2.
BTW traits are a great piece of functionality. Thank you!
Best regards,
Michal
12 years, 5 months
Drools verifier
by FrankVhh
Hi all,
Triggered by a post on this forum, I decided to try a testcase
implementation of Drool Verifiier.
I manage to write some code that does not produce any errors at runtime,
which is good. Unfortunately, it doesn't produce any errors/warnings/notes
on my rulefile either, which isn't good.
The drl file consists of some duplicate rules, and since the file is only
part of a ruleset, there might be some gaps as well.
I pasted the java-code below. Does anyone see where I am going wrong?
Thanks in advance!
Regards,
Frank
VerifierBuilder vBuilder =
VerifierBuilderFactory.newVerifierBuilder();
Verifier verifier = vBuilder.newVerifier();
String ruleText =
"C:\\Users\\Frank\\Documents\\DroolsWorkSpaces\\EmpiricalExperiments\\Financial
Rules\\src\\main\\rules\\clearancerules.drl";
verifier.addResourcesToVerify( ResourceFactory.newReaderResource(
new StringReader( ruleText ) ), ResourceType.DRL );
verifier.fireAnalysis();
VerifierReport result = verifier.getResult();
for(VerifierMessageBase base: result.getBySeverity(
Severity.ERROR ) ){
System.out.println( base );
}
for(VerifierMessageBase base: result.getBySeverity(
Severity.WARNING ) ){
System.out.println( base );
}
for(VerifierMessageBase base: result.getBySeverity( Severity.NOTE )
){
System.out.println( base );
}
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-verifier-tp268...
Sent from the Drools - User mailing list archive at Nabble.com.
12 years, 5 months
can't put formula on Guvnor screen
by zeeshan khan
Hi Team !
Earlier I sent this mail to rules-dev(a)lists.jboss.org. Mark
Proctor asked me to mail here so I am mailing here in the hope of reply.
Since yesterday only I started learning Drools with the help of
Google and *JBOSS DROOLS BUSINESS RULES pdf file*. I faced many problems to
understand the concept but now its going smooth. But the problem is
the *version
of PDF file of the book* and the *Govener version*. *Its quite different*.
I request you all to please provide me the latest version of PDF as I am
unable to find on net. The problem I am facing is to put the formula as
given in the screen shot in the book.
I am unable to put the *formula* as described in JBOSS DROOLS
BUSINESS RULES pdf file on page no. 102.....the formula is *salesValue-10
as the box is not capable of taking cahracters. *It is taking only integer.
Thanks in Advance for all the help and material !!!!
12 years, 5 months