Search in sources :

Example 76 with Decision

use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.

the class DMNMarshallerStandalone method unmarshall.

@Override
@SuppressWarnings("unchecked")
public Graph unmarshall(final Metadata metadata, final InputStream input) throws IOException {
    final Map<String, HasComponentWidths> hasComponentWidthsMap = new HashMap<>();
    final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer = (uuid, hcw) -> {
        if (Objects.nonNull(uuid)) {
            hasComponentWidthsMap.put(uuid, hcw);
        }
    };
    final org.kie.dmn.model.api.Definitions dmnXml = marshaller.unmarshal(new InputStreamReader(input));
    final List<org.kie.dmn.model.api.DRGElement> diagramDrgElements = dmnXml.getDrgElement();
    final Optional<org.kie.dmn.model.api.dmndi.DMNDiagram> dmnDDDiagram = findDMNDiagram(dmnXml);
    // Get external DMN model information
    final Map<Import, org.kie.dmn.model.api.Definitions> importDefinitions = dmnMarshallerImportsHelper.getImportDefinitions(metadata, dmnXml.getImport());
    // Get external PMML model information
    final Map<Import, PMMLDocumentMetadata> pmmlDocuments = dmnMarshallerImportsHelper.getPMMLDocuments(metadata, dmnXml.getImport());
    // Map external DRGElements
    final List<DMNShape> dmnShapes = dmnDDDiagram.map(this::getUniqueDMNShapes).orElse(emptyList());
    final List<org.kie.dmn.model.api.DRGElement> importedDrgElements = getImportedDrgElementsByShape(dmnShapes, importDefinitions);
    // Group DRGElements
    final List<org.kie.dmn.model.api.DRGElement> drgElements = new ArrayList<>();
    drgElements.addAll(diagramDrgElements);
    drgElements.addAll(importedDrgElements);
    // Remove DRGElements that doesn't have any local or imported shape.
    removeDrgElementsWithoutShape(drgElements, dmnShapes);
    final Map<String, Entry<org.kie.dmn.model.api.DRGElement, Node>> elems = drgElements.stream().collect(toMap(org.kie.dmn.model.api.DRGElement::getId, dmn -> new SimpleEntry<>(dmn, dmnToStunner(dmn, hasComponentWidthsConsumer, importedDrgElements))));
    final Set<org.kie.dmn.model.api.DecisionService> dmnDecisionServices = new HashSet<>();
    // Stunner rely on relative positioning for Edge connections, so need to cycle on DMNShape first.
    for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) {
        ddExtAugmentStunner(dmnDDDiagram, kv.getValue());
    }
    // Setup Node Relationships and Connections all based on absolute positioning
    for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) {
        final org.kie.dmn.model.api.DRGElement elem = kv.getKey();
        final Node currentNode = kv.getValue();
        // For imported nodes, we don't have its connections
        if (isImportedDRGElement(importedDrgElements, elem)) {
            continue;
        }
        // DMN spec table 2: Requirements connection rules
        if (elem instanceof org.kie.dmn.model.api.Decision) {
            final org.kie.dmn.model.api.Decision decision = (org.kie.dmn.model.api.Decision) elem;
            for (org.kie.dmn.model.api.InformationRequirement ir : decision.getInformationRequirement()) {
                connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredInput(), elems, dmnXml, currentNode);
                connectEdgeToNodes(INFO_REQ_ID, ir, ir.getRequiredDecision(), elems, dmnXml, currentNode);
            }
            for (org.kie.dmn.model.api.KnowledgeRequirement kr : decision.getKnowledgeRequirement()) {
                connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), elems, dmnXml, currentNode);
            }
            for (org.kie.dmn.model.api.AuthorityRequirement ar : decision.getAuthorityRequirement()) {
                connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode);
            }
        } else if (elem instanceof org.kie.dmn.model.api.BusinessKnowledgeModel) {
            final org.kie.dmn.model.api.BusinessKnowledgeModel bkm = (org.kie.dmn.model.api.BusinessKnowledgeModel) elem;
            for (org.kie.dmn.model.api.KnowledgeRequirement kr : bkm.getKnowledgeRequirement()) {
                connectEdgeToNodes(KNOWLEDGE_REQ_ID, kr, kr.getRequiredKnowledge(), elems, dmnXml, currentNode);
            }
            for (org.kie.dmn.model.api.AuthorityRequirement ar : bkm.getAuthorityRequirement()) {
                connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode);
            }
        } else if (elem instanceof org.kie.dmn.model.api.KnowledgeSource) {
            final org.kie.dmn.model.api.KnowledgeSource ks = (org.kie.dmn.model.api.KnowledgeSource) elem;
            for (org.kie.dmn.model.api.AuthorityRequirement ar : ks.getAuthorityRequirement()) {
                connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredInput(), elems, dmnXml, currentNode);
                connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredDecision(), elems, dmnXml, currentNode);
                connectEdgeToNodes(AUTH_REQ_ID, ar, ar.getRequiredAuthority(), elems, dmnXml, currentNode);
            }
        } else if (elem instanceof org.kie.dmn.model.api.DecisionService) {
            final org.kie.dmn.model.api.DecisionService ds = (org.kie.dmn.model.api.DecisionService) elem;
            dmnDecisionServices.add(ds);
            for (org.kie.dmn.model.api.DMNElementReference er : ds.getEncapsulatedDecision()) {
                final String reqInputID = getId(er);
                final Node requiredNode = getRequiredNode(elems, reqInputID);
                if (Objects.nonNull(requiredNode)) {
                    connectDSChildEdge(currentNode, requiredNode);
                }
            }
            for (org.kie.dmn.model.api.DMNElementReference er : ds.getOutputDecision()) {
                final String reqInputID = getId(er);
                final Node requiredNode = getRequiredNode(elems, reqInputID);
                if (Objects.nonNull(requiredNode)) {
                    connectDSChildEdge(currentNode, requiredNode);
                }
            }
        }
    }
    final Map<String, Node<View<TextAnnotation>, ?>> textAnnotations = dmnXml.getArtifact().stream().filter(org.kie.dmn.model.api.TextAnnotation.class::isInstance).map(org.kie.dmn.model.api.TextAnnotation.class::cast).collect(Collectors.toMap(org.kie.dmn.model.api.TextAnnotation::getId, dmn -> textAnnotationConverter.nodeFromDMN(dmn, hasComponentWidthsConsumer)));
    textAnnotations.values().forEach(n -> ddExtAugmentStunner(dmnDDDiagram, n));
    final List<org.kie.dmn.model.api.Association> associations = dmnXml.getArtifact().stream().filter(org.kie.dmn.model.api.Association.class::isInstance).map(org.kie.dmn.model.api.Association.class::cast).collect(Collectors.toList());
    for (org.kie.dmn.model.api.Association a : associations) {
        final String sourceId = getId(a.getSourceRef());
        final Node sourceNode = Optional.ofNullable(elems.get(sourceId)).map(Entry::getValue).orElse(textAnnotations.get(sourceId));
        final String targetId = getId(a.getTargetRef());
        final Node targetNode = Optional.ofNullable(elems.get(targetId)).map(Entry::getValue).orElse(textAnnotations.get(targetId));
        @SuppressWarnings("unchecked") final Edge<View<Association>, ?> myEdge = (Edge<View<Association>, ?>) factoryManager.newElement(idOfDMNorWBUUID(a), ASSOCIATION_ID).asEdge();
        final Id id = new Id(a.getId());
        final Description description = new Description(a.getDescription());
        final Association definition = new Association(id, description);
        myEdge.getContent().setDefinition(definition);
        connectEdge(myEdge, sourceNode, targetNode);
        setConnectionMagnets(myEdge, a.getId(), dmnXml);
    }
    // Ensure all locations are updated to relative for Stunner
    for (Entry<org.kie.dmn.model.api.DRGElement, Node> kv : elems.values()) {
        PointUtils.convertToRelativeBounds(kv.getValue());
    }
    final Graph graph = factoryManager.newDiagram("prova", BindableAdapterUtils.getDefinitionSetId(DMNDefinitionSet.class), metadata).getGraph();
    elems.values().stream().map(Map.Entry::getValue).forEach(graph::addNode);
    textAnnotations.values().forEach(graph::addNode);
    final Node<?, ?> dmnDiagramRoot = findDMNDiagramRoot(graph);
    final Definitions definitionsStunnerPojo = DefinitionsConverter.wbFromDMN(dmnXml, importDefinitions, pmmlDocuments);
    loadImportedItemDefinitions(definitionsStunnerPojo, importDefinitions);
    ((View<DMNDiagram>) dmnDiagramRoot.getContent()).getDefinition().setDefinitions(definitionsStunnerPojo);
    // Only connect Nodes to the Diagram that are not referenced by DecisionServices
    final List<String> references = new ArrayList<>();
    dmnDecisionServices.forEach(ds -> references.addAll(ds.getEncapsulatedDecision().stream().map(org.kie.dmn.model.api.DMNElementReference::getHref).collect(Collectors.toList())));
    dmnDecisionServices.forEach(ds -> references.addAll(ds.getOutputDecision().stream().map(org.kie.dmn.model.api.DMNElementReference::getHref).collect(Collectors.toList())));
    final Map<org.kie.dmn.model.api.DRGElement, Node> elemsToConnectToRoot = elems.values().stream().filter(elem -> !references.contains("#" + elem.getKey().getId())).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
    elemsToConnectToRoot.values().stream().forEach(node -> connectRootWithChild(dmnDiagramRoot, node));
    textAnnotations.values().stream().forEach(node -> connectRootWithChild(dmnDiagramRoot, node));
    // Copy ComponentWidths information
    final Optional<ComponentsWidthsExtension> extension = findComponentsWidthsExtension(dmnDDDiagram);
    extension.ifPresent(componentsWidthsExtension -> {
        // can be imported from another diagram but the extension is not imported or present in this diagram.
        if (componentsWidthsExtension.getComponentsWidths() != null) {
            hasComponentWidthsMap.forEach((uuid, hasComponentWidths) -> componentsWidthsExtension.getComponentsWidths().stream().filter(componentWidths -> componentWidths.getDmnElementRef().getLocalPart().equals(uuid)).findFirst().ifPresent(componentWidths -> {
                final List<Double> widths = hasComponentWidths.getComponentWidths();
                widths.clear();
                widths.addAll(componentWidths.getWidths());
            }));
        }
    });
    return graph;
}
Also used : Edge(org.kie.workbench.common.stunner.core.graph.Edge) PointUtils.yOfBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.yOfBound) PointUtils.xOfBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.xOfBound) DoubleConsumer(java.util.function.DoubleConsumer) Bounds(org.kie.dmn.model.api.dmndi.Bounds) Map(java.util.Map) NamedElement(org.kie.workbench.common.dmn.api.definition.model.NamedElement) 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) Height(org.kie.workbench.common.dmn.api.property.dimensions.Height) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) Set(java.util.Set) BusinessKnowledgeModelConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.BusinessKnowledgeModelConverter) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) PointUtils.heightOfShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.heightOfShape) Stream(java.util.stream.Stream) PointUtils(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils) QName(javax.xml.namespace.QName) PointUtils.widthOfShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.widthOfShape) DMNMarshaller(org.kie.dmn.api.marshalling.DMNMarshaller) PointUtils.yOfShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.yOfShape) DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) DMNStyle(org.kie.dmn.model.api.dmndi.DMNStyle) Point(org.kie.dmn.model.api.dmndi.Point) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) Color(org.kie.dmn.model.api.dmndi.Color) ItemDefinitionPropertyConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.ItemDefinitionPropertyConverter) DiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.definition.service.DiagramMetadataMarshaller) ArrayList(java.util.ArrayList) FontSetPropertyConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.FontSetPropertyConverter) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) PointUtils.upperLeftBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.upperLeftBound) BiConsumer(java.util.function.BiConsumer) StreamSupport(java.util.stream.StreamSupport) BindableAdapterUtils(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils) IOException(java.io.IOException) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) InputStreamReader(java.io.InputStreamReader) InputDataConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.InputDataConverter) Association(org.kie.workbench.common.dmn.api.definition.model.Association) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) KnowledgeSourceConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.KnowledgeSourceConverter) Graph(org.kie.workbench.common.stunner.core.graph.Graph) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) DecisionConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DecisionConverter) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) DMNDecisionServiceDividerLine(org.kie.dmn.model.api.dmndi.DMNDecisionServiceDividerLine) DMNEdge(org.kie.dmn.model.api.dmndi.DMNEdge) UUID(org.kie.workbench.common.stunner.core.util.UUID) BorderColour(org.kie.workbench.common.dmn.api.property.styling.BorderColour) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) TextAnnotationConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.TextAnnotationConverter) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) Collectors.toMap(java.util.stream.Collectors.toMap) PointUtils.lowerRightBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.lowerRightBound) InformationRequirement(org.kie.workbench.common.dmn.api.definition.model.InformationRequirement) DiagramElement(org.kie.dmn.model.v1_2.dmndi.DiagramElement) Collections.emptyList(java.util.Collections.emptyList) DiagramMarshaller(org.kie.workbench.common.stunner.core.definition.service.DiagramMarshaller) Import(org.kie.dmn.model.api.Import) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Collectors(java.util.stream.Collectors) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Objects(java.util.Objects) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) List(java.util.List) DMNShape(org.kie.dmn.model.api.dmndi.DMNShape) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths) BgColour(org.kie.workbench.common.dmn.api.property.styling.BgColour) DMNDI(org.kie.dmn.model.v1_2.dmndi.DMNDI) Entry(java.util.Map.Entry) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Node(org.kie.workbench.common.stunner.core.graph.Node) PointUtils.xOfShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.xOfShape) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Width(org.kie.workbench.common.dmn.api.property.dimensions.Width) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) RectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.RectangleDimensionsSet) DefinitionsConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DefinitionsConverter) HashMap(java.util.HashMap) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ColorUtils(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ColorUtils) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ComponentsWidthsExtension(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentsWidthsExtension) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) 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) DMNViewDefinition(org.kie.workbench.common.dmn.api.definition.DMNViewDefinition) SimpleEntry(java.util.AbstractMap.SimpleEntry) DecisionServiceDividerLineY(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) AssociationConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.AssociationConverter) DMNMarshallerImportsHelperStandalone(org.kie.workbench.common.dmn.backend.common.DMNMarshallerImportsHelperStandalone) DecisionServiceConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DecisionServiceConverter) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) AuthorityRequirement(org.kie.workbench.common.dmn.api.definition.model.AuthorityRequirement) Consumer(java.util.function.Consumer) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DiscreteConnection(org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection) InputStream(java.io.InputStream) Import(org.kie.dmn.model.api.Import) HashMap(java.util.HashMap) Node(org.kie.workbench.common.stunner.core.graph.Node) ArrayList(java.util.ArrayList) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) HashSet(java.util.HashSet) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) SimpleEntry(java.util.AbstractMap.SimpleEntry) Graph(org.kie.workbench.common.stunner.core.graph.Graph) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) BindableAdapterUtils.getDefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId) Map(java.util.Map) Collectors.toMap(java.util.stream.Collectors.toMap) HashMap(java.util.HashMap) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) AuthorityRequirement(org.kie.workbench.common.dmn.api.definition.model.AuthorityRequirement) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) DMNShape(org.kie.dmn.model.api.dmndi.DMNShape) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) Association(org.kie.workbench.common.dmn.api.definition.model.Association) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) InputStreamReader(java.io.InputStreamReader) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) 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) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) ComponentsWidthsExtension(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentsWidthsExtension) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DMNEdge(org.kie.dmn.model.api.dmndi.DMNEdge)

Example 77 with Decision

use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.

the class DMNMarshallerStandalone method ddExtAugmentStunner.

private void ddExtAugmentStunner(final Optional<org.kie.dmn.model.api.dmndi.DMNDiagram> dmnDDDiagram, Node currentNode) {
    if (!dmnDDDiagram.isPresent()) {
        return;
    }
    final Stream<DMNShape> drgShapeStream = dmnDDDiagram.get().getDMNDiagramElement().stream().filter(DMNShape.class::isInstance).map(DMNShape.class::cast);
    final View content = (View) currentNode.getContent();
    final Bound ulBound = upperLeftBound(content);
    final Bound lrBound = lowerRightBound(content);
    if (content.getDefinition() instanceof Decision) {
        final Decision d = (Decision) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), ulBound, d.getDimensionsSet(), lrBound, d.getStylingSet());
    } else if (content.getDefinition() instanceof InputData) {
        final InputData d = (InputData) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), ulBound, d.getDimensionsSet(), lrBound, d.getStylingSet());
    } else if (content.getDefinition() instanceof BusinessKnowledgeModel) {
        final BusinessKnowledgeModel d = (BusinessKnowledgeModel) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), ulBound, d.getDimensionsSet(), lrBound, d.getStylingSet());
    } else if (content.getDefinition() instanceof KnowledgeSource) {
        final KnowledgeSource d = (KnowledgeSource) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), ulBound, d.getDimensionsSet(), lrBound, d.getStylingSet());
    } else if (content.getDefinition() instanceof TextAnnotation) {
        final TextAnnotation d = (TextAnnotation) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), ulBound, d.getDimensionsSet(), lrBound, d.getStylingSet());
    } else if (content.getDefinition() instanceof DecisionService) {
        final DecisionService d = (DecisionService) content.getDefinition();
        internalAugment(drgShapeStream, d.getId(), ulBound, d.getDimensionsSet(), lrBound, d.getStylingSet(), dividerLineY -> d.setDividerLineY(new DecisionServiceDividerLineY(dividerLineY - ulBound.getY())));
    }
}
Also used : DMNShape(org.kie.dmn.model.api.dmndi.DMNShape) Edge(org.kie.workbench.common.stunner.core.graph.Edge) PointUtils.yOfBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.yOfBound) PointUtils.xOfBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.xOfBound) DoubleConsumer(java.util.function.DoubleConsumer) Bounds(org.kie.dmn.model.api.dmndi.Bounds) Map(java.util.Map) NamedElement(org.kie.workbench.common.dmn.api.definition.model.NamedElement) 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) Height(org.kie.workbench.common.dmn.api.property.dimensions.Height) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) Set(java.util.Set) BusinessKnowledgeModelConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.BusinessKnowledgeModelConverter) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) ItemDefinition(org.kie.workbench.common.dmn.api.definition.model.ItemDefinition) PointUtils.heightOfShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.heightOfShape) Stream(java.util.stream.Stream) PointUtils(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils) QName(javax.xml.namespace.QName) PointUtils.widthOfShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.widthOfShape) DMNMarshaller(org.kie.dmn.api.marshalling.DMNMarshaller) PointUtils.yOfShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.yOfShape) DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) DMNStyle(org.kie.dmn.model.api.dmndi.DMNStyle) Point(org.kie.dmn.model.api.dmndi.Point) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) Color(org.kie.dmn.model.api.dmndi.Color) ItemDefinitionPropertyConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.ItemDefinitionPropertyConverter) DiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.definition.service.DiagramMetadataMarshaller) ArrayList(java.util.ArrayList) FontSetPropertyConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.FontSetPropertyConverter) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) PointUtils.upperLeftBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.upperLeftBound) BiConsumer(java.util.function.BiConsumer) StreamSupport(java.util.stream.StreamSupport) BindableAdapterUtils(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils) IOException(java.io.IOException) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) InputStreamReader(java.io.InputStreamReader) InputDataConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.InputDataConverter) Association(org.kie.workbench.common.dmn.api.definition.model.Association) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) KnowledgeSourceConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.KnowledgeSourceConverter) Graph(org.kie.workbench.common.stunner.core.graph.Graph) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) Definitions(org.kie.workbench.common.dmn.api.definition.model.Definitions) DecisionConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DecisionConverter) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) DMNDecisionServiceDividerLine(org.kie.dmn.model.api.dmndi.DMNDecisionServiceDividerLine) DMNEdge(org.kie.dmn.model.api.dmndi.DMNEdge) UUID(org.kie.workbench.common.stunner.core.util.UUID) BorderColour(org.kie.workbench.common.dmn.api.property.styling.BorderColour) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) TextAnnotationConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.TextAnnotationConverter) DMNElement(org.kie.workbench.common.dmn.api.definition.model.DMNElement) Collectors.toMap(java.util.stream.Collectors.toMap) PointUtils.lowerRightBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.lowerRightBound) InformationRequirement(org.kie.workbench.common.dmn.api.definition.model.InformationRequirement) DiagramElement(org.kie.dmn.model.v1_2.dmndi.DiagramElement) Collections.emptyList(java.util.Collections.emptyList) DiagramMarshaller(org.kie.workbench.common.stunner.core.definition.service.DiagramMarshaller) Import(org.kie.dmn.model.api.Import) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) Collectors(java.util.stream.Collectors) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Objects(java.util.Objects) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) List(java.util.List) DMNShape(org.kie.dmn.model.api.dmndi.DMNShape) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths) BgColour(org.kie.workbench.common.dmn.api.property.styling.BgColour) DMNDI(org.kie.dmn.model.v1_2.dmndi.DMNDI) Entry(java.util.Map.Entry) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Node(org.kie.workbench.common.stunner.core.graph.Node) PointUtils.xOfShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.xOfShape) PMMLDocumentMetadata(org.kie.workbench.common.dmn.api.editors.included.PMMLDocumentMetadata) Width(org.kie.workbench.common.dmn.api.property.dimensions.Width) ControlPoint(org.kie.workbench.common.stunner.core.graph.content.view.ControlPoint) RectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.RectangleDimensionsSet) DefinitionsConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DefinitionsConverter) HashMap(java.util.HashMap) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ColorUtils(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ColorUtils) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ComponentsWidthsExtension(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentsWidthsExtension) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) 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) DMNViewDefinition(org.kie.workbench.common.dmn.api.definition.DMNViewDefinition) SimpleEntry(java.util.AbstractMap.SimpleEntry) DecisionServiceDividerLineY(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) AssociationConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.AssociationConverter) DMNMarshallerImportsHelperStandalone(org.kie.workbench.common.dmn.backend.common.DMNMarshallerImportsHelperStandalone) DecisionServiceConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DecisionServiceConverter) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) AuthorityRequirement(org.kie.workbench.common.dmn.api.definition.model.AuthorityRequirement) Consumer(java.util.function.Consumer) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DiscreteConnection(org.kie.workbench.common.stunner.core.graph.content.view.DiscreteConnection) InputStream(java.io.InputStream) DecisionServiceDividerLineY(org.kie.workbench.common.dmn.api.property.dmn.DecisionServiceDividerLineY) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) PointUtils.yOfBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.yOfBound) PointUtils.xOfBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.xOfBound) PointUtils.upperLeftBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.upperLeftBound) PointUtils.lowerRightBound(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.PointUtils.lowerRightBound) Bound(org.kie.workbench.common.stunner.core.graph.content.Bound) InputData(org.kie.workbench.common.dmn.api.definition.model.InputData) TextAnnotation(org.kie.workbench.common.dmn.api.definition.model.TextAnnotation) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService)

Example 78 with Decision

use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.

the class DecisionConverter method dmnFromNode.

@Override
public org.kie.dmn.model.api.Decision dmnFromNode(final Node<View<Decision>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) {
    final Decision source = (Decision) DefinitionUtils.getElementDefinition(node);
    final org.kie.dmn.model.api.Decision d = new org.kie.dmn.model.v1_2.TDecision();
    d.setId(source.getId().getValue());
    d.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
    d.setName(source.getName().getValue());
    final org.kie.dmn.model.api.InformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
    if (variable != null) {
        variable.setParent(d);
    }
    d.setVariable(variable);
    final org.kie.dmn.model.api.Expression expression = ExpressionPropertyConverter.dmnFromWB(source.getExpression(), componentWidthsConsumer);
    if (expression != null) {
        expression.setParent(d);
    }
    d.setExpression(expression);
    d.setQuestion(QuestionPropertyConverter.dmnFromWB(source.getQuestion()));
    d.setAllowedAnswers(AllowedAnswersPropertyConverter.dmnFromWB(source.getAllowedAnswers()));
    // DMN spec table 2: Requirements connection rules
    final List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
    for (Edge<?, ?> e : inEdges) {
        final Node<?, ?> sourceNode = e.getSourceNode();
        if (sourceNode.getContent() instanceof View<?>) {
            final View<?> view = (View<?>) sourceNode.getContent();
            if (view.getDefinition() instanceof DRGElement) {
                final DRGElement drgElement = (DRGElement) view.getDefinition();
                if (drgElement instanceof Decision) {
                    final org.kie.dmn.model.api.InformationRequirement iReq = new org.kie.dmn.model.v1_2.TInformationRequirement();
                    iReq.setId(e.getUUID());
                    final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredDecision(ri);
                    d.getInformationRequirement().add(iReq);
                } else if (drgElement instanceof BusinessKnowledgeModel) {
                    final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement();
                    iReq.setId(e.getUUID());
                    final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredKnowledge(ri);
                    d.getKnowledgeRequirement().add(iReq);
                } else if (drgElement instanceof KnowledgeSource) {
                    final org.kie.dmn.model.api.AuthorityRequirement iReq = new org.kie.dmn.model.v1_2.TAuthorityRequirement();
                    iReq.setId(e.getUUID());
                    final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredAuthority(ri);
                    d.getAuthorityRequirement().add(iReq);
                } else if (drgElement instanceof InputData) {
                    final org.kie.dmn.model.api.InformationRequirement iReq = new org.kie.dmn.model.v1_2.TInformationRequirement();
                    iReq.setId(e.getUUID());
                    final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
                    ri.setHref(getHref(drgElement));
                    iReq.setRequiredInput(ri);
                    d.getInformationRequirement().add(iReq);
                } else if (drgElement instanceof DecisionService) {
                    if (e.getContent() instanceof Child) {
                    // Stunner relationship of this Decision be encapsulated by the DecisionService, not managed here.
                    } else if (e.getContent() instanceof View && ((View) e.getContent()).getDefinition() instanceof KnowledgeRequirement) {
                        final org.kie.dmn.model.api.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_2.TKnowledgeRequirement();
                        iReq.setId(e.getUUID());
                        final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
                        ri.setHref(getHref(drgElement));
                        iReq.setRequiredKnowledge(ri);
                        d.getKnowledgeRequirement().add(iReq);
                    } else {
                        throw new UnsupportedOperationException("wrong model definition.");
                    }
                } else {
                    throw new UnsupportedOperationException("wrong model definition.");
                }
            }
        }
    }
    DMNExternalLinksToExtensionElements.loadExternalLinksIntoExtensionElements(source, d);
    return d;
}
Also used : DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource) 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) 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) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement)

Example 79 with Decision

use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.

the class DecisionServiceConverter method dmnFromNode.

@Override
@SuppressWarnings("unchecked")
public org.kie.dmn.model.api.DecisionService dmnFromNode(final Node<View<DecisionService>, ?> node, final Consumer<ComponentWidths> componentWidthsConsumer) {
    final DecisionService source = (DecisionService) DefinitionUtils.getElementDefinition(node);
    final org.kie.dmn.model.api.DecisionService ds = new org.kie.dmn.model.v1_2.TDecisionService();
    ds.setId(source.getId().getValue());
    ds.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
    ds.setName(source.getName().getValue());
    final org.kie.dmn.model.api.InformationItem variable = InformationItemPrimaryPropertyConverter.dmnFromWB(source.getVariable(), source);
    if (variable != null) {
        variable.setParent(ds);
    }
    ds.setVariable(variable);
    final List<org.kie.dmn.model.api.DMNElementReference> existing_outputDecision = source.getOutputDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
    final List<org.kie.dmn.model.api.DMNElementReference> existing_encapsulatedDecision = source.getEncapsulatedDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
    final List<org.kie.dmn.model.api.DMNElementReference> existing_inputDecision = source.getInputDecision().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
    final List<org.kie.dmn.model.api.DMNElementReference> existing_inputData = source.getInputData().stream().map(DMNElementReferenceConverter::dmnFromWB).collect(Collectors.toList());
    final List<org.kie.dmn.model.api.DMNElementReference> candidate_outputDecision = new ArrayList<>();
    final List<org.kie.dmn.model.api.DMNElementReference> candidate_encapsulatedDecision = new ArrayList<>();
    final List<org.kie.dmn.model.api.DMNElementReference> candidate_inputDecision = new ArrayList<>();
    final List<org.kie.dmn.model.api.DMNElementReference> candidate_inputData = new ArrayList<>();
    final List<InputData> reqInputs = new ArrayList<>();
    final List<Decision> reqDecisions = new ArrayList<>();
    // 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 org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
                    ri.setHref(new StringBuilder("#").append(decision.getId().getValue()).toString());
                    if (isOutputDecision(targetNode.getContent(), node.getContent())) {
                        candidate_outputDecision.add(ri);
                    } else {
                        candidate_encapsulatedDecision.add(ri);
                    }
                    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 org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
        ri.setHref(new StringBuilder("#").append(x.getId().getValue()).toString());
        return ri;
    }).forEach(candidate_inputData::add);
    reqDecisions.stream().sorted(Comparator.comparing(x -> x.getName().getValue())).map(x -> {
        final org.kie.dmn.model.api.DMNElementReference ri = new org.kie.dmn.model.v1_2.TDMNElementReference();
        ri.setHref(new StringBuilder("#").append(x.getId().getValue()).toString());
        return ri;
    }).forEach(candidate_inputDecision::add);
    for (org.kie.dmn.model.api.DMNElementReference er : candidate_outputDecision) {
        candidate_inputDecision.removeIf(x -> x.getHref().equals(er.getHref()));
    }
    for (org.kie.dmn.model.api.DMNElementReference er : candidate_encapsulatedDecision) {
        candidate_inputDecision.removeIf(x -> x.getHref().equals(er.getHref()));
    }
    reconcileExistingAndCandidate(ds.getInputData(), existing_inputData, candidate_inputData);
    reconcileExistingAndCandidate(ds.getInputDecision(), existing_inputDecision, candidate_inputDecision);
    reconcileExistingAndCandidate(ds.getEncapsulatedDecision(), existing_encapsulatedDecision, candidate_encapsulatedDecision);
    reconcileExistingAndCandidate(ds.getOutputDecision(), 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) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) BindableAdapterUtils.getDefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId) BiConsumer(java.util.function.BiConsumer) KnowledgeRequirement(org.kie.workbench.common.dmn.api.definition.model.KnowledgeRequirement) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) FactoryManager(org.kie.workbench.common.stunner.core.api.FactoryManager) HasComponentWidths(org.kie.workbench.common.dmn.api.definition.HasComponentWidths) 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) 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) Consumer(java.util.function.Consumer) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement) List(java.util.List) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) ComponentWidths(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ComponentWidths) 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) ArrayList(java.util.ArrayList) DecisionService(org.kie.workbench.common.dmn.api.definition.model.DecisionService) 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) 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) DMNElementReference(org.kie.workbench.common.dmn.api.definition.model.DMNElementReference) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DRGElement(org.kie.workbench.common.dmn.api.definition.model.DRGElement)

Example 80 with Decision

use of org.kie.workbench.common.dmn.api.definition.model.Decision in project kie-wb-common by kiegroup.

the class DecisionConverter method nodeFromDMN.

@Override
public Node<View<Decision>, ?> nodeFromDMN(final NodeEntry nodeEntry) {
    final JSITDecision dmn = Js.uncheckedCast(nodeEntry.getDmnElement());
    @SuppressWarnings("unchecked") final Node<View<Decision>, ?> node = (Node<View<Decision>, ?>) factoryManager.newElement(nodeEntry.getId(), getDefinitionId(Decision.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);
    Expression expression = null;
    final JSITExpression jsiWrapped = dmn.getExpression();
    if (Objects.nonNull(jsiWrapped)) {
        final JSITExpression jsiExpression = Js.uncheckedCast(JsUtils.getUnwrappedElement(jsiWrapped));
        expression = ExpressionPropertyConverter.wbFromDMN(jsiExpression, Js.uncheckedCast(dmn), nodeEntry.getComponentWidthsConsumer());
    }
    final Decision decision = new Decision(id, description, name, new Question(), new AllowedAnswers(), informationItem, expression, new StylingSet(), new GeneralRectangleDimensionsSet());
    decision.setDiagramId(nodeEntry.getDiagramId());
    decision.setQuestion(QuestionPropertyConverter.wbFromDMN(dmn.getQuestion()));
    decision.setAllowedAnswers(AllowedAnswersPropertyConverter.wbFromDMN(dmn.getAllowedAnswers()));
    node.getContent().setDefinition(decision);
    if (Objects.nonNull(informationItem)) {
        informationItem.setParent(decision);
    }
    if (Objects.nonNull(expression)) {
        expression.setParent(decision);
    }
    DMNExternalLinksToExtensionElements.loadExternalLinksFromExtensionElements(dmn, decision);
    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) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) GeneralRectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.GeneralRectangleDimensionsSet) AllowedAnswers(org.kie.workbench.common.dmn.api.property.dmn.AllowedAnswers) View(org.kie.workbench.common.stunner.core.graph.content.view.View) JSITDecision(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDecision) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) StylingSet(org.kie.workbench.common.dmn.api.property.styling.StylingSet) Question(org.kie.workbench.common.dmn.api.property.dmn.Question) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) IdUtils.getRawId(org.kie.workbench.common.dmn.client.marshaller.common.IdUtils.getRawId) BindableAdapterUtils.getDefinitionId(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils.getDefinitionId) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)

Aggregations

Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)121 Test (org.junit.Test)79 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)39 View (org.kie.workbench.common.stunner.core.graph.content.view.View)38 InputData (org.kie.workbench.common.dmn.api.definition.model.InputData)37 Node (org.kie.workbench.common.stunner.core.graph.Node)28 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)23 Edge (org.kie.workbench.common.stunner.core.graph.Edge)23 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)22 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.model.KnowledgeSource)21 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)21 ViewImpl (org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl)20 List (java.util.List)16 TDecision (org.kie.dmn.model.v1_2.TDecision)16 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)16 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)16 TextAnnotation (org.kie.workbench.common.dmn.api.definition.model.TextAnnotation)16 ArrayList (java.util.ArrayList)15 Optional (java.util.Optional)15 DecisionService (org.kie.workbench.common.dmn.api.definition.model.DecisionService)15