public static Path newLock(final Path path) { Path lockPath = newLockPath(path); return PathFactory.newPath(path.getFileName() + LOCK_FILE_EXTENSION, lockPath.toURI() + LOCK_FILE_EXTENSION); }
@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()); } }
@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()); } }