Search in sources :

Example 6 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)

Example 7 with DiagramParsingException

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

the class StunnerEditorTest method testHandleParsingError.

@Test
@SuppressWarnings("all")
public void testHandleParsingError() {
    Consumer<Throwable> exceptionConsumer = mock(Consumer.class);
    tested.setExceptionProcessor(exceptionConsumer);
    Consumer<DiagramParsingException> parsingExceptionConsumer = mock(Consumer.class);
    tested.setParsingExceptionProcessor(parsingExceptionConsumer);
    when(xmlEditorView.getContent()).thenReturn("testXml");
    DiagramParsingException dpe = new DiagramParsingException(mock(Metadata.class), "testXml");
    ClientRuntimeError error = new ClientRuntimeError(dpe);
    tested.handleError(error);
    verify(xmlEditorViews, times(1)).get();
    verify(xmlEditorView, times(1)).setReadOnly(eq(false));
    verify(xmlEditorView, times(1)).setContent(eq("testXml"), eq(AceEditorMode.XML));
    verify(view, times(1)).setWidget(eq(xmlEditorViewWidget));
    verify(errorPopupPresenter, never()).showMessage(anyString());
    assertEquals("testXml".hashCode(), tested.getCurrentContentHash());
    verify(parsingExceptionConsumer, times(1)).accept(eq(dpe));
    verify(exceptionConsumer, never()).accept(any());
}
Also used : DiagramParsingException(org.kie.workbench.common.stunner.core.diagram.DiagramParsingException) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) Test(org.junit.Test)

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