Search in sources :

Example 21 with FunctionDefinition

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

the class BoxedExpressionHelperTest method testGetOptionalHasExpressionWhenNodeIsBusinessKnowledgeModel.

@Test
public void testGetOptionalHasExpressionWhenNodeIsBusinessKnowledgeModel() {
    final View content = mock(View.class);
    final BusinessKnowledgeModel businessKnowledgeModel = new BusinessKnowledgeModel();
    final FunctionDefinition encapsulatedLogic = mock(FunctionDefinition.class);
    businessKnowledgeModel.setEncapsulatedLogic(encapsulatedLogic);
    when(node.getContent()).thenReturn(content);
    when(content.getDefinition()).thenReturn(businessKnowledgeModel);
    final Optional<HasExpression> actualHasExpression = helper.getOptionalHasExpression(node);
    assertTrue(actualHasExpression.isPresent());
    assertEquals(businessKnowledgeModel, actualHasExpression.get().asDMNModelInstrumentedBase());
    assertEquals(encapsulatedLogic, actualHasExpression.get().getExpression());
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 22 with FunctionDefinition

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

the class PMMLIncludedModelHandlerTest method assertNestedLiteralExpression.

private void assertNestedLiteralExpression(final BusinessKnowledgeModel bkm) {
    final FunctionDefinition function = bkm.getEncapsulatedLogic();
    assertThat(function.getExpression()).isInstanceOf(Context.class);
    final Context context = (Context) function.getExpression();
    assertThat(context.getContextEntry()).hasSize(1);
    final ContextEntry contextEntry = context.getContextEntry().get(0);
    assertThat(contextEntry.getExpression()).isInstanceOf(LiteralExpression.class);
    assertThat(((LiteralExpression) contextEntry.getExpression()).getText().getValue()).isEmpty();
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry)

Example 23 with FunctionDefinition

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

the class PMMLIncludedModelHandlerTest method assertTopLevelLiteralExpression.

private void assertTopLevelLiteralExpression(final BusinessKnowledgeModel bkm) {
    final FunctionDefinition function = bkm.getEncapsulatedLogic();
    assertThat(function.getExpression()).isInstanceOf(LiteralExpression.class);
    assertThat(((LiteralExpression) function.getExpression()).getText().getValue()).isEmpty();
}
Also used : FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)

Example 24 with FunctionDefinition

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

the class ExpressionPropertyConverter method dmnFromWB.

public static JSITExpression dmnFromWB(final Expression wb, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
    if (Objects.isNull(wb)) {
        return null;
    }
    final String uuid = wb.getId().getValue();
    if (Objects.nonNull(uuid)) {
        final JSITComponentWidths componentWidths = new JSITComponentWidths();
        componentWidths.setDmnElementRef(uuid);
        wb.getComponentWidths().stream().filter(Objects::nonNull).forEach(w -> componentWidths.addWidth(new Float(w)));
        componentWidthsConsumer.accept(componentWidths);
    }
    if (wb instanceof IsLiteralExpression) {
        final JSITLiteralExpression unwrappedJSITLiteralExpression = LiteralExpressionPropertyConverter.dmnFromWB((IsLiteralExpression) wb);
        final JSITLiteralExpression wrappedJSITLiteralExpression = getWrappedJSITLiteralExpression(unwrappedJSITLiteralExpression, "dmn", "literalExpression");
        return wrappedJSITLiteralExpression;
    } else if (wb instanceof Context) {
        final JSITContext unwrappedJSITContext = ContextPropertyConverter.dmnFromWB((Context) wb, componentWidthsConsumer);
        final JSITContext wrappedJSITContext = getWrappedJSITContext(unwrappedJSITContext, "dmn", "context");
        return wrappedJSITContext;
    } else if (wb instanceof Relation) {
        final JSITRelation unwrappedJSITRelation = RelationPropertyConverter.dmnFromWB((Relation) wb, componentWidthsConsumer);
        final JSITRelation wrappedJSITRelation = getWrappedJSITRelation(unwrappedJSITRelation, "dmn", "relation");
        return wrappedJSITRelation;
    } else if (wb instanceof List) {
        final JSITList unwrappedJSITList = ListPropertyConverter.dmnFromWB((List) wb, componentWidthsConsumer);
        final JSITList wrappedJSITList = getWrappedJSITList(unwrappedJSITList, "dmn", "list");
        return wrappedJSITList;
    } else if (wb instanceof Invocation) {
        final JSITInvocation unwrappedJSITInvocation = InvocationPropertyConverter.dmnFromWB((Invocation) wb, componentWidthsConsumer);
        final JSITInvocation wrappedJSITInvocation = getWrappedJSITInvocation(unwrappedJSITInvocation, "dmn", "invocation");
        return wrappedJSITInvocation;
    } else if (wb instanceof FunctionDefinition) {
        final JSITFunctionDefinition unwrappedJSITFunctionDefinition = FunctionDefinitionPropertyConverter.dmnFromWB((FunctionDefinition) wb, componentWidthsConsumer);
        final JSITFunctionDefinition wrappedJSITFunctionDefinition = getWrappedJSITFunctionDefinition(unwrappedJSITFunctionDefinition, "dmn", "functionDefinition");
        return wrappedJSITFunctionDefinition;
    } else if (wb instanceof DecisionTable) {
        final JSITDecisionTable unwrappedJSITDecisionTable = DecisionTablePropertyConverter.dmnFromWB((DecisionTable) wb);
        final JSITDecisionTable wrappedJSITDecisionTable = getWrappedJSITDecisionTable(unwrappedJSITDecisionTable, "dmn", "decisionTable");
        return wrappedJSITDecisionTable;
    }
    return null;
}
Also used : JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) WrapperUtils.getWrappedJSITContext(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) WrapperUtils.getWrappedJSITFunctionDefinition(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITFunctionDefinition) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) JSITRelation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRelation) WrapperUtils.getWrappedJSITRelation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITRelation) JSITList(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList) WrapperUtils.getWrappedJSITList(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITList) WrapperUtils.getWrappedJSITInvocation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITInvocation) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) JSITInvocation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation) WrapperUtils.getWrappedJSITLiteralExpression(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITLiteralExpression) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) WrapperUtils.getWrappedJSITDecisionTable(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITDecisionTable) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) JSITRelation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRelation) WrapperUtils.getWrappedJSITRelation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITRelation) JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) WrapperUtils.getWrappedJSITContext(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITContext) List(org.kie.workbench.common.dmn.api.definition.model.List) JSITList(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList) WrapperUtils.getWrappedJSITList(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITList) WrapperUtils.getWrappedJSITInvocation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITInvocation) JSITInvocation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation) WrapperUtils.getWrappedJSITFunctionDefinition(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITFunctionDefinition) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) JSITComponentWidths(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITComponentWidths) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) WrapperUtils.getWrappedJSITDecisionTable(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITDecisionTable)

Example 25 with FunctionDefinition

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

the class ExpressionPropertyConverter method wbFromDMN.

public static Expression wbFromDMN(final JSITExpression dmn, final JSITExpression parent, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    if (JSITLiteralExpression.instanceOf(dmn)) {
        final JSITLiteralExpression jsiExpression = Js.uncheckedCast(dmn);
        final LiteralExpression e = LiteralExpressionPropertyConverter.wbFromDMN(jsiExpression);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (JSITContext.instanceOf(dmn)) {
        final JSITContext jsiExpression = Js.uncheckedCast(dmn);
        final Context e = ContextPropertyConverter.wbFromDMN(jsiExpression, parent, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (JSITRelation.instanceOf(dmn)) {
        final JSITRelation jsiExpression = Js.uncheckedCast(dmn);
        final Relation e = RelationPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (JSITList.instanceOf(dmn)) {
        final JSITList jsiExpression = Js.uncheckedCast(dmn);
        final List e = ListPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (JSITInvocation.instanceOf(dmn)) {
        final JSITInvocation jsiExpression = Js.uncheckedCast(dmn);
        final Invocation e = InvocationPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (JSITFunctionDefinition.instanceOf(dmn)) {
        final JSITFunctionDefinition jsiExpression = Js.uncheckedCast(dmn);
        final FunctionDefinition e = FunctionDefinitionPropertyConverter.wbFromDMN(jsiExpression, hasComponentWidthsConsumer);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    } else if (JSITDecisionTable.instanceOf(dmn)) {
        final JSITDecisionTable jsiExpression = Js.uncheckedCast(dmn);
        final DecisionTable e = DecisionTablePropertyConverter.wbFromDMN(jsiExpression);
        hasComponentWidthsConsumer.accept(dmn.getId(), e);
        return e;
    }
    return null;
}
Also used : JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) WrapperUtils.getWrappedJSITContext(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) WrapperUtils.getWrappedJSITFunctionDefinition(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITFunctionDefinition) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) JSITRelation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRelation) WrapperUtils.getWrappedJSITRelation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITRelation) JSITList(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList) WrapperUtils.getWrappedJSITList(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITList) WrapperUtils.getWrappedJSITInvocation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITInvocation) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) JSITInvocation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) WrapperUtils.getWrappedJSITLiteralExpression(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITLiteralExpression) IsLiteralExpression(org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) WrapperUtils.getWrappedJSITLiteralExpression(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITLiteralExpression) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) WrapperUtils.getWrappedJSITDecisionTable(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITDecisionTable) DecisionTable(org.kie.workbench.common.dmn.api.definition.model.DecisionTable) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) JSITRelation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRelation) WrapperUtils.getWrappedJSITRelation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITRelation) JSITContext(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITContext) WrapperUtils.getWrappedJSITContext(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITContext) List(org.kie.workbench.common.dmn.api.definition.model.List) JSITList(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList) WrapperUtils.getWrappedJSITList(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITList) WrapperUtils.getWrappedJSITInvocation(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITInvocation) JSITInvocation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInvocation) WrapperUtils.getWrappedJSITFunctionDefinition(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITFunctionDefinition) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) JSITFunctionDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITFunctionDefinition) JSITDecisionTable(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionTable) WrapperUtils.getWrappedJSITDecisionTable(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils.getWrappedJSITDecisionTable)

Aggregations

FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)40 Test (org.junit.Test)12 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)12 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)12 Context (org.kie.workbench.common.dmn.api.definition.model.Context)11 ArrayList (java.util.ArrayList)8 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)8 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)8 Before (org.junit.Before)7 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)7 View (org.kie.workbench.common.stunner.core.graph.content.view.View)7 TFunctionDefinition (org.kie.dmn.model.v1_2.TFunctionDefinition)5 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)5 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)5 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)5 IsLiteralExpression (org.kie.workbench.common.dmn.api.definition.model.IsLiteralExpression)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)5 List (java.util.List)4 QName (javax.xml.namespace.QName)4 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)4