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)));
}
}
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 + "]");
}
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));
}
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));
}
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());
}
}
Aggregations