@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); }
@Override public org.kie.dmn.model.api.BusinessKnowledgeModel dmnFromNode(final Node<View<BusinessKnowledgeModel>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) { final BusinessKnowledgeModel source = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(node); final org.kie.dmn.model.api.BusinessKnowledgeModel result = new org.kie.dmn.model.v1_2.TBusinessKnowledgeModel(); result.setId(source.getId().getValue()); result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription())); result.setName(source.getName().getValue()); DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, result); final org.kie.dmn.model.api.InformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source); if (variable != null) { variable.setParent(result); } result.setVariable(variable); final org.kie.dmn.model.api.FunctionDefinition functionDefinition = FunctionDefinitionPropertyConverter.dmnFromWB(source.getEncapsulatedLogic(), componentWidthsConsumer); final FunctionDefinition wbFunctionDefinition = source.getEncapsulatedLogic(); if (Objects.nonNull(wbFunctionDefinition)) { final String uuid = wbFunctionDefinition.getId().getValue(); if (Objects.nonNull(uuid)) { final ComponentWidths componentWidths = new ComponentWidths(); componentWidths.setDmnElementRef(new QName(uuid)); componentWidths.setWidths(new ArrayList<>(source.getEncapsulatedLogic().getComponentWidths())); componentWidthsConsumer.accept(componentWidths); } } if (functionDefinition != null) { functionDefinition.setParent(result); } result.setEncapsulatedLogic(functionDefinition); final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges(); for (Edge<?, ?> e : inEdges) { final Node<?, ?> sourceNode = e.getSourceNode(); if (sourceNode.getContent() instanceof View<?>) { final View<?> view = (View<?>) sourceNode.getContent(); if (view.getDefinition() instanceof DRGElement) { final DRGElement drgElement = (DRGElement) view.getDefinition(); if (drgElement instanceof BusinessKnowledgeModel) { final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredKnowledge(ri); result.getKnowledgeRequirement().add(iReq); } else if (drgElement instanceof KnowledgeSource) { final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredAuthority(ri); result.getAuthorityRequirement().add(iReq); } else if (drgElement instanceof DecisionService) { if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) { final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredKnowledge(ri); result.getKnowledgeRequirement().add(iReq); } else { throw new UnsupportedOperationException("wrong model definition."); } } else { throw new UnsupportedOperationException("wrong model definition."); } } } } return result; }
BusinessKnowledgeModelConverter implements NodeConverter<org.kie.dmn.model.api.BusinessKnowledgeModel, org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel> { @Override public org.kie.dmn.model.api.BusinessKnowledgeModel dmnFromNode(final Node<View<BusinessKnowledgeModel>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) { final BusinessKnowledgeModel source = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(node); final org.kie.dmn.model.api.BusinessKnowledgeModel result = new org.kie.dmn.model.v1_2.TBusinessKnowledgeModel(); result.setId(source.getId().getValue()); result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription())); result.setName(source.getName().getValue()); DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, result); final org.kie.dmn.model.api.InformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source); if (variable != null) { variable.setParent(result); } result.setVariable(variable); final org.kie.dmn.model.api.FunctionDefinition functionDefinition = FunctionDefinitionPropertyConverter.dmnFromWB(source.getEncapsulatedLogic(), componentWidthsConsumer); final FunctionDefinition wbFunctionDefinition = source.getEncapsulatedLogic(); if (Objects.nonNull(wbFunctionDefinition)) { final String uuid = wbFunctionDefinition.getId().getValue(); if (Objects.nonNull(uuid)) { final ComponentWidths componentWidths = new ComponentWidths(); componentWidths.setDmnElementRef(new QName(uuid)); componentWidths.setWidths(new ArrayList<>(source.getEncapsulatedLogic().getComponentWidths())); componentWidthsConsumer.accept(componentWidths); } } if (functionDefinition != null) { functionDefinition.setParent(result); } result.setEncapsulatedLogic(functionDefinition); final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges(); for (Edge<?, ?> e : inEdges) { final Node<?, ?> sourceNode = e.getSourceNode(); if (sourceNode.getContent() instanceof View<?>) { final View<?> view = (View<?>) sourceNode.getContent(); if (view.getDefinition() instanceof DRGElement) { final DRGElement drgElement = (DRGElement) view.getDefinition(); if (drgElement instanceof BusinessKnowledgeModel) { final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredKnowledge(ri); result.getKnowledgeRequirement().add(iReq); } else if (drgElement instanceof KnowledgeSource) { final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredAuthority(ri); result.getAuthorityRequirement().add(iReq); } else if (drgElement instanceof DecisionService) { if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) { final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredKnowledge(ri); result.getKnowledgeRequirement().add(iReq); } else { throw new UnsupportedOperationException("wrong model definition."); } } else { throw new UnsupportedOperationException("wrong model definition."); } } } } return result; } }
BusinessKnowledgeModelConverter implements NodeConverter<org.kie.dmn.model.api.BusinessKnowledgeModel, org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel> { @Override public org.kie.dmn.model.api.BusinessKnowledgeModel dmnFromNode(final Node<View<BusinessKnowledgeModel>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) { final BusinessKnowledgeModel source = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(node); final org.kie.dmn.model.api.BusinessKnowledgeModel result = new org.kie.dmn.model.v1_2.TBusinessKnowledgeModel(); result.setId(source.getId().getValue()); result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription())); result.setName(source.getName().getValue()); DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, result); final org.kie.dmn.model.api.InformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source); if (variable != null) { variable.setParent(result); } result.setVariable(variable); final org.kie.dmn.model.api.FunctionDefinition functionDefinition = FunctionDefinitionPropertyConverter.dmnFromWB(source.getEncapsulatedLogic(), componentWidthsConsumer); final FunctionDefinition wbFunctionDefinition = source.getEncapsulatedLogic(); if (Objects.nonNull(wbFunctionDefinition)) { final String uuid = wbFunctionDefinition.getId().getValue(); if (Objects.nonNull(uuid)) { final ComponentWidths componentWidths = new ComponentWidths(); componentWidths.setDmnElementRef(new QName(uuid)); componentWidths.setWidths(new ArrayList<>(source.getEncapsulatedLogic().getComponentWidths())); componentWidthsConsumer.accept(componentWidths); } } if (functionDefinition != null) { functionDefinition.setParent(result); } result.setEncapsulatedLogic(functionDefinition); final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges(); for (Edge<?, ?> e : inEdges) { final Node<?, ?> sourceNode = e.getSourceNode(); if (sourceNode.getContent() instanceof View<?>) { final View<?> view = (View<?>) sourceNode.getContent(); if (view.getDefinition() instanceof DRGElement) { final DRGElement drgElement = (DRGElement) view.getDefinition(); if (drgElement instanceof BusinessKnowledgeModel) { final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredKnowledge(ri); result.getKnowledgeRequirement().add(iReq); } else if (drgElement instanceof KnowledgeSource) { final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredAuthority(ri); result.getAuthorityRequirement().add(iReq); } else if (drgElement instanceof DecisionService) { if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) { final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredKnowledge(ri); result.getKnowledgeRequirement().add(iReq); } else { throw new UnsupportedOperationException("wrong model definition."); } } else { throw new UnsupportedOperationException("wrong model definition."); } } } } return result; } BusinessKnowledgeModelConverter(final FactoryManager factoryManager); }
BusinessKnowledgeModelConverter implements NodeConverter<org.kie.dmn.model.api.BusinessKnowledgeModel, org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel> { @Override public org.kie.dmn.model.api.BusinessKnowledgeModel dmnFromNode(final Node<View<BusinessKnowledgeModel>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) { final BusinessKnowledgeModel source = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(node); final org.kie.dmn.model.api.BusinessKnowledgeModel result = new org.kie.dmn.model.v1_2.TBusinessKnowledgeModel(); result.setId(source.getId().getValue()); result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription())); result.setName(source.getName().getValue()); DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, result); final org.kie.dmn.model.api.InformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source); if (variable != null) { variable.setParent(result); } result.setVariable(variable); final org.kie.dmn.model.api.FunctionDefinition functionDefinition = FunctionDefinitionPropertyConverter.dmnFromWB(source.getEncapsulatedLogic(), componentWidthsConsumer); final FunctionDefinition wbFunctionDefinition = source.getEncapsulatedLogic(); if (Objects.nonNull(wbFunctionDefinition)) { final String uuid = wbFunctionDefinition.getId().getValue(); if (Objects.nonNull(uuid)) { final ComponentWidths componentWidths = new ComponentWidths(); componentWidths.setDmnElementRef(new QName(uuid)); componentWidths.setWidths(new ArrayList<>(source.getEncapsulatedLogic().getComponentWidths())); componentWidthsConsumer.accept(componentWidths); } } if (functionDefinition != null) { functionDefinition.setParent(result); } result.setEncapsulatedLogic(functionDefinition); final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges(); for (Edge<?, ?> e : inEdges) { final Node<?, ?> sourceNode = e.getSourceNode(); if (sourceNode.getContent() instanceof View<?>) { final View<?> view = (View<?>) sourceNode.getContent(); if (view.getDefinition() instanceof DRGElement) { final DRGElement drgElement = (DRGElement) view.getDefinition(); if (drgElement instanceof BusinessKnowledgeModel) { final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredKnowledge(ri); result.getKnowledgeRequirement().add(iReq); } else if (drgElement instanceof KnowledgeSource) { final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredAuthority(ri); result.getAuthorityRequirement().add(iReq); } else if (drgElement instanceof DecisionService) { if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) { final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredKnowledge(ri); result.getKnowledgeRequirement().add(iReq); } else { throw new UnsupportedOperationException("wrong model definition."); } } else { throw new UnsupportedOperationException("wrong model definition."); } } } } return result; } BusinessKnowledgeModelConverter(final FactoryManager factoryManager); @Override Node<View<BusinessKnowledgeModel>, ?> nodeFromDMN(final org.kie.dmn.model.api.BusinessKnowledgeModel dmn,
                                                             final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer); @Override org.kie.dmn.model.api.BusinessKnowledgeModel dmnFromNode(final Node<View<BusinessKnowledgeModel>, ?> node,
                                                                    final Consumer<ComponentWidths> componentWidthsConsumer); }
BusinessKnowledgeModelConverter implements NodeConverter<org.kie.dmn.model.api.BusinessKnowledgeModel, org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel> { @Override public org.kie.dmn.model.api.BusinessKnowledgeModel dmnFromNode(final Node<View<BusinessKnowledgeModel>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) { final BusinessKnowledgeModel source = (BusinessKnowledgeModel) DefinitionUtils.getElementDefinition(node); final org.kie.dmn.model.api.BusinessKnowledgeModel result = new org.kie.dmn.model.v1_2.TBusinessKnowledgeModel(); result.setId(source.getId().getValue()); result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription())); result.setName(source.getName().getValue()); DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, result); final org.kie.dmn.model.api.InformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source); if (variable != null) { variable.setParent(result); } result.setVariable(variable); final org.kie.dmn.model.api.FunctionDefinition functionDefinition = FunctionDefinitionPropertyConverter.dmnFromWB(source.getEncapsulatedLogic(), componentWidthsConsumer); final FunctionDefinition wbFunctionDefinition = source.getEncapsulatedLogic(); if (Objects.nonNull(wbFunctionDefinition)) { final String uuid = wbFunctionDefinition.getId().getValue(); if (Objects.nonNull(uuid)) { final ComponentWidths componentWidths = new ComponentWidths(); componentWidths.setDmnElementRef(new QName(uuid)); componentWidths.setWidths(new ArrayList<>(source.getEncapsulatedLogic().getComponentWidths())); componentWidthsConsumer.accept(componentWidths); } } if (functionDefinition != null) { functionDefinition.setParent(result); } result.setEncapsulatedLogic(functionDefinition); final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges(); for (Edge<?, ?> e : inEdges) { final Node<?, ?> sourceNode = e.getSourceNode(); if (sourceNode.getContent() instanceof View<?>) { final View<?> view = (View<?>) sourceNode.getContent(); if (view.getDefinition() instanceof DRGElement) { final DRGElement drgElement = (DRGElement) view.getDefinition(); if (drgElement instanceof BusinessKnowledgeModel) { final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredKnowledge(ri); result.getKnowledgeRequirement().add(iReq); } else if (drgElement instanceof KnowledgeSource) { final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredAuthority(ri); result.getAuthorityRequirement().add(iReq); } else if (drgElement instanceof DecisionService) { if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) { final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement(); iReq.setId(e.getUUID()); final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference(); ri.setHref(getHref(drgElement)); iReq.setRequiredKnowledge(ri); result.getKnowledgeRequirement().add(iReq); } else { throw new UnsupportedOperationException("wrong model definition."); } } else { throw new UnsupportedOperationException("wrong model definition."); } } } } return result; } BusinessKnowledgeModelConverter(final FactoryManager factoryManager); @Override Node<View<BusinessKnowledgeModel>, ?> nodeFromDMN(final org.kie.dmn.model.api.BusinessKnowledgeModel dmn,
                                                             final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer); @Override org.kie.dmn.model.api.BusinessKnowledgeModel dmnFromNode(final Node<View<BusinessKnowledgeModel>, ?> node,
                                                                    final Consumer<ComponentWidths> componentWidthsConsumer);  }