How to write Hibernate query lang(HQL) in .DRL file
by zeeshan
Hi !
According to my requirement I need to fetch and Insert data from database
using Hibernate Query from .DRL file.
I have idea how to execute HQL in Plain Java class but according to my
requirement,I need to fire query to database from .DRL file which I tried
but unable to get output instead I was getting errors.
Can anyone suggest me process to execute Hibernate Query from DRL file
or please provide me some sample code or any link.
Thanks !!
--
View this message in context: http://drools.46999.n3.nabble.com/How-to-write-Hibernate-query-lang-HQL-i...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
[Planner]
by Mats Norén
Hi,
I've got a really simple problem that I can't seem to fix. :-)
I'm trying to use a simplified model for a room planning problem.
The planning entity is a Topic and the planning variables are Room and
TimeSlot.
A Person is tied to a Topic as a moderator.
Each Person can have multiple Topics as an interest.
The hard constraints are that a Person cannot be moderator in two Topics at
the same TimeSlot and that there cannot be multiple Topics in the same Room
at the same TimeSlot.
rule "conflictingModeratorInSameTimeslot"
when
$leftTopic : Topic($leftId : id, $leftTimeslot : timeSlot, timeSlot
!= null, $leftModerator: moderator)
$rightTopic : Topic(timeSlot == $leftTimeslot, moderator ==
$leftModerator, id > $leftId)
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
rule "multipleTopicsInSameRoomAndTimeslot"
when
$leftTopic : Topic($leftId : id, $leftTimeslot : timeSlot, timeSlot
!= null, $leftRoom: room)
$rightTopic : Topic(timeSlot == $leftTimeslot, room == $leftRoom,
id > $leftId)
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
The soft constraint that I have a problem with is that a Person has
multiple Topics as interests and I would like to penalize the Solution with
the number of Topics in the Persons interests collection with the number of
Topics that are allocated at the same TimeSlot.
Any ideas on how to go about this?
Regards,
Mats
12 years, 10 months
KnowledgeAgent to update knowledge base built with Guvnor pkg
by riri
Hello everyone,
I am trying to take advantage of the automatic uploading that the
KnowledgeAgent provides and am using the 5.5.Final Drools version. The
Drools Expert documentation states that one can use an existing knowledge
base to create an agent, and the agent will subscribe to the resources that
it finds (Example 3.26. Using an existing KnowledgeBase).
I am at first creating the knowledge base using a set of .drl files defined
in a change-set file and also a Guvnor url :
http://127.0.0.1:8080/guvnor/org.drools.guvnor.Guvnor/package/<package-name>/LATEST.
I then create the knowledge agent as shown in Example 3.26 of the
documentation. The problem is that if I modify the Guvnor package (add or
remove a rule) and then rerun a stateful knowledge session, the knowledge
base is not updated. I thought that I needed to build the package in Guvnor
every time I modify it but doing so does not solve the problem. Modifying
the rules in the change-set files seems to update the knowledge base.
I start the ResourceChangeScanner and ResourceChangeNotifier and if I call
isMonitorChangeSetEvents() and isScanResources() they return true. And also,
whenever I create a session, I use the getKnowledgeBase() method and am not
caching it somewhere in my program. Should I not be creating the agent with
an existing knowledge base and instead use the applyChangeSet() method? If
so, how would I be able to configure the knowledge base to use
AssertBehaviorOption.EQUALITY?
Thany you very much for any help or tips to point me in the right direction.
Best regards
--
View this message in context: http://drools.46999.n3.nabble.com/KnowledgeAgent-to-update-knowledge-base...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
Error deploying Guvnor 6.0.0.Beta1 on Tomcat 7
by maunakea
I was excited to try out Guvnor 6. Downloaded the Beta1 and tried deploying
on Tomcat 7.0.32. It deployed fine, but when I access the URL, I get the
trace below. Anybody able to deploy on Tomcat 7?
org.jboss.errai.bus.client.api.base.MessageDeliveryFailure: error invoking
endpoint
at
org.jboss.errai.bus.server.io.ConversationalEndpointCallback.callback(ConversationalEndpointCallback.java:132)
at
org.jboss.errai.bus.server.io.RemoteServiceCallback.callback(RemoteServiceCallback.java:54)
at
org.jboss.errai.cdi.server.CDIExtensionPoints$3.callback(CDIExtensionPoints.java:512)
at
org.jboss.errai.bus.client.framework.DeliveryPlan.deliver(DeliveryPlan.java:43)
...
Caused by: java.lang.NullPointerException
at
org.uberfire.backend.server.UserServicesImpl.buildPath(UserServicesImpl.java:71)
at
org.uberfire.backend.server.UserServicesImpl$Proxy$_$$_WeldClientProxy.buildPath(UserServicesImpl$Proxy$_$$_We
at
org.uberfire.backend.server.WorkbenchServicesImpl.getPathToDefaultEditors(WorkbenchServicesImpl.java:105)
at
org.uberfire.backend.server.WorkbenchServicesImpl.loadDefaultEditorsMap(WorkbenchServicesImpl.java:76)
at
org.uberfire.backend.server.WorkbenchServicesImpl$Proxy$_$$_WeldClientProxy.loadDefaultEditorsMap(WorkbenchSer
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.errai.bus.server.io.ConversationalEndpointCallback.callback(ConversationalEndpointCallback.java:114)
... 29 more
*** Message delivery failure ***
Bus: org.jboss.errai.bus.server.ServerMessageBusImpl@134137c
Message: CommandType=loadDefaultEditorsMap:,
ErrorTo=org.uberfire.client.workbench.services.WorkbenchServices:RPC.loadDef
errorMessage: Error calling remote service:
org.uberfire.client.workbench.services.WorkbenchServices:RPC
exception: org.jboss.errai.bus.client.api.base.MessageDeliveryFailure: error
invoking endpoint
disconnect: false
org.jboss.errai.bus.client.api.base.MessageDeliveryFailure: error invoking
endpoint
at
org.jboss.errai.bus.server.io.ConversationalEndpointCallback.callback(ConversationalEndpointCallback.java:132)
at
org.jboss.errai.bus.server.io.RemoteServiceCallback.callback(RemoteServiceCallback.java:54)
at
org.jboss.errai.cdi.server.CDIExtensionPoints$3.callback(CDIExtensionPoints.java:512)
at
org.jboss.errai.bus.client.framework.DeliveryPlan.deliver(DeliveryPlan.java:43)
--
View this message in context: http://drools.46999.n3.nabble.com/Error-deploying-Guvnor-6-0-0-Beta1-on-T...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
window:length with variables as constraints not working correctly
by Andreas
Hello,
I'm having a problem using sliding windows length
I would like to get the average oft he last 5 Events of the AccountNumber
"123"
(rule: FiveLastEventsWhichBelongsToTheAccount).
If there are no Events with other AccountNumbers and if the AccountNumber is
directly added as String as a rule constraint, both cases will work
correctly as I understand the rule behaviour
But
If there are Events available for different AccountNumbers and the
AccountNumber is extracted from the $account : Account() to use it as a
constraint to check if the Event belongs to the AccountNumber the condition
is not working like first filter then window; it seems to work like first
window then filter)
I don’t know if it should work like this or if it is maybe a bug.
If I’m wrong, how is it possible to solve my problem, so that I don’t need
to write a rule for every possible account number.
Thanks in advanced
Andreas
I’m using drools version 5.3.5 because of the NPE (
https://issues.jboss.org/browse/DROOLS-78?page=com.atlassian.jira.plugin....),
which don’t occurs in this test case but in other rules I’ve implemented. So
it would be nice to have a solution for version 5.3.5.
For Testing you can use the following classes and drl File:
public class Account {
private String number = "";
public Account() {
super();
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
}
public class Event implements Serializable {
private static final long serialVersionUID = 1L;
private String accountNumber = "";
private double amount = 0.00;
public Event(String accountNumber, double amount) {
this.accountNumber = accountNumber;
this.amount = amount;
}
public String getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
}
Rule file
declare Event
@role( event )
end
rule "FiveLastEventsWhichBelongsToTheAccount"
when
$account : Account()
$averageOfAmount : Number( doubleValue > 0 )
from accumulate(
Event(
//accountNumber == “123“, //works
accountNumber == $account.number, //not working if
more than one
//AccountNumbers available during all events
$amount : amount
)
over window:length( 5 ) from
entry-point EventStream,
average($amount)
)
then
System.out.println("Average of aveOfLastClaims: " + $averageOfAmount);
End
TesterClass:
public class Tester {
private static final String DRL_FILENAME = "account.drl";
private static final String ENTRY_POINT = "EventStream";
private static KnowledgeBase knowledgeBase = null;
private static StatefulKnowledgeSession session = null;
private static Account account123 = null;
private static String accountNumber123 = "123";
private static Account account456 = null;
private static String accountNumber456 = "456";
private static void setUp() {
prepareKnowledgeBase();
prepareStatefulKnowledgeSession();
prepareAccounts();
}
private static void prepareAccounts() {
account123 = new Account();
account123.setNumber(accountNumber123);
account456 = new Account();
account456.setNumber(accountNumber456);
}
private static void prepareStatefulKnowledgeSession() {
KnowledgeSessionConfiguration sessConfig =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
sessConfig.setOption(ClockTypeOption.get("pseudo"));
session = knowledgeBase.newStatefulKnowledgeSession(sessConfig, null);
}
private static void prepareKnowledgeBase() {
try {
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder();
builder.add(ResourceFactory.newClassPathResource(DRL_FILENAME),
ResourceType.DRL);
KnowledgeBuilderErrors errors = builder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error : errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
knowledgeBase.addKnowledgePackages(builder.getKnowledgePackages());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
setUp();
try {
SessionPseudoClock clock = session.getSessionClock();
WorkingMemoryEntryPoint eventStream =
session.getWorkingMemoryEntryPoint(ENTRY_POINT);
eventStream.insert(new Event(accountNumber123, 50.00));
eventStream.insert(new Event(accountNumber456, 500.00));
clock.advanceTime(5, TimeUnit.DAYS);
eventStream.insert(new Event(accountNumber123, 40.00));
eventStream.insert(new Event(accountNumber456, 400.00));
clock.advanceTime(10, TimeUnit.DAYS);
eventStream.insert(new Event(accountNumber123, 30.00));
eventStream.insert(new Event(accountNumber456, 300.00));
clock.advanceTime(15, TimeUnit.DAYS);
eventStream.insert(new Event(accountNumber123, 20.00));
eventStream.insert(new Event(accountNumber456, 200.00));
clock.advanceTime(20, TimeUnit.DAYS);
eventStream.insert(new Event(accountNumber123, 10.00));
eventStream.insert(new Event(accountNumber456, 100.00));
session.insert(account123);
session.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
}
}
--
View this message in context: http://drools.46999.n3.nabble.com/window-length-with-variables-as-constra...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months
[fusion] weird race conditions and a null pointer exception
by burmanator
I am running 2 rules that are very similar but with a slight change:
rule One
when
$foo : Foo($name : Name, $msg : Message !="")
$prev : ArrayList(size<1) from collect( Foo(Name==$name, Message == $msg,
this before $foo)
$list : Set(size>0) from accumulate( Foo(Name == $name, $msgs: Message !=
$msg, this after $foo), collectSet($msgs))
then
System.out.println($name + "\twent from \"" + $msg + "\"\tto " + $list);
end
rule Two
when
$foo : Foo($name : Name, $msg : Message !="")
Not( Foo(Name==$name, Message == $msg, this before $foo))
$list : Set(size>0) from accumulate( Foo(Name == $name, $msgs: Message !=
$msg, this after $foo), collectSet($msgs))
then
System.out.println($name + "\twent A from \"" + $msg + "\"\tto " + $list);
end
rule One works just fine however its rule Two I seem to be having trouble
with. In my main method I have an initial print statement, then I go through
this whole process of parsing XML files into objects and then adding those
objects into the session. Once all the objects are entered I do a print out,
I then call fireAllRules on the session and then do another print out.
When I use rule Two, my program starts firing the rules and displaying their
results almost immediately, even before the 2nd print out (sometimes even
before the first initial print out). Most of the time I get a Null Pointer
Exception but it does occasionally finish running. In the cases it does
finish it spits out the output from most of the rules then displays the 2nd
printout, the print out from a rule and then the ending print out. When it
does throw the null pointer exception I get:
java.lang.NullPointerException
at org.drools.core.util.LinkedList.remove(LinkedList.java:133)
at
org.drools.common.DefaultAgenda.addActivation(DefaultAgenda.java.446)
at
org.drools.common.DefaultAgenda.modifyActivation(DefaultAgenda.java:382)
at
org.drools.reteoo.RuleTerminalNode.modifyLeftTuple(RuleTerminalNode.java:301)
at
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateModifyChildLeftTuple(SingleLeftTupleSinkAdapter.java:259)
at
org.drools.reteoo.AccumulateNode.exaluateResultConstraints(AccumulateNode.java:676)
at
org.drools.reteoo.ReteooWorkingMemory$EvaluateResultConstraints.execute(ReteooWorkingMemory.java:590)
at
org.drools.common.PropagationContextImpl.evaluateActionQueue(PropagationContextimple:350)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:355)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:311)
at
org.drools.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:903)
at
org.drools.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:847)
at
org.drools.imp.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:269)
at test2.Engine2.main(Engine2.java:80)
However sometimes when it throws the Null pointer exception, it prints out
some of the results of the rules in the middle of the display of the
exception, such as:
java.lang.NullPointerExceptionName1 went A from "msg1" to [msg2]
Name2 went A from "msg1" to [msg2]
at org.drools.core.util.LinkledList.remove(LinkedList.java.133)
and you know the rest.
When I run both rules together, for some reason it seems to run rule One
over the same name and message pair multiple times even though based on the
logic it should only run it based on the first occurrence.
Also I don't know if this matters but there are 361,694 objects that are
entered into the session, 44,269 of which are Foo objects
--
View this message in context: http://drools.46999.n3.nabble.com/fusion-weird-race-conditions-and-a-null...
Sent from the Drools: User forum mailing list archive at Nabble.com.
12 years, 10 months