Using an Arraylist in ILOG/ODM to loop through a set of records

2.5k views Asked by At

I have a requirement to loop through a set of records and compare the start date in each record with current date and output a message in the Action part of the rule. I am trying to find out if I can use an arraylist in ILOG/ODM rule XOM and use it in the rule to loop through the set of records. Can you please suggest me the best way to implement this requirement.

2

There are 2 answers

0
uoyilmaz On

Yes, you can use an arraylist in rule XOM, and iterate over it in the rule. Let's assume your rule project takes an instance of your XOM class as an input parameter with the verbalization 'test'. You would have something like below.

XOM:

import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class Test
{
    private List<Record> recordList;

    public Test()
    {
    }

    public void setRecordList(List<Record> recordList)
    {
        this.recordList = recordList;
    }

    public List<Record> getRecordList()
    {
        return recordList;
    }

    public static int compareWithCurrentDate( Date date)
    {
        Calendar cal = Calendar.getInstance();
        cal.setTime( date);
        return cal.compareTo( Calendar.getInstance());
    }
}


import java.util.Date;

public class Record
{
    private Date startDate;

    public Record()
    {
    }

    public void setStartDate(Date startDate)
    {
        this.startDate = startDate;
    }

    public Date getStartDate()
    {
        return startDate;
    }
}

BOM Verbalization:

# Record
Record#concept.label = record
Record.startDate#phrase.action = set the start date of {this} to {start date}
Record.startDate#phrase.navigation = {start date} of {this}

# Test
Test#concept.label = test
Test.compareWithCurrentDate(java.util.Date)#phrase.navigation = compare {0} with current date
Test.recordList#phrase.action = set the record list of {this} to {record list}
Test.recordList#phrase.navigation = {record list} of {this}

Rule:

definitions 
    set 'current record' to a record in the record lists of test ; 
if
    compare the start date of 'current record' with current date is not 0 
then
    print "" ;
0
Leon Matthews On

You can follow the instructions in the ODM Blogs on developerWorks under "iterating over input parameters" topic.

It can be found here:

Iterating over Input Parameters

Basically you are going to a virtual method for your ArrayList to retrieve an entry at particular loop index. The virtual method will cast the entry before returning it, but from there you should be able to perform any rule on that object.

Note that you cannot use ArrayList as an input parameter for Dynamic XOM but you can use Arrays for input parameter with a Java XOM.