Drools Smooks Data Loader

Smooks is a powerful open source ETL tool, it can transform variety of data sources.

Drools now supports an internal model, so ideally you want to be able to load different payloads, such as XML, into this model. I’ve just added support for this and it’ll be in M2 🙂

Here is an example of the api loading an XML file into a drools session, the xml entries for OrderItem are mapped into the internal class and inserted into the given session. The matching rules simple do a print statement.

declare OrderItem
productId : long
quantity : Integer
price : double
end

rule someRule
when
$i : OrderItem()
then
System.out.println( $i );
end
PackageBuilder pkgBuilder = new PackageBuilder();
pkgBuilder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test.drl" )) );

RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkgBuilder.getPackage() );

StatefulSession session = ruleBase.newStatefulSession();

// Instantiate Smooks with the config...
Smooks smooks = new Smooks( "smooks-config.xml" );

// set rood id
DroolsSmooksConfiguration conf = new DroolsSmooksConfiguration( "root" );
DroolsSmooks loader = new DroolsSmooks( session, smooks, conf );
loader.insertFilter( new StreamSource( new ByteArrayInputStream( readInputMessage() ) ) );

session.fireAllRules();

Author

Comments are closed.