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();
}
}
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;
}
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;
}
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;
}
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));
}
Aggregations