Search in sources :

Example 1 with InformationItemPrimary

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

the class BusinessKnowledgeModelConverter method nodeFromDMN.

@Override
public Node<View<BusinessKnowledgeModel>, ?> nodeFromDMN(final org.kie.dmn.model.api.BusinessKnowledgeModel dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    @SuppressWarnings("unchecked") final Node<View<BusinessKnowledgeModel>, ?> node = (Node<View<BusinessKnowledgeModel>, ?>) factoryManager.newElement(dmn.getId(), getDefinitionId(BusinessKnowledgeModel.class)).asNode();
    final Id id = new Id(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final Name name = new Name(dmn.getName());
    final InformationItemPrimary informationItem = InformationItemPrimaryPropertyConverter.wbFromDMN(dmn.getVariable(), dmn);
    final org.kie.dmn.model.api.FunctionDefinition dmnFunctionDefinition = dmn.getEncapsulatedLogic();
    final FunctionDefinition functionDefinition = FunctionDefinitionPropertyConverter.wbFromDMN(dmnFunctionDefinition, hasComponentWidthsConsumer);
    final BusinessKnowledgeModel bkm = new BusinessKnowledgeModel(id, description, name, informationItem, functionDefinition, new StylingSet(), new GeneralRectangleDimensionsSet());
    node.getContent().setDefinition(bkm);
    if (informationItem != null) {
        informationItem.setParent(bkm);
    }
    if (functionDefinition != null) {
        functionDefinition.setParent(bkm);
    }
    if (Objects.nonNull(dmnFunctionDefinition)) {
        hasComponentWidthsConsumer.accept(dmnFunctionDefinition.getId(), functionDefinition);
    }
    DMNExternalLinksToExtensionElements.loadExternalLinksFromExtensionElements(dmn, bkm);
    return node;
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Node(org.kie.workbench.common.stunner.core.graph.Node) GeneralRectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.GeneralRectangleDimensionsSet) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) QName(javax.xml.namespace.QName) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) BindableAdapterUtils.getDefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId)

Example 2 with InformationItemPrimary

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

the class DecisionConverter method nodeFromDMN.

@Override
public Node<View<Decision>, ?> nodeFromDMN(final org.kie.dmn.model.api.Decision dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    @SuppressWarnings("unchecked") final Node<View<Decision>, ?> node = (Node<View<Decision>, ?>) factoryManager.newElement(dmn.getId(), getDefinitionId(Decision.class)).asNode();
    final Id id = new Id(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final Name name = new Name(dmn.getName());
    final InformationItemPrimary informationItem = InformationItemPrimaryPropertyConverter.wbFromDMN(dmn.getVariable(), dmn);
    final Expression expression = ExpressionPropertyConverter.wbFromDMN(dmn.getExpression(), hasComponentWidthsConsumer);
    final Decision decision = new Decision(id, description, name, new Question(), new AllowedAnswers(), informationItem, expression, new StylingSet(), new GeneralRectangleDimensionsSet());
    decision.setQuestion(QuestionPropertyConverter.wbFromDMN(dmn.getQuestion()));
    decision.setAllowedAnswers(AllowedAnswersPropertyConverter.wbFromDMN(dmn.getAllowedAnswers()));
    node.getContent().setDefinition(decision);
    if (informationItem != null) {
        informationItem.setParent(decision);
    }
    if (expression != null) {
        expression.setParent(decision);
    }
    DMNExternalLinksToExtensionElements.loadExternalLinksFromExtensionElements(dmn, decision);
    return node;
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Node(org.kie.workbench.common.stunner.core.graph.Node) GeneralRectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.GeneralRectangleDimensionsSet) AllowedAnswers(org.kie.workbench.common.dmn.api.property.dmn.AllowedAnswers) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) Question(org.kie.workbench.common.dmn.api.property.dmn.Question) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) BindableAdapterUtils.getDefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId)

Example 3 with InformationItemPrimary

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

the class DecisionServiceConverter method nodeFromDMN.

@Override
public Node<View<DecisionService>, ?> nodeFromDMN(final org.kie.dmn.model.api.DecisionService dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    @SuppressWarnings("unchecked") final Node<View<DecisionService>, ?> node = (Node<View<DecisionService>, ?>) factoryManager.newElement(dmn.getId(), getDefinitionId(DecisionService.class)).asNode();
    final Id id = new Id(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final Name name = new Name(dmn.getName());
    final InformationItemPrimary informationItem = InformationItemPrimaryPropertyConverter.wbFromDMN(dmn.getVariable(), dmn);
    final List<DMNElementReference> outputDecision = dmn.getOutputDecision().stream().map(DMNElementReferenceConverter::wbFromDMN).collect(Collectors.toList());
    final List<DMNElementReference> encapsulatedDecision = dmn.getEncapsulatedDecision().stream().map(DMNElementReferenceConverter::wbFromDMN).collect(Collectors.toList());
    final List<DMNElementReference> inputDecision = dmn.getInputDecision().stream().map(DMNElementReferenceConverter::wbFromDMN).collect(Collectors.toList());
    final List<DMNElementReference> inputData = dmn.getInputData().stream().map(DMNElementReferenceConverter::wbFromDMN).collect(Collectors.toList());
    final DecisionService decisionService = new DecisionService(id, description, name, informationItem, outputDecision, encapsulatedDecision, inputDecision, inputData, new StylingSet(), new DecisionServiceRectangleDimensionsSet(), new DecisionServiceDividerLineY());
    node.getContent().setDefinition(decisionService);
    if (informationItem != null) {
        informationItem.setParent(decisionService);
    }
    DMNExternalLinksToExtensionElements.loadExternalLinksFromExtensionElements(dmn, decisionService);
    return node;
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Node(org.kie.workbench.common.stunner.core.graph.Node) View(org.kie.workbench.common.stunner.core.graph.content.view.View) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) DecisionServiceDividerLineY(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY) DMNElementReference(org.kie.workbench.common.dmn.api.definition.model.DMNElementReference) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) BindableAdapterUtils.getDefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId) DecisionServiceRectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.DecisionServiceRectangleDimensionsSet)

Example 4 with InformationItemPrimary

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

the class InformationItemPrimaryPropertyConverter method wbFromDMN.

public static InformationItemPrimary wbFromDMN(final InformationItem dmn, final org.kie.dmn.model.api.DMNModelInstrumentedBase parent) {
    if (dmn == null) {
        return null;
    }
    final Id id = new Id(dmn.getId());
    final Name name = new Name(getParentName(parent));
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef(), dmn);
    return new InformationItemPrimary(id, name, typeRef);
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) HasName(org.kie.workbench.common.dmn.api.definition.HasName) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Example 5 with InformationItemPrimary

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

Aggregations

InformationItemPrimary (org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary)39 Test (org.junit.Test)21 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)18 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)17 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)14 View (org.kie.workbench.common.stunner.core.graph.content.view.View)13 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)12 Node (org.kie.workbench.common.stunner.core.graph.Node)10 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)9 StylingSet (org.kie.workbench.common.dmn.api.property.styling.StylingSet)8 BindableAdapterUtils.getDefinitionId (org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId)8 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)7 GeneralRectangleDimensionsSet (org.kie.workbench.common.dmn.api.property.dimensions.GeneralRectangleDimensionsSet)6 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)5 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)5 OutputClause (org.kie.workbench.common.dmn.api.definition.model.OutputClause)5 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)5 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)4 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)4 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)4