<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.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.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;}
/* List Definitions */
@list l0
        {mso-list-id:1177429595;
        mso-list-type:hybrid;
        mso-list-template-ids:-906830992 67698703 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;}
@list l0:level1
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level2
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level3
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level4
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level5
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level6
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
@list l0:level7
        {mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level8
        {mso-level-number-format:alpha-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-.25in;}
@list l0:level9
        {mso-level-number-format:roman-lower;
        mso-level-tab-stop:none;
        mso-level-number-position:right;
        text-indent:-9.0pt;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></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=MsoNormal>Hello,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I am new to Java and Drools and have a doubt regarding the sequence of rules’ execution as stated below :- <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><b>Scenario:- </b>I have a scenario wherein I have to apply multiple rules on multiple columns coming in a file. To simulate that I created a 2-D array as follows <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Courier New";color:black'>String[][] data = {</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><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"1791"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"8459625"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"78458745"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"20120610"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"20120610" </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><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"1792"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"8459623"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"78458745"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"20120610"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"20120610" </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><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"1793"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"8459624"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"78458745"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"20120610"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"20120610" </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><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"17944"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"8459626"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"78458745"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"20120610"</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>,</span><span style='font-size:10.0pt;font-family:"Courier New";color:#2A00FF'>"20120610"</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><span style='font-size:10.0pt;font-family:"Courier New";color:black'> };<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";color:black'><o:p> </o:p></span></p><p class=MsoNormal>Here each column of corresponds to a member for the following class <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='text-autospace:none'><b><span style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>public</span></b><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:#7F0055'>class</span></b><span style='font-size:10.0pt;font-family:"Courier New";color:black'> DailyPLC {</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:#7F0055'>private</span></b><span style='font-size:10.0pt;font-family:"Courier New";color:black'> String </span><span style='font-size:10.0pt;font-family:"Courier New";color:#0000C0'>Id</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>; </span><span style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>// This value will correspond to data[i][0]</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:#7F0055'>private</span></b><span style='font-size:10.0pt;font-family:"Courier New";color:black'> String </span><span style='font-size:10.0pt;font-family:"Courier New";color:#0000C0'>productCode</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>; </span><span style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>// This value will correspond to data[i][1]</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:#7F0055'>private</span></b><span style='font-size:10.0pt;font-family:"Courier New";color:black'> String </span><span style='font-size:10.0pt;font-family:"Courier New";color:#0000C0'>customerCode</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>; </span><span style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>// This value will correspond to data[i][2]</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:#7F0055'>private</span></b><span style='font-size:10.0pt;font-family:"Courier New";color:black'> String </span><span style='font-size:10.0pt;font-family:"Courier New";color:#0000C0'>date1</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>; </span><span style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>// This value will correspond to data[i][3]</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:#7F0055'>private</span></b><span style='font-size:10.0pt;font-family:"Courier New";color:black'> String </span><span style='font-size:10.0pt;font-family:"Courier New";color:#0000C0'>date2</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>; </span><span style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>// This value will correspond to data[i][4]</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:#7F0055'>private</span></b><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:#7F0055'>int</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:#0000C0'>rowNumber</span><span style='font-size:10.0pt;font-family:"Courier New";color:black'>; </span><span style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>// The row number to keep a track of row for which the record exists</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><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New";color:black'> </span><span style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>/*Getters and Setters defined for each of them*/<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>}<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'><o:p> </o:p></span></p><p class=MsoNormal>I have to perform checks on each of the columns, and the intent is to create all the rules that I need for the entire array and save it in a single drl file. Also, at the execution time, all the rules should be applied – either at once or sequentially – to all the rows of the data.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><b>Approach:- </b> I tried the following<o:p></o:p></p><p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>1.<span style='font:7.0pt "Times New Roman"'> </span></span><![endif]>Created an ArrayList <o:p></o:p></p><p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New";color:black'>ArrayList<DailyPLC> alPLCArrayList = new ArrayList<DailyPLC>();<o:p></o:p></span></p><p class=MsoListParagraph><o:p> </o:p></p><p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>2.<span style='font:7.0pt "Times New Roman"'> </span></span><![endif]>Iterated over the <span style='font-size:10.0pt;font-family:"Courier New";color:black'>data </span>and stored each row into a field of the object of <span style='font-size:10.0pt;font-family:"Courier New";color:black'>DailyPLC </span>class. <o:p></o:p></p><p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>3.<span style='font:7.0pt "Times New Roman"'> </span></span><![endif]>For every iteration, added the object into the array list. <o:p></o:p></p><p class=MsoListParagraph><o:p> </o:p></p><p class=MsoListParagraph><span style='font-size:10.0pt;font-family:"Courier New";color:black'>alPLCArrayList.add(plcToday); </span><span style='font-size:10.0pt;font-family:"Courier New";color:#3F7F5F'>// The plcToday is the object of the DailyPLC class<o:p></o:p></span></p><p class=MsoListParagraph><o:p> </o:p></p><p class=MsoListParagraph style='text-indent:-.25in;mso-list:l0 level1 lfo1'><![if !supportLists]><span style='mso-list:Ignore'>4.<span style='font:7.0pt "Times New Roman"'> </span></span><![endif]>When executing the rules, I am adding all the items of the ArrayList one by one and adding into the Knowledge Session. <o:p></o:p></p><p class=MsoListParagraph style='text-autospace:none'><b><span style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'><o:p> </o:p></span></b></p><p class=MsoListParagraph style='text-autospace:none'><b><span style='font-size:10.0pt;font-family:"Courier New";color:#7F0055'>for</span></b><span style='font-size:10.0pt;font-family:"Courier New";color:black'>(DailyPLC d : alPLCArrayList)</span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoListParagraph style='text-autospace:none'><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=MsoListParagraph style='text-autospace:none'><span style='font-size:10.0pt;font-family:"Courier New";color:black'> ksession.insert(d); </span><span style='font-size:10.0pt;font-family:"Courier New"'><o:p></o:p></span></p><p class=MsoListParagraph style='text-autospace:none'><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><span style='font-size:10.0pt;font-family:"Courier New";color:black'><o:p> </o:p></span></p><p class=MsoListParagraph><o:p> </o:p></p><p class=MsoNormal><b>Problem Faced :- </b><u>The problem that I faced is that when I do FireAllRules, the rule only validates the last record. The intent is that it should traverse the list and give a result for all the members of the list</u>. <o:p></o:p></p><p class=MsoNormal>Have I missed something here? <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Please assist. Let me know in case you need any more information<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><b>Thanks in Advance,<o:p></o:p></b></p><p class=MsoNormal><b>Amal Gupta<o:p></o:p></b></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>
<table><tr><td bgcolor=#ffffff><font color=#000000><pre>**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
for the use of the addressee(s). If you are not the intended recipient, please
notify the sender by e-mail and delete the original message. Further, you are not
to copy, disclose, or distribute this e-mail or its contents to any other person and
any such actions are unlawful. This e-mail may contain viruses. Infosys has taken
every reasonable precaution to minimize this risk, but is not liable for any damage
you may sustain as a result of any virus in this e-mail. You should carry out your
own virus checks before opening the e-mail or attachment. Infosys reserves the
right to monitor and review the content of all messages sent to or from this e-mail
address. Messages sent to or from this e-mail address may be stored on the
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***</pre></font></td></tr></table>