Store a Map in Country Enumeration
by srinivasasanda
Hi,
I have a declarative model with a fact named Person with
field*(country,state)*
I have seen in guvnor documentation that
'Board.type':['short','long','NN=MIn Mal']
Min Mal will be displayed in GUI where as NN will be used backend
In the sameway,I need to use country ids instead of countrynames in backend
where countryname should displayed at GUI.How I can do this?please suggest
me..
'Person.country':(new com.sample.DropDownList()).loadCountriesList()-----
Countries are succesfully loaded---US,UK,JAPAN....etc....in dropdown list
Now I should use different IDs for these different countries in backend.
In the above enumeration I should use different Ids for different countries
in backend(rule)..How can I do this
Please suggest me.Please How can I achieve
--
View this message in context: http://drools.46999.n3.nabble.com/Store-a-Map-in-Country-Enumeration-tp35...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
Sliding window behavior in stream mode and realtime clock
by MarcoMojana
Hi,
The situation is the following: we need to process a stream of delayed
events. This means that the event timestamp is provided for each one
of them and that it doesn't generally correspond to the system time when
we insert them in the entry-point. The events delay may vary, but they
are always inserted in chronological order. My questions refer to the
enclosed implementation and are:
1) Given my source code, would the timestamps correctly read and used?
2) I would like that the "time window" behaves as if it is initially
placed at t = -inf and, when a new event is inserted in the
entry-point, it would slide to the time of the last event timestamp.
In my code I have used the stream mode and a realtime clock: is it
correct?
3) When I run the given application, I expect it to print only:
Found TriggerEvent [timestamp=Tue Dec 06 13:00:00 CET 2011]
because it is the only event of type TriggerEvent for which there
exists a window of size 1h that contains no InhibitEvent. Instead,
sometimes it prints nothing and sometimes:
Found TriggerEvent [timestamp=Tue Dec 06 14:10:00 CET 2011]
Found TriggerEvent [timestamp=Tue Dec 06 13:00:00 CET 2011]
How is this possible? How can I achieve my goal?
(I'm currently using Drools 5.3.0 final.)
Cheers
Marco Mojana
------------------------------------------------------------------------
package com.sample;
import java.sql.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.drools.KnowledgeBase;
import org.drools.KnowledgeBaseConfiguration;
import org.drools.KnowledgeBaseFactory;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderError;
import org.drools.builder.KnowledgeBuilderErrors;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.conf.EventProcessingOption;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.KnowledgeSessionConfiguration;
import org.drools.runtime.StatefulKnowledgeSession;
import org.drools.runtime.conf.ClockTypeOption;
import org.drools.runtime.rule.WorkingMemoryEntryPoint;
public class DroolsTest {
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
final KnowledgeSessionConfiguration sessionConfig =
KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
sessionConfig.setOption(ClockTypeOption.get("realtime"));
StatefulKnowledgeSession ksession =
kbase.newStatefulKnowledgeSession(sessionConfig, null);
WorkingMemoryEntryPoint eventStream =
ksession.getWorkingMemoryEntryPoint("EventStream");
KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
// Insert events
eventStream.insert(new InhibitEvent(new GregorianCalendar(2011,
Calendar.DECEMBER, 6, 12, 0, 0).getTime()));
eventStream.insert(new TriggerEvent(new GregorianCalendar(2011,
Calendar.DECEMBER, 6, 13, 0, 0).getTime()));
eventStream.insert(new InhibitEvent(new GregorianCalendar(2011,
Calendar.DECEMBER, 6, 14, 0, 0).getTime()));
eventStream.insert(new TriggerEvent(new GregorianCalendar(2011,
Calendar.DECEMBER, 6, 14, 10, 0).getTime()));
eventStream.insert(new InhibitEvent(new GregorianCalendar(2011,
Calendar.DECEMBER, 6, 14, 20, 0).getTime()));
ksession.fireAllRules();
ksession.dispose();
logger.close();
} catch (Throwable t) {
t.printStackTrace();
}
}
private static KnowledgeBase readKnowledgeBase() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("Rules.drl"),
ResourceType.DRL);
KnowledgeBuilderErrors errors = kbuilder.getErrors();
if (errors.size() > 0) {
for (KnowledgeBuilderError error: errors) {
System.err.println(error);
}
throw new IllegalArgumentException("Could not parse knowledge.");
}
final KnowledgeBaseConfiguration kbConfig =
KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbConfig.setOption(EventProcessingOption.STREAM);
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(kbConfig);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
return kbase;
}
}
------------------------------------------------------------------------
package com.sample;
import java.util.Date;
public class TriggerEvent {
private final Date timestamp;
public TriggerEvent(final Date timestamp) {
this.timestamp = timestamp;
}
public Date getTimestamp() {
return timestamp;
}
@Override
public String toString() {
return "TriggerEvent [timestamp=" + timestamp + "]";
}
}
------------------------------------------------------------------------
package com.sample;
import java.util.Date;
public class InhibitEvent {
private final Date timestamp;
public InhibitEvent(final Date timestamp) {
this.timestamp = timestamp;
}
public Date getTimestamp() {
return timestamp;
}
@Override
public String toString() {
return "InhibitEvent [timestamp=" + timestamp + "]";
}
}
------------------------------------------------------------------------
package com.sample
declare InhibitEvent
@role(event)
@timestamp(timestamp)
end
declare TriggerEvent
@role(event)
@timestamp(timestamp)
end
rule "EventNotInhibited"
dialect "mvel"
when
not( InhibitEvent() over window:time(1h) from entry-point EventStream )
$e0 : TriggerEvent() over window:time(1h) from entry-point EventStream
then
System.err.println("Found " + $e0);
end
------------------------------------------------------------------------
--
View this message in context: http://drools.46999.n3.nabble.com/Sliding-window-behavior-in-stream-mode-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
[MVEL] the data converter does not work
by kapokfly
Can someone tell why the data converter does not work at all and what is the
reason we make the data converter to value assignment statement only?
public void testDataConverter() throws Exception {
OptimizerFactory.setDefaultOptimizer(OptimizerFactory.SAFE_REFLECTIVE);
DataConversion.addConversionHandler(Date.class, new MyDateConverter());
Locale.setDefault(Locale.US);
Cheese cheese = new Cheese();
cheese.setUseBy(new
SimpleDateFormat("dd-MMM-yyyy").parse("10-Jul-1974"));
Map<String, Object> variables = new HashMap<String, Object>();
variables.put("cheese", cheese);
Serializable compiledExpression = MVEL.compileExpression("cheese.useBy
== '10-Jul-1974'");
boolean result = MVEL.executeExpression(compiledExpression, variables,
Boolean.class);
assertTrue(result);
}
Here is what I can see from the code, at the end this method will be called,
would it be nice to allow the data converter here?
private static Boolean safeEquals(final Object val1, final Object val2)
{
if (val1 != null) {
return val1.equals(val2) ? Boolean.TRUE : Boolean.FALSE;
}
else return val2 == null || (val2.equals(val1) ? Boolean.TRUE :
Boolean.FALSE);
}
-----
Ivan, your Panda, forever
--
View this message in context: http://drools.46999.n3.nabble.com/MVEL-the-data-converter-does-not-work-t...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
Temporal operators for point-in-time events
by Mike Melton
Apologies for the stupid question, but I haven't seen anything in the
documentation regarding this and I want to verify my solution. Say I
have a point-in-time event (i.e., duration of 0) that I want to
correlate to another point-in-time event. I want a rule that will
activate if the timestamp of one is greater than or equal to the
other, basically "after or coincides". I wrote a test using the
following rule and it seemed to work:
rule "Greater Than or Equal"
when
$e1 : TestEvent( $id : id )
$e2 : TestEvent( id != id, this after[0ms] $e1 )
then
System.out.println($e2 + " is greater than or equal to " + $e1);
end
I realize this rule will fire twice if the event timestamps are equal,
but it's just for demonstration purposes; my question is specifically
about the "after[0ms]" part. Is this the way to go to accomplish what
I need? It seems so simple but I have this annoying feeling that I'm
missing something.
On a slightly related topic, is there an updated version of the
temporal operators image from the Drools Fusion homepage? It is a
great visual description of the operators and I want to print it out
and post it at my desk, but it doesn't include all of the operators.
Image: http://www.jboss.org/drools/drools-fusion/mainColumnParagraphs/02/imageBi...
>From page: http://www.jboss.org/drools/drools-fusion.html
Thanks
Mike
13 years
rules execution on Collection
by Java Bean
Hello Droolers,
Here is my Scenario:
public class Parties {
protected List<Party> party;
....
}
public class Party {
protected IdentificationGroup idGroup;
}
public class IdentificationGroup {
protected String partyType;
}
I have a collection of "Party" objects in the statefulsession. I want to
find in the collection whether there is a partyType of "SELLER" .
In Object Graph notation it will be something like
Parites[0].idGroup.partyType is "SELLER". If not found execute the
consequence.
Your help is very much appreciated.
13 years
Stateless session in drools server keeping classes around?
by dunnlow
Hi, I'm using drolls 5.3 server with one rule in a _stateless_ session. I am
sending a POJO to the server, having it check a few attributes, modify the
attributes of the bean as needed then return the result. I have this
working and get back an execution results object like I need.
The problem is that when I send the batch execution command to the server a
number of classes stick around with each call (as shown in jconsole).
Memory grows with each call until I run out. (I see garbage collection
taking place so that doesnt seem to be the problem - and if I stop sending
events to the server, the memory is never returned).
I figured with a stateless session I wouldnt need to worry about this,
anyone have thoughts about why this is happening? I am trying to do this
quickly, and don't want to call dispose/retract (the whole reason I'm using
stateless).
knowledge-services.xml:
<drools:ksession id="ksession1" type="stateless" kbase="kbase1"
node="node1"/>
my code that builds the command:
list cmds = new arraylist
InsertObjectCommand icmd = CommandFactory.newInsert(myBean)
icmd.setOutIdentifier("inserter")
icmd.setEntryPoint("DEFAULT")
cmds.add(icmd)
FileAllRulesCommand farc = new FileAllRulesCommand()
cmds.add(fileAllRulesCommand)
BatchExecutionCommand command =
CommandFactory.newBatchExecution(cmds,"ksession1")
..
As an aside, I also looked into setting the sequential mode to true to see
if that helps, but am still trying to figure out how to configure that via
Spring.
Thanks for any insight,
-j
--
View this message in context: http://drools.46999.n3.nabble.com/Stateless-session-in-drools-server-keep...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years
Drools 4.0.7 - Serialization of Rules and Facts
by Ryan
I've inherited a rule engine implementation based on Drools 4.0.7 in
which we're seeing a portion of rules failing to fire after we
serialize then deserialize rules and facts across the restart of our
application server.
Here is our current implementation:
serialization
===========
1. All facts are persisted to database tables from Events received via
an implementation of WorkingMemoryEventListener
2. All Rules are persisted to database tables as a collection of rule
"arguments"
deserialization
============
after an app server restart, a new RuleBase is created, and
RuleBase.newStatefulSession() is called
1. Rule "arguments" from db table are passed to an in-memory process
that writes a plain text DRL file
2. DRL string is built to a Package, then installed as a new rule
within the RuleBase
3. each individual fact is loaded from db table and inserted into the
newly created working memory (StatefulSession)
I do not believe this is a valid way of de/serialization. Reading the
tests that ship with Drools 4.0.7, as well as the documentation, it
seems the proper way is to use Java object serialization with both the
RuleBase and WorkingMemory - is that correct?
Assuming that my current serialization is incorrect, I'm investigating
how best to repopulate the newly created RuleBase and working memory
so that rules reliably fire. What I am seeing is that rules do not
fire in a non-deterministic fashion after repopulating the new working
memory as described above. Are there any suggestions for other paths
to attempt?
Thanks in advance for any help,
Ryan
13 years
Can Drools supply large Knowledge Base?
by WangRamon
Hi All I'm new to Drools, I will build a very large Knowledge Base, let's say it will be larger than 100GB, the files will be stored in a distribute database, so can Droools supply this large Knowledge Base? Any solution? Thank you very much. CheersRamon
13 years