Search in sources :

Example 21 with Context

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();
    }
}
Also used : DMNExpressionEvaluator(org.kie.dmn.core.api.DMNExpressionEvaluator) DMNNode(org.kie.dmn.api.core.ast.DMNNode) FunctionDefinition(org.kie.dmn.model.v1_1.FunctionDefinition) BusinessKnowledgeModelNodeImpl(org.kie.dmn.core.ast.BusinessKnowledgeModelNodeImpl) BusinessKnowledgeModelNode(org.kie.dmn.api.core.ast.BusinessKnowledgeModelNode)

Example 22 with Context

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));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) DMNMessage(org.kie.dmn.api.core.DMNMessage) VALIDATE_COMPILATION(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_COMPILATION) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) ContextEntry(org.kie.dmn.model.v1_1.ContextEntry) IOException(java.io.IOException) Test(org.junit.Test) Reader(java.io.Reader) Context(org.kie.dmn.model.v1_1.Context) List(java.util.List) VALIDATE_SCHEMA(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_SCHEMA) Assert(org.junit.Assert) VALIDATE_MODEL(org.kie.dmn.validation.DMNValidator.Validation.VALIDATE_MODEL) Context(org.kie.dmn.model.v1_1.Context) DMNMessage(org.kie.dmn.api.core.DMNMessage) ContextEntry(org.kie.dmn.model.v1_1.ContextEntry) Test(org.junit.Test)

Example 23 with Context

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;
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.v1_1.Context) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) ContextEntry(org.kie.workbench.common.dmn.api.definition.v1_1.ContextEntry)

Example 24 with Context

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;
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.v1_1.Context) ContextEntry(org.kie.workbench.common.dmn.api.definition.v1_1.ContextEntry)

Example 25 with Context

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);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.v1_1.Context) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem) ContextEntry(org.kie.workbench.common.dmn.api.definition.v1_1.ContextEntry) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) HasName(org.kie.workbench.common.dmn.api.definition.HasName)

Aggregations

Context (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context)58 Context (com.microsoft.z3.Context)36 CoreException (org.eclipse.core.runtime.CoreException)34 Test (org.junit.Test)29 List (java.util.List)24 BoolExpr (com.microsoft.z3.BoolExpr)23 HashMap (java.util.HashMap)20 IOException (java.io.IOException)18 Map (java.util.Map)18 ArrayList (java.util.ArrayList)17 ServerInstance (org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)17 Context (org.kie.workbench.common.dmn.api.definition.v1_1.Context)17 DMNMessage (org.kie.dmn.api.core.DMNMessage)14 File (java.io.File)13 Solver (com.microsoft.z3.Solver)12 Status (com.microsoft.z3.Status)12 IPath (org.eclipse.core.runtime.IPath)11 IStatus (org.eclipse.core.runtime.IStatus)11 Status (org.eclipse.core.runtime.Status)11 Factory (org.eclipse.jst.server.tomcat.core.internal.xml.Factory)11