Building a rule base from the content of a directory
by Bruno Freudensprung
Hello,
Sorry for the duplicate post, the previous one got inserted into another
thread (also sorry for that). So here it is... in its own thread :-).
I plan to use the Drools Eclipse plugin in order to create rules with
both the "Guided rule" editor and the "Rule resource" editor, and I
would like to write a rather "generic" piece of code (using a
KnowledgeBuilder) in order to setup a KnowledgeBase from the rule files
contained in a directory.
Would you say that am I completly re-inventing something that already
exists? If not, is there is a convention related to building a rule base
from a directory containing a mix of Drools files (drools.package, BRL,
DRL...) created with the Drools Eclipse plugin?
My first experiments showed that, in a directory containing only a BRL
file and its associated "drools.package" file:
* If I add both the "drools.package" file (as a DRL resource), then
the BRL file (as a BRL resource) into the KnowledgeBuilder, I get
a compilation error telling "Unable to resolve ObjectType 'Document'"
* If I concatenate the content of the "drools.package" file and the
result of the "BRL 2 DRL" conversion into a single DRL file, then
add that unique DRL file (as a DRL resource) into the
KnowledgeBuilder, everything is fine.
Does any of you have an idea where I am mistaken?
Many thanks in advance,
Best regards,
Bruno.
14 years
BuildError: Unable to resolve ObjectType
by BS
Hi all,
I'm quite new to Drools and have a problem with the guided editor of the
Eclipse plugin. I'm using Drools 5.0.1.
These are the two BuildErrors for "TestGuided.brl" in Eclipse:
1) BuildError: Unable to build expression for 'consequence': Failed to
compile: 1 compilation error(s): - (1,1) unqualified type in strict mode
for: p ' update( p );
2) BuildError: Unable to resolve ObjectType 'Produkt'
In "drools.package" I have all necessary imports and also the package
statement. This is the BRL source of "TestGuided.brl":
<rule>
<name>TestGuided</name>
<modelVersion>1.0</modelVersion>
<attributes/>
<metadataList/>
<lhs>
<fact>
<factType>Produkt</factType>
<boundName>p</boundName>
</fact>
</lhs>
<rhs>
<modify>
<fieldValues/>
<variable>p</variable>
</modify>
</rhs>
</rule>
When I use the generated DRL output of the guided editor in a DRL file, I do
not get any error message. The DRL file looks like this and compiles
perfectly in Eclipse:
package com.test
rule "TestGuided"
dialect "mvel"
when
p : Produkt( )
then
update( p );
end
Adding the BRL from above to Guvnor does not throw any error. The BRL
validates and compiles perfectly in Guvnor.
So, why is it only in the guided editor of Eclipse not working but in the
guided editor of Guvnor as well as DRL file? Maybe something in my
configuration is errorneous?
Any help is appreciated, many thanks
Bernd
--
View this message in context: http://n3.nabble.com/BuildError-Unable-to-resolve-ObjectType-tp702633p702...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years
Problems modifying objects in flow
by raic
Hi,
I'm using Drools commands API
(http://downloads.jboss.com/drools/docs/5.1.1.34858.FINAL/drools-integrati...)
for interacting via REST to my Drools server for executing flows.
I want to execute a simple flow with some human tasks. In this flow, I'm
passing a client object which will be modified inside the flow in script
nodes (client.setParameter("parameterChanged");)
The code i'm using for executing this flow is below:
Command insertObjectCommand = CommandFactory.newInsert(client,
"client", true, null);
Map<String, Object> params = new HashMap<String, Object>();
params.put("client", client);
WorkItemHandler htHandler = new WSHumanTaskHandler();
List<Command> cmds = new ArrayList<Command>();
RegisterWorkItemHandlerCommand workItemHandlerCommand = new
RegisterWorkItemHandlerCommand(
"Human Task", htHandler);
StartProcessCommand startProcessCommand = new StartProcessCommand();
cmds.add(insertObjectCommand);
startProcessCommand.setProcessId("harrods.HumanFlow");
startProcessCommand.setParameters(params);
cmds.add(workItemHandlerCommand);
cmds.add(startProcessCommand);
result = execute(cmds); //Execute is a function which takes care of
marshalling commands and sending them to the execution server.
This starts the process correctly, i can complete the user tasks correctly
(i see in traces that the object is modifyed), but the problem is that i
can't retrieve the modified object from my application.
I try to do this from my application:
FactHandle fact = (FactHandle) result.getFactHandle("client");
cmds.clear();
GetObjectCommand getObjectCommand = new GetObjectCommand(fact);
getObjectCommand.setOutIdentifier("client");
cmds.add(getObjectCommand);
result = execute(cmds);
But i'm obtaining the same object i sent to the flow (without the flow
modifications).
So, the question is, how can i modify objects inside my flow and retrieve
them in my application using drools commands api?? is it possible? i'm doing
something wrong?
I have the same example without execution server using normal API, and it
works fine...
Some ideas?
Thanks
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Problems-modifying-ob...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years
Drools and Java EE
by ljnelson
Hello; I've made a JCA resource adapter for Drools.
I've had to hack quite a bit to get it so that the KnowledgeAgent- and
resource-scanning-related parts don't use Threads, but, instead, use the
JCA-supplied WorkManager and BootstrapContext#createTimer() for asynchronous
operations (like resource scanning and notifying).
Here are some changes it would sure be nice to see, that I needed to hack
around in order to make it so that a KnowledgeAgent-produced KnowledgeBase
could be shared by Java EE components in a specification compliant manner:
1. ResourceChangeNotifierImpl#ProcessChangetSet is an inner class that is
marked as public static, but which has a package-protected constructor. I
have to create a new instance of this in order to create a
ResourceChangeNotifierImpl subclass that doesn't use threads. I hope this
constructor could be made public instead. Right now I'm calling
setAccessible(true). Yecch.
2. ResourceFactory#setFactoryService(): sure do wish this were public, or
that there were another way to install a ResourceFactoryService. I need to
do this so that the scanner and notifier are under my control (and don't use
Threads, but instead use Timers as provided by the JCA BootstrapContext
class). It appears that I do have some control here in Drools 5.1 with the
(undocumented) ServiceRegistry interface (how do I get an instance of it?
what does it do? is it used pervasively?), but I don't know, since it's
undocumented, whether it's the preferred way to do this sort of thing or
not.
3. All this indirection is really quite clunky, especially given the
META-INF/services facility. Was there a good reason this was not used? I'm
sure there was something, because having to consult a factory for a service
to get a provider to produce an instance of something is a bit much.
Hacking around those limitations, I was able to produce a Drools resource
adapter that vends KnowledgeBase instances as its user connection factories.
This means to use it in a spec-compliant manner, you do this in your
stateless (or stateful) session bean:
@Resource
private KnowledgeBase kb;
...and you get injected a wrapper KnowledgeBase that uses the Java EE
container's JCA machinery to invoke operations on the shared KnowledgeBase.
Is this something that would be interesting to other people? If so I am
happy to open source it.
Thanks for a great toolkit.
Best,
Laird
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Drools-and-Java-EE-tp...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years
Object not seen in working memory i.e not evaluated by rules
by drooRam
Hi
I tried to do a simple test case using spring drools. Following is the
test class, it inserts customer object into the workflow.rf and fire the
rules 1. nameShouldBeEntered & 2. emailShouldBeValid
I have also attached drl, rf and applicationContext.xml files in this mail.
nameShouldBeEntered Rule is fired since its just evaluating to true by
default. But emailShouldBeValid rule has not been evaluated if i debug
through test case since customer object has not seen in working memory I
believe.
I added customer variable in RF, also inserted using kession.insert, also
passing using paramenter's map in startProcess()...nothing helps... i think
its due to some class loader issue or i might be doing some thing wrong in
the code...but it looks pretty straight forward and i analyzed the code
thoroughly ..could anyone tell me what i am missing in this code? Thanks
==============================================================
package edu.rascalworkflow.test;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.process.ProcessInstance;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import edu.rascalworkflow.model.Account;
import edu.rascalworkflow.model.Customer;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContextTest.xml"})
public final class LoanRequestTest {
private static final String PROCESS_LOAN_APPROVAL = "loanApproval";
@Autowired
private StatefulKnowledgeSession ksession;
Customer customer;
ProcessInstance processInstance;
@Test
public void testRequestLoan() throws Exception{
customer = new Customer();
customer.setFirstName(null);
customer.setLastName("Green");
customer.setEmail(null);
customer.setUuid(UUID.randomUUID().toString());
Account account = new Account();
account.setAccountNumber(123456789l);
customer.addAccount(account);
account.setOwner(customer);
startProcess();
//System.out.println("customer name:" +
loanAppHolder.getCustomer().getFirstName());
}
private void startProcess() {
Map<String, Object> parameterMap = new HashMap<String, Object>();
parameterMap.put("customer", customer);
try{
processInstance = ksession.startProcess(PROCESS_LOAN_APPROVAL,
parameterMap);
ksession.insert(customer);
ksession.insert(processInstance);
ksession.fireAllRules();
}catch(Exception e){
e.printStackTrace();
}
}
}
====================================================
package edu.rascalworkflow.loan
import edu.rascalworkflow.model.*
import edu.rascalworkflow.service.*
import edu.rascalworkflow.helper.*
import org.drools.runtime.process.ProcessInstance
global ValidationReport validationReport
import function
edu.rascalworkflow.helper.ValidationHelper.error;
rule nameShouldBeEntered
ruleflow-group "validateLoan"
when
eval(true)
then
//c.setFirstName("ERROR");
System.out.println("inside firstname rule THEN ***");
end
rule emailShouldBeValid
ruleflow-group "validateLoan"
when
c : Customer()
then
c.setEmail("ERROR");
System.out.println("inside email rule THEN ***");
end
====================================================================
http://drools-java-rules-engine.46999.n3.nabble.com/file/n1912489/applica...
applicationContextTest.xml
http://drools-java-rules-engine.46999.n3.nabble.com/file/n1912489/applica...
applicationContextTest.xml
http://drools-java-rules-engine.46999.n3.nabble.com/file/n1912489/Custome...
Customer.java
http://drools-java-rules-engine.46999.n3.nabble.com/file/n1912489/Account...
Account.java
http://drools-java-rules-engine.46999.n3.nabble.com/file/n1912489/loanApp...
loanApproval.rf
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Object-not-seen-in-wo...
Sent from the Drools - User mailing list archive at Nabble.com.
14 years
Rules-Flow question
by Carlos De Matos
I am confused as to how to fire off a rules flow (DRL) file.
In a stateless session, how many individual rules-flows are valid, how do we
choose which one to fire or do they all fire?
In a state-full session, I imagine any number of rules-flows would be valid.
Is this correct? How do I choose to fire one rules flow, and what happens
when I execute a fireAllRules? Do all rules-flow also fire, or none of them?
--
Carlos M. De Matos
cmdematos.com
14 years
Drools 5.1 and JMX
by Agarwal, Beena
I've enabled JMX using the following configuration
KnowledgeBaseConfiguration kbaseConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbaseConf.setOption(MBeansOption.ENABLED);
commonKB = KnowledgeBaseFactory.newKnowledgeBase("kb-"+gameCode, kbaseConf);
commonKB.addKnowledgePackages(kbuilder.getKnowledgePackages());
I see the Mbeans in jconsole. However, don't have any session information. I tried using both stateless and stateful sessions.
>From looking at the source code stateful sessions are automatically registered.
I'm looking for sessions stats for rules such as totalActivationsCreated, totalActivationsFired, etc.
Is there something I need to do to enable that?
Any help would be greatly appreciated
Beena
14 years
Rules Flow Eclipse editor
by Prafull Kumar
Hi All,
I would like to know how we can modify the Rules flow eclipse editor look and
feel and functionality. e.g. If we have a Embedded Sub-Process in the flow and
reduce the size of it, the arrows are still displayed in the main canvas. Please
see the attached snapshot for reference.
How we can fix it? also if we want to open the Embedded Sub-Process in a new
window for easy maintainability/readability of the very complex processes, how
we can achieve it?
Going forward we are also looking to create the custom editor for the nodes.
Please guide us if its possible and there is any document for this.
Note: It seems that I can not attach files in the mailing list. Let me know if
its possible to share the image.
Regards, Prafull
14 years