Search in sources :

Example 1 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 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 2 with Invocation

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

the class ExpressionPropertyConverter method dmnFromWB.

public static org.kie.dmn.model.api.Expression dmnFromWB(final Expression wb, final Consumer<ComponentWidths> componentWidthsConsumer) {
    if (Objects.isNull(wb)) {
        return null;
    }
    final String uuid = wb.getId().getValue();
    if (Objects.nonNull(uuid)) {
        final ComponentWidths componentWidths = new ComponentWidths();
        componentWidths.setDmnElementRef(new QName(uuid));
        componentWidths.setWidths(new ArrayList<>(wb.getComponentWidths()));
        componentWidthsConsumer.accept(componentWidths);
    }
    if (wb instanceof IsLiteralExpression) {
        return LiteralExpressionPropertyConverter.dmnFromWB((IsLiteralExpression) wb);
    } else if (wb instanceof Context) {
        return ContextPropertyConverter.dmnFromWB((Context) wb, componentWidthsConsumer);
    } else if (wb instanceof Relation) {
        return RelationPropertyConverter.dmnFromWB((Relation) wb, componentWidthsConsumer);
    } else if (wb instanceof List) {
        return ListPropertyConverter.dmnFromWB((List) wb, componentWidthsConsumer);
    } else if (wb instanceof Invocation) {
        return InvocationPropertyConverter.dmnFromWB((Invocation) wb, componentWidthsConsumer);
    } else if (wb instanceof FunctionDefinition) {
        return FunctionDefinitionPropertyConverter.dmnFromWB((FunctionDefinition) wb, componentWidthsConsumer);
    } else if (wb instanceof DecisionTable) {
        return DecisionTablePropertyConverter.dmnFromWB((DecisionTable) wb);
    }
    return null;
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) QName(javax.xml.namespace.QName) List(org.kie.workbench.common.dmn.api.definition.model.List) ArrayList(java.util.ArrayList) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths)

Example 3 with Invocation

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

the class InvocationPropertyConverterTest method testWBFromDMN.

@Test
public void testWBFromDMN() {
    final org.kie.dmn.model.api.Invocation dmn = new TInvocation();
    final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
    literalExpression.setId(EXPRESSION_UUID);
    dmn.setId(INVOCATION_UUID);
    dmn.setDescription(INVOCATION_DESCRIPTION);
    dmn.setTypeRef(new QName(INVOCATION_QNAME_LOCALPART));
    dmn.setExpression(literalExpression);
    final Invocation wb = InvocationPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
    assertThat(wb).isNotNull();
    assertThat(wb.getId()).isNotNull();
    assertThat(wb.getId().getValue()).isEqualTo(INVOCATION_UUID);
    assertThat(wb.getDescription()).isNotNull();
    assertThat(wb.getDescription().getValue()).isEqualTo(INVOCATION_DESCRIPTION);
    assertThat(wb.getTypeRef()).isNotNull();
    assertThat(wb.getTypeRef().getLocalPart()).isEqualTo(INVOCATION_QNAME_LOCALPART);
    assertThat(wb.getExpression()).isNotNull();
    assertThat(wb.getExpression().getId().getValue()).isEqualTo(EXPRESSION_UUID);
    verify(hasComponentWidthsConsumer).accept(eq(EXPRESSION_UUID), hasComponentWidthsCaptor.capture());
    final HasComponentWidths hasComponentWidths = hasComponentWidthsCaptor.getValue();
    assertThat(hasComponentWidths).isNotNull();
    assertThat(hasComponentWidths).isEqualTo(wb.getExpression());
}
Also used : TInvocation(org.kie.dmn.model.v1_2.TInvocation) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) QName(javax.xml.namespace.QName) TInvocation(org.kie.dmn.model.v1_2.TInvocation) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) Test(org.junit.Test)

Example 4 with Invocation

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

the class InvocationPropertyConverterTest method testDMNFromWB.

@Test
public void testDMNFromWB() {
    final Invocation wb = new Invocation();
    final LiteralExpression literalExpression = new LiteralExpression();
    literalExpression.getComponentWidths().set(0, 200.0);
    literalExpression.getId().setValue(EXPRESSION_UUID);
    wb.getId().setValue(INVOCATION_UUID);
    wb.getDescription().setValue(INVOCATION_DESCRIPTION);
    wb.setTypeRef(new org.kie.workbench.common.dmn.api.property.dmn.QName(org.kie.workbench.common.dmn.api.property.dmn.QName.NULL_NS_URI, INVOCATION_QNAME_LOCALPART));
    wb.setExpression(literalExpression);
    final org.kie.dmn.model.api.Invocation dmn = InvocationPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getId()).isNotNull();
    assertThat(dmn.getId()).isEqualTo(INVOCATION_UUID);
    assertThat(dmn.getDescription()).isNotNull();
    assertThat(dmn.getDescription()).isEqualTo(INVOCATION_DESCRIPTION);
    assertThat(dmn.getTypeRef()).isNotNull();
    assertThat(dmn.getTypeRef().getLocalPart()).isEqualTo(INVOCATION_QNAME_LOCALPART);
    assertThat(dmn.getExpression()).isNotNull();
    assertThat(dmn.getExpression().getId()).isEqualTo(EXPRESSION_UUID);
    verify(componentWidthsConsumer).accept(componentWidthsCaptor.capture());
    final ComponentWidths componentWidths = componentWidthsCaptor.getValue();
    assertThat(componentWidths).isNotNull();
    assertThat(componentWidths.getDmnElementRef().getLocalPart()).isEqualTo(EXPRESSION_UUID);
    assertThat(componentWidths.getWidths().size()).isEqualTo(literalExpression.getRequiredComponentWidthCount());
    assertThat(componentWidths.getWidths().get(0)).isEqualTo(200.0);
}
Also used : TInvocation(org.kie.dmn.model.v1_2.TInvocation) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths) Test(org.junit.Test)

Example 5 with Invocation

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

the class DeleteParameterBindingCommandTest method setup.

@Before
public void setup() {
    this.invocation = new Invocation();
    this.binding = makeBinding("p" + invocation.getBinding().size());
    this.invocation.getBinding().add(binding);
    this.uiModel = new BaseGridData(false);
    this.uiGridRow = new BaseGridRow();
    this.uiModel.appendRow(uiGridRow);
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiNameColumn);
    this.uiModel.appendColumn(uiExpressionEditorColumn);
    doReturn(ruleManager).when(handler).getRuleManager();
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiNameColumn).getIndex();
    doReturn(2).when(uiExpressionEditorColumn).getIndex();
}
Also used : Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Before(org.junit.Before)

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