Search in sources :

Example 1 with Binding

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

the class InvocationPropertyConverter method dmnFromWB.

public static org.kie.dmn.model.api.Invocation dmnFromWB(final Invocation wb, final Consumer<ComponentWidths> componentWidthsConsumer) {
    if (wb == null) {
        return null;
    }
    final org.kie.dmn.model.api.Invocation result = new org.kie.dmn.model.v1_2.TInvocation();
    result.setId(wb.getId().getValue());
    result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
    final org.kie.dmn.model.api.Expression convertedExpression = ExpressionPropertyConverter.dmnFromWB(wb.getExpression(), componentWidthsConsumer);
    if (convertedExpression != null) {
        convertedExpression.setParent(result);
    }
    result.setExpression(convertedExpression);
    for (Binding b : wb.getBinding()) {
        final org.kie.dmn.model.api.Binding bConverted = BindingPropertyConverter.dmnFromWB(b, componentWidthsConsumer);
        if (bConverted != null) {
            bConverted.setParent(result);
        }
        result.getBinding().add(bConverted);
    }
    return result;
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding)

Example 2 with Binding

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

the class InvocationPropertyConverter method wbFromDMN.

public static Invocation wbFromDMN(final org.kie.dmn.model.api.Invocation dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    if (dmn == null) {
        return null;
    }
    final Id id = new Id(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef(), dmn);
    final Invocation result = new Invocation();
    result.setId(id);
    result.setDescription(description);
    result.setTypeRef(typeRef);
    final Expression convertedExpression = ExpressionPropertyConverter.wbFromDMN(dmn.getExpression(), hasComponentWidthsConsumer);
    result.setExpression(convertedExpression);
    if (convertedExpression != null) {
        convertedExpression.setParent(result);
    }
    for (org.kie.dmn.model.api.Binding b : dmn.getBinding()) {
        final Binding bConverted = BindingPropertyConverter.wbFromDMN(b, hasComponentWidthsConsumer);
        if (bConverted != null) {
            bConverted.setParent(result);
        }
        result.getBinding().add(bConverted);
    }
    return result;
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Id(org.kie.workbench.common.dmn.api.property.dmn.Id)

Example 3 with Binding

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

the class InvocationDefaultValueUtilitiesTest method testGetNewParameterNameWithDeletion.

@Test
public void testGetNewParameterNameWithDeletion() {
    final Binding binding1 = new Binding() {

        {
            setParameter(new InformationItem());
        }
    };
    invocation.getBinding().add(binding1);
    binding1.getParameter().getName().setValue(InvocationDefaultValueUtilities.getNewParameterName(invocation));
    assertThat(binding1.getParameter().getName().getValue()).isEqualTo(InvocationDefaultValueUtilities.PREFIX + "1");
    final Binding binding2 = new Binding() {

        {
            setParameter(new InformationItem());
        }
    };
    invocation.getBinding().add(binding2);
    binding2.getParameter().getName().setValue(InvocationDefaultValueUtilities.getNewParameterName(invocation));
    assertThat(binding2.getParameter().getName().getValue()).isEqualTo(InvocationDefaultValueUtilities.PREFIX + "2");
    invocation.getBinding().remove(binding1);
    final Binding binding3 = new Binding() {

        {
            setParameter(new InformationItem());
        }
    };
    invocation.getBinding().add(binding3);
    binding3.getParameter().getName().setValue(InvocationDefaultValueUtilities.getNewParameterName(invocation));
    assertThat(binding3.getParameter().getName().getValue()).isEqualTo(InvocationDefaultValueUtilities.PREFIX + "3");
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Test(org.junit.Test)

Example 4 with Binding

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

the class InvocationPropertyConverter method dmnFromWB.

public static JSITInvocation dmnFromWB(final Invocation wb, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
    if (Objects.isNull(wb)) {
        return null;
    }
    final JSITInvocation result = new JSITInvocation();
    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);
    final JSITExpression convertedExpression = ExpressionPropertyConverter.dmnFromWB(wb.getExpression(), componentWidthsConsumer);
    result.setExpression(convertedExpression);
    for (Binding b : wb.getBinding()) {
        final JSITBinding bConverted = BindingPropertyConverter.dmnFromWB(b, componentWidthsConsumer);
        result.addBinding(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) JSITBinding(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBinding) JSITInvocation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)

Example 5 with Binding

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

the class InvocationUIModelMapper method fromDMNModel.

@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
    dmnModel.get().ifPresent(invocation -> {
        switch(columnIndex) {
            case ROW_NUMBER_COLUMN_INDEX:
                uiModel.get().setCell(rowIndex, columnIndex, () -> new InvocationGridCell<>(new BaseGridCellValue<>(rowIndex + 1), listSelector));
                uiModel.get().getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE);
                break;
            case BINDING_PARAMETER_COLUMN_INDEX:
                final InformationItem variable = invocation.getBinding().get(rowIndex).getParameter();
                uiModel.get().setCell(rowIndex, columnIndex, () -> new InformationItemCell(() -> InformationItemCell.HasNameAndDataTypeCell.wrap(variable), listSelector));
                break;
            case BINDING_EXPRESSION_COLUMN_INDEX:
                final Binding binding = invocation.getBinding().get(rowIndex);
                final Optional<Expression> expression = Optional.ofNullable(binding.getExpression());
                final boolean isOnlyVisualChangeAllowed = this.isOnlyVisualChangeAllowedSupplier.get();
                final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitionsSupplier.get().getExpressionEditorDefinition(expression);
                expressionEditorDefinition.ifPresent(ed -> {
                    final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = ed.getEditor(new GridCellTuple(rowIndex, columnIndex, gridWidget), Optional.empty(), binding, Optional.ofNullable(binding.getParameter()), isOnlyVisualChangeAllowed, nesting + 1);
                    uiModel.get().setCell(rowIndex, columnIndex, () -> new InvocationGridCell<>(new ExpressionCellValue(editor), listSelector));
                });
        }
    });
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) InformationItemCell(org.kie.workbench.common.dmn.client.editors.expressions.types.context.InformationItemCell) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) BaseUIModelMapper(org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)

Aggregations

Binding (org.kie.workbench.common.dmn.api.definition.model.Binding)26 Test (org.junit.Test)13 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)13 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)7 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)7 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)5 Invocation (org.kie.workbench.common.dmn.api.definition.model.Invocation)4 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)4 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)3 JSITBinding (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBinding)3 JSITExpression (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)3 Optional (java.util.Optional)2 TBinding (org.kie.dmn.model.v1_2.TBinding)2 TInformationItem (org.kie.dmn.model.v1_2.TInformationItem)2 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)2 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)2 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)2 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)2 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)2