Search in sources :

Example 1 with DMN12MarshallCallback

use of org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.callbacks.DMN12MarshallCallback in project kie-wb-common by kiegroup.

the class DMNMarshallerService method marshall.

public void marshall(final Diagram diagram, final ServiceCallback<String> contentServiceCallback) {
    final DMN12MarshallCallback jsCallback = result -> {
        final String xml;
        final String prefix = "<?xml version=\"1.0\" ?>";
        if (result.startsWith(prefix)) {
            xml = result;
        } else {
            xml = prefix + result;
        }
        contentServiceCallback.onSuccess(xml);
    };
    if (Objects.isNull(diagram)) {
        contentServiceCallback.onError(new ClientRuntimeError("The Diagram cannot be null."));
        return;
    }
    final Graph graph = diagram.getGraph();
    if (Objects.isNull(graph)) {
        contentServiceCallback.onError(new ClientRuntimeError("The Diagram graph cannot be null."));
        return;
    }
    try {
        final JSITDefinitions jsitDefinitions = dmnMarshaller.marshall();
        final DMN12 dmn12 = Js.uncheckedCast(JsUtils.newWrappedInstance());
        JsUtils.setNameOnWrapped(dmn12, makeJSINameForDMN12());
        JsUtils.setValueOnWrapped(dmn12, jsitDefinitions);
        final JavaScriptObject namespaces = createNamespaces(jsitDefinitions.getOtherAttributes(), jsitDefinitions.getNamespace());
        MainJs.marshall(dmn12, namespaces, jsCallback);
    } catch (final Exception e) {
        contentServiceCallback.onError(new ClientRuntimeError("Error during the marshaller: " + e.getMessage()));
    }
}
Also used : DMNDefinitionSet(org.kie.workbench.common.dmn.api.DMNDefinitionSet) Promises(org.uberfire.client.promise.Promises) HashMap(java.util.HashMap) GWT(com.google.gwt.core.client.GWT) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Inject(javax.inject.Inject) DMN12UnmarshallCallback(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.callbacks.DMN12UnmarshallCallback) PathFactory(org.uberfire.backend.vfs.PathFactory) Js(jsinterop.base.Js) JSIName(org.kie.workbench.common.dmn.webapp.kogito.marshaller.mapper.JSIName) Map(java.util.Map) Observes(javax.enterprise.event.Observes) DMNShapeSet(org.kie.workbench.common.dmn.client.DMNShapeSet) DefinitionManager(org.kie.workbench.common.stunner.core.api.DefinitionManager) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) Diagram(org.kie.workbench.common.stunner.core.diagram.Diagram) Path(org.uberfire.backend.vfs.Path) BindableAdapterUtils(org.kie.workbench.common.stunner.core.definition.adapter.binding.BindableAdapterUtils) MainJs(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.MainJs) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) DiagramParsingException(org.kie.workbench.common.stunner.core.diagram.DiagramParsingException) JSONString(com.google.gwt.json.client.JSONString) DMNDiagram(org.kie.workbench.common.dmn.api.definition.model.DMNDiagram) WorkspaceProjectContext(org.guvnor.common.services.project.client.context.WorkspaceProjectContext) DMNUnmarshaller(org.kie.workbench.common.dmn.client.marshaller.unmarshall.DMNUnmarshaller) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) Objects(java.util.Objects) DMNDiagramFactory(org.kie.workbench.common.dmn.api.factory.DMNDiagramFactory) DMN12(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.DMN12) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DMNDiagramsSession(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramsSession) JsUtils(org.kie.workbench.common.dmn.webapp.kogito.marshaller.mapper.JsUtils) Dependent(javax.enterprise.context.Dependent) DMNGraphUtils(org.kie.workbench.common.dmn.client.marshaller.common.DMNGraphUtils) DMNMarshaller(org.kie.workbench.common.dmn.client.marshaller.marshall.DMNMarshaller) MetadataImpl(org.kie.workbench.common.stunner.core.diagram.MetadataImpl) DRGDiagramUtils(org.kie.workbench.common.dmn.client.docks.navigator.drds.DRGDiagramUtils) QName(javax.xml.namespace.QName) JSONObject(com.google.gwt.json.client.JSONObject) DMNDiagramSelected(org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramSelected) StringUtils(org.kie.workbench.common.stunner.core.util.StringUtils) DMNDiagramElement(org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement) DMN12MarshallCallback(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.callbacks.DMN12MarshallCallback) Node(org.kie.workbench.common.stunner.core.graph.Node) DMN12MarshallCallback(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.callbacks.DMN12MarshallCallback) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DMN12(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.DMN12) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) JSONString(com.google.gwt.json.client.JSONString) DiagramParsingException(org.kie.workbench.common.stunner.core.diagram.DiagramParsingException) JSITDefinitions(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITDefinitions)

Aggregations

GWT (com.google.gwt.core.client.GWT)1 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 JSONObject (com.google.gwt.json.client.JSONObject)1 JSONString (com.google.gwt.json.client.JSONString)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Dependent (javax.enterprise.context.Dependent)1 Observes (javax.enterprise.event.Observes)1 Inject (javax.inject.Inject)1 QName (javax.xml.namespace.QName)1 Js (jsinterop.base.Js)1 WorkspaceProjectContext (org.guvnor.common.services.project.client.context.WorkspaceProjectContext)1 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)1 DMNDefinitionSet (org.kie.workbench.common.dmn.api.DMNDefinitionSet)1 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)1 DMNDiagramElement (org.kie.workbench.common.dmn.api.definition.model.DMNDiagramElement)1 DMNDiagramFactory (org.kie.workbench.common.dmn.api.factory.DMNDiagramFactory)1 DMNShapeSet (org.kie.workbench.common.dmn.client.DMNShapeSet)1 DMNDiagramSelected (org.kie.workbench.common.dmn.client.docks.navigator.drds.DMNDiagramSelected)1