Search in sources :

Example 6 with KnowledgeSource

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

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

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

the class KnowledgeSourceConverter method nodeFromDMN.

@Override
public Node<View<KnowledgeSource>, ?> nodeFromDMN(final org.kie.dmn.model.v1_1.KnowledgeSource dmn) {
    @SuppressWarnings("unchecked") Node<View<KnowledgeSource>, ?> node = (Node<View<KnowledgeSource>, ?>) factoryManager.newElement(dmn.getId(), KnowledgeSource.class).asNode();
    Id id = new Id(dmn.getId());
    Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    Name name = new Name(dmn.getName());
    KnowledgeSourceType ksType = new KnowledgeSourceType(dmn.getType());
    LocationURI locationURI = new LocationURI(dmn.getLocationURI());
    KnowledgeSource ks = new KnowledgeSource(id, description, name, ksType, locationURI, new BackgroundSet(), new FontSet(), new RectangleDimensionsSet());
    node.getContent().setDefinition(ks);
    return node;
}
Also used : LocationURI(org.kie.workbench.common.dmn.api.property.dmn.LocationURI) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) KnowledgeSourceType(org.kie.workbench.common.dmn.api.property.dmn.KnowledgeSourceType) Node(org.kie.workbench.common.stunner.core.graph.Node) RectangleDimensionsSet(org.kie.workbench.common.dmn.api.property.dimensions.RectangleDimensionsSet) View(org.kie.workbench.common.stunner.core.graph.content.view.View) 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) KnowledgeSource(org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource) Id(org.kie.workbench.common.dmn.api.property.dmn.Id)

Example 9 with KnowledgeSource

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

the class DMNMarshallerTest method checkAssociationsGraph.

private void checkAssociationsGraph(Graph<?, Node<?, ?>> g) {
    Node<?, ?> inputData = g.getNode("BD168F8B-4398-4478-8BEA-E67AA5F90FAF");
    assertNodeContentDefinitionIs(inputData, InputData.class);
    Node<?, ?> decision = g.getNode("A960E2D2-FBC1-4D11-AA33-064F6A0B5CB9");
    assertNodeContentDefinitionIs(decision, Decision.class);
    Node<?, ?> knowledgeSource = g.getNode("FB99ED65-BC43-4750-999F-7FE24690845B");
    assertNodeContentDefinitionIs(knowledgeSource, KnowledgeSource.class);
    Node<?, ?> bkm = g.getNode("2F07453C-854F-436F-8378-4CFCE63BB124");
    assertNodeContentDefinitionIs(bkm, BusinessKnowledgeModel.class);
    Node<?, ?> textAnnotation = g.getNode("7F4B8130-6F3D-4A16-9F6C-01D01DA481D2");
    assertNodeContentDefinitionIs(textAnnotation, TextAnnotation.class);
    Edge fromInput = assertNodeEdgesTo(inputData, textAnnotation, Association.class);
    assertEquals("From Input", ((View<Association>) fromInput.getContent()).getDefinition().getDescription().getValue());
    Edge fromDecision = assertNodeEdgesTo(decision, textAnnotation, Association.class);
    assertEquals("From Decision", ((View<Association>) fromDecision.getContent()).getDefinition().getDescription().getValue());
    Edge fromBkm = assertNodeEdgesTo(bkm, textAnnotation, Association.class);
    assertEquals("From BKM", ((View<Association>) fromBkm.getContent()).getDefinition().getDescription().getValue());
    Edge fromKnowledgeSource = assertNodeEdgesTo(knowledgeSource, textAnnotation, Association.class);
    assertEquals("From Knowledge Source", ((View<Association>) fromKnowledgeSource.getContent()).getDefinition().getDescription().getValue());
}
Also used : Association(org.kie.workbench.common.dmn.api.definition.v1_1.Association) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 10 with KnowledgeSource

use of org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource in project drools by kiegroup.

the class KnowledgeSourceConverter method assignAttributes.

@Override
protected void assignAttributes(HierarchicalStreamReader reader, Object parent) {
    super.assignAttributes(reader, parent);
    KnowledgeSource ks = (KnowledgeSource) parent;
    String locationUri = reader.getAttribute(LOCATION_URI);
    ks.setLocationURI(locationUri);
}
Also used : KnowledgeSource(org.kie.dmn.model.v1_1.KnowledgeSource)

Aggregations

KnowledgeSource (org.kie.workbench.common.dmn.api.definition.v1_1.KnowledgeSource)7 View (org.kie.workbench.common.stunner.core.graph.content.view.View)6 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.v1_1.BusinessKnowledgeModel)5 Decision (org.kie.workbench.common.dmn.api.definition.v1_1.Decision)5 InputData (org.kie.workbench.common.dmn.api.definition.v1_1.InputData)5 Edge (org.kie.workbench.common.stunner.core.graph.Edge)5 List (java.util.List)4 DRGElement (org.kie.workbench.common.dmn.api.definition.v1_1.DRGElement)4 KnowledgeSource (org.kie.dmn.model.v1_1.KnowledgeSource)3 TextAnnotation (org.kie.workbench.common.dmn.api.definition.v1_1.TextAnnotation)3 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)3 DMNShape (org.kie.workbench.common.dmn.backend.definition.v1_1.dd.DMNShape)3 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Association (org.kie.workbench.common.dmn.api.definition.v1_1.Association)2 BackgroundSet (org.kie.workbench.common.dmn.api.property.background.BackgroundSet)2 RectangleDimensionsSet (org.kie.workbench.common.dmn.api.property.dimensions.RectangleDimensionsSet)2 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)2 FontSet (org.kie.workbench.common.dmn.api.property.font.FontSet)2 Bounds (org.kie.workbench.common.dmn.backend.definition.v1_1.dd.org.omg.spec.CMMN_20151109_DC.Bounds)2 Node (org.kie.workbench.common.stunner.core.graph.Node)2