use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileTest method failsUpdateContentOfLockedFileByStreamWhenLockTokenIsInvalid.
@Test
public void failsUpdateContentOfLockedFileByStreamWhenLockTokenIsInvalid() throws Exception {
VirtualFile root = getRoot();
VirtualFile file = root.createFile(generateFileName(), DEFAULT_CONTENT);
String invalidLockToken = invalidateLockToken(file.lock(0));
try {
file.updateContent(new ByteArrayInputStream("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 failsMoveLockedFileWithoutLockToken.
@Test
public void failsMoveLockedFileWithoutLockToken() throws Exception {
VirtualFile file = getRoot().createFile(generateFileName(), DEFAULT_CONTENT);
file.setProperty("property1", "value1");
Path filePath = file.getPath();
file.lock(0);
VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
Path movedFilePath = targetFolder.getPath().newPath(file.getName());
try {
file.moveTo(targetFolder);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException e) {
assertionHelper.assertThatIoFileDoesNotExist(movedFilePath);
assertionHelper.assertThatLockIoFileDoesNotExist(movedFilePath);
assertionHelper.assertThatMetadataIoFileDoesNotExist(movedFilePath);
assertionHelper.assertThatIoFileHasContent(filePath, DEFAULT_CONTENT_BYTES);
assertionHelper.assertThatMetadataIoFileHasContent(filePath, serializeVirtualFileMetadata(ImmutableMap.of("property1", "value1")));
assertionHelper.assertThatLockIoFileExists(filePath);
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class LocalVirtualFileSystem method untar.
void untar(LocalVirtualFile parent, InputStream tarArchive, boolean overwrite, int stripNumber) throws ForbiddenException, ConflictException, ServerException {
if (archiverFactory == null)
throw new ServerException("VFS: Could not create tar archiver. Archiver Factory is not properly configured (is null)");
if (parent.isFolder()) {
extract(archiverFactory.createArchiver(parent, "tar"), tarArchive, overwrite, stripNumber);
addInSearcher(parent);
} else {
throw new ForbiddenException(String.format("Unable import tar archive. Item '%s' is not a folder", parent.getPath()));
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFile method copyTo.
@Override
public VirtualFile copyTo(VirtualFile parent, String newName, boolean overwrite) throws ForbiddenException, ConflictException, ServerException {
checkExistence();
((MemoryVirtualFile) parent).checkExistence();
if (isRoot()) {
throw new ServerException("Unable copy root folder");
}
if (newName == null || newName.trim().isEmpty()) {
newName = this.getName();
}
if (parent.isFolder()) {
VirtualFile copy = doCopy((MemoryVirtualFile) parent, newName, overwrite);
addInSearcher(copy);
return copy;
} else {
throw new ForbiddenException(String.format("Unable create copy of '%s'. Item '%s' specified as parent is not a folder.", getPath(), parent.getPath()));
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFile method moveTo.
@Override
public VirtualFile moveTo(VirtualFile parent, String newName, boolean overwrite, String lockToken) throws ForbiddenException, ConflictException, ServerException {
checkExistence();
MemoryVirtualFile memoryParent = (MemoryVirtualFile) parent;
memoryParent.checkExistence();
if (isRoot()) {
throw new ForbiddenException("Unable move root folder");
}
if (!parent.isFolder()) {
throw new ForbiddenException("Unable move item. Item specified as parent is not a folder");
}
if (newName == null || newName.trim().isEmpty()) {
newName = this.getName();
}
final boolean isFile = isFile();
final Path myPath = getPath();
final Path newParentPath = parent.getPath();
final boolean folder = isFolder();
if (folder) {
if (newParentPath.isChild(myPath)) {
throw new ForbiddenException(String.format("Unable move item %s to %s. Item may not have itself as parent", myPath, newParentPath));
}
final List<VirtualFile> lockedFiles = new LockedFileFinder(this).findLockedFiles();
if (!lockedFiles.isEmpty()) {
throw new ForbiddenException(String.format("Unable move item '%s'. Child items '%s' are locked", getName(), lockedFiles));
}
} else if (fileIsLockedAndLockTokenIsInvalid(lockToken)) {
throw new ForbiddenException(String.format("Unable move item %s. Item is locked", myPath));
}
if (overwrite) {
MemoryVirtualFile existedItem = memoryParent.children.get(newName);
if (existedItem != null) {
existedItem.delete();
}
}
if (memoryParent.children.containsKey(newName)) {
throw new ConflictException(String.format("Item '%s' already exists", parent.getPath().newPath(newName)));
}
this.parent.children.remove(name);
memoryParent.children.put(newName, this);
this.parent = memoryParent;
this.name = newName;
lock = null;
deleteFromSearcher(myPath, isFile);
addInSearcher(this);
return this;
}
Aggregations