You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Andrea Zoppello <zo...@tiscali.it> on 2007/04/04 15:08:25 UTC

Drools 31 Endpoint Enhancements

Hi Guillaume,

I've made two simple enhancements to Drools31 Component, due to enable 
some check
against one of the datasource defined in smx.

1) First of all i added a org.apache.servicemix.drools.model.DbHelper 
class with two methods*:

            public boolean exist(<value>, <valueType>, <tableName>, 
<field_name>,<connectionName>)*

this method checks if there are one or more row in tableName where 
table.fieldName = value on the datasource named connectionName

*            public boolean existOne(<value>, <valueType>, <tableName>, 
<field_name>,<connectionName>)*

this method check if there ate exactly one ad no more than one row in 
tableName where table.fieldName = value on the datasource named 
connectionName

2) To use this method against arbitrary message content i need a method 
to extract values from xptah so i've modify the class 
org.apache.servicemix.drools.model.Message and i added the following method:

 public String valueOf(String xpath) throws Exception {
        JAXPStringXPathExpression expression = new 
JAXPStringXPathExpression(xpath);
        String res = (String)expression.evaluate(null, message);
        return res;

3) The DbHelper Object is asserted in memory, it is not global.

Finally in my drools file i'm able to write rules similar to:

rule "RuleNum1"
    when
        me : Exchange( status == Exchange.ACTIVE, in : in != null );
        db : DbHelper ( );
        eval( db.exist( in.valueOf("/ACTION/@nome"), "STRING", 
"attributes", "name", "metadb" ) );
    then
        jbi.fault( "<ERROR>value is in table </ERROR>" );
    end


I don't know if this can be utils to smx community. If so i can 
contribute my code.

Cheers
Andrea Zoppello