Search in sources :

Example 16 with LiteralExpression

use of org.kie.workbench.common.dmn.api.definition.model.LiteralExpression 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)

Example 17 with LiteralExpression

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

the class DecisionRulePropertyConverter method dmnFromWB.

public static JSITDecisionRule dmnFromWB(final DecisionRule wb) {
    final JSITDecisionRule result = new JSITDecisionRule();
    result.setId(wb.getId().getValue());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    description.ifPresent(result::setDescription);
    for (final RuleAnnotationClauseText ruleAnnotationClauseText : wb.getAnnotationEntry()) {
        final JSITRuleAnnotation ruleAnnotation = RuleAnnotationClauseTextPropertyConverter.dmnFromWB(ruleAnnotationClauseText);
        result.addAnnotationEntry(ruleAnnotation);
    }
    for (UnaryTests ie : wb.getInputEntry()) {
        final JSITUnaryTests inputEntryConverted = UnaryTestsPropertyConverter.dmnFromWB(ie);
        result.addInputEntry(inputEntryConverted);
    }
    for (LiteralExpression oe : wb.getOutputEntry()) {
        final JSITLiteralExpression outputEntryConverted = LiteralExpressionPropertyConverter.dmnFromWB(oe);
        result.addOutputEntry(outputEntryConverted);
    }
    return result;
}
Also used : JSITUnaryTests(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) JSITDecisionRule(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) JSITUnaryTests(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests) JSITRuleAnnotation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRuleAnnotation)

Example 18 with LiteralExpression

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

the class DecisionRulePropertyConverter method wbFromDMN.

public static DecisionRule wbFromDMN(final JSITDecisionRule dmn) {
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final DecisionRule result = new DecisionRule();
    result.setId(id);
    result.setDescription(description);
    final List<JSITRuleAnnotation> jsiAnnotationEntries = dmn.getAnnotationEntry();
    for (int i = 0; i < jsiAnnotationEntries.size(); i++) {
        final JSITRuleAnnotation jsiRuleAnnotation = Js.uncheckedCast(jsiAnnotationEntries.get(i));
        final RuleAnnotationClauseText ruleAnnotationClauseText = RuleAnnotationClauseTextPropertyConverter.wbFromDMN(jsiRuleAnnotation);
        if (Objects.nonNull(ruleAnnotationClauseText)) {
            ruleAnnotationClauseText.setParent(result);
            result.getAnnotationEntry().add(ruleAnnotationClauseText);
        }
    }
    if (result.getAnnotationEntry().isEmpty()) {
        final RuleAnnotationClauseText annotationEntryText = new RuleAnnotationClauseText();
        annotationEntryText.getText().setValue(description.getValue());
        annotationEntryText.setParent(result);
        result.getAnnotationEntry().add(annotationEntryText);
    }
    final List<JSITUnaryTests> jsiInputEntries = dmn.getInputEntry();
    for (int i = 0; i < jsiInputEntries.size(); i++) {
        final JSITUnaryTests jsiInputEntry = Js.uncheckedCast(jsiInputEntries.get(i));
        final UnaryTests inputEntryConverted = UnaryTestsPropertyConverter.wbFromDMN(jsiInputEntry);
        if (Objects.nonNull(inputEntryConverted)) {
            inputEntryConverted.setParent(result);
            result.getInputEntry().add(inputEntryConverted);
        }
    }
    final List<JSITLiteralExpression> jsiOutputEntries = dmn.getOutputEntry();
    for (int i = 0; i < jsiOutputEntries.size(); i++) {
        final JSITLiteralExpression jsiOutputEntry = Js.uncheckedCast(jsiOutputEntries.get(i));
        final LiteralExpression outputEntryConverted = LiteralExpressionPropertyConverter.wbFromDMN(jsiOutputEntry);
        if (Objects.nonNull(outputEntryConverted)) {
            outputEntryConverted.setParent(result);
            result.getOutputEntry().add(outputEntryConverted);
        }
    }
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) RuleAnnotationClauseText(org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText) JSITDecisionRule(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionRule) DecisionRule(org.kie.workbench.common.dmn.api.definition.model.DecisionRule) JSITRuleAnnotation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITRuleAnnotation) JSITUnaryTests(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests) JSITLiteralExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITLiteralExpression) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) UnaryTests(org.kie.workbench.common.dmn.api.definition.model.UnaryTests) JSITUnaryTests(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITUnaryTests)

Example 19 with LiteralExpression

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

the class BusinessKnowledgeModelConverterTest method testDMNFromWB.

@Test
public void testDMNFromWB() {
    final BusinessKnowledgeModel wb = new BusinessKnowledgeModel();
    final LiteralExpression literalExpression = new LiteralExpression();
    final InformationItemPrimary informationItem = new InformationItemPrimary();
    final FunctionDefinition functionDefinition = new FunctionDefinition();
    literalExpression.getComponentWidths().set(0, 200.0);
    literalExpression.getId().setValue(EXPRESSION_UUID);
    functionDefinition.getComponentWidths().set(0, 200.0);
    functionDefinition.setExpression(literalExpression);
    functionDefinition.getId().setValue(FUNCTION_DEFINITION_UUID);
    wb.getId().setValue(DECISION_UUID);
    wb.getName().setValue(DECISION_NAME);
    wb.getDescription().setValue(DECISION_DESCRIPTION);
    wb.setVariable(informationItem);
    wb.setEncapsulatedLogic(functionDefinition);
    final Node<View<BusinessKnowledgeModel>, ?> node = new NodeImpl<>(UUID.uuid());
    final View<BusinessKnowledgeModel> view = new ViewImpl<>(wb, Bounds.create());
    node.setContent(view);
    final org.kie.dmn.model.api.BusinessKnowledgeModel dmn = converter.dmnFromNode(node, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getId()).isNotNull();
    assertThat(dmn.getId()).isEqualTo(DECISION_UUID);
    assertThat(dmn.getName()).isNotNull();
    assertThat(dmn.getName()).isEqualTo(DECISION_NAME);
    assertThat(dmn.getDescription()).isNotNull();
    assertThat(dmn.getDescription()).isEqualTo(DECISION_DESCRIPTION);
    assertThat(dmn.getVariable()).isNotNull();
    assertThat(dmn.getVariable().getName()).isEqualTo(DECISION_NAME);
    assertThat(dmn.getEncapsulatedLogic()).isNotNull();
    assertThat(dmn.getEncapsulatedLogic().getExpression()).isNotNull();
    assertThat(dmn.getEncapsulatedLogic().getExpression().getId()).isEqualTo(EXPRESSION_UUID);
    verify(componentWidthsConsumer, times(2)).accept(componentWidthsCaptor.capture());
    final List<ComponentWidths> componentWidths = componentWidthsCaptor.getAllValues();
    assertThat(componentWidths).isNotNull();
    assertThat(componentWidths).hasSize(2);
    final ComponentWidths componentWidths0 = componentWidths.get(0);
    assertThat(componentWidths0.getDmnElementRef().getLocalPart()).isEqualTo(EXPRESSION_UUID);
    assertThat(componentWidths0.getWidths().size()).isEqualTo(literalExpression.getRequiredComponentWidthCount());
    assertThat(componentWidths0.getWidths().get(0)).isEqualTo(200.0);
    final ComponentWidths componentWidths1 = componentWidths.get(1);
    assertThat(componentWidths1.getDmnElementRef().getLocalPart()).isEqualTo(FUNCTION_DEFINITION_UUID);
    assertThat(componentWidths1.getWidths().size()).isEqualTo(functionDefinition.getRequiredComponentWidthCount());
    assertThat(componentWidths1.getWidths().get(0)).isEqualTo(200.0);
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) View(org.kie.workbench.common.stunner.core.graph.content.view.View) TBusinessKnowledgeModel(org.kie.dmn.model.v1_2.TBusinessKnowledgeModel) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) TFunctionDefinition(org.kie.dmn.model.v1_2.TFunctionDefinition) 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 20 with LiteralExpression

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

the class DecisionConverterTest method testDMNFromWB.

@Test
public void testDMNFromWB() {
    final Decision wb = new Decision();
    final LiteralExpression literalExpression = new LiteralExpression();
    final InformationItemPrimary informationItem = new InformationItemPrimary();
    literalExpression.getComponentWidths().set(0, 200.0);
    literalExpression.getId().setValue(EXPRESSION_UUID);
    wb.getId().setValue(DECISION_UUID);
    wb.getName().setValue(DECISION_NAME);
    wb.getDescription().setValue(DECISION_DESCRIPTION);
    wb.setVariable(informationItem);
    wb.setExpression(literalExpression);
    final Node<View<Decision>, ?> node = new NodeImpl<>(UUID.uuid());
    final View<Decision> view = new ViewImpl<>(wb, Bounds.create());
    node.setContent(view);
    final org.kie.dmn.model.api.Decision dmn = converter.dmnFromNode(node, componentWidthsConsumer);
    assertThat(dmn).isNotNull();
    assertThat(dmn.getId()).isNotNull();
    assertThat(dmn.getId()).isEqualTo(DECISION_UUID);
    assertThat(dmn.getName()).isNotNull();
    assertThat(dmn.getName()).isEqualTo(DECISION_NAME);
    assertThat(dmn.getDescription()).isNotNull();
    assertThat(dmn.getDescription()).isEqualTo(DECISION_DESCRIPTION);
    assertThat(dmn.getVariable()).isNotNull();
    assertThat(dmn.getVariable().getName()).isEqualTo(DECISION_NAME);
    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 : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) NodeImpl(org.kie.workbench.common.stunner.core.graph.impl.NodeImpl) TLiteralExpression(org.kie.dmn.model.v1_2.TLiteralExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) View(org.kie.workbench.common.stunner.core.graph.content.view.View) TDecision(org.kie.dmn.model.v1_2.TDecision) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) 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)

Aggregations

LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)113 Test (org.junit.Test)64 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)25 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)25 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)23 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)21 List (org.kie.workbench.common.dmn.api.definition.model.List)20 UnaryTests (org.kie.workbench.common.dmn.api.definition.model.UnaryTests)16 DecisionRule (org.kie.workbench.common.dmn.api.definition.model.DecisionRule)15 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)14 Before (org.junit.Before)13 RuleAnnotationClauseText (org.kie.workbench.common.dmn.api.definition.model.RuleAnnotationClauseText)12 Optional (java.util.Optional)11 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)11 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)11 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)11 Context (org.kie.workbench.common.dmn.api.definition.model.Context)10 BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)10 ContextEntry (org.kie.workbench.common.dmn.api.definition.model.ContextEntry)9 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)9