Search in sources :

Example 41 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 JSITContext dmn, final JSITExpression parent, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
    final Context result = new Context(id, description, typeRef);
    final List<JSITContextEntry> jsiContextEntries = dmn.getContextEntry();
    for (int i = 0; i < jsiContextEntries.size(); i++) {
        final JSITContextEntry jsiContextentry = Js.uncheckedCast(jsiContextEntries.get(i));
        final ContextEntry ceConverted = ContextEntryPropertyConverter.wbFromDMN(jsiContextentry, hasComponentWidthsConsumer);
        if (Objects.nonNull(ceConverted)) {
            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 (JSITFunctionDefinition.instanceOf(parent)) {
        final JSITFunctionDefinition functionDefinition = Js.uncheckedCast(parent);
        final String sKind = Js.uncheckedCast(functionDefinition.getKind());
        final Kind kind = Kind.fromValue(sKind);
        if (!Objects.equals(Kind.FEEL, kind)) {
            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 : JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) JSITContextEntry(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Kind(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition.Kind) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) JSITContextEntry(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry)

Example 42 with Context

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

the class DecisionTableGridTest method testSelectHeaderMultipleOutputClauseColumnNestedContextEntry.

@Test
@SuppressWarnings("unchecked")
public void testSelectHeaderMultipleOutputClauseColumnNestedContextEntry() {
    // Mock nesting of DecisionTable in a ContextEntry
    final Context context = new Context();
    final ContextEntry contextEntry = new ContextEntry();
    final InformationItem variable = new InformationItem();
    contextEntry.setVariable(variable);
    context.getContextEntry().add(contextEntry);
    contextEntry.setExpression(expression.get());
    this.hasExpression.setExpression(context);
    this.grid = spy((DecisionTableGrid) definition.getEditor(parent, Optional.empty(), contextEntry, makeHasNameForDecision(), false, 1).get());
    addOutputClause(2);
    reset(domainObjectSelectionEvent);
    grid.selectHeaderCell(0, DEFAULT_OUTPUT_CLAUSE_COLUMN_INDEX, false, false);
    assertDomainObjectSelection(variable);
    reset(domainObjectSelectionEvent);
    grid.selectHeaderCell(1, DEFAULT_OUTPUT_CLAUSE_COLUMN_INDEX, false, false);
    assertDomainObjectSelection(expression.get().getOutput().get(0));
}
Also used : GridBodyCellEditContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyCellEditContext) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) Test(org.junit.Test)

Example 43 with Context

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

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsContextEntryDefaultResult.

@Test
public void testModelEnrichmentWhenParentIsContextEntryDefaultResult() {
    final String name = "decision";
    final Context context = new Context();
    final ContextEntry contextEntry = new ContextEntry();
    context.getContextEntry().add(contextEntry);
    contextEntry.setParent(context);
    context.setParent(decision);
    decision.setName(new Name(name));
    decision.getVariable().setTypeRef(OUTPUT_DATA_QNAME);
    final Optional<DecisionTable> oModel = definition.getModelClass();
    oModel.get().setParent(contextEntry);
    definition.enrich(Optional.empty(), decision, oModel);
    final DecisionTable model = oModel.get();
    assertBasicEnrichment(model);
    assertStandardInputClauseEnrichment(model);
    final List<OutputClause> output = model.getOutput();
    assertThat(output.size()).isEqualTo(1);
    assertThat(output.get(0).getName()).isEqualTo(DEFAULT_OUTPUT_NAME);
    assertThat(output.get(0).getTypeRef()).isEqualTo(OUTPUT_DATA_QNAME);
    assertStandardDecisionRuleEnrichment(model);
    assertParentHierarchyEnrichment(model);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 44 with Context

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

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsNestedContextEntryDefaultResult.

@Test
public void testModelEnrichmentWhenParentIsNestedContextEntryDefaultResult() {
    final Decision decision = mock(Decision.class);
    final String name = "context-entry";
    final Context innerContext = new Context();
    final ContextEntry innerContextEntry = new ContextEntry();
    innerContext.getContextEntry().add(innerContextEntry);
    innerContextEntry.setParent(innerContext);
    final Context outerContext = new Context();
    final ContextEntry outerContextEntry = new ContextEntry();
    outerContext.getContextEntry().add(outerContextEntry);
    outerContextEntry.setParent(outerContext);
    innerContext.setParent(outerContextEntry);
    outerContext.setParent(decision);
    outerContextEntry.setVariable(new InformationItem(new Id(), new Description(), new Name(name), OUTPUT_DATA_QNAME));
    when(decision.asDMNModelInstrumentedBase()).thenReturn(outerContextEntry);
    final Optional<DecisionTable> oModel = definition.getModelClass();
    oModel.get().setParent(innerContextEntry);
    definition.enrich(Optional.empty(), decision, oModel);
    final DecisionTable model = oModel.get();
    assertBasicEnrichment(model);
    assertStandardInputClauseEnrichment(model);
    final List<OutputClause> output = model.getOutput();
    assertThat(output.size()).isEqualTo(1);
    assertThat(output.get(0).getName()).isEqualTo(DEFAULT_OUTPUT_NAME);
    assertThat(output.get(0).getTypeRef()).isEqualTo(OUTPUT_DATA_QNAME);
    assertStandardDecisionRuleEnrichment(model);
    assertParentHierarchyEnrichment(model);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

Example 45 with Context

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

the class DecisionTableEditorDefinitionEnricherTest method testModelEnrichmentWhenParentIsContextEntry.

@Test
public void testModelEnrichmentWhenParentIsContextEntry() {
    final Decision decision = mock(Decision.class);
    final String name = "context-entry";
    final Context context = new Context();
    final ContextEntry contextEntry = new ContextEntry();
    context.getContextEntry().add(contextEntry);
    contextEntry.setVariable(new InformationItem(new Id(), new Description(), new Name(name), OUTPUT_DATA_QNAME));
    final Optional<DecisionTable> oModel = definition.getModelClass();
    oModel.get().setParent(contextEntry);
    contextEntry.setParent(context);
    context.setParent(decision);
    when(decision.asDMNModelInstrumentedBase()).thenReturn(contextEntry);
    definition.enrich(Optional.empty(), decision, oModel);
    final DecisionTable model = oModel.get();
    assertBasicEnrichment(model);
    assertStandardInputClauseEnrichment(model);
    final List<OutputClause> output = model.getOutput();
    assertThat(output.size()).isEqualTo(1);
    assertThat(output.get(0).getName()).isEqualTo(DEFAULT_OUTPUT_NAME);
    assertThat(output.get(0).getTypeRef()).isEqualTo(OUTPUT_DATA_QNAME);
    assertStandardDecisionRuleEnrichment(model);
    assertParentHierarchyEnrichment(model);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) OutputClause(org.kie.workbench.common.dmn.api.definition.model.OutputClause) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Test(org.junit.Test)

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