Search in sources :

Example 6 with DRGElement

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

the class KnowledgeSourceConverter method dmnFromNode.

@Override
public org.kie.dmn.model.v1_1.KnowledgeSource dmnFromNode(final Node<View<KnowledgeSource>, ?> node) {
    KnowledgeSource source = node.getContent().getDefinition();
    org.kie.dmn.model.v1_1.KnowledgeSource result = new org.kie.dmn.model.v1_1.KnowledgeSource();
    result.setId(source.getId().getValue());
    result.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
    result.setName(source.getName().getValue());
    result.setType(source.getType().getValue());
    result.setLocationURI(source.getLocationURI().getValue());
    // DMN spec table 2: Requirements connection rules
    List<Edge<?, ?>> inEdges = (List<Edge<?, ?>>) node.getInEdges();
    for (Edge<?, ?> e : inEdges) {
        Node<?, ?> sourceNode = e.getSourceNode();
        if (sourceNode.getContent() instanceof View<?>) {
            View<?> view = (View<?>) sourceNode.getContent();
            if (view.getDefinition() instanceof DRGElement) {
                DRGElement drgElement = (DRGElement) view.getDefinition();
                if (drgElement instanceof Decision) {
                    org.kie.dmn.model.v1_1.AuthorityRequirement iReq = new org.kie.dmn.model.v1_1.AuthorityRequirement();
                    org.kie.dmn.model.v1_1.DMNElementReference ri = new org.kie.dmn.model.v1_1.DMNElementReference();
                    ri.setHref(new StringBuilder("#").append(drgElement.getId().getValue()).toString());
                    iReq.setRequiredDecision(ri);
                    result.getAuthorityRequirement().add(iReq);
                } else if (drgElement instanceof KnowledgeSource) {
                    org.kie.dmn.model.v1_1.AuthorityRequirement iReq = new org.kie.dmn.model.v1_1.AuthorityRequirement();
                    org.kie.dmn.model.v1_1.DMNElementReference ri = new org.kie.dmn.model.v1_1.DMNElementReference();
                    ri.setHref(new StringBuilder("#").append(drgElement.getId().getValue()).toString());
                    iReq.setRequiredAuthority(ri);
                    result.getAuthorityRequirement().add(iReq);
                } else if (drgElement instanceof InputData) {
                    org.kie.dmn.model.v1_1.AuthorityRequirement iReq = new org.kie.dmn.model.v1_1.AuthorityRequirement();
                    org.kie.dmn.model.v1_1.DMNElementReference ri = new org.kie.dmn.model.v1_1.DMNElementReference();
                    ri.setHref(new StringBuilder("#").append(drgElement.getId().getValue()).toString());
                    iReq.setRequiredInput(ri);
                    result.getAuthorityRequirement().add(iReq);
                } else {
                    throw new UnsupportedOperationException("wrong model definition.");
                }
            }
        }
    }
    return result;
}
Also used : View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource) List(java.util.List) InputData(org.kie.workbench.common.dmn.api.definition.v1_1.InputData) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DRGElement(org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement)

Example 7 with DRGElement

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

the class DMNMarshaller method marshall.

@Override
public String marshall(final Diagram<Graph, Metadata> diagram) throws IOException {
    Graph<?, Node<View, ?>> g = diagram.getGraph();
    Map<String, org.kie.dmn.model.v1_1.DRGElement> nodes = new HashMap<>();
    Map<String, org.kie.dmn.model.v1_1.TextAnnotation> textAnnotations = new HashMap<>();
    @SuppressWarnings("unchecked") Node<View<DMNDiagram>, ?> dmnDiagramRoot = (Node<View<DMNDiagram>, ?>) findDMNDiagramRoot(g);
    Definitions definitionsStunnerPojo = dmnDiagramRoot.getContent().getDefinition().getDefinitions();
    org.kie.dmn.model.v1_1.Definitions definitions = DefinitionsConverter.dmnFromWB(definitionsStunnerPojo);
    if (definitions.getExtensionElements() == null) {
        definitions.setExtensionElements(new org.kie.dmn.model.v1_1.Definitions.ExtensionElements());
    }
    org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram dmnDDDMNDiagram = new org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram();
    definitions.getExtensionElements().getAny().add(dmnDDDMNDiagram);
    for (Node<?, ?> node : g.nodes()) {
        if (node.getContent() instanceof View<?>) {
            View<?> view = (View<?>) node.getContent();
            if (view.getDefinition() instanceof DRGElement) {
                DRGElement n = (org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement) view.getDefinition();
                nodes.put(n.getId().getValue(), stunnerToDMN(node));
                dmnDDDMNDiagram.getAny().add(stunnerToDDExt((View<? extends DMNElement>) view));
            } else if (view.getDefinition() instanceof TextAnnotation) {
                TextAnnotation textAnnotation = (TextAnnotation) view.getDefinition();
                textAnnotations.put(textAnnotation.getId().getValue(), textAnnotationConverter.dmnFromNode((Node<View<TextAnnotation>, ?>) node));
                dmnDDDMNDiagram.getAny().add(stunnerToDDExt((View<? extends DMNElement>) view));
                List<org.kie.dmn.model.v1_1.Association> associations = AssociationConverter.dmnFromWB((Node<View<TextAnnotation>, ?>) node);
                definitions.getArtifact().addAll(associations);
            }
        }
    }
    nodes.values().forEach(definitions.getDrgElement()::add);
    textAnnotations.values().forEach(definitions.getArtifact()::add);
    String marshalled = marshaller.marshal(definitions);
    return marshalled;
}
Also used : HashMap(java.util.HashMap) Node(org.kie.workbench.common.stunner.core.graph.Node) DMNElement(org.kie.workbench.common.dmn.api.definition.v1_1.DMNElement) List(java.util.List) TextAnnotation(org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation) DMNDiagram(org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram) Definitions(org.kie.workbench.common.dmn.api.definition.v1_1.Definitions) View(org.kie.workbench.common.stunner.core.graph.content.view.View) DRGElement(org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement)

Aggregations

List (java.util.List)6 DRGElement (org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement)6 View (org.kie.workbench.common.stunner.core.graph.content.view.View)6 Edge (org.kie.workbench.common.stunner.core.graph.Edge)5 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource)4 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel)3 Decision (org.kie.workbench.common.dmn.api.definition.v1_1.Decision)3 InputData (org.kie.workbench.common.dmn.api.definition.v1_1.InputData)3 TextAnnotation (org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation)3 HashMap (java.util.HashMap)2 Association (org.kie.workbench.common.dmn.api.definition.v1_1.Association)2 DMNDiagram (org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram)2 DMNElement (org.kie.workbench.common.dmn.api.definition.v1_1.DMNElement)2 Definitions (org.kie.workbench.common.dmn.api.definition.v1_1.Definitions)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1