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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations