Is nested loops possible ?
by Dinesh kumar
Hi,
I am having a problem in iterating a list inside a list.
I am having the following business scenario.
Public Class CustomerOrder {
private String customerName;
private ArrayList<Order> orderList;
}
Public Class Order {
private String orderId;
private String orderTime;
private ArrayList<OrderItem> orderList;
}
Public Class OrderItem {
private String itemName;
private Double itemAmount;
}
I need to find the total order amount for each order and the sum of all
order.
My rule is like individual orders should not exceed a 10000 and total order
amount of all customers should not exceed 100000.
For this, I need to iterate ArrayList<Order> orderList and during each
iteration , I need to iterate ArrayList<OrderItem> orderList. Is this
possible in Drools ?
I tried something like this. But it doesn't seem to be working.
when
ClaimRegistration($orderList: orderList)
Number( $count : intValue > 0)
from accumulate(Order(orderId== "order1"
&&
Number( doubleValue > 10000 )
from accumulate( OrderItem( $value : itemAmount),
init( double total = 0; ),
action( total += $value; ),
reverse( total -= $value; ),
result( total ) )
) from $orderList,count(1))
then
Sysout(",,,,,");
It would be of great help if any one can give suggestions to solve this.
Is nested loops possible in Drools ?
Regards,
Dinesh
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Is-nested-loops-possi...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 3 months
Math calculations on attributes in WHEN section of rules.
by tom ska
Hello,
what I want to do, is to calculate on object's attributes in WHEN section of
rule. Can I do it?
For example:
class CObj
{
private int k;
private int n;
// setters and getters
}
Now what I want to do is:
rule "r1"
when
p : CObj ( k + n <= 1000)
then
System.out.println("We love Drools :)");
end
Why can't I construct conditions like in Java, or C++ (with calculations in
conditions)? How can I achieve my goal?
Thx,
Tom.
14 years, 3 months
Another solution for: Detecting more than 3 occurrences within 1 hour
by Tina Vießmann
Hi,
I'm working on thinking in Drools rules. Right now I'm trying to solve this:
The rule shall fire if _a special event occurs more than 3 times
within 1 hour_.
My _first thought of a solution_ was to count the count the detected
events using a counter. But the counter has to be a global variable,
hasn't it? And global variables are not to be used to frequently, aren't
they?
And global variables must always be initialized from outside the rules
file, don't they?
Because of these thoughts I've looked for a _different solution without
global variables_. I came up with:
function boolean valueExceededLimit(Set<Alarms> alarmSet) {
//....
}
rule "more than 3 occurs within 1 hour"
when
// event #1
$eventA : Value(
eval(parameterValueExceededLimit($eventA.getAlarms())) )
// event #2
$eventB : Value( this after[0ms,1h] $eventA &&
this != $eventA &&
eval(valueExceededLimit($eventB.getAlarms())) )
// event #3
$eventC : Value( this after[0ms,1h] $eventA &&
this != $eventA &&
this != $eventB &&
eval(valueExceededLimit($eventC.getAlarms())) )
// event #4 -> 4 > 3
$eventD : Value( this after[0ms,1h] $eventA &&
this != $eventA &&
this != $eventB &&
this != $eventC &&
eval(valueExceededLimit($eventD.getAlarms())) )
then
// ... do something ...
end
More than 3 is kind of a doable task. But I think of this solution as
heavy in case its needed to detect a larger number of events. I would be
thankful for other approaches to the problem.
Thanks :)
Tina
14 years, 3 months
NullPointerException on jpaSingleSessionCommandService
by drooRam
I have configured the applicationContext.xml as follows for stateful JPA
persistance session - jpaSingleSessionCommandService :
<drools:ksession id="jpaSingleSessionCommandService" type="stateful"
kbase="flowKnowledge">
<drools:configuration>
<drools:jpa-persistence>
<drools:transaction-manager ref="transactionManager" />
<drools:entity-manager-factory ref="entityManagerFactory" />
<drools:variable-persisters>
<drools:persister for-class="javax.persistence.Entity"
implementation="org.drools.persistence.processinstance.persisters.JPAVariablePersister"/>
<drools:persister for-class="java.io.Serializable"
implementation="org.drools.persistence.processinstance.persisters.SerializableVariablePersister"/>
</drools:variable-persisters>
</drools:jpa-persistence>
</drools:configuration>
</drools:ksession>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="rascalflow-persistence" />
<property name="persistenceProvider">
<bean class="org.hibernate.ejb.HibernatePersistence" />
</property>
<property name="jpaVendorAdapter">
<bean id="jpaVendorAdapter"
class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="database" value="ORACLE" />
<property name="showSql" value="true" />
</bean>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"
p:dataSource-ref="dataSource">
<property name="hibernateProperties">
<value>
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.hbm2ddl.auto=update
hibernate.show_sql=true
hibernate.max_fetch_depth=3
hibernate.format_sql=true
hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
</value>
</property>
</bean>
<bean id="sharedEntityManagerBean"
class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager"
p:sessionFactory-ref="sessionFactory" />
When i tried to start the application, i have got Null pointer exception
from drools ...Error creating bean with name
'jpaSingleSessionCommandService': ... i know this is something to do with
the parameter transaction manager in drools configuration tag... but i have
no clue why this error is occuring or any soln....
It might be the configuration that i have done was incorrect, someone please
go through the above configuration and let me know where exactly that I am
doing the mistake....
Basic runtime exception is :
Caused by: java.lang.RuntimeException: Could not commit session
at
org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:135)
... 52 more
Caused by: java.lang.NullPointerException
at
org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:124)
... 52 more
Aug 5, 2010 3:26:44 PM org.apache.catalina.core.StandardContext
loadOnStartup
SEVERE: Servlet /rascalFlow threw load() exception
java.lang.NullPointerException
at
org.drools.persistence.session.SingleSessionCommandService.<init>(SingleSessionCommandService.java:124)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:119)
at
org.drools.persistence.jpa.impl.KnowledgeStoreServiceImpl.newStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:57)
at
org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:93)
at
org.drools.container.spring.beans.StatefulKnowledgeSessionBeanFactory.internalAfterPropertiesSet(StatefulKnowledgeSessionBeanFactory.java:71)
at
org.drools.container.spring.beans.AbstractKnowledgeSessionBeanFactory.afterPropertiesSet(AbstractKnowledgeSessionBeanFactory.java:93)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
at
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
at
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
at
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
at
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
at
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at
org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at
org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4187)
at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4496)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
at
org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
at
org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
at
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/NullPointerException-...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 3 months
A Set of Rules but no match
by Wolfgang Laun
I'm using code such as
KnowledgeRuntime knowledgeRuntime;
for( KnowledgePackage knowledgePackage:
knowledgeRuntime.getKnowledgeBase().getKnowledgePackages() ){
for( Rule rule: knowledgePackage.getRules() ){
}
}
to obtain rules, intending to construct a Set<Rule>. This, however, breaks
since repeated executions of
knowledgePackage.getRules() appear to return different objects and - this is
the evil thing -
org.drools.definitions.rule.impl.RuleImpl does not implement hashCode() and
equals(); hence
Set<Rules>( rule ).contains( rule ) fails for actually identical rules. I
consider this a bug in Drools (5.1).
org.drools.definitions.rule.impl.RuleImpl could easily retain a reference to
the org.drools.rule.Rule object from which it is built and delegate
hashCode/equals to that.
-W
14 years, 3 months
Is Drools rule engine thread safe
by james corrigan
Hi All,
I am trying to implement a mutli-threaded application using Drools Guvnor,
my question is whether or not i can share a reference of say a
StatefulKnowledgeSession or Knowledge between multiple threads? Any help is
much appreciated.
Kind regards,
James.
14 years, 3 months
drools 5.1 overview
by miguel machado
Hi all,
I just recently noticed that drools 5.1 is out and i'd like to congratulate
the jboss team for this great milestone achievement. I've also noticed that
there is separate documentation for this version on
http://jboss.org/drools/documentation.html but i haven't been able to find
the major updates on the project, since 5.0.0.
I presume the *changelog* so far is huge, so what I was looking is some kind
of blog post or release announcement so i can update a few reports i've been
writing on drools features, modules, architecture, API, requirements,
integration mechanisms, etc.
Any help is very much appreciated.
Thanks in advance,
_ miguel
--
"To understand what is recursion you must first understand recursion"
14 years, 3 months
Rule flow persistence MY SQL
by sony.john@kie.com.sg
Hi ,
Iam trying to persistence drools workflow using my sql as back end . But
iam getting "Could not commit sessions"
Iam trying with example code,
drool.session.conf file contains
drools.workItemHandlers = MyWorkItemHandlers.conf
#drools.commandService =
org.drools.persistence.session.SingleSessionCommandService
#drools.processInstanceManagerFactory =
org.drools.persistence.processinstance.JPAProcessInstanceManagerFactory
#drools.workItemManagerFactory =
org.drools.persistence.processinstance.JPAWorkItemManagerFactory
#drools.processSignalManagerFactory =
org.drools.persistence.processinstance.JPASignalManagerFactory
Folllwoing are my rf file
My RF file
<?xml version="1.0" encoding="UTF-8"?>
<process xmlns="http://drools.org/drools-5.0/process"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://drools.org/drools-5.0/process
drools-processes-5.0.xsd"
type="RuleFlow" name="droolsflow"
id="org.plugtree.labs.droolsflow" package-name="org.plugtree.labs" >
<header>
<imports>
<import name="org.kie.lab.variablepersistence.MyEntity" />
<import name="org.kie.lab.variablepersistence.MyVariableSerializable"
/>
</imports>
<variables>
<variable name="x" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</variable>
<variable name="y" >
<type
name="org.drools.process.core.datatype.impl.type.ObjectDataType"
className="org.kie.lab.variablepersistence.MyEntity" />
</variable>
<variable name="z" >
<type
name="org.drools.process.core.datatype.impl.type.ObjectDataType"
className="org.kie.lab.variablepersistence.MyVariableSerializable" />
</variable>
<variable name="a" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</variable>
<variable name="b" >
<type
name="org.drools.process.core.datatype.impl.type.ObjectDataType"
className="org.kie.lab.variablepersistence.MyEntity" />
</variable>
<variable name="c" >
<type
name="org.drools.process.core.datatype.impl.type.ObjectDataType"
className="org.kie.lab.variablepersistence.MyVariableSerializable" />
</variable>
</variables>
</header>
<nodes>
<humanTask id="4" name="Human Task" x="208" y="16" width="93"
height="48" >
<work name="Human Task" >
<parameter name="ActorId" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="Comment" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="Content" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="Priority" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="Skippable" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="TaskName" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
</work>
</humanTask>
<humanTask id="9" name="Human Task" x="713" y="16" width="100"
height="48" >
<work name="Human Task" >
<parameter name="ActorId" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="Comment" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="Content" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="Priority" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="Skippable" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="TaskName" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
</work>
</humanTask>
<actionNode id="8" name="Action" x="601" y="20" width="80" height="40"
>
<action type="expression" dialect="java" >System.out.println("x = "
+ x);
System.out.println("y = " + y);
System.out.println("z = " + z);
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);
kcontext.setVariable("a", "Some changed String");
kcontext.setVariable("b", new MyEntity("This is a changed test Entity"));
kcontext.setVariable("c", new MyVariableSerializable("This is a changed
test SerializableObject"));</action>
</actionNode>
<actionNode id="6" name="Action" x="333" y="20" width="80" height="40"
>
<action type="expression" dialect="java" >System.out.println("x = "
+ x);
System.out.println("y = " + y);
System.out.println("z = " + z);
kcontext.setVariable("a", "Some new String");
kcontext.setVariable("b", new MyEntity("This is a new test Entity"));
kcontext.setVariable("c", new MyVariableSerializable("This is a new test
SerializableObject"));</action>
</actionNode>
<start id="1" name="Start" x="16" y="16" width="48" height="48" />
<end id="3" name="End" x="957" y="16" width="48" height="48" />
<actionNode id="10" name="Action" x="845" y="16" width="80" height="48"
>
<action type="expression" dialect="java" >System.out.println("x = "
+ x);
System.out.println("y = " + y);
System.out.println("z = " + z);
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);</action>
</actionNode>
<humanTask id="7" name="Human Task" x="445" y="20" width="124"
height="40" >
<work name="Human Task" >
<parameter name="ActorId" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="Comment" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="Content" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="Priority" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="Skippable" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
<parameter name="TaskName" >
<type
name="org.drools.process.core.datatype.impl.type.StringDataType" />
</parameter>
</work>
</humanTask>
<actionNode id="5" name="Action" x="96" y="20" width="80" height="40" >
<action type="expression" dialect="java" >System.out.println("x = "
+ x);
System.out.println("y = " + y);
System.out.println("z = " + z);</action>
</actionNode>
</nodes>
<connections>
<connection from="5" to="4" />
<connection from="8" to="9" />
<connection from="7" to="8" />
<connection from="4" to="6" />
<connection from="10" to="3" />
<connection from="9" to="10" />
<connection from="6" to="7" />
<connection from="1" to="5" />
</connections>
</process>
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="org.drools.persistence.jpa"
transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/testDS1</jta-data-source>
<class>org.drools.persistence.session.SessionInfo</class>
<class>org.drools.persistence.processinstance.ProcessInstanceInfo</class>
<class>org.drools.persistence.processinstance.WorkItemInfo</class>
<class>org.drools.persistence.processinstance.variabletypes.VariableInstanceInfo</class>
<class>org.drools.persistence.processinstance.variabletypes.JPAPersistedVariable</class>
<class>org.drools.persistence.processinstance.variabletypes.SerializablePersistedVariable</class>
<class>org.kie.lab.variablepersistence.MyEntity</class>
<class>org.kie.lab.variablepersistence.StringPersistedVariable</class>
<class>org.kie.lab.variablepersistence.MyVariableSerializable</class>
<properties>
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQL5Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.connection.autocommit" value="false"/>
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.BTMTransactionManagerLookup"/>
</properties>
</persistence-unit>
</persistence>
Information in this e-mail is intended solely for the person(s) to whom it is addressed and may contain confidential information. If you are not the intended recipient, please notify the sender and delete this e-mail message and any other record of it from your system immediately. You should not disclose or disseminate the information to any person, use it for any purpose or store or copy the information in any form or manner.
14 years, 3 months