[rules-users] Unable to fire Rules
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.
[rules-users] Drools Pattern Matching
Hi, I am writing a rule which checks for the presence of substring in a string. Hard coding rule works fine but if I am using variables which may have dynamic values giving problems. How to write code equivalent of hardcoding version. HardCode verson : --- rule Process 834 no-loop when m: Message( fileName matches ^.*ABC-834.*$) then System.out.println( Reading Rule for 834 ... ); m.setFromQ(ABC.834.EDI); m.setToQ(ABC.834.XML); m.setProcess(834); update( m ); end Dynamic Version: //fileName has data 'ABC-834-test-100.edi' // p.FILEMASK has data 'ABC-834' rule Process ALL no-loop when p: TransactionVO() m: Message( fileName matches p.FILEMASK) // I can't say as (matches ^.*+p.FILEMASK+.*$) //the above st should be like if fileName has FILEMASK in it then System.out.println( Reading Rule for ... + p.NAME ); m.setFromQ(p.FROM_Q); m.setToQ(p.TO_Q); m.setProcess(p.TRANS_TYPE); update( m ); end -- View this message in context: http://www.nabble.com/Drools-Pattern-Matching-tp16442998p16442998.html Sent from the drools - user mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] Firing Rules from DB (Dynamic Rules)
Hi, As rules may keep on changing, I am using database to store the datails of a rule. Say in table Transaction (ruleName, fileMask, fromQ, ToQ,transType). An admin application may keep on adding/editing these rules as and when required. I have a mule application, where in a mule Component will poll a specific directory for a file. The file name will follow certain guidelines so that, I can check the fileName against the fileMask in the database(Transaction table. Assume there are rows as follows: 'Rule ABC', 'ABC-834','ABC-834-edi','ABC-834.xml','834' (indicates when fileName has mask 'ABC-834' then the fromQueue for it is 'ABC-834.edi' and toQueue is 'ABC-834.xml' 'Rule XYZ', 'XYZ-834','XYZ-834.edi','XYZ-834.xml','834' 'Rule JIM', 'JIM-850','JIM-850.edi','JIM-850.xml','850' so fileMask's r ('ABC-834','XYZ-834','JIM-850') The rules check will be in the .drl file, which will check the fileName against each row(a bean repr. of eachrow) of the database and when ever finds the match, obtains the fromQ and toQ of that matching row and updates the fact object Message. Further activities of the Mule Component makes use of updated values(by rules Engine) of Message object to decide on the target queues for the content of the file. I have issues in implementing this and unable to fire the rules successfully. Here I am facing issues of using the two objects in WorkingMemory (Message and RuleVO-representing a rows information of DB) If anyone has worked in similar areas please help me out in solving this problem. I am uploading the files Bean(Message,TransactionVO), Business object(commonBO) (using applyRule() method), drl(Test.drl, and hardcoded working version of Test_old.drl file ) In Mule UMO Component I will call commonBo's applyRule(); /// here is the code in Mule Component cbo = new CommonBO(); LoadContextPath.setEdiFileName((String)msg.getProperty(originalFilename)); cbo.applyRule(); Thanks in advance, Hanumesh M http://www.nabble.com/file/p16443580/DynRules.zip DynRules.zip -- View this message in context: http://www.nabble.com/Firing-Rules-from-DB-%28Dynamic-Rules%29-tp16443580p16443580.html Sent from the drools - user mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
[rules-users] dynamic rule creation - from database.
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.-tp1635p1635.html Sent from the drools - user mailing list archive at Nabble.com. ___ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users