Search in sources :

Example 1 with Definitions

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

the class DMNCompilerImpl method compile.

@Override
public DMNModel compile(Reader source, Collection<DMNModel> dmnModels) {
    try {
        Definitions dmndefs = getMarshaller().unmarshal(source);
        DMNModel model = compile(dmndefs, dmnModels);
        return model;
    } catch (Exception e) {
        logger.error("Error compiling model from source.", e);
    }
    return null;
}
Also used : Definitions(org.kie.dmn.model.v1_1.Definitions) DMNModel(org.kie.dmn.api.core.DMNModel) IOException(java.io.IOException)

Example 2 with Definitions

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

the class DMNValidatorImpl method validate.

@Override
public List<DMNMessage> validate(Reader reader, Validation... options) {
    DMNMessageManager results = new DefaultDMNMessagesManager();
    EnumSet<Validation> flags = EnumSet.copyOf(Arrays.asList(options));
    try {
        String content = readContent(reader);
        if (flags.contains(VALIDATE_SCHEMA)) {
            results.addAll(validateSchema(new StringReader(content)));
        }
        if (flags.contains(VALIDATE_MODEL) || flags.contains(VALIDATE_COMPILATION)) {
            Definitions dmndefs = DMNMarshallerFactory.newDefaultMarshaller().unmarshal(new StringReader(content));
            Definitions.normalize(dmndefs);
            validateModelCompilation(dmndefs, results, flags);
        }
    } catch (Throwable t) {
        MsgUtil.reportMessage(LOG, DMNMessage.Severity.ERROR, null, results, t, null, Msg.FAILED_VALIDATOR);
    }
    return results.getMessages();
}
Also used : DMNMessageManager(org.kie.dmn.core.api.DMNMessageManager) Definitions(org.kie.dmn.model.v1_1.Definitions) StringReader(java.io.StringReader) DefaultDMNMessagesManager(org.kie.dmn.core.util.DefaultDMNMessagesManager)

Example 3 with Definitions

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

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

the class DefinitionsConverter method wbFromDMN.

public static Definitions wbFromDMN(final org.kie.dmn.model.v1_1.Definitions dmn) {
    if (dmn == null) {
        return null;
    }
    Id id = new Id(dmn.getId());
    Name name = new Name(dmn.getName());
    String namespace = dmn.getNamespace();
    Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    Definitions result = new Definitions();
    result.setId(id);
    result.setName(name);
    result.setNamespace(namespace);
    result.setDescription(description);
    result.getNsContext().putAll(dmn.getNsContext());
    for (org.kie.dmn.model.v1_1.ItemDefinition itemDef : dmn.getItemDefinition()) {
        ItemDefinition itemDefConvered = ItemDefinitionPropertyConverter.wbFromDMN(itemDef);
        result.getItemDefinition().add(itemDefConvered);
    }
    return result;
}
Also used : Description(org.kie.workbench.common.dmn.api.property.dmn.Description) Definitions(org.kie.workbench.common.dmn.api.definition.v1_1.Definitions) ItemDefinition(org.kie.workbench.common.dmn.api.definition.v1_1.ItemDefinition) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Example 5 with Definitions

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

the class BPMNDirectDiagramMarshaller method marshall.

@Override
@SuppressWarnings("unchecked")
public String marshall(final Diagram<Graph, Metadata> diagram) throws IOException {
    LOG.debug("Starting diagram marshalling...");
    Bpmn2Resource resource = createBpmn2Resource();
    // we start converting from the root, then pull out the result
    DefinitionsConverter definitionsConverter = new DefinitionsConverter(diagram.getGraph());
    Definitions definitions = definitionsConverter.toDefinitions();
    resource.getContents().add(definitions);
    LOG.debug("Diagram marshalling completed successfully.");
    String outputString = renderToString(resource);
    LOG.trace(outputString);
    return outputString;
}
Also used : Bpmn2Resource(org.eclipse.bpmn2.util.Bpmn2Resource) Definitions(org.eclipse.bpmn2.Definitions) DefinitionsConverter(org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter)

Aggregations

Definitions (org.eclipse.bpmn2.Definitions)42 Process (org.eclipse.bpmn2.Process)16 Test (org.junit.Test)15 Graph (org.kie.workbench.common.stunner.core.graph.Graph)12 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)11 Before (org.junit.Before)9 IOException (java.io.IOException)8 List (java.util.List)8 DefinitionsConverter (org.kie.workbench.common.stunner.bpmn.backend.converters.fromstunner.DefinitionsConverter)8 RootElement (org.eclipse.bpmn2.RootElement)7 BPMNDiagram (org.eclipse.bpmn2.di.BPMNDiagram)6 BusinessProcessFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.process.BusinessProcessFormModel)6 DefinitionResolver (org.kie.workbench.common.stunner.bpmn.backend.converters.tostunner.DefinitionResolver)6 HashMap (java.util.HashMap)5 Optional (java.util.Optional)5 DataInput (org.eclipse.bpmn2.DataInput)5 XMLResource (org.eclipse.emf.ecore.xmi.XMLResource)5 Definitions (org.kie.dmn.model.v1_1.Definitions)5 TaskFormModel (org.kie.workbench.common.forms.jbpm.model.authoring.task.TaskFormModel)5 Path (org.uberfire.backend.vfs.Path)5