Hi Wolfgang,
This problem has been resolved now. I wrote the rule that you gave me, and found out that
the control was only considering the last row and the remaining rows were not considered
for execution.
I was trying to look for a solution in the Session and the ArrayList details of the
session.
I rectified it by creating a different object inside the loop when reading values, so
that the original value was not modified.
The Old code for reading the objects was
DailyPLC plcToday = new DailyPLC();
for(int iLoopIndex = 0;iLoopIndex <4; iLoopIndex++)
{
plcToday.setSrceSysId(data[iLoopIndex][0]);
plcToday.setProductCode(data[iLoopIndex][1]);
plcToday.setDistributorCode(data[iLoopIndex][2]);
plcToday.setDuePeriod(data[iLoopIndex][3]);
plcToday.setTimePeriodStartDate(data[iLoopIndex][4]);
plcToday.setRowNumber(iLoopIndex+1);
alPLCArrayList.add(plcToday);
}
Which I modified to
DailyPLC plcToday ;
for(int iLoopIndex = 0;iLoopIndex <4; iLoopIndex++)
{
/** will need to create a new object every time and
* assign it to the same reference.
* This is because in case the object is same,
* the value gets modified after
* every execution. ( Pass by value and reference )
*/
plcToday = new DailyPLC();
plcToday.setSrceSysId(data[iLoopIndex][0]);
plcToday.setProductCode(data[iLoopIndex][1]);
plcToday.setDistributorCode(data[iLoopIndex][2]);
plcToday.setDuePeriod(data[iLoopIndex][3]);
plcToday.setTimePeriodStartDate(data[iLoopIndex][4]);
plcToday.setRowNumber(iLoopIndex+1);
alPLCArrayList.add(plcToday);
}
Thank you so much for investing your time on the problem. It really helped.
Regards,
Amal
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of Wolfgang Laun
Sent: Tuesday, June 12, 2012 4:58 PM
To: Rules Users List
Subject: Re: [rules-users] Firing the rules in a sequence for all the items in an
ArrayList.
The rule you've shown will fire for all 4 elements created from the 4 rows of your
table.
Something might have gone wrong while constructing the objects or the list.
To see what you have, add this rule, which should print the IDs of all DailyPLC objects.
rule show
when
plc : DailyPLC();
then
System.out.println(" ID " + plc.getId()+ " at row : " +
plc.getRowNumber()); end
-W
On 12/06/2012, Amal Gupta
<Amal_Gupta@infosys.com<mailto:Amal_Gupta@infosys.com>> wrote:
Hi Wolfgang,
Thanks for your response.
Here is the rule that I had written for the file.
rule "Id != value"
when
plc : DailyPLC(Id!="1794");
then
System.out.println("Incorrect ID " + plc.getId()+
" at row : "
+ plc.getRowNumber()); end
Any pointers shall be really very helpful.
Regards,
Amal
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Wolfgang
Laun
Sent: Tuesday, June 12, 2012 3:57 PM
To: Rules Users List
Subject: Re: [rules-users] Firing the rules in a sequence for all the
items in an ArrayList.
Your question can't be answered without the rules. - If your Java
code
does what you say it does, then it should be OK.
-W
On 12/06/2012, Amal Gupta
<Amal_Gupta@infosys.com<mailto:Amal_Gupta@infosys.com<mailto:Amal_Gupta@infosys.com%3cmailto:Amal_Gupta@infosys.com>>>
wrote:
> 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***
>
_______________________________________________
rules-users mailing list
>
rules-users@lists.jboss.org<mailto:rules-users@lists.jboss.org<mailto:rules-users@lists.jboss.org%3cmailto:rules-users@lists.jboss.org>
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org<mailto:rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users