Hi Markus,
Thanks a lot.. Now I am able to fire the rules dynamically by fetching
rules from Database.
I have modified the code as follows:
While filling the VO's iteself, I am concatinating the .* to the field
fileMask, and the drl code.
And the .drl is as follows:
rule "Process ALL"
no-loop
when
t:TransactionVO();
m:Message(fileName matches t.fileMask)
then
System.out.println( "Reading Rule for ..." + t.getFileMask() );
m.setFromQ(t.getFrom_Q());
m.setToQ(t.getTo_Q());
m.setTransType(t.getTrans_type());
update( m );
end
Thanks again,
Hanumesh M
On 4/4/08, Markus Helbig <info(a)markushelbig.de> wrote:
Hi,
your rules represent the following Java Code (the system.out are just
to see the result of matches)
public static void main(String[] args)
{
// You're rule
System.out.println("ABC-834".matches("ABC-834-test-100.edi"));
//false
System.out.println("XYZ-834".matches("ABC-834-test-100.edi")); //
false
System.out.println("834".matches("ABC-834-test-100.edi")); // false
so it could never work
but maybe this is what you want to have
// m.fileName matches .*+fileMask+.*
System.out.println("ABC-834-test-100.edi".matches(".*ABC-834.*"));
//true
System.out.println("ABC-834-test-100.edi".matches(".*XYZ-834.*"));
//false, if this should also be true because fo the 834 you have to
use regex grouping with an optional group before the -
System.out.println("ABC-834-test-100.edi".matches(".*834.*"));
//true
}
Cheers
Markus
On Fri, Apr 4, 2008 at 9:28 AM, hanumesh.m <hanumesh.m(a)gmail.com> wrote:
>
> Hi,
>
> I am inserting message(fileName, fromQ,toQ,transType) to
WorkingMemory.
> fileName as "ABC-834-test-100.edi"
>
> I am inserting 3 instances of TrasactionVO's to workingmemory as
follows:
> TransactionVO transVO = new TransactionVO("ABC-834",
"ABC.834.EDI",
> "ABC.834.XML", "834");
> TransactionVO transVO1 = new TransactionVO("XYZ-834",
"XYZ.834.EDI",
> "XYZ.834.XML", "834");
> TransactionVO transVO2 = new TransactionVO("834",
"INBOUND.834.EDI",
> "INBOUND.834.XML", "834");
>
> In drl, which ever object of TransactionVO matches the fileName of
Message,
> then update Message's rest of the details with TransactionVO. But the
rules
> are not getting fired.
>
> Follewed is the testCase and .drl file along with FactObjects.
>
> TestCase:
> -------------------------------------------------------------
> package com.sample;
>
> import java.io.InputStreamReader;
> import java.io.Reader;
>
> import org.drools.FactException;
> import org.drools.RuleBase;
> import org.drools.RuleBaseFactory;
> import org.drools.WorkingMemory;
> import org.drools.compiler.PackageBuilder;
> import org.drools.rule.Package;
> import com.sample.MessageEA;
> import com.sample.TransactionVO;
>
> /**
> * This is a sample file to launch a rule package from a rule source
file.
> */
> public class DroolsTest2 {
>
> public static final void main(String[] args) {
> try {
>
> //load up the rulebase
> RuleBase ruleBase = readRule();
> WorkingMemory workingMemory = ruleBase.newStatefulSession();
> MessageEA messageEA = new MessageEA();
> messageEA.setFileName("ABC-834-test-100.edi");
> workingMemory.insert( messageEA );
>
> TransactionVO transVO = new TransactionVO("ABC-834",
> "ABC.834.EDI", "ABC.834.XML", "834");
> TransactionVO transVO1 = new TransactionVO("XYZ-834",
> "XYZ.834.EDI", "XYZ.834.XML", "834");
> TransactionVO transVO2 = new TransactionVO("834",
> "INBOUND.834.EDI", "INBOUND.834.XML", "834");
> workingMemory.insert( transVO );
> workingMemory.insert( transVO1 );
> workingMemory.insert( transVO2);
> try{
> workingMemory.fireAllRules();
> }catch (FactException e ){
> System.out.println("err: "+e.getMessage());
> }catch(Exception ee){
> System.out.println("Err2 : "+ee.getMessage());
> }
>
> System.out.println("fName: "+messageEA.getFileName());
> System.out.println("frQ: "+messageEA.getFromQ());
> System.out.println("toQ: "+messageEA.getToQ());
>
>
> } catch (Throwable t) {
> t.printStackTrace();
> }
> }
>
> /**
> * Please note that this is the "low level" rule assembly API.
> */
> private static RuleBase readRule() throws Exception {
> //read in the source
> Reader source = new InputStreamReader(
> DroolsTest.class.getResourceAsStream( "/EATech.drl" ) );
>
> //optionally read in the DSL (if you are using it).
> //Reader dsl = new InputStreamReader(
> DroolsTest.class.getResourceAsStream( "/mylang.dsl" ) );
>
> //Use package builder to build up a rule package.
> //An alternative lower level class called "DrlParser"
can also be used...
>
> PackageBuilder builder = new PackageBuilder();
>
> //this wil parse and compile in one step
> //NOTE: There are 2 methods here, the one argument one
is for normal DRL.
> builder.addPackageFromDrl( source );
>
> //Use the following instead of above if you are using a
DSL:
> //builder.addPackageFromDrl( source, dsl );
>
> //get the compiled package (which is serializable)
> Package pkg = builder.getPackage();
>
> //add the package to a rulebase (deploy the rule
package).
> RuleBase ruleBase = RuleBaseFactory.newRuleBase();
> ruleBase.addPackage( pkg );
> return ruleBase;
> }
>
> }
> -------------------------------------------
> .drl file
>
> package com.sample;
>
> import com.sample.MessageEA;
> import com.sample.TransactionVO;
>
> rule "Process ALL"
> no-loop
> when
> m:MessageEA()
> p: TransactionVO(fileMask matches m.fileName)
> then
> System.out.println( "Reading Rule for ..." + p.getFileMask() );
> m.setFromQ(p.getFrom_Q());
> m.setToQ(p.getTo_Q());
> m.setTransType(p.getTransType());
> update( m );
> end
> ------------------------------------------------------------------
> MessageEA (private String transType, private String fileName,private
String
> fromQ, private String toQ)
> TransactionVO(private String fileMask, private String from_Q,private
String
> to_Q,private String transType);
> )
>
>
> This testCase has executed only Once accurately. But from later on it
> stopped working. Not able to file Rules..
>
> I am doing wrong anywhere?
>
> Please suggest.
> Hanumesh M
> --
> View this message in context:
http://www.nabble.com/Unable-to-fire-Rules-tp16486801p16486801.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