Re: [rules-users] Example test case fails when setting JANINO in KnowledgeBuilderConfiguration
by Edson Tirelli
Nicholas,
It seems that dialect configuration is not exposed yet through the
drools-api. We need to do that.
Would you please open a JIRA so that this is not lost?
Meanwhile, the work around is to fallback to the previous API:
JavaDialectConfiguration conf = (JavaDialectConfiguration)
((PackageBuilderConfiguration)knowledgeBuilderConfiguration).getDialectConfiguration(
"java" );
conf.setCompiler( JavaDialectConfiguration.JANINO );
Finally, please remember that JANINO does not support java 1.6. From his
project page it supports java 1.4 with a few features from 1.5.
[]s
Edson
2009/7/2 Nicholas Hemley <nic.hemley(a)sidonis.com>
> Hello,
>
>
>
> I have a little test case as follows:
>
>
>
> *import* org.drools.builder.KnowledgeBuilderConfiguration;
>
> *import* org.drools.builder.KnowledgeBuilderFactory;
>
> *import* org.junit.Assert;
>
> *import* org.junit.Test;
>
>
>
> *public* *class* TestDrools5Config {
>
>
>
> @Test
>
> *public* *void* testConfig() {
>
> KnowledgeBuilderConfiguration knowledgeBuilderConfiguration =
> KnowledgeBuilderFactory.*newKnowledgeBuilderConfiguration*();
>
> knowledgeBuilderConfiguration.setProperty(
> "drools.dialect.java.compiler", "JANINO");
>
> knowledgeBuilderConfiguration.setProperty(
> "drools.dialect.java.lngLevel", "1.6");
>
>
>
> String droolsDialectJavaCompiler =
> knowledgeBuilderConfiguration.getProperty("drools.dialect.java.compiler");
>
> System.*out*.println("droolsDialectJavaCompiler=" +
> droolsDialectJavaCompiler);
>
> Assert.*assertNotNull*(droolsDialectJavaCompiler);
>
>
>
> String *droolsDialectJavaLngLevel* =
> knowledgeBuilderConfiguration.getProperty("drools.dialect.java.lngLevel");
>
> System.*out*.println("drools.dialect.java.lngLevel=" +
> droolsDialectJavaLngLevel);
>
> Assert.*assertNotNull*(droolsDialectJavaLngLevel);
>
> }
>
> }
>
>
>
> It fails.
>
>
>
> I have seen the post for using JANINO with Drools:
>
> http://lists.jboss.org/pipermail/rules-users/2009-February/008089.html
>
>
>
> Yet this does not explain my test case failing – any ideas.
>
>
>
> It appears as if it is not possible to set JANINO programmatically, only
> via properties.conf, etc. which I don’t want to do(!)
>
>
>
> Cheerio,
>
> Nic Hemley
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
--
Edson Tirelli
JBoss Drools Core Development
JBoss by Red Hat @ www.jboss.com
15 years, 5 months
Example test case fails when setting JANINO in KnowledgeBuilderConfiguration
by Nicholas Hemley
Hello,
I have a little test case as follows:
import org.drools.builder.KnowledgeBuilderConfiguration;
import org.drools.builder.KnowledgeBuilderFactory;
import org.junit.Assert;
import org.junit.Test;
public class TestDrools5Config {
@Test
public void testConfig() {
KnowledgeBuilderConfiguration knowledgeBuilderConfiguration =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
knowledgeBuilderConfiguration.setProperty("drools.dialect.java.compiler",
"JANINO");
knowledgeBuilderConfiguration.setProperty("drools.dialect.java.lngLevel",
"1.6");
String droolsDialectJavaCompiler =
knowledgeBuilderConfiguration.getProperty("drools.dialect.java.compiler");
System.out.println("droolsDialectJavaCompiler=" +
droolsDialectJavaCompiler);
Assert.assertNotNull(droolsDialectJavaCompiler);
String droolsDialectJavaLngLevel =
knowledgeBuilderConfiguration.getProperty("drools.dialect.java.lngLevel");
System.out.println("drools.dialect.java.lngLevel=" +
droolsDialectJavaLngLevel);
Assert.assertNotNull(droolsDialectJavaLngLevel);
}
}
It fails.
I have seen the post for using JANINO with Drools:
http://lists.jboss.org/pipermail/rules-users/2009-February/008089.html
Yet this does not explain my test case failing - any ideas.
It appears as if it is not possible to set JANINO programmatically, only via
properties.conf, etc. which I don't want to do(!)
Cheerio,
Nic Hemley
15 years, 5 months
problems with variables in drools-flow
by Ševčík Martin
I have a simple process with action and one human task.
When I'm starting a process, I add a variable this way:
Map<String,Object> data = new HashMap<String,Object>();
data.put("data3", "this is data3");
ProcessInstance pi = ksession.startProcess("com.sample.ruleflow",data);
Another data I put in variable properties of the ruleflow, and called it data1.
Third variable I added in action this way:
((org.drools.process.instance.context.variable.VariableScopeInstance) (context.getProcessInstance().getContextInstance(org.drools.process.core.context.variable.VariableScope.VARIABLE_SCOPE))).setVariable("data2", "this is data2");
But when I'm trying to map this variables in human task, only data1 is visible, the other end up with :
Could not find variable scope for variable data2
when trying to execute Work Item Human Task
Continuing without setting parameter.
Could not find variable scope for variable data3
when trying to execute Work Item Human Task
Continuing without setting parameter.
Could you please help me?
And also, how can I get this data in human task?
I can get a task summary this way:
BlockingTaskSummaryResponseHandler responseHandler = new BlockingTaskSummaryResponseHandler();
client1.getTasksAssignedAsPotentialOwner("martin", "en-UK", responseHandler);
List<TaskSummary> list = responseHandler.getResults();
And then a task this way:
BlockingGetTaskResponseHandler rh2 = new BlockingGetTaskResponseHandler();
client1.getTask(task.getId(), rh2);
Task task2 = rh2.getTask();
But how can i get object data1?
Thank you.
Martin
15 years, 5 months
streams and equality assertion behavior
by Jaroslaw Kijanowski
Hi,
I've configured my knowledge base to use the EQUALITY assertion behaviour.
When I insert two equal facts into the session, only one gets processed
(objects and their fact handles are equal).
However when I insert two equal facts via streams, my rule fires twice
(objects are equal, but their fact handles are not). Isn't equality
assertion behaviour supported when using streams?
Here's my rule and test class:
package com.sample
import com.sample.Message;
declare Message
@role( event )
@timestamp( time )
end
rule "r"
when
Message( $i:i) //from entry-point "myStream"
then
System.out.println( $i );
end
+++++++++++++++++++++++++++++++++++++++++
public class Message {
private int i;
private Date time;
//getters, setters, hashcode, equals, constructor
}
+++++++++++++++++++++++++++++++++++++++++
public class DroolsTest {
public static final void main(String[] args) {
try {
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession();
//WorkingMemoryEntryPoint stream =
ksession.getWorkingMemoryEntryPoint("myStream");
Date d = new Date();
Message message1 = new Message(1,d);
FactHandle fh1 = ksession.insert(message1);
//FactHandle fh1 = stream.insert(message1);
Message message2 = new Message(1,d);
FactHandle fh2 = ksession.insert(message2);
//FactHandle fh2 = stream.insert(message2);
if (message1.equals(message2) && fh1.equals(fh2)){
System.out.println("equal");
}
ksession.fireAllRules();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("Sample.drl"),
ResourceType.DRL);
if (kbuilder.getErrors().size() > 0) {
throw new IllegalArgumentException("Could not parse knowledge.");
}
KnowledgeBaseConfiguration kbaseConfig =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbaseConfig.setOption(AssertBehaviorOption.EQUALITY);
kbaseConfig.setOption(EventProcessingOption.STREAM);
kbaseConfig.setOption(RemoveIdentitiesOption.YES);
KnowledgeBase kbase =
KnowledgeBaseFactory.newKnowledgeBase(kbaseConfig);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
}
+++++++++++++++++++++++++++++++++++++++++
Thanks,
Jarek
15 years, 6 months
migration from drools 3.0.6 to 5.0.1
by Nicholas Hemley
Hello,
I have just completed a migration from 3.0.6 to 5.0.1 and have one specific
question.
It appears that the new Agenda interface has had the agendaSize() method
removed, so what is the equivalent in Drools 5, please?
Maybe there is an easier way for me to check if there is at least one
Activation on an Agenda?
Cheerio,
Nic Hemley
15 years, 6 months
classLoader issue...
by Julien Nicoulaud
Hi, I'm migrating my system from Drools 4.0.7 to Drools 5.1.0.
Now when I try to compile rules that check fact fields, I get the
following exception:
ERROR: EventDispatcher: Error during dispatch.
(java.lang.NoClassDefFoundError:
org/drools/base/extractors/BaseObjectClassFieldReader)
java.lang.NoClassDefFoundError:
org/drools/base/extractors/BaseObjectClassFieldReader
( http://paste2.org/p/296380 )
It seems the classloaders I pass to the configurations are not taken in
account... I get exactly the same error if I do not specify the
classloaders. Here is the code:
KnowledgeBuilderConfiguration kBuilderCfg =
KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null,classLoader);
KnowledgeBuilder knowledgeBuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(kBuilderCfg);
KnowledgeBaseConfiguration kbaseConfig =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration(null,multiBundleClassLoader);
kbaseConfig.setOption(EventProcessingOption.STREAM);
knowledgeBase =
KnowledgeBaseFactory.newKnowledgeBase(kbaseConfig);
On Drools 4, we did exactly the same with PackageBuilder instead of
KnowledgeBuilder and RuleBase for KnowledgeBase. So the classloaders I
pass are the good ones... Is there some trick ?
Thanks for any help !
15 years, 6 months
[drools-solver] help for defining my drools model / moves
by Laurent Michenaud
Hi,
Here is my test :
I have an appointment to schedule on a customer availability.
I have a list of customer availabilities.
A customer availability is a period.
An appointment needs an exact number of persons.
A resource is composed of persons ( between 1 and n ) and has availabilities too.
The problem is to schedule the appointment : it has to choose the
right resource availabilities that matches one of the customer availabilities and
the total number of persons inside chosen resources must match exactly the
needed number of persons of the appointment.
My moves are for the moment :
- Change the customer availability.
- Add a resource to the list of chosen resources.
My init is :
- One of the customer availability is taken
- 0 resource taken.
First, i don't know if my model and my init are ok.
Secondly, the solver does the following :
- At the beginning, the score is bad because there is no resource.
So, it begins adding resource and the score is getting better
but when it changes the availability, the score gets very bad either because
the chosen resources don't match the new availability or it has no resource
inside. The solver doesnot seem to interest in the new chosen availibity with no
resource, but i wish it does.
Thanks for your remarks/help
Best regards
15 years, 6 months