Can we set a default value for emlpty cells in Drools templates
by swaroop
Hi,
I am trying to write a template and came across a scenario where one of the
condition cell $a : Company(condition), When
condition is left blank then entire predicate is missed and iam using the
ref of the company obj $a to set some values which is failing as the
declaration part is missing, So i was thinking, if we can have a default
value to the cell as $a : Company(), then the scenario will be
handled.Kindly let me know how to implement the default value for a cell in
template to overcome the above mentioned scenario
Thanks
Swaroop
--
View this message in context: http://drools.46999.n3.nabble.com/Can-we-set-a-default-value-for-emlpty-c...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
ClassCastException when KnowledgeAgent loads declared type
by lhorton
Code level: 5.2.0.Final
I have a DRL file that includes a declared type:
package com.abclegal.rules.servicerequirements
declare TransgressionMetaData
attempt : ServiceAttempt
requirement : Requirement
end
The package loads the first time and its rules run without error. If I make
a change to the file and hot-deploy it (copy it to the server), the
ResourceChangeScanner picks up the file and KnowledgeAgent loads it, but
when any rule from that package subsequently fires, I get a
ClassCastException on the declared type:
com.abclegal.rules.servicerequirements.TransgressionMetaData cannot be cast
to com.abclegal.rules.servicerequirements.TransgressionMetaData
it appears the KnowledgeAgent is not replacing the existing (in working
memory) definition of the declared type, but instead is creating a new one
with a different hash code.
looks like a bug?
Full stack trace:
Caused by: RulesConsequenceException executing consequence for rule
"PHOTO_WHEN_SERVED: Photo must be taken if served." in
com.abclegal.rules.servicerequirements
[Error: drools.insert(new TransgressionMetaData($attempt,$req)):
com.abclegal.rules.servicerequirements.TransgressionMetaData cannot be cast
to com.abclegal.rules.servicerequirements.TransgressionMetaData]
[Near : {... @Modify with($attempt){ ....}]
^
[Line: 1, Column: 1]
java.lang.ClassCastException:
com.abclegal.rules.servicerequirements.TransgressionMetaData cannot be cast
to com.abclegal.rules.servicerequirements.TransgressionMetaData
Rules working memory:
Fact ServiceAttempt id: 17
at
com.abclegal.rules.utility.RulesConsequenceExceptionHandler.handleException(RulesConsequenceExceptionHandler.java:24)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:912)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:845)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1056)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:733)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:699)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:218)
at
org.drools.impl.StatelessKnowledgeSessionImpl.execute(StatelessKnowledgeSessionImpl.java:305)
at
com.abclegal.rules.server.RulesServiceImpl.execute(RulesServiceImpl.java:378)
... 44 more
Caused by: [Error: drools.insert(new TransgressionMetaData($attempt,$req)):
com.abclegal.rules.servicerequirements.TransgressionMetaData cannot be cast
to com.abclegal.rules.servicerequirements.TransgressionMetaData]
[Near : {... @Modify with($attempt){ ....}]
^
[Line: 1, Column: 1]
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:409)
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:140)
at
org.mvel2.optimizers.dynamic.DynamicOptimizer.optimizeAccessor(DynamicOptimizer.java:67)
at org.mvel2.ast.ASTNode.optimize(ASTNode.java:154)
at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:110)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:86)
at
org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:122)
at
org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:115)
at org.mvel2.MVEL.executeExpression(MVEL.java:928)
at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:105)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:906)
... 51 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1066)
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:338)
... 61 more
--
View this message in context: http://drools.46999.n3.nabble.com/ClassCastException-when-KnowledgeAgent-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
Upgrade Drools from 5.1 to 5.3
by womuji
Hi,
We have a legacy Drools application using 5.1 and we are planning to upgrade
to 5.3. I have several questions:
1. Are org.drools.StatelessSession and RuleBase deprecated? and instead we
should use KnowledgeBase and StatelessKnowledgeSession?
2. In 5.1.1, we extend WorkingMemoryLogger(final WorkingMemoryEventManager
workingMemoryEventManager) , but it's changed to WorkingMemoryLogger(final
WorkingMemory workingMemory) in 5.3, how do we change accordingly?
Thanks in advance.
--
View this message in context: http://drools.46999.n3.nabble.com/Upgrade-Drools-from-5-1-to-5-3-tp367287...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
Groovy classes as fact classes in drool
by kavita
Hi,
Can anybody tell me how to use groovy classes as fact classes in drools.
When i try to upload the jar file generated from the groovy class am getting
the following error:
SEVERE: Servlet.service() for servlet AssetFileServlet threw exception
java.lang.ClassNotFoundException: groovy.lang.GroovyObject
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at
org.drools.rule.MapBackedClassLoader.loadClass(MapBackedClassLoader.java:109)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at
org.drools.rule.MapBackedClassLoader.fastFindClass(MapBackedClassLoader.java:86)
at
org.drools.rule.MapBackedClassLoader.loadClass(MapBackedClassLoader.java:104)
at java.lang.ClassLoader.loadClass(Unknown Source)
at
org.drools.guvnor.server.contenthandler.ModelContentHandler.isClassVisible(ModelContentHandler.java:183)
at
org.drools.guvnor.server.contenthandler.ModelContentHandler.getImportsFromJar(ModelContentHandler.java:148)
at
org.drools.guvnor.server.contenthandler.ModelContentHandler.onAttachmentAdded(ModelContentHandler.java:66)
at
org.drools.guvnor.server.files.FileManagerUtils.attachFileToAsset(FileManagerUtils.java:115)
at
org.drools.guvnor.server.files.FileManagerUtils.attachFile(FileManagerUtils.java:87)
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.jboss.seam.util.Reflections.invoke(Reflections.java:22)
at
org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
at
org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.security.SecurityInterceptor.aroundInvoke(SecurityInterceptor.java:163)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
at
org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
at
org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
at
org.drools.guvnor.server.files.FileManagerUtils_$$_javassist_seam_10.attachFile(FileManagerUtils_$$_javassist_seam_10.java)
at
org.drools.guvnor.server.files.AssetFileServlet.processAttachFileToAsset(AssetFileServlet.java:97)
at
org.drools.guvnor.server.files.AssetFileServlet.doPost(AssetFileServlet.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.web.ContextFilter$1.process(ContextFilter.java:42)
at
org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:65)
at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:37)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Please help.
Thanks,
Kavitha.
--
View this message in context: http://drools.46999.n3.nabble.com/Groovy-classes-as-fact-classes-in-drool...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
Why isn't my rule firing??
by dunnlow
First, my intent:
1) insert a pojo into a stateful session
2) based upon that pojo's attributes, create and insert a new fact
(different type)
3) retract the initial pojo, but keep the newly created fact in memory for
some period of time
After some helpful insight from the forum, I thought I could knock this out.
However, I'm stuck and I've boiled down to what I imagine is a
misunderstanding that I have. I have the code and rules below.
With each fact that I insert, I expected
1) to see the number of facts grow (the list of facts printed line 16 does
grow with each call). This works
2) to see the NotificationEvent added only once to working memory (the
facts printed shows only one NotificationEvent and then a new MyBean for
each one I insert). So, I think this works also.
3) BUT, each time I call fireAllRules(), I expect the "foundNE" rule to be
triggered and to see "Found A notification event" printed. However, this is
only printed once - after my first insert. Also, I see that 0 rules get
fired (line 13) after the first MyBean insert.
SO, if I see a NotificationEvent in the list of facts in line 17, why isn't
my foundNE rule printing out the message each time I insert a new MyBean and
call fireallrules??
FYI, my future plan is to have a rule with low salience that retracts the
MyBeans just inserted and have my foundNE rule retract any
NotificationEvents that are at least 10 mins old. (so that the
NotificationEvents will grow but not MyBeans) .
Here is my test code (please excuse typos - there are none in my code):
Thanks very much for any insight.
-J
===test.java ===============
1 KnowledgeBase kbase = readKnowledgeBaseFromFile();
2 StatefulKnowledegeSession ksession = kbase.newStatefulKnowledgeSession():
3 KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession,"testlog");
4 for (int x=0;x<10;x++){
5 myBean mb = new MyBean();
6 mb.setName("me");
7 mb.setHeadline("my_head");
8 mb.setTag("tagline");
9
10 List<Command> cmds = new ArrayList<Command>();
11 FactHandle fh = (FactHandle) ksession.insert(seb);
12 int rf = ksession.fireAllRules();
13 System.out.println(rf+"rules fired");
14
15 Collection<FactHandle> c = ksession.getFactHandles();
16 for (FactHandle f:c) {
17 System.out.println(" now: "+f.toString());
18 }
19
20 Thread.sleep(5000);
21 }
=== test.drl ================
import com.me.MyBean
import java.util.Calendar
declare NotificationEvent
name: String
headline: String
tagline: String
dts: Long
end
rule "foundNE"
dialect "mvel"
when
$ne : NotificationEvent()
then
System.out.println("Found a Notification Event");
end
rule "NotTemplate_1"
dialect "mvel"
when
$myb : MyBean(name matches "me", headline matches "my_head")
not ($ne : NotificationEvent(name matches $myb.name,
headline=$myb.headline)
then
NotificationEvent fact0 = new NotificationEvent();
fact0.setName($myb.name);
fact0.setHeadline($myb.headline);
insert(fact0);
System.out.println("Adding a notification event");
end
--
View this message in context: http://drools.46999.n3.nabble.com/Why-isn-t-my-rule-firing-tp3670261p3670...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
unable to load jar file
by kavita
Hi,
I am trying to upload a POJO jar file into drools guvnor. But it is throwing
me an error saying "unable to load file".
This is the file that am trying to upload
http://drools.46999.n3.nabble.com/file/n3669841/QcResult.jar QcResult.jar
I am running drools guvnor 5.3 on tomcat server. When i looked into the logs
of tomcat, the following is the stacktrace..
SEVERE: Servlet.service() for servlet AssetFileServlet threw exception
java.lang.ClassNotFoundException: groovy.lang.GroovyObject
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
at
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at
org.drools.rule.MapBackedClassLoader.loadClass(MapBackedClassLoader.java:109)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at
org.drools.rule.MapBackedClassLoader.fastFindClass(MapBackedClassLoader.java:86)
at
org.drools.rule.MapBackedClassLoader.loadClass(MapBackedClassLoader.java:104)
at java.lang.ClassLoader.loadClass(Unknown Source)
at
org.drools.guvnor.server.contenthandler.ModelContentHandler.isClassVisible(ModelContentHandler.java:183)
at
org.drools.guvnor.server.contenthandler.ModelContentHandler.getImportsFromJar(ModelContentHandler.java:148)
at
org.drools.guvnor.server.contenthandler.ModelContentHandler.onAttachmentAdded(ModelContentHandler.java:66)
at
org.drools.guvnor.server.files.FileManagerUtils.attachFileToAsset(FileManagerUtils.java:115)
at
org.drools.guvnor.server.files.FileManagerUtils.attachFile(FileManagerUtils.java:87)
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.jboss.seam.util.Reflections.invoke(Reflections.java:22)
at
org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
at
org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.security.SecurityInterceptor.aroundInvoke(SecurityInterceptor.java:163)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
at
org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
at
org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
at
org.drools.guvnor.server.files.FileManagerUtils_$$_javassist_seam_10.attachFile(FileManagerUtils_$$_javassist_seam_10.java)
at
org.drools.guvnor.server.files.AssetFileServlet.processAttachFileToAsset(AssetFileServlet.java:97)
at
org.drools.guvnor.server.files.AssetFileServlet.doPost(AssetFileServlet.java:49)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.web.ContextFilter$1.process(ContextFilter.java:42)
at
org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:65)
at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:37)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Please help.
Thanks,
Kavitha.
--
View this message in context: http://drools.46999.n3.nabble.com/unable-to-load-jar-file-tp3669841p36698...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months