[rules-users] looping in drools

Sandhya Sree sandhyachinnaraj at gmail.com
Mon Mar 10 14:04:54 EDT 2014


hi,
im new to drools..im trying to create a project as follows. i have a class
called Monitor  which monitors a folder and creates two lists called
fileOld( which is the list of filenames in that folder at time t1)  and
fileNew(which is the list of filenames in that folder at time t2). i have
another class called FileData which contains two members fileOld and
fileNew (list of strings) with getters,setters and constructor. fileOld and
fileNew from Monitor Class are passed to FileData class.

i also have another class called Event which is as follows:
public class Event {
 public static String name;
 private  File source;
 private  Date timeStamp;
        public  static  List<Event> listOfEvents = new ArrayList<Event>();

public Event(String name, File source, Date timeStamp) {
this.name = name;
this.source = source;
this.timeStamp = timeStamp;
}
 public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public File getSource() {
return source;
}
public void setSource(File source) {
this.source = source;
}
public Date getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(Date timeStamp) {
this.timeStamp = timeStamp;
}

now i have to compare these two lists(fileOld and fileNew) in a rule file
and if they are not equal i have to create an event object for every file
added and deleted and put it in the List<Event> listOfEvents.

here is my rule file:

rrule "files are equal"
    when
         FileData( fileOld == fileNew)
    then
       System.out.println("files are equal");
    end


rule "files not equal"
when
    FileData($old : fileOld, $new : fileNew, fileOld != fileNew)

then
   accumulate( $s : String( this not memberOf $old ) from $new, $plus :
collectList( $s ) )
   accumulate( $t : String( this not memberOf $new ) from $old, $mins :
collectList( $t ) )
   System.out.println("files added:" + $plus );
   System.out.println( "files deleted:" + $mins );
end



how can i loop through each of the file added or deleted and create an
Event Class object for every file added and deleted  and finally add all
the created objects to List<Event> listOfEvents..


Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20140310/c75ff57c/attachment.html 


More information about the rules-users mailing list