Search in sources :

Example 16 with Relation

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

the class RelationPropertyConverterTest method testDMNFromWB.

@Test
public void testDMNFromWB() {
    final Relation wb = new Relation();
    final InformationItem informationItem = new InformationItem();
    final List list = new List();
    final LiteralExpression literalExpression = new LiteralExpression();
    final HasExpression hasExpression = HasExpression.wrap(wb, literalExpression);
    literalExpression.getComponentWidths().set(0, 200.0);
    literalExpression.getId().setValue(EXPRESSION_UUID);
    list.getExpression().add(hasExpression);
    wb.getId().setValue(RELATION_UUID);
    wb.getDescription().setValue(RELATION_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, RELATION_QNAME_LOCALPART));
    wb.getColumn().add(informationItem);
    wb.getRow().add(list);
    final org.kie.dmn.model.api.Relation dmn = RelationPropertyConverter.dmnFromWB(wb, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getId()).isNotNull();
    assertThat(dmn.getId()).isEqualTo(RELATION_UUID);
    assertThat(dmn.getDescription()).isNotNull();
    assertThat(dmn.getDescription()).isEqualTo(RELATION_DESCRIPTION);
    assertThat(dmn.getTypeRef()).isNotNull();
    assertThat(dmn.getTypeRef().getLocalPart()).isEqualTo(RELATION_QNAME_LOCALPART);
    assertThat(dmn.getColumn()).isNotNull();
    assertThat(dmn.getColumn().size()).isEqualTo(1);
    assertThat(dmn.getColumn().get(0)).isNotNull();
    assertThat(dmn.getRow()).isNotNull();
    assertThat(dmn.getRow().size()).isEqualTo(1);
    assertThat(dmn.getRow().get(0)).isNotNull();
    assertThat(dmn.getRow().get(0).getExpression()).isNotNull();
    assertThat(dmn.getRow().get(0).getExpression().size()).isEqualTo(1);
    assertThat(dmn.getRow().get(0).getExpression().get(0).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 : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) TRelation(org.kie.dmn.model.v1_2.TRelation) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) List(org.kie.workbench.common.dmn.api.definition.model.List) TList(org.kie.dmn.model.v1_2.TList) 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 17 with Relation

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

the class RelationPropertyConverterTest method testWBFromDMN.

@Test
public void testWBFromDMN() {
    final org.kie.dmn.model.api.Relation dmn = new TRelation();
    final org.kie.dmn.model.api.InformationItem informationItem = new TInformationItem();
    final org.kie.dmn.model.api.List list = new TList();
    final org.kie.dmn.model.api.LiteralExpression literalExpression = new TLiteralExpression();
    literalExpression.setId(EXPRESSION_UUID);
    list.getExpression().add(literalExpression);
    dmn.setId(RELATION_UUID);
    dmn.setDescription(RELATION_DESCRIPTION);
    dmn.setTypeRef(new QName(RELATION_QNAME_LOCALPART));
    dmn.getColumn().add(informationItem);
    dmn.getRow().add(list);
    final Relation wb = RelationPropertyConverter.wbFromDMN(dmn, hasComponentWidthsConsumer);
    assertThat(wb).isNotNull();
    assertThat(wb.getId()).isNotNull();
    assertThat(wb.getId().getValue()).isEqualTo(RELATION_UUID);
    assertThat(wb.getDescription()).isNotNull();
    assertThat(wb.getDescription().getValue()).isEqualTo(RELATION_DESCRIPTION);
    assertThat(wb.getTypeRef()).isNotNull();
    assertThat(wb.getTypeRef().getLocalPart()).isEqualTo(RELATION_QNAME_LOCALPART);
    assertThat(wb.getColumn()).isNotNull();
    assertThat(wb.getColumn().size()).isEqualTo(1);
    assertThat(wb.getColumn().get(0)).isNotNull();
    assertThat(wb.getRow()).isNotNull();
    assertThat(wb.getRow().size()).isEqualTo(1);
    assertThat(wb.getRow().get(0)).isNotNull();
    assertThat(wb.getRow().get(0).getExpression()).isNotNull();
    assertThat(wb.getRow().get(0).getExpression().size()).isEqualTo(1);
    assertThat(wb.getRow().get(0).getExpression().get(0).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.getRow().get(0).getExpression().get(0).getExpression());
}
Also used : QName(javax.xml.namespace.QName) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) TList(org.kie.dmn.model.v1_2.TList) TRelation(org.kie.dmn.model.v1_2.TRelation) TRelation(org.kie.dmn.model.v1_2.TRelation) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) TInformationItem(org.kie.dmn.model.v1_2.TInformationItem) Test(org.junit.Test)

Example 18 with Relation

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

the class RelationPropertyConverter method wbFromDMN.

public static Relation wbFromDMN(final org.kie.dmn.model.api.Relation dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    final Id id = new Id(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef(), dmn);
    final List<org.kie.dmn.model.api.InformationItem> column = dmn.getColumn();
    final List<org.kie.dmn.model.api.List> row = dmn.getRow();
    final List<InformationItem> convertedColumn = column.stream().map(InformationItemPropertyConverter::wbFromDMN).collect(Collectors.toList());
    final List<org.kie.workbench.common.dmn.api.definition.model.List> convertedRow = row.stream().map(r -> ListPropertyConverter.wbFromDMN(r, hasComponentWidthsConsumer)).collect(Collectors.toList());
    final Relation result = new Relation(id, description, typeRef, convertedColumn, convertedRow);
    for (InformationItem c : convertedColumn) {
        if (c != null) {
            c.setParent(result);
        }
    }
    for (org.kie.workbench.common.dmn.api.definition.model.List r : convertedRow) {
        if (r != null) {
            r.setParent(result);
        }
    }
    return result;
}
Also used : Consumer(java.util.function.Consumer) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) List(java.util.List) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) BiConsumer(java.util.function.BiConsumer) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Collectors(java.util.stream.Collectors) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) List(java.util.List) Id(org.kie.workbench.common.dmn.api.property.dmn.Id)

Example 19 with Relation

use of org.kie.workbench.common.dmn.api.definition.model.Relation 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 20 with Relation

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

the class DeleteRelationColumnCommandTest method setup.

@Before
public void setup() {
    this.relation = new Relation();
    this.informationItem = new InformationItem();
    this.relation.getColumn().add(informationItem);
    this.uiModel = new BaseGridData();
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiModelColumn);
    doReturn(ruleManager).when(handler).getRuleManager();
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiModelColumn).getIndex();
    this.uiModelMapper = new RelationUIModelMapper(() -> uiModel, () -> Optional.of(relation), listSelector, DEFAULT_HEIGHT);
}
Also used : RelationUIModelMapper(org.kie.workbench.common.dmn.client.editors.expressions.types.relation.RelationUIModelMapper) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Before(org.junit.Before)

Aggregations

Relation (org.kie.workbench.common.dmn.api.definition.model.Relation)21 List (org.kie.workbench.common.dmn.api.definition.model.List)9 Before (org.junit.Before)7 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)7 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)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 Invocation (org.kie.workbench.common.dmn.api.definition.model.Invocation)4 IsLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression)4 RelationUIModelMapper (org.kie.workbench.common.dmn.client.editors.expressions.types.relation.RelationUIModelMapper)4 BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)4 TRelation (org.kie.dmn.model.v1_2.TRelation)3 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)3 JSITList (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList)3 JSITRelation (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRelation)3 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)3