use of org.kie.dmn.model.v1_1.Context in project drools by kiegroup.
the class BusinessKnowledgeModelCompiler method compileEvaluator.
@Override
public void compileEvaluator(DMNNode node, DMNCompilerImpl compiler, DMNCompilerContext ctx, DMNModelImpl model) {
BusinessKnowledgeModelNodeImpl bkmi = (BusinessKnowledgeModelNodeImpl) node;
compiler.linkRequirements(model, bkmi);
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());
}
}
// to allow recursive call from inside a BKM node, a variable for self must be available for the compiler context:
ctx.setVariable(bkmi.getName(), bkmi.getResultType());
FunctionDefinition funcDef = bkmi.getBusinessKnowledModel().getEncapsulatedLogic();
DMNExpressionEvaluator exprEvaluator = compiler.getEvaluatorCompiler().compileExpression(ctx, model, bkmi, bkmi.getName(), funcDef);
bkmi.setEvaluator(exprEvaluator);
} finally {
ctx.exitFrame();
}
}
use of org.kie.dmn.model.v1_1.Context in project drools by kiegroup.
the class ValidatorContextTest method testCONTEXT_ENTRY_MISSING_VARIABLE_DefinitionsInput.
@Test
public void testCONTEXT_ENTRY_MISSING_VARIABLE_DefinitionsInput() {
final List<DMNMessage> validate = validator.validate(getDefinitions("context/CONTEXT_ENTRY_MISSING_VARIABLE.dmn", "https://github.com/kiegroup/kie-dmn", "CONTEXT_MISSING_EXPR"), VALIDATE_MODEL, VALIDATE_COMPILATION);
assertThat(ValidatorUtil.formatMessages(validate), validate.size(), is(1));
assertTrue(validate.stream().anyMatch(p -> p.getMessageType().equals(DMNMessageType.MISSING_VARIABLE)));
// check that it reports and error for the second context entry, but not for the last one
final ContextEntry ce = (ContextEntry) validate.get(0).getSourceReference();
assertThat(((Context) ce.getParent()).getContextEntry().indexOf(ce), is(1));
}
use of org.kie.dmn.model.v1_1.Context in project kie-wb-common by kiegroup.
the class ContextPropertyConverter method wbFromDMN.
public static Context wbFromDMN(final org.kie.dmn.model.v1_1.Context dmn) {
Id id = new Id(dmn.getId());
Description description = new Description(dmn.getDescription());
QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
Context result = new Context(id, description, typeRef);
for (org.kie.dmn.model.v1_1.ContextEntry ce : dmn.getContextEntry()) {
ContextEntry ceConverted = ContextEntryPropertyConverter.wbFromDMN(ce);
result.getContextEntry().add(ceConverted);
}
return result;
}
use of org.kie.dmn.model.v1_1.Context in project kie-wb-common by kiegroup.
the class ContextPropertyConverter method dmnFromWB.
public static org.kie.dmn.model.v1_1.Context dmnFromWB(final Context wb) {
org.kie.dmn.model.v1_1.Context result = new org.kie.dmn.model.v1_1.Context();
result.setId(wb.getId().getValue());
result.setDescription(wb.getDescription().getValue());
QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
for (ContextEntry ce : wb.getContextEntry()) {
org.kie.dmn.model.v1_1.ContextEntry ceConverted = ContextEntryPropertyConverter.dmnFromWB(ce);
result.getContextEntry().add(ceConverted);
}
return result;
}
use of org.kie.dmn.model.v1_1.Context in project kie-wb-common by kiegroup.
the class PMMLFunctionEditorDefinition method getModelClass.
@Override
public Optional<Context> getModelClass() {
final Context context = new Context();
final ContextEntry documentEntry = new ContextEntry();
final InformationItem documentEntryVariable = new InformationItem();
documentEntryVariable.setName(new Name(VARIABLE_DOCUMENT));
documentEntry.setVariable(documentEntryVariable);
documentEntry.setExpression(new LiteralExpression());
context.getContextEntry().add(documentEntry);
final ContextEntry modelEntry = new ContextEntry();
final InformationItem modelEntryVariable = new InformationItem();
modelEntryVariable.setName(new Name(VARIABLE_MODEL));
modelEntry.setVariable(modelEntryVariable);
modelEntry.setExpression(new LiteralExpression());
context.getContextEntry().add(modelEntry);
return Optional.of(context);
}
Aggregations