Search in sources :

Example 1 with InputDataNode

use of org.kie.dmn.api.core.ast.InputDataNode in project drools by kiegroup.

the class DecisionCompiler method compileEvaluator.

@Override
public void compileEvaluator(DMNNode node, DMNCompilerImpl compiler, DMNCompilerContext ctx, DMNModelImpl model) {
    DecisionNodeImpl di = (DecisionNodeImpl) node;
    compiler.linkRequirements(model, di);
    ctx.enterFrame();
    try {
        Map<String, DMNType> importedTypes = new HashMap<>();
        for (DMNNode dep : di.getDependencies().values()) {
            if (dep instanceof DecisionNode) {
                ctx.setVariable(dep.getName(), ((DecisionNode) dep).getResultType());
            } else if (dep instanceof InputDataNode) {
                ctx.setVariable(dep.getName(), ((InputDataNode) dep).getType());
            } else if (dep instanceof BusinessKnowledgeModelNode) {
                if (dep.getModelNamespace().equals(model.getNamespace())) {
                    // might need to create a DMNType for "functions" and replace the type here by that
                    ctx.setVariable(dep.getName(), ((BusinessKnowledgeModelNode) dep).getResultType());
                } else {
                    // then the BKM dependency is an imported BKM.
                    Optional<String> alias = model.getImportAliasFor(dep.getModelNamespace(), dep.getModelName());
                    if (alias.isPresent()) {
                        CompositeTypeImpl importedComposite = (CompositeTypeImpl) importedTypes.computeIfAbsent(alias.get(), a -> new CompositeTypeImpl());
                        importedComposite.addField(dep.getName(), ((BusinessKnowledgeModelNode) dep).getResultType());
                    }
                }
            }
        }
        for (Entry<String, DMNType> importedType : importedTypes.entrySet()) {
            ctx.setVariable(importedType.getKey(), importedType.getValue());
        }
        DMNExpressionEvaluator evaluator = compiler.getEvaluatorCompiler().compileExpression(ctx, model, di, di.getName(), di.getDecision().getExpression());
        di.setEvaluator(evaluator);
    } finally {
        ctx.exitFrame();
    }
}
Also used : DMNType(org.kie.dmn.api.core.DMNType) DMNNode(org.kie.dmn.api.core.ast.DMNNode) DMNModelImpl(org.kie.dmn.core.impl.DMNModelImpl) HashMap(java.util.HashMap) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode) Decision(org.kie.dmn.model.v1_1.Decision) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DMNExpressionEvaluator(org.kie.dmn.core.api.DMNExpressionEvaluator) Map(java.util.Map) DRGElement(org.kie.dmn.model.v1_1.DRGElement) Entry(java.util.Map.Entry) Optional(java.util.Optional) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) CompositeTypeImpl(org.kie.dmn.core.impl.CompositeTypeImpl) Msg(org.kie.dmn.core.util.Msg) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) DMNExpressionEvaluator(org.kie.dmn.core.api.DMNExpressionEvaluator) HashMap(java.util.HashMap) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) DMNNode(org.kie.dmn.api.core.ast.DMNNode) InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) CompositeTypeImpl(org.kie.dmn.core.impl.CompositeTypeImpl) DMNType(org.kie.dmn.api.core.DMNType)

Example 2 with InputDataNode

use of org.kie.dmn.api.core.ast.InputDataNode in project drools by kiegroup.

the class DMNModelImpl method getRequiredInputsForDecisionId.

@Override
public Set<InputDataNode> getRequiredInputsForDecisionId(String decisionId) {
    DecisionNodeImpl decision = (DecisionNodeImpl) getDecisionById(decisionId);
    Set<InputDataNode> inputs = new HashSet<>();
    if (decision != null) {
        collectRequiredInputs(decision.getDependencies().values(), inputs);
    }
    return inputs;
}
Also used : InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) HashSet(java.util.HashSet)

Example 3 with InputDataNode

use of org.kie.dmn.api.core.ast.InputDataNode in project drools by kiegroup.

the class DMNModelImpl method getRequiredInputsForDecisionName.

@Override
public Set<InputDataNode> getRequiredInputsForDecisionName(String decisionName) {
    DecisionNodeImpl decision = (DecisionNodeImpl) getDecisionByName(decisionName);
    Set<InputDataNode> inputs = new HashSet<>();
    if (decision != null) {
        collectRequiredInputs(decision.getDependencies().values(), inputs);
    }
    return inputs;
}
Also used : InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) HashSet(java.util.HashSet)

Example 4 with InputDataNode

use of org.kie.dmn.api.core.ast.InputDataNode in project drools by kiegroup.

the class DMNRuntimeImpl method checkDependencyValueIsValid.

private boolean checkDependencyValueIsValid(DMNNode dep, DMNResultImpl result) {
    if (dep instanceof InputDataNode) {
        InputDataNodeImpl inputDataNode = (InputDataNodeImpl) dep;
        BaseDMNTypeImpl dmnType = (BaseDMNTypeImpl) inputDataNode.getType();
        return dmnType.isAssignableValue(result.getContext().get(dep.getName()));
    }
    // if the dependency is NOT an InputData, the type coherence was checked at evaluation result assignment.
    return true;
}
Also used : InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) InputDataNodeImpl(org.kie.dmn.core.ast.InputDataNodeImpl)

Example 5 with InputDataNode

use of org.kie.dmn.api.core.ast.InputDataNode in project drools by kiegroup.

the class DMNInputRuntimeTest method testDMNInputDataNodeTypeTest.

@Test
public void testDMNInputDataNodeTypeTest() {
    // DROOLS-1569
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("DMNInputDataNodeTypeTest.dmn", this.getClass());
    final String MODEL_NAMESPACE = "http://www.trisotech.com/definitions/_17396034-163a-48aa-9a7f-c6eb17f9cc6c";
    final String FEEL_NAMESPACE = "http://www.omg.org/spec/FEEL/20140401";
    final DMNModel dmnModel = runtime.getModel(MODEL_NAMESPACE, "DMNInputDataNodeTypeTest");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    final InputDataNode idnMembership = dmnModel.getInputs().stream().filter(idn -> idn.getName().equals("Membership Level")).findFirst().get();
    assertThat(idnMembership.getType().getBaseType().getNamespace(), is(FEEL_NAMESPACE));
    assertThat(idnMembership.getType().getBaseType().getName(), is("string"));
    assertThat(idnMembership.getType().isCollection(), is(false));
    assertThat(idnMembership.getType().isComposite(), is(false));
    assertThat(idnMembership.getType().getAllowedValues().size(), is(3));
    assertThat(idnMembership.getType().getAllowedValues().get(0).toString(), is("\"Gold\""));
    assertThat(idnMembership.getType().getAllowedValues().get(1).toString(), is("\"Silver\""));
    assertThat(idnMembership.getType().getAllowedValues().get(2).toString(), is("\"None\""));
    final InputDataNode idnMembershipLevels = dmnModel.getInputs().stream().filter(idn -> idn.getName().equals("Membership Levels")).findFirst().get();
    assertThat(idnMembershipLevels.getType().getBaseType().getNamespace(), is(MODEL_NAMESPACE));
    assertThat(idnMembershipLevels.getType().getBaseType().getName(), is("tMembershipLevel"));
    assertThat(idnMembershipLevels.getType().isCollection(), is(true));
    assertThat(idnMembershipLevels.getType().isComposite(), is(false));
    assertThat(idnMembershipLevels.getType().getAllowedValues().isEmpty(), is(true));
    final InputDataNode idnPercent = dmnModel.getInputs().stream().filter(idn -> idn.getName().equals("Percent")).findFirst().get();
    assertThat(idnPercent.getType().getBaseType().getNamespace(), is(FEEL_NAMESPACE));
    assertThat(idnPercent.getType().getBaseType().getName(), is("number"));
    assertThat(idnPercent.getType().isCollection(), is(false));
    assertThat(idnPercent.getType().isComposite(), is(false));
    assertThat(idnPercent.getType().getAllowedValues().size(), is(1));
    assertThat(idnPercent.getType().getAllowedValues().get(0).toString(), is("[0..100]"));
    final InputDataNode idnCarDamageResponsibility = dmnModel.getInputs().stream().filter(idn -> idn.getName().equals("Car Damage Responsibility")).findFirst().get();
    assertThat(idnCarDamageResponsibility.getType().getBaseType(), is(nullValue()));
    assertThat(idnCarDamageResponsibility.getType().isCollection(), is(false));
    assertThat(idnCarDamageResponsibility.getType().isComposite(), is(true));
}
Also used : InputDataNode(org.kie.dmn.api.core.ast.InputDataNode) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Aggregations

InputDataNode (org.kie.dmn.api.core.ast.InputDataNode)8 Test (org.junit.Test)3 DMNModel (org.kie.dmn.api.core.DMNModel)3 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)3 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)3 HashSet (java.util.HashSet)2 BusinessKnowledgeModelNode (org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)2 DecisionNode (org.kie.dmn.api.core.ast.DecisionNode)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 DMNType (org.kie.dmn.api.core.DMNType)1 DMNNode (org.kie.dmn.api.core.ast.DMNNode)1 DMNExpressionEvaluator (org.kie.dmn.core.api.DMNExpressionEvaluator)1 InputDataNodeImpl (org.kie.dmn.core.ast.InputDataNodeImpl)1 CompositeTypeImpl (org.kie.dmn.core.impl.CompositeTypeImpl)1 DMNModelImpl (org.kie.dmn.core.impl.DMNModelImpl)1 Msg (org.kie.dmn.core.util.Msg)1 DRGElement (org.kie.dmn.model.v1_1.DRGElement)1