private Path decodePath(String uri, String prefix) { final String name = uri.substring(uri.lastIndexOf('/') + 1, uri.length()); final String decodedURI = uri.substring(prefix.length(), uri.length()); return PathFactory.newPath(name, decodedURI); }
private Path stripFileName( final Path path ) { String uri = path.toURI(); uri = uri.replace( path.getFileName(), "" ); return PathFactory.newPathBasedOn( path.getFileName(), uri, path ); }
public static String readLockedBy(final Path path) { org.uberfire.java.nio.file.Path lock = convert(PathFactory.newLock(path)); if (!Files.exists(lock)) { return null; } else { return new String(Files.readAllBytes(lock)); } }
public static Path newLock(final Path path) { Path lockPath = newLockPath(path); return PathFactory.newPath(path.getFileName() + LOCK_FILE_EXTENSION, lockPath.toURI() + LOCK_FILE_EXTENSION); }
@Test public void lockTest() { Path path = mock(Path.class); when(path.toURI()).thenReturn("default://master@myteam/dora/src/main/resources/com/myteam/dora/sample.drl"); assertEquals("default://locks@system/system/myteam/master/dora/src/main/resources/com/myteam/dora/sample.drl.ulock", PathFactory.newLock(path).toURI()); Path lockPath = PathFactory.newLockPath(path); Path extractedPath = PathFactory.fromLock(lockPath); assertEquals(path.toURI(), extractedPath.toURI()); } }
@Override public List<LockInfo> retrieveLockInfos(Path path, boolean excludeOwnedLocks) throws IllegalArgumentException, IOException { if (!Files.isDirectory(Paths.convert(path))) { return Collections.emptyList(); } final Path lockPath = PathFactory.newLockPath(path); final List<Path> locks = new ArrayList<Path>(); retrieveLocks(ioService.get(URI.create(lockPath.toURI())), locks); final List<LockInfo> lockInfos = new LinkedList<LockInfo>(); for (Path lock : locks) { final LockInfo lockInfo = retrieveLockInfo(PathFactory.fromLock(lock)); if (!excludeOwnedLocks || !sessionInfo.getIdentity().getIdentifier().equals(lockInfo.lockedBy())) { if (Files.exists(Paths.convert(lockInfo.getFile()))) { lockInfos.add(lockInfo); } } } return lockInfos; }
@Test public void lockTest() { Path path = mock(Path.class); when(path.toURI()).thenReturn("default://master@myteam/dora/src/main/resources/com/myteam/dora/sample.drl"); assertEquals("default://locks@system/system/myteam/master/dora/src/main/resources/com/myteam/dora/sample.drl.ulock", PathFactory.newLock(path).toURI()); Path lockPath = PathFactory.newLockPath(path); Path extractedPath = PathFactory.fromLock(lockPath); assertEquals(path.toURI(), extractedPath.toURI()); } }
private Path getPath(String fileName) { return PathFactory.newPath(fileName, "default://tmp/" + fileName); } }
private Path getLatestVersionPath(final Path path) { final List<VersionRecord> versions = versionRecordService.load(Paths.convert(path)); final String versionUri = versions.get(versions.size() - 1).uri(); return PathFactory.newPathBasedOn(path.getFileName(), versionUri, path); }
private LockInfo retrieveLockInfo(org.uberfire.backend.vfs.Path path) { final org.uberfire.java.nio.file.Path lockPath = Paths.convert(PathFactory.newLock(path)); try { //See https://issues.jboss.org/browse/GUVNOR-2399. We simply try to read the lock file returning a default. final String lockedBy = configIOService.readAllString(lockPath); return new LockInfo(true, lockedBy, path); } catch (NoSuchFileException nsfe) { return new LockInfo(false, "", path); } } }
private Path getPath(String fileName) { return PathFactory.newPath(fileName, "file://tmp/" + fileName); }
private Path getLatestVersionPath(final Path path) { final List<VersionRecord> versions = versionRecordService.load(Paths.convert(path)); final String versionUri = versions.get(versions.size() - 1).uri(); return PathFactory.newPathBasedOn(path.getFileName(), versionUri, path); }
private LockInfo retrieveLockInfo(org.uberfire.backend.vfs.Path path) { final org.uberfire.java.nio.file.Path lockPath = Paths.convert(PathFactory.newLock(path)); try { //See https://issues.jboss.org/browse/GUVNOR-2399. We simply try to read the lock file returning a default. final String lockedBy = configIOService.readAllString(lockPath); return new LockInfo(true, lockedBy, path); } catch (NoSuchFileException nsfe) { return new LockInfo(false, "", path); } } }
private Path getAnotherDirectory() { return PathFactory.newPath("/", PATH_PREFIX + "new-parent/"); }
public ObservablePath createObservablePath(Path path, String uri) { return IOC.getBeanManager().lookupBean(ObservablePath.class).getInstance().wrap( PathFactory.newPathBasedOn(path.getFileName(), uri, path)); } }
for (LockInfo lock : locks) { try { final Path lockPath = Paths.convert(PathFactory.newLock(lock.getFile()));
private Path getAnotherDirectory() { return PathFactory.newPath("/", PATH_PREFIX + "new-parent/"); }
public ObservablePath createObservablePath(Path path, String uri) { return IOC.getBeanManager().lookupBean(ObservablePath.class).getInstance().wrap( PathFactory.newPathBasedOn(path.getFileName(), uri, path)); } }
@Override public LockInfo retrieveLockInfo(Path path) throws IllegalArgumentException, IOException { final Path vfsLock = PathFactory.newLock(path); final org.uberfire.java.nio.file.Path realLock = Paths.convert(vfsLock); if (ioService.exists(realLock)) { try { final String lockedBy = ioService.readAllString(realLock); return new LockInfo(true, lockedBy, path, vfsLock); } catch (NoSuchFileException nsfe) { // We want to avoid starting a batch (to ensure cluster-wide consistent reads) here since // this method is invoked very frequently. Therefore it's possible that the lock file // was deleted after the check to exists but before readAllString was invoked. There's // no need for special exception handling as it simply means that file is no longer locked. } } return new LockInfo(false, null, path, vfsLock); }
private Path createFile(final String fileName) { return PathFactory.newPath(fileName, PATH_PREFIX + fileName); }