Search in sources :

Example 6 with JSIDMNDiagram

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram in project kie-wb-common by kiegroup.

the class DMNMarshaller method marshall.

public JSITDefinitions marshall() {
    final Map<String, JSITDRGElement> nodes = new HashMap<>();
    final Map<String, JSITTextAnnotation> textAnnotations = new HashMap<>();
    final Node<View<DMNDiagram>, ?> dmnDiagramRoot = (Node<View<DMNDiagram>, ?>) DMNGraphUtils.findDMNDiagramRoot(dmnDiagramsSession.getDRGDiagram().getGraph());
    final Definitions definitionsStunnerPojo = ((DMNDiagram) getElementDefinition(dmnDiagramRoot)).getDefinitions();
    final List<String> dmnDiagramElementIds = new ArrayList<>();
    final JSITDefinitions definitions = DefinitionsConverter.dmnFromWB(definitionsStunnerPojo, true);
    if (Objects.isNull(definitions.getExtensionElements())) {
        JSITDMNElement.JSIExtensionElements jsiExtensionElements = new JSITDMNElement.JSIExtensionElements();
        definitions.setExtensionElements(jsiExtensionElements);
    }
    final JsArrayLike<JSIDMNDiagram> dmnDiagrams = definitions.getDMNDI().getNativeDMNDiagram();
    for (int i = 0; i < dmnDiagrams.getLength(); i++) {
        JSIDMNDiagram diagram = Js.uncheckedCast(dmnDiagrams.getAt(i));
        final String elementDiagramId = diagram.getId();
        final List<JSIDMNEdge> dmnEdges = new ArrayList<>();
        final List<Node> diagramNodes = getNodeStream(dmnDiagramsSession.getDiagram(elementDiagramId));
        // Setup callback for marshalling ComponentWidths
        if (Objects.isNull(diagram.getExtension())) {
            diagram.setExtension(new JSIDiagramElement.JSIExtension());
        }
        final JSITComponentsWidthsExtension componentsWidthsExtension = new JSITComponentsWidthsExtension();
        final JSIDiagramElement.JSIExtension extension = diagram.getExtension();
        JSITComponentsWidthsExtension wrappedComponentsWidthsExtension = WrapperUtils.getWrappedJSITComponentsWidthsExtension(componentsWidthsExtension);
        extension.addAny(wrappedComponentsWidthsExtension);
        final Consumer<JSITComponentWidths> componentWidthsConsumer = (cw) -> componentsWidthsExtension.addComponentWidths(cw);
        // Convert relative positioning to absolute
        for (final Node<?, ?> node : diagramNodes) {
            PointUtils.convertToAbsoluteBounds(node);
        }
        // Iterate Graph processing nodes..
        for (final Node<?, ?> node : diagramNodes) {
            if (!(node.getContent() instanceof View<?>)) {
                continue;
            }
            final View<?> view = (View<?>) node.getContent();
            final Object viewDefinition = view.getDefinition();
            if (!(viewDefinition instanceof HasContentDefinitionId)) {
                continue;
            }
            final HasContentDefinitionId hasContentDefinitionId = (HasContentDefinitionId) viewDefinition;
            final String nodeDiagramId = hasContentDefinitionId.getDiagramId();
            if (!Objects.equals(nodeDiagramId, elementDiagramId)) {
                continue;
            }
            if (viewDefinition instanceof DRGElement) {
                final DRGElement drgElement = (DRGElement) viewDefinition;
                if (!drgElement.isAllowOnlyVisualChange()) {
                    if (nodes.containsKey(drgElement.getId().getValue())) {
                        final JSITDRGElement currentValue = nodes.get(drgElement.getId().getValue());
                        mergeNodeRequirements(stunnerToDMN(withIncludedModels(node, definitionsStunnerPojo), componentWidthsConsumer), currentValue);
                    } else {
                        nodes.put(drgElement.getId().getValue(), stunnerToDMN(withIncludedModels(node, definitionsStunnerPojo), componentWidthsConsumer));
                    }
                }
                final String namespaceURI = definitionsStunnerPojo.getDefaultNamespace();
                diagram.addDMNDiagramElement(WrapperUtils.getWrappedJSIDMNShape(diagram, dmnDiagramElementIds, definitionsStunnerPojo, (View<? extends DMNElement>) view, namespaceURI));
            }
            if (viewDefinition instanceof TextAnnotation) {
                final TextAnnotation textAnnotation = (TextAnnotation) viewDefinition;
                if (!textAnnotation.isAllowOnlyVisualChange()) {
                    textAnnotations.put(textAnnotation.getId().getValue(), textAnnotationConverter.dmnFromNode((Node<View<TextAnnotation>, ?>) node, componentWidthsConsumer));
                }
                final String namespaceURI = definitionsStunnerPojo.getDefaultNamespace();
                diagram.addDMNDiagramElement(WrapperUtils.getWrappedJSIDMNShape(diagram, dmnDiagramElementIds, definitionsStunnerPojo, (View<? extends DMNElement>) view, namespaceURI));
                final List<JSITAssociation> associations = AssociationConverter.dmnFromWB((Node<View<TextAnnotation>, ?>) node);
                forEach(associations, association -> {
                    final JSITAssociation wrappedJSITAssociation = WrapperUtils.getWrappedJSITAssociation(Js.uncheckedCast(association));
                    definitions.addArtifact(wrappedJSITAssociation);
                });
            }
            connect(diagram, dmnDiagramElementIds, definitionsStunnerPojo, dmnEdges, node, view);
        }
        nodes.values().forEach(node -> {
            addNodeToDefinitionsIfNotPresent(node, definitions);
        });
        textAnnotations.values().forEach(text -> {
            final boolean exists = anyMatch(definitions.getArtifact(), artifact -> Objects.equals(artifact.getId(), text.getId()));
            if (!exists) {
                definitions.addArtifact(WrapperUtils.getWrappedJSITTextAnnotation(text));
            }
        });
        forEach(dmnEdges, dmnEdge -> {
            final boolean exists = anyMatch(diagram.getDMNDiagramElement(), diagramElement -> {
                if (JSIDMNEdge.instanceOf(diagramElement)) {
                    final JSIDMNEdge jsidmnEdge = Js.uncheckedCast(diagramElement);
                    return Objects.equals(jsidmnEdge.getDmnElementRef(), dmnEdge.getDmnElementRef());
                }
                return false;
            });
            if (!exists) {
                diagram.addDMNDiagramElement(WrapperUtils.getWrappedJSIDMNEdge(Js.uncheckedCast(dmnEdge)));
            }
        });
        // Convert absolute positioning to relative
        for (final Node<?, ?> node : diagramNodes) {
            PointUtils.convertToRelativeBounds(node);
        }
    }
    ;
    return definitions;
}
Also used : TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) KnowledgeSourceConverter(org.kie.workbench.common.dmn.client.marshaller.converters.KnowledgeSourceConverter) JsInteropUtils.anyMatch(org.kie.workbench.common.dmn.client.marshaller.common.JsInteropUtils.anyMatch) JSITDMNElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElement) JSITTextAnnotation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITTextAnnotation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) PointUtils.upperLeftBound(org.kie.workbench.common.dmn.client.marshaller.converters.dd.PointUtils.upperLeftBound) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) Import(org.kie.workbench.common.dmn.api.definition.model.Import) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) Map(java.util.Map) FactoryManager(org.kie.workbench.common.stunner.core.api.FactoryManager) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) IdUtils.getEdgeId(org.kie.workbench.common.dmn.client.marshaller.common.IdUtils.getEdgeId) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) DecisionServiceConverter(org.kie.workbench.common.dmn.client.marshaller.converters.DecisionServiceConverter) PointUtils.yOfBound(org.kie.workbench.common.dmn.client.marshaller.converters.dd.PointUtils.yOfBound) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Collectors(java.util.stream.Collectors) JSITComponentWidths(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITComponentWidths) Objects(java.util.Objects) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) JSITDecisionService(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionService) TextAnnotationConverter(org.kie.workbench.common.dmn.client.marshaller.converters.TextAnnotationConverter) List(java.util.List) Stream(java.util.stream.Stream) DMNDiagramsSession(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramsSession) BusinessKnowledgeModelConverter(org.kie.workbench.common.dmn.client.marshaller.converters.BusinessKnowledgeModelConverter) DMNGraphUtils(org.kie.workbench.common.dmn.client.marshaller.common.DMNGraphUtils) PostConstruct(javax.annotation.PostConstruct) DefinitionUtils.getElementDefinition(org.kie.workbench.common.stunner.core.util.DefinitionUtils.getElementDefinition) Optional(java.util.Optional) JSITBusinessKnowledgeModel(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBusinessKnowledgeModel) ApplicationScoped(javax.enterprise.context.ApplicationScoped) JSITKnowledgeSource(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITKnowledgeSource) QName(javax.xml.namespace.QName) Node(org.kie.workbench.common.stunner.core.graph.Node) JSIDiagramElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) AssociationConverter(org.kie.workbench.common.dmn.client.marshaller.converters.AssociationConverter) InputDataConverter(org.kie.workbench.common.dmn.client.marshaller.converters.InputDataConverter) JSITInputData(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInputData) HashMap(java.util.HashMap) HasContentDefinitionId(org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ArrayList(java.util.ArrayList) WrapperUtils(org.kie.workbench.common.dmn.client.marshaller.common.WrapperUtils) Inject(javax.inject.Inject) Js(jsinterop.base.Js) JsArrayLike(jsinterop.base.JsArrayLike) IdUtils.getRawId(org.kie.workbench.common.dmn.client.marshaller.common.IdUtils.getRawId) StreamSupport(java.util.stream.StreamSupport) JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement) DMNViewDefinition(org.kie.workbench.common.dmn.api.definition.DMNViewDefinition) XMLConstants(javax.xml.XMLConstants) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) MainJs(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.MainJs) JSITAssociation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITAssociation) DefinitionsConverter(org.kie.workbench.common.dmn.client.marshaller.converters.DefinitionsConverter) PointUtils.xOfBound(org.kie.workbench.common.dmn.client.marshaller.converters.dd.PointUtils.xOfBound) PointUtils(org.kie.workbench.common.dmn.client.marshaller.converters.dd.PointUtils) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) DecisionConverter(org.kie.workbench.common.dmn.client.marshaller.converters.DecisionConverter) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Association(org.kie.workbench.common.dmn.api.definition.model.Association) Consumer(java.util.function.Consumer) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Graph(org.kie.workbench.common.stunner.core.graph.Graph) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) JSITComponentsWidthsExtension(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITComponentsWidthsExtension) JsInteropUtils.forEach(org.kie.workbench.common.dmn.client.marshaller.common.JsInteropUtils.forEach) DiscreteConnection(org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection) HasContentDefinitionId(org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId) JSITComponentsWidthsExtension(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITComponentsWidthsExtension) JSITAssociation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITAssociation) HashMap(java.util.HashMap) JSITTextAnnotation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITTextAnnotation) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) JSITDMNElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElement) JSITDMNElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElement) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) JSITTextAnnotation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITTextAnnotation) JSITComponentWidths(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITComponentWidths) JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) JSIDiagramElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) JSITDRGElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDRGElement)

Example 7 with JSIDMNDiagram

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram in project kie-wb-common by kiegroup.

the class DMNMarshaller method connect.

protected void connect(final JSIDMNDiagram diagram, final List<String> dmnDiagramElementIds, final Definitions definitionsStunnerPojo, final List<JSIDMNEdge> dmnEdges, final Node<?, ?> node, final View<?> view) {
    // DMNDI Edge management.
    final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
    for (Edge<?, ?> e : inEdges) {
        if (e.getContent() instanceof ViewConnector) {
            final ViewConnector connectionContent = (ViewConnector) e.getContent();
            DiscreteConnection sourceConnection = (DiscreteConnection) connectionContent.getSourceConnection().orElse(null);
            DiscreteConnection targetConnection = (DiscreteConnection) connectionContent.getTargetConnection().orElse(null);
            if (sourceConnection != null && targetConnection != null) {
                final Node<?, ?> sourceNode = e.getSourceNode();
                final View<?> sourceView = (View<?>) sourceNode.getContent();
                Point2D sourcePoint = sourceConnection.getLocation();
                double xSource = xOfBound(upperLeftBound(sourceView));
                double ySource = yOfBound(upperLeftBound(sourceView));
                if (Objects.isNull(sourcePoint)) {
                    // If the "connection source/target location is null" assume it's the centre of the shape.
                    if (sourceView.getDefinition() instanceof DMNViewDefinition) {
                        DMNViewDefinition dmnViewDefinition = (DMNViewDefinition) sourceView.getDefinition();
                        xSource += dmnViewDefinition.getDimensionsSet().getWidth().getValue() / 2;
                        ySource += dmnViewDefinition.getDimensionsSet().getHeight().getValue() / 2;
                    }
                    sourcePoint = Point2D.create(xSource, ySource);
                } else {
                    // If it is non-null it is relative to the source/target shape location.
                    sourcePoint = Point2D.create(xSource + sourcePoint.getX(), ySource + sourcePoint.getY());
                }
                Point2D targetPoint = targetConnection.getLocation();
                double xTarget = xOfBound(upperLeftBound(view));
                double yTarget = yOfBound(upperLeftBound(view));
                if (Objects.isNull(targetPoint)) {
                    // If the "connection source/target location is null" assume it's the centre of the shape.
                    if (view.getDefinition() instanceof DMNViewDefinition) {
                        DMNViewDefinition dmnViewDefinition = (DMNViewDefinition) view.getDefinition();
                        xTarget += dmnViewDefinition.getDimensionsSet().getWidth().getValue() / 2;
                        yTarget += dmnViewDefinition.getDimensionsSet().getHeight().getValue() / 2;
                    }
                    targetPoint = Point2D.create(xTarget, yTarget);
                } else {
                    // If it is non-null it is relative to the source/target shape location.
                    targetPoint = Point2D.create(xTarget + targetPoint.getX(), yTarget + targetPoint.getY());
                }
                final JSIDMNEdge dmnEdge = new JSIDMNEdge();
                // DMNDI edge elementRef is uuid of Stunner edge,
                // with the only exception when edge contains as content a DMN Association (Association is an edge)
                final String uuid = getRawId(getUUID(e));
                final String edgeId = getEdgeId(diagram, dmnDiagramElementIds, uuid, sourceConnection.isAuto(), targetConnection.isAuto());
                dmnEdge.setId(edgeId);
                final String namespaceURI = definitionsStunnerPojo.getDefaultNamespace();
                dmnEdge.setDmnElementRef(new QName(namespaceURI, uuid, XMLConstants.DEFAULT_NS_PREFIX));
                dmnEdge.addWaypoint(PointUtils.point2dToDMNDIPoint(sourcePoint));
                for (ControlPoint cp : connectionContent.getControlPoints()) {
                    dmnEdge.addWaypoint(PointUtils.point2dToDMNDIPoint(cp.getLocation()));
                }
                dmnEdge.addWaypoint(PointUtils.point2dToDMNDIPoint(targetPoint));
                dmnEdges.add(dmnEdge);
            }
        }
    }
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) DiscreteConnection(org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection) DMNViewDefinition(org.kie.workbench.common.dmn.api.definition.DMNViewDefinition) QName(javax.xml.namespace.QName) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) List(java.util.List) ArrayList(java.util.ArrayList) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) Edge(org.kie.workbench.common.stunner.core.graph.Edge) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)

Example 8 with JSIDMNDiagram

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram in project kie-wb-common by kiegroup.

the class NodeConnector method connect.

void connect(final JSIDMNDiagram dmnDiagram, final List<JSIDMNEdge> edges, final List<JSITAssociation> associations, final List<NodeEntry> nodeEntries, final boolean isDMNDIPresent) {
    final Map<String, List<NodeEntry>> entriesById = makeNodeIndex(nodeEntries);
    final String diagramId = dmnDiagram.getId();
    for (final NodeEntry nodeEntry : nodeEntries) {
        final JSITDMNElement element = nodeEntry.getDmnElement();
        final Node node = nodeEntry.getNode();
        // For imported nodes, we don't have its connections
        if (nodeEntry.isIncluded()) {
            continue;
        }
        // DMN spec table 2: Requirements
        if (JSITDecision.instanceOf(element)) {
            final JSITDecision decision = Js.uncheckedCast(element);
            final List<JSITInformationRequirement> jsiInformationRequirements = decision.getInformationRequirement();
            for (int i = 0; i < jsiInformationRequirements.size(); i++) {
                final JSITInformationRequirement ir = Js.uncheckedCast(jsiInformationRequirements.get(i));
                connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredInput(), entriesById, diagramId, edges, isDMNDIPresent, node);
                connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredDecision(), entriesById, diagramId, edges, isDMNDIPresent, node);
            }
            final List<JSITKnowledgeRequirement> jsiKnowledgeRequirements = decision.getKnowledgeRequirement();
            for (int i = 0; i < jsiKnowledgeRequirements.size(); i++) {
                final JSITKnowledgeRequirement kr = Js.uncheckedCast(jsiKnowledgeRequirements.get(i));
                connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), entriesById, diagramId, edges, isDMNDIPresent, node);
            }
            final List<JSITAuthorityRequirement> jsiAuthorityRequirements = decision.getAuthorityRequirement();
            for (int i = 0; i < jsiAuthorityRequirements.size(); i++) {
                final JSITAuthorityRequirement ar = Js.uncheckedCast(jsiAuthorityRequirements.get(i));
                connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), entriesById, diagramId, edges, isDMNDIPresent, node);
            }
            continue;
        }
        if (JSITBusinessKnowledgeModel.instanceOf(element)) {
            final JSITBusinessKnowledgeModel bkm = Js.uncheckedCast(element);
            final List<JSITKnowledgeRequirement> jsiKnowledgeRequirements = bkm.getKnowledgeRequirement();
            for (int i = 0; i < jsiKnowledgeRequirements.size(); i++) {
                final JSITKnowledgeRequirement kr = Js.uncheckedCast(jsiKnowledgeRequirements.get(i));
                connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), entriesById, diagramId, edges, isDMNDIPresent, node);
            }
            final List<JSITAuthorityRequirement> jsiAuthorityRequirements = bkm.getAuthorityRequirement();
            for (int i = 0; i < jsiAuthorityRequirements.size(); i++) {
                final JSITAuthorityRequirement ar = Js.uncheckedCast(jsiAuthorityRequirements.get(i));
                connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), entriesById, diagramId, edges, isDMNDIPresent, node);
            }
            continue;
        }
        if (JSITKnowledgeSource.instanceOf(element)) {
            final JSITKnowledgeSource ks = Js.uncheckedCast(element);
            final List<JSITAuthorityRequirement> jsiAuthorityRequirements = ks.getAuthorityRequirement();
            for (int i = 0; i < jsiAuthorityRequirements.size(); i++) {
                final JSITAuthorityRequirement ar = Js.uncheckedCast(jsiAuthorityRequirements.get(i));
                connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredInput(), entriesById, diagramId, edges, isDMNDIPresent, node);
                connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredDecision(), entriesById, diagramId, edges, isDMNDIPresent, node);
                connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), entriesById, diagramId, edges, isDMNDIPresent, node);
            }
            continue;
        }
        if (JSITDecisionService.instanceOf(element)) {
            final JSITDecisionService ds = Js.uncheckedCast(element);
            final List<JSITDMNElementReference> encapsulatedDecisions = ds.getEncapsulatedDecision();
            forEach(encapsulatedDecisions, er -> {
                final String reqInputID = getId(er);
                getNode(nodeEntry, reqInputID, entriesById).ifPresent(requiredNode -> {
                    connectDSChildEdge(node, requiredNode);
                });
            });
            final List<JSITDMNElementReference> outputDecisions = ds.getOutputDecision();
            forEach(outputDecisions, er -> {
                final String reqInputID = getId(er);
                getNode(nodeEntry, reqInputID, entriesById).ifPresent(requiredNode -> {
                    connectDSChildEdge(node, requiredNode);
                });
            });
        }
    }
    forEach(associations, association -> {
        final String sourceId = getId(association.getSourceRef());
        final String targetId = getId(association.getTargetRef());
        final List<NodeEntry> source = entriesById.get(sourceId);
        final List<NodeEntry> target = entriesById.get(targetId);
        final boolean sourcePresent = source != null && source.size() > 0;
        final boolean targetPresent = target != null && target.size() > 0;
        if (sourcePresent && targetPresent) {
            final NodeEntry sourceEntry = source.get(0);
            final NodeEntry targetEntry = target.get(0);
            final Node sourceNode = sourceEntry.getNode();
            final Node targetNode = targetEntry.getNode();
            @SuppressWarnings("unchecked") final Edge<View<Association>, ?> myEdge = (Edge<View<Association>, ?>) factoryManager.newElement(diagramId + "#" + association.getId(), ASSOCIATION_ID).asEdge();
            final ViewConnector connectionContent = (ViewConnector) myEdge.getContent();
            final Id id = new Id(association.getId());
            final Description description = new Description(association.getDescription());
            final Association definition = new Association(id, description);
            connectEdge(myEdge, sourceNode, targetNode);
            connectionContent.setDefinition(definition);
            connectionContent.setTargetConnection(MagnetConnection.Builder.atCenter(targetNode));
            connectionContent.setSourceConnection(MagnetConnection.Builder.atCenter(sourceNode));
        }
    });
}
Also used : JSITKnowledgeSource(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITKnowledgeSource) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Node(org.kie.workbench.common.stunner.core.graph.Node) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) JSITBusinessKnowledgeModel(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBusinessKnowledgeModel) JSITDMNElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElement) JSITAssociation(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITAssociation) Association(org.kie.workbench.common.dmn.api.definition.model.Association) JSITDecisionService(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionService) JSITAuthorityRequirement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITAuthorityRequirement) List(java.util.List) ArrayList(java.util.ArrayList) JSITInformationRequirement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationRequirement) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) JSITDMNElementReference(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) JSIPoint(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint) JSITKnowledgeRequirement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITKnowledgeRequirement) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) BindableAdapterUtils.getDefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId) Edge(org.kie.workbench.common.stunner.core.graph.Edge) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)

Example 9 with JSIDMNDiagram

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram in project kie-wb-common by kiegroup.

the class NodeEntriesFactory method getEdges.

private List<JSIDMNEdge> getEdges(final JSIDMNDiagram dmnDiagram) {
    final List<JSIDMNEdge> edges = new ArrayList<>();
    final List<JSIDiagramElement> dmnDiagramElements = dmnDiagram.getDMNDiagramElement();
    forEach(dmnDiagramElements, dmnDiagramElement -> {
        if (JSIDMNEdge.instanceOf(dmnDiagramElement)) {
            final JSIDMNEdge jsiEdge = Js.uncheckedCast(dmnDiagramElement);
            edges.add(jsiEdge);
        }
    });
    return edges;
}
Also used : JSIDiagramElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement) ArrayList(java.util.ArrayList) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)

Example 10 with JSIDMNDiagram

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram in project kie-wb-common by kiegroup.

the class DMNMarshallerTest method testConnect.

@Test
public void testConnect() {
    final DMNMarshaller dmnMarshaller = new DMNMarshaller();
    final JSIDMNDiagram diagram = mock(JSIDMNDiagram.class);
    final List<String> dmnDiagramElementIds = mock(List.class);
    final Definitions definitionsStunnerPojo = mock(Definitions.class);
    final List<JSIDMNEdge> dmnEdges = new ArrayList<>();
    final Node<?, ?> node = mock(Node.class);
    final List inEdges = new ArrayList<>();
    final Edge edge = mock(Edge.class);
    final Node sourceNode = mock(Node.class);
    final View sourceView = mock(View.class);
    final ViewConnector viewConnector = mock(ViewConnector.class);
    final DiscreteConnection sourceConnection = mock(DiscreteConnection.class);
    final DiscreteConnection targetConnection = mock(DiscreteConnection.class);
    final View<?> view = mock(View.class);
    inEdges.add(edge);
    when(edge.getSourceNode()).thenReturn(sourceNode);
    when(sourceNode.getContent()).thenReturn(sourceView);
    when(node.getInEdges()).thenReturn(inEdges);
    when(edge.getContent()).thenReturn(viewConnector);
    when(viewConnector.getControlPoints()).thenReturn(new ControlPoint[] {});
    when(sourceConnection.isAuto()).thenReturn(true);
    when(targetConnection.isAuto()).thenReturn(true);
    when(diagram.getName()).thenReturn("dmnEdge");
    when(definitionsStunnerPojo.getDefaultNamespace()).thenReturn("org.edge");
    when(viewConnector.getSourceConnection()).thenReturn(Optional.of(sourceConnection));
    when(viewConnector.getTargetConnection()).thenReturn(Optional.of(targetConnection));
    dmnMarshaller.connect(diagram, dmnDiagramElementIds, definitionsStunnerPojo, dmnEdges, node, view);
    when(viewConnector.getSourceConnection()).thenReturn(Optional.empty());
    when(viewConnector.getTargetConnection()).thenReturn(Optional.empty());
    dmnMarshaller.connect(diagram, dmnDiagramElementIds, definitionsStunnerPojo, dmnEdges, node, view);
    when(viewConnector.getSourceConnection()).thenReturn(Optional.of(sourceConnection));
    when(viewConnector.getTargetConnection()).thenReturn(Optional.empty());
    dmnMarshaller.connect(diagram, dmnDiagramElementIds, definitionsStunnerPojo, dmnEdges, node, view);
    verify(sourceConnection).isAuto();
    verify(targetConnection).isAuto();
}
Also used : ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) DiscreteConnection(org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) View(org.kie.workbench.common.stunner.core.graph.content.view.View) JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) Edge(org.kie.workbench.common.stunner.core.graph.Edge) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge) Test(org.junit.Test)

Aggregations

JSIDMNDiagram (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram)14 ArrayList (java.util.ArrayList)7 JSIDMNEdge (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)6 Test (org.junit.Test)5 JSIDiagramElement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement)5 List (java.util.List)4 QName (javax.xml.namespace.QName)4 Edge (org.kie.workbench.common.stunner.core.graph.Edge)4 View (org.kie.workbench.common.stunner.core.graph.content.view.View)4 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)4 HashMap (java.util.HashMap)3 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)3 JSITDefinitions (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)3 JSIDMNShape (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNShape)3 Node (org.kie.workbench.common.stunner.core.graph.Node)3 ControlPoint (org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)3 DiscreteConnection (org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection)3 DMNViewDefinition (org.kie.workbench.common.dmn.api.definition.DMNViewDefinition)2 Association (org.kie.workbench.common.dmn.api.definition.model.Association)2 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)2