Hello,

 

I am new to Java and Drools and have a doubt regarding the sequence of rules’ execution as stated below :-

 

Scenario:- 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

 

String[][] data =  {

                        {"1791","8459625","78458745","20120610","20120610" },

                        {"1792","8459623","78458745","20120610","20120610" },

                        {"1793","8459624","78458745","20120610","20120610" },

                        {"17944","8459626","78458745","20120610","20120610"}

                  };

 

Here each column of corresponds to a member for the following class

 

public class DailyPLC {

 

      private String Id;    // This value will correspond to data[i][0]

      private String productCode; // This value will correspond to data[i][1]

      private String customerCode; // This value will correspond to data[i][2]

      private String date1; // This value will correspond to data[i][3]

      private String date2; // This value will correspond to data[i][4]

 

      private int rowNumber; // The row number to keep a track of row for which the record exists

     

      /*Getters and Setters defined for each of them*/

}

 

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.

 

Approach:-  I tried the following

1.       Created an ArrayList

ArrayList<DailyPLC> alPLCArrayList = new ArrayList<DailyPLC>();

 

2.       Iterated over the data and stored each row into a field of the object of DailyPLC class.

3.       For every iteration, added the object into the array list.

 

alPLCArrayList.add(plcToday);  // The plcToday is the object of the DailyPLC class

 

4.       When executing the rules, I am adding all the items of the ArrayList one by one and adding into the Knowledge Session.

 

for(DailyPLC d : alPLCArrayList)

            {

           ksession.insert(d);   

            }

 

 

Problem Faced :- 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.

Have I missed something here? 

 

Please assist.  Let me know in case you need any more information

 

Thanks in Advance,

Amal Gupta

 

**************** 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***