Fetching Facts from WM...
by jdepaul
Suppose my client code initially asserts two Facts into WorkingMemory
instance: one Source object and one TargetOne object. As the rules get
applied, some of the rules may assert additional Target facts into WM. How
can I retrieve all of the Target facts (however many were created) from the
WorkingMemory after fireAllRules() method was called (regardless of how many
Target objects were created as a result)?!
I will not know the concrete type of the target object types that were
asserted into WM instance, as they can be as many as 7 class sub-types
(TargetOne, TargetTwo, TargetThree), though they will all share a common
super-class (com.mypackage.Target). Can someone show an example on how to
fetch the resulting Target objects after fireAllRules() is called and filter
out the Target objects?
Thanks in advance -
James
--
View this message in context: http://www.nabble.com/Fetching-Facts-from-WM...-tf3550451.html#a9912199
Sent from the drools - user mailing list archive at Nabble.com.
17 years, 7 months
Dynamic property names...
by jdepaul
Hi all -
I have the following challenge with data mapping. I'm trying to decide if
DROOLS is the appropriate solution to this problem - please help me decide.
I have a Source object and Target object. Both objects have the same field
names - the goal is to map data across from Source object to Target object
by apply a set of rules to object's fields. More than one rule may need to
be activated for each field. Results of previous mapping operation may
affect later mapping operations further 'downstream' - so it's important to
process fields in a specific sequence and for each field evaluate rules in a
specific order - (not sure, can rule Salience accomplish both?)
About the rules: There may be several rules in affect for each field -
which must be executed in specific order top to bottom. Rules should be
applied until the target field is mapped - until the target field is
non-blank. Same rule may be applied to more than one field from the Source
object. Rules will be maintain by a Customer Service Reps and will change
periodically.
I would envision the rule setup to be something like this:
Rule "Setup variables"
when
$source : SOURCE (rec_type == "PARTNER", $s_loc : location,
$s_op : operator, $s_wo : workorder)
$target : TARGET ($t_loc : location, $t_op : operator, $t_wo :
workorder)
then
<do nothing>
end
# Simple mapping for Location field...
rule "Location"
when
$target($t_loc == "") // if blank
then
$target.setLocation($s_loc);
modify($target);
end
# Simple mapping for Operator field...
rule "Operator"
when
$target($t_op == "") // if blank...
then
$target.setLocation($s_op);
modify($target);
end
... rules continue for the rest of the fields... There are about 150-200
fields to map. Some rules will define simple straight across mappings,
other rules will need to fetch values from objects from DB (using 'from'
keyword). Here are some questions:
1) Opinion please: Would the outlined approach work in this case given the
number of fields to process and the required sequence for processing. Seems
that rule management may be a bit difficult...
2) Is there a way to define functions that could take field names, and then
apply common operations using dynamic field names - i.e. function
simple_map(fieldName) would source data from Source.fieldName and map it to
Tartget.fieldName - this would require that get/set methods be dynamic - is
that possible?
3) Is there another approach that would be better suited in this case that
you'd recommend?
Thanks,
James
--
View this message in context: http://www.nabble.com/Dynamic-property-names...-tf3532720.html#a9859805
Sent from the drools - user mailing list archive at Nabble.com.
17 years, 7 months
enum Support
by John Howard
Hi,
I have the following rule:
dh : DealtHand(seat == Seat.NORTH)
Seat is a Java 5 enum. When I trace through the code it appears that
Seat.NORTH gets changed to 'NORTH' for the comparison which fails the test.
I have Java Language Level set to 1.5.
Is this type of construct supported in DROOLS.
Thanks,
John
17 years, 7 months
RE: [rules-users] LHS Dao Calls
by Sanjay Singh - s0singh
Anyone Please ? Database calls from LHS ..
when
item : ItemVo(itemStatusCode != ItemVo.STATUS_ACTIVE ,
(itemValidationDao.isValidItemStatus(itemStatusCode)))
anyone has the right syntax .. thanks
________________________________
From: Sanjay Singh - s0singh
Sent: Monday, April 09, 2007 8:33 AM
To: 'Rules Users List'
Subject: RE: [rules-users] LHS Dao Calls
Has anyone in the users list tested any DAO calls from condition side
.... without using from keyword .. something like this .. i know i am
supposed to test this in trunk but is there anyone who has actually done
it either in trunk or M1
________________________________
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Edson Tirelli
Sent: Friday, April 06, 2007 1:50 PM
To: Rules Users List
Subject: Re: [rules-users] LHS Dao Calls
Sanjay,
Are you trying with trunk? there was an issue using globals inside
predicates that was fixed after M1...
Let me know...
[]s
Edson
2007/4/6, Sanjay Singh - s0singh < Sanjay.Singh(a)wal-mart.com>:
Thanks Edson .. i tried with these syntaxes but does not work ..
any other clues ? just to let you know that itemValidationDao is
declared global and itemvo is asserted
when
item : ItemVo(itemStatusCode != ItemVo.STATUS_ACTIVE ,
(itemValidationDao.isValidItemStatus(itemStatusCode)))
Caused by: org.drools.rule.InvalidRulePackage: unknown:15:70
Unexpected token '('
unknown:16:1 mismatched token: [@160,673:676='then',<33>,16:1];
expecting type ')'
unknown:17:29 Unexpected token '"itemStatusCode"'
unknown:18:22 Unexpected token '"Item is cross ref prime"'
when
item : ItemVo(statusCode : itemStatusCode !=
ItemVo.STATUS_ACTIVE , itemValidationDao.isValidItemStatus(statusCode))
Caused by: org.drools.rule.InvalidRulePackage: unknown:15:70
Unexpected token 'itemValidationDao'
unknown:16:1 mismatched token: [@158,671:674='then',<33>,16:1];
expecting type ')'
unknown:17:29 Unexpected token '"itemStatusCode"'
unknown:18:22 Unexpected token '"Item is cross ref prime"'
This also does not seem to work -- i have 3.1.0 M1 version ..
item : ItemVo ( itemStatusCode == ItemVo.STATUS_ACTIVE | ==
ItemVo.STATUS_DELETE )
while this still works :
item : ItemVo(itemStatusCode == ItemVo.STATUS_INACTIVE) or
ItemVo(itemStatusCode == ItemVo.STATUS_DELETE)
________________________________
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Edson Tirelli
Sent: Friday, April 06, 2007 10:22 AM
To: Rules Users List
Subject: Re: [rules-users] LHS Dao Calls
Sunjay,
Methods called by using the "from" CE are expected to return
a collection of VO's, not boolean results. For your case, probably what
you want is something like:
ItemVo( statusCode : itemStatusCode != null,
(itemValidationDao.isValidItemStatus (statusCode)) )
A predicate allow you to call a method returning a boolean
value and use it as a constraint.
[]s
Edson
2007/4/5, Sanjay Singh - s0singh <Sanjay.Singh(a)wal-mart.com>:
Here is a quick test i was trying to do for calling the
dao in LHS but it fails ... what am i missing ..
global com.itemfile.item.dao.ItemValidationDao
itemValidationDao;
global com.itemfile.rules.ValidationErrorMap errors;
rule "Item should have a valid status"
when
ItemVo( statusCode : itemStatusCode != null)
ItemVo( statusCode == true ) from
itemValidationDao.isValidItemStatus(statusCode)
then
errors.addValidationError("nullItemStatusCode","Item
Status Code is null");
System.out.println("Item Base Defaults Called" +
itemValidationDao.isValidItemStatus(statusCode));
System.out.println("Item Status Code is null");
end
Caused by: org.drools.rule.InvalidRulePackage:
unknown:32:28 Unexpected token 'itemValidationDao'
isValidItemStatus () method returns a boolean and i
need to check if thats true than go to the RHS side .... somehow it
does not recognize itemValidationDao in LHS side .. RHS same call works
....
Can anybody suggest how to call database in LHS ...
thanks
________________________________
*******************************************************************
*** This email and any files transmitted with it are
confidential
and intended solely for the individual or entity to whom
they are
addressed. If you have received this email in error
destroy it
immediately.
******************************************************
**************** Wal-Mart Confidential
****************************
******************************************
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3124-6000
Mobile: +55 11 9218-4151
JBoss, a division of Red Hat @ www.jboss.com
________________________________
*******************************************************************
*** This email and any files transmitted with it are
confidential
and intended solely for the individual or entity to whom they
are
addressed. If you have received this email in error destroy it
immediately.
******************************************************
**************** Wal-Mart Confidential
****************************
******************************************
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3124-6000
Mobile: +55 11 9218-4151
JBoss, a division of Red Hat @ www.jboss.com
-----------------------------------------
*******************************************************************
*** This email and any files transmitted with it are confidential
and intended solely for the individual or entity to whom they are
addressed. If you have received this email in error destroy it
immediately. ******************************************************
**************** Wal-Mart Confidential ****************************
******************************************
17 years, 7 months
help me please
by fakhfakh ismail
Hello,
when I execute this code
rule "sample6"
when
act :activity(activityName != "activite1",type:type, activite : activite)
pp: activite.getactivity()
then
act.getActivityName();
System.out.println("deux clés ont la meme valeurs " +act.getActivityName());
end
an error is affiched
Exception in thread "main" org.drools.rule.InvalidRulePackage: Unable to resolve ObjectType 'activite.getActivity'
at org.drools.rule.Package.checkValidity(Unknown Source)
at org.drools.common.AbstractRuleBase.addPackage(Unknown Source)
at org.drools.jsr94.rules.admin.RuleExecutionSetImpl.<init>(Unknown Source)
at org.drools.jsr94.rules.admin.LocalRuleExecutionSetProviderImpl.createRuleExecutionSet(Unknown Source)
at org.drools.jsr94.rules.admin.LocalRuleExecutionSetProviderImpl.createRuleExecutionSet(Unknown Source)
at org.drools.jsr94.rules.admin.LocalRuleExecutionSetProviderImpl.createRuleExecutionSet(Unknown Source)
at com.sample.Rule.fireRules(Rule.java:41)
at com.sample.Rule.fireRules(Rule.java:70)
at com.sample.DroolsTest.main(DroolsTest.java:60)
Thank you for your help
Best regard
Ismail
---------------------------------
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses.
17 years, 7 months
code error
by fakhfakh ismail
hello,
when I execute this code
rule "sample6"
when
act :activity( Type == 5)
//nod: act.getNodeProperty()
//nod.Property(key1: Key, value1:value)
//nod.Property(key2: Key, value==value1)
then
System.out.println("deux clés ont la meme valeurs");
end
error is affiiched
Exception in thread "main" org.drools.rule.InvalidRulePackage: Unable to create Field Extractor for 'Type'
at org.drools.rule.Package.checkValidity(Unknown Source)
at org.drools.common.AbstractRuleBase.addPackage(Unknown Source)
at org.drools.jsr94.rules.admin.RuleExecutionSetImpl.<init>(Unknown Source)
at org.drools.jsr94.rules.admin.LocalRuleExecutionSetProviderImpl.createRuleExecutionSet(Unknown Source)
at org.drools.jsr94.rules.admin.LocalRuleExecutionSetProviderImpl.createRuleExecutionSet(Unknown Source)
at org.drools.jsr94.rules.admin.LocalRuleExecutionSetProviderImpl.createRuleExecutionSet(Unknown Source)
at com.sample.Rule.fireRules(Rule.java:41)
at com.sample.Rule.fireRules(Rule.java:70)
at com.sample.DroolsTest.main(DroolsTest.java:59)
however the attribut Type exist in class activity
Best regard
Thank you for your help
---------------------------------
Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses.
17 years, 7 months
LHS Dao Calls
by Sanjay Singh - s0singh
Here is a quick test i was trying to do for calling the dao in LHS but
it fails .. what am i missing ..
global com.itemfile.item.dao.ItemValidationDao itemValidationDao;
global com.itemfile.rules.ValidationErrorMap errors;
rule "Item should have a valid status"
when
ItemVo( statusCode : itemStatusCode != null)
ItemVo( statusCode == true ) from
itemValidationDao.isValidItemStatus(statusCode)
then
errors.addValidationError("nullItemStatusCode","Item Status Code is
null");
System.out.println("Item Base Defaults Called" +
itemValidationDao.isValidItemStatus(statusCode));
System.out.println("Item Status Code is null");
end
Caused by: org.drools.rule.InvalidRulePackage: unknown:32:28 Unexpected
token 'itemValidationDao'
isValidItemStatus () method returns a boolean and i need to check if
thats true than go to the RHS side .... somehow it does not recognize
itemValidationDao in LHS side .. RHS same call works ..
Can anybody suggest how to call database in LHS ..
thanks
-----------------------------------------
*******************************************************************
*** This email and any files transmitted with it are confidential
and intended solely for the individual or entity to whom they are
addressed. If you have received this email in error destroy it
immediately. ******************************************************
**************** Wal-Mart Confidential ****************************
******************************************
17 years, 7 months
MVEL error (was: 3.1 M Help Needed)
by Edson Tirelli
Mark,
What is the status on MVEL stuff used in core?
[]s
Edson
2007/4/6, vista2007 <my_vista2007(a)yahoo.com>:
>
>
> I implement the following logic using 3.1M edition,
>
> package com.software.warehouse.rules.impl;
>
> #list any import classes here.
> import com.software.warehouse.model.Item;
> import com.software.warehouse.model.ItemCollect;
>
>
> #declare any global variables here
>
> global com.software.warehouse.model.ItemCollect itemCollect;
>
> rule "Rule 1"
>
> salience 20
> when
> # itemCollect.getItemList() method returns a List of
> objects
>
> m : Item(status == Item.ACTIVE) from
> itemCollect.getItemList()
>
> then
> m.setStatus(Item.INACTIVE);
> System.out.println(m.getStatus());
> end
>
>
> It gave me the followin error.
>
> ObjectAsserted:
> handle=[fid:1:1:com.software.warehouse.model.ItemCollect@12a3722];
> object=com.software.warehouse.model.ItemCollect@12a3722]
> org.mvel.PropertyAccessException: null pointer exception in property:
> itemCollect.getItemList().list()
> at
> org.mvel.optimizers.impl.refl.ReflectiveOptimizer.compileGetChain(
> ReflectiveOptimizer.java:137)
> at
> org.mvel.optimizers.impl.refl.ReflectiveOptimizer.optimize(
> ReflectiveOptimizer.java:92)
> at org.mvel.Token.getReducedValueAccelerated(Token.java:302)
> at org.mvel.ExecutableAccessor.getValue(ExecutableAccessor.java
> :46)
> at org.mvel.MVEL.executeExpression(MVEL.java:173)
> at
> org.drools.base.dataproviders.MVELDataProvider.getResults(
> MVELDataProvider.java:43)
> at org.drools.reteoo.FromNode.assertTuple(FromNode.java:61)
> at
> org.drools.reteoo.SingleTupleSinkAdapter.createAndPropagateAssertTuple(
> SingleTupleSinkAdapter.java:55)
> at
> org.drools.reteoo.LeftInputAdapterNode.assertObject(
> LeftInputAdapterNode.java:147)
> at
> org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(
> SingleObjectSinkAdapter.java:20)
> at
> org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:163)
> at org.drools.reteoo.Rete.assertObject(Rete.java:121)
> at
> org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:196)
> at
>
> org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.propagate
> (ReteooWorkingMemory.java:157)
> at
> org.drools.common.AbstractWorkingMemory.propagateQueuedActions(
> AbstractWorkingMemory.java:998)
> at
> org.drools.common.AbstractWorkingMemory.assertObject(
> AbstractWorkingMemory.java:733)
>
>
> Can anyone please help me to slove this problum. Thank You.
> --
> View this message in context:
> http://www.nabble.com/3.1-M-Help-Needed-tf3535402.html#a9868300
> Sent from the drools - user mailing list archive at Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3124-6000
Mobile: +55 11 9218-4151
JBoss, a division of Red Hat @ www.jboss.com
17 years, 7 months
Function compilation error
by Krunoslav Sabljak
Hi all!!
Im having some problems with calling functions one from another in .drl
Here is some code snippet:
#created on: 2007.04.03
*
package* hr.combis.unimsg.ruleengine.rules.message
#list any import classes here.
*
import* javax.mail.internet.MimeMessage;
*
import* javax.mail.internet.InternetAddress;
*
import* javax.mail.Message;
*
import* javax.mail.Header;
*
import* javax.mail.Multipart;
*
import* javax.mail.Part;
*
import* java.util.Enumeration;
*
import* java.lang.String;
*
import* java.lang.Object;
*
import* java.lang.Integer;
#declare any global variables here
#global IMessageService messageService;
*
rule* "Initial rule"
*when
*
#conditions
msg : MimeMessage( )
*then*
#actions
drools.setFocus("Content group");
*
end
*
*
rule* "Header parsing rule"
*agenda-group* "Header group"
*when
*
#conditions
msg : MimeMessage( )
*then*
#actions
*if* (msg.getContent() != *null* && msg.getAllHeaders() != *null*){
System.out.println("TODO: header processing");
}
*
end
*
*
rule* "Content parsing rule"
*agenda-group* "Content group"
*when
*
#conditions
msg : MimeMessage( )
*then*
#actions
*if* (msg.getContent() != *null*){
*if* (msg.getContent() *instanceof* Multipart){
System.out.println("mail je multipart");
Object body = msg.getContent();
processMultipart((Multipart) body);
}*else*{
System.out.println("mail je singlepart");
singlePart(msg);
}
}
drools.setFocus("Header group");
*
end
*
*
function* *void* singlePart(Part p) {
String fileName = p.getFileName( );
String disposition = p.getDisposition( );
String contentType = p.getContentType( );
*if* (contentType.toLowerCase( ).startsWith("multipart/")) {
System.out.println("Part ima svoje partove");
ProcessMultipart.processMultipart((Multipart) p.getContent( ) );
}
p.writeTo(System.out);
}
*
function* *void* processMultipart(Multipart mp){
System.out.println("procesiram multipart");
*for* (*int* i = 0; i < mp.getCount(); i++){
Part part = mp.getBodyPart(i);
System.out.println("Procesiram part: " + i);
SinglePart.singlePart(part);
}
}
When i assert in working memory multipart message , the first is being
called processMultipart() method, which then calls singlePart() method for
each part and that works just fine. But, when singlePart needs to call
processMultipart() again (thats just the way javamail api works), everything
crashes with no specific explanation. Here is the part of log:
ERROR 07 04 2007 12:36:05,031 - Bad error
com.ibm.ejs.container.UnknownLocalException:
at org.codehaus.janino.Parser.parseAdditiveExpression(Parser.java)
at org.codehaus.janino.Parser.parseShiftExpression(Parser.java)
at org.codehaus.janino.Parser.parseRelationalExpression(Parser.java)
at org.codehaus.janino.Parser.parseEqualityExpression(Parser.java)
at org.codehaus.janino.Parser.parseAndExpression(Parser.java)
at org.codehaus.janino.Parser.parseExclusiveOrExpression(Parser.java)
at org.codehaus.janino.Parser.parseInclusiveOrExpression(Parser.java)
at org.codehaus.janino.Parser.parseConditionalAndExpression(Parser.java)
at org.codehaus.janino.Parser.parseConditionalOrExpression(Parser.java)
at org.codehaus.janino.Parser.parseConditionalExpression(Parser.java)
at org.codehaus.janino.Parser.parseAssignmentExpression(Parser.java)
at org.codehaus.janino.Parser.parseExpression(Parser.java)
at org.codehaus.janino.Parser.parsePrimary(Parser.java)
at org.codehaus.janino.Parser.parseUnaryExpression(Parser.java)
at org.codehaus.janino.Parser.parseMultiplicativeExpression(Parser.java)
at org.codehaus.janino.Parser.parseAdditiveExpression(Parser.java)
at org.codehaus.janino.Parser.parseShiftExpression(Parser.java)
at org.codehaus.janino.Parser.parseRelationalExpression(Parser.java)
at org.codehaus.janino.Parser.parseEqualityExpression(Parser.java)
at org.codehaus.janino.Parser.parseAndExpression(Parser.java)
at org.codehaus.janino.Parser.parseExclusiveOrExpression(Parser.java)
at org.codehaus.janino.Parser.parseInclusiveOrExpression(Parser.java)
at org.codehaus.janino.Parser.parseConditionalAndExpression(Parser.java)
at org.codehaus.janino.Parser.parseConditionalOrExpression(Parser.java)
at org.codehaus.janino.Parser.parseConditionalExpression(Parser.java)
at org.codehaus.janino.Parser.parseAssignmentExpression(Parser.java)
at org.codehaus.janino.Parser.parseExpression(Parser.java)
at org.codehaus.janino.Parser.parseArgumentList(Parser.java)
at org.codehaus.janino.Parser.parseArguments(Parser.java)
at org.codehaus.janino.Parser.parsePrimary(Parser.java)
at org.codehaus.janino.Parser.parseUnaryExpression(Parser.java)
.......
Please, help. Thnx
17 years, 7 months