access to in working memory generated objects
by thomas kukofka
Hi,
I want to use rules which shall generate as a consequence a new java object.
The GUI of my application shall display the new generated objekt.
but how can the GUI of my application get informed by the rule engine that
it has generated a new object (Warning)? And how the GUI or any other java
component can access this new generated object from outside?
rule "Value below threshold"
when
FactX ( property < threshold)
then
insert(new Warning( "Under threshold" ) );
end
rule "Value above threshold"
when
FactX ( property >= threshold)
then
insert(new Warning("Threshold exceeded" ) );
end
regards
Thomas
16 years, 6 months
Running Drools 4 examples
by Ron Kneusel
Greetings!
I am attempting to run the HelloWorld example for Drools 4. I have Eclipse 3.3 setup on Windows with the Drools plugin. I have created a project with the Drools examples and added all the Drools .jar files to the project. Everything compiles. When I initially ran HelloWorldExample.java it appeared that it could not find the HelloWorld.drl file. So, I moved that file into the same directory as HelloWorldExample.java and ran again. This time I am getting an error that the JDT compiler is not found even though it appears that there are JDT jar files in the Eclipse plugins.
I also attempted to run this example under Linux from the command line. In this case I placed all the Drools .jar files into the JRE ext folder and changed the source code to use the Janino compiler by adding:
// Set up for the Janino compiler, not Eclipse
System.setProperty("drools.dialect.java.compiler", "JANINO");
PackageBuilderConfiguration cfg = new PackageBuilderConfiguration();
JavaDialectConfiguration javaConf = (JavaDialectConfiguration)cfg.getDialectConfiguration("java");
This version compiles with javac and runs with java -cp . HelloWorldExample but gives me an error within the compiler while compiling the .drl file:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1938)
at org.drools.base.ClassTypeResolver.importClass(ClassTypeResolver.java:242)
at org.drools.base.ClassTypeResolver.resolveType(ClassTypeResolver.java:158)
at org.drools.rule.builder.dialect.mvel.MVELDialect.addImport(MVELDialect.java:257)
at org.drools.compiler.DialectRegistry.addImport(DialectRegistry.java:98)
at org.drools.compiler.PackageBuilder.mergePackage(PackageBuilder.java:377)
at org.drools.compiler.PackageBuilder.newPackage(PackageBuilder.java:350)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:267)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:167)
at HelloWorldExample.main(HelloWorldExample.java:39)
It is dying on this line:
builder.addPackageFromDrl( source );
My version of HelloWorldExample.java the same as the given example except for the addition of the lines above for Janino. My ultimate goal is to run this all under Linux, I am not an Eclipse user.
Any help getting this working would be greatly appreciated!
Ron
_________________________________________________________________
Introducing Live Search cashback . It's search that pays you back!
http://search.live.com/cashback/?&pkw=form=MIJAAF/publ=HMTGL/crea=introsr...
16 years, 6 months
Different working memories/rulebases for different application issues?
by thomaskukofka@web.de
Hi,
I'm quite a beginner with Drools and I want to integrate Drools in our
application. The application could use rules for different smaller
issues which use partly different facts as input. My question is if I
should use different rulebases or working memories for each issue or is
on rulesbase contiaining all rules which then refers to different fact
tyes and one session is enough? does it make sense to bundle the rules
for each issue in an own agenda group?
Regards
Thomas
16 years, 6 months
how to find which condition evaluated to TRUE?
by Marina
Hello,
If I have a complex rule with a few conditions concatenated via AND and OR and NOT, and the rule evaluated to true during the engine run - is there a way to figure out which of the conditions caused the rule to evaluate to true?
In a simple example:
rule "test1"
dialect "java"
when
$data : ContractRulesData (region=='NE' && sum > 250)
then
approverList.add("approver1, approver2, Level1");
System.out.println("test1 is TRUE; result: approver1, approver2, Level1");
end
I tried to add an AgendaListener with the following code to find out which rules have fired:
public void afterActivationFired(AfterActivationFiredEvent event, WorkingMemory workingMemory) {
Activation activation = event.getActivation();
Rule rule = activation.getRule();
GroupElement[] leftElements = rule.getTransformedLhs();
System.out.println("afterActivationFired: rule = " + rule.getName());
System.out.println("Conditions: ");
for (GroupElement left_el: leftElements){
System.out.println(left_el.toString());
}
The output is somewhat cryptic :
afterActivationFired: rule = test1
Conditions:
AND[Pattern type='[ClassObjectType class=com.emptoris.ecm.domain.ContractRulesData]', index='0', offset='0', identifer='[Declaration: type=ValueType = 'Object' identifier=$data]']
So, is there a way to get even more information about the conditions and whether they evaluated to TRUE or FALSE?
Thanks,
Marina
16 years, 6 months
Changing DSL in BRMS
by Richard Ambridge
Hi,
I have a DSL defined in BRMS
that says for example..
[when]The cat sat on the mat=Object(moose)
and then loads of rules defined that are using that DSL..
Now the business wants to change the words so that the DSL reads
[when]The dog sat on the mat=Object(moose)
That is easy to do, as I just edit the DSL..
but none of the rules change... and there are lots of them... now all
the rules fail validation
How can I search and replace the DSL in the rules?
Cheers
Ric
16 years, 6 months
"not in" error
by Mike D
Just wondering if anyone else has come across this:
I have a rule that has a variable with the same name as the element and when
used in a "not in", the rule does not fire properly.
rule "0620 Fail Invalid SPI Primary"
when
exists ValidationControl(validationNo == 620)
CiLines($ciNo : ciNo, $ciLineNo : ciLineNo, $countryOrigin :
countryOrigin)
Country(country == $countryOrigin, canadianProvince not in ("Y","L"))
CiTariffClass(id.ciNo == $ciNo, id.ciLineNo == $ciLineNo,
$spiPrimary : spiPrimary not in (null,"","W","Z","Y","N"), $tariffNo :
tariffNo,
spiPrimary0_1 not in ("P","A","E"), $tariffLineNo : tariffLineNo)
ShipmentHeader($dateEntry : dateEntry)
TariffClass(id.tariffNo == $tariffNo, dateTariffEffective <= $dateEntry,
dateTariffExpiration >= $dateEntry,
$dateTariffEffective : dateTariffEffective)
TariffValidSpi(id.tariffNo == $tariffNo, id.dateTariffEffective ==
$dateTariffEffective)
spiProgram1_1 not in ("*","+"), id.spiProgram not in (null, "",
$spiPrimary))
$status : ValidationPassFailStatus()
then
ValidationData $data = new ValidationData(620);
$data.setCiNo($ciNo);
$data.setCiLine($ciLineNo);
$data.setTariffLineNo($tariffLineNo);
$data.setTariffNo($tariffNo);
$data.setAdditionalInfo("SPI Primary: "+$spiPrimary);
$status.fail($data);
end
whereas, if I change the rule to:
rule "0620 Fail Invalid SPI Primary"
when
exists ValidationControl(validationNo == 620)
CiLines($ciNo : ciNo, $ciLineNo : ciLineNo, $countryOrigin :
countryOrigin)
Country(country == $countryOrigin, canadianProvince not in ("Y","L"))
CiTariffClass(id.ciNo == $ciNo, id.ciLineNo == $ciLineNo,
$spiP : spiPrimary not in (null,"","W","Z","Y","N"), $tariffNo :
tariffNo,
spiPrimary0_1 not in ("P","A","E"), $tariffLineNo : tariffLineNo)
ShipmentHeader($dateEntry : dateEntry)
TariffClass(id.tariffNo == $tariffNo, dateTariffEffective <= $dateEntry,
dateTariffExpiration >= $dateEntry,
$dateTariffEffective : dateTariffEffective)
TariffValidSpi(id.tariffNo == $tariffNo, id.dateTariffEffective ==
$dateTariffEffective)
spiProgram1_1 not in ("*","+"), id.spiProgram not in (null, " ", "",
$spiP))
$status : ValidationPassFailStatus()
then
ValidationData $data = new ValidationData(620);
$data.setCiNo($ciNo);
$data.setCiLine($ciLineNo);
$data.setTariffLineNo($tariffLineNo);
$data.setTariffNo($tariffNo);
$data.setAdditionalInfo("SPI Primary: "+$spiP);
$status.fail($data);
end
it works as it should. I found this when hardcoding the value it was
looking for and it passed.
--
View this message in context: http://www.nabble.com/%22not-in%22-error-tp17867925p17867925.html
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 6 months
trouble adding newline to DSL
by Matt Geis
Hi,
I'm having a really strange scenario. I have a DSL entry that I need to expand onto two lines. When I write it as plain DRL, on a single line, the rule fails. When I separate it into two lines, it passes. The problem is that I'm having issues getting my DSL to insert a newline char into the drl it generates and split my resulting rule into two constraints.
Here's what I want to do... (assume the '\n actually works)
[condition][]offer with code "{offer}" and no accounts present where {constraints}=rd: RuleData(offerId == "{offer}", uc : userContext) \n not ( Account(where {constraints}) from uc.accounts)
if you put the value into a DRL rule like this, it works:
rd: RuleData(offerId == "{offer}", uc : userContext)
not ( Account(where {constraints}) from uc.accounts)
put it in like this... it fails
rd: RuleData(offerId == "{offer}", uc : userContext) not ( Account(where {constraints}) from uc.accounts)
I know that in a regex, the backslash is special, just as it is in replacement strings in Matcher.replaceAll(). What I can't figure out is how to split that line. I've tried 1, 2, 3, 4... up to 8 backslashes, and nothing works. I either get an assertion failed at the end of my test, or I get "unrecognized token" on the \ or the n .
Can someone point me in the right direction? Or, just tell me how to make the rule work all one one line!
Thanks in advance,
Matt
16 years, 6 months