Search in sources :

Example 1 with DiagramParsingException

use of org.kie.workbench.common.stunner.core.diagram.DiagramParsingException in project kie-wb-common by kiegroup.

the class DMNMarshallerService method unmarshall.

public void unmarshall(final Metadata metadata, final String xml, final ServiceCallback<Diagram> callback) {
    setOnDiagramLoad(callback);
    setMetadata(metadata);
    try {
        final DMN12UnmarshallCallback jsCallback = dmn12 -> {
            final JSITDefinitions definitions = Js.uncheckedCast(JsUtils.getUnwrappedElement(dmn12));
            dmnUnmarshaller.unmarshall(getMetadata(), definitions).then(graph -> {
                final String fileName = getMetadata().getPath().getFileName();
                onDiagramLoad(dmnDiagramFactory.build(fileName, getMetadata(), graph));
                return promises.resolve();
            });
        };
        MainJs.unmarshall(xml, "", jsCallback);
    } catch (final Exception e) {
        GWT.log(e.getMessage(), e);
        callback.onError(new ClientRuntimeError(new DiagramParsingException(getMetadata(), xml)));
    }
}
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) DMN12UnmarshallCallback(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.callbacks.DMN12UnmarshallCallback) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) DiagramParsingException(org.kie.workbench.common.stunner.core.diagram.DiagramParsingException) 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)

Example 2 with DiagramParsingException

use of org.kie.workbench.common.stunner.core.diagram.DiagramParsingException in project kie-wb-common by kiegroup.

the class AbstractVFSDiagramService method getDiagramByPath.

@SuppressWarnings("unchecked")
public D getDiagramByPath(final org.uberfire.backend.vfs.Path file) {
    if (accepts(file)) {
        DefinitionSetService services = getServiceByPath(file);
        if (null != services) {
            final String defSetId = getDefinitionSetId(services);
            final String name = parseFileName(file, services);
            final M metadata = (M) buildMetadataInstance(file, defSetId, name);
            metadata.setPath(file);
            // Parse and load the diagram raw data.
            final InputStream is = loadPath(file);
            try {
                final MarshallingResponse<Graph<DefinitionSet, ?>> marshallingResponse = services.getDiagramMarshaller().unmarshallWithValidation(MarshallingRequest.builder().metadata(metadata).input(is).mode(MarshallingRequest.Mode.AUTO).build());
                final Graph<DefinitionSet, ?> graph = Optional.ofNullable(marshallingResponse.getResult()).orElseThrow(() -> new RuntimeException(marshallingResponse.getMessages().toString()));
                final DiagramFactory<M, ?> factory = factoryManager.registry().getDiagramFactory(graph.getContent().getDefinition(), getMetadataType());
                return (D) factory.build(name, metadata, graph);
            } catch (Exception e) {
                LOG.error("Cannot unmarshall diagram for diagram's path [" + file + "]", e);
                final String xml = getIoService().readAllString(convertToNioPath(file));
                throw new DiagramParsingException(metadata, xml);
            }
        }
    }
    throw new UnsupportedOperationException("Diagram format not supported [" + file + "]");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DiagramParsingException(org.kie.workbench.common.stunner.core.diagram.DiagramParsingException) DefinitionSetService(org.kie.workbench.common.stunner.core.definition.service.DefinitionSetService) DiagramParsingException(org.kie.workbench.common.stunner.core.diagram.DiagramParsingException) IOException(org.uberfire.java.nio.IOException) FileAlreadyExistsException(org.uberfire.java.nio.file.FileAlreadyExistsException) Graph(org.kie.workbench.common.stunner.core.graph.Graph) DefinitionSet(org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)

Example 3 with DiagramParsingException

use of org.kie.workbench.common.stunner.core.diagram.DiagramParsingException in project kie-wb-common by kiegroup.

the class StunnerEditorTest method testHandleError.

@Test
@SuppressWarnings("all")
public void testHandleError() {
    Consumer<Throwable> exceptionConsumer = mock(Consumer.class);
    tested.setExceptionProcessor(exceptionConsumer);
    Consumer<DiagramParsingException> parsingExceptionConsumer = mock(Consumer.class);
    tested.setParsingExceptionProcessor(parsingExceptionConsumer);
    Throwable e = new Throwable("someErrorMessage");
    ClientRuntimeError error = new ClientRuntimeError(e);
    tested.handleError(error);
    verify(xmlEditorViews, never()).get();
    verify(xmlEditorView, never()).setReadOnly(anyBoolean());
    verify(xmlEditorView, never()).setContent(any(), any());
    verify(view, never()).setWidget(eq(xmlEditorViewWidget));
    verify(errorPopupPresenter, times(1)).showMessage(anyString());
    verify(parsingExceptionConsumer, never()).accept(any());
    verify(exceptionConsumer, times(1)).accept(eq(e));
}
Also used : DiagramParsingException(org.kie.workbench.common.stunner.core.diagram.DiagramParsingException) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) Test(org.junit.Test)

Example 4 with DiagramParsingException

use of org.kie.workbench.common.stunner.core.diagram.DiagramParsingException in project kie-wb-common by kiegroup.

the class AbstractProjectDiagramEditorTest method testLoadContentWithInvalidFile.

@Test
@SuppressWarnings("unchecked")
public void testLoadContentWithInvalidFile() {
    tested.doStartUp(mock(ObservablePath.class), mock(PlaceRequest.class));
    doAnswer(invocation -> {
        ProjectMetadata metadata = mock(ProjectMetadata.class);
        when(metadata.getTitle()).thenReturn("someXmlTitle");
        when(metadata.getOverview()).thenReturn(overview);
        DiagramParsingException dpe = new DiagramParsingException(metadata, "someXml");
        parsingExceptionProcessor.accept(dpe);
        ((Viewer.Callback) invocation.getArguments()[1]).onError(new ClientRuntimeError(dpe));
        return null;
    }).when(stunnerEditor).open(eq(diagram), Mockito.<SessionPresenter.SessionPresenterCallback>any());
    tested.open(diagram);
    verify(view).hideBusyIndicator();
    verify(overviewWidget).setContent(eq(overview), eq(filePath));
    verify(changeTitleNotification).fire(any());
    verify(notification).fire(any());
    verify(kieView).clear();
    verify(kieView).addMainEditorPage(eq(view));
    verify(kieView).addOverviewPage(eq(overviewWidget), Mockito.<com.google.gwt.user.client.Command>any());
    verify(menuSessionItems).setEnabled(eq(false));
}
Also used : PlaceRequest(org.uberfire.mvp.PlaceRequest) ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) ProjectMetadata(org.kie.workbench.common.stunner.project.diagram.ProjectMetadata) DiagramParsingException(org.kie.workbench.common.stunner.core.diagram.DiagramParsingException) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) ObservablePath(org.uberfire.backend.vfs.ObservablePath) SessionPresenter(org.kie.workbench.common.stunner.client.widgets.presenters.session.SessionPresenter) Test(org.junit.Test)

Example 5 with DiagramParsingException

use of org.kie.workbench.common.stunner.core.diagram.DiagramParsingException in project kie-wb-common by kiegroup.

the class StunnerEditor method handleError.

public void handleError(final ClientRuntimeError error) {
    final Throwable e = error.getThrowable();
    if (e instanceof DiagramParsingException) {
        final DiagramParsingException dpe = (DiagramParsingException) e;
        close();
        parsingExceptionProcessor.accept(dpe);
        xmlEditorView = xmlEditorViews.get();
        xmlEditorView.setReadOnly(isReadOnly());
        xmlEditorView.setContent(dpe.getXml(), AceEditorMode.XML);
        resetContentHash();
        view.setWidget(xmlEditorView.asWidget());
        Scheduler.get().scheduleDeferred(xmlEditorView::onResize);
    } else {
        String message = null;
        if (e instanceof DefinitionNotFoundException) {
            final DefinitionNotFoundException dnfe = (DefinitionNotFoundException) e;
            message = translationService.getValue(CoreTranslationMessages.DIAGRAM_LOAD_FAIL_UNSUPPORTED_ELEMENTS, dnfe.getDefinitionId());
        } else {
            message = error.getThrowable() != null ? error.getThrowable().getMessage() : error.getMessage();
        }
        showError(message);
        exceptionProcessor.accept(error.getThrowable());
    }
}
Also used : DefinitionNotFoundException(org.kie.workbench.common.stunner.core.definition.exception.DefinitionNotFoundException) DiagramParsingException(org.kie.workbench.common.stunner.core.diagram.DiagramParsingException)

Aggregations

DiagramParsingException (org.kie.workbench.common.stunner.core.diagram.DiagramParsingException)7 Test (org.junit.Test)4 ClientRuntimeError (org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError)4 ServiceCallback (org.kie.workbench.common.stunner.core.client.service.ServiceCallback)2 Graph (org.kie.workbench.common.stunner.core.graph.Graph)2 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 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)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