Checking in one rule the "result" of another rule
by orchid
Hi All,
I have "rule1" and "rule2", very simple rules. I would like in "rule3" to
check one of the following:
"rule1" AND "rule2" (i.e. if both rule1 and rule2 were fired)
"rule1" OR "rule2" (rule1 or rule2 was fired)
How can I achieve this? Does the "extends" keyword might help here?
I achieved that buy defining a list, to which rule1 and rule2 in the RHS
inserted some value. In rule3 I checked the values of that list. I would
like to ask if there are some prettier solutions.
Thanks in advance.
Any help would be appreciated.
--
View this message in context: http://n3.nabble.com/Checking-in-one-rule-the-result-of-another-rule-tp17...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 11 months
Re: [rules-users] newbie, Expressing a rule in different ways
by rouvas@di.uoa.gr
Wolfgang Laun wrote:
> 2010/1/31 <rouvas(a)di.uoa.gr>
>
>> Wolfang,
>>
>> thank you very much for your reply.
>>
>> Your assumptions are correct and your explanation makes sense.
>> Unfortunately, I cannot understand why this happens.
>>
>>
> It may very well be an implementation restriction; whether it can be
> removed easily I'm not prepared to say. (@Edson?)
Fair enough.
>
>
>> The IUEcop has the following structure (in rough terms)
>> IUEcop
>> +- (various objects as properties)
>> +- list of traderAuthorisation
>> +- list of warehouseAuthorisation
>> +- list of temporaryAuthorisation
>>
>>
>> A more general issue with my understanding has to do with handling of
>> deeply nested objects. In my case, the "traderAuthorisation" object has
>> itself another set of object properties and lists that I would like to
>> refer to in my rules. Are you aware of any relevant documentation?
>>
>
> Nested objects that are not facts but shared between fact objects should
> not
> cause any problems; especially the MVEL syntax is provided for easy
> access to properties of a property.
>
> If such an object is shared among several fact objects, you'll have a
> problem whenever such a shared object is updated by code on a RHS:
> To trigger reevaluation of rules, the engine would have to be
> notified about all objects referring to the shared object as being
> updated.
Although in my case the objects are not shared, I understand the issues
involved.
>
> Lists is adding another twist, even though the "from" CE appears
> to simplify handling of Iterable properties and works well enough.
> The recommended (see Drools Expert, section 4.8.2.8, Conditional
> Element "from") alternative is to add List elements as WM elements
> of their own,
I was hoping to avoid this.
This is how I was doing things in Prolog, but I was hoping that
object-orientation would help tackling this issue.
Anyway, thanks a lot for your help.
-Stathis
> even though this may require the addition of linking
> information to the list elements. (In your case: a TraderAuthorisation
> would have to contain a reference to the IUEcop object it belongs
> to.) You'll have to balance the additionally required coding effort
> for this against the greater complexity of rules using "from".
>
> -W
>
>
>> Thank you very much for your time,
>> -Stathis
>>
>>
>
14 years, 11 months
newbie, Expressing a rule in different ways
by rouvas@di.uoa.gr
Can you please explain why the second form of the same (as it seems to me)
rule does not work?
This works:
rule "takeTwo"
when
$c : CD713AType(
Body.incrementalUpdateOfEconomicOperators.traderAuthorisation.size !=
0 )
$t : TraderAuthorisationType ( $t.OperatorRole.size == 0) from
$c.Body.incrementalUpdateOfEconomicOperators.traderAuthorisation
then
stdout(drools.getRule().getName()+"
"+$c.getHeader().getMessageIdentifier());
end
and this fails to compile:
rule "take3"
when
$c : CD713AType( $i : this.Body.incrementalUpdateOfEconomicOperators )
$t : TraderAuthorisationType ( $t.OperatorRole.size !=0 ) from
$i.traderAuthorisation
then
stdout(drools.getRule().getName()+"
"+$c.getHeader().getMessageIdentifier());
end
with the message:
Unable to build expression for 'from' : Failed to compile: 1 compilation
error(s):
- (1,22) unqualified type in strict mode for: traderAuthorisation
'$i.traderAuthorisation' : [Rule name='take3']
Pretty new to Drools and try to figure out how things work.
In the second form of the rule I am trying to use the $i variable as a
shortcut for the "Body.incrementalUpdateOfEconomicOperators" locator.
"stdout" is just a function that print to System.out
Thank you for your time,
-Stathis
14 years, 11 months
Drools and Persistence How much Reliable and Secure
by KiranP
i m a Novice level user of drools and i want to use drools for our firms new
projects
so, i m evaluating the Drools 5.0 and 5.1 versions so that i can rely on
some thing very reliable and secure
i have worked out with the Drools5.1 variable persistence strategy and also
worked out some examples and i think it is also good to work with a
plugabble version of Persistence
So now my problem is what to use My own Persistence Mechanism in Drools5.0
or to use Drools5.1 with its provided plugabble Persistence Mechanism ???
one more thing can somebody tell me which books or online documents to refer
while using drools 5.1 ???
Thanks in advance......
yours always thankfullllll
KiranP
--
View this message in context: http://n3.nabble.com/Drools-and-Persistence-How-much-Reliable-and-Secure-...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 11 months
Are knowledgebases configurable?
by HonorGod
Hi,
I am working on a simple framework that does 4 things in sequence -
1 - Load Rules
2 - Load Data
3 - Apply Rules
4 - Persist Data
The framework allows to perform steps 3 and 4 multiple times that is
configurable via XML. My question - Is there a way that drools provides me
so that I can specify in configuration file that - load rules file 1 into
knowledgeBase 1 and load rules file 2 into knowledgeBase 2 and so on. I need
this because when I apply rules I wanted to specify which knowledge base to
use, configurable via xml again.
I hope my question is clear!
Thank You,
Jagadeesh.
--
View this message in context: http://n3.nabble.com/Are-knowledgebases-configurable-tp135809p135809.html
Sent from the Drools - User mailing list archive at Nabble.com.
14 years, 11 months
Drools Execution Server and NoClassDefFound
by Régis Ramillien
Hello,
I have a problem using execution server. It sends a NoClassDefFoundError.
I search for hours, but find nothing...
Why I have done, in guvnor:
I have created :
-- a package "com.myorg.myapp"
---- a declarative model "Model1"
------ with a fact "Fact1"
-------- with a text field "field1"
-------- with an integer field "field2"
---- a Business Rule "rule1"
------ which test for the "field1" value, and set the "field2" to a dummy
value.
I then created a snapshot called 'release'
I created a myappAgent.properties with the following values:
name=mrgAgent
newInstance=true
url=
http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/package/com....
poll=60
I put the file in drools-server classes directory
I then tried to call execution server using CURL:
curl --data "<knowledgebase-request><
inOutFacts><named-fact><id>Fact1</id><fact
class='com.myorg.myapp.Fact1'><field1>Any
response?</field1></fact></named-fact></inOutFacts></knowledgebase-request>"
http://localhost:8080/drools-server/knowledgebase/myappAgent
And the server (drools-server I assume, not guvnor ?), send me this
response:
...
ling this request.</u></p><p><b>exception</b>
<pre>javax.servlet.ServletException: Servlet execution threw an exception
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
</pre></p><p><b>root cause</b> <pre>java.lang.NoClassDefFoundError:
com/myorg/myapp/Fact1
ASMAccessorImpl_87013581264610722640.getValue(Unknown Source)
org.mvel2.optimizers.dynamic.DynamicGetAccessor.getValue(DynamicGetAccessor.java:66)
org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:99)
org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:107)
org.mvel2.MVEL.executeExpression(MVEL.java:978)
org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:87)
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:934)
org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:885)
org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1086)
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:660)
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:637)
org.drools.reteoo.ReteooStatelessSession.execute(ReteooStatelessSession.java:203)
org.drools.server.KnowledgeStatelessServlet.doService(KnowledgeStatelessServlet.java:152)
org.drools.server.KnowledgeStatelessServlet.doPost(KnowledgeStatelessServlet.java:82)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
What have I done wrong ???
Please ,help me !!!
Regards,
Régis Ramillien
14 years, 11 months
Flow variables not getting updated when fact changes in rule node
by Todd Pagni
I am seeing a problem in the latest stable build 12/27 andn 1/26 where a
flow variable does not get updates from a facts updated in a rule node
in the flow. Both the flow variable and the fact are initially the same
object instance, but It looks like the flow variable gets a cloned
instance after the rule node.
I am inserting 1 fact and running a flow with a debug node, a rule node,
a debug node, and a human task. As you can see below the hashcode
changes for the flow variable after the rule node, but retains the user
value set earlier in the flow. After the rule node the user should be
myuser which is set in the rule, but instead has the value bogus, which
is set in the first debug node.
Is anyone else seeing similar issues in drools flow? This is happening
when we run in JBoss 5.1. This is a blocking issue that makes drools
flow unusable for us, so any help you can provide is appreciated.
Debug:
15:00:31,985 INFO [STDOUT] ******** flowApproval hashcode at fact
insert:18886777
15:00:31,985 INFO [STDOUT] Hibernate: insert into ProcessInstanceInfo
(externalVariables, lastModificationDate, lastReadDate, processId,
processInstanceByteArray, startDate, state, OPTLOCK) values (?, ?, ?, ?,
?, ?, ?, ?)
15:00:31,985 INFO [STDOUT] ******** first flow node, hashcode: 18886777
user: null
15:00:31,985 INFO [STDOUT] ******** first flow node after approver set
to bogus, hashcode: 18886777 user: bogus
15:00:32,000 INFO [STDOUT] Hibernate: update ProcessInstanceInfo set
externalVariables=?, lastModificationDate=?, lastReadDate=?,
processId=?, processInstanceByteArray=?, startDate=?, state=?, OPTLOCK=?
where processInstanceId=? and OPTLOCK=?
15:00:32,000 INFO [STDOUT] Hibernate: insert into
ProcessInstanceInfo_eventTypes (ProcessInstanceInfo_processInstanceId,
element) values (?, ?)
15:00:32,000 INFO [STDOUT] Hibernate: update SessionInfo set dirty=?,
lastModificationDate=?, rulesByteArray=?, startDate=? where id=?
15:00:32,000 INFO [STDOUT] ******** in rule node setting approver to
enduser, hashcode: 18886777 user: myuser
15:00:32,000 INFO [STDOUT] Hibernate: select
processins0_.processInstanceId as col_0_0_ from ProcessInstanceInfo
processins0_ where ? in (select eventtypes1_.element from
ProcessInstanceInfo_eventTypes eventtypes1_ where
processins0_.processInstanceId=eventtypes1_.ProcessInstanceInfo_processI
nstanceId)
15:00:32,000 INFO [STDOUT] Hibernate: select
processins0_.processInstanceId as processI1_149_0_,
processins0_.externalVariables as external2_149_0_,
processins0_.lastModificationDate as lastModi3_149_0_,
processins0_.lastReadDate as lastRead4_149_0_, processins0_.processId as
processId149_0_, processins0_.processInstanceByteArray as
processI6_149_0_, processins0_.startDate as startDate149_0_,
processins0_.state as state149_0_, processins0_.OPTLOCK as OPTLOCK149_0_
from ProcessInstanceInfo processins0_ where
processins0_.processInstanceId=?
15:00:32,016 INFO [STDOUT] ******** after rule node, hashcode:15392910
user: bogus
Rule:
dialect "mvel"
rule "Assign Initial Approver"
ruleflow-group "approver"
no-loop
when
$flow : com.datacert.FlowApproval()
then
modify( $flow ) { setLastapprover( 'myuser' ) };
System.out.println("******** in rule node setting approver
to enduser, hashcode: " + $flow.hashCode() + " user: " +
$flow.getLastapprover());
end
Flow:
<?xml version="1.0" encoding="UTF-8"?>
<definitions id="Definition"
targetNamespace="http://www.jboss.org/drools"
typeLanguage="http://www.java.com/javaTypes"
expressionLanguage="http://www.mvel.org/2.0"
xmlns="http://schema.omg.org/spec/BPMN/2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="http://schema.omg.org/spec/BPMN/2.0
BPMN20.xsd"
xmlns:g="http://www.jboss.org/drools/flow/gpd"
xmlns:tns="http://www.jboss.org/drools">
<itemDefinition id="entityIdItem" structureRef="java.lang.Object" />
<itemDefinition id="entityItem" structureRef="java.lang.Object" />
<itemDefinition id="flowApprovalItem" structureRef="java.lang.Object"
/>
<resource id="Actor" name="Human Actor" />
<process id="com.datacert.workflow.Base" name="approval" >
<!-- process variables -->
<property id="entityId" itemSubjectRef="tns:entityIdItem"/>
<property id="entity" itemSubjectRef="tns:entityItem"/>
<property id="flowApproval" itemSubjectRef="tns:flowApprovalItem"/>
<!-- nodes -->
<endEvent id="_2" name="End" g:x="564" g:y="16" g:width="48"
g:height="48" />
<userTask id="_4" name="Human Task" g:x="432" g:y="16" g:width="100"
g:height="48" >
<ioSpecification>
<dataInput id="_4_CommentInput" name="Comment" />
<dataInput id="_4_TaskNameInput" name="TaskName" />
<dataInput id="_4_ContentInput" name="Content" />
<inputSet>
<dataInputRefs>_4_CommentInput</dataInputRefs>
<dataInputRefs>_4_TaskNameInput</dataInputRefs>
<dataInputRefs>_4_ContentInput</dataInputRefs>
</inputSet>
<outputSet>
</outputSet>
</ioSpecification>
<property id="_4_Comment" />
<property id="_4_TaskName" />
<property id="_4_Content" />
<dataInputAssociation>
<assignment>
<from xs:type="tFormalExpression">workitem</from>
<to xs:type="tFormalExpression">_4_CommentInput</to>
</assignment>
<sourceRef>_4_Comment</sourceRef>
<targetRef>_4_CommentInput</targetRef>
</dataInputAssociation>
<dataInputAssociation>
<assignment>
<from xs:type="tFormalExpression">Human Task</from>
<to xs:type="tFormalExpression">_4_TaskNameInput</to>
</assignment>
<sourceRef>_4_TaskName</sourceRef>
<targetRef>_4_TaskNameInput</targetRef>
</dataInputAssociation>
<dataInputAssociation>
<assignment>
<from xs:type="tFormalExpression">#{entityId}</from>
<to xs:type="tFormalExpression">_4_ContentInput</to>
</assignment>
<sourceRef>_4_Content</sourceRef>
<targetRef>_4_ContentInput</targetRef>
</dataInputAssociation>
<potentialOwner resourceRef="tns:Actor" >
<resourceAssignmentExpression>
<formalExpression>#{flowApproval.getLastapprover()}</formalExpression>
</resourceAssignmentExpression>
</potentialOwner>
</userTask>
<scriptTask id="_6" name="After Rule" g:x="320" g:y="16"
g:width="80" g:height="48" >
<script>System.out.println("******** after rule node, hashcode:" +
flowApproval.hashCode() + " user: " +
flowApproval.getLastapprover());</script>
</scriptTask>
<startEvent id="_1" name="StartProcess" g:x="16" g:y="16"
g:width="48" g:height="48" />
<businessRuleTask id="_3" name="Rule" g:x="208" g:y="16"
g:width="80" g:height="48" g:ruleFlowGroup="approver" />
<scriptTask id="_7" name="Before Rule" g:x="96" g:y="16"
g:width="80" g:height="48" >
<script>System.out.println("******** first flow node, hashcode: "
+ flowApproval.hashCode() + " user: " + flowApproval.getLastapprover());
flowApproval.setLastapprover("bogus");
System.out.println("******** first flow node after approver set to
bogus, hashcode: " + flowApproval.hashCode() + " user: " +
flowApproval.getLastapprover());</script>
</scriptTask>
<!-- connections -->
<sequenceFlow sourceRef="_4" targetRef="_2" />
<sequenceFlow sourceRef="_6" targetRef="_4" />
<sequenceFlow sourceRef="_3" targetRef="_6" />
<sequenceFlow sourceRef="_7" targetRef="_3" />
<sequenceFlow sourceRef="_1" targetRef="_7" />
</process>
</definitions>
Most Code:
package com.datacert;
import groovy.lang.GroovyClassLoader;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.annotation.Resource;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.apache.log4j.Level;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseConfiguration;
import org.drools.KnowledgeBaseFactory;
import org.drools.SessionConfiguration;
import org.drools.SystemEventListenerFactory;
import org.drools.base.MapGlobalResolver;
import org.drools.bpmn2.xml.BPMNSemanticModule;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderConfiguration;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.compiler.PackageBuilderConfiguration;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.persistence.jpa.JPAKnowledgeService;
import org.drools.process.workitem.wsht.CommandBasedWSHumanTaskHandler;
import org.drools.runtime.Environment;
import org.drools.runtime.EnvironmentName;
import org.drools.runtime.KnowledgeSessionConfiguration;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.ProcessInstance;
import org.drools.runtime.process.WorkItemManager;
import org.drools.task.service.MinaTaskServer;
import org.drools.task.service.TaskService;
import com.arjuna.ats.jta.TransactionManager;
public class FlowService {
private static final String FLOW_SERVICE_URL =
"flow.service.url";
private static final String FLOW_SERVICE_LOCATION =
"flow.service.location";
private TaskService taskService;
private MinaTaskServer server;
private EntityManagerFactory taskServerEntityManagerFactory;
public void startWorkflow() {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("entityId", 22);
parameters.put("flowApproval", new FlowApproval());
KnowledgeBase kbase = getKnowledgeBase("approval.bpmn",
"approval.drl");
StatefulKnowledgeSession ksession = getSession(kbase);
KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
registerHumanTaskHandler(ksession);
ksession.insert(parameters.get("flowApproval"));
System.out.println("******** flowApproval hashcode at fact
insert:" + parameters.get("flowApproval").hashCode());
ProcessInstance pi =
ksession.startProcess("com.datacert.workflow.Base", parameters);
ksession.fireAllRules();
}
private ClassLoader getClassLoader() {
GroovyClassLoader gcl = new GroovyClassLoader();
gcl.addClasspath("c:\\temp\\");
return gcl;
}
private Environment getEnvironment() {
Environment env = KnowledgeBaseFactory.newEnvironment();
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("org.drools.persistence.jpa");
env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);
env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());
InitialContext ctx = null;
try {
ctx = new InitialContext();
} catch (NamingException e) {
System.err.println(e);
}
env.set(EnvironmentName.TRANSACTION_MANAGER,
TransactionManager.transactionManager(ctx));
return env;
}
private KnowledgeBase getKnowledgeBase(String xmlFileName, String
ruleFileName) {
KnowledgeBaseConfiguration config =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null,
getClassLoader());
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase(config);
kbase.addKnowledgePackages(getKnowledgeBuilder(xmlFileName,
ruleFileName).getKnowledgePackages());
return kbase;
}
private KnowledgeBuilder getKnowledgeBuilder(String xmlFileName,
String ruleFileName) {
Thread.currentThread().setContextClassLoader(getClassLoader());
System.setProperty("drools.dialect.mvel.strict", "false");
KnowledgeBuilderConfiguration conf =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null,
getClassLoader());
((PackageBuilderConfiguration) conf).initSemanticModules();
((PackageBuilderConfiguration) conf).addSemanticModule(new
BPMNSemanticModule());
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(conf);
kbuilder.add(ResourceFactory.newClassPathResource("approval.bpmn"),
ResourceType.DRF);
kbuilder.add(ResourceFactory.newClassPathResource("approval.drl"),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse
knowledge.");
}
return kbuilder;
}
private StatefulKnowledgeSession getSession(int sessionId,
KnowledgeBase kbase) {
return
JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase,
getSessionConfig(), getEnvironment());
}
private StatefulKnowledgeSession getSession(KnowledgeBase kbase) {
return JPAKnowledgeService.newStatefulKnowledgeSession(kbase,
getSessionConfig(), getEnvironment());
}
private KnowledgeSessionConfiguration getSessionConfig() {
SessionConfiguration c = new SessionConfiguration();
c.setClassLoader(getClassLoader());
return c;
}
private void registerHumanTaskHandler(StatefulKnowledgeSession
ksession) {
CommandBasedWSHumanTaskHandler approveTask = new
CommandBasedWSHumanTaskHandler(ksession);
WorkItemManager wm = ksession.getWorkItemManager();
wm.registerWorkItemHandler("Human Task", approveTask);
}
}
Thanks,
Todd
14 years, 11 months