collection question
by javaj
I'm trying to write a rule to add an object to a collection if the collection
already contained a certain object with a specific attribute.
I developed a small example so maybe that will make more sense:
Use Case: In a product shipping applicaiton, anytime a product with the name
"cd1" is in the shipping order, a bonus product named "bonus_cd" needs to be
added to the shipping order. The bonus cd should not be added if it's
already in the shipping order.
Shipping Order:
public class ShippingOrder {
private Set<Product> products;
public ShippingOrder() {}
public Set<Product> getProducts() {
return products;
}
public void setProducts(Set<Product> products) {
this.products = products;
}
}
Product:
public class Product {
private String name;
public Product(){}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Rule:
rule "AddBonusCd"
when
$so : ShippingOrder()
$productList : ArrayList(size == 1) from collect( Product(name matches
"cd1|bonus_cd") from $so.products)
then
System.out.println("Adding Bonus Cd");
Set<Product> productSet = new HashSet<Product>($so.getProducts());
Product bonusCd = new Product();
bonusCd.setName("bonus_cd");
productSet.add(bonusCd);
modify($so) {
setProducts(productSet);
}
end
The Shipping Order object is inserted as the fact.
The rule is valid if only cd1 or cd_bonus is in the shipping order. I only
want the rule to run when cd1 is in the product set but cd_bonus is not.
Makes sense?
Thanks,
J
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/collection-question-t...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 11 months
Drools Flow 5.1 - latest snapshot -- Gateway (Diverge) : Split Node - Priority Does not Work
by Vijay K Pandey
Hi All,
In the Drools Flow 5.1 latest snapshot , for the node (Gateway (Diverge) : Split Node), somehow priority does not work. If we set some value, lets say 100 and open the process file(BPMN2) again and check the priority - somehow it doesn't retains the priority value and reports the value always as 0.
I am trying to make use one of the feature of XOR type node where one of the constraint is "always true" with the highest priority. I hope my understanding is right.
This is what the Drools Flow Doc says:
XOR means that exactly one of the outgoing connections will be chosen. The decision is made by evaluating the constraints that are linked to each of the outgoing connections. Constraints are specified using the same syntax as the left-hand side of a rule. The constraint with the lowest priority number that evaluates to true is selected. Note that you should always make sure that at least one of the outgoing connections will evaluate to true at runtime (the ruleflow will throw an exception at runtime if it cannot find at least one outgoing connection). For example, you could use a connection which is always true (default) with a high priority number to specify what should happen if none of the other connections can be taken.
Has anyone faced this issue?
Thanks
Vijay
15 years, 11 months
Drools Flow - Human Task
by jawa
Hi,
I am developing a drools flow application and at one point of the flow I
want end user (User of my website) to reply to some questions one by one
i.e. I'll show them a question on a web page and they'll answer it then next
question etc. It has a flow sequence depending on the answers of questions.
e.g. If user replied 'No' to Q1 then go to Q5 else go to Q2 etc. So I want
my flow to stop for a user input when the flow reaches to the 'Ask question'
stage. I have read the drools flow documentation and it looks like there is
an option to use Human Task which will cause my flow to stop at that point
and wait for user input but for that I'll have to use Apache Mina server and
will need to claim tasks etc. But I don't want that because my front end
application is in php and backend (Drools flow) is in java and I connect
both using webservice. So I just want to ask my front end that ask question
then front end will reply with an answer that I want to feed to my flow then
flow will continue and decide which question to ask next. The website users
are anonymous it can be anyone answering the questions.
Can anyone please give me an idea how to achieve this using drools flow?
Thank you
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-Flow-Human-Tas...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 11 months
Implementing Timers With Drools Persistence Enabled
by nanic23
Hi All,
I was able to implement some timers and they behave as expected until I
enable persistence. Timers work (get triggered) when creating the
StatefulKnowledgeSession by kbase.newStatefulKnowledgeSession() but they do
NOT work (do not get triggered) when creating the StatefulKnowledgeSession
by JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
I am calling ksession.fireUntilHalt() from within a new thread and all that.
The problem is not getting timers to work, as I have already accomplished
this, but the problem is rather getting them to work with persistence
enabled.
- Has anyone implemented timers while using (having enabled) persistence?
- Did you experience any problems such as timers not triggering?
- If so, have you found a work around you could share?
The timers are being implemented in ruleflow (DRF) and I'm using drools
5.1.0
Any comments are welcome.
Thanks,
Nick.
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Implementing-Timers-W...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 11 months
Still getting an EvalConditionNode ClassCastException
by Paul Ryan
We're still getting a class cast exception for beta and eval memory (exception below). It is a different location and the opposite direction of the exception cast from JBRULES-1719.
The rule we ran was:
/**
* Load the smgl transform
*/
rule "Load Transform"
when
$fact : ParametersFact(
doc != "dmodule",
$xml : xml != null,
noopResponse == true,
eval(XPathUtil.selectElement($xml,"/*/transformLog//transform[name='s1000dv3']")==null),
flags['loadedS1000Dv3']!=true,
eval(XPathUtil.selectElement($xml,"/*/transformLog//transform[name='detect']/results[result='text/xml']")!=null)
)
$importUtil : RuleImportUtil()
$model : EditionsRulesJobRunner(stop==false,interrupt==false)
then
Vector<String> libraries = new Vector<String>();
libraries.add("lib");
String documentType = "dmodule";
String fragmentType = "dmodule";
$importUtil.importRules(kcontext,"transformCmd",documentType,fragmentType,libraries);
$fact.getFlags().put("loadedS1000Dv3",true);
end
The thing of consequence here is the importRules call which modifies the kcontext and acts as a dynamic include (e.g. it imports new rules).
The exception received is:
INFO | 2010/07/19 17:07:29 | jvm 1 | 2010-07-19 17:07:29,743 INFO com.infotrustgroup.restless.server.ThreadedService:An exception was trapped in com.infotrustgroup.jobs.services.auth.EditionsRulesJobRunner
INFO | 2010/07/19 17:07:29 | jvm 1 | org.drools.runtime.rule.ConsequenceException: java.lang.ClassCastException: org.drools.reteoo.BetaMemory cannot be cast to org.drools.reteoo.EvalConditionNode$EvalMemory
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:943)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:885)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1086)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:660)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:627)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:183)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.rules.engine.RulesManager.runRules(RulesManager.java:363)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.rules.RuleFileUtil.runRules(RuleFileUtil.java:385)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.rules.RuleFileUtil.runRules(RuleFileUtil.java:349)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.rules.RuleRunner.run(RuleRunner.java:395)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.rules.RuleRunner.call(RuleRunner.java:193)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.jobs.services.auth.EditionsRulesJobRunner.runRules(EditionsRulesJobRunner.java:87)
INFO | 2010/07/19 17:07:29 | jvm 1 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
INFO | 2010/07/19 17:07:29 | jvm 1 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
INFO | 2010/07/19 17:07:29 | jvm 1 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
INFO | 2010/07/19 17:07:29 | jvm 1 | at java.lang.reflect.Method.invoke(Method.java:597)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.restless.server.ThreadedService.runServiceMethod(ThreadedService.java:845)
INFO | 2010/07/19 17:07:29 | jvm 1 | Caused by: java.lang.ClassCastException: org.drools.reteoo.BetaMemory cannot be cast to org.drools.reteoo.EvalConditionNode$EvalMemory
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.reteoo.EvalConditionNode.retractLeftTuple(EvalConditionNode.java:199)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.reteoo.ObjectTypeNode.retractObject(ObjectTypeNode.java:239)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.reteoo.EntryPointNode.retractObject(EntryPointNode.java:195)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1416)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1350)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.impl.StatefulKnowledgeSessionImpl.update(StatefulKnowledgeSessionImpl.java:231)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.rules.engine.RulesManager$InnerPropertyChangeListener.propertyChange(RulesManager.java:467)
INFO | 2010/07/19 17:07:29 | jvm 1 | at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.collections.BoundMap.put(BoundMap.java:67)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.what.Rule_Load_ATAXML_Transform_0.consequence(Rule_Load_ATAXML_Transform_0.java:28)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.what.Rule_Load_ATAXML_Transform_0ConsequenceInvoker.evaluate(Rule_Load_ATAXML_Transform_0ConsequenceInvoker.java:28)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:934)
INFO | 2010/07/19 17:07:29 | jvm 1 | ... 16 more
INFO | 2010/07/19 17:07:29 | jvm 1 | org.drools.runtime.rule.ConsequenceException: java.lang.ClassCastException: org.drools.reteoo.BetaMemory cannot be cast to org.drools.reteoo.EvalConditionNode$EvalMemory
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:943)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:885)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1086)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:660)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:627)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:183)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.rules.engine.RulesManager.runRules(RulesManager.java:363)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.rules.RuleFileUtil.runRules(RuleFileUtil.java:385)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.rules.RuleFileUtil.runRules(RuleFileUtil.java:349)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.rules.RuleRunner.run(RuleRunner.java:395)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.rules.RuleRunner.call(RuleRunner.java:193)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.jobs.services.auth.EditionsRulesJobRunner.runRules(EditionsRulesJobRunner.java:87)
INFO | 2010/07/19 17:07:29 | jvm 1 | at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
INFO | 2010/07/19 17:07:29 | jvm 1 | at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
INFO | 2010/07/19 17:07:29 | jvm 1 | at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
INFO | 2010/07/19 17:07:29 | jvm 1 | at java.lang.reflect.Method.invoke(Method.java:597)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.restless.server.ThreadedService.runServiceMethod(ThreadedService.java:845)
INFO | 2010/07/19 17:07:29 | jvm 1 | Caused by: java.lang.ClassCastException: org.drools.reteoo.BetaMemory cannot be cast to org.drools.reteoo.EvalConditionNode$EvalMemory
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.reteoo.EvalConditionNode.retractLeftTuple(EvalConditionNode.java:199)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.reteoo.ObjectTypeNode.retractObject(ObjectTypeNode.java:239)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.reteoo.EntryPointNode.retractObject(EntryPointNode.java:195)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1416)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1350)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.impl.StatefulKnowledgeSessionImpl.update(StatefulKnowledgeSessionImpl.java:231)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.rules.engine.RulesManager$InnerPropertyChangeListener.propertyChange(RulesManager.java:467)
INFO | 2010/07/19 17:07:29 | jvm 1 | at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.collections.BoundMap.put(BoundMap.java:67)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.what.Rule_Load_ATAXML_Transform_0.consequence(Rule_Load_ATAXML_Transform_0.java:28)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.what.Rule_Load_ATAXML_Transform_0ConsequenceInvoker.evaluate(Rule_Load_ATAXML_Transform_0ConsequenceInvoker.java:28)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:934)
INFO | 2010/07/19 17:07:29 | jvm 1 | ... 16 more
INFO | 2010/07/19 17:07:29 | jvm 1 | 2010-07-19 17:07:29,759 FATAL com.infotrustgroup.jobs.services.auth.EditionsRulesJobRunner:Worker service threw an unexpected exception.
INFO | 2010/07/19 17:07:29 | jvm 1 | org.drools.runtime.rule.ConsequenceException: java.lang.ClassCastException: org.drools.reteoo.BetaMemory cannot be cast to org.drools.reteoo.EvalConditionNode$EvalMemory
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:943)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:885)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1086)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:660)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:627)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:183)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.rules.engine.RulesManager.runRules(RulesManager.java:363)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.rules.RuleFileUtil.runRules(RuleFileUtil.java:385)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.rules.RuleFileUtil.runRules(RuleFileUtil.java:349)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.rules.RuleRunner.run(RuleRunner.java:395)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.rules.RuleRunner.call(RuleRunner.java:193)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.jobs.services.auth.EditionsRulesJobRunner.runRules(EditionsRulesJobRunner.java:87)
INFO | 2010/07/19 17:07:29 | jvm 1 | Caused by: java.lang.ClassCastException: org.drools.reteoo.BetaMemory cannot be cast to org.drools.reteoo.EvalConditionNode$EvalMemory
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.reteoo.EvalConditionNode.retractLeftTuple(EvalConditionNode.java:199)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.reteoo.ObjectTypeNode.retractObject(ObjectTypeNode.java:239)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.reteoo.EntryPointNode.retractObject(EntryPointNode.java:195)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1416)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.AbstractWorkingMemory.update(AbstractWorkingMemory.java:1350)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.impl.StatefulKnowledgeSessionImpl.update(StatefulKnowledgeSessionImpl.java:231)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.rules.engine.RulesManager$InnerPropertyChangeListener.propertyChange(RulesManager.java:467)
INFO | 2010/07/19 17:07:29 | jvm 1 | at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.util.collections.BoundMap.put(BoundMap.java:67)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.what.Rule_Load_ATAXML_Transform_0.consequence(Rule_Load_ATAXML_Transform_0.java:28)
INFO | 2010/07/19 17:07:29 | jvm 1 | at com.infotrustgroup.what.Rule_Load_ATAXML_Transform_0ConsequenceInvoker.evaluate(Rule_Load_ATAXML_Transform_0ConsequenceInvoker.java:28)
INFO | 2010/07/19 17:07:29 | jvm 1 | at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:934)
INFO | 2010/07/19 17:07:29 | jvm 1 | ... 11 more
Point of speculation:
When looking at the latest code on trunk I would believe this is not fixed as the line pointed to here has not changed (the place where this line exists has changed but not the code see fisheye at http://fisheye.jboss.org/browse/JBossRules/trunk/drools-core/src/main/jav... and where the lefthand side was 199 for 5.0.1 it is still the same code in the latest svn revision (now line 229).
-- Paul Ryan
15 years, 11 months
Drools 5.1.0CR1
by Juan Ignacio Barisich
Hello everyone.
I'm working on a research about migration from OSWorklow to DroolsFlow.
Among other things, I need spring integration support. As I know, this
feature will be supported in the 5.1.0CR1 version of Drools. Do you know
when this version will be released? On
https://jira.jboss.org/browse/JBRULESthere isn't an expected date for
this version.
Thanks in advance.
Juan Barisich
15 years, 11 months