Search in sources :

Example 31 with ContextEntry

use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry 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 32 with ContextEntry

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

the class ContextPropertyConverter method dmnFromWB.

public static JSITContext dmnFromWB(final Context wb, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
    final JSITContext result = new JSITContext();
    result.setId(wb.getId().getValue());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    description.ifPresent(result::setDescription);
    QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
    for (ContextEntry ce : wb.getContextEntry()) {
        final JSITContextEntry ceConverted = ContextEntryPropertyConverter.dmnFromWB(ce, componentWidthsConsumer);
        result.addContextEntry(ceConverted);
    }
    // The UI appends a ContextEntry for the _default_ result that may contain an undefined Expression.
    // If this is the case then DMN does not require the ContextEntry to be written out to the XML.
    // Conversion of ContextEntries will always create a _mock_ LiteralExpression if no Expression has
    // been defined therefore remove the last entry from the org.kie.dmn.model if the WB had no Expression.
    final int contextEntriesCount = result.getContextEntry().size();
    if (contextEntriesCount > 0) {
        if (Objects.isNull(wb.getContextEntry().get(contextEntriesCount - 1).getExpression())) {
            result.removeContextEntry(contextEntriesCount - 1);
        }
    }
    return result;
}
Also used : JSITContextEntry(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry) JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) JSITContextEntry(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContextEntry)

Example 33 with ContextEntry

use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry 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 34 with ContextEntry

use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry 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 35 with ContextEntry

use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry 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)

Aggregations

ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)40 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)22 Context (org.kie.workbench.common.dmn.api.definition.model.Context)19 Test (org.junit.Test)16 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)8 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)7 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)6 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)5 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)5 TContextEntry (org.kie.dmn.model.v1_2.TContextEntry)4 TInformationItem (org.kie.dmn.model.v1_2.TInformationItem)4 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)4 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)4 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)4 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)4 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)4 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)4 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)3 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)3 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)3