looping in drools
by Sandhya Sree
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.
11 years, 10 months
(no subject)
by Sandhya Sree
hi ,
i have a class called Event which is as follows:
public class Event {
private String name;
private File source;
private Date timeStamp;
public static List<Event> listOfEvents;
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;
}
public void display()
{
System.out.println(name +" " + "in folder: " + source + " on " + timeStamp
);
}
there are also some other classes associated with my project.. i have a
rules file which computes the size of a folder and creates an object of
Event class. every time this object of Event class is created i wwant to
put it in a List<Event>.. how can i do this..
my rules is as follows:
rule "size"
when
$p: RuleContext($size: getOldContext().getParent().getUsableSpace() >
(30*1024*1024))
then
Event event = new Event("folder almost full",
$p.getOldContext().getParent(), new Date());
event.display();
......here i want to put this event into the List<Event> declared in
Event Class.....
end
thanks,
Sandhya
11 years, 10 months
Disjunctive normal form
by Mercier Jonathan
Dear,
Little question when we writing a rules.
I would like to know if they are a difference between to write a rule as
disjunctive normal form or not into Phreak graph ?
Thanks
Regards
11 years, 10 months
setting consequence exception handler
by kenneth.westelinck@telenet.be
All,
I want to configure my drools through spring (version 6.0.1). This is working fine, thanks to kie-spring. Now, I want to configure a consequence exception handler. In drools 5 this was configured like this:
<drools:configuration>
<drools:mbeans enabled="true" />
<drools:event-processing-mode mode="STREAM" />
<drools:consequenceExceptionHandler handler="com.sample.MyConsequenceExceptionHandler" />
</drools:configuration>
For 6.0.1, after some debugging, I've managed to set it throught a system property:
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject">
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetClass" value="java.lang.System" />
<property name="targetMethod" value="getProperties" />
</bean>
</property>
<property name="targetMethod" value="putAll" />
<property name="arguments">
<util:properties>
<prop key="drools.consequenceExceptionHandler">com.sample.MyConsequenceExceptionHandler</prop>
</util:properties>
</property>
</bean>
I don't think this is the way to go however, so I'm wondering how to do this properly for drools 6.0.1.
Thanks!
regards,
Kenneth
11 years, 10 months
Test classpath question
by balazs.molnar
Hello,
I am running my tests on spring+drools v 6.0.1.Final. When running tests
KModuleBeanFactoryPostProcessor seems to pick up rules files only from the
test class path (configFilePath = "...target/test-classes/"). This means if
I have rules in main/resources these cannot be tested. How do I get
KModuleBeanFactoryPostProcessor to look in other classpaths in the
environment ? What is the intended use ?
thanks.
also I noticed that this version of KModuleBeanFactoryPostProcessor fails if
beans have no id, I saw the fix of that but it is not yet in the release.
When is that expected to be release ?
--
View this message in context: http://drools.46999.n3.nabble.com/Test-classpath-question-tp4028584.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 10 months
Drools in Glassfish 4 Ear
by Joe White
This is just an FYI for drools users. When deploying an EAR to Glassfish 4 we received an exception about Weld dependency injection.
org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [Injector] with qualifiers [@Default] at injection point [[BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedMethod] @Inject org.sonatype.guice.bean.locators.DefaultBeanLocator.autoPublish(Injector)]
The solution that worked in our case was putting this setting in Glassfish:
asadmin set configs.config.server-config.cdi-service.enable-implicit-cdi=false
That solution is from this forum post (lots more detail there):
http://www.eclipse.org/forums/index.php/t/490794/
Took some time for me to figure out so figured it might help somebody someday.
Joe
11 years, 10 months
Some basic questions/assumptions on Drools Work-bench/Guvnor
by mattmadhavan
Hello,
I have some basic questions on the Drools workbench. Can some one please
validate my assumptions?
1) Drools workbench/Guvnor is not a replacement for Eclipse.
2) Geeks like me develop the applications in Eclipse
3) Drools workbench will be mainly used by the Rule authors (Business
Analysts etc) once I set it up for them.
4) The anslysts will author the rules and test it in the workbench.
5) They will build the DRLs into a jar and I include it as a dependency in
my POM.xml.
How close am I to these assumptions?
Thanks
Matt'M
--
View this message in context: http://drools.46999.n3.nabble.com/Some-basic-questions-assumptions-on-Dro...
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years, 10 months