@Override public PathOperationRestriction hasRestriction(final Path path) { final LockInfo lockInfo = lockService.retrieveLockInfo(path); if (lockInfo != null && lockInfo.isLocked() && !identity.getIdentifier().equals(lockInfo.lockedBy())) { return new PathOperationRestriction() { @Override public String getMessage(final Path path) { return path.toURI() + " cannot be deleted, moved or renamed. It is locked by: " + lockInfo.lockedBy(); } }; } final List<LockInfo> lockInfos = lockService.retrieveLockInfos(path, true); if (lockInfos != null && !lockInfos.isEmpty()) { return new PathOperationRestriction() { @Override public String getMessage(final Path path) { return path.toURI() + " cannot be deleted, moved or renamed. It contains the following locked files: " + lockInfos; } }; } return null; } }
@Override public void acquireLock(final Path path, final ParameterizedCommand<LockResult> parameterizedCommand) { vfsLockService.call(new RemoteCallback<LockResult>() { @Override public void callback(final LockResult result) { parameterizedCommand.execute(result); } }, new BusErrorCallback() { @Override public boolean error(Message message, Throwable throwable) { logger.error("Error when trying to acquire lock for " + path.toURI(), throwable); parameterizedCommand.execute(LockResult.error()); return false; } }).acquireLock(path); }
@Override public void forceReleaseLock(final Path path, final ParameterizedCommand<LockResult> parameterizedCommand) { vfsLockService.call(new RemoteCallback<LockResult>() { @Override public void callback(final LockResult result) { parameterizedCommand.execute(result); } }).forceReleaseLock(path); }
@Override public void retrieveLockInfo(final Path path, final ParameterizedCommand<LockInfo> parameterizedCommand) { vfsLockService.call(new RemoteCallback<LockInfo>() { @Override public void callback(final LockInfo lockInfo) { parameterizedCommand.execute(lockInfo); } }).retrieveLockInfo(path); } }
@Override public void releaseLock(final Path path, final ParameterizedCommand<LockResult> parameterizedCommand) { vfsLockService.call(new RemoteCallback<LockResult>() { @Override public void callback(final LockResult result) { parameterizedCommand.execute(result); } }).releaseLock(path); }
@Override public void retrieveLockInfo(final Path path, final ParameterizedCommand<LockInfo> parameterizedCommand) { vfsLockService.call(new RemoteCallback<LockInfo>() { @Override public void callback(final LockInfo lockInfo) { parameterizedCommand.execute(lockInfo); } }).retrieveLockInfo(path); } }
@Override public void releaseLock(final Path path, final ParameterizedCommand<LockResult> parameterizedCommand) { vfsLockService.call(new RemoteCallback<LockResult>() { @Override public void callback(final LockResult result) { parameterizedCommand.execute(result); } }).releaseLock(path); }
@Override public PathOperationRestriction hasRestriction(final Path path) { final LockInfo lockInfo = lockService.retrieveLockInfo(path); if (lockInfo != null && lockInfo.isLocked() && !identity.getIdentifier().equals(lockInfo.lockedBy())) { return new PathOperationRestriction() { @Override public String getMessage(final Path path) { return path.toURI() + " cannot be deleted, moved or renamed. It is locked by: " + lockInfo.lockedBy(); } }; } final List<LockInfo> lockInfos = lockService.retrieveLockInfos(path, true); if (lockInfos != null && !lockInfos.isEmpty()) { return new PathOperationRestriction() { @Override public String getMessage(final Path path) { return path.toURI() + " cannot be deleted, moved or renamed. It contains the following locked files: " + lockInfos; } }; } return null; } }
private void changeLockInfo(Path path, boolean locked) { when(lockService.retrieveLockInfo(path)).thenReturn(new LockInfo(locked, "lockedBy", path)); } }
@Override public void forceReleaseLock(final Path path, final ParameterizedCommand<LockResult> parameterizedCommand) { vfsLockService.call(new RemoteCallback<LockResult>() { @Override public void callback(final LockResult result) { parameterizedCommand.execute(result); } }).forceReleaseLock(path); }
@Override public void acquireLock(final Path path, final ParameterizedCommand<LockResult> parameterizedCommand) { vfsLockService.call(new RemoteCallback<LockResult>() { @Override public void callback(final LockResult result) { parameterizedCommand.execute(result); } }, new BusErrorCallback() { @Override public boolean error(Message message, Throwable throwable) { logger.error("Error when trying to acquire lock for " + path.toURI(), throwable); parameterizedCommand.execute(LockResult.error()); return false; } }).acquireLock(path); }
@Test public void lockBySameUserShouldNotCauseRestriction() { when(lockInfo.isLocked()).thenReturn(true); when(lockService.retrieveLockInfo(any())).thenReturn(lockInfo); when(identity.getIdentifier()).thenReturn("123"); when(lockInfo.lockedBy()).thenReturn("123"); when(lockService.retrieveLockInfos(path, true)).thenReturn(lockInfos); when(lockInfos.isEmpty()).thenReturn(true); PathOperationRestriction result = lockRestrictor.hasRestriction(path); assertNull(result); }
private void changeLockInfo(Path path, boolean locked) { when(lockService.retrieveLockInfo(path)).thenReturn(new LockInfo(locked, "lockedBy", path)); } }
@Test public void lockBySameUserShouldNotCauseRestriction() { when(lockInfo.isLocked()).thenReturn(true); when(lockService.retrieveLockInfo(any())).thenReturn(lockInfo); when(identity.getIdentifier()).thenReturn("123"); when(lockInfo.lockedBy()).thenReturn("123"); when(lockService.retrieveLockInfos(path, true)).thenReturn(lockInfos); when(lockInfos.isEmpty()).thenReturn(true); PathOperationRestriction result = lockRestrictor.hasRestriction(path); assertNull(result); }
private void changeLockInfo(Path path, boolean locked) { when(lockService.retrieveLockInfo(path)).thenReturn(new LockInfo(locked, "lockedBy", path)); } }
@Test public void emptyRestrictionListShouldNotCauseRestriction() { when(lockInfo.isLocked()).thenReturn(false); when(lockService.retrieveLockInfo(any())).thenReturn(lockInfo); when(identity.getIdentifier()).thenReturn("123"); when(lockInfo.lockedBy()).thenReturn("456"); when(lockInfos.isEmpty()).thenReturn(true); when(lockService.retrieveLockInfos(path, true)).thenReturn(lockInfos); PathOperationRestriction result = lockRestrictor.hasRestriction(path); assertNull(result); } }
private void changeLockInfo(Path path, boolean locked) { when(lockService.retrieveLockInfo(path)).thenReturn(new LockInfo(locked, "lockedBy", path)); } }
@Test public void noLockShouldNotCauseRestriction() { when(lockInfo.isLocked()).thenReturn(false); when(lockService.retrieveLockInfo(any())).thenReturn(lockInfo); when(identity.getIdentifier()).thenReturn("456"); when(lockInfo.lockedBy()).thenReturn("123"); when(lockService.retrieveLockInfos(path, true)).thenReturn(lockInfos); when(lockInfos.isEmpty()).thenReturn(true); PathOperationRestriction result = lockRestrictor.hasRestriction(path); assertNull(result); }
@Test public void lockFromAnotherUserShouldCauseRestriction() { when(lockInfo.isLocked()).thenReturn(true); when(lockService.retrieveLockInfo(any())).thenReturn(lockInfo); when(identity.getIdentifier()).thenReturn("456"); when(lockInfo.lockedBy()).thenReturn("123"); when(lockService.retrieveLockInfos(path, true)).thenReturn(Arrays.asList(lockInfo)); when(lockInfos.isEmpty()).thenReturn(true); PathOperationRestriction result = lockRestrictor.hasRestriction(path); assertNotNull(result); assertTrue(result instanceof PathOperationRestriction); }
@Test public void lockFromAnotherUserShouldCauseRestriction() { when(lockInfo.isLocked()).thenReturn(true); when(lockService.retrieveLockInfo(any())).thenReturn(lockInfo); when(identity.getIdentifier()).thenReturn("456"); when(lockInfo.lockedBy()).thenReturn("123"); when(lockService.retrieveLockInfos(path, true)).thenReturn(Arrays.asList(lockInfo)); when(lockInfos.isEmpty()).thenReturn(true); PathOperationRestriction result = lockRestrictor.hasRestriction(path); assertNotNull(result); assertTrue(result instanceof PathOperationRestriction); }