Skip to content

Commit

Permalink
DROOLS-1458: fixing compilation of BKM Nodes that depend on other BKM…
Browse files Browse the repository at this point in the history
… nodes (apache#47)
  • Loading branch information
etirelli authored Mar 1, 2017
1 parent 58b890e commit 3ff4716
Show file tree
Hide file tree
Showing 3 changed files with 383 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,22 @@ private void processDrgElements(DMNCompilerContext ctx, DMNFEELHelper feel, DMNM
for ( BusinessKnowledgeModelNode bkm : model.getBusinessKnowledgeModels() ) {
BusinessKnowledgeModelNodeImpl bkmi = (BusinessKnowledgeModelNodeImpl) bkm;
linkRequirements( model, bkmi );
FunctionDefinition funcDef = bkm.getBusinessKnowledModel().getEncapsulatedLogic();
DMNExpressionEvaluator exprEvaluator = evaluatorCompiler.compileExpression( ctx, model, bkmi, bkm.getName(), funcDef );
bkmi.setEvaluator( exprEvaluator );

ctx.enterFrame();
try {
for( DMNNode dep : bkmi.getDependencies().values() ) {
if( dep instanceof BusinessKnowledgeModelNode ) {
// might need to create a DMNType for "functions" and replace the type here by that
ctx.setVariable( dep.getName(), ((BusinessKnowledgeModelNode)dep).getResultType() );
}
}
FunctionDefinition funcDef = bkm.getBusinessKnowledModel().getEncapsulatedLogic();
DMNExpressionEvaluator exprEvaluator = evaluatorCompiler.compileExpression( ctx, model, bkmi, bkm.getName(), funcDef );
bkmi.setEvaluator( exprEvaluator );
} finally {
ctx.exitFrame();
}

}
for ( DecisionNode d : model.getDecisions() ) {
DecisionNodeImpl di = (DecisionNodeImpl) d;
Expand Down
14 changes: 14 additions & 0 deletions kie-dmn-core/src/test/java/org/kie/dmn/core/DMNRuntimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,20 @@ public void testDTUsingEqualsUnaryTestWithVariable2() {
assertThat( result.get( "Compare String" ), is( "Different String" ) );
}

@Test
public void testLoanComparison() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime( "loanComparison.dmn", this.getClass() );
DMNModel dmnModel = runtime.getModel( "http://www.trisotech.com/definitions/_3a1fd8f4-ea04-4453-aa30-ff14140e3441", "loanComparison" );
assertThat( dmnModel, notNullValue() );
assertThat( formatMessages( dmnModel.getMessages() ), dmnModel.hasErrors(), is( false ) );

DMNContext context = DMNFactory.newContext();
context.set( "RequestedAmt", 500000 );

DMNResult dmnResult = runtime.evaluateAll( dmnModel, context );
assertThat( formatMessages( dmnResult.getMessages() ), dmnResult.hasErrors(), is( false ) );
}

@Test
public void testGetViableLoanProducts() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime( "Get_Viable_Loan_Products.dmn", this.getClass() );
Expand Down
Loading

0 comments on commit 3ff4716

Please sign in to comment.