Search in sources :

Example 11 with Invocation

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

the class ExpressionPropertyConverter method wbFromDMN.

public static Expression wbFromDMN(final org.kie.dmn.model.api.Expression dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    if (dmn instanceof org.kie.dmn.model.api.LiteralExpression) {
        final LiteralExpression e = LiteralExpressionPropertyConverter.wbFromDMN((org.kie.dmn.model.api.LiteralExpression) dmn);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (dmn instanceof org.kie.dmn.model.api.Context) {
        final Context e = ContextPropertyConverter.wbFromDMN((org.kie.dmn.model.api.Context) dmn, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (dmn instanceof org.kie.dmn.model.api.Relation) {
        final Relation e = RelationPropertyConverter.wbFromDMN((org.kie.dmn.model.api.Relation) dmn, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (dmn instanceof org.kie.dmn.model.api.List) {
        final List e = ListPropertyConverter.wbFromDMN((org.kie.dmn.model.api.List) dmn, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (dmn instanceof org.kie.dmn.model.api.Invocation) {
        final Invocation e = InvocationPropertyConverter.wbFromDMN((org.kie.dmn.model.api.Invocation) dmn, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (dmn instanceof org.kie.dmn.model.api.FunctionDefinition) {
        final FunctionDefinition e = FunctionDefinitionPropertyConverter.wbFromDMN((org.kie.dmn.model.api.FunctionDefinition) dmn, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (dmn instanceof org.kie.dmn.model.api.DecisionTable) {
        final DecisionTable e = DecisionTablePropertyConverter.wbFromDMN((org.kie.dmn.model.api.DecisionTable) dmn);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    }
    return null;
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) List(org.kie.workbench.common.dmn.api.definition.model.List) ArrayList(java.util.ArrayList) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)

Example 12 with Invocation

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

the class MoveRowsCommandTest method setup.

@Before
public void setup() {
    this.invocation = new Invocation();
    this.uiModel = new DMNGridData();
    doReturn(ruleManager).when(handler).getRuleManager();
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiNameColumn).getIndex();
    doReturn(2).when(uiExpressionEditorColumn).getIndex();
    addParameterBinding(II1);
    addParameterBinding(II2);
    addUiModelColumn(uiRowNumberColumn);
    addUiModelColumn(uiNameColumn);
    addUiModelColumn(uiExpressionEditorColumn);
    addUiModelRow(0);
    addUiModelRow(1);
}
Also used : Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) Before(org.junit.Before)

Example 13 with Invocation

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

the class InvocationEditorDefinitionTest method testModelEnrichment.

@Test
public void testModelEnrichment() {
    final Optional<Invocation> oModel = definition.getModelClass();
    definition.enrich(Optional.empty(), hasExpression, oModel);
    final Invocation model = oModel.get();
    assertNotNull(model.getExpression());
    assertTrue(model.getExpression() instanceof LiteralExpression);
    assertEquals(1, model.getBinding().size());
    assertNotNull(model.getBinding().get(0).getParameter());
    assertEquals(InvocationDefaultValueUtilities.PREFIX + "1", model.getBinding().get(0).getParameter().getName().getValue());
    assertNull(model.getBinding().get(0).getExpression());
    assertNotNull(model.getId());
    assertEquals(model, model.getExpression().getParent());
    assertEquals(model, model.getBinding().get(0).getParent());
    assertEquals(model.getBinding().get(0), model.getBinding().get(0).getParameter().getParent());
}
Also used : Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Test(org.junit.Test)

Example 14 with Invocation

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

the class InvocationUIModelMapperTest method setup.

@SuppressWarnings("unchecked")
public void setup(final boolean isOnlyVisualChangeAllowedSupplier) {
    this.uiModel = new BaseGridData();
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiNameColumn);
    this.uiModel.appendColumn(uiExpressionEditorColumn);
    when(uiRowNumberColumn.getIndex()).thenReturn(0);
    when(uiNameColumn.getIndex()).thenReturn(1);
    when(uiExpressionEditorColumn.getIndex()).thenReturn(2);
    when(gridWidget.getModel()).thenReturn(uiModel);
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add(literalExpressionEditorDefinition);
    when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(literalExpression));
    when(literalExpressionEditor.getExpression()).thenReturn(() -> Optional.of(literalExpression));
    when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
    final LiteralExpression invocationExpression = new LiteralExpression();
    invocationExpression.getText().setValue("invocation-expression");
    final LiteralExpression bindingExpression = new LiteralExpression();
    bindingExpression.getText().setValue("binding-expression");
    final Binding binding = new Binding();
    final InformationItem parameter = new InformationItem();
    parameter.setName(new Name("p0"));
    binding.setParameter(parameter);
    binding.setExpression(bindingExpression);
    this.invocation = new Invocation();
    this.invocation.setExpression(invocationExpression);
    this.invocation.getBinding().add(binding);
    this.mapper = new InvocationUIModelMapper(gridWidget, () -> uiModel, () -> Optional.of(invocation), () -> isOnlyVisualChangeAllowedSupplier, expressionEditorDefinitionsSupplier, listSelector, 0);
    this.cellValueSupplier = Optional::empty;
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) Optional(java.util.Optional) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Example 15 with Invocation

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

the class InvocationPropertyConverter method wbFromDMN.

public static Invocation wbFromDMN(final JSITInvocation dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    if (Objects.isNull(dmn)) {
        return null;
    }
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
    final Invocation result = new Invocation();
    result.setId(id);
    result.setDescription(description);
    result.setTypeRef(typeRef);
    Expression expression = null;
    final JSITExpression jsiWrapped = dmn.getExpression();
    if (Objects.nonNull(jsiWrapped)) {
        final JSITExpression jsiExpression = Js.uncheckedCast(JsUtils.getUnwrappedElement(jsiWrapped));
        expression = ExpressionPropertyConverter.wbFromDMN(jsiExpression, Js.uncheckedCast(dmn), hasComponentWidthsConsumer);
    }
    result.setExpression(expression);
    if (Objects.nonNull(expression)) {
        expression.setParent(result);
    }
    final List<JSITBinding> jsiBindings = dmn.getBinding();
    for (int i = 0; i < jsiBindings.size(); i++) {
        final JSITBinding jsiBinding = Js.uncheckedCast(jsiBindings.get(i));
        final Binding bConverted = BindingPropertyConverter.wbFromDMN(jsiBinding, hasComponentWidthsConsumer);
        if (Objects.nonNull(bConverted)) {
            bConverted.setParent(result);
        }
        result.getBinding().add(bConverted);
    }
    return result;
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) JSITBinding(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBinding) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) JSITInvocation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) JSITBinding(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBinding) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)

Aggregations

Invocation (org.kie.workbench.common.dmn.api.definition.model.Invocation)15 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)5 Test (org.junit.Test)4 Binding (org.kie.workbench.common.dmn.api.definition.model.Binding)4 Context (org.kie.workbench.common.dmn.api.definition.model.Context)4 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)4 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)4 IsLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression)4 List (org.kie.workbench.common.dmn.api.definition.model.List)4 Relation (org.kie.workbench.common.dmn.api.definition.model.Relation)4 Before (org.junit.Before)3 TInvocation (org.kie.dmn.model.v1_2.TInvocation)3 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)3 JSITInvocation (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation)3 BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)3 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)3 ArrayList (java.util.ArrayList)2 Optional (java.util.Optional)2 QName (javax.xml.namespace.QName)2 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)2