Problems trying to get simple tRules implementation working

Highlighted
One Star

Problems trying to get simple tRules implementation working

Hi
I am looking at what is involved in using the tRules component and I am getting run time errors.
I created the rule in Guvnor (not the one integrated into TAC) and added it to the meta data section of Talend under the Embeded Rules following the steps in the User Guide. The rule looks like this.
package Account
import dave.test.Account
rule "loan_OK"
dialect "mvel"
when
Account( age > "18" )
then
Account fact0 = new Account();
fact0.setCurrent_Ballance( 1000 );
insert(fact0 );
end

The error I get is



^

at org.mvel2.compiler.AbstractParser.procTypedNode(AbstractParser.java:1278)
at org.mvel2.compiler.AbstractParser.nextToken(AbstractParser.java:712)
at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:106)
at org.mvel2.compiler.ExpressionCompiler.compile(ExpressionCompiler.java:55)
at org.drools.rule.builder.dialect.mvel.MVELExprAnalyzer.analyzeExpression(MVELExprAnalyzer.java:86)
at org.drools.rule.builder.dialect.mvel.MVELDialect.analyzeBlock(MVELDialect.java:492)
at org.drools.rule.builder.dialect.mvel.MVELConsequenceBuilder.build(MVELConsequenceBuilder.java:84)
at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:86)
at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:1159)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:649)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:290)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:488)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:25)
at dev.rules_0_1.Rules$1KnowledgeBase_tRules_2.readKnowledgeBaseDRL(Rules.java:991)
at dev.rules_0_1.Rules$1KnowledgeBase_tRules_2.readKnowledgeBase(Rules.java:980)
at dev.rules_0_1.Rules.tRowGenerator_1Process(Rules.java:1044)
at dev.rules_0_1.Rules.runJobInTOS(Rules.java:3919)
at dev.rules_0_1.Rules.main(Rules.java:3726)
Unable to resolve ObjectType 'Account' :

Unable to build expression for 'consequence': unknown class or illegal statement: Account 'Account fact0 = new Account();
fact0.setCurrent_Ballance( 1000 );
insert(fact0 );
' :

Error importing : 'dave.test.Account'
Exception in component tRules_2
java.lang.IllegalArgumentException: Could not parse knowledge.
at dev.rules_0_1.Rules$1KnowledgeBase_tRules_2.readKnowledgeBaseDRL(Rules.java:1000)
at dev.rules_0_1.Rules$1KnowledgeBase_tRules_2.readKnowledgeBase(Rules.java:980)
at dev.rules_0_1.Rules.tRowGenerator_1Process(Rules.java:1044)
at dev.rules_0_1.Rules.runJobInTOS(Rules.java:3919)
at dev.rules_0_1.Rules.main(Rules.java:3726)

I simplified the rule by hand in Talend to
package Account
import dave.test.Account
rule "loan_OK"
dialect "mvel"
when
Account( age > "18" )
then
System.out.println("Customer is full age");
end

I then get the error

Unable to resolve ObjectType 'Account' :
Error importing : 'dave.test.Account'
Exception in component tRules_2
java.lang.IllegalArgumentException: Could not parse knowledge.
at dev.rules_0_1.Rules$1KnowledgeBase_tRules_2.readKnowledgeBaseDRL(Rules.java:1000)
at dev.rules_0_1.Rules$1KnowledgeBase_tRules_2.readKnowledgeBase(Rules.java:980)
at dev.rules_0_1.Rules.tRowGenerator_1Process(Rules.java:1044)
at dev.rules_0_1.Rules.runJobInTOS(Rules.java:3919)
at dev.rules_0_1.Rules.main(Rules.java:3726)

It looks like it can not find the imported class Account, Have I missed somthing when setting up the rule?
Many thanks in advance Dave
One Star

Re: Problems trying to get simple tRules implementation working

Hi
I added a tLibraryLoad component to load the jar with the class in it and it stopped the error "importing dave.test.Account" error. But I now get the following error.

Exception in component tRules_1
java.lang.RuntimeException: Unexpected global
    at org.drools.common.AbstractWorkingMemory.setGlobal(AbstractWorkingMemory.java:550)
    at org.drools.impl.StatefulKnowledgeSessionImpl.setGlobal(StatefulKnowledgeSessionImpl.java:284)
    at drools.trule_0_1.tRule.tRowGenerator_1Process(tRule.java:917)
    at drools.trule_0_1.tRule.tLibraryLoad_1Process(tRule.java:316)
    at drools.trule_0_1.tRule.runJobInTOS(tRule.java:1221)
    at drools.trule_0_1.tRule.main(tRule.java:1095)

Any ideas where to look next?
Many thanks Dave

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog