Search in sources :

Example 1 with DefinitionNotFoundException

use of org.kie.workbench.common.stunner.core.definition.exception.DefinitionNotFoundException in project kie-wb-common by kiegroup.

the class ProjectDiagramEditorTest method testLoadContentError.

@Test
public void testLoadContentError() {
    ArgumentCaptor<ServiceCallback> callbackArgumentCaptor = forClass(ServiceCallback.class);
    tested.loadContent();
    verify(projectDiagramServices, times(1)).getByPath(eq(path), callbackArgumentCaptor.capture());
    callbackArgumentCaptor.getValue().onError(new ClientRuntimeError(new DefinitionNotFoundException()));
    verify(placeManager, times(1)).forceClosePlace(any(PathPlaceRequest.class));
    ArgumentCaptor<Consumer> consumerArgumentCaptor = forClass(Consumer.class);
    verify(diagramClientErrorHandler, times(1)).handleError(any(ClientRuntimeError.class), consumerArgumentCaptor.capture());
    consumerArgumentCaptor.getValue().accept("error message");
    verify(errorPopupPresenter, times(1)).showMessage("error message");
}
Also used : ServiceCallback(org.kie.workbench.common.stunner.core.client.service.ServiceCallback) Consumer(java.util.function.Consumer) DefinitionNotFoundException(org.kie.workbench.common.stunner.core.definition.exception.DefinitionNotFoundException) PathPlaceRequest(org.uberfire.mvp.impl.PathPlaceRequest) ClientRuntimeError(org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError) Test(org.junit.Test)

Example 2 with DefinitionNotFoundException

use of org.kie.workbench.common.stunner.core.definition.exception.DefinitionNotFoundException in project kie-wb-common by kiegroup.

the class DiagramClientErrorHandlerTest method handleErrorTest.

@Test
public void handleErrorTest() {
    reset(clientRuntimeError);
    when(clientRuntimeError.getThrowable()).thenReturn(new DefinitionNotFoundException("Error", DEFINITION_ID));
    diagramClientErrorHandler.handleError(clientRuntimeError, message -> Assert.assertEquals(ERROR_MESSAGE, message));
    when(clientRuntimeError.getThrowable()).thenReturn(new RuntimeException());
    when(clientRuntimeError.toString()).thenReturn("runtime");
    diagramClientErrorHandler.handleError(clientRuntimeError, message -> Assert.assertEquals("runtime", message));
}
Also used : DefinitionNotFoundException(org.kie.workbench.common.stunner.core.definition.exception.DefinitionNotFoundException) Test(org.junit.Test)

Example 3 with DefinitionNotFoundException

use of org.kie.workbench.common.stunner.core.definition.exception.DefinitionNotFoundException in project kie-wb-common by kiegroup.

the class BPMNGraphObjectBuilderFactory method builderFor.

@Override
@SuppressWarnings("all")
public GraphObjectBuilder<?, ?> builderFor(final String oryxId) {
    if (oryxId == null) {
        throw new NullPointerException();
    }
    final Class<?> defClass = oryxManager.getMappingsManager().getDefinition(oryxId);
    if (null != defClass) {
        final String defId = oryxManager.getMappingsManager().getDefinitionId(oryxId);
        if (ServiceTask.class.equals(defClass)) {
            return new ServiceTaskNodeBuilder(defId, workItemDefinitionRegistries);
        }
        MorphAdapter<Object> morphAdapter = definitionManager.adapters().registry().getMorphAdapter(defClass);
        BindablePropertyMorphDefinition propertyMorphDefinition = null;
        if (null != morphAdapter) {
            final Iterable<MorphDefinition> morphDefinitions = ((BindableMorphAdapter<Object>) morphAdapter).getMorphDefinitionsForType(defClass);
            if (null != morphDefinitions && morphDefinitions.iterator().hasNext()) {
                for (MorphDefinition morphDefinition : morphDefinitions) {
                    if (morphDefinition instanceof BindablePropertyMorphDefinition) {
                        propertyMorphDefinition = (BindablePropertyMorphDefinition) morphDefinition;
                        break;
                    }
                }
            }
        }
        if (null != propertyMorphDefinition) {
            // Specific handle for morphing based on class inheritance.
            return new NodePropertyMorphBuilderImpl(defClass, propertyMorphDefinition);
        } else {
            Class<? extends ElementFactory> elementFactory = BackendDefinitionAdapter.getGraphFactory(defClass);
            if (isNodeFactory(elementFactory)) {
                return new NodeBuilderImpl(defClass, defId);
            } else if (isEdgeFactory(elementFactory)) {
                return new EdgeBuilderImpl(defClass);
            } else {
                throw new RuntimeException("No graph element found for definition with class [" + defClass.getName() + "]");
            }
        }
    }
    throw new DefinitionNotFoundException("No definition found for oryx stencil with id [" + oryxId + "]", oryxId);
}
Also used : BindablePropertyMorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.BindablePropertyMorphDefinition) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) BindablePropertyMorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.BindablePropertyMorphDefinition) BindableMorphAdapter(org.kie.workbench.common.stunner.core.definition.adapter.BindableMorphAdapter) DefinitionNotFoundException(org.kie.workbench.common.stunner.core.definition.exception.DefinitionNotFoundException)

Example 4 with DefinitionNotFoundException

use of org.kie.workbench.common.stunner.core.definition.exception.DefinitionNotFoundException 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

DefinitionNotFoundException (org.kie.workbench.common.stunner.core.definition.exception.DefinitionNotFoundException)4 Test (org.junit.Test)2 Consumer (java.util.function.Consumer)1 ClientRuntimeError (org.kie.workbench.common.stunner.core.client.service.ClientRuntimeError)1 ServiceCallback (org.kie.workbench.common.stunner.core.client.service.ServiceCallback)1 BindableMorphAdapter (org.kie.workbench.common.stunner.core.definition.adapter.BindableMorphAdapter)1 BindablePropertyMorphDefinition (org.kie.workbench.common.stunner.core.definition.morph.BindablePropertyMorphDefinition)1 MorphDefinition (org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition)1 DiagramParsingException (org.kie.workbench.common.stunner.core.diagram.DiagramParsingException)1 PathPlaceRequest (org.uberfire.mvp.impl.PathPlaceRequest)1