Search in sources :

Example 1 with InformationItem

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

the class ContextEntryPropertyConverter method wbFromDMN.

public static ContextEntry wbFromDMN(final org.kie.dmn.model.api.ContextEntry dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    final InformationItem variable = InformationItemPropertyConverter.wbFromDMN(dmn.getVariable());
    final Expression expression = ExpressionPropertyConverter.wbFromDMN(dmn.getExpression(), hasComponentWidthsConsumer);
    final ContextEntry result = new ContextEntry();
    if (Objects.nonNull(variable)) {
        variable.setParent(result);
    }
    result.setVariable(variable);
    if (Objects.nonNull(expression)) {
        expression.setParent(result);
    }
    result.setExpression(expression);
    return result;
}
Also used : Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry)

Example 2 with InformationItem

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

the class FunctionDefinitionPropertyConverter method wbFromDMN.

public static FunctionDefinition wbFromDMN(final org.kie.dmn.model.api.FunctionDefinition 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 Expression expression = ExpressionPropertyConverter.wbFromDMN(dmn.getExpression(), hasComponentWidthsConsumer);
    final FunctionDefinition result = new FunctionDefinition(id, description, typeRef, expression);
    if (expression != null) {
        expression.setParent(result);
    }
    final FunctionKind kind = dmn.getKind();
    switch(kind) {
        case FEEL:
            result.setKind(Kind.FEEL);
            break;
        case JAVA:
            result.setKind(Kind.JAVA);
            break;
        case PMML:
            result.setKind(Kind.PMML);
            convertPMMLFunctionExpression(result);
            break;
        default:
            result.setKind(Kind.FEEL);
            break;
    }
    for (org.kie.dmn.model.api.InformationItem ii : dmn.getFormalParameter()) {
        final InformationItem iiConverted = InformationItemPropertyConverter.wbFromDMN(ii);
        if (iiConverted != null) {
            iiConverted.setParent(result);
        }
        result.getFormalParameter().add(iiConverted);
    }
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) FunctionKind(org.kie.dmn.model.api.FunctionKind)

Example 3 with InformationItem

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

the class FunctionDefinitionPropertyConverter method dmnFromWB.

public static org.kie.dmn.model.api.FunctionDefinition dmnFromWB(final FunctionDefinition wb, final Consumer<ComponentWidths> componentWidthsConsumer) {
    if (wb == null) {
        return null;
    }
    final org.kie.dmn.model.api.FunctionDefinition result = new org.kie.dmn.model.v1_2.TFunctionDefinition();
    result.setId(wb.getId().getValue());
    result.setDescription(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
    result.setExpression(ExpressionPropertyConverter.dmnFromWB(wb.getExpression(), componentWidthsConsumer));
    final Kind kind = wb.getKind();
    switch(kind) {
        case FEEL:
            result.setKind(FunctionKind.FEEL);
            break;
        case JAVA:
            result.setKind(FunctionKind.JAVA);
            break;
        case PMML:
            result.setKind(FunctionKind.PMML);
            break;
        default:
            result.setKind(FunctionKind.FEEL);
            break;
    }
    for (InformationItem ii : wb.getFormalParameter()) {
        final org.kie.dmn.model.api.InformationItem iiConverted = InformationItemPropertyConverter.dmnFromWB(ii);
        if (iiConverted != null) {
            iiConverted.setParent(result);
        }
        result.getFormalParameter().add(iiConverted);
    }
    return result;
}
Also used : Kind(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition.Kind) FunctionKind(org.kie.dmn.model.api.FunctionKind) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem)

Example 4 with InformationItem

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

the class FunctionDefaultValueUtilitiesTest method testGetNewParameterName.

@Test
public void testGetNewParameterName() {
    final InformationItem informationItem1 = new InformationItem();
    function.getFormalParameter().add(informationItem1);
    informationItem1.getName().setValue(FunctionDefaultValueUtilities.getNewParameterName(function));
    assertThat(informationItem1.getName().getValue()).isEqualTo(FunctionDefaultValueUtilities.PREFIX + "1");
    final InformationItem informationItem2 = new InformationItem();
    function.getFormalParameter().add(informationItem2);
    informationItem2.getName().setValue(FunctionDefaultValueUtilities.getNewParameterName(function));
    assertThat(informationItem2.getName().getValue()).isEqualTo(FunctionDefaultValueUtilities.PREFIX + "2");
}
Also used : InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Test(org.junit.Test)

Example 5 with InformationItem

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

the class InformationItemCellInformationItemTest method testHasNameAndDataTypeCellGetHasTypeRefs.

@Test
public void testHasNameAndDataTypeCellGetHasTypeRefs() {
    final InformationItem informationItem = mock(InformationItem.class);
    final HasNameAndDataTypeCell hasNameAndDataTypeCell = HasNameAndDataTypeCell.wrap(informationItem);
    final HasTypeRef hasTypeRef1 = mock(HasTypeRef.class);
    final HasTypeRef hasTypeRef2 = mock(HasTypeRef.class);
    final List<HasTypeRef> expectedHasTypeRefs = asList(hasTypeRef1, hasTypeRef2);
    when(informationItem.getHasTypeRefs()).thenReturn(expectedHasTypeRefs);
    final List<HasTypeRef> actualHasTypeRefs = hasNameAndDataTypeCell.getHasTypeRefs();
    assertEquals(expectedHasTypeRefs, actualHasTypeRefs);
}
Also used : HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) HasNameAndDataTypeCell(org.kie.workbench.common.dmn.client.editors.expressions.types.context.InformationItemCell.HasNameAndDataTypeCell) Test(org.junit.Test)

Aggregations

InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)110 Test (org.junit.Test)61 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)24 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)22 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)22 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)20 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)19 Binding (org.kie.workbench.common.dmn.api.definition.model.Binding)13 Context (org.kie.workbench.common.dmn.api.definition.model.Context)11 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)11 Before (org.junit.Before)10 List (org.kie.workbench.common.dmn.api.definition.model.List)10 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)10 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)10 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)9 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)9 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)9 HasName (org.kie.workbench.common.dmn.api.definition.HasName)7 Relation (org.kie.workbench.common.dmn.api.definition.model.Relation)7 JSITInformationItem (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationItem)7