Search in sources :

Example 1 with JSIDMNEdge

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

the class WrapperUtils method getWrappedJSIDMNEdge.

public static JSIDMNEdge getWrappedJSIDMNEdge(final JSIDMNEdge toWrap) {
    final JSIDMNEdge toReturn = Js.uncheckedCast(JsUtils.getWrappedElement(toWrap));
    final JSIName jsiName = JSIDMNEdge.getJSIName();
    updateJSIName(jsiName, "dmndi", "DMNEdge");
    JsUtils.setNameOnWrapped(toReturn, jsiName);
    return toReturn;
}
Also used : JSIName(org.kie.workbench.common.dmn.webapp.kogito.marshaller.mapper.JSIName) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)

Example 2 with JSIDMNEdge

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge 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 3 with JSIDMNEdge

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge 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 4 with JSIDMNEdge

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge 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 5 with JSIDMNEdge

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

the class NodeConnector method newEdge.

JSIDMNEdge newEdge(double x, double y) {
    final JSIDMNEdge dmnEdge = new JSIDMNEdge();
    final JSIPoint point = new JSIPoint();
    point.setX(x);
    point.setY(y);
    dmnEdge.addAllWaypoint(point, point);
    return dmnEdge;
}
Also used : JSIPoint(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint) JSIDMNEdge(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)

Aggregations

JSIDMNEdge (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNEdge)26 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)13 List (java.util.List)11 Node (org.kie.workbench.common.stunner.core.graph.Node)10 Collections.singletonList (java.util.Collections.singletonList)8 Edge (org.kie.workbench.common.stunner.core.graph.Edge)8 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)7 JSIPoint (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIPoint)6 View (org.kie.workbench.common.stunner.core.graph.content.view.View)6 QName (javax.xml.namespace.QName)4 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)4 ControlPoint (org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint)4 JSIBounds (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dc.JSIBounds)3 JSIDiagramElement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement)3 JSITDMNElement (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElement)3 JSIDMNDiagram (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram)3 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)3 DiscreteConnection (org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection)3 Point2D (com.ait.lienzo.client.core.types.Point2D)2