use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFile method unlock.
@Override
public VirtualFile unlock(String lockToken) throws ForbiddenException, ConflictException {
checkExistence();
if (isFile()) {
final LockHolder theLock = lock;
if (theLock == null) {
throw new ConflictException("File is not locked");
} else if (isExpired(theLock)) {
lock = null;
throw new ConflictException("File is not locked");
}
if (theLock.lockToken.equals(lockToken)) {
lock = null;
lastModificationDate = System.currentTimeMillis();
} else {
throw new ForbiddenException("Unable remove lock from file. Lock token does not match");
}
lastModificationDate = System.currentTimeMillis();
return this;
} else {
throw new ForbiddenException(String.format("Unable unlock '%s'. Locking allowed for files only", getPath()));
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFile method delete.
@Override
public void delete(String lockToken) throws ForbiddenException, ServerException {
checkExistence();
boolean isFile = isFile();
if (isRoot()) {
throw new ForbiddenException("Unable delete root folder");
}
final Path myPath = getPath();
final boolean folder = isFolder();
if (folder) {
final List<VirtualFile> lockedFiles = new LockedFileFinder(this).findLockedFiles();
if (!lockedFiles.isEmpty()) {
throw new ForbiddenException(String.format("Unable delete item '%s'. Child items '%s' are locked", getName(), lockedFiles));
}
for (VirtualFile virtualFile : getTreeAsList(this)) {
((MemoryVirtualFile) virtualFile).exists = false;
}
} else {
if (fileIsLockedAndLockTokenIsInvalid(lockToken)) {
throw new ForbiddenException(String.format("Unable delete item '%s'. Item is locked", getPath()));
}
}
parent.children.remove(name);
exists = false;
parent = null;
deleteFromSearcher(myPath, isFile);
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsUpdateContentOfLockedFileByBytesWhenLockTokenIsInvalid.
@Test
public void failsUpdateContentOfLockedFileByBytesWhenLockTokenIsInvalid() throws Exception {
VirtualFile root = getRoot();
VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
String invalidLockToken = invalidateLockToken(file.lock(0));
try {
file.updateContent("updated content".getBytes(), invalidLockToken);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException expected) {
assertionHelper.assertThatIoFileHasContent(file.getPath(), DEFAULT_CONTENT_BYTES);
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsDeleteFolderWhenItContainsLockedFile.
@Test
public void failsDeleteFolderWhenItContainsLockedFile() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
folder.setProperty("property1", "value1");
Path folderPath = folder.getPath();
VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
file.setProperty("property2", "value2");
Path filePath = file.getPath();
file.lock(0);
try {
folder.delete();
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException e) {
assertionHelper.assertThatIoFileExists(folderPath);
assertionHelper.assertThatMetadataIoFileHasContent(folder.getPath(), serializeVirtualFileMetadata(ImmutableMap.of("property1", "value1")));
assertionHelper.assertThatIoFileHasContent(filePath, DEFAULT_CONTENT_BYTES);
assertionHelper.assertThatMetadataIoFileHasContent(file.getPath(), serializeVirtualFileMetadata(ImmutableMap.of("property2", "value2")));
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsLockFolder.
@Test
public void failsLockFolder() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
try {
folder.lock(0);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException e) {
assertionHelper.assertThatLockIoFileDoesNotExist(folder.getPath());
assertFalse(folder.isLocked());
}
}
Aggregations