Search in sources :

Example 21 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 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)

Example 22 with Binding

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

the class AddParameterBindingCommandTest method testGraphCommandUndoFromStart.

@Test
public void testGraphCommandUndoFromStart() {
    final Binding firstBinding = new Binding();
    final Binding secondBinding = new Binding();
    invocation.getBinding().add(firstBinding);
    invocation.getBinding().add(secondBinding);
    makeCommand(0);
    final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
    // Add parameter and then undo
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.undo(gce));
    assertBindingDefinitions(firstBinding, secondBinding);
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 23 with Binding

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

the class AddParameterBindingCommandTest method testGraphCommandExecuteInsertToFirstPlace.

@Test
public void testGraphCommandExecuteInsertToFirstPlace() {
    final Binding firstBinding = new Binding();
    final Binding secondBinding = new Binding();
    invocation.getBinding().add(firstBinding);
    invocation.getBinding().add(secondBinding);
    makeCommand(0);
    final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
    assertBindingDefinitions(binding, firstBinding, secondBinding);
    assertEquals(invocation, binding.getParent());
    assertEquals(binding, binding.getParameter().getParent());
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 24 with Binding

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

the class DeleteParameterBindingCommandTest method testGraphCommandExecuteRemoveFromMiddle.

@Test
public void testGraphCommandExecuteRemoveFromMiddle() {
    final Binding firstBinding = new Binding();
    final Binding lastBinding = new Binding();
    invocation.getBinding().add(0, firstBinding);
    invocation.getBinding().add(lastBinding);
    uiModel.appendRow(new BaseGridRow());
    uiModel.appendRow(new BaseGridRow());
    makeCommand(1);
    final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
    Assertions.assertThat(invocation.getBinding()).containsExactly(firstBinding, lastBinding);
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Example 25 with Binding

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

the class DeleteParameterBindingCommandTest method makeBinding.

private Binding makeBinding(final String bindingName) {
    final Binding newBinding = new Binding();
    final InformationItem parameter = new InformationItem();
    parameter.setName(new Name(bindingName));
    newBinding.setParameter(parameter);
    return newBinding;
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

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