use of org.eclipse.che.api.core.ConflictException 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;
}
use of org.eclipse.che.api.core.ConflictException in project che by eclipse.
the class ZipArchiver method extract.
@Override
public void extract(InputStream zipInput, boolean overwrite, int stripNumber) throws IOException, ForbiddenException, ConflictException, ServerException {
try (ZipInputStream zip = new ZipInputStream(ZipContent.of(zipInput).getContent())) {
InputStream notClosableInputStream = new NotClosableInputStream(zip);
ZipEntry zipEntry;
while ((zipEntry = zip.getNextEntry()) != null) {
VirtualFile extractFolder = folder;
Path relativePath = Path.of(zipEntry.getName());
if (stripNumber > 0) {
if (relativePath.length() <= stripNumber) {
continue;
}
relativePath = relativePath.subPath(stripNumber);
}
if (zipEntry.isDirectory()) {
if (!extractFolder.hasChild(relativePath)) {
extractFolder.createFolder(relativePath.toString());
}
continue;
}
if (relativePath.length() > 1) {
Path neededParentPath = relativePath.getParent();
VirtualFile neededParent = extractFolder.getChild(neededParentPath);
if (neededParent == null) {
neededParent = extractFolder.createFolder(neededParentPath.toString());
}
extractFolder = neededParent;
}
String fileName = relativePath.getName();
VirtualFile file = extractFolder.getChild(Path.of(fileName));
if (file == null) {
extractFolder.createFile(fileName, notClosableInputStream);
} else {
if (overwrite) {
file.updateContent(notClosableInputStream);
} else {
throw new ConflictException(String.format("File '%s' already exists", file.getPath()));
}
}
zip.closeEntry();
}
}
}
use of org.eclipse.che.api.core.ConflictException in project che by eclipse.
the class ProjectManagerWriteTest method registerImporter.
private void registerImporter(String importType, InputStream zip) throws Exception {
final ValueHolder<FolderEntry> folderHolder = new ValueHolder<>();
importerRegistry.register(new ProjectImporter() {
@Override
public String getId() {
return importType;
}
@Override
public boolean isInternal() {
return false;
}
@Override
public String getDescription() {
return "importer";
}
@Override
public void importSources(FolderEntry baseFolder, SourceStorage storage) throws ConflictException, ServerException, ForbiddenException {
importSources(baseFolder, storage, LineConsumerFactory.NULL);
}
@Override
public void importSources(FolderEntry baseFolder, SourceStorage storage, LineConsumerFactory importOutputConsumerFactory) throws ConflictException, ServerException, ForbiddenException {
// Don't really use location in this test.
baseFolder.getVirtualFile().unzip(zip, true, 0);
folderHolder.set(baseFolder);
}
@Override
public ImporterCategory getCategory() {
return ProjectImporter.ImporterCategory.ARCHIVE;
}
});
}
use of org.eclipse.che.api.core.ConflictException in project che by eclipse.
the class ProjectManagerWriteTest method testSamePathProjectCreateFailed.
@Test
public void testSamePathProjectCreateFailed() throws Exception {
// SPECS:
// If there is a project with the same path ConflictException will be thrown on create project
ProjectConfig pc = new NewProjectConfigImpl("/testSamePathProjectCreateFailed", "blank", null, "name", "descr", null, null, null);
pm.createProject(pc, null);
pc = new NewProjectConfigImpl("/testSamePathProjectCreateFailed", "blank", null, "name", "descr", null, null, null);
try {
pm.createProject(pc, null);
fail("ConflictException: Project config already exists /testSamePathProjectCreateFailed");
} catch (ConflictException e) {
}
assertNotNull(projectRegistry.getProject("/testSamePathProjectCreateFailed"));
}
use of org.eclipse.che.api.core.ConflictException in project che by eclipse.
the class ProjectManagerWriteTest method testInvalidConfigProjectCreateFailed.
@Test
public void testInvalidConfigProjectCreateFailed() throws Exception {
// SPECS:
// If project path is not defined
// Project creation failed with ConflictException
ProjectConfig pc = new NewProjectConfigImpl(null, "pt2", null, "name", "descr", null, null, null);
try {
pm.createProject(pc, null);
fail("ConflictException: Path for new project should be defined ");
} catch (ConflictException e) {
}
}
Aggregations