Maps in Drools
by KDR
Hi, I'm relatively new to both Java and Drools. I'm trying to figure out how
to use maps in Drools. I've looked at the thread
http://www.mail-archive.com/rules-users@lists.jboss.org/msg09802.html
>From what I've read generally it seems best to insert objects directly
rather than use nested accessors. So I've been experimenting with trying to
insert a map and then checking stuff in it.
I set up a simple test map of String to Integer, with just "a" as key and 1
as value, and "b" with 2.
Map<String, Integer> map = new HashMap<String, Integer>();
map.put("a", 1);
map.put("b", 2);
String a = "a";
I then inserted the map and also inserted the String a of value "a".
Here's the test rule, with various things I tried commented out:
rule "testing maps"
dialect "mvel"
when
$str: String()
// $m: Map( this[$str] == 1 ) # error
// $m: Map( this.$str == 1 ) # error
// $m: Map( this["$str"] == 1 ) # compiles but rule won't fire
$m: Map( this["a"] == 1 ) # this works however!
then
System.out.println($m[$str]); #also works with String and Map objects & no
conditions
end
It obviously doesn't like it when I try to use the String object as the key
for the map. But it works when I use a String literal as the key. What am I
doing wrong?
Does anyone have any suggestions please, or shall I give up and either use
eval as mentioned in
http://www.mail-archive.com/rules-users@lists.jboss.org/msg09716.html or use
the map as a field of another object which I insert instead of the map (in
fact that was my original plan!)?
I'd also need to test for null i.e. whether a key/value pair exists for a
given String as the key.
Any thoughts would be very much appreciated.
Many thanks in advance.
--
View this message in context: http://www.nabble.com/Maps-in-Drools-tp25031348p25031348.html
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 6 months
Re: [rules-users] rules-users Digest, Vol 33, Issue 60
by Nilima R
Hi
I am new to Drools have developed one project using jsp,servlet and drools
.But there is some problem the rule file don't get called .I have attached
the project in zip format.Could you please let me know the cause of the
problem.
Thanks
Nilima Rajendra Raichandani
Tata Consultancy Services
Mailto: nilima.r(a)tcs.com
Website: http://www.tcs.com
____________________________________________
Experience certainty. IT Services
Business Solutions
Outsourcing
____________________________________________
rules-users-request(a)lists.jboss.org
Sent by: rules-users-bounces(a)lists.jboss.org
08/21/2009 06:17 PM
Please respond to
rules-users(a)lists.jboss.org
To
rules-users(a)lists.jboss.org
cc
Subject
rules-users Digest, Vol 33, Issue 60
Send rules-users mailing list submissions to
rules-users(a)lists.jboss.org
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.jboss.org/mailman/listinfo/rules-users
or, via email, send a message with subject or body 'help' to
rules-users-request(a)lists.jboss.org
You can reach the person managing the list at
rules-users-owner(a)lists.jboss.org
When replying, please edit your Subject line so it is more specific
than "Re: Contents of rules-users digest..."
Today's Topics:
1. Re: "extends" in rules (Chandana Pingle)
2. RuleML-2009: Second Call for Submissions to the 2009 Rules
Challenge (Wolfgang Laun)
3. Drool Flow persistence Doubt (Pardeep.Ruhil(a)lntinfotech.com)
4. Re: Maps in Drools (Edson Tirelli)
----------------------------------------------------------------------
Message: 1
Date: Fri, 21 Aug 2009 13:22:20 +1000
From: Chandana Pingle <chandana.pingle(a)intunity.com.au>
Subject: Re: [rules-users] "extends" in rules
To: Rules Users List <rules-users(a)lists.jboss.org>
Message-ID:
<c93048200908202022g5411cd71s306b5ea9c6ff4193(a)mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Thanks for ur reply
That works if i put everthing in one rule.
When using extends and trying to access the variable in RHS of sub rule
error in the editor is
Builder Error:Internal Error:Unable to find declaration in list while
generating the consequence invoker
Thanks
Chandana
On 8/21/09, mrhoden(a)franklinamerican.com <mrhoden(a)franklinamerican.com>
wrote:
> It should work fine, the entire LHS is basically copied to the second
> rule. Just try it with it all in one rule and make sure you syntax is
> correct.
>
> -Michael
>
> On Aug 20, 2009, at 8:30 PM, Chandana Pingle
> <chandana.pingle(a)intunity.com.au
> > wrote:
>
>> Hi,
>>
>> I found an example on using "extends" to extend a rule from another
>> rule.
>> Using extends would only include the WHEN side of the rule.
>>
>> I want to use the variable defined in the parent rule in sub rule
>> ,something like below example,how do i do that?
>>
>> rule A
>> when
>> $a:String( )
>> eval($a=="abc")
>> then
>> do something
>> end
>>
>> rule B extends A
>> when
>> $b:String( )
>> $c:SomeClass()
>> then
>> $c.someMethod($a,$b) //i am not able to use $a here
>> end
>>
>>
>> Any suggestions?
>>
>> Thanks
>> Chandana
>> _______________________________________________
>> rules-users mailing list
>> rules-users(a)lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
------------------------------
Message: 2
Date: Fri, 21 Aug 2009 12:58:58 +0200
From: Wolfgang Laun <wolfgang.laun(a)gmail.com>
Subject: [rules-users] RuleML-2009: Second Call for Submissions to the
2009 Rules Challenge
To: Rules Users List <rules-users(a)lists.jboss.org>
Message-ID:
<17de7ee80908210358w416da0eck2d19ad81288a7ecf(a)mail.gmail.com>
Content-Type: text/plain; charset="windows-1252"
[Our apologies if you receive duplicates of this posting]
3rd International Rules Challenge
at
RuleML-2009
co-located with the Business Rules Forum
November 5-7 2009, Las Vegas, Nevada, USA
http://2009.ruleml.org/challenge
====================================================================
Second Call for Submissions to the 2009 Rules Challenge
====================================================================
The Rules Challenge is one of the highlights at RuleML-2009. Submissions
are bound to come to the attention of a wide audience, for reasons
outlined below. The goal of the Rules Challenge is to encourage any
work of practical relevance in the field of Rule Based Applications,
spanning the range from research to industry.
* What to submit
Submission topics may come from a wide range of the field, such as
(but not limited to) the following:
- best practice solutions, e.g., design patterns and architecture models;
- case studies and experience reports describing novel or interesting
solutions and use cases;
- benchmarks and other evaluations of rule-based systems;
- tools for manipulating rules and related data in existing or
emerging standards (e.g., RuleML, RIF, SBVR, PRR,...) or commercial
rule-based system implementations;
- engineering methods for development and deployment of rule-based
solutions.
Authors are invited to submit original contributions of practical
relevance and technical rigor in the field.
A submission should consist of a paper (typically of 4-8 pages) describing
any theoretical foundation, implementation issues, technical details and
collected results of your work. If applicable, a demonstration program
illustrating your development would be highly valued.
* Publication and Review
Peer-reviewed papers, which must be in English, will be published
in additional special Challenge proceedings, to be published (as
CEUR proceedings www.CEUR-WS.org), along with the online publication
of your demo in the highly visible growing Rules Challenge pool
(http://ruleml-challenge.cs.nccu.edu.tw). To ensure high quality,
submitted papers will be carefully peer-reviewed by 3 PC members
based on originality, significance, technical soundness, and clarity
of exposition. A selection of revised papers from the Challenge will
be resubmitted to a special issue of a journal.
* Where to submit
The RuleML-2009 Challenge papers submission website:
http://www.easychair.org/conferences/?conf=2009ruleschallenge
Please upload all submissions as PDF files in LNCS format
(http://www.springer.de/comp/lncs/authors.html).
The RuleML-2009 Demonstration systems submission website:
http://ruleml-challenge.cs.nccu.edu.tw
Alternatively, your demo could be provided online, as a Web service,
or for downloading from a site of your choice. Links to product demos
should be password-protected: please submit a password for anonymous
login from any Web browser, giving us the permission to pass the
password on up to 5 PC members.
* Why you should participate
RuleML-2009, the 3rd International Symposium on Rules, Applications and
Interoperability in Las Vegas, Nevada, USA, is one of the most attractive
international conferences, now being in the top 100 venues for scientific
impact factor in CiteseerX. Being this year collocated with the 12th
Business Rules Forum, the world's largest Business Rules event, it is
guaranteed to bring your contribution to the attention of the widest-ever
audience.
The participants of the Challenge will have the opportunity to be part
of the latest trends in rule technology and standards development
through high-density interaction with the experts in this field.
Last, but not least - there are prestigious prizes to be won!
* Important Dates
September 4th ? submission deadline for demo papers and systems
September 15th ? notification of accepted demo papers and systems
October 22th - submission deadline for demo systems without papers
October 29th - notification of accepted demo systems without papers
MAKE RULEML-2009 YOUR SHOWCASE!
* 2009 Rules Challenge Program Committee
See Challenge website http://2009.ruleml.org/challenge.
===================================================================
About RuleML-2009
===================================================================
This year, the 3rd International Symposium on Rules, Applications and
Interoperability (RuleML-2009) takes place in Las Vegas, Nevada, USA,
collocated with the 12th Business Rules Forum, the world's largest
Business Rules event. RuleML-2009 is devoted to practical distributed
rule technologies and rule-based applications. The International
Symposium on Rules, Applications and Interoperability has evolved
from an annual series of international workshops since 2002,
international conferences in 2005 and 2006, and international symposia
since 2007, and is now in the top 100 venues for scientific impact
factor in CiteseerX (http://citeseerx.ist.psu.edu/stats/venues).
===================================================================
Supported by
===================================================================
W3C, OMG, ACM, AAAI, ECCAI, IAAIL, ACM, Belgian Business Rules Forum MIT
Sloan CIO Symposium, EPTS, BPM Forum Belgium
===================================================================
Sponsored by
===================================================================
BBN Technologies
Franz Inc
NICTA (National ICT Australia) Ltd
Corporate Semantic Web
Logic Programming Associated Ltd
ruleCore
JBoss
Modelsystems Ltd
(Sponsoring opportunities: http://2009.ruleml.org/sponsors)
===================================================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://lists.jboss.org/pipermail/rules-users/attachments/20090821/7166e3a...
------------------------------
Message: 3
Date: Fri, 21 Aug 2009 16:48:24 +0530
From: Pardeep.Ruhil(a)lntinfotech.com
Subject: [rules-users] Drool Flow persistence Doubt
To: rules-users(a)lists.jboss.org
Message-ID:
<OFB3F49208.F7425B5B-ON65257619.0036268B-65257619.003D9903(a)lntinfotech.com>
Content-Type: text/plain; charset="us-ascii"
Hi Users,
I am having a doubt regarding the Drools Workflow in my scenario.
I want to integrate Drools Flow in my application and have some doubts
regarding the
persistence of Workflow process instances.
Let suppose I have a workflow running in my application and at point
my application crashed or i restart my application. So is their way i can
restart the workflow the point it was.
If i store the process instance Id in the database, so am I able to start
my workflow process
from where it had stopped , if it is possible can you tell me the method
responsible for the same.
Please help me to get through the situation.
Thanks & Regards
Pardeep Ruhil
L&T Infotech Ltd
Mumbai
Ph: +919820283884
Larsen & Toubro Infotech Ltd.
www.Lntinfotech.com
This Document is classified as:
L&T Infotech Proprietary L&T Infotech Confidential L&T Infotech
Internal Use Only L&T Infotech General Business
This Email may contain confidential or privileged information for the
intended recipient (s) If you are not the intended recipient, please do
not use or disseminate the information, notify the sender and delete it
from your system.
______________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://lists.jboss.org/pipermail/rules-users/attachments/20090821/c683859...
------------------------------
Message: 4
Date: Fri, 21 Aug 2009 08:47:13 -0400
From: Edson Tirelli <tirelli(a)post.com>
Subject: Re: [rules-users] Maps in Drools
To: Rules Users List <rules-users(a)lists.jboss.org>
Message-ID:
<e6dd5ba30908210547w4d8f7fdex24da77138a1ae077(a)mail.gmail.com>
Content-Type: text/plain; charset="windows-1252"
Andre,
The misunderstanding here is that the LHS, except for code blocks like
"eval", "return value expressions" and "accumulate code blocks", are all
"Drools Language". When you use the "dialect" attribute in a rule or
package
you are telling the compiler what dialect (MVEL or Java) you will use
inside
these code blocks mentioned previously + the language for the RHS.
In other words:
Map( this["type"] == "Point", $x : this["x"], size == 5 )
Everything you see in the previous expression is "Drools language",
does
not matter if you set the dialect to java or mvel in the rule. It happens
that Drools uses the same map syntax as MVEL (and a lot of other scripting
languages). Also, we know, that drools implementation will resolve the
first
2 above expressions in MVEL behind the scenes, and the 3rd will be
resolved
nativelly, but that is not something users should have to worry about,
since
they are writing it in "Drools Language".
If they write an eval, THEN they need to differentiate between MVEL
and
Java according to the chosen dialect.
rule xyz
dialect "mvel"
when
eval( ...here you write MVEL code... )
then
// here you write MVEL code
end
rule xyz2
dialect "java"
when
eval( ...here you write JAVA code... )
then
// here you write JAVA code
end
[]s
Edson
2009/8/20 Andr? Thieme <address.good.until.2009.dec.14(a)justmail.de>
> Edson Tirelli schrieb:
> >
> > ooops... correct version:
> >
> > when
> > Map( this["type"] == "Point", $x : this["x"] )
> > Map( this["type"] == "Circle", this["x"] == $x )
> > then
> > end
>
> Okay, so in the mvel syntax this is possible.
> Can this also be achieved in the default rule syntax, without mvel?
>
> The mvel syntax needs to be interpreted at runtime, so my Clojure lib
> will have to output rules in Drools' native rule language.
>
> What interests me most is that first part:
> Map( this["type"] == "Point", $x : this["x"] )
>
>
> Andr?
> --
> Lisp is not dead. It?s just the URL that has changed:
> http://clojure.org/
> _______________________________________________
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://lists.jboss.org/pipermail/rules-users/attachments/20090821/b69a7d8...
------------------------------
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
End of rules-users Digest, Vol 33, Issue 60
*******************************************
ForwardSourceID:NT0001E1C6
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
16 years, 6 months
RuleML-2009: Second Call for Submissions to the 2009 Rules Challenge
by Wolfgang Laun
[Our apologies if you receive duplicates of this posting]
3rd International Rules Challenge
at
RuleML-2009
co-located with the Business Rules Forum
November 5-7 2009, Las Vegas, Nevada, USA
http://2009.ruleml.org/challenge
====================================================================
Second Call for Submissions to the 2009 Rules Challenge
====================================================================
The Rules Challenge is one of the highlights at RuleML-2009. Submissions
are bound to come to the attention of a wide audience, for reasons
outlined below. The goal of the Rules Challenge is to encourage any
work of practical relevance in the field of Rule Based Applications,
spanning the range from research to industry.
* What to submit
Submission topics may come from a wide range of the field, such as
(but not limited to) the following:
- best practice solutions, e.g., design patterns and architecture models;
- case studies and experience reports describing novel or interesting
solutions and use cases;
- benchmarks and other evaluations of rule-based systems;
- tools for manipulating rules and related data in existing or
emerging standards (e.g., RuleML, RIF, SBVR, PRR,...) or commercial
rule-based system implementations;
- engineering methods for development and deployment of rule-based
solutions.
Authors are invited to submit original contributions of practical
relevance and technical rigor in the field.
A submission should consist of a paper (typically of 4-8 pages) describing
any theoretical foundation, implementation issues, technical details and
collected results of your work. If applicable, a demonstration program
illustrating your development would be highly valued.
* Publication and Review
Peer-reviewed papers, which must be in English, will be published
in additional special Challenge proceedings, to be published (as
CEUR proceedings www.CEUR-WS.org), along with the online publication
of your demo in the highly visible growing Rules Challenge pool
(http://ruleml-challenge.cs.nccu.edu.tw). To ensure high quality,
submitted papers will be carefully peer-reviewed by 3 PC members
based on originality, significance, technical soundness, and clarity
of exposition. A selection of revised papers from the Challenge will
be resubmitted to a special issue of a journal.
* Where to submit
The RuleML-2009 Challenge papers submission website:
http://www.easychair.org/conferences/?conf=2009ruleschallenge
Please upload all submissions as PDF files in LNCS format
(http://www.springer.de/comp/lncs/authors.html).
The RuleML-2009 Demonstration systems submission website:
http://ruleml-challenge.cs.nccu.edu.tw
Alternatively, your demo could be provided online, as a Web service,
or for downloading from a site of your choice. Links to product demos
should be password-protected: please submit a password for anonymous
login from any Web browser, giving us the permission to pass the
password on up to 5 PC members.
* Why you should participate
RuleML-2009, the 3rd International Symposium on Rules, Applications and
Interoperability in Las Vegas, Nevada, USA, is one of the most attractive
international conferences, now being in the top 100 venues for scientific
impact factor in CiteseerX. Being this year collocated with the 12th
Business Rules Forum, the world's largest Business Rules event, it is
guaranteed to bring your contribution to the attention of the widest-ever
audience.
The participants of the Challenge will have the opportunity to be part
of the latest trends in rule technology and standards development
through high-density interaction with the experts in this field.
Last, but not least - there are prestigious prizes to be won!
* Important Dates
September 4th – submission deadline for demo papers and systems
September 15th – notification of accepted demo papers and systems
October 22th - submission deadline for demo systems without papers
October 29th - notification of accepted demo systems without papers
MAKE RULEML-2009 YOUR SHOWCASE!
* 2009 Rules Challenge Program Committee
See Challenge website http://2009.ruleml.org/challenge.
===================================================================
About RuleML-2009
===================================================================
This year, the 3rd International Symposium on Rules, Applications and
Interoperability (RuleML-2009) takes place in Las Vegas, Nevada, USA,
collocated with the 12th Business Rules Forum, the world's largest
Business Rules event. RuleML-2009 is devoted to practical distributed
rule technologies and rule-based applications. The International
Symposium on Rules, Applications and Interoperability has evolved
from an annual series of international workshops since 2002,
international conferences in 2005 and 2006, and international symposia
since 2007, and is now in the top 100 venues for scientific impact
factor in CiteseerX (http://citeseerx.ist.psu.edu/stats/venues).
===================================================================
Supported by
===================================================================
W3C, OMG, ACM, AAAI, ECCAI, IAAIL, ACM, Belgian Business Rules Forum MIT
Sloan CIO Symposium, EPTS, BPM Forum Belgium
===================================================================
Sponsored by
===================================================================
BBN Technologies
Franz Inc
NICTA (National ICT Australia) Ltd
Corporate Semantic Web
Logic Programming Associated Ltd
ruleCore
JBoss
Modelsystems Ltd
(Sponsoring opportunities: http://2009.ruleml.org/sponsors)
===================================================================
16 years, 6 months
Re: [rules-users] when condition on multiple facts of the same type
by Greg Barton
Doesn't seem to be a problem. See attached project.
--- On Mon, 8/17/09, Justin King <justin.matthew.king(a)gmail.com> wrote:
> From: Justin King <justin.matthew.king(a)gmail.com>
> Subject: [rules-users] when condition on multiple facts of the same type
> To: "Rules Users List" <rules-users(a)lists.jboss.org>
> Date: Monday, August 17, 2009, 8:24 PM
> I'm trying to have a rule execute based
> on the following condition:
>
> ObligationComplianceEvent(term == "term
> 1", obligation == "obligation 1", level ==
> 1)
> ObligationComplianceEvent(term == "term
> 2", obligation == "obligation 1", level ==
> 1)
>
>
> I pass in two facts of type ObligationComplianceEvent with
> the values shown above but the rule does not execute. It
> only executes if I put an 'or' like so
>
> ObligationComplianceEvent(term == "term
> 1", obligation == "obligation 1", level == 1)
> or
>
>
> ObligationComplianceEvent(term == "term
> 2", obligation == "obligation 1", level ==
> 1)
>
> Any help on what the correct way to do this is? I'm
> guessing its because it does not distinguish the two lines
> as two different facts, so because neither of the facts has
> the value 'term 1' and 'term 2' it never
> executes.
>
>
> Thanks for any help.
>
> Justin
>
>
> -----Inline Attachment Follows-----
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
16 years, 6 months
Here is a ResultSetCompiler for drools-templates
by Bill Tarr
I’ve been trying out the DROOLS-TEMPLATES project, really impressed so far, surprised there isn’t more buzz about this project.
I wrote a new version of the DataProviderCompiler that takes a SQL ResultSet instead of a org.drools.template.DataProvider.
I don’t think it will be useful to that many people, so I’m not going to try and add it to the code base, but I’ll provide it here. I used it for testing out templates, but for our actual production code, I will naturally be using Hibernate to retrieve the rules from the DB (so I can take advantage of Hibernate cache.) It is much quicker to set up a template test with this compiler though.
It also allows you to put the data in whatever types you like in the database, as long as you add a String converter for that type in processData(), like:
<pre>
case java.sql.Types.DOUBLE:
cell = String.valueOf(rs.getInt(cellNum));
break;
</pre>
Calling Code (based on drools-examples\drools-examples-drl\src\main\java\org\drools\examples\DataDrivenTemplateExample.java)
<pre>
ResultSet rs;
try {
Statement sta = conn.createStatement();
rs = sta.executeQuery("SELECT * FROM RulePricingPolicy");
// TODO: you need to catch or handle
} catch (SQLException e) {
}
final ResultSetCompiler converter = new ResultSetCompiler();
final String drl = converter.compile(rs, getTemplate());
</pre>
Here is the ResultSet Compiler:
<pre>
import org.drools.template.parser.TemplateContainer;
import org.drools.template.parser.DefaultTemplateContainer;
import org.drools.template.parser.TemplateDataListener;
import org.drools.template.parser.DataListener;
import java.io.InputStream;
import java.util.List;
import java.util.ArrayList;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
/**
* <p> A Drools template compiler which takes a ResultSet and compiles it into
* a template using DefaultTemplateContainer.
* </p>
*
* @author bxt, Aug 19, 2009 1:53:38 PM
* <br>
* Copyright © 2008 Customized Services Administrators, Inc.
* All Rights Reserved.
*/
public class ResultSetCompiler {
/**
* Generates DRL from a data provider for the spreadsheet data and templates.
*
* @param rs the resultset for the table data
* @param template the string containing the template resource name
* @return the generated DRL text as a String
*/
public String compile(final ResultSet rs,
final String template) {
final InputStream templateStream = this.getClass().getResourceAsStream(template);
return compile(rs,
templateStream);
}
/**
* Generates DRL from a data provider for the spreadsheet data and templates.
*
* @param rs the resultset for the table data
* @param templateStream the InputStream for reading the templates
* @return the generated DRL text as a String
*/
public String compile(final ResultSet rs,
final InputStream templateStream) {
TemplateContainer tc = new DefaultTemplateContainer(templateStream);
closeStream(templateStream);
return compile(rs,
new TemplateDataListener(tc));
}
/**
* Generates DRL from a data provider for the spreadsheet data and templates.
*
* @param rs the resultset for the table data
* @param listener a template data listener
* @return the generated DRL text as a String
*/
public String compile(final ResultSet rs,
final TemplateDataListener listener) {
List<DataListener> listeners = new ArrayList<DataListener>();
listeners.add(listener);
processData(rs,
listeners);
return listener.renderDRL();
}
/**
* Iterate through the resultset.
* @param rs the resultset for the table data
* @param listeners list of template data listener
*/
private void processData(final ResultSet rs,
List<DataListener> listeners) {
try {
ResultSetMetaData rsmd = rs.getMetaData();
int colCount = rsmd.getColumnCount();
int i = 0;
while (rs.next()) {
newRow(listeners, i, colCount);
for (int cellNum = 1; cellNum < colCount + 1; cellNum++) {
String cell;
int sqlType = rsmd.getColumnType(cellNum);
switch (sqlType) {
case java.sql.Types.DATE:
cell = rs.getDate(cellNum).toString();
break;
case java.sql.Types.INTEGER:
case java.sql.Types.DOUBLE:
cell = String.valueOf(rs.getInt(cellNum));
break;
default:
cell = rs.getString(cellNum);
}
newCell(listeners,
i,
cellNum -1,
cell,
DataListener.NON_MERGED);
}
i++;
}
//TODO: you need to throw or handle
} catch (SQLException e) {
}
finishData(listeners);
}
private void finishData(List<DataListener> listeners) {
for (DataListener listener : listeners) {
listener.finishSheet();
}
}
private void newRow(List<DataListener> listeners,
int row,
int cols) {
for (DataListener listener : listeners) {
listener.newRow(row,
cols);
}
}
public void newCell(List<DataListener> listeners,
int row,
int column,
String value,
int mergedColStart) {
for (DataListener listener : listeners) {
listener.newCell(row,
column,
value,
mergedColStart);
}
}
protected void closeStream(final InputStream stream) {
try {
stream.close();
} catch (final Exception e) {
System.err.print("WARNING: Wasn't able to correctly close stream for rule template. " + e.getMessage());
}
}
}
</pre>
16 years, 6 months
Drools and Clojure (maps as facts)
by André Thieme
Hello group!
I am a Clojure user and would like to look into using Drools with it.
From Clojure I can use all Java classes and call all methods. So,
instantiating a KnowledgeBase, KnowledgePackages or a KBFactory is no
problem, and calling the respective methods, to get the system started,
or insert facts into a session, dispose it and fireAllRules is also
fine.
It is just that in Clojure one typically does not use POJOs.
The most typical data structures used are: hashmaps, vectors, structs,
lists, structuremaps and sets (in no particular order).
Those are persistent and "concurrency ready" Clojure DSs, and btw, also
usable from Java directly.
Now the basic Drools examples I saw all work with POJOs.
They were mostly comparisons of native typed fields in a class.
I however would be interested to compare different qualities of key/
value pairs in a hashmap, or compare structs with each other.
Comparing structuremaps is maybe what comes closest to the POJO examples.
For example, we may have a struct (defstruct person :name :age :type)
and store it's instances in a vector. And we would also insert it into
our Drools session object:
(doseq [p all-persons] (.insert session p))
which would correspond roughly to
for (Person p : allPersons) { session.insert(p); }
Only that "person" is a map, not a class.
Well, of course it is also an object and under the hood a class, a
java.util.Map even - but I mean that unlike POJOs the key/value pairs
are stored differently (fields in classes are also just key/value pairs).
So, is there a way to insert maps (let it be java.util.HashMaps for
example) and also to reason about them? I won't care if the syntax
for that is complicated. As Clojure is a Lisp I would just write a
little macro and have a very nice and readable syntax (probably a bit
similar to the one of Jess or Lisa).
Instead of looking at all instances of the type Person AND then have
their age compared, I would look at all maps/structs which have a key
:type with the value :person AND then compare the value of their :age
key with a number, such as:
(rule "example person rule, matching non-adults"
:when (= :type :person)
(< :age 18)
:then
(println "No service for minors."))
In Java terms it would mean that we insert several instances of
java.util.HashMap, all having the k/v pairs for name, age and type.
HashMap<String, Object> hm = new HashMap<String, Object>();
hm.put("name", someName);
hm.put("age", someAge);
hm.put("type", "person");
session.insert(hm);
Is that in principle possible with Drools 5?
Sunny greetings,
André
--
Lisp is not dead. It’s just the URL that has changed:
http://clojure.org/
16 years, 6 months
Drools library - updating Drools jar
by KDR
Thanks to Edson and André for the very interesting discussion on maps in
Drools. :) I suspect my follow up question got a bit buried in that thread
and probably is a separate topic anyway, so I hope you don't mind my asking
this newbie question in a new thread.
All Drools projects created in Eclipse with the Drools plugin have a Drools
library associated with them, which shows up as a Drools Library entry on
the left in both project/package explorer, and in the project properties for
the project - in the Libraries tab for the project properties' Java Build
Path.
My question is, how do you get Eclipse to recognise an updated jar in the
Drools library please? Or perhaps it should be, how do you get Drools to
recognise an update to a jar which it uses?
Edson said in the other thread that I need to update my mvel jar to 2.0.12.
I can only find 2.0.13 but no doubt that's also got the maps bugfix.
However where I'm stuck is how get the Drools projects to use the updated
jar. I've copied the 2.0.13 jar to the Drools runtime folder on my computer
(both top level and subfolder). I've tried to add the 2.0.13 jar to the Java
build path for the project as an external jar. I've tried to create a fresh
Drools project in Eclipse. I've restarted Eclipse with -clean. The map issue
is still there, and the Drools library for the Drools projects still don't
even show 2.0.13 in the list of jars - just 2.0.10. I'm sure the crux of it
is that somewhere Drools has been told to use 2.0.10, and I don't know how
to tell it otherwise.
I'm sure it's a really easy thing to do if you know how, but I've tried
everything I can think of and am totally at a loss as to what to try next.
(Probably try to rename 2.0.13 to 2.0.10, delete or rename the old 2.0.10
and restart Eclipse?).
Would some kind person be able to point me in the right direction please?
I'm trying to think of a workaround for my project that doesn't use maps,
but ideally maps would be the best way. I'm willing to offer a box of
chocolates or a bottle of wine or beer whatever your poison of choice, if
blatant bribes will help! :D
Many thanks. Any suggestions at all would be most appreciated.
--
View this message in context: http://www.nabble.com/Drools-library---updating-Drools-jar-tp25057905p250...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 6 months
Using "in" in Guvnor's Guided Rule Editor
by Steve Ronderos
Hello Rules Users,
I think I've seen a message about this before, but I can not find it.
We make heavy use of the "in" keyword in our current DRL rules files. We
are trying to start using Guvnor and its Guided Rule Editor. Is there a
way to use "in" in the Guided Rule Editor, other than by adding free form
DRL? If there is not a way, can anyone propose another way to accomplish
the same goal?
Also if you can't use "in" in the Guided Rule Editor, is there an open
feature request?
Thanks,
Steve Ronderos
16 years, 6 months
how to use xml file instead of java object ?
by tv.raghavan
I remember seeing a sample in jboss-esb sample where they were able to use
xpath to query a xml file
[sample extract]
package com.jboss.soa.esb.routing.cbr
#list any import classes here.
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageType;
expander XPathLanguage.dsl
#declare any global variables here
global java.util.List destinations;
rule "Blue Routing Rule using XPATH"
when
xpathEquals "/Order/@statusCode", "0"
then
Log : "Blue Team";
Destination : "blue";
end
Is it possible to use this approach to use a xml as input to drool vs java
object ?
Thanks,
-Raghav
--
View this message in context: http://www.nabble.com/how-to-use-xml-file-instead-of-java-object---tp2502...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 6 months
Decision table problem
by Alex Esmann
Hey
I am using drools with a decision table (XLS). One of the conditions in
the table is a call to a java method, c.checkFoo($1,$2)), where c is of
type Foo. When I first created this method it took 2 integers and that
worked fine, now I need to update it to take to strings instead. I have
updated the method but when trying to it I get some errors.
Some examples of values in the cells for this condition are
[ 901, 910 ]
[ 90AAA, 90ABC]
For the first value I get this error:
The method checkFoo(String, String) in the type Foo is not applicable
for the arguments (int, int)
For the second value I get this error:
The method checkFoo(String, String) in the type Foo is not applicable
for the arguments (int, int)
Syntax error on token "AAA", delete this token
Syntax error on token "AAC", delete this token
How do I convince drools that the values in the cells should be read as
strings and not integers?
Kind Regards
Alex
16 years, 6 months