Search in sources :

Example 1 with JSITDecisionService

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

the class DecisionServiceConverter method dmnFromNode.

@Override
@SuppressWarnings("unchecked")
public JSITDecisionService dmnFromNode(final Node<View<DecisionService>, ?> node, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
    final DecisionService source = (DecisionService) DefinitionUtils.getElementDefinition(node);
    final JSITDecisionService ds = new JSITDecisionService();
    ds.setId(source.getId().getValue());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
    description.ifPresent(ds::setDescription);
    ds.setName(source.getName().getValue());
    final JSITInformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
    ds.setVariable(variable);
    final List<JSITDMNElementReference> existing_outputDecision = source.getOutputDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
    final List<JSITDMNElementReference> existing_encapsulatedDecision = source.getEncapsulatedDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
    final List<JSITDMNElementReference> existing_inputDecision = source.getInputDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
    final List<JSITDMNElementReference> existing_inputData = source.getInputData().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
    final List<JSITDMNElementReference> candidate_outputDecision = new ArrayList<>();
    final List<JSITDMNElementReference> candidate_encapsulatedDecision = new ArrayList<>();
    final List<JSITDMNElementReference> candidate_inputDecision = new ArrayList<>();
    final List<JSITDMNElementReference> candidate_inputData = new ArrayList<>();
    final HashSet<InputData> reqInputs = new HashSet();
    final HashSet<Decision> reqDecisions = new HashSet();
    // DMN spec table 2: Requirements connection rules
    final List<Edge<?, ?>> outEdges = (List<Edge<?, ?>>) node.getOutEdges();
    for (Edge<?, ?> e : outEdges) {
        if (e.getContent() instanceof Child) {
            @SuppressWarnings("unchecked") final Node<View<?>, ?> targetNode = e.getTargetNode();
            final View<?> targetNodeView = targetNode.getContent();
            if (targetNodeView.getDefinition() instanceof DRGElement) {
                final DRGElement drgElement = (DRGElement) targetNodeView.getDefinition();
                if (drgElement instanceof Decision) {
                    final Decision decision = (Decision) drgElement;
                    final JSITDMNElementReference ri = new JSITDMNElementReference();
                    ri.setHref("#" + decision.getId().getValue());
                    if (isOutputDecision(targetNode.getContent(), node.getContent())) {
                        candidate_outputDecision.add(ri);
                    } else {
                        candidate_encapsulatedDecision.add(ri);
                        final List<Node> all = diagramsSession.getNodesFromAllDiagramsWithContentId(drgElement.getContentDefinitionId());
                        for (final Node other : all) {
                            if (!Objects.equals(other, targetNode)) {
                                inspectDecisionForDSReqs(other, reqInputs, reqDecisions);
                            }
                        }
                    }
                    inspectDecisionForDSReqs(targetNode, reqInputs, reqDecisions);
                } else {
                    throw new UnsupportedOperationException("wrong model definition: a DecisionService is expected to encapsulate only Decision");
                }
            }
        } else if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) {
        // this was taken care by the receiving Decision or BKM.
        } else {
            throw new UnsupportedOperationException("wrong model definition.");
        }
    }
    reqInputs.stream().sorted(Comparator.comparing(x -> x.getName().getValue())).map(x -> {
        final JSITDMNElementReference ri = new JSITDMNElementReference();
        ri.setHref("#" + x.getId().getValue());
        return ri;
    }).forEach(ri -> candidate_inputData.add(Js.uncheckedCast(ri)));
    reqDecisions.stream().sorted(Comparator.comparing(x -> x.getName().getValue())).map(x -> {
        final JSITDMNElementReference ri = new JSITDMNElementReference();
        ri.setHref("#" + x.getId().getValue());
        return ri;
    }).forEach(rs -> candidate_inputDecision.add(Js.uncheckedCast(rs)));
    for (int i = 0; i < candidate_outputDecision.size(); i++) {
        final JSITDMNElementReference er = Js.uncheckedCast(candidate_outputDecision.get(i));
        candidate_inputDecision.removeIf(x -> x.getHref().equals(er.getHref()));
    }
    for (int i = 0; i < candidate_encapsulatedDecision.size(); i++) {
        final JSITDMNElementReference er = Js.uncheckedCast(candidate_encapsulatedDecision.get(i));
        candidate_inputDecision.removeIf(x -> x.getHref().equals(er.getHref()));
    }
    ds.setInputData(reconcileExistingAndCandidate(existing_inputData, candidate_inputData));
    ds.setInputDecision(reconcileExistingAndCandidate(existing_inputDecision, candidate_inputDecision));
    ds.setEncapsulatedDecision(reconcileExistingAndCandidate(existing_encapsulatedDecision, candidate_encapsulatedDecision));
    ds.setOutputDecision(reconcileExistingAndCandidate(existing_outputDecision, candidate_outputDecision));
    DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, ds);
    return ds;
}
Also used : DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) Edge(org.kie.workbench.common.stunner.core.graph.Edge) InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Js(jsinterop.base.Js) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) NodeEntry(org.kie.workbench.common.dmn.client.marshaller.unmarshall.nodes.NodeEntry) BindableAdapterUtils.getDefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId) KnowledgeRequirement(org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) JSITDMNElementReference(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference) FactoryManager(org.kie.workbench.common.stunner.core.api.FactoryManager) DecisionServiceDividerLineY(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) DecisionServiceRectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.DecisionServiceRectangleDimensionsSet) JSITInformationItem(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationItem) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Collectors(java.util.stream.Collectors) JSITComponentWidths(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITComponentWidths) Objects(java.util.Objects) Consumer(java.util.function.Consumer) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) JSITDecisionService(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionService) List(java.util.List) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) DMNDiagramsSession(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramsSession) Optional(java.util.Optional) DMNElementReference(org.kie.workbench.common.dmn.api.definition.model.DMNElementReference) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Comparator(java.util.Comparator) Node(org.kie.workbench.common.stunner.core.graph.Node) JSITInformationItem(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITInformationItem) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) JSITDecisionService(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionService) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) JSITDecisionService(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionService) ArrayList(java.util.ArrayList) List(java.util.List) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) HashSet(java.util.HashSet) JSITDMNElementReference(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) KnowledgeRequirement(org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement)

Example 2 with JSITDecisionService

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

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

the class DMNUnmarshaller method unmarshall.

private Promise<Graph> unmarshall(final Metadata metadata, final JSITDefinitions dmnDefinitions, final Map<JSITImport, JSITDefinitions> importDefinitions, final Map<JSITImport, PMMLDocumentMetadata> pmmlDocuments) {
    final Map<String, HasComponentWidths> hasComponentWidthsMap = new HashMap<>();
    final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer = (uuid, hcw) -> {
        if (Objects.nonNull(uuid)) {
            hasComponentWidthsMap.put(uuid, hcw);
        }
    };
    // Check before the DRG creation ('ensureDRGElementExists').
    final boolean isDMNDIPresent = Optional.ofNullable(dmnDefinitions.getDMNDI()).isPresent();
    ensureDRGElementExists(dmnDefinitions);
    final Definitions wbDefinitions = DefinitionsConverter.wbFromDMN(dmnDefinitions, importDefinitions, pmmlDocuments);
    final List<NodeEntry> nodeEntries = modelToStunnerConverter.makeNodes(dmnDefinitions, importDefinitions, isDMNDIPresent, hasComponentWidthsConsumer);
    final List<JSITDecisionService> dmnDecisionServices = getDecisionServices(nodeEntries);
    // Ensure all locations are updated to relative for Stunner
    nodeEntries.forEach(e -> PointUtils.convertToRelativeBounds(e.getNode()));
    final Map<String, Diagram> stunnerDiagramsById = new HashMap<>();
    final Map<String, DMNDiagramElement> dmnDiagramsById = new HashMap<>();
    for (final DMNDiagramElement dmnDiagramElement : wbDefinitions.getDiagramElements()) {
        final String dmnDiagramId = dmnDiagramElement.getId().getValue();
        final Diagram value = factoryManager.newDiagram(dmnDiagramId, BindableAdapterUtils.getDefinitionSetId(DMNDefinitionSet.class), metadata);
        stunnerDiagramsById.put(dmnDiagramId, value);
        dmnDiagramsById.put(dmnDiagramId, dmnDiagramElement);
    }
    final DMNDiagramsSessionState state = dmnDiagramsSession.setState(metadata, stunnerDiagramsById, dmnDiagramsById);
    nodeEntries.forEach(nodeEntry -> {
        final String diagramId = nodeEntry.getDiagramId();
        final Graph graph = stunnerDiagramsById.get(diagramId).getGraph();
        graph.addNode(nodeEntry.getNode());
    });
    final Graph drgGraph = state.getDRGDiagram().getGraph();
    loadImportedItemDefinitions(wbDefinitions, importDefinitions);
    for (final Diagram value : stunnerDiagramsById.values()) {
        final Node<?, ?> dmnDiagramRoot = DMNGraphUtils.findDMNDiagramRoot(value.getGraph());
        ((View<DMNDiagram>) dmnDiagramRoot.getContent()).getDefinition().setDefinitions(wbDefinitions);
        nodeEntries.forEach(nodeEntry -> {
            if (Objects.equals(stunnerDiagramsById.get(nodeEntry.getDiagramId()), value)) {
                connectRootWithChild(dmnDiagramRoot, nodeEntry.getNode());
            }
        });
    }
    // Only connect Nodes to the Diagram that are not referenced by DecisionServices
    final List<String> references = new ArrayList<>();
    final List<JSITDecisionService> lstDecisionServices = new ArrayList<>(dmnDecisionServices);
    for (int iDS = 0; iDS < lstDecisionServices.size(); iDS++) {
        final JSITDecisionService jsiDecisionService = Js.uncheckedCast(lstDecisionServices.get(iDS));
        final List<JSITDMNElementReference> jsiEncapsulatedDecisions = jsiDecisionService.getEncapsulatedDecision();
        if (Objects.nonNull(jsiEncapsulatedDecisions)) {
            for (int i = 0; i < jsiEncapsulatedDecisions.size(); i++) {
                final JSITDMNElementReference jsiEncapsulatedDecision = Js.uncheckedCast(jsiEncapsulatedDecisions.get(i));
                references.add(jsiEncapsulatedDecision.getHref());
            }
        }
        final List<JSITDMNElementReference> jsiOutputDecisions = jsiDecisionService.getOutputDecision();
        if (Objects.nonNull(jsiOutputDecisions)) {
            for (int i = 0; i < jsiOutputDecisions.size(); i++) {
                final JSITDMNElementReference jsiOutputDecision = Js.uncheckedCast(jsiOutputDecisions.get(i));
                references.add(jsiOutputDecision.getHref());
            }
        }
    }
    // Copy ComponentWidths information
    final List<JSITComponentsWidthsExtension> extensions = findComponentsWidthsExtensions(dmnDefinitions.getDMNDI().getDMNDiagram());
    extensions.forEach(componentsWidthsExtension -> {
        // can be imported from another diagram but the extension is not imported or present in this diagram.
        if (Objects.nonNull(componentsWidthsExtension.getComponentWidths())) {
            hasComponentWidthsMap.entrySet().forEach(es -> {
                final List<JSITComponentWidths> jsiComponentWidths = componentsWidthsExtension.getComponentWidths();
                for (int i = 0; i < jsiComponentWidths.size(); i++) {
                    final JSITComponentWidths jsiWidths = Js.uncheckedCast(jsiComponentWidths.get(i));
                    if (Objects.equals(jsiWidths.getDmnElementRef(), es.getKey())) {
                        final List<Double> widths = es.getValue().getComponentWidths();
                        if (Objects.nonNull(jsiWidths.getWidth())) {
                            widths.clear();
                            for (int w = 0; w < jsiWidths.getWidth().size(); w++) {
                                final double width = jsiWidths.getWidth().get(w).doubleValue();
                                widths.add(width);
                            }
                        }
                    }
                }
            });
        }
    });
    return promises.resolve(drgGraph);
}
Also used : JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) Edge(org.kie.workbench.common.stunner.core.graph.Edge) UUID(org.kie.workbench.common.stunner.core.util.UUID) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) Map(java.util.Map) DMNDiagramElementsUtils(org.kie.workbench.common.dmn.client.marshaller.common.DMNDiagramElementsUtils) JSITDMNElementReference(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference) FactoryManager(org.kie.workbench.common.stunner.core.api.FactoryManager) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) 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) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Objects(java.util.Objects) JSITDecisionService(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionService) List(java.util.List) DMNDiagramsSession(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramsSession) DMNGraphUtils(org.kie.workbench.common.dmn.client.marshaller.common.DMNGraphUtils) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) Node(org.kie.workbench.common.stunner.core.graph.Node) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) JSIDiagramElement(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.di.JSIDiagramElement) DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) Promises(org.uberfire.client.promise.Promises) HashMap(java.util.HashMap) Promise(elemental2.promise.Promise) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Js(jsinterop.base.Js) NodeEntry(org.kie.workbench.common.dmn.client.marshaller.unmarshall.nodes.NodeEntry) DMNMarshallerImportsClientHelper(org.kie.workbench.common.dmn.client.marshaller.included.DMNMarshallerImportsClientHelper) BiConsumer(java.util.function.BiConsumer) NodeEntriesFactory(org.kie.workbench.common.dmn.client.marshaller.unmarshall.nodes.NodeEntriesFactory) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) BindableAdapterUtils(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils) MainJs(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.MainJs) DMNDiagramsSessionState(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramsSessionState) JSITItemDefinition(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITItemDefinition) DefinitionsConverter(org.kie.workbench.common.dmn.client.marshaller.converters.DefinitionsConverter) PointUtils(org.kie.workbench.common.dmn.client.marshaller.converters.dd.PointUtils) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) Graph(org.kie.workbench.common.stunner.core.graph.Graph) JsUtils(org.kie.workbench.common.dmn.webapp.kogito.marshaller.mapper.JsUtils) ItemDefinitionPropertyConverter(org.kie.workbench.common.dmn.client.marshaller.converters.ItemDefinitionPropertyConverter) JSITImport(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITImport) JSITComponentsWidthsExtension(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITComponentsWidthsExtension) JSITComponentsWidthsExtension(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.kie.JSITComponentsWidthsExtension) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) JSITDecisionService(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionService) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) DMNDiagramsSessionState(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramsSessionState) 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) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) JSITDMNElementReference(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference) DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) JSIDMNDiagram(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmndi12.JSIDMNDiagram) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Graph(org.kie.workbench.common.stunner.core.graph.Graph) NodeEntry(org.kie.workbench.common.dmn.client.marshaller.unmarshall.nodes.NodeEntry)

Example 4 with JSITDecisionService

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

the class DecisionServiceConverter method nodeFromDMN.

@Override
public Node<View<DecisionService>, ?> nodeFromDMN(final NodeEntry nodeEntry) {
    final JSITDecisionService dmn = Js.uncheckedCast(nodeEntry.getDmnElement());
    @SuppressWarnings("unchecked") final Node<View<DecisionService>, ?> node = (Node<View<DecisionService>, ?>) factoryManager.newElement(nodeEntry.getId(), getDefinitionId(DecisionService.class)).asNode();
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final Name name = new Name(dmn.getName());
    final InformationItemPrimary informationItem = InformationItemPrimaryPropertyConverter.wbFromDMN(dmn.getVariable(), dmn);
    final List<DMNElementReference> outputDecision = new ArrayList<>();
    final List<DMNElementReference> encapsulatedDecision = new ArrayList<>();
    final List<DMNElementReference> inputDecision = new ArrayList<>();
    final List<DMNElementReference> inputData = new ArrayList<>();
    final List<JSITDMNElementReference> jsiOutputDecisions = dmn.getOutputDecision();
    if (Objects.nonNull(jsiOutputDecisions)) {
        for (int i = 0; i < jsiOutputDecisions.size(); i++) {
            final JSITDMNElementReference jsiOutputDecision = Js.uncheckedCast(jsiOutputDecisions.get(i));
            outputDecision.add(DMNElementReferenceConverter.wbFromDMN(jsiOutputDecision));
        }
    }
    final List<JSITDMNElementReference> jsiEncapsulatedDecisions = dmn.getEncapsulatedDecision();
    if (Objects.nonNull(jsiEncapsulatedDecisions)) {
        for (int i = 0; i < jsiEncapsulatedDecisions.size(); i++) {
            final JSITDMNElementReference jsiEncapsulatedDecision = Js.uncheckedCast(jsiEncapsulatedDecisions.get(i));
            encapsulatedDecision.add(DMNElementReferenceConverter.wbFromDMN(jsiEncapsulatedDecision));
        }
    }
    final List<JSITDMNElementReference> jsiInputDecisions = dmn.getInputDecision();
    if (Objects.nonNull(jsiInputDecisions)) {
        for (int i = 0; i < jsiInputDecisions.size(); i++) {
            final JSITDMNElementReference jsiInputDecision = Js.uncheckedCast(jsiInputDecisions.get(i));
            inputDecision.add(DMNElementReferenceConverter.wbFromDMN(jsiInputDecision));
        }
    }
    final List<JSITDMNElementReference> jsiInputDatas = dmn.getInputData();
    if (Objects.nonNull(jsiInputDatas)) {
        for (int i = 0; i < jsiInputDatas.size(); i++) {
            final JSITDMNElementReference jsiInputData = Js.uncheckedCast(jsiInputDatas.get(i));
            inputData.add(DMNElementReferenceConverter.wbFromDMN(jsiInputData));
        }
    }
    final DecisionService decisionService = new DecisionService(id, description, name, informationItem, outputDecision, encapsulatedDecision, inputDecision, inputData, new StylingSet(), new DecisionServiceRectangleDimensionsSet(), new DecisionServiceDividerLineY());
    decisionService.setDiagramId(nodeEntry.getDiagramId());
    node.getContent().setDefinition(decisionService);
    if (Objects.nonNull(informationItem)) {
        informationItem.setParent(decisionService);
    }
    DMNExternalLinksToExtensionElements.loadExternalLinksFromExtensionElements(dmn, decisionService);
    return node;
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) JSITDMNElementReference(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference) View(org.kie.workbench.common.stunner.core.graph.content.view.View) JSITDecisionService(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionService) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) DecisionServiceDividerLineY(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY) JSITDMNElementReference(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference) DMNElementReference(org.kie.workbench.common.dmn.api.definition.model.DMNElementReference) JSITDecisionService(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionService) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) BindableAdapterUtils.getDefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId) DecisionServiceRectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.DecisionServiceRectangleDimensionsSet)

Aggregations

ArrayList (java.util.ArrayList)4 JSITDMNElementReference (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDMNElementReference)4 JSITDecisionService (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecisionService)4 Node (org.kie.workbench.common.stunner.core.graph.Node)4 View (org.kie.workbench.common.stunner.core.graph.content.view.View)4 List (java.util.List)3 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)3 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)3 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Js (jsinterop.base.Js)2 DMNElementReference (org.kie.workbench.common.dmn.api.definition.model.DMNElementReference)2 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)2 InformationItemPrimary (org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary)2 DecisionServiceRectangleDimensionsSet (org.kie.workbench.common.dmn.api.property.dimensions.DecisionServiceRectangleDimensionsSet)2 DecisionServiceDividerLineY (org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY)2 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)2 StylingSet (org.kie.workbench.common.dmn.api.property.styling.StylingSet)2 DMNDiagramsSession (org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramsSession)2