@Test public void testCreate() throws IOException { Path path = mock(Path.class); when(path.toURI()).thenReturn(DIR_URI); final org.uberfire.java.nio.file.Path expectedNioPath = Paths.convert(path).resolve(FILE_NAME_IN_RESOURCE_FORMAT); when(factoryManager.newDiagram(FILE_NAME, DEFINITION_SET_ID, metadata)).thenReturn(diagram); diagramService.create(path, FILE_NAME, DEFINITION_SET_ID, metadata); verify(ioService, times(1)).write(eq(expectedNioPath), eq(DIAGRAM_MARSHALLED), any(CommentedOption.class)); }
public Path create(final Path path, final String name, final String defSetId, final Metadata metadata) { final DefinitionSetService services = getServiceById(defSetId); if (null == services) { throw new IllegalStateException("No backend Definition Set services for [" + defSetId + "]"); } final String fName = buildFileName(name, services.getResourceType()); final org.uberfire.java.nio.file.Path kiePath = Paths.convert(path).resolve(fName); if (getIoService().exists(kiePath)) { throw new FileAlreadyExistsException(kiePath.toString()); } try { final D diagram = factoryManager.newDiagram(name, defSetId, metadata); final String[] raw = serialize(diagram); getIoService().write(kiePath, raw[0], new CommentedOption(identity.getIdentifier())); return Paths.convert(kiePath); } catch (final Exception e) { LOG.error("Cannot create diagram in path [" + kiePath + "]", e); } return null; }
AbstractVFSDiagramService implements BaseDiagramService<M, D> { public Path create(final Path path, final String name, final String defSetId, final Metadata metadata) { final DefinitionSetService services = getServiceById(defSetId); if (null == services) { throw new IllegalStateException("No backend Definition Set services for [" + defSetId + "]"); } final String fName = buildFileName(name, services.getResourceType()); final org.uberfire.java.nio.file.Path kiePath = Paths.convert(path).resolve(fName); if (getIoService().exists(kiePath)) { throw new FileAlreadyExistsException(kiePath.toString()); } try { final D diagram = factoryManager.newDiagram(name, defSetId, metadata); final String[] raw = serialize(diagram); getIoService().write(kiePath, raw[0], new CommentedOption(identity.getIdentifier())); return Paths.convert(kiePath); } catch (final Exception e) { LOG.error("Cannot create diagram in path [" + kiePath + "]", e); } return null; } }
AbstractVFSDiagramService implements BaseDiagramService<M, D> { public Path create(final Path path, final String name, final String defSetId, final Metadata metadata) { final DefinitionSetService services = getServiceById(defSetId); if (null == services) { throw new IllegalStateException("No backend Definition Set services for [" + defSetId + "]"); } final String fName = buildFileName(name, services.getResourceType()); final org.uberfire.java.nio.file.Path kiePath = Paths.convert(path).resolve(fName); if (getIoService().exists(kiePath)) { throw new FileAlreadyExistsException(kiePath.toString()); } try { final D diagram = factoryManager.newDiagram(name, defSetId, metadata); final String[] raw = serialize(diagram); getIoService().write(kiePath, raw[0], new CommentedOption(identity.getIdentifier())); return Paths.convert(kiePath); } catch (final Exception e) { LOG.error("Cannot create diagram in path [" + kiePath + "]", e); } return null; } AbstractVFSDiagramService(final DefinitionManager definitionManager,
                                     final FactoryManager factoryManager,
                                     final Instance<DefinitionSetService> definitionSetServiceInstances,
                                     final BackendRegistryFactory registryFactory,
                                     final User identity); }
AbstractVFSDiagramService implements BaseDiagramService<M, D> { public Path create(final Path path, final String name, final String defSetId, final Metadata metadata) { final DefinitionSetService services = getServiceById(defSetId); if (null == services) { throw new IllegalStateException("No backend Definition Set services for [" + defSetId + "]"); } final String fName = buildFileName(name, services.getResourceType()); final org.uberfire.java.nio.file.Path kiePath = Paths.convert(path).resolve(fName); if (getIoService().exists(kiePath)) { throw new FileAlreadyExistsException(kiePath.toString()); } try { final D diagram = factoryManager.newDiagram(name, defSetId, metadata); final String[] raw = serialize(diagram); getIoService().write(kiePath, raw[0], new CommentedOption(identity.getIdentifier())); return Paths.convert(kiePath); } catch (final Exception e) { LOG.error("Cannot create diagram in path [" + kiePath + "]", e); } return null; } 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> { public Path create(final Path path, final String name, final String defSetId, final Metadata metadata) { final DefinitionSetService services = getServiceById(defSetId); if (null == services) { throw new IllegalStateException("No backend Definition Set services for [" + defSetId + "]"); } final String fName = buildFileName(name, services.getResourceType()); final org.uberfire.java.nio.file.Path kiePath = Paths.convert(path).resolve(fName); if (getIoService().exists(kiePath)) { throw new FileAlreadyExistsException(kiePath.toString()); } try { final D diagram = factoryManager.newDiagram(name, defSetId, metadata); final String[] raw = serialize(diagram); getIoService().write(kiePath, raw[0], new CommentedOption(identity.getIdentifier())); return Paths.convert(kiePath); } catch (final Exception e) { LOG.error("Cannot create diagram in path [" + kiePath + "]", e); } return null; } 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; }