Dynamically create drools mvel rules
by Anton Hughes
Hi
I remember seeing this functionality, but after googling - and not finding
anything - I thought I would ask here.
I have a lot of xml files that contain if conditions.
I would like to read these, and convert them to drools mvel rules.
Can someone suggest the best way to do this?
Thanks and regards,
Anton
13 years, 11 months
Drools Guvnor - validate a rule results in "Unable to Analyse Expression"
by FlyingEagle
Hi folks,
I have defined some rules in Eclipse and tested with JUnit tests and
everything was fine.
Now I defined the rules in Guvnor and while validating I get the following
error:
[CardTrapping] Unable to Analyse Expression Fraud fraud = new
Fraud(Fraud.CARD_TRAPPING, new SSTEvent[] { $event1, $event2, $event3,
$event4 }); fraudControl.handleFraud(fraud);: [Error: expected type:
com.wn.fraud.droolstest.model.SSTEvent; but found:
com.wn.fraud.droolstest.model.SSTEvent] [Near : {... SSTEvent[] { $event1,
$event2, $event3, $event4 }) ....}] ^ [Line: 1, Column: 70]
I have imported my data model, before creating the rules, therefor for the
type SSTEvent an import is defined. But it seems, that the type SSTEvent
exists with different versions?
I have this problem for each rule, when I'm using the SSTEvent type in the
"then" case.
Here the complete rule defintion:
package com.wn.fraud.droolstest
import com.wn.fraud.droolstest.model.Fraud;
import com.wn.fraud.droolstest.model.FraudControl;
import com.wn.fraud.droolstest.model.SSTEvent;
global FraudControl fraudControl;
rule "CardTrapping"
when
$event1 : SSTEvent ( eventNumber == SSTEvent.CARD_JAMMED ) from
entry-point "device-event-stream"
$event2 : SSTEvent ( this after [ 0s, 30s ] $event1,
eventNumber == SSTEvent.IN_SERVICE,
deviceId == $event1.deviceId,
branchName == $event1.branchName ) from entry-point
"device-event-stream"
$event3 : SSTEvent ( this after [ 0s, 30s ] $event2,
eventNumber == SSTEvent.CARD_JAMMED,
deviceId == $event1.deviceId,
branchName == $event1.branchName ) from entry-point
"device-event-stream"
$event4 : SSTEvent ( this after [ 0s, 30s ] $event3,
eventNumber == SSTEvent.IN_SERVICE,
deviceId == $event1.deviceId,
branchName == $event1.branchName ) from entry-point
"device-event-stream"
then
// inform fraud control
Fraud fraud = new Fraud(Fraud.CARD_TRAPPING, new SSTEvent[] {
$event1, $event2, $event3, $event4 });
fraudControl.handleFraud(fraud);
end
Thx a lot for help!
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Guvnor-validate-a-rule-results-i...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 11 months
Re: [rules-users] Using GUVNOR for FUSION RULES
by Pellecchia Carolina
Hi Mike,
I’m a colleague of Matteo Cusmai, we would like to thank you for your suggestions. you have been very helpful.
Following your steps, I couldn't understand a point: how can I bind a field(for ex. RadiationObservation.location) to a variable?
specifically,
$obs : RadiationObservation(?$obsLocation : location? ) over window:length (1) from entry-point "lowLevelSensorStream"
Best regards,
Carolina Pellecchia
________________________________________
Da: rules-users-bounces(a)lists.jboss.org [rules-users-bounces(a)lists.jboss.org] per conto di rules-users-request(a)lists.jboss.org [rules-users-request(a)lists.jboss.org]
Inviato: giovedì 26 aprile 2012 19.07
A: rules-users(a)lists.jboss.org
Oggetto: rules-users Digest, Vol 65, Issue 93
Send rules-users mailing list submissions to
rules-users(a)lists.jboss.org
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.jboss.org/mailman/listinfo/rules-users
or, via email, send a message with subject or body 'help' to
rules-users-request(a)lists.jboss.org
You can reach the person managing the list at
rules-users-owner(a)lists.jboss.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of rules-users digest..."
Today's Topics:
1. Re: Setting variables in a stateless session (Welsh, Armand)
2. Re: Using GUVNOR for FUSION RULES (Michael Anstis)
3. Re: Guvnor guided editor and non argument constructor
(Michael Anstis)
4. looking for advice (Bobby Richards)
5. Re: Guvnor guided editor and non argument constructor
(Vincent LEGENDRE)
6. Re: Guvnor guided editor and non argument constructor (Sean Su)
----------------------------------------------------------------------
Message: 1
Date: Thu, 26 Apr 2012 15:57:11 +0000
From: "Welsh, Armand" <AWelsh(a)StateStreet.com>
Subject: Re: [rules-users] Setting variables in a stateless session
To: "rules-users(a)lists.jboss.org" <rules-users(a)lists.jboss.org>
Message-ID:
<D52DE19B4C463C4BA21F81790B9F079543084863(a)GDCPW3376.corp.statestr.com>
Content-Type: text/plain; charset="us-ascii"
Think of a stateless knowledge session as being a statefull knowledge session, with the following adjustments:
A stateless knowledge session cannot be manipulated prior the start of the session.
A stateless knowledge session cannot be manipulated or queried after the end of the session.
A stateless session begins when you execute the fireallrules method.
A stateless session ends when the rule processing terminates. -- There is no pause, there is no restarting. The instant the rules stop firing, and return to your calling code, the knowledge session has been torn down.
-----Original Message-----
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of bardelman
Sent: Thursday, April 26, 2012 2:06 AM
To: rules-users(a)lists.jboss.org
Subject: [rules-users] Setting variables in a stateless session
hi folks, this is a simple question ,
i just want to understand how is it possible that a stateless session have a
setGlobal() method as it does not maintain a state. What's the point ?!
i also have some confusion between a "request scope" and a "stateless
session scope" i think it s the same..
--
View this message in context: http://drools.46999.n3.nabble.com/Setting-variables-in-a-stateless-sessio...
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
------------------------------
Message: 2
Date: Thu, 26 Apr 2012 15:52:09 +0100
From: Michael Anstis <michael.anstis(a)gmail.com>
Subject: Re: [rules-users] Using GUVNOR for FUSION RULES
To: Rules Users List <rules-users(a)lists.jboss.org>
Message-ID:
<CAAG9P0tN=HqTJ9hkJHDiQGBk=_10o4f810-bQBhbTFwUtO-fEQ(a)mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Sure.
- Create "New Rule"
- Add a condition (green + near "WHEN")
- Select "From Entry Point"
- Type "lowLevelSensorStream" into TextBox
- Click on "click to add patterns..."
- Select your Fact Type (see * below)
- In "Over sliding window" ListBox select "Length"
- Type "1" into the TextBox next to "Length".
* OK, so this is possibly where you're having problems.
In order for a Fact Type to be used with CEP it needs to be annotated as an
Event. This is how this can be accomplished:-
*If you have a Declarative Model
*
- Open the Declarative Model
- Select the Fact Type that should be an Event
- Add an Annotation, name="role", key="value", value="event"
- Save
*If you have a POJO Model*
- Create a new Declarative Model
- Add a Fact Type that matches the name of that in your JAR
- Add an Annotation, name="role", key="value", value="event"
- Save
Annotating your POJO is covered in the Drools Expert User Guide. You are
just using Guvnor to achieve what is required.
With kind regards,
Mike
On 26 April 2012 15:22, Matteo Cusmai <cusmaimatteo(a)gmail.com> wrote:
> Hi Mike,
> thanks for suggestion, but i have already read documentation.
>
> First of all, i cannot define "over window:length(1) from entry-point
> lowLevelSensorStream".
> Do you help me to do this?
>
> Best Regards,
> Matteo.
>
>
>
> On Thu, Apr 26, 2012 at 11:32 AM, Michael Anstis <michael.anstis(a)gmail.com
> > wrote:
>
>> Yes this is possible with Guvnor 5.2 onwards.
>>
>> The user-guide explains how to use the Guided Rule Editor (but not
>> specifically CEP features).
>>
>> Read that and give it a try - it's reasonably intuitive (not an excuse
>> for poor documentation though) and come back here with questions.
>>
>> With kind regards,
>>
>> Mike
>>
>> On 26 April 2012 09:08, Matteo Cusmai <cusmaimatteo(a)gmail.com> wrote:
>>
>>> Hi all,
>>> i am novice on GUVNOR, but i would like to define my fusion rules by
>>> graphical tool.
>>>
>>> An example of my rules is:
>>>
>>> rule "radiation-event"
>>> salience 10
>>> no-loop
>>> when
>>> $obs : RadiationObservation( $obsLocation : location, value >
>>> 10 ) over window:length(1) from entry-point lowLevelSensorStream
>>> not RadiationEvent( this meets[ 25s ] $obs, location
>>> geoIsWithinDistance[ 5m ] $obsLocation )
>>> then
>>> insert(new RadiationEvent( $obs, "Radiation over 10",
>>> Event.THREAT_HIGH, $obsLocation, $obs.getSensor() ));
>>> end
>>>
>>> rule "radiation-update"
>>> salience 5
>>> no-loop
>>> when
>>> $obs : RadiationObservation( $obsLocation : location, value >
>>> 10 ) over window:length(1) from entry-point lowLevelSensorStream
>>> $event : RadiationEvent( this meets[ 25s ] $obs, location
>>> geoIsWithinDistance[ 5m ] $obsLocation )
>>> then
>>> Event e = Event.clone($event);
>>> e.addObservation($obs);
>>> insert( e );
>>> retract($event);
>>> retract($obs);
>>> end
>>>
>>> Is it possibile to define rules such the above using GUVNOR?
>>> Are there some documentation or tutorial?
>>>
>>> Thanks a lot in advance,
>>> Matteo Cusmai.
>>>
>>> _______________________________________________
>>> rules-users mailing list
>>> rules-users(a)lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users(a)lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
13 years, 11 months
Guvnor and Joda time
by Sean Su
Do we support Joda time objects in Guvnor (5.3)? I did add joda time jar on
the classpath (Guvnor's lib folder) and there is no class not found
exception. However I get following exception when trying to access the
deployment snapshot.
The snapshot worked fine when I was using Date. After switching to Joda
time, I did reload the POJO model and regenerated the deployment snapshot.
I am using 5.3.final.
java.lang.NullPointerException
at java.io.OutputStream.write(OutputStream.java:58)
at
org.drools.guvnor.server.files.FileManagerUtils.loadBinaryPackage(FileManagerUtils.java:196)
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.jboss.seam.util.Reflections.invoke(Reflections.java:22)
at
org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
at
org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.security.SecurityInterceptor.aroundInvoke(SecurityInterceptor.java:163)
at
org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at
org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
at
org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
at
org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
at
org.drools.guvnor.server.files.FileManagerUtils_$$_javassist_seam_10.loadBinaryPackage(FileManagerUtils_$$_javassist_seam_10.java)
at
org.drools.guvnor.server.files.PackageDeploymentServlet$1.execute(PackageDeploymentServlet.java:252)
at
org.drools.guvnor.server.files.RepositoryServlet.doAuthorizedAction(RepositoryServlet.java:75)
at
org.drools.guvnor.server.files.PackageDeploymentServlet.doGet(PackageDeploymentServlet.java:130)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:625)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.seam.web.ContextFilter$1.process(ContextFilter.java:42)
at
org.jboss.seam.servlet.ContextualHttpServletRequest.run(ContextualHttpServletRequest.java:65)
at org.jboss.seam.web.ContextFilter.doFilter(ContextFilter.java:37)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
--
"But beware of the Dark Side. Anger, fear, aggression - the Dark Side of
the Force are they." -Yoda
13 years, 11 months
Redundancy check option not working in Drools Verifier 5.4
by worldofprasanna
Hi All,
I tried to use Drools Verifier to validate the available rules. I got all
the warning types like MISSING_EQUALITY, ALWAYS_FALSE. But I couldn t get
the redundancy warning, eventhough i have given the duplicate rules
explicitly.
I am using Drools Verifier 5.4.0.Final.
Herewith given the following details,
1. Sample rule file
rule "rule 1"
when
$server : Server(processors==2, memory==1024)
then
System.out.println("rule 1")
end
rule "rule 2"
when
$server : Server(processors==2, processors!=2)
then
System.out.println("rule")
end
rule "rule 3"
when
$server : Server(processors==2, memory==1024)
then
System.out.println("rule 3")
end
2. Code which verifies the validity of the rule.
VerifierBuilder vBuilder = VerifierBuilderFactory.newVerifierBuilder();
Verifier verifier = vBuilder.newVerifier();
verifier.addResourcesToVerify(new
ClassPathResource("sample.drl",
DroolsVerifierCheck.class),
ResourceType.DRL);
verifier.fireAnalysis();
VerifierReport result = verifier.getResult();
// To display the warnings in verifier.
Collection<VerifierMessageBase> warningMessages =
result.getBySeverity(Severity.WARNING);
for (VerifierMessageBase msg : warningMessages) {
System.out.println("Note: " + msg.getMessage() +
" type: " + msg.getMessageType() +
" on: " + msg.getFaulty());
}
Problem
In the sample rule, you can find rule 1 and rule 3 are same. But I didn t
get the warning for redundancy.
Research done
When i debug the code, i found like the rule "Find redundant pattern
possibilities from rule possibilities" and "Find redundant restrictions from
pattern possibilities" are loaded into the Knowledge base created and tagged
with Agenda group as Main, but those are not present in the Knowledge
session created (I mean after inserting the objects into the Knowledge
session in the code : VerifierImpl.java).
Also can anybody explain when a rule will be present in the knowledge base
but not selected by the agenda. I haven t modified anything in the
AgendaFilter and its given the default value ScopeAgendaFilter.
Kindly let me know why the redundancy warning is not given in my case ?
P.S : I have gone through the post below,
http://http://drools.46999.n3.nabble.com/Drools-verifier-td2681002.html
http://drools.46999.n3.nabble.com/Drools-verifier-td2681002.html
and at the bottom they have asked the same question, but there is no answer
available for it.
Thanks,
Prasanna.
--
View this message in context: http://drools.46999.n3.nabble.com/Redundancy-check-option-not-working-in-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 11 months
Guvnor guided editor and non argument constructor
by Sean Su
It seems that the new fact created by the guided editor must be from
the java class that has the default non argument constructor in
Guvnor. There seems no way we can customize it to pass arguments in.
This would force us to provide setters to the object.
Is this a true statement?
Thanks
Sean
Sent from my iPad
13 years, 11 months
looking for advice
by Bobby Richards
I have not yet determined how I want to implement my problem and was hoping
to get some feedback.
I am using drools to migrate the logic from my automated currency trading
infrastructure. Each currency pair, i.e. eurusd has around
200 attributes associated with it.
This includes range values (high, low, average) for multiple time periods,
volatility information, bid/ask updates etc.
Currently I have classes associated for each, so say for range:
class Range {
double high;
double low;
double avg;
}
Range europe = new Range(); //european trading hours
Range us = new Range(); //us trading hours
Questions:
1. I am wondering if I should not just create a map that lists every
attribute per pair as a key ("eurusd:range:europe:high")? So essentially
my drools session will have one fact, not counting the incoming quotes. I
see on the list that this was a problem before the mvel updates but that
was a while ago.
2. When an incoming quote might modify a value, what is the performance
difference between using a rule to change the value or making the changes
outside of the ksession and referencing the facthandler to modify? Is one
method considered 'cleaner'?
Thanks,
Bobby
13 years, 11 months
Using GUVNOR for FUSION RULES
by Matteo Cusmai
Hi all,
i am novice on GUVNOR, but i would like to define my fusion rules by
graphical tool.
An example of my rules is:
rule "radiation-event"
salience 10
no-loop
when
$obs : RadiationObservation( $obsLocation : location, value > 10
) over window:length(1) from entry-point lowLevelSensorStream
not RadiationEvent( this meets[ 25s ] $obs, location
geoIsWithinDistance[ 5m ] $obsLocation )
then
insert(new RadiationEvent( $obs, "Radiation over 10",
Event.THREAT_HIGH, $obsLocation, $obs.getSensor() ));
end
rule "radiation-update"
salience 5
no-loop
when
$obs : RadiationObservation( $obsLocation : location, value > 10
) over window:length(1) from entry-point lowLevelSensorStream
$event : RadiationEvent( this meets[ 25s ] $obs, location
geoIsWithinDistance[ 5m ] $obsLocation )
then
Event e = Event.clone($event);
e.addObservation($obs);
insert( e );
retract($event);
retract($obs);
end
Is it possibile to define rules such the above using GUVNOR?
Are there some documentation or tutorial?
Thanks a lot in advance,
Matteo Cusmai.
13 years, 11 months