Search in sources :

Example 6 with Decision

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

the class DMNMarshaller method unmarshall.

@Override
public Graph unmarshall(final Metadata metadata, final InputStream input) throws IOException {
    org.kie.dmn.model.v1_1.Definitions dmnXml = marshaller.unmarshal(new InputStreamReader(input));
    Map<String, Entry<org.kie.dmn.model.v1_1.DRGElement, Node>> elems = dmnXml.getDrgElement().stream().collect(Collectors.toMap(org.kie.dmn.model.v1_1.DRGElement::getId, dmn -> new SimpleEntry<>(dmn, dmnToStunner(dmn))));
    Optional<org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNDiagram> dmnDDDiagram = findDMNDiagram(dmnXml);
    for (Entry<org.kie.dmn.model.v1_1.DRGElement, Node> kv : elems.values()) {
        org.kie.dmn.model.v1_1.DRGElement elem = kv.getKey();
        Node currentNode = kv.getValue();
        ddExtAugmentStunner(dmnDDDiagram, currentNode);
        // DMN spec table 2: Requirements connection rules
        if (elem instanceof org.kie.dmn.model.v1_1.Decision) {
            org.kie.dmn.model.v1_1.Decision decision = (org.kie.dmn.model.v1_1.Decision) elem;
            for (org.kie.dmn.model.v1_1.InformationRequirement ir : decision.getInformationRequirement()) {
                if (ir.getRequiredInput() != null) {
                    String reqInputID = getId(ir.getRequiredInput());
                    Node requiredNode = elems.get(reqInputID).getValue();
                    Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.InformationRequirement.class).asEdge();
                    connectEdge(myEdge, requiredNode, currentNode);
                    setConnectionMagnets(myEdge);
                }
                if (ir.getRequiredDecision() != null) {
                    String reqInputID = getId(ir.getRequiredDecision());
                    Node requiredNode = elems.get(reqInputID).getValue();
                    Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.InformationRequirement.class).asEdge();
                    connectEdge(myEdge, requiredNode, currentNode);
                    setConnectionMagnets(myEdge);
                }
            }
            for (org.kie.dmn.model.v1_1.KnowledgeRequirement kr : decision.getKnowledgeRequirement()) {
                String reqInputID = getId(kr.getRequiredKnowledge());
                Node requiredNode = elems.get(reqInputID).getValue();
                Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeRequirement.class).asEdge();
                connectEdge(myEdge, requiredNode, currentNode);
                setConnectionMagnets(myEdge);
            }
            for (org.kie.dmn.model.v1_1.AuthorityRequirement kr : decision.getAuthorityRequirement()) {
                String reqInputID = getId(kr.getRequiredAuthority());
                Node requiredNode = elems.get(reqInputID).getValue();
                Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
                connectEdge(myEdge, requiredNode, currentNode);
                setConnectionMagnets(myEdge);
            }
        } else if (elem instanceof org.kie.dmn.model.v1_1.BusinessKnowledgeModel) {
            org.kie.dmn.model.v1_1.BusinessKnowledgeModel bkm = (org.kie.dmn.model.v1_1.BusinessKnowledgeModel) elem;
            for (org.kie.dmn.model.v1_1.KnowledgeRequirement kr : bkm.getKnowledgeRequirement()) {
                String reqInputID = getId(kr.getRequiredKnowledge());
                Node requiredNode = elems.get(reqInputID).getValue();
                Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeRequirement.class).asEdge();
                connectEdge(myEdge, requiredNode, currentNode);
                setConnectionMagnets(myEdge);
            }
            for (org.kie.dmn.model.v1_1.AuthorityRequirement kr : bkm.getAuthorityRequirement()) {
                String reqInputID = getId(kr.getRequiredAuthority());
                Node requiredNode = elems.get(reqInputID).getValue();
                Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
                connectEdge(myEdge, requiredNode, currentNode);
                setConnectionMagnets(myEdge);
            }
        } else if (elem instanceof org.kie.dmn.model.v1_1.KnowledgeSource) {
            org.kie.dmn.model.v1_1.KnowledgeSource ks = (org.kie.dmn.model.v1_1.KnowledgeSource) elem;
            for (org.kie.dmn.model.v1_1.AuthorityRequirement ir : ks.getAuthorityRequirement()) {
                if (ir.getRequiredInput() != null) {
                    String reqInputID = getId(ir.getRequiredInput());
                    Node requiredNode = elems.get(reqInputID).getValue();
                    Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
                    connectEdge(myEdge, requiredNode, currentNode);
                    setConnectionMagnets(myEdge);
                }
                if (ir.getRequiredDecision() != null) {
                    String reqInputID = getId(ir.getRequiredDecision());
                    Node requiredNode = elems.get(reqInputID).getValue();
                    Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
                    connectEdge(myEdge, requiredNode, currentNode);
                    setConnectionMagnets(myEdge);
                }
                if (ir.getRequiredAuthority() != null) {
                    String reqInputID = getId(ir.getRequiredAuthority());
                    Node requiredNode = elems.get(reqInputID).getValue();
                    Edge myEdge = factoryManager.newElement(UUID.uuid(), org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement.class).asEdge();
                    connectEdge(myEdge, requiredNode, currentNode);
                    setConnectionMagnets(myEdge);
                }
            }
        }
    }
    Map<String, Node<View<TextAnnotation>, ?>> textAnnotations = dmnXml.getArtifact().stream().filter(org.kie.dmn.model.v1_1.TextAnnotation.class::isInstance).map(org.kie.dmn.model.v1_1.TextAnnotation.class::cast).collect(Collectors.toMap(org.kie.dmn.model.v1_1.TextAnnotation::getId, textAnnotationConverter::nodeFromDMN));
    textAnnotations.values().forEach(n -> ddExtAugmentStunner(dmnDDDiagram, n));
    List<org.kie.dmn.model.v1_1.Association> associations = dmnXml.getArtifact().stream().filter(org.kie.dmn.model.v1_1.Association.class::isInstance).map(org.kie.dmn.model.v1_1.Association.class::cast).collect(Collectors.toList());
    for (org.kie.dmn.model.v1_1.Association a : associations) {
        String sourceId = getId(a.getSourceRef());
        Node sourceNode = Optional.ofNullable(elems.get(sourceId)).map(Entry::getValue).orElse(textAnnotations.get(sourceId));
        String targetId = getId(a.getTargetRef());
        Node targetNode = Optional.ofNullable(elems.get(targetId)).map(Entry::getValue).orElse(textAnnotations.get(targetId));
        @SuppressWarnings("unchecked") Edge<View<Association>, ?> myEdge = (Edge<View<Association>, ?>) factoryManager.newElement(UUID.uuid(), Association.class).asEdge();
        Id id = new Id(a.getId());
        Description description = new Description(a.getDescription());
        Association definition = new Association(id, description);
        myEdge.getContent().setDefinition(definition);
        connectEdge(myEdge, sourceNode, targetNode);
        setConnectionMagnets(myEdge);
    }
    Graph graph = factoryManager.newDiagram("prova", BindableAdapterUtils.getDefinitionSetId(DMNDefinitionSet.class), metadata).getGraph();
    elems.values().stream().map(kv -> kv.getValue()).forEach(graph::addNode);
    textAnnotations.values().forEach(graph::addNode);
    @SuppressWarnings("unchecked") Node<View<DMNDiagram>, ?> dmnDiagramRoot = findDMNDiagramRoot(graph);
    Definitions definitionsStunnerPojo = DefinitionsConverter.wbFromDMN(dmnXml);
    dmnDiagramRoot.getContent().getDefinition().setDefinitions(definitionsStunnerPojo);
    elems.values().stream().map(kv -> kv.getValue()).forEach(node -> connectRootWithChild(dmnDiagramRoot, node));
    textAnnotations.values().stream().forEach(node -> connectRootWithChild(dmnDiagramRoot, node));
    return graph;
}
Also used : Arrays(java.util.Arrays) DecisionConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.DecisionConverter) Edge(org.kie.workbench.common.stunner.core.graph.Edge) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource) UUID(org.kie.workbench.common.stunner.core.util.UUID) EdgeImpl(org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl) Definitions(org.kie.workbench.common.dmn.api.definition.v1_1.Definitions) TextAnnotationConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.TextAnnotationConverter) Bounds(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.org.omg.spec.CMMN_20151109_DC.Bounds) Map(java.util.Map) DMNDiagram(org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram) ServerMarshalling(org.jboss.errai.marshalling.server.ServerMarshalling) BgColour(org.kie.workbench.common.dmn.api.property.background.BgColour) FactoryManager(org.kie.workbench.common.stunner.core.api.FactoryManager) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Height(org.kie.workbench.common.dmn.api.property.dimensions.Height) InputData(org.kie.workbench.common.dmn.api.definition.v1_1.InputData) DiagramMarshaller(org.kie.workbench.common.stunner.core.definition.service.DiagramMarshaller) BusinessKnowledgeModelConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.BusinessKnowledgeModelConverter) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) FontSet(org.kie.workbench.common.dmn.api.property.font.FontSet) Collectors(java.util.stream.Collectors) BorderColour(org.kie.workbench.common.dmn.api.property.background.BorderColour) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel) List(java.util.List) Stream(java.util.stream.Stream) DDExtensionsRegister(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DDExtensionsRegister) Entry(java.util.Map.Entry) DMNMarshallerFactory(org.kie.dmn.backend.marshalling.v1_1.DMNMarshallerFactory) Optional(java.util.Optional) DMNShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) Node(org.kie.workbench.common.stunner.core.graph.Node) Width(org.kie.workbench.common.dmn.api.property.dimensions.Width) DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) 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) DiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.definition.service.DiagramMetadataMarshaller) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ColorUtils(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.ColorUtils) Inject(javax.inject.Inject) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Bound(org.kie.workbench.common.stunner.core.graph.content.Bounds.Bound) DRGElement(org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) StreamSupport(java.util.stream.StreamSupport) SimpleEntry(java.util.AbstractMap.SimpleEntry) BindableAdapterUtils(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils) TextAnnotation(org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) BorderSize(org.kie.workbench.common.dmn.api.property.background.BorderSize) AssociationConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.AssociationConverter) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Association(org.kie.workbench.common.dmn.api.definition.v1_1.Association) BackgroundSet(org.kie.workbench.common.dmn.api.property.background.BackgroundSet) FontSetPropertyConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.FontSetPropertyConverter) InputDataConverter(org.kie.workbench.common.dmn.backend.definition.v1_1.InputDataConverter) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Consumer(java.util.function.Consumer) 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) DMNElement(org.kie.workbench.common.dmn.api.definition.v1_1.DMNElement) InputStream(java.io.InputStream) Node(org.kie.workbench.common.stunner.core.graph.Node) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource) DMNDiagram(org.kie.workbench.common.dmn.api.definition.v1_1.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) DRGElement(org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) Association(org.kie.workbench.common.dmn.api.definition.v1_1.Association) TextAnnotation(org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation) InputStreamReader(java.io.InputStreamReader) Definitions(org.kie.workbench.common.dmn.api.definition.v1_1.Definitions) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 7 with Decision

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

the class DecisionConverter method dmnFromNode.

@Override
public org.kie.dmn.model.v1_1.Decision dmnFromNode(final Node<View<Decision>, ?> node) {
    Decision source = node.getContent().getDefinition();
    org.kie.dmn.model.v1_1.Decision d = new org.kie.dmn.model.v1_1.Decision();
    d.setId(source.getId().getValue());
    d.setDescription(DescriptionPropertyConverter.dmnFromWB(source.getDescription()));
    d.setName(source.getName().getValue());
    d.setVariable(InformationItemPropertyConverter.dmnFromWB(source.getVariable()));
    d.setExpression(ExpressionPropertyConverter.dmnFromWB(source.getExpression()));
    // 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.InformationRequirement iReq = new org.kie.dmn.model.v1_1.InformationRequirement();
                    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);
                    d.getInformationRequirement().add(iReq);
                } else if (drgElement instanceof BusinessKnowledgeModel) {
                    org.kie.dmn.model.v1_1.KnowledgeRequirement iReq = new org.kie.dmn.model.v1_1.KnowledgeRequirement();
                    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.setRequiredKnowledge(ri);
                    d.getKnowledgeRequirement().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);
                    d.getAuthorityRequirement().add(iReq);
                } else if (drgElement instanceof InputData) {
                    org.kie.dmn.model.v1_1.InformationRequirement iReq = new org.kie.dmn.model.v1_1.InformationRequirement();
                    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);
                    d.getInformationRequirement().add(iReq);
                } else {
                    throw new UnsupportedOperationException("wrong model definition.");
                }
            }
        }
    }
    return d;
}
Also used : 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) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel) Edge(org.kie.workbench.common.stunner.core.graph.Edge) DRGElement(org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement)

Example 8 with Decision

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

the class DecisionConverter method nodeFromDMN.

@Override
public Node<View<Decision>, ?> nodeFromDMN(final org.kie.dmn.model.v1_1.Decision dmn) {
    @SuppressWarnings("unchecked") Node<View<Decision>, ?> node = (Node<View<Decision>, ?>) factoryManager.newElement(dmn.getId(), Decision.class).asNode();
    Id id = new Id(dmn.getId());
    Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    Name name = new Name(dmn.getName());
    InformationItem informationItem = InformationItemPropertyConverter.wbFromDMN(dmn.getVariable());
    Expression expression = ExpressionPropertyConverter.wbFromDMN(dmn.getExpression());
    Decision decision = new Decision(id, description, name, new Question(), new AllowedAnswers(), informationItem, expression, new BackgroundSet(), new FontSet(), new RectangleDimensionsSet());
    node.getContent().setDefinition(decision);
    return node;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Node(org.kie.workbench.common.stunner.core.graph.Node) InformationItem(org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem) RectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.RectangleDimensionsSet) AllowedAnswers(org.kie.workbench.common.dmn.api.property.dmn.AllowedAnswers) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) FontSet(org.kie.workbench.common.dmn.api.property.font.FontSet) BackgroundSet(org.kie.workbench.common.dmn.api.property.background.BackgroundSet) Expression(org.kie.workbench.common.dmn.api.definition.v1_1.Expression) Question(org.kie.workbench.common.dmn.api.property.dmn.Question) Id(org.kie.workbench.common.dmn.api.property.dmn.Id)

Example 9 with Decision

use of org.kie.workbench.common.dmn.api.definition.v1_1.Decision 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 10 with Decision

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

the class DMNMarshallerTest method test_function_java_WB_model.

@Test
public void test_function_java_WB_model() throws IOException {
    final DMNMarshaller m = new DMNMarshaller(new XMLEncoderDiagramMetadataMarshaller(), applicationFactoryManager);
    @SuppressWarnings("unchecked") final Graph<?, Node<?, ?>> g = m.unmarshall(null, this.getClass().getResourceAsStream("/DROOLS-2372.dmn"));
    final Stream<Node<?, ?>> stream = StreamSupport.stream(Spliterators.spliteratorUnknownSize(g.nodes().iterator(), Spliterator.ORDERED), false);
    final Optional<Decision> wbDecision = stream.filter(n -> n.getContent() instanceof ViewImpl).map(n -> (ViewImpl) n.getContent()).filter(n -> n.getDefinition() instanceof Decision).map(n -> (Decision) n.getDefinition()).findFirst();
    wbDecision.ifPresent(d -> {
        assertTrue(d.getExpression() instanceof FunctionDefinition);
        final FunctionDefinition wbFunction = (FunctionDefinition) d.getExpression();
        // This is what the WB expects
        assertTrue(wbFunction.getAdditionalAttributes().containsKey(FunctionDefinition.KIND_QNAME));
        assertEquals("J", wbFunction.getAdditionalAttributes().get(FunctionDefinition.KIND_QNAME));
    });
    final DMNRuntime runtime = roundTripUnmarshalMarshalThenUnmarshalDMN(this.getClass().getResourceAsStream("/DROOLS-2372.dmn"));
    final DMNModel dmnModel = runtime.getModels().get(0);
    final DecisionNode dmnDecision = dmnModel.getDecisions().iterator().next();
    assertTrue(dmnDecision.getDecision().getExpression() instanceof org.kie.dmn.model.v1_1.FunctionDefinition);
    final org.kie.dmn.model.v1_1.FunctionDefinition dmnFunction = (org.kie.dmn.model.v1_1.FunctionDefinition) dmnDecision.getDecision().getExpression();
    assertTrue(dmnFunction.getAdditionalAttributes().containsKey(org.kie.dmn.model.v1_1.FunctionDefinition.KIND_QNAME));
    assertEquals("J", dmnFunction.getAdditionalAttributes().get(org.kie.dmn.model.v1_1.FunctionDefinition.KIND_QNAME));
}
Also used : Arrays(java.util.Arrays) DefinitionUtils(org.kie.workbench.common.stunner.core.util.DefinitionUtils) AuthorityRequirement(org.kie.workbench.common.dmn.api.definition.v1_1.AuthorityRequirement) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNResult(org.kie.dmn.api.core.DMNResult) Spliterators(java.util.Spliterators) Edge(org.kie.workbench.common.stunner.core.graph.Edge) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) BackendDefinitionSetAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendDefinitionSetAdapter) EdgeFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.EdgeFactoryImpl) BigDecimal(java.math.BigDecimal) DMNModel(org.kie.dmn.api.core.DMNModel) Bounds(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.org.omg.spec.CMMN_20151109_DC.Bounds) DecisionEvaluationStatus(org.kie.dmn.api.core.DMNDecisionResult.DecisionEvaluationStatus) DMNDiagram(org.kie.workbench.common.dmn.api.definition.v1_1.DMNDiagram) Mockito.doAnswer(org.mockito.Mockito.doAnswer) GraphFactory(org.kie.workbench.common.stunner.core.factory.graph.GraphFactory) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) StringInputStream(org.apache.tools.ant.filters.StringInputStream) NodeFactory(org.kie.workbench.common.stunner.core.factory.graph.NodeFactory) InputData(org.kie.workbench.common.dmn.api.definition.v1_1.InputData) Collection(java.util.Collection) BackendPropertySetAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendPropertySetAdapter) Child(org.kie.workbench.common.stunner.core.graph.content.relationship.Child) EdgeFactory(org.kie.workbench.common.stunner.core.factory.graph.EdgeFactory) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Stream(java.util.stream.Stream) Definitions(org.kie.dmn.model.v1_1.Definitions) Context(org.kie.workbench.common.dmn.api.definition.v1_1.Context) DDExtensionsRegister(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DDExtensionsRegister) Assert.assertFalse(org.junit.Assert.assertFalse) DMNContext(org.kie.dmn.api.core.DMNContext) DMNMarshallerFactory(org.kie.dmn.backend.marshalling.v1_1.DMNMarshallerFactory) MetadataImpl(org.kie.workbench.common.stunner.core.diagram.MetadataImpl) Optional(java.util.Optional) MappingContextSingleton(org.jboss.errai.marshalling.server.MappingContextSingleton) KieHelper(org.kie.dmn.core.util.KieHelper) DMNShape(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape) Color(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.org.omg.spec.CMMN_20151109_DC.Color) Spliterator(java.util.Spliterator) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) Node(org.kie.workbench.common.stunner.core.graph.Node) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) DMNStyle(org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNStyle) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.v1_1.FunctionDefinition) Mock(org.mockito.Mock) GraphCommandManager(org.kie.workbench.common.stunner.core.graph.command.GraphCommandManager) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) GraphCommandManagerImpl(org.kie.workbench.common.stunner.core.graph.command.GraphCommandManagerImpl) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Matchers.anyString(org.mockito.Matchers.anyString) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) BackendDefinitionAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendDefinitionAdapter) KieServices(org.kie.api.KieServices) DiagramImpl(org.kie.workbench.common.stunner.core.diagram.DiagramImpl) StreamSupport(java.util.stream.StreamSupport) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) InformationRequirement(org.kie.workbench.common.dmn.api.definition.v1_1.InformationRequirement) GraphFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.GraphFactoryImpl) AdapterManager(org.kie.workbench.common.stunner.core.definition.adapter.AdapterManager) Before(org.junit.Before) BindableAdapterUtils(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils) NodeFactoryImpl(org.kie.workbench.common.stunner.core.factory.impl.NodeFactoryImpl) TextAnnotation(org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) Assert.assertNotNull(org.junit.Assert.assertNotNull) KieContainer(org.kie.api.runtime.KieContainer) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) AdapterRegistry(org.kie.workbench.common.stunner.core.registry.definition.AdapterRegistry) Mockito.when(org.mockito.Mockito.when) UUID(org.uberfire.commons.uuid.UUID) Association(org.kie.workbench.common.dmn.api.definition.v1_1.Association) TestScopeModelFactory(org.kie.workbench.common.stunner.backend.definition.factory.TestScopeModelFactory) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Consumer(java.util.function.Consumer) GraphCommandFactory(org.kie.workbench.common.stunner.core.graph.command.impl.GraphCommandFactory) Graph(org.kie.workbench.common.stunner.core.graph.Graph) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) BackendFactoryManager(org.kie.workbench.common.stunner.core.backend.BackendFactoryManager) KnowledgeRequirement(org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeRequirement) BackendPropertyAdapter(org.kie.workbench.common.stunner.core.backend.definition.adapter.reflect.BackendPropertyAdapter) ElementFactory(org.kie.workbench.common.stunner.core.factory.graph.ElementFactory) RuleManager(org.kie.workbench.common.stunner.core.rule.RuleManager) Assert(org.junit.Assert) BeanManager(javax.enterprise.inject.spi.BeanManager) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) Node(org.kie.workbench.common.stunner.core.graph.Node) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) DecisionNode(org.kie.dmn.api.core.ast.DecisionNode) Decision(org.kie.workbench.common.dmn.api.definition.v1_1.Decision) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) XMLEncoderDiagramMetadataMarshaller(org.kie.workbench.common.stunner.core.backend.service.XMLEncoderDiagramMetadataMarshaller) ViewImpl(org.kie.workbench.common.stunner.core.graph.content.view.ViewImpl) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.v1_1.FunctionDefinition) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Aggregations

Decision (org.kie.workbench.common.dmn.api.definition.v1_1.Decision)16 Edge (org.kie.workbench.common.stunner.core.graph.Edge)7 View (org.kie.workbench.common.stunner.core.graph.content.view.View)7 Before (org.junit.Before)6 InputData (org.kie.workbench.common.dmn.api.definition.v1_1.InputData)6 KnowledgeSource (org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource)6 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)6 List (java.util.List)5 Optional (java.util.Optional)5 Test (org.junit.Test)5 HasName (org.kie.workbench.common.dmn.api.definition.HasName)5 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel)5 Decision (org.kie.dmn.model.v1_1.Decision)4 TextAnnotation (org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation)4 DMNShape (org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape)4 Node (org.kie.workbench.common.stunner.core.graph.Node)4 InputStream (java.io.InputStream)3 Consumer (java.util.function.Consumer)3 DMNMessage (org.kie.dmn.api.core.DMNMessage)3 DMNType (org.kie.dmn.api.core.DMNType)3