<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {mso-style-priority:99;
        mso-style-link:"Plain Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
span.PlainTextChar
        {mso-style-name:"Plain Text Char";
        mso-style-priority:99;
        mso-style-link:"Plain Text";
        font-family:"Calibri","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoPlainText>Hi Wolfgang,<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>Thanks for your response.<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>Here is the rule that I had written for the file. <o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoNormal style='text-autospace:none'><b><span style='font-size:10.0pt;font-family:"Courier New";color:#960000'>rule</span></b><span style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span style='font-size:10.0pt;font-family:"Courier New";color:green'>"Id != value"</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span style='font-size:10.0pt;font-family:"Courier New";color:#960000'>when</span></b><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Courier New";color:black'> plc : DailyPLC(Id!=</span><span style='font-size:10.0pt;font-family:"Courier New";color:green'>"1794"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>);</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><b><span style='font-size:10.0pt;font-family:"Courier New";color:#960000'>then</span></b><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Courier New";color:black'> System.out.println(</span><span style='font-size:10.0pt;font-family:"Courier New";color:green'>"Incorrect ID "</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'> + plc.getId()+ </span><span style='font-size:10.0pt;font-family:"Courier New";color:green'>" at row : "</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'> + plc.getRowNumber());</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal style='text-autospace:none'><b><span style='font-size:10.0pt;font-family:"Courier New";color:#960000'>end</span></b><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>Any pointers shall be really very helpful. <o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>Regards,<o:p></o:p></p><p class=MsoPlainText>Amal<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>-----Original Message-----<br>From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Wolfgang Laun<br>Sent: Tuesday, June 12, 2012 3:57 PM<br>To: Rules Users List<br>Subject: Re: [rules-users] Firing the rules in a sequence for all the items in an ArrayList.</p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>Your question can't be answered without the rules. - If your Java code does what you say it does, then it should be OK.<o:p></o:p></p><p class=MsoPlainText>-W<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>On 12/06/2012, Amal Gupta <<a href="mailto:Amal_Gupta@infosys.com"><span style='color:windowtext;text-decoration:none'>Amal_Gupta@infosys.com</span></a>> wrote:<o:p></o:p></p><p class=MsoPlainText>> Hello,<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> I am new to Java and Drools and have a doubt regarding the sequence of <o:p></o:p></p><p class=MsoPlainText>> rules' execution as stated below :-<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> Scenario:- I have a scenario wherein I have to apply multiple rules on <o:p></o:p></p><p class=MsoPlainText>> multiple columns coming in a file. To simulate that I created a 2-D <o:p></o:p></p><p class=MsoPlainText>> array as follows<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> String[][] data = {<o:p></o:p></p><p class=MsoPlainText>> {"1791","8459625","78458745","20120610","20120610"<o:p></o:p></p><p class=MsoPlainText>> },<o:p></o:p></p><p class=MsoPlainText>> {"1792","8459623","78458745","20120610","20120610"<o:p></o:p></p><p class=MsoPlainText>> },<o:p></o:p></p><p class=MsoPlainText>> {"1793","8459624","78458745","20120610","20120610"<o:p></o:p></p><p class=MsoPlainText>> },<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> {"17944","8459626","78458745","20120610","20120610"}<o:p></o:p></p><p class=MsoPlainText>> };<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> Here each column of corresponds to a member for the following class<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> public class DailyPLC {<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> private String Id; // This value will correspond to data[i][0]<o:p></o:p></p><p class=MsoPlainText>> private String productCode; // This value will correspond to <o:p></o:p></p><p class=MsoPlainText>> data[i][1]<o:p></o:p></p><p class=MsoPlainText>> private String customerCode; // This value will correspond to <o:p></o:p></p><p class=MsoPlainText>> data[i][2]<o:p></o:p></p><p class=MsoPlainText>> private String date1; // This value will correspond to data[i][3]<o:p></o:p></p><p class=MsoPlainText>> private String date2; // This value will correspond to <o:p></o:p></p><p class=MsoPlainText>> data[i][4]<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> private int rowNumber; // The row number to keep a track of row <o:p></o:p></p><p class=MsoPlainText>> for which the record exists<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> /*Getters and Setters defined for each of them*/ }<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> I have to perform checks on each of the columns, and the intent is to <o:p></o:p></p><p class=MsoPlainText>> create all the rules that I need for the entire array and save it in a <o:p></o:p></p><p class=MsoPlainText>> single drl file. Also, at the execution time, all the rules should be <o:p></o:p></p><p class=MsoPlainText>> applied - either at once or sequentially - to all the rows of the data.<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> Approach:- I tried the following<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> 1. Created an ArrayList<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> ArrayList<DailyPLC> alPLCArrayList = new ArrayList<DailyPLC>();<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> 2. Iterated over the data and stored each row into a field of the<o:p></o:p></p><p class=MsoPlainText>> object of DailyPLC class.<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> 3. For every iteration, added the object into the array list.<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> alPLCArrayList.add(plcToday); // The plcToday is the object of the <o:p></o:p></p><p class=MsoPlainText>> DailyPLC class<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> 4. When executing the rules, I am adding all the items of the<o:p></o:p></p><p class=MsoPlainText>> ArrayList one by one and adding into the Knowledge Session.<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> for(DailyPLC d : alPLCArrayList)<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> {<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> ksession.insert(d);<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> }<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> Problem Faced :- The problem that I faced is that when I do <o:p></o:p></p><p class=MsoPlainText>> FireAllRules, the rule only validates the last record. The intent is <o:p></o:p></p><p class=MsoPlainText>> that it should traverse the list and give a result for all the members of the list.<o:p></o:p></p><p class=MsoPlainText>> Have I missed something here?<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> Please assist. Let me know in case you need any more information<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> Thanks in Advance,<o:p></o:p></p><p class=MsoPlainText>> Amal Gupta<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> **************** CAUTION - Disclaimer ***************** This e-mail <o:p></o:p></p><p class=MsoPlainText>> contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> for the use of the addressee(s). If you are not the intended <o:p></o:p></p><p class=MsoPlainText>> recipient, please notify the sender by e-mail and delete the original <o:p></o:p></p><p class=MsoPlainText>> message. Further, you are not to copy, disclose, or distribute this <o:p></o:p></p><p class=MsoPlainText>> e-mail or its contents to any other person and any such actions are <o:p></o:p></p><p class=MsoPlainText>> unlawful. This e-mail may contain viruses. Infosys has taken every <o:p></o:p></p><p class=MsoPlainText>> reasonable precaution to minimize this risk, but is not liable for any <o:p></o:p></p><p class=MsoPlainText>> damage you may sustain as a result of any virus in this e-mail. You <o:p></o:p></p><p class=MsoPlainText>> should carry out your own virus checks before opening the e-mail or <o:p></o:p></p><p class=MsoPlainText>> attachment. Infosys reserves the right to monitor and review the <o:p></o:p></p><p class=MsoPlainText>> content of all messages sent to or from this e-mail address. Messages <o:p></o:p></p><p class=MsoPlainText>> sent to or from this e-mail address may be stored on the Infosys <o:p></o:p></p><p class=MsoPlainText>> e-mail system.<o:p></o:p></p><p class=MsoPlainText>> ***INFOSYS******** End of Disclaimer ********INFOSYS***<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>_______________________________________________<o:p></o:p></p><p class=MsoPlainText>rules-users mailing list<o:p></o:p></p><p class=MsoPlainText><a href="mailto:rules-users@lists.jboss.org"><span style='color:windowtext;text-decoration:none'>rules-users@lists.jboss.org</span></a><o:p></o:p></p><p class=MsoPlainText><a href="https://lists.jboss.org/mailman/listinfo/rules-users"><span style='color:windowtext;text-decoration:none'>https://lists.jboss.org/mailman/listinfo/rules-users</span></a><o:p></o:p></p></div></body></html>