@Test @SuppressWarnings("unchecked") public void testGetDiagramByPathParseException() throws IOException { final String processDefinition = "broken DEFINITION"; final Path path = mockGetDiagramByPathObjects(); when(ioService.readAllString(Paths.convert(path))).thenReturn(processDefinition); try { Mockito.when(diagramMarshaller.unmarshallWithValidation(anyObject())) .thenReturn(MarshallingResponse.builder() .state(MarshallingResponse.State.ERROR) .addMessage(MarshallingMessage.builder().message("error").build()) .build()); diagramService.getDiagramByPath(path); } catch (DiagramParsingException dpe) { assertEquals(processDefinition, dpe.getXml()); assertNotNull(dpe.getMetadata()); } catch (Exception e) { fail("Exception should have been caught and wrapped as DiagramParsingException"); } }
@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); 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(Paths.convert(file)); throw new DiagramParsingException(metadata, xml); } } } throw new UnsupportedOperationException("Diagram format not supported [" + file + "]"); }
AbstractVFSDiagramService implements BaseDiagramService<M, D> { @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); 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(Paths.convert(file)); throw new DiagramParsingException(metadata, xml); } } } throw new UnsupportedOperationException("Diagram format not supported [" + file + "]"); } }
AbstractVFSDiagramService implements BaseDiagramService<M, D> { @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); 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(Paths.convert(file)); throw new DiagramParsingException(metadata, xml); } } } throw new UnsupportedOperationException("Diagram format not supported [" + file + "]"); } AbstractVFSDiagramService(final DefinitionManager definitionManager,
                                     final FactoryManager factoryManager,
                                     final Instance<DefinitionSetService> definitionSetServiceInstances,
                                     final BackendRegistryFactory registryFactory,
                                     final User identity); }
AbstractVFSDiagramService implements BaseDiagramService<M, D> { @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); 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(Paths.convert(file)); throw new DiagramParsingException(metadata, xml); } } } throw new UnsupportedOperationException("Diagram format not supported [" + file + "]"); } AbstractVFSDiagramService(final DefinitionManager definitionManager,
                                     final FactoryManager factoryManager,
                                     final Instance<DefinitionSetService> definitionSetServiceInstances,
                                     final BackendRegistryFactory registryFactory,
                                     final User identity); Path create(final Path path,
                       final String name,
                       final String defSetId,
                       final Metadata metadata); @Override String getRawContent(D diagram); @SuppressWarnings("unchecked") D getDiagramByPath(final org.uberfire.backend.vfs.Path file); M saveOrUpdate(final D diagram); @Override Path saveOrUpdateSvg(Path diagramPath, String rawDiagramSvg); boolean delete(final D diagram); boolean contains(final D item); Collection<D> getDiagramsByPath(final org.uberfire.java.nio.file.Path root); boolean accepts(final org.uberfire.backend.vfs.Path path); }
AbstractVFSDiagramService implements BaseDiagramService<M, D> { @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); 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(Paths.convert(file)); throw new DiagramParsingException(metadata, xml); } } } throw new UnsupportedOperationException("Diagram format not supported [" + file + "]"); } AbstractVFSDiagramService(final DefinitionManager definitionManager,
                                     final FactoryManager factoryManager,
                                     final Instance<DefinitionSetService> definitionSetServiceInstances,
                                     final BackendRegistryFactory registryFactory,
                                     final User identity); Path create(final Path path,
                       final String name,
                       final String defSetId,
                       final Metadata metadata); @Override String getRawContent(D diagram); @SuppressWarnings("unchecked") D getDiagramByPath(final org.uberfire.backend.vfs.Path file); M saveOrUpdate(final D diagram); @Override Path saveOrUpdateSvg(Path diagramPath, String rawDiagramSvg); boolean delete(final D diagram); boolean contains(final D item); Collection<D> getDiagramsByPath(final org.uberfire.java.nio.file.Path root); boolean accepts(final org.uberfire.backend.vfs.Path path); static final String SVG_SUFFIX; }