DRL Functions
by Swindells, Thomas
I've just been writing what should be a really simple function in my DRL.
What I wanted to do is to take an object in, construct another object from it and then insert both into working memory.
Eg.
function void insertBoth(Object1 object1) {
insert(new Object2(object1));
insert(object 1);
}
Rule XYZ
When
Then
insertBoth(new Object1());
End
This didn't work as expected however as it couldn't find the method insert.
I then thought, ah maybe I need to use the kcontext global to access them
function void insertBoth(Object1 object1) {
kcontext.insert(new Object2(object1));
kcontext.insert(object 1);
}
Rule XYZ
When
Then
insertBoth(new Object1());
End
This doesn't work either so what I've had to do is:
function void insertBoth(KnowledgeContext kcontext, Object1 object1) {
kcontext.getKnowledgeRuntime().insert(new Object2(object1));
kcontext.getKnowledgeRuntime().insert(object 1);
}
Rule XYZ
When
Then
insertBoth(kcontext, new Object1());
End
This is suddenly a lot more complicated than it needs to be. Why can't functions have the same access to the standard operations (insert, update, retract etc) and globals as rule actions currently do?
Should I raise an issue for this or am I missing something?
Thomas
________________________________
**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster(a)nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************
15 years, 2 months
Variable Notation in rule Condition
by sumatheja
Hi All,
I have this doubt regarding the notation used inside the rule's
condition. I have a fact HOST having the variables* HostName* and *
CPUSockets*. I have the following rule
rule "Test"
when
HOST(HostName!=null, CPUSockets>3)
then
# do something
Is throws an error saying cannot extract field *HostName*. It works fine
when i use *hostName*. Can anyone explain me the concept behind this.
Thanks in advance :)
--
cheers
Sumatheja Dasararaju
15 years, 2 months
Drools-Spring Config for Knowledge Agent
by KiranP
Hello Everybody,
I've used Drools5.1.0 and I have following Config In Spring :
<drools:resource id="profileChangeProcess" type="DRF"
source="classpath:/process/profilechangeprocess.rf"></drools:resource>
<drools:resource id="documentsRule" type="DRL"
source="classpath:/rules/documentsrule.drl" />
<drools:resource id="ChangeSet" type="CHANGE_SET"
source="classpath:/ChangeSet.xml"></drools:resource>
<drools:resource-change-scanner id="scanner" interval="10" />
<drools:kagent id="agent" kbase="knowledgeBase" new-instance="true">
<drools:resources>
<drools:resource ref="profileChangeProcess"></drools:resource>
<drools:resource ref="documentsRule"></drools:resource>
<drools:resource ref="ChangeSet"></drools:resource>
</drools:resources>
</drools:kagent>
<drools:kbase id="knowledgeBase"></drools:kbase>
now when i run the code i get following exception :
org.springframework.beans.factory.BeanCreationException: Error creating
bean with name 'kSession': Error setting property values; nested exception
is org.springframework.beans.NotWritablePropertyException: Invalid property
'knowledgeAgent' of bean class
[org.drools.container.spring.beans.StatefulKnowledgeSessionBeanFactory]:
Bean property 'knowledgeAgent' is not writable or has an invalid setter
method. Does the parameter type of the setter match the return type of the
getter?
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1341)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1067)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:511)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:820)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:762)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:680)
at
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:475)
... 30 more
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid
property 'knowledgeAgent' of bean class
[org.drools.container.spring.beans.StatefulKnowledgeSessionBeanFactory]:
Bean property 'knowledgeAgent' is not writable or has an invalid setter
method. Does the parameter type of the setter match the return type of the
getter?
at
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:1012)
at
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:857)
at
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:76)
at
org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:58)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1338)
... 41 more
any help or pointers to examples may help.............
-----
Keep Working >>
KiranP
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Spring-Config-...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 2 months
Resuming a simple process involving human task
by Touma
Hi all,
For the past few weeks I've been trying to get a simple drools flow example
involving human tasks up and running. I've done quite a bit to the point
that my session, process, task and workitems are being persisted in the
database. Here is what my flow looks like:
Start -> Ruleflow -> Decision node -> Human Task -> Printing Node -> End
The work item handler for the Human task simply performs the task of
persisting the Task instance. After reaching the Human Task, the flow stops
and the state is persisted. But how would I go about restarting/resuming the
flow so that the 'Printing node' is reached? I've tried using the
loadStatefulKnowledgeSession(sessionId) to load the session but querying the
list of all the processes for the given session returns an empty list. Ditto
with the list of all the process events. I have all the ID's with me
(workitem, process, task, session) but am pretty confused as to how these
can be put to use to resume my suspended workflow.
Any pointers would be much appreciated. TIA.
Peace,
/T\
--
View this message in context: http://n3.nabble.com/Resuming-a-simple-process-involving-human-task-tp716...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 2 months
Constants and BigDecimals
by Evert Penninckx
Hi
I've got the following rule:
when
$sale : Sale( amount > 300 )
then
modify($sale) { amount = 300; }
end
First problem: I don't like putting the constant value "300" two times in my
rule.
Second problem: amount is a BigDecimal. I read that mvel2 supports
BigDecimal literals like 300.00B, but drools won't compile this.
An ideal solution would look like something like this:
when
$maxAmount : 300.00B
$sale : Sale( amount > $maxAmount )
then
modify($sale) { amount = $maxAmount; }
end
1. Is it possible to attribute values to a variable?
2. If not, is it possible to use mvel's BigDecimal support? Because amount
> 300.00B says a lot more than eval(amount.compareTo(new
BigDecimal("300.00")) > 0).
Evert
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Constants-and-BigDeci...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 2 months
Re: [rules-users] Is it possible to use CEP features in Guvnor?
by John Peterson
I've done some additional experimentation and verified that you can't
run Test Scenarios (at least, can't run them successfully). I did
discover that I could create a "Technical Rule" that has the declare to
establish our object as an event. I'm sure this isn't intended, but it
works....
For technical rules, adding the "from entry-point "X" " is easy.
For DSL rules, I can hide it in the translation for the literal values
the user can specify
For the Guided Rule Editor, it appears that adding "Free Form DRL" to
the LHS of the rule under the Fact block to enter the "from entry-point
"X" " part as well and it parses and runs okay.
jp
> Date: Tue, 12 Oct 2010 20:50:28 +0100
> From: Michael Anstis <michael.anstis(a)gmail.com>
> Subject: Re: [rules-users] Is it possible to use CEP features in
> Guvnor?
> To: Rules Users List <rules-users(a)lists.jboss.org>
> Message-ID:
> <AANLkTingb2zOtR3WZsKkn6rEqfAGcLg60axGZuYLvnM1(a)mail.gmail.com>
> Content-Type: text/plain; charset="windows-1252"
>
> I assume you mean using ther guided editor rather than a vanilla "DRL
Rule"
> (free format text)?
>
> If the former then I don't believe it is possible (nor would testing
with Guvnor's QA facility).
>
> DRL rules could be defined but not tested.
>
> 2010/10/12 John Peterson <john.peterson.gv3k(a)statefarm.com>
>
> > I was wondering if it was possible to leverage the CEP features in
> > Guvnor. I am not sure how we?d set the ?@role(event)? in Guvnor or
> > putting the ?entry-point? in the rule unless you use DSL (embedding
it
> > in the translation) or doing technical rules.
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users(a)lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
15 years, 2 months
Interfaces without inputs and with multiple operations
by sam.squire@paretopartners.com
Hello there,
I am using BPMN and trying to call a ServiceTask without any input
messages. Unfortunately the BPMN specification seems to require exactly
one inMessageRef. Is there a way to get it to call a method without
arguments, like doStuff() ?
Is there any way to get around this without having to change the class and
add a nonce parameter? This works but it is not ideal.
Does drools support the <operations> tag in BPMN? It seems to complain If
I try to use it. I can only have a single operation in each interface.
Thanks,
Sam Squire
This message may contain confidential and privileged information and is intended solely for the use of the named addressee. Access, copying or re-use of the e-mail or any information contained therein by any other person is not authorised. If you are not the intended recipient please notify us immediately by returning the e-mail to the originator and then immediately delete this message. Although we attempt to sweep e-mail and attachments for viruses, we do not guarantee that either are virus-free and accept no liability for any damage sustained as a result of viruses.
Please refer to http://www.bnymellon.com/disclaimer/piml.html for certain disclosures.
15 years, 2 months
Parallel processing of large batches of facts
by Tim Jones
Hello,
I’m working on a project that needs a high performance rules system for
processing batches of objects. Typically I’ll have a dozen or so rules, the
most complex of which will aggregate several objects based on timestamps and
specified data patterns. The objects will come in batches of a few 100ks.
The system is reset back to the starting point after each batch is
processed.
My guess at doing this with Drools is that you load up all the rules and
enter all the objects as “facts”. You then hit fireallrules and sit back and
wait. Doing this, I only get so much performance and I can see that its only
using a single thread. Is there a way to process the whole lot in a
parallel, or multithreaded way? Unfortunately there's no natural way to
partition the objects that would make things easier.
Cheers,
Tim
15 years, 2 months