drools date compare not working as documented
by magaram
hi -
i am using drools-distribution-5.2.0.M2. Here is the drl i am using -
----------
dialect "mvel"
import com.deltadental.drools.sample.*
rule "Rule 01"
when
$underageCustomer : Customer(dob>"15-May-1993")
$order : Order(customerId == $underageCustomer.customerId)
eval($order.discountPercentage == 0)
then
$order.discountPercentage = 25;
System.out.println("Rule 01 fired. Applied discount
"+$order.discountPercentage);
end
------------------
I get a RuntimeDroolsException: Exception executing predicate dob >
"15-May-1993"
Caused by: java.lang.RuntimeException: uncomparable values <<Mon May 01
00:00:00 EDT 2000>> and <<15-May-1993>>
caused by a class cast exception - String cannot be converted to a Date.
I get the same exception with 5.1.1. I tried the same setting Locale and
drools.dateformat properties - no luck so far..
Am I missing something here?
Thanks
Muk
--
View this message in context: http://drools.46999.n3.nabble.com/drools-date-compare-not-working-as-docu...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 10 months
Catch 22 ANTLR DSL matching issue
by jstroup
Hi Droolers,
Regarding this blurb from the 5.2 DSL reference:
"It is important to note that the compiler transforms DSL rule files line by
line. In the above example, all the text after "Something is " to the end of
the line is captured as the replacement value for "{colour}", and this is
used for interpolating the target string. This may not be exactly what you
want. For instance, when you intend to merge different DSL expressions to
generate a composite DRL pattern, you need to transform a DSLR line in
several independent operations. The best way to achieve this is to ensure
that the captures are surrounded by characteristic text - words or even
single characters. As a result, the matching operation done by the parser
plucks out a substring from somewhere within the line. In the example below,
quotes are used as distinctive characters. Note that the characters that
surround the capture are not included during interpolation, just the
contents between them."
Given this DSL (test_expander.dsl)
[when](C|c)heese is "{type}"=Cheese(type=="{type}")
[when](is|hails|comes) from {country}=Cheese(country=="{country}")
[then]Add the message {message}=System.out.println({message});
And this DSLR
package com.sample
import com.sample.DroolsTest.Cheese;
expander test_expander.dsl
rule "rule_1"
when
Cheese is "cheddar" and is from Italy
then
Add the message "Cheddar IS from Italy"
end
rule "rule_2"
when
cheese is cheddar and comes from Italy
then
Add the message "Cheddar COMES from Italy"
end
I know that rule_2 fails because I removed the “distinctive characters” so
ANTLR is confused on what to capture. It just seems so unnatural for a rule
author to have to somehow magically know to add quotes in order to merge
different DSL expressions to generate a composite DRL pattern. The
documentation suggests also surrounding it with distinctive words so I sneak
an “and” into the DSL entry.
[when](C|c)heese is {type} and=Cheese(type=="{type}")
This allows me to write my rules more naturally.
rule "rule_1"
when
Cheese is cheddar and is from Italy
then
Add the message "Cheddar IS from Italy"
end
rule "rule_2"
when
cheese is cheddar and comes from Italy
then
Add the message "Cheddar COMES from Italy"
end
In the first example the “and” in
Cheese is "cheddar" and is from Italy
is actually a logical AND - not a matching character – which is nice because
we can use it to logically connect the 2 expressions or just match the first
DSL expression by itself as in
Cheese is cheddar
And since the second expression is not present we can drop the quotes. (But
how on earth will a rule author know this?). But if we add the “and” as part
of the first DSL expression
1) It is no longer a connecting logical character but is part of the
expression to match (yuk)
2) We can no longer just write “Cheese is cheddar” by itself but are
forced to write “Cheese is cheddar and” if we want to match only the first
expression. You might as well just combined the two expressions into one
since there is no real advantage now to having two expressions!
One nice thing would be for the Guvnor DSL editor to
1)try the capture greedily first,
2)get the annoying “no viable alternative error”,
3)CATCH the error instead of just giving up,
4)capture non-greedily and match only the first word,
5)then search for matching DSL expressions beyond that.
Or something like that. The only time you should have to add quotes is if
the text you are matching actually contains multiple words. Anything else is
counter-intuitive. Please tell me the planned replacement for DSL addresses
this!
Jeff
--
View this message in context: http://drools.46999.n3.nabble.com/Catch-22-ANTLR-DSL-matching-issue-tp299...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 10 months
Rule Flow and Stateless Session
by John Peterson
I'm having some difficulty getting a rule flow with a stateless session to work. Essentially, it is just executing the first task and then stops. I'm using Drools 5.1.1 and I just built the sample Drools by creating a new Drools Project.
My rule flow is simple: Start-RuleGroup1-RuleGroup2-End
I use the 2 rules from example, putting the "Hello World" in RuleGroup1 and "Goodbye" in RuleGroup2.
Here's my code to run it:
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession();
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
// start a new process instance
Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
ArrayList cmds = new ArrayList();
ArrayList dataList = new ArrayList();
dataList.add(message);
cmds.add(CommandFactory.newInsertElements(dataList));
cmds.add(CommandFactory.newStartProcess("com.sample.ruleflow"));
ksession.execute(CommandFactory.newBatchExecution(cmds));
logger.close();
When I run the rules, all I get is "Hello World" (no "Goodbye cruel world"). It does work with a Stateful Session using insert, startProcess, and fireAllRules, but this is a test using the rule flows with CommandFactory functionality, something we need for an application we are developing.
14 years, 10 months
Thread hung while trying to addKnowledgePackages
by nirmal
Hi,
I am trying to do some drools calls on startup of application
server(Websphere) and the server gets hung at a point and shows the
following warnings.
Any pointers or help appreciated.
[5/26/11 17:28:02:977 EDT] 00000020 ThreadMonitor W WSVR0605W: Thread
"SoapConnectorThreadPool : 1" (00000028) has been active for 674145
milliseconds and may be hung. There is/are 1 thread(s) in total in the
server that may be hung.
at java.lang.ClassLoader.defineClassImpl(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:275)
at
org.drools.rule.JavaDialectRuntimeData$PackageClassLoader.fastFindClass(JavaDialectRuntimeData.java:576)
at
org.drools.util.CompositeClassLoader$CachingLoader.load(CompositeClassLoader.java:259)
at
org.drools.util.CompositeClassLoader$CachingLoader.load(CompositeClassLoader.java:242)
at
org.drools.util.CompositeClassLoader.loadClass(CompositeClassLoader.java:89)
at java.lang.ClassLoader.loadClass(ClassLoader.java:619)
at
org.drools.rule.JavaDialectRuntimeData.wire(JavaDialectRuntimeData.java:410)
at
org.drools.rule.JavaDialectRuntimeData.reload(JavaDialectRuntimeData.java:477)
at
org.drools.rule.JavaDialectRuntimeData.onBeforeExecute(JavaDialectRuntimeData.java:237)
at
org.drools.rule.DialectRuntimeRegistry.onBeforeExecute(DialectRuntimeRegistry.java:134)
at
org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:513)
at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:430)
at
org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:143)
Thanks,
Nirmal
--
View this message in context: http://drools.46999.n3.nabble.com/Thread-hung-while-trying-to-addKnowledg...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 10 months
DSL Entry Question
by jstroup
Hi,
The 5.2 docs list the following example DSL entry
[when][][Tt]here is an? {entity:\w+}=${entity!lc}: ${entity!ucfirst} ()
and say the following about what follows the equals sign
"The remaining part of the line after the delimiting equal sign is the
replacement text for any DSLR text matching the regular expression. It may
contain variable references, i.e., a variable name enclosed in braces."
What does the colon following the first variable do? I'm guessing it acts as
an OR? I didn't see any explanation of this and I don't *think* this is
regex.
Also, I'm used to (and actually understand) the following syntax which does
not prefix { with a $.
[when]There is some {cheese} cheese available=Cheese(type=="{cheese}")
My best guess is that the $ denotes a class name that is specified
declaratively in the matching DSLR rule as opposed to a field {cheese} that
is simply a replaceable parameter that matches whatever you type between
"some" and "cheese available" and looks for Cheese objects of that type. So,
given the first DSL entry, if my rule text is
when
there is a cheese
the rule will fire if a Cheese object has been inserted. And, conversely
when
There is an Cheese
will also fire.
Am I on the right track here?
Thanks,
Jeff
--
View this message in context: http://drools.46999.n3.nabble.com/DSL-Entry-Question-tp2993076p2993076.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 10 months
Accessing globals after FireAllRules
by sdinoo
I have a rule flow that has two tasks that insert global value called ndc11
In the ProcessTest.java (using the sample program) I am trying this code
ksession.startProcess("com.drughistory");
ksession.fireAllRules();
NdcMaster myNdc = (NdcMaster)ksession.getGlobal("ndc11");
System.out.println(">>>>>>" + myNdc.getNdc11()); //THIS IS LINE 53
CONSOLE OUTPUT
Inserted drug with ABCDEFGH
Found Global ABCDEFGH
java.lang.NullPointerException
at rules.tester.ProcessTest.main(ProcessTest.java:53)
All I want to do is access the inserted object and use the same - Can
someone please help?
DROOLS FILE
rule "getDrugMaster" ruleflow-group "DUR" dialect "java" salience 100
when
dc: DurClaim( )
then
ndc11 = ClaimsHistoryHelper.getClaimDrugRecord(dc.getProductSvcID());
insert(ndc11);
System.out.println("Inserted drug with " + ndc11.getNdc11());
end
rule "Get History Claims" ruleflow-group "getClaimHistory" dialect "java"
salience 99
when
n: NdcMaster( ndc11 == "ABCDEFGH" )
then
insert(ndc11);
System.out.println("Found Global " + n.getNdc11());
end
--
View this message in context: http://drools.46999.n3.nabble.com/Accessing-globals-after-FireAllRules-tp...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 10 months
[Drools Flow 5.1] persistence + spring + localTransaction
by anton.litvinenko
Hi!
I am quite new to Drools and Drools Flow - please let me know if I am asking
something obvious here :)
I've implemented my custom WorkItemHandlers that are aware of the
KnowledgeSession. Now, I am trying to enable persistence to flows using
drools-persistence-jpa and drools-spring. Ideally, I wanted drools to start
and end transactions, but I wasn't able to achieve that (this is the
problem) and I have start/end transactions manually before
starting/aborting/signaling a process (i.e. running a process is a single
transaction -> if exception happens no state is persisted).
Problem: DroolsSpringTransactionManager has a flag localTransaction which is
set to true whenever a new transaction is started and transaction is
committed only if this flag is set to true. Now, if inside workItemHandler I
invoke a method on knowledgeSession, then my call is being delegated to
SingleSessionCommandService and it tries to start a transaction, but it sees
that there is a transaction already running and sets localTransaction flag
to false -> transaction never gets committed.
Am I doing something wrong here?
Thanks in advance!
Anton
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Flow-5-1-persistence-spring-loca...
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 10 months
Two version of hibernate in the same classpath, how to specify thecorrect version to be used in drools ?
by JAMAL Moundir (EXT)
Hello,
I'm working on a new functionality of an existing project, we will use drools flow to manage our workflow and we want to use persistent and BAM capabilities given by drools.
In all the examples I saw on the internet, only hibernate is used as an implementation of JPA, so I made an example who work very well using hibernate.
The problem is that the existing application already use an old version of hibernate. I can't change it ! So I have two versions of the hibernate in the same classpath which's made several problems.
Maybe I can use another implementation of JPA with drools, but It will be difficult to change the persistence and the BAM from hibernate to another framework !
What I want to do, is to keep hibernate and tell drools to use a specific version of hibernate, I don't know how to do this ? maybe with using the manifest but I don't know if It will work !
Any idea
thanks
*************************************************************************
This message and any attachments (the "message") are confidential, intended solely for the addressee(s), and may contain legally privileged information.
Any unauthorised use or dissemination is prohibited. E-mails are susceptible to alteration.
Neither SOCIETE GENERALE nor any of its subsidiaries or affiliates shall be liable for the message if altered, changed or
falsified.
************
Ce message et toutes les pieces jointes (ci-apres le "message") sont confidentiels et susceptibles de contenir des informations couvertes
par le secret professionnel.
Ce message est etabli a l'intention exclusive de ses destinataires. Toute utilisation ou diffusion non autorisee est interdite.
Tout message electronique est susceptible d'alteration.
La SOCIETE GENERALE et ses filiales declinent toute responsabilite au titre de ce message s'il a ete altere, deforme ou falsifie.
*************************************************************************
14 years, 10 months