calling a function in When of DRL
by wtang
I need to call a java function in the LHS (When part of the DRL) like so:
When
eval(DataComparator.compare("key1", "key2"))
where key1 and key2 are keys into a Map encapsulated by DataComparator
class. How do I pass the Map to the DataComparator class in the first
place. Do I have to do like so:
eval(DataComparator.init(Map<String, String> map)
eval(DataComparator.compare("key1", "key2")
This all seems like a bad hack to me.
What are the standard best practice to achieve what I need?
Also eval are slow why? is eval the only way to call a function in the When
part?
thx!
--
View this message in context: http://drools.46999.n3.nabble.com/calling-a-function-in-When-of-DRL-tp402...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 11 months
[Optaplanner] Filter values
by Mats Norén
Hi,
I've got a domain with the following entities:
- Person (planning entity)
- Desk (planning variable)
- DeskAssignment (solution)
All persons should be assigned to a desk according to some rules.
What I would like to do is to make certain Persons and their Desk
immovable, ie, they are assigned a desk in the initial solution and should
be fixed there. They are only there for the score calculation.
I looked at 14.3.1 Immovable planning entities but couldn't really see how
I would apply it to my use case.
Why is the filter applied at the planning entity level? Since it's the
planning variable that changes I thought that I should somehow filter the
allowed values for the Desk.
Regards,
Mats
10 years, 11 months
Facts - One to Many
by Ray Hooker
I am trying to figure out how to work with an existing model. The data is in
MongoDB with embedded documents. It is about patients would have
sub-documents. For example. An individual patient may have multiple
allergies. Also a patient has multiple medications. So it is as follows:
- Patient.medications ---> multiple Medication objects
So I see where you have a simple one to one. Typically perhaps you might
have the medication record know that it is associated with the patient, but
that is not how it is currently organized. So the question is can I write
rules when patients.medications returns a set/ collection of medications
associated with the patient. I want to write a rule such as "if a patient is
taking medication=xxx...."
Thanks for your help.
Ray Hooker
10 years, 11 months
Adding rules incrementally
by calcacuervo
Hi Guys.
I am trying to add rules incrementally to the kbase, using the same
ksession. I mean, when I have a new DRL, I receive it, and want to add it to
the kbase (in memory), and the ksession I have will start to use this new
rule too.
I have been using this example,
https://github.com/droolsjbpm/drools/blob/master/drools-compiler/src/test...
I can add new rules, but just passing all the DRLS, and creating a new
KieFileSystem. I would like, when I have a new rule, just add (or modify),
this rule to the working memory.
Is this possible? Any idea?
Thanks!
Demian
--
View this message in context: http://drools.46999.n3.nabble.com/Adding-rules-incrementally-tp4027631.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 11 months
Drool 6.0.0.Final, 2 question re kie-maven-plugin, please?
by Matteo Mortari
Ciao, with premise I'm not a Maven expert...
I'm following now the new recommended version for 6.0 KIE project/module
development as documented in [1] by generating a new maven archetype
"quickstart" but if compared to the documentation I found, at least in my
case, I had at a minimum to apply also the following in the pom.xml:
A. the packaging must be changed to "kjar"
B. if the project and the rules depend on an external library/maven
artifact, say for instance the object model or domain model objects the
rules will be based on, it is NOT enough to declare them in the
pom.xml <dependencies>, but the exact same dependencies MUST ALSO be also
declared within the kie-maven-plugin <plugin> <dependencies> as well.
Failing to do so, would imply that, respectively:
A. when you run Maven with the default "mvn package" or "mvn deploy" etc,
the kie-maven-plugin would not trigger
B. kie-maven-plugin will fail the build because unable to resolve the
"external" classes referenced in the .drl, with a message similar to
[ERROR] Message [id=3, level=ERROR, path=package.drl, line=3, column=0
text=Unable to find class 'classname']
Questions are:
1. Is this correct, or I'm just complicating my life without noticing, and
it is existing a simpler way, please?
2. Especially point #B, is this really the intended behavior, having to
replicate the dependencies in the two parts of the pom.xml ?
Thanks if somebody can feedback on this,
Ciao
MM
I'm making reference to:
[1]
http://docs.jboss.org/drools/release/6.0.0.Final/drools-docs/html_single/...
For reference, here is an example pom.xml I'm using:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.acme</groupId>
<artifactId>my-rules</artifactId>
<version>0.0.1</version>
<!-- point #A, must set to kjar -->
<packaging>kjar</packaging>
<!-- ... -->
<dependencies>
<!-- maven artifact containing the object model or domain model objects
the rules will be based on -->
<dependency>
<groupId>com.acme</groupId>
<artifactId>object-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>my-rules</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<version>6.0.0.Final</version>
<extensions>true</extensions>
<dependencies>
<!-- point #B, the dependency must be repeated in here as well -->
<dependency>
<groupId>com.acme</groupId>
<artifactId>object-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
</plugins>
<!-- The following is added to avoid Eclipse ERROR at the pom.xml line
defining the kie-maven-plugin, by explicitly telling Eclipse to avoid run
the plugin on Eclipse-build, leaving it trigger only when running Maven, eg
"mvn package" or "mvn deploy", etc etc , see
http://wiki.eclipse.org/M2E_plugin_execution_not_covered -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.kie</groupId>
<artifactId>kie-maven-plugin</artifactId>
<versionRange>[6.0.0,)</versionRange>
<goals>
<goal>build</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<!-- ... -->
</project>
10 years, 11 months
java.lang.RuntimeException: Unable to instance KieServices
by kurrent93
Hi
I am trying to get started with Drools 6x, and in eclipse, I have created a
Drools project, which creates the boilerplate code to run a simple drl.
I have the drools runtime installed via Eclipse.
Yet, when I try to run the following, I get the following error:
java.lang.ExceptionInInitializerError
at com.sample.DroolsTest.main(DroolsTest.java:15)
Caused by: java.lang.RuntimeException: Unable to instance KieServices
at org.kie.api.KieServices$Factory.<clinit>(KieServices.java:167)
... 1 more
Caused by: java.lang.ClassNotFoundException:
org.drools.compiler.kie.builder.impl.KieServicesImpl
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.kie.api.KieServices$Factory.<clinit>(KieServices.java:165)
... 1 more
package com.sample;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
/**
* This is a sample class to launch a rule.
*/
public class DroolsTest {
public static final void main(String[] args) {
try {
// load up the knowledge base
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
KieSession kSession = kContainer.newKieSession("ksession-rules");
// go !
Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
kSession.insert(message);
kSession.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
}
public static class Message {
public static final int HELLO = 0;
public static final int GOODBYE = 1;
private String message;
private int status;
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
public int getStatus() {
return this.status;
}
public void setStatus(int status) {
this.status = status;
}
}
}
--
View this message in context: http://drools.46999.n3.nabble.com/java-lang-RuntimeException-Unable-to-in...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 11 months
Drools 6.0.1 xstream marshaling via camel config not working
by jroman
Hi all,
I am not sure if I have met a bug in kie-camel-xstream marshalling (drools
6.0.1). The use case is:
Java client: MiniRESTClient.java
- Build a list of commands, group them under a BatchExecutionCommand and
send them to a camel route.
Camel route: camel-client.xml
- Marshal the commad, send it to a drools server and unmarshal the result.
The problem is that the marshalling part seams to fail with:
It seams that the xstream marshaler is building a java.util.ArrayList
instead of the expected org.apache.cxf.message.MessageContentsList
The funny thing is that, if I explicitly do the marshaling in the java
client with:
And remove the
from the policy definition no exception is thrown and the client-server
communication works as expected. Besides, I have the reverse policy in the
server side and there is no problem there.
Am I doing something wrong?
I think I have attached everything needed to test the case: my_tests.zip
<http://drools.46999.n3.nabble.com/file/n4027607/my_tests.zip>
Thanks for reading down to here and for any help you could provide.
-----
--
jroman
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-6-0-1-xstream-marshaling-via-cam...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 11 months
Using Advanced Enumeration Concepts in guvnor
by abhinay_agarwal
The following sentences are taking directly from the user guide:
/ 'Person.age' : (new com.yourco.DataHelper()).getListOfAges()
This assumes you have a class called "DataHelper" which has a method
"getListOfAges()" which returns a List of strings (and is on the classpath).
You can of course mix these "dynamic" enumerations with fixed lists. You
could for example load from a database using JDBC. The data enumerations are
loaded the first time you use the guided editor in a session./
Now, I would like to know how guvnor would connect to the database ?
Inside the getListOfAges(), I want to hit the database and get the list of
ages, put it inside a Map<String, List<String>>.
The example that is shown in the user guide is again hard coding the values.
>From the user guide :
/public class SampleDataSource2 {
public Map<String>, List<String> loadData() {
Map data = new HashMap();
List d = new ArrayList();
d.add("value1");
d.add("value2");
data.put("Fact.field", d);
return data;
}
}/
AFAIK, the jar of this class SampleDataSource2 will be uploaded to guvnor,
so should I keep the connection details to database inside the same class ?
If yes,
1. How will guvnor be able to directly connect to the database ?
2. Should I add the jars for database connectivity as well ?
3. Is keeping the connection details inside the jar, not a security threat ?
I am not sure if I understand completely how this enumeration works, please
feel free to guide me, if I am wrong somewhere.
Regards,
Abhinay
--
View this message in context: http://drools.46999.n3.nabble.com/Using-Advanced-Enumeration-Concepts-in-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 11 months