Search in sources :

Example 1 with ContextEntry

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

the class ContextEntryPropertyConverter method wbFromDMN.

public static ContextEntry wbFromDMN(final org.kie.dmn.model.api.ContextEntry dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    final InformationItem variable = InformationItemPropertyConverter.wbFromDMN(dmn.getVariable());
    final Expression expression = ExpressionPropertyConverter.wbFromDMN(dmn.getExpression(), hasComponentWidthsConsumer);
    final ContextEntry result = new ContextEntry();
    if (Objects.nonNull(variable)) {
        variable.setParent(result);
    }
    result.setVariable(variable);
    if (Objects.nonNull(expression)) {
        expression.setParent(result);
    }
    result.setExpression(expression);
    return result;
}
Also used : Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry)

Example 2 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 org.kie.dmn.model.api.Context dmnFromWB(final Context wb, final Consumer<ComponentWidths> componentWidthsConsumer) {
    final org.kie.dmn.model.api.Context result = new org.kie.dmn.model.v1_2.TContext();
    result.setId(wb.getId().getValue());
    result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
    for (ContextEntry ce : wb.getContextEntry()) {
        final org.kie.dmn.model.api.ContextEntry ceConverted = ContextEntryPropertyConverter.dmnFromWB(ce, componentWidthsConsumer);
        if (ceConverted != null) {
            ceConverted.setParent(result);
        }
        result.getContextEntry().add(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.getContextEntry().remove(contextEntriesCount - 1);
        }
    }
    return result;
}
Also used : ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry)

Example 3 with ContextEntry

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

the class ContextEntryDefaultValueUtilitiesTest method testGetNewContextEntryNameWithDeletion.

@Test
public void testGetNewContextEntryNameWithDeletion() {
    final ContextEntry contextEntry1 = new ContextEntry() {

        {
            setVariable(new InformationItem());
        }
    };
    context.getContextEntry().add(contextEntry1);
    contextEntry1.getVariable().getName().setValue(ContextEntryDefaultValueUtilities.getNewContextEntryName(context));
    assertThat(contextEntry1.getVariable().getName().getValue()).isEqualTo(ContextEntryDefaultValueUtilities.PREFIX + "1");
    final ContextEntry contextEntry2 = new ContextEntry() {

        {
            setVariable(new InformationItem());
        }
    };
    context.getContextEntry().add(contextEntry2);
    contextEntry2.getVariable().getName().setValue(ContextEntryDefaultValueUtilities.getNewContextEntryName(context));
    assertThat(contextEntry2.getVariable().getName().getValue()).isEqualTo(ContextEntryDefaultValueUtilities.PREFIX + "2");
    context.getContextEntry().remove(contextEntry1);
    final ContextEntry contextEntry3 = new ContextEntry() {

        {
            setVariable(new InformationItem());
        }
    };
    context.getContextEntry().add(contextEntry3);
    contextEntry3.getVariable().getName().setValue(ContextEntryDefaultValueUtilities.getNewContextEntryName(context));
    assertThat(contextEntry3.getVariable().getName().getValue()).isEqualTo(ContextEntryDefaultValueUtilities.PREFIX + "3");
}
Also used : 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 4 with ContextEntry

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

the class ContextEntryDefaultValueUtilitiesTest method testGetNewContextEntryName.

@Test
public void testGetNewContextEntryName() {
    final ContextEntry contextEntry1 = new ContextEntry() {

        {
            setVariable(new InformationItem());
        }
    };
    context.getContextEntry().add(contextEntry1);
    contextEntry1.getVariable().getName().setValue(ContextEntryDefaultValueUtilities.getNewContextEntryName(context));
    assertThat(contextEntry1.getVariable().getName().getValue()).isEqualTo(ContextEntryDefaultValueUtilities.PREFIX + "1");
    final ContextEntry contextEntry2 = new ContextEntry() {

        {
            setVariable(new InformationItem());
        }
    };
    context.getContextEntry().add(contextEntry2);
    contextEntry2.getVariable().getName().setValue(ContextEntryDefaultValueUtilities.getNewContextEntryName(context));
    assertThat(contextEntry2.getVariable().getName().getValue()).isEqualTo(ContextEntryDefaultValueUtilities.PREFIX + "2");
}
Also used : 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 5 with ContextEntry

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

the class ContextEntryDefaultValueUtilitiesTest method testGetNewContextEntryNameWithExistingContextEntries.

@Test
public void testGetNewContextEntryNameWithExistingContextEntries() {
    final ContextEntry contextEntry1 = new ContextEntry() {

        {
            setVariable(new InformationItem());
        }
    };
    context.getContextEntry().add(contextEntry1);
    contextEntry1.getVariable().getName().setValue("entry");
    final ContextEntry contextEntry2 = new ContextEntry() {

        {
            setVariable(new InformationItem());
        }
    };
    context.getContextEntry().add(contextEntry2);
    contextEntry2.getVariable().getName().setValue(ContextEntryDefaultValueUtilities.getNewContextEntryName(context));
    assertThat(contextEntry2.getVariable().getName().getValue()).isEqualTo(ContextEntryDefaultValueUtilities.PREFIX + "1");
}
Also used : InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) 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