Search in sources :

Example 31 with Context

use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.

the class ContextPropertyConverterTest method testWBFromDMNWithFEELFunctionDefinitionAsParent.

@Test
public void testWBFromDMNWithFEELFunctionDefinitionAsParent() {
    when(functionDefinition.getKind()).thenReturn(FunctionKind.FEEL);
    final org.kie.dmn.model.api.Context dmn = setupWBFromDMN(functionDefinition);
    final Context wb = ContextPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
    assertDefaultContextEntry(wb);
}
Also used : TContext(org.kie.dmn.model.v1_2.TContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) Test(org.junit.Test)

Example 32 with Context

use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.

the class HasExpressionTest method testWrapNull.

@Test
public void testWrapNull() {
    final HasExpression hasExpression = HasExpression.wrap(parent, null);
    assertNull(hasExpression.getExpression());
    assertEquals(parent, hasExpression.asDMNModelInstrumentedBase());
    final Context context = new Context();
    hasExpression.setExpression(context);
    assertNotNull(hasExpression.getExpression());
    assertEquals(context, hasExpression.getExpression());
    assertEquals(parent, hasExpression.asDMNModelInstrumentedBase());
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) Test(org.junit.Test)

Example 33 with Context

use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.

the class HasExpressionTest method testNOP.

@Test
public void testNOP() {
    final HasExpression hasExpression = HasExpression.NOP;
    assertNull(hasExpression.getExpression());
    assertNull(hasExpression.asDMNModelInstrumentedBase());
    final Context context = new Context();
    hasExpression.setExpression(context);
    assertNull(hasExpression.getExpression());
    assertNull(hasExpression.asDMNModelInstrumentedBase());
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) Test(org.junit.Test)

Example 34 with Context

use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.

the class ContextPropertyConverter method wbFromDMN.

public static Context wbFromDMN(final org.kie.dmn.model.api.Context dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    final Id id = new Id(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef(), dmn);
    final Context result = new Context(id, description, typeRef);
    for (org.kie.dmn.model.api.ContextEntry ce : dmn.getContextEntry()) {
        final ContextEntry ceConverted = ContextEntryPropertyConverter.wbFromDMN(ce, hasComponentWidthsConsumer);
        if (ceConverted != null) {
            ceConverted.setParent(result);
        }
        result.getContextEntry().add(ceConverted);
    }
    // No need to append a _default_ row if the Context is part of a JAVA or PMML FunctionDefinition
    if (dmn.getParent() instanceof FunctionDefinition) {
        final FunctionDefinition functionDefinition = (FunctionDefinition) dmn.getParent();
        if (!functionDefinition.getKind().equals(FunctionKind.FEEL)) {
            return result;
        }
    }
    // The UI requires a ContextEntry for the _default_ result even if none has been defined
    final int contextEntriesCount = result.getContextEntry().size();
    if (contextEntriesCount == 0) {
        result.getContextEntry().add(new ContextEntry());
    } else if (!Objects.isNull(result.getContextEntry().get(contextEntriesCount - 1).getVariable())) {
        result.getContextEntry().add(new ContextEntry());
    }
    return result;
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) FunctionDefinition(org.kie.dmn.model.api.FunctionDefinition) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry)

Example 35 with Context

use of org.kie.workbench.common.dmn.api.definition.model.Context in project kie-wb-common by kiegroup.

the class FunctionDefinitionPropertyConverter method convertPMMLFunctionExpression.

private static void convertPMMLFunctionExpression(final FunctionDefinition function) {
    final Expression expression = function.getExpression();
    if (expression instanceof Context) {
        final Context context = (Context) expression;
        context.getContextEntry().forEach(FunctionDefinitionPropertyConverter::convertContextEntryExpression);
    }
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression)

Aggregations

Context (org.kie.workbench.common.dmn.api.definition.model.Context)49 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)21 Test (org.junit.Test)20 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)15 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)13 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)12 TContext (org.kie.dmn.model.v1_2.TContext)9 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)8 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)7 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)7 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)7 NamespaceContext (javax.xml.namespace.NamespaceContext)6 Before (org.junit.Before)6 DMNContext (org.kie.dmn.api.core.DMNContext)6 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)5 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)5 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)5 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)5 View (org.kie.workbench.common.stunner.core.graph.content.view.View)5 ArrayList (java.util.ArrayList)4