dynamic rule creation - from database.
by hanumesh.m
Hi
I need an example of using dynamic rules. Its very urgent.
My application will poll a directory for a file(trade partners will drop
the file on server), which contains some mask(fileMask) in name which can
decide on the target Queue where the data of file should be directed to.
If the trade partners are fixed then there is no problem, I can write .drl
file(fixed) with one rule for a trade partner and then I can fire the rules
to decide the target Queue.( .drl content followed )
But new partners may add up by admin module, (which has details like
fileMask, toQueue, fromQueue etc. all these details are in database). When a
new trade partner added then my program should fire a rule for new trade
partner i.e new rule should be created at runtime(from database) for
fileMask, toQueue, fromQueue.
Please suggest how should I write rule at runtime so that adding new
partner will not require changes in code and redeploy.
Here is .drl
----------------------------------------------------------------------
rule "Process 834"
no-loop
when
m: Message( fileName matches "^.*834.*$")
then
System.out.println( "Reading Rule for 834 ..." );
m.setFromQ("INBOUND.834.EDI");
m.setToQ("INBOUND.834.XML");
m.setProcess("834");
update( m );
end
rule "Process 850"
no-loop
when
m: Message( fileName matches "^.*850.*$")
then
System.out.println( "Reading Rule for 850 ..." );
m.setFromQ("INBOUND.850.EDI");
m.setToQ("INBOUND.850.XML");
m.setProcess("850");
update( m );
end
-----------------------------------------------------------------------
How to avoid writing these static rules and making them dynamic by fetching
from database.
I have already posted it but didn't got help so reposting the same again
hoping to have some luck this time
Thanks in advance,
Hanumesh
--
View this message in context: http://www.nabble.com/dynamic-rule-creation---from-database.-tp16300005p1...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 9 months
RE: [rules-users] compare string and int in LHS
by brenner
Hi,
the class "TripleObject" has a method "getValue". This method convert the
String value to an Ingeger.
rule "a Rule"
when
$vb_refmax : TripleObject( name == "vb_refmax" );
$vb_reflow : TripleObject( name == "vb_reflow");
eval( $vb_reflow.getValue(TripleObject.VALUE_TYP_INTEGER) >=
$vb_refmax.getValue(TripleObject.VALUE_TYP_INTEGER) );
then
end
I hope this helps.
blackone wrote:
>
>
> Hi! Could you provide the rule showing how you have used eval to solve the
> problem? I'm new to drools and have the same problem...
>
>
>
> brenner wrote:
>>
>> Thanks for your answer.
>>
>> Yes, with eval it works. I had oversight it.
>>
>> The question with the model I have aked myself. But I can't change it.
>> There are to much factors involved. Storable by Hibernate. Based on
>> configuration files with key-value, whereas the value could have various
>> data types (c-types) and all without a rule. Very bad, I know.
>>
>>
>>
>>
>>
>> Anstis, Michael (M.) wrote:
>>>
>>> You could use an inline eval too.
>>>
>>> The problem possibly lies more with your model; why not have one
>>> subclass
>>> expose the String property and another the Integer property and code the
>>> rules using the subclasses? Much safer throughout the entire application
>>> than having to worry whether some field is meant to be a string or
>>> number
>>> (It's very easy to question problems though - there could be very good
>>> reason why you need the model "as is").
>>>
>>> -----Original Message-----
>>> From: rules-users-bounces(a)lists.jboss.org
>>> [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of brenner
>>> Sent: 08 February 2008 12:33
>>> To: rules-users(a)lists.jboss.org
>>> Subject: Re: [rules-users] compare string and int in LHS
>>>
>>>
>>> Hi,
>>>
>>> I have found a solution, but I don't know that it is the best:
>>> My solution:
>>>
>>> I have extend my Class with a method which returns the string as a
>>> integer.
>>> And my rule is like this:
>>>
>>> i : Integer( intValue <= 1) from $test.getValue(Test.VALUE_TYP_INTEGER);
>>>
>>> Is that the only/best solution.
>>> Can't I convert Strings to Integer on the LHS of a rule?
>>>
>>> greeting
>>> Daniel
>>>
>>>
>>>
>>>
>>> brenner wrote:
>>>>
>>>> Hi,
>>>>
>>>> I have a class, wich contains a string value. This value is in some use
>>>> cases an integer.
>>>> For this use case I want to convert (parse) the string typ to an
>>>> integer
>>>> because I want that the following rule matches:
>>>>
>>>> rule
>>>> when
>>>> t : Test(value <= 1)
>>>> then
>>>> System.out.println(t)
>>>> end
>>>>
>>>>
>>>> class Test {
>>>>
>>>> String value;
>>>>
>>>> getValue();
>>>> setValue();
>>>>
>>>> }
>>>>
>>>> Have anyone a solution or some help for me?
>>>> Is that possible what I want to do?
>>>>
>>>> Thanks
>>>> Daniel
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/compare-string-and-int-in-LHS-tp15337728p15354435.html
>>> 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
>>>
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users(a)lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/compare-string-and-int-in-LHS-tp15337728p16301146.html
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 9 months
Drools 4.0.5 with Maven and JDK 1.4
by Eric Miles
I am attempting to build a project using Maven2 with Drools 4.0.5 and
JDK 1.4. The MVEL dependency was downloaded and I'm getting an error
with it's pom:
mvel-1.2.24-java1.4.pom
3/26/08 8:51:09 AM EDT: Parsing
error /home/emiles/.m2/repository/org/mvel/mvel/1.2.24-java1.4/mvel-1.2.24-java1.4.pom; org.codehaus.plexus.util.xml.pull.XmlPullParserException: end tag name </pakaging> must match start tag name <packaging> from line 6 (position: TEXT seen ...<packaging>jar</pakaging>... @6:30)
3/26/08 8:51:09 AM EDT: Unable to read smarttime/pom.xml;
org.eclipse.core.runtime.CoreException: Parsing
error /home/emiles/.m2/repository/org/mvel/mvel/1.2.24-java1.4/mvel-1.2.24-java1.4.pom; org.codehaus.plexus.util.xml.pull.XmlPullParserException: end tag name </pakaging> must match start tag name <packaging> from line 6 (position: TEXT seen ...<packaging>jar</pakaging>... @6:30)
I excluded version 1.2.24 and used 1.2.25 instead, which fixes my build
path errors. Is this version okay to use with Drools 4.0.5?
Thanks!
Eric
16 years, 9 months
Issue with nested objects (Repost from message with no subject so that there is a subject)...
by Jason Partyka
Hi all,
I'm having an issue with my rule and Drools 4.0.4. The object that my rule is supposed to reason over has nested objects and Drools does not appear to be reasoning over it when I modify attributes. I've pasted the rule at the end of the e-mail. I am attempting to change the value of the ez_width and ez_drop properties and have the corresponding rule below invoked.
I have tried to use the StatefulSession.modifyRetract(FactHandle) and StatefulSession.modifyInsert(FactHandle, Object) methods, which I expected to work. I then, for the sake of trying, tried the StatefulSession.update(FactHandle, Object) method.
After both, I've tried StatefulSession.fireAllRules() as well and nothing.
It's possible I'm missing something in the rules editor but I do not know.
Any insights?
Thanks,
Jason
----
package com.hightower.templates;
dialect "mvel"
import com.hightower.tables.BasicBlindFridayTest_JP;
import com.hightower.tables.BasicMountFridayTest;
import com.hightower.tables.CRGtest;
global org.apache.commons.logging.Log LOG;
global com.hightower.drools.beans.hibernate.SoSalesOrderHeader SalesOrderHeader;
global com.hightower.drools.beans.hibernate.ArCustomer Customer;
global com.hightower.drools.beans.hibernate.ArCustomerContact Contact;
global com.hightower.drools.beans.hibernate.SyZipCode ZipCode;
global com.hightower.drools.beans.hibernate.SoShipToAddress ShipToAddress;
global com.hightower.drools.beans.hibernate.SoSalesOrderDetail SalesOrderDetail;
global com.hightower.drools.beans.hibernate.SoSalesHistory SalesHistory;
global com.hightower.drools.beans.hibernate.HtSalesOrderNo SalesOrderNo;
global com.hightower.drools.beans.hibernate.HtCustomerInstallation CustomerInstallation;
global com.hightower.drools.beans.hibernate.HtCustomerInfo CustomerInfo;
global com.hightower.drools.beans.hibernate.HtCustomerApplyDiscounts CustomerDiscounts;
global com.hightower.drools.beans.hibernate.HtOrderBasicsInfo OrderBasics;
global com.hightower.drools.beans.hibernate.Windows Window;
global com.hightower.drools.beans.hibernate.Rooms Room;
rule "awe"
dialect "mvel"
ruleflow-group 'Validation'
when
$daObj : AReallyWonderfulAndCrappyTest( basicMountFridayTest.mountType == "T" )
then
$daObj.getBasicBlindFridayTest_JP().setRightwidht(44);
end
rule "priceTableValues_ValRule0"
dialect "mvel"
ruleflow-group 'Validation'
when
$daObj : AReallyWonderfulAndCrappyTest( priceTable.Ez_drop <= 50.00, priceTable.Ez_width <= 50.00 )
then
$daObj.getPriceTable().setEz_price("2500.00");
end
rule "priceTableValues_ValRule1"
dialect "mvel"
ruleflow-group 'Validation'
when
$daObj : AReallyWonderfulAndCrappyTest( priceTable.Ez_drop <= 100.00, priceTable.Ez_width <= 100.00 )
then
$daObj.getPriceTable().setEz_price("10000.00");
end
rule "priceTableValues_ValRule2"
dialect "mvel"
ruleflow-group 'Validation'
when
$daObj : AReallyWonderfulAndCrappyTest( priceTable.Ez_drop <= 25.00, priceTable.Ez_width <= 25.00 )
then
$daObj.getPriceTable().setEz_price("625.00");
end
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
16 years, 9 months
Assert an xml
by anishanc
Hello friends...
Now i am using normal java objects (eg: dto) as assertobjects , and make
decisions in LSH side, its ok.
But am using an xml , from this xml i used to set values to the above
mentioned dto. That means
1, Reading from xml
2, Setting to dto
These two steps are done in the service class, and then just giving dto's
object as an assert object to drools for other checking.
My doubt is that can i use this xml object as an assert object to drools,
so i need not to create a dto to check values in xml
am expecting some related ideas ........
thanks in advance.
--
View this message in context: http://www.nabble.com/Assert-an-xml-tp16271120p16271120.html
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 9 months
Using trim in LHS cause "Exception executing predicate..."
by ferry97
Hi,
I have a rule
rule "rule 1"
when
Cheese(color.trim == "yellow")
then
System.out.println("hmm.. its yellow");
will raise :
org.drools.spi.ConsequenceException: org.drools.RuntimeDroolsException:
Exception executing predicate
org.drools.base.mvel.MVELPredicateExpression@19adc2c
I suspect it's because of the "trim" function. Does it allowed ? Is there
any alternative ?
I need this function because "Cheese" is loaded from database, and all the
fields comes with space trailing.
Thanks
--
View this message in context: http://www.nabble.com/Using-trim-in-LHS-cause-%22Exception-executing-pred...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 9 months
(no subject)
by Jason Partyka
Hi all,
I'm having an issue with my rule and Drools 4.0.4. The object that my rule is supposed to reason over has nested objects and Drools does not appear to be reasoning over it when I modify attributes. I've pasted the rule at the end of the e-mail. I am attempting to change the value of the ez_width and ez_drop properties and have the corresponding rule below invoked.
I have tried to use the StatefulSession.modifyRetract(FactHandle) and StatefulSession.modifyInsert(FactHandle, Object) methods, which I expected to work. I then, for the sake of trying, tried the StatefulSession.update(FactHandle, Object) method.
After both, I've tried StatefulSession.fireAllRules() as well and nothing.
It's possible I'm missing something in the rules editor but I do not know.
Any insights?
Thanks,
Jason
----
package com.hightower.templates;
dialect "mvel"
import com.hightower.tables.BasicBlindFridayTest_JP;
import com.hightower.tables.BasicMountFridayTest;
import com.hightower.tables.CRGtest;
global org.apache.commons.logging.Log LOG;
global com.hightower.drools.beans.hibernate.SoSalesOrderHeader SalesOrderHeader;
global com.hightower.drools.beans.hibernate.ArCustomer Customer;
global com.hightower.drools.beans.hibernate.ArCustomerContact Contact;
global com.hightower.drools.beans.hibernate.SyZipCode ZipCode;
global com.hightower.drools.beans.hibernate.SoShipToAddress ShipToAddress;
global com.hightower.drools.beans.hibernate.SoSalesOrderDetail SalesOrderDetail;
global com.hightower.drools.beans.hibernate.SoSalesHistory SalesHistory;
global com.hightower.drools.beans.hibernate.HtSalesOrderNo SalesOrderNo;
global com.hightower.drools.beans.hibernate.HtCustomerInstallation CustomerInstallation;
global com.hightower.drools.beans.hibernate.HtCustomerInfo CustomerInfo;
global com.hightower.drools.beans.hibernate.HtCustomerApplyDiscounts CustomerDiscounts;
global com.hightower.drools.beans.hibernate.HtOrderBasicsInfo OrderBasics;
global com.hightower.drools.beans.hibernate.Windows Window;
global com.hightower.drools.beans.hibernate.Rooms Room;
rule "awe"
dialect "mvel"
ruleflow-group 'Validation'
when
$daObj : AReallyWonderfulAndCrappyTest( basicMountFridayTest.mountType == "T" )
then
$daObj.getBasicBlindFridayTest_JP().setRightwidht(44);
end
rule "priceTableValues_ValRule0"
dialect "mvel"
ruleflow-group 'Validation'
when
$daObj : AReallyWonderfulAndCrappyTest( priceTable.Ez_drop <= 50.00, priceTable.Ez_width <= 50.00 )
then
$daObj.getPriceTable().setEz_price("2500.00");
end
rule "priceTableValues_ValRule1"
dialect "mvel"
ruleflow-group 'Validation'
when
$daObj : AReallyWonderfulAndCrappyTest( priceTable.Ez_drop <= 100.00, priceTable.Ez_width <= 100.00 )
then
$daObj.getPriceTable().setEz_price("10000.00");
end
rule "priceTableValues_ValRule2"
dialect "mvel"
ruleflow-group 'Validation'
when
$daObj : AReallyWonderfulAndCrappyTest( priceTable.Ez_drop <= 25.00, priceTable.Ez_width <= 25.00 )
then
$daObj.getPriceTable().setEz_price("625.00");
end
16 years, 9 months