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