Reg : Drools 5.5 Templates : CompoundValueRestrictions
by Barada (Native5)
Hi,
Am trying to model some rules using drools templates.
Currently the data inputs to rule templates are only strings, I need to be able to define a compound value restriction set for the rule i.e if fact attribute is present in a list. (see sample below).
e.g.
template header
dealers
template "my-template"
rule "my-rule"
when
$order : Order(dealer in (@{dealers}))
then
System.out.println("Order is present in dealer"
end
end template
I am trying to compile this template by passing it an Object which has a dealers attribute which is essentially a List<String>. Short of creating a function which sends back a comma separated representation of the list, does the drools compiler provide any option to send a list.
~ Barry
11 years
NullPointer while deleting a rule since 6.0.0 upgrade
by Nicolas de Dreuille
Hey,
I recently upgraded drools from 5.5.0.Final to 6.0.0.CR3
A rule deletion that used to work now throws a NullPointerException.
A fact has to be inserted for the Exception to be thrown.
Here is the log :
[main] INFO org.drools.compiler.kie.builder.impl.KieRepositoryImpl -
> KieModule was added:MemoryKieModule[
> ReleaseId=org.default:artifact:1.0.0-SNAPSHOT]
> objectInserted org.test.ProximityTest$Track@2c6c5356
> [Rule name=ProxRule, agendaGroup=MAIN, salience=0, no-loop=false]
> Exception in thread "main" java.lang.NullPointerException
> at org.drools.core.phreak.AddRemoveRule.deletePeerLeftTuple(
> AddRemoveRule.java:687)
> at org.drools.core.phreak.AddRemoveRule.followPeer(AddRemoveRule.java:659)
> at org.drools.core.phreak.AddRemoveRule.processLeftTuples(
> AddRemoveRule.java:620)
> at org.drools.core.phreak.AddRemoveRule.flushStagedTuples(
> AddRemoveRule.java:243)
> at org.drools.core.phreak.AddRemoveRule.removeRule(AddRemoveRule.java:134)
> at org.drools.core.reteoo.ReteooBuilder.removeRule(ReteooBuilder.java:172)
> at org.drools.core.reteoo.ReteooRuleBase.removeRule(
> ReteooRuleBase.java:1402)
> at org.drools.core.reteoo.ReteooRuleBase.removeRule(
> ReteooRuleBase.java:1393)
> at org.drools.core.reteoo.ReteooRuleBase.removeRule(
> ReteooRuleBase.java:1371)
> at org.drools.core.impl.KnowledgeBaseImpl.removeRule(
> KnowledgeBaseImpl.java:210)
> at org.test.ProximityTest.CreateKieRuleOnTheFly(ProximityTest.java:72)
> at org.test.ProximityTest.main(ProximityTest.java:102)
Here is a code sample that reproduces the issue :
package org.test;
> import java.util.ArrayList;
> import java.util.List;
> import org.kie.api.KieBase;
> import org.kie.api.KieServices;
> import org.kie.api.builder.KieBuilder;
> import org.kie.api.builder.KieFileSystem;
> import org.kie.api.builder.KieRepository;
> import org.kie.api.builder.Message.Level;
> import org.kie.api.definition.rule.Rule;
> import org.kie.api.event.rule.ObjectDeletedEvent;
> import org.kie.api.event.rule.ObjectInsertedEvent;
> import org.kie.api.event.rule.ObjectUpdatedEvent;
> import org.kie.api.event.rule.WorkingMemoryEventListener;
> import org.kie.api.runtime.KieContainer;
> import org.kie.api.runtime.KieSession;
> public class ProximityTest {
> private void CreateKieRuleOnTheFly() {
> KieServices ks = KieServices.Factory.get();
> KieRepository kr = ks.getRepository();
> KieFileSystem kfs = ks.newKieFileSystem();
> // Can't understand why this does not work without the
> // src/main/resources part
> kfs.write("src/main/resources/org/test/rule.drl", getRule());
> KieBuilder kb = ks.newKieBuilder(kfs);
> kb.buildAll();
> if (kb.getResults().hasMessages(Level.ERROR)) {
> throw new RuntimeException("Build Errors:\n"
> + kb.getResults().toString());
> }
> KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
> KieSession kSession = kContainer.newKieSession();
> kSession.addEventListener(new WorkingMemoryEventListener() {
> @Override
> public void objectUpdated(ObjectUpdatedEvent oue) {
> System.out.println("objectUpdated " + oue.getObject());
> }
> @Override
> public void objectInserted(ObjectInsertedEvent oi) {
> System.out.println("objectInserted " + oi.getObject());
> }
> @Override
> public void objectDeleted(ObjectDeletedEvent ore) {
> System.out.println("objectRetracted " + ore.getOldObject());
> }
> });
> // CloseTrack closeTrack = new CloseTrack(100,200);
> Track track = new Track(100);
> // track.getCloseTracks().add(closeTrack);
> // kSession.insert(track);
> // track = new Track(200);
> kSession.insert(track);
> kSession.fireAllRules();
> KieBase kieBase = kSession.getKieBase();
> Rule rule = kieBase.getRule("org.test", "ProxRule");
> System.out.println(rule);
> kieBase.removeRule("org.test", "ProxRule");
> System.out.println("done");
> }
> private static String getRule() {
> String s = ""
> + "package org.test"
> + "\nimport org.test.ProximityTest.*"
> + "\nrule \"ProxRule\""
> + "\nwhen "
> + "\n $track:Track("
> + "\n )"
> + "\n $track1:Track("
> + "\n )"
> + "\n exists (CloseTrack(closeTrackId==$track1.trackId) from
> $track.closeTracks)"
> + "\nthen " + "\nSystem.out.println(\"proximity asserted\"); "
> + "\nend";
> return s;
> }
> /** test main */
> public static void main(String[] args) {
> (new ProximityTest()).CreateKieRuleOnTheFly();
> }
> public class CloseTrack {
> private int trackId;
> private int closeTrackId;
> public CloseTrack(int i, int j) {
> this.trackId = i;
> this.closeTrackId = j;
> }
> public int getTrackId() {
> return trackId;
> }
> public void setTrackId(int trackId) {
> this.trackId = trackId;
> }
> public int getCloseTrackId() {
> return closeTrackId;
> }
> public void setCloseTrackId(int closeTrackId) {
> this.closeTrackId = closeTrackId;
> }
> }
> public class Track {
> private int trackId;
> private List<CloseTrack> closeTracks = new ArrayList<CloseTrack>();
> public Track(int i) {
> this.trackId = i;
> }
> public List<CloseTrack> getCloseTracks() {
> return closeTracks;
> }
> public int getTrackId() {
> return trackId;
> }
> public void setTrackId(int id) {
> this.trackId = id;
> }
> public void setCloseTracks(List<CloseTrack> closeTracks) {
> this.closeTracks = closeTracks;
> }
> }
> }
>
>
Hope this helps.
Thanks.
--
N.
11 years
Does Guvnor limits the number of unsuccessful Login Attempts ?
by Zahid Ahmed
Hi,
I want to know that is there any configuration in Guvnor to limit the number of unsuccessful login attempts. This is required as I want to prevent Brute Force attack on my production Guvnor server.
Environment:
1. Drools-Guvnor 5.5.0-Final
2. Jboss EAP 6.1.0
Thanks and Best Regards,
Zahid Ahmed
11 years
JBPM 6 Loop back.
by Naman Shah
I got a work flow, which has a loop back.
?node : yes--> do x /?node:no -->repeat previous
yes works and n o dont
and also i cant find entires into process instance data ,using which i can
see the process status.
I am using jbpm beta 6.05
Please find the attached BPMN for the same.
Node name where loop back dont work : inclusiveGateway id="_49"
and others too.
-----------------------------------------------------------------------------
11 years
How To Implement Rule Flow
by neerajs20
Hi All,
I am new to drools and guvnor. I have basic question for rule flow.
I have created 3 rules using guided editor on guvnor plugin. Now I want to
invoke the 2nd or 3rd rule based on the outcome of 1st rule.
e.g. If the patient's age is less than 18 go for 2nd rule for minor checks
otherwise invoke 3rd rule for check from senior physician.
So can this be achieved using rule flow? If yes how? Is there any example
links, documents demonstrating it? Any help very much appreciated.
Thanks
--
View this message in context: http://drools.46999.n3.nabble.com/How-To-Implement-Rule-Flow-tp4025932.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years
Optaplanner rules error
by SNELS Nick
Hi,
I have the following Drools rule in Optaplanner:
rule "oneShiftPerDay"
when
$leftAssignment : ShiftAssignment($leftId : id, $employee : employee, $shiftDate : shiftDate, employee != null)
$rightAssignment : ShiftAssignment(employee == $employee, shiftDate == $shiftDate, id > $leftId)
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
But when I run the solver I get the following error:
09:02:46.128 [main] ERROR o.d.c.k.b.impl.AbstractKieModule - Unable to build KieBaseModel:defaultKieBase
Error importing : 'be.comp.permanenties.domain.solver.EmployeeAssignmentTotal'
Error importing : 'be.comp.permanenties.domain.solver.EmployeeWorkSequence'
Rule Compilation error : [Rule name='oneShiftPerDay']
be/comp/permanenties/solver/Rule_oneShiftPerDay544009415.java (2:220) : Only a type can be imported. be.comp.permanenties.domain.solver.EmployeeWorkSequence resolves to a package
be/comp/permanenties/solver/Rule_oneShiftPerDay544009415.java (2:978) : Only a type can be imported. be.comp.permanenties.domain.solver.EmployeeAssignmentTotal resolves to a package
How can I solve this error? Thanks.
Kind regards,
Nick
[http://www.ocmwturnhout.be] <http://www.ocmwturnhout.be>
Dit bericht is onderworpen aan de bepalingen van onze disclaimer<http://www.ocmwturnhout.be/nl/content/2436>
11 years
performance of ruleflowGroup
by ashish6276
Hi
I am exploring ruleflow. Can somebody help me in knowing how
RuleFlOWGROUP affects the performance of rules. Say i have 1 lakh rules.
what will be difference in performance if i keep all rules without any group
and if i group rules in diff small small ruleflowgroup and then create a
processflow to execute the flow in such a way where selected ruleflowgroup
will be used based on condition defined in process flow.
--
View this message in context: http://drools.46999.n3.nabble.com/performance-of-ruleflowGroup-tp4026085....
Sent from the Drools: User forum mailing list archive at Nabble.com.
11 years
Indicating "used" rules
by Andrzej Grzelak
Hello again,
Im making some kind of expert system. And now i got new problem:
User is asked sequentially for propetieries of object, than I modify object
propetieries, then i call update() and fireAllRules() to check for any
answers.
It is repeated for every object property till we fire rule with answer.
Now problem comes : When user decline answer we need to find another one.
But first answer will fire every time now. That's not what i need....
Making somewhere in app list of "false answers" and then striping out them
on return wont work. My app flow is determined by drools rule fire - if one
of "answer rules" fires i return that answer, normally i would ask another
question.
I would need to indicate drools somehow to delete/deactivate that rule.
Thanks for any help.
11 years
Declared Types and Globals in different files with incremental KnowledgeAgent
by De Rooms Brecht
Dear Drools Users,
I am building a network server for drools since the existing
drools-server did not meet my requirements. Since I recently found a
bug and find the people here very helpful I'll try to explain another
issue I encountered in the hope that it improves drools 5.6 and 6.0.
I noticed that declared types and globals don't seem to be found when
you access them from a rule that was written in a different file. For
the declared types I hacked around this issue by preprocessing the files
and placing every declared type at the top of each file that needs it.
For globals this is of course not possible.
An example is shown below. File1 is loaded from the moment the agent
starts up, then file2 is loaded.
There is a difference when the knowledgeAgent detects the two files at
once or one by one. In this case the KnowledgeAgent detects one file and
then a few minutes later the other file and compiles them completely
separately.
The idea is to keep how many rules are matched of a certain type in a
global.
* FILE1: global_rules_matches.drl
----------------------------------------------
package ellipsoidfacts
// declare
global Integer RULES_MATCHED;
// initialize global
rule "initRULESMATCHED"
salience 999
when
then
RULES_MATCHED = 0;
end*
* FILE2: testrule.drl
----------------------------------------------
package ellipsoidfacts
rule "Gesture_lefthook"
when
// ... any precedent rules ...
then
System.out.println("matched gesture: lefthook"+ RULES_MATCHED);
end*
In this particular case, my rule is not matched. I load these rules
using a changeset xml, my knowledgeagent is set to incremental (but
either doesnt work).
The same happens when I declare types in FILE1 and use them in FILE2.
When I write the type declaration in both files it works perfectly.
Being the same package I assumed that these two scenarios should work.
Am I doing something wrong or is the agent not supposed to work like
this and should a package be in one file?
Kind Regards,
De Rooms Brecht
11 years