@Test public void test_function_java_WB_model() throws IOException { final DMNMarshallerStandalone m = getDMNMarshaller(); @SuppressWarnings("unchecked") final Graph<?, Node<?, ?>> g = m.unmarshall(createMetadata(), this.getClass().getResourceAsStream("/DROOLS-2372.dmn")); final Stream<Node<?, ?>> stream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(g.nodes().iterator(), Spliterator.ORDERED), false); final Optional<Decision> wbDecision = stream .filter(n -> n.getContent() instanceof ViewImpl) .map(n -> (ViewImpl) n.getContent()) .filter(n -> n.getDefinition() instanceof Decision) .map(n -> (Decision) n.getDefinition()) .findFirst(); wbDecision.ifPresent(d -> { assertTrue(d.getExpression() instanceof FunctionDefinition); final FunctionDefinition wbFunction = (FunctionDefinition) d.getExpression(); assertEquals(FunctionDefinition.Kind.JAVA, wbFunction.getKind()); }); final DMNRuntime runtime = roundTripUnmarshalMarshalThenUnmarshalDMN(this.getClass().getResourceAsStream("/DROOLS-2372.dmn")); final DMNModel dmnModel = runtime.getModels().get(0); final BusinessKnowledgeModelNode bkmNode = dmnModel.getBusinessKnowledgeModels().iterator().next(); final org.kie.dmn.model.api.FunctionDefinition dmnFunction = bkmNode.getBusinessKnowledModel().getEncapsulatedLogic(); assertEquals(FunctionKind.JAVA, dmnFunction.getKind()); }
@Override @SuppressWarnings("unchecked") public Graph unmarshall(final Metadata metadata, final InputStream input) throws IOException { final Map<String, HasComponentWidths> hasComponentWidthsMap = new HashMap<>(); final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer = (uuid, hcw) -> { if (Objects.nonNull(uuid)) { hasComponentWidthsMap.put(uuid, hcw); } }; final org.kie.dmn.model.api.Definitions dmnXml = marshaller.unmarshal(new InputStreamReader(input)); final List<org.kie.dmn.model.api.DRGElement> diagramDrgElements = dmnXml.getDrgElement(); final Optional<org.kie.dmn.model.api.dmndi.DMNDiagram> dmnDDDiagram = findDMNDiagram(dmnXml); final Map<Import, org.kie.dmn.model.api.Definitions> importDefinitions = dmnMarshallerImportsHelper.getImportDefinitions(metadata, dmnXml.getImport()); final Map<Import, PMMLDocumentMetadata> pmmlDocuments = dmnMarshallerImportsHelper.getPMMLDocuments(metadata, dmnXml.getImport()); final List<DMNShape> dmnShapes = dmnDDDiagram.map(this::getUniqueDMNShapes).orElse(emptyList()); final List<org.kie.dmn.model.api.DRGElement> importedDrgElements = getImportedDrgElementsByShape(dmnShapes, importDefinitions); final List<org.kie.dmn.model.api.DRGElement> drgElements = new ArrayList<>(); drgElements.addAll(diagramDrgElements); drgElements.addAll(importedDrgElements); removeDrgElementsWithoutShape(drgElements, dmnShapes); final Map<String, Entry<org.kie.dmn.model.api.DRGElement, Node>> elems = drgElements.stream().collect(toMap(org.kie.dmn.model.api.DRGElement::getId, dmn -> new SimpleEntry<>(dmn, dmnToStunner(dmn, hasComponentWidthsConsumer, importedDrgElements)))); final Set<org.kie.dmn.model.api.DecisionService> dmnDecisionServices = new HashSet<>(); for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { ddExtAugmentStunner(dmnDDDiagram, kv.getValue()); } for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { final org.kie.dmn.model.api.DRGElement elem = kv.getKey(); final Node currentNode = kv.getValue(); if (isImportedDRGElement(importedDrgElements, elem)) { continue; } if (elem instanceof org.kie.dmn.model.api.Decision) { final org.kie.dmn.model.api.Decision decision = (org.kie.dmn.model.api.Decision) elem; for (org.kie.dmn.model.api.InformationRequirement ir : decision.getInformationRequirement()) { connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredInput(), elems, dmnXml, currentNode); connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredDecision(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.KnowledgeRequirement kr : decision.getKnowledgeRequirement()) { connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.AuthorityRequirement ar : decision.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.BusinessKnowledgeModel) { final org.kie.dmn.model.api.BusinessKnowledgeModel bkm = (org.kie.dmn.model.api.BusinessKnowledgeModel) elem; for (org.kie.dmn.model.api.KnowledgeRequirement kr : bkm.getKnowledgeRequirement()) { connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.AuthorityRequirement ar : bkm.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.KnowledgeSource) { final org.kie.dmn.model.api.KnowledgeSource ks = (org.kie.dmn.model.api.KnowledgeSource) elem; for (org.kie.dmn.model.api.AuthorityRequirement ar : ks.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredInput(), elems, dmnXml, currentNode); connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredDecision(), elems, dmnXml, currentNode); connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.DecisionService) { final org.kie.dmn.model.api.DecisionService ds = (org.kie.dmn.model.api.DecisionService) elem; dmnDecisionServices.add(ds); for (org.kie.dmn.model.api.DMNElementReference er : ds.getEncapsulatedDecision()) { final String reqInputID = getId(er); final Node requiredNode = getRequiredNode(elems, reqInputID); if (Objects.nonNull(requiredNode)) { connectDSChildEdge(currentNode, requiredNode); } } for (org.kie.dmn.model.api.DMNElementReference er : ds.getOutputDecision()) { final String reqInputID = getId(er); final Node requiredNode = getRequiredNode(elems, reqInputID); if (Objects.nonNull(requiredNode)) { connectDSChildEdge(currentNode, requiredNode); } } } } final Map<String, Node<View<TextAnnotation>, ?>> textAnnotations = dmnXml.getArtifact().stream() .filter(org.kie.dmn.model.api.TextAnnotation.class::isInstance) .map(org.kie.dmn.model.api.TextAnnotation.class::cast) .collect(Collectors.toMap(org.kie.dmn.model.api.TextAnnotation::getId, dmn -> textAnnotationConverter.nodeFromDMN(dmn, hasComponentWidthsConsumer))); textAnnotations.values().forEach(n -> ddExtAugmentStunner(dmnDDDiagram, n)); final List<org.kie.dmn.model.api.Association> associations = dmnXml.getArtifact().stream() .filter(org.kie.dmn.model.api.Association.class::isInstance) .map(org.kie.dmn.model.api.Association.class::cast) .collect(Collectors.toList()); for (org.kie.dmn.model.api.Association a : associations) { final String sourceId = getId(a.getSourceRef()); final Node sourceNode = Optional.ofNullable(elems.get(sourceId)).map(Entry::getValue).orElse(textAnnotations.get(sourceId)); final String targetId = getId(a.getTargetRef()); final Node targetNode = Optional.ofNullable(elems.get(targetId)).map(Entry::getValue).orElse(textAnnotations.get(targetId)); @SuppressWarnings("unchecked") final Edge<View<Association>, ?> myEdge = (Edge<View<Association>, ?>) factoryManager.newElement(idOfDMNorWBUUID(a), ASSOCIATION_ID).asEdge(); final Id id = new Id(a.getId()); final Description description = new Description(a.getDescription()); final Association definition = new Association(id, description); myEdge.getContent().setDefinition(definition); connectEdge(myEdge, sourceNode, targetNode); setConnectionMagnets(myEdge, a.getId(), dmnXml); } for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { PointUtils.convertToRelativeBounds(kv.getValue()); } final Graph graph = factoryManager.newDiagram("prova", BindableAdapterUtils.getDefinitionSetId(DMNDefinitionSet.class), metadata).getGraph(); elems.values().stream().map(Map.Entry::getValue).forEach(graph::addNode); textAnnotations.values().forEach(graph::addNode); final Node<?, ?> dmnDiagramRoot = findDMNDiagramRoot(graph); final Definitions definitionsStunnerPojo = DefinitionsConverter.wbFromDMN(dmnXml, importDefinitions, pmmlDocuments); loadImportedItemDefinitions(definitionsStunnerPojo, importDefinitions); ((View<DMNDiagram>) dmnDiagramRoot.getContent()).getDefinition().setDefinitions(definitionsStunnerPojo); final List<String> references = new ArrayList<>(); dmnDecisionServices.forEach(ds -> references.addAll(ds.getEncapsulatedDecision().stream().map(org.kie.dmn.model.api.DMNElementReference::getHref).collect(Collectors.toList()))); dmnDecisionServices.forEach(ds -> references.addAll(ds.getOutputDecision().stream().map(org.kie.dmn.model.api.DMNElementReference::getHref).collect(Collectors.toList()))); final Map<org.kie.dmn.model.api.DRGElement, Node> elemsToConnectToRoot = elems.values().stream() .filter(elem -> !references.contains("#" + elem.getKey().getId())) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); elemsToConnectToRoot.values().stream() .forEach(node -> connectRootWithChild(dmnDiagramRoot, node)); textAnnotations.values().stream().forEach(node -> connectRootWithChild(dmnDiagramRoot, node)); final Optional<ComponentsWidthsExtension> extension = findComponentsWidthsExtension(dmnDDDiagram); extension.ifPresent(componentsWidthsExtension -> { if (componentsWidthsExtension.getComponentsWidths() != null) { hasComponentWidthsMap.forEach((uuid, hasComponentWidths) -> componentsWidthsExtension .getComponentsWidths() .stream() .filter(componentWidths -> componentWidths.getDmnElementRef().getLocalPart().equals(uuid)) .findFirst() .ifPresent(componentWidths -> { final List<Double> widths = hasComponentWidths.getComponentWidths(); widths.clear(); widths.addAll(componentWidths.getWidths()); })); } }); return graph; }
DMNMarshallerStandalone implements DiagramMarshaller<Graph, Metadata, Diagram<Graph, Metadata>> { @Override @SuppressWarnings("unchecked") public Graph unmarshall(final Metadata metadata, final InputStream input) throws IOException { final Map<String, HasComponentWidths> hasComponentWidthsMap = new HashMap<>(); final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer = (uuid, hcw) -> { if (Objects.nonNull(uuid)) { hasComponentWidthsMap.put(uuid, hcw); } }; final org.kie.dmn.model.api.Definitions dmnXml = marshaller.unmarshal(new InputStreamReader(input)); final List<org.kie.dmn.model.api.DRGElement> diagramDrgElements = dmnXml.getDrgElement(); final Optional<org.kie.dmn.model.api.dmndi.DMNDiagram> dmnDDDiagram = findDMNDiagram(dmnXml); final Map<Import, org.kie.dmn.model.api.Definitions> importDefinitions = dmnMarshallerImportsHelper.getImportDefinitions(metadata, dmnXml.getImport()); final Map<Import, PMMLDocumentMetadata> pmmlDocuments = dmnMarshallerImportsHelper.getPMMLDocuments(metadata, dmnXml.getImport()); final List<DMNShape> dmnShapes = dmnDDDiagram.map(this::getUniqueDMNShapes).orElse(emptyList()); final List<org.kie.dmn.model.api.DRGElement> importedDrgElements = getImportedDrgElementsByShape(dmnShapes, importDefinitions); final List<org.kie.dmn.model.api.DRGElement> drgElements = new ArrayList<>(); drgElements.addAll(diagramDrgElements); drgElements.addAll(importedDrgElements); removeDrgElementsWithoutShape(drgElements, dmnShapes); final Map<String, Entry<org.kie.dmn.model.api.DRGElement, Node>> elems = drgElements.stream().collect(toMap(org.kie.dmn.model.api.DRGElement::getId, dmn -> new SimpleEntry<>(dmn, dmnToStunner(dmn, hasComponentWidthsConsumer, importedDrgElements)))); final Set<org.kie.dmn.model.api.DecisionService> dmnDecisionServices = new HashSet<>(); for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { ddExtAugmentStunner(dmnDDDiagram, kv.getValue()); } for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { final org.kie.dmn.model.api.DRGElement elem = kv.getKey(); final Node currentNode = kv.getValue(); if (isImportedDRGElement(importedDrgElements, elem)) { continue; } if (elem instanceof org.kie.dmn.model.api.Decision) { final org.kie.dmn.model.api.Decision decision = (org.kie.dmn.model.api.Decision) elem; for (org.kie.dmn.model.api.InformationRequirement ir : decision.getInformationRequirement()) { connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredInput(), elems, dmnXml, currentNode); connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredDecision(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.KnowledgeRequirement kr : decision.getKnowledgeRequirement()) { connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.AuthorityRequirement ar : decision.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.BusinessKnowledgeModel) { final org.kie.dmn.model.api.BusinessKnowledgeModel bkm = (org.kie.dmn.model.api.BusinessKnowledgeModel) elem; for (org.kie.dmn.model.api.KnowledgeRequirement kr : bkm.getKnowledgeRequirement()) { connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.AuthorityRequirement ar : bkm.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.KnowledgeSource) { final org.kie.dmn.model.api.KnowledgeSource ks = (org.kie.dmn.model.api.KnowledgeSource) elem; for (org.kie.dmn.model.api.AuthorityRequirement ar : ks.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredInput(), elems, dmnXml, currentNode); connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredDecision(), elems, dmnXml, currentNode); connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.DecisionService) { final org.kie.dmn.model.api.DecisionService ds = (org.kie.dmn.model.api.DecisionService) elem; dmnDecisionServices.add(ds); for (org.kie.dmn.model.api.DMNElementReference er : ds.getEncapsulatedDecision()) { final String reqInputID = getId(er); final Node requiredNode = getRequiredNode(elems, reqInputID); if (Objects.nonNull(requiredNode)) { connectDSChildEdge(currentNode, requiredNode); } } for (org.kie.dmn.model.api.DMNElementReference er : ds.getOutputDecision()) { final String reqInputID = getId(er); final Node requiredNode = getRequiredNode(elems, reqInputID); if (Objects.nonNull(requiredNode)) { connectDSChildEdge(currentNode, requiredNode); } } } } final Map<String, Node<View<TextAnnotation>, ?>> textAnnotations = dmnXml.getArtifact().stream() .filter(org.kie.dmn.model.api.TextAnnotation.class::isInstance) .map(org.kie.dmn.model.api.TextAnnotation.class::cast) .collect(Collectors.toMap(org.kie.dmn.model.api.TextAnnotation::getId, dmn -> textAnnotationConverter.nodeFromDMN(dmn, hasComponentWidthsConsumer))); textAnnotations.values().forEach(n -> ddExtAugmentStunner(dmnDDDiagram, n)); final List<org.kie.dmn.model.api.Association> associations = dmnXml.getArtifact().stream() .filter(org.kie.dmn.model.api.Association.class::isInstance) .map(org.kie.dmn.model.api.Association.class::cast) .collect(Collectors.toList()); for (org.kie.dmn.model.api.Association a : associations) { final String sourceId = getId(a.getSourceRef()); final Node sourceNode = Optional.ofNullable(elems.get(sourceId)).map(Entry::getValue).orElse(textAnnotations.get(sourceId)); final String targetId = getId(a.getTargetRef()); final Node targetNode = Optional.ofNullable(elems.get(targetId)).map(Entry::getValue).orElse(textAnnotations.get(targetId)); @SuppressWarnings("unchecked") final Edge<View<Association>, ?> myEdge = (Edge<View<Association>, ?>) factoryManager.newElement(idOfDMNorWBUUID(a), ASSOCIATION_ID).asEdge(); final Id id = new Id(a.getId()); final Description description = new Description(a.getDescription()); final Association definition = new Association(id, description); myEdge.getContent().setDefinition(definition); connectEdge(myEdge, sourceNode, targetNode); setConnectionMagnets(myEdge, a.getId(), dmnXml); } for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { PointUtils.convertToRelativeBounds(kv.getValue()); } final Graph graph = factoryManager.newDiagram("prova", BindableAdapterUtils.getDefinitionSetId(DMNDefinitionSet.class), metadata).getGraph(); elems.values().stream().map(Map.Entry::getValue).forEach(graph::addNode); textAnnotations.values().forEach(graph::addNode); final Node<?, ?> dmnDiagramRoot = findDMNDiagramRoot(graph); final Definitions definitionsStunnerPojo = DefinitionsConverter.wbFromDMN(dmnXml, importDefinitions, pmmlDocuments); loadImportedItemDefinitions(definitionsStunnerPojo, importDefinitions); ((View<DMNDiagram>) dmnDiagramRoot.getContent()).getDefinition().setDefinitions(definitionsStunnerPojo); final List<String> references = new ArrayList<>(); dmnDecisionServices.forEach(ds -> references.addAll(ds.getEncapsulatedDecision().stream().map(org.kie.dmn.model.api.DMNElementReference::getHref).collect(Collectors.toList()))); dmnDecisionServices.forEach(ds -> references.addAll(ds.getOutputDecision().stream().map(org.kie.dmn.model.api.DMNElementReference::getHref).collect(Collectors.toList()))); final Map<org.kie.dmn.model.api.DRGElement, Node> elemsToConnectToRoot = elems.values().stream() .filter(elem -> !references.contains("#" + elem.getKey().getId())) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); elemsToConnectToRoot.values().stream() .forEach(node -> connectRootWithChild(dmnDiagramRoot, node)); textAnnotations.values().stream().forEach(node -> connectRootWithChild(dmnDiagramRoot, node)); final Optional<ComponentsWidthsExtension> extension = findComponentsWidthsExtension(dmnDDDiagram); extension.ifPresent(componentsWidthsExtension -> { if (componentsWidthsExtension.getComponentsWidths() != null) { hasComponentWidthsMap.forEach((uuid, hasComponentWidths) -> componentsWidthsExtension .getComponentsWidths() .stream() .filter(componentWidths -> componentWidths.getDmnElementRef().getLocalPart().equals(uuid)) .findFirst() .ifPresent(componentWidths -> { final List<Double> widths = hasComponentWidths.getComponentWidths(); widths.clear(); widths.addAll(componentWidths.getWidths()); })); } }); return graph; } }
DMNMarshallerStandalone implements DiagramMarshaller<Graph, Metadata, Diagram<Graph, Metadata>> { @Override @SuppressWarnings("unchecked") public Graph unmarshall(final Metadata metadata, final InputStream input) throws IOException { final Map<String, HasComponentWidths> hasComponentWidthsMap = new HashMap<>(); final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer = (uuid, hcw) -> { if (Objects.nonNull(uuid)) { hasComponentWidthsMap.put(uuid, hcw); } }; final org.kie.dmn.model.api.Definitions dmnXml = marshaller.unmarshal(new InputStreamReader(input)); final List<org.kie.dmn.model.api.DRGElement> diagramDrgElements = dmnXml.getDrgElement(); final Optional<org.kie.dmn.model.api.dmndi.DMNDiagram> dmnDDDiagram = findDMNDiagram(dmnXml); final Map<Import, org.kie.dmn.model.api.Definitions> importDefinitions = dmnMarshallerImportsHelper.getImportDefinitions(metadata, dmnXml.getImport()); final Map<Import, PMMLDocumentMetadata> pmmlDocuments = dmnMarshallerImportsHelper.getPMMLDocuments(metadata, dmnXml.getImport()); final List<DMNShape> dmnShapes = dmnDDDiagram.map(this::getUniqueDMNShapes).orElse(emptyList()); final List<org.kie.dmn.model.api.DRGElement> importedDrgElements = getImportedDrgElementsByShape(dmnShapes, importDefinitions); final List<org.kie.dmn.model.api.DRGElement> drgElements = new ArrayList<>(); drgElements.addAll(diagramDrgElements); drgElements.addAll(importedDrgElements); removeDrgElementsWithoutShape(drgElements, dmnShapes); final Map<String, Entry<org.kie.dmn.model.api.DRGElement, Node>> elems = drgElements.stream().collect(toMap(org.kie.dmn.model.api.DRGElement::getId, dmn -> new SimpleEntry<>(dmn, dmnToStunner(dmn, hasComponentWidthsConsumer, importedDrgElements)))); final Set<org.kie.dmn.model.api.DecisionService> dmnDecisionServices = new HashSet<>(); for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { ddExtAugmentStunner(dmnDDDiagram, kv.getValue()); } for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { final org.kie.dmn.model.api.DRGElement elem = kv.getKey(); final Node currentNode = kv.getValue(); if (isImportedDRGElement(importedDrgElements, elem)) { continue; } if (elem instanceof org.kie.dmn.model.api.Decision) { final org.kie.dmn.model.api.Decision decision = (org.kie.dmn.model.api.Decision) elem; for (org.kie.dmn.model.api.InformationRequirement ir : decision.getInformationRequirement()) { connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredInput(), elems, dmnXml, currentNode); connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredDecision(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.KnowledgeRequirement kr : decision.getKnowledgeRequirement()) { connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.AuthorityRequirement ar : decision.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.BusinessKnowledgeModel) { final org.kie.dmn.model.api.BusinessKnowledgeModel bkm = (org.kie.dmn.model.api.BusinessKnowledgeModel) elem; for (org.kie.dmn.model.api.KnowledgeRequirement kr : bkm.getKnowledgeRequirement()) { connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.AuthorityRequirement ar : bkm.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.KnowledgeSource) { final org.kie.dmn.model.api.KnowledgeSource ks = (org.kie.dmn.model.api.KnowledgeSource) elem; for (org.kie.dmn.model.api.AuthorityRequirement ar : ks.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredInput(), elems, dmnXml, currentNode); connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredDecision(), elems, dmnXml, currentNode); connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.DecisionService) { final org.kie.dmn.model.api.DecisionService ds = (org.kie.dmn.model.api.DecisionService) elem; dmnDecisionServices.add(ds); for (org.kie.dmn.model.api.DMNElementReference er : ds.getEncapsulatedDecision()) { final String reqInputID = getId(er); final Node requiredNode = getRequiredNode(elems, reqInputID); if (Objects.nonNull(requiredNode)) { connectDSChildEdge(currentNode, requiredNode); } } for (org.kie.dmn.model.api.DMNElementReference er : ds.getOutputDecision()) { final String reqInputID = getId(er); final Node requiredNode = getRequiredNode(elems, reqInputID); if (Objects.nonNull(requiredNode)) { connectDSChildEdge(currentNode, requiredNode); } } } } final Map<String, Node<View<TextAnnotation>, ?>> textAnnotations = dmnXml.getArtifact().stream() .filter(org.kie.dmn.model.api.TextAnnotation.class::isInstance) .map(org.kie.dmn.model.api.TextAnnotation.class::cast) .collect(Collectors.toMap(org.kie.dmn.model.api.TextAnnotation::getId, dmn -> textAnnotationConverter.nodeFromDMN(dmn, hasComponentWidthsConsumer))); textAnnotations.values().forEach(n -> ddExtAugmentStunner(dmnDDDiagram, n)); final List<org.kie.dmn.model.api.Association> associations = dmnXml.getArtifact().stream() .filter(org.kie.dmn.model.api.Association.class::isInstance) .map(org.kie.dmn.model.api.Association.class::cast) .collect(Collectors.toList()); for (org.kie.dmn.model.api.Association a : associations) { final String sourceId = getId(a.getSourceRef()); final Node sourceNode = Optional.ofNullable(elems.get(sourceId)).map(Entry::getValue).orElse(textAnnotations.get(sourceId)); final String targetId = getId(a.getTargetRef()); final Node targetNode = Optional.ofNullable(elems.get(targetId)).map(Entry::getValue).orElse(textAnnotations.get(targetId)); @SuppressWarnings("unchecked") final Edge<View<Association>, ?> myEdge = (Edge<View<Association>, ?>) factoryManager.newElement(idOfDMNorWBUUID(a), ASSOCIATION_ID).asEdge(); final Id id = new Id(a.getId()); final Description description = new Description(a.getDescription()); final Association definition = new Association(id, description); myEdge.getContent().setDefinition(definition); connectEdge(myEdge, sourceNode, targetNode); setConnectionMagnets(myEdge, a.getId(), dmnXml); } for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { PointUtils.convertToRelativeBounds(kv.getValue()); } final Graph graph = factoryManager.newDiagram("prova", BindableAdapterUtils.getDefinitionSetId(DMNDefinitionSet.class), metadata).getGraph(); elems.values().stream().map(Map.Entry::getValue).forEach(graph::addNode); textAnnotations.values().forEach(graph::addNode); final Node<?, ?> dmnDiagramRoot = findDMNDiagramRoot(graph); final Definitions definitionsStunnerPojo = DefinitionsConverter.wbFromDMN(dmnXml, importDefinitions, pmmlDocuments); loadImportedItemDefinitions(definitionsStunnerPojo, importDefinitions); ((View<DMNDiagram>) dmnDiagramRoot.getContent()).getDefinition().setDefinitions(definitionsStunnerPojo); final List<String> references = new ArrayList<>(); dmnDecisionServices.forEach(ds -> references.addAll(ds.getEncapsulatedDecision().stream().map(org.kie.dmn.model.api.DMNElementReference::getHref).collect(Collectors.toList()))); dmnDecisionServices.forEach(ds -> references.addAll(ds.getOutputDecision().stream().map(org.kie.dmn.model.api.DMNElementReference::getHref).collect(Collectors.toList()))); final Map<org.kie.dmn.model.api.DRGElement, Node> elemsToConnectToRoot = elems.values().stream() .filter(elem -> !references.contains("#" + elem.getKey().getId())) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); elemsToConnectToRoot.values().stream() .forEach(node -> connectRootWithChild(dmnDiagramRoot, node)); textAnnotations.values().stream().forEach(node -> connectRootWithChild(dmnDiagramRoot, node)); final Optional<ComponentsWidthsExtension> extension = findComponentsWidthsExtension(dmnDDDiagram); extension.ifPresent(componentsWidthsExtension -> { if (componentsWidthsExtension.getComponentsWidths() != null) { hasComponentWidthsMap.forEach((uuid, hasComponentWidths) -> componentsWidthsExtension .getComponentsWidths() .stream() .filter(componentWidths -> componentWidths.getDmnElementRef().getLocalPart().equals(uuid)) .findFirst() .ifPresent(componentWidths -> { final List<Double> widths = hasComponentWidths.getComponentWidths(); widths.clear(); widths.addAll(componentWidths.getWidths()); })); } }); return graph; } protected  DMNMarshallerStandalone(); @Inject  DMNMarshallerStandalone(final XMLEncoderDiagramMetadataMarshaller diagramMetadataMarshaller,
                                   final FactoryManager factoryManager,
                                   final DMNMarshallerImportsHelperStandalone dmnMarshallerImportsHelper,
                                   final DMNMarshaller marshaller); }
DMNMarshallerStandalone implements DiagramMarshaller<Graph, Metadata, Diagram<Graph, Metadata>> { @Override @SuppressWarnings("unchecked") public Graph unmarshall(final Metadata metadata, final InputStream input) throws IOException { final Map<String, HasComponentWidths> hasComponentWidthsMap = new HashMap<>(); final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer = (uuid, hcw) -> { if (Objects.nonNull(uuid)) { hasComponentWidthsMap.put(uuid, hcw); } }; final org.kie.dmn.model.api.Definitions dmnXml = marshaller.unmarshal(new InputStreamReader(input)); final List<org.kie.dmn.model.api.DRGElement> diagramDrgElements = dmnXml.getDrgElement(); final Optional<org.kie.dmn.model.api.dmndi.DMNDiagram> dmnDDDiagram = findDMNDiagram(dmnXml); final Map<Import, org.kie.dmn.model.api.Definitions> importDefinitions = dmnMarshallerImportsHelper.getImportDefinitions(metadata, dmnXml.getImport()); final Map<Import, PMMLDocumentMetadata> pmmlDocuments = dmnMarshallerImportsHelper.getPMMLDocuments(metadata, dmnXml.getImport()); final List<DMNShape> dmnShapes = dmnDDDiagram.map(this::getUniqueDMNShapes).orElse(emptyList()); final List<org.kie.dmn.model.api.DRGElement> importedDrgElements = getImportedDrgElementsByShape(dmnShapes, importDefinitions); final List<org.kie.dmn.model.api.DRGElement> drgElements = new ArrayList<>(); drgElements.addAll(diagramDrgElements); drgElements.addAll(importedDrgElements); removeDrgElementsWithoutShape(drgElements, dmnShapes); final Map<String, Entry<org.kie.dmn.model.api.DRGElement, Node>> elems = drgElements.stream().collect(toMap(org.kie.dmn.model.api.DRGElement::getId, dmn -> new SimpleEntry<>(dmn, dmnToStunner(dmn, hasComponentWidthsConsumer, importedDrgElements)))); final Set<org.kie.dmn.model.api.DecisionService> dmnDecisionServices = new HashSet<>(); for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { ddExtAugmentStunner(dmnDDDiagram, kv.getValue()); } for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { final org.kie.dmn.model.api.DRGElement elem = kv.getKey(); final Node currentNode = kv.getValue(); if (isImportedDRGElement(importedDrgElements, elem)) { continue; } if (elem instanceof org.kie.dmn.model.api.Decision) { final org.kie.dmn.model.api.Decision decision = (org.kie.dmn.model.api.Decision) elem; for (org.kie.dmn.model.api.InformationRequirement ir : decision.getInformationRequirement()) { connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredInput(), elems, dmnXml, currentNode); connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredDecision(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.KnowledgeRequirement kr : decision.getKnowledgeRequirement()) { connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.AuthorityRequirement ar : decision.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.BusinessKnowledgeModel) { final org.kie.dmn.model.api.BusinessKnowledgeModel bkm = (org.kie.dmn.model.api.BusinessKnowledgeModel) elem; for (org.kie.dmn.model.api.KnowledgeRequirement kr : bkm.getKnowledgeRequirement()) { connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.AuthorityRequirement ar : bkm.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.KnowledgeSource) { final org.kie.dmn.model.api.KnowledgeSource ks = (org.kie.dmn.model.api.KnowledgeSource) elem; for (org.kie.dmn.model.api.AuthorityRequirement ar : ks.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredInput(), elems, dmnXml, currentNode); connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredDecision(), elems, dmnXml, currentNode); connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.DecisionService) { final org.kie.dmn.model.api.DecisionService ds = (org.kie.dmn.model.api.DecisionService) elem; dmnDecisionServices.add(ds); for (org.kie.dmn.model.api.DMNElementReference er : ds.getEncapsulatedDecision()) { final String reqInputID = getId(er); final Node requiredNode = getRequiredNode(elems, reqInputID); if (Objects.nonNull(requiredNode)) { connectDSChildEdge(currentNode, requiredNode); } } for (org.kie.dmn.model.api.DMNElementReference er : ds.getOutputDecision()) { final String reqInputID = getId(er); final Node requiredNode = getRequiredNode(elems, reqInputID); if (Objects.nonNull(requiredNode)) { connectDSChildEdge(currentNode, requiredNode); } } } } final Map<String, Node<View<TextAnnotation>, ?>> textAnnotations = dmnXml.getArtifact().stream() .filter(org.kie.dmn.model.api.TextAnnotation.class::isInstance) .map(org.kie.dmn.model.api.TextAnnotation.class::cast) .collect(Collectors.toMap(org.kie.dmn.model.api.TextAnnotation::getId, dmn -> textAnnotationConverter.nodeFromDMN(dmn, hasComponentWidthsConsumer))); textAnnotations.values().forEach(n -> ddExtAugmentStunner(dmnDDDiagram, n)); final List<org.kie.dmn.model.api.Association> associations = dmnXml.getArtifact().stream() .filter(org.kie.dmn.model.api.Association.class::isInstance) .map(org.kie.dmn.model.api.Association.class::cast) .collect(Collectors.toList()); for (org.kie.dmn.model.api.Association a : associations) { final String sourceId = getId(a.getSourceRef()); final Node sourceNode = Optional.ofNullable(elems.get(sourceId)).map(Entry::getValue).orElse(textAnnotations.get(sourceId)); final String targetId = getId(a.getTargetRef()); final Node targetNode = Optional.ofNullable(elems.get(targetId)).map(Entry::getValue).orElse(textAnnotations.get(targetId)); @SuppressWarnings("unchecked") final Edge<View<Association>, ?> myEdge = (Edge<View<Association>, ?>) factoryManager.newElement(idOfDMNorWBUUID(a), ASSOCIATION_ID).asEdge(); final Id id = new Id(a.getId()); final Description description = new Description(a.getDescription()); final Association definition = new Association(id, description); myEdge.getContent().setDefinition(definition); connectEdge(myEdge, sourceNode, targetNode); setConnectionMagnets(myEdge, a.getId(), dmnXml); } for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { PointUtils.convertToRelativeBounds(kv.getValue()); } final Graph graph = factoryManager.newDiagram("prova", BindableAdapterUtils.getDefinitionSetId(DMNDefinitionSet.class), metadata).getGraph(); elems.values().stream().map(Map.Entry::getValue).forEach(graph::addNode); textAnnotations.values().forEach(graph::addNode); final Node<?, ?> dmnDiagramRoot = findDMNDiagramRoot(graph); final Definitions definitionsStunnerPojo = DefinitionsConverter.wbFromDMN(dmnXml, importDefinitions, pmmlDocuments); loadImportedItemDefinitions(definitionsStunnerPojo, importDefinitions); ((View<DMNDiagram>) dmnDiagramRoot.getContent()).getDefinition().setDefinitions(definitionsStunnerPojo); final List<String> references = new ArrayList<>(); dmnDecisionServices.forEach(ds -> references.addAll(ds.getEncapsulatedDecision().stream().map(org.kie.dmn.model.api.DMNElementReference::getHref).collect(Collectors.toList()))); dmnDecisionServices.forEach(ds -> references.addAll(ds.getOutputDecision().stream().map(org.kie.dmn.model.api.DMNElementReference::getHref).collect(Collectors.toList()))); final Map<org.kie.dmn.model.api.DRGElement, Node> elemsToConnectToRoot = elems.values().stream() .filter(elem -> !references.contains("#" + elem.getKey().getId())) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); elemsToConnectToRoot.values().stream() .forEach(node -> connectRootWithChild(dmnDiagramRoot, node)); textAnnotations.values().stream().forEach(node -> connectRootWithChild(dmnDiagramRoot, node)); final Optional<ComponentsWidthsExtension> extension = findComponentsWidthsExtension(dmnDDDiagram); extension.ifPresent(componentsWidthsExtension -> { if (componentsWidthsExtension.getComponentsWidths() != null) { hasComponentWidthsMap.forEach((uuid, hasComponentWidths) -> componentsWidthsExtension .getComponentsWidths() .stream() .filter(componentWidths -> componentWidths.getDmnElementRef().getLocalPart().equals(uuid)) .findFirst() .ifPresent(componentWidths -> { final List<Double> widths = hasComponentWidths.getComponentWidths(); widths.clear(); widths.addAll(componentWidths.getWidths()); })); } }); return graph; } protected  DMNMarshallerStandalone(); @Inject  DMNMarshallerStandalone(final XMLEncoderDiagramMetadataMarshaller diagramMetadataMarshaller,
                                   final FactoryManager factoryManager,
                                   final DMNMarshallerImportsHelperStandalone dmnMarshallerImportsHelper,
                                   final DMNMarshaller marshaller); @Override @SuppressWarnings("unchecked") Graph unmarshall(final Metadata metadata,
                            final InputStream input); static Node<?, ?> findDMNDiagramRoot(final Graph<?, Node<View, ?>> graph); @SuppressWarnings({"rawtypes", "unchecked"}) static void connectRootWithChild(final Node dmnDiagramRoot,
                                            final Node child); @SuppressWarnings({"rawtypes", "unchecked"}) static void connectEdge(final Edge edge,
                                   final Node source,
                                   final Node target); @Override @SuppressWarnings("unchecked") String marshall(final Diagram<Graph, Metadata> diagram); @Override DiagramMetadataMarshaller<Metadata> getMetadataMarshaller(); }
DMNMarshallerStandalone implements DiagramMarshaller<Graph, Metadata, Diagram<Graph, Metadata>> { @Override @SuppressWarnings("unchecked") public Graph unmarshall(final Metadata metadata, final InputStream input) throws IOException { final Map<String, HasComponentWidths> hasComponentWidthsMap = new HashMap<>(); final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer = (uuid, hcw) -> { if (Objects.nonNull(uuid)) { hasComponentWidthsMap.put(uuid, hcw); } }; final org.kie.dmn.model.api.Definitions dmnXml = marshaller.unmarshal(new InputStreamReader(input)); final List<org.kie.dmn.model.api.DRGElement> diagramDrgElements = dmnXml.getDrgElement(); final Optional<org.kie.dmn.model.api.dmndi.DMNDiagram> dmnDDDiagram = findDMNDiagram(dmnXml); final Map<Import, org.kie.dmn.model.api.Definitions> importDefinitions = dmnMarshallerImportsHelper.getImportDefinitions(metadata, dmnXml.getImport()); final Map<Import, PMMLDocumentMetadata> pmmlDocuments = dmnMarshallerImportsHelper.getPMMLDocuments(metadata, dmnXml.getImport()); final List<DMNShape> dmnShapes = dmnDDDiagram.map(this::getUniqueDMNShapes).orElse(emptyList()); final List<org.kie.dmn.model.api.DRGElement> importedDrgElements = getImportedDrgElementsByShape(dmnShapes, importDefinitions); final List<org.kie.dmn.model.api.DRGElement> drgElements = new ArrayList<>(); drgElements.addAll(diagramDrgElements); drgElements.addAll(importedDrgElements); removeDrgElementsWithoutShape(drgElements, dmnShapes); final Map<String, Entry<org.kie.dmn.model.api.DRGElement, Node>> elems = drgElements.stream().collect(toMap(org.kie.dmn.model.api.DRGElement::getId, dmn -> new SimpleEntry<>(dmn, dmnToStunner(dmn, hasComponentWidthsConsumer, importedDrgElements)))); final Set<org.kie.dmn.model.api.DecisionService> dmnDecisionServices = new HashSet<>(); for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { ddExtAugmentStunner(dmnDDDiagram, kv.getValue()); } for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { final org.kie.dmn.model.api.DRGElement elem = kv.getKey(); final Node currentNode = kv.getValue(); if (isImportedDRGElement(importedDrgElements, elem)) { continue; } if (elem instanceof org.kie.dmn.model.api.Decision) { final org.kie.dmn.model.api.Decision decision = (org.kie.dmn.model.api.Decision) elem; for (org.kie.dmn.model.api.InformationRequirement ir : decision.getInformationRequirement()) { connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredInput(), elems, dmnXml, currentNode); connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredDecision(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.KnowledgeRequirement kr : decision.getKnowledgeRequirement()) { connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.AuthorityRequirement ar : decision.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.BusinessKnowledgeModel) { final org.kie.dmn.model.api.BusinessKnowledgeModel bkm = (org.kie.dmn.model.api.BusinessKnowledgeModel) elem; for (org.kie.dmn.model.api.KnowledgeRequirement kr : bkm.getKnowledgeRequirement()) { connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), elems, dmnXml, currentNode); } for (org.kie.dmn.model.api.AuthorityRequirement ar : bkm.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.KnowledgeSource) { final org.kie.dmn.model.api.KnowledgeSource ks = (org.kie.dmn.model.api.KnowledgeSource) elem; for (org.kie.dmn.model.api.AuthorityRequirement ar : ks.getAuthorityRequirement()) { connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredInput(), elems, dmnXml, currentNode); connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredDecision(), elems, dmnXml, currentNode); connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode); } } else if (elem instanceof org.kie.dmn.model.api.DecisionService) { final org.kie.dmn.model.api.DecisionService ds = (org.kie.dmn.model.api.DecisionService) elem; dmnDecisionServices.add(ds); for (org.kie.dmn.model.api.DMNElementReference er : ds.getEncapsulatedDecision()) { final String reqInputID = getId(er); final Node requiredNode = getRequiredNode(elems, reqInputID); if (Objects.nonNull(requiredNode)) { connectDSChildEdge(currentNode, requiredNode); } } for (org.kie.dmn.model.api.DMNElementReference er : ds.getOutputDecision()) { final String reqInputID = getId(er); final Node requiredNode = getRequiredNode(elems, reqInputID); if (Objects.nonNull(requiredNode)) { connectDSChildEdge(currentNode, requiredNode); } } } } final Map<String, Node<View<TextAnnotation>, ?>> textAnnotations = dmnXml.getArtifact().stream() .filter(org.kie.dmn.model.api.TextAnnotation.class::isInstance) .map(org.kie.dmn.model.api.TextAnnotation.class::cast) .collect(Collectors.toMap(org.kie.dmn.model.api.TextAnnotation::getId, dmn -> textAnnotationConverter.nodeFromDMN(dmn, hasComponentWidthsConsumer))); textAnnotations.values().forEach(n -> ddExtAugmentStunner(dmnDDDiagram, n)); final List<org.kie.dmn.model.api.Association> associations = dmnXml.getArtifact().stream() .filter(org.kie.dmn.model.api.Association.class::isInstance) .map(org.kie.dmn.model.api.Association.class::cast) .collect(Collectors.toList()); for (org.kie.dmn.model.api.Association a : associations) { final String sourceId = getId(a.getSourceRef()); final Node sourceNode = Optional.ofNullable(elems.get(sourceId)).map(Entry::getValue).orElse(textAnnotations.get(sourceId)); final String targetId = getId(a.getTargetRef()); final Node targetNode = Optional.ofNullable(elems.get(targetId)).map(Entry::getValue).orElse(textAnnotations.get(targetId)); @SuppressWarnings("unchecked") final Edge<View<Association>, ?> myEdge = (Edge<View<Association>, ?>) factoryManager.newElement(idOfDMNorWBUUID(a), ASSOCIATION_ID).asEdge(); final Id id = new Id(a.getId()); final Description description = new Description(a.getDescription()); final Association definition = new Association(id, description); myEdge.getContent().setDefinition(definition); connectEdge(myEdge, sourceNode, targetNode); setConnectionMagnets(myEdge, a.getId(), dmnXml); } for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) { PointUtils.convertToRelativeBounds(kv.getValue()); } final Graph graph = factoryManager.newDiagram("prova", BindableAdapterUtils.getDefinitionSetId(DMNDefinitionSet.class), metadata).getGraph(); elems.values().stream().map(Map.Entry::getValue).forEach(graph::addNode); textAnnotations.values().forEach(graph::addNode); final Node<?, ?> dmnDiagramRoot = findDMNDiagramRoot(graph); final Definitions definitionsStunnerPojo = DefinitionsConverter.wbFromDMN(dmnXml, importDefinitions, pmmlDocuments); loadImportedItemDefinitions(definitionsStunnerPojo, importDefinitions); ((View<DMNDiagram>) dmnDiagramRoot.getContent()).getDefinition().setDefinitions(definitionsStunnerPojo); final List<String> references = new ArrayList<>(); dmnDecisionServices.forEach(ds -> references.addAll(ds.getEncapsulatedDecision().stream().map(org.kie.dmn.model.api.DMNElementReference::getHref).collect(Collectors.toList()))); dmnDecisionServices.forEach(ds -> references.addAll(ds.getOutputDecision().stream().map(org.kie.dmn.model.api.DMNElementReference::getHref).collect(Collectors.toList()))); final Map<org.kie.dmn.model.api.DRGElement, Node> elemsToConnectToRoot = elems.values().stream() .filter(elem -> !references.contains("#" + elem.getKey().getId())) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); elemsToConnectToRoot.values().stream() .forEach(node -> connectRootWithChild(dmnDiagramRoot, node)); textAnnotations.values().stream().forEach(node -> connectRootWithChild(dmnDiagramRoot, node)); final Optional<ComponentsWidthsExtension> extension = findComponentsWidthsExtension(dmnDDDiagram); extension.ifPresent(componentsWidthsExtension -> { if (componentsWidthsExtension.getComponentsWidths() != null) { hasComponentWidthsMap.forEach((uuid, hasComponentWidths) -> componentsWidthsExtension .getComponentsWidths() .stream() .filter(componentWidths -> componentWidths.getDmnElementRef().getLocalPart().equals(uuid)) .findFirst() .ifPresent(componentWidths -> { final List<Double> widths = hasComponentWidths.getComponentWidths(); widths.clear(); widths.addAll(componentWidths.getWidths()); })); } }); return graph; } protected  DMNMarshallerStandalone(); @Inject  DMNMarshallerStandalone(final XMLEncoderDiagramMetadataMarshaller diagramMetadataMarshaller,
                                   final FactoryManager factoryManager,
                                   final DMNMarshallerImportsHelperStandalone dmnMarshallerImportsHelper,
                                   final DMNMarshaller marshaller); @Override @SuppressWarnings("unchecked") Graph unmarshall(final Metadata metadata,
                            final InputStream input); static Node<?, ?> findDMNDiagramRoot(final Graph<?, Node<View, ?>> graph); @SuppressWarnings({"rawtypes", "unchecked"}) static void connectRootWithChild(final Node dmnDiagramRoot,
                                            final Node child); @SuppressWarnings({"rawtypes", "unchecked"}) static void connectEdge(final Edge edge,
                                   final Node source,
                                   final Node target); @Override @SuppressWarnings("unchecked") String marshall(final Diagram<Graph, Metadata> diagram); @Override DiagramMetadataMarshaller<Metadata> getMetadataMarshaller(); static final String INFO_REQ_ID; static final String KNOWLEDGE_REQ_ID; static final String AUTH_REQ_ID; static final String ASSOCIATION_ID; }