use of org.eclipse.che.api.core.ConflictException in project che by eclipse.
the class ProjectManagerWriteTest method testInvalidUpdateConfig.
@Test
public void testInvalidUpdateConfig() throws Exception {
ProjectConfig pc = new NewProjectConfigImpl(null, BaseProjectType.ID, null, "name", "descr", null, null, null);
try {
pm.updateProject(pc);
fail("ConflictException: Project path is not defined");
} catch (ConflictException e) {
}
pc = new NewProjectConfigImpl("/nothing", BaseProjectType.ID, null, "name", "descr", null, null, null);
try {
pm.updateProject(pc);
fail("NotFoundException: Project '/nothing' doesn't exist.");
} catch (NotFoundException e) {
}
}
use of org.eclipse.che.api.core.ConflictException in project che by eclipse.
the class ProjectManagerWriteTest method shouldThrowConflictExceptionAtCreatingBatchProjectsWhenProjectWithPathAlreadyExist.
@Test
public void shouldThrowConflictExceptionAtCreatingBatchProjectsWhenProjectWithPathAlreadyExist() throws Exception {
final String path = "/somePath";
final NewProjectConfig config = createProjectConfigObject("project", path, BaseProjectType.ID, null);
final List<NewProjectConfig> configs = new ArrayList<>(1);
configs.add(config);
pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
checkProjectExist(path);
assertEquals(1, projectRegistry.getProjects().size());
try {
pm.createBatchProjects(configs, false, new ProjectOutputLineConsumerFactory("ws", 300));
fail("ConflictException should be thrown : Project config with the same path is already exists");
} catch (ConflictException e) {
assertEquals(1, projectRegistry.getProjects().size());
}
}
use of org.eclipse.che.api.core.ConflictException in project che by eclipse.
the class ProjectService method uploadZip.
private static Response uploadZip(VirtualFile parent, Iterator<FileItem> formData) throws ForbiddenException, ConflictException, ServerException {
try {
FileItem contentItem = null;
boolean overwrite = false;
boolean skipFirstLevel = false;
while (formData.hasNext()) {
FileItem item = formData.next();
if (!item.isFormField()) {
if (contentItem == null) {
contentItem = item;
} else {
throw new ServerException("More then one upload file is found but only one should be. ");
}
} else if ("overwrite".equals(item.getFieldName())) {
overwrite = Boolean.parseBoolean(item.getString().trim());
} else if ("skipFirstLevel".equals(item.getFieldName())) {
skipFirstLevel = Boolean.parseBoolean(item.getString().trim());
}
}
if (contentItem == null) {
throw new ServerException("Cannot find file for upload. ");
}
try {
importZip(parent, contentItem.getInputStream(), overwrite, skipFirstLevel);
} catch (IOException ioe) {
throw new ServerException(ioe.getMessage(), ioe);
}
return Response.ok("", MediaType.TEXT_HTML).build();
} catch (ForbiddenException | ConflictException | ServerException e) {
HtmlErrorFormatter.sendErrorAsHTML(e);
// never thrown
throw e;
}
}
use of org.eclipse.che.api.core.ConflictException in project che by eclipse.
the class LocalVirtualFileSystem method createFolder.
LocalVirtualFile createFolder(LocalVirtualFile parent, String name) throws ForbiddenException, ConflictException, ServerException {
checkName(name);
if (parent.isFolder()) {
final Path newPath = parent.getPath().newPath(name);
final File newIoFile = new File(ioRoot, toIoPath(newPath));
if (!newIoFile.mkdirs()) {
if (newIoFile.exists()) {
throw new ConflictException(String.format("Item '%s' already exists", newPath));
}
}
return new LocalVirtualFile(newIoFile, newPath, this);
} else {
throw new ForbiddenException("Unable create folder. Item specified as parent is not a folder");
}
}
use of org.eclipse.che.api.core.ConflictException in project che by eclipse.
the class LocalVirtualFileSystem method createFile.
LocalVirtualFile createFile(LocalVirtualFile parent, String name, InputStream content) throws ForbiddenException, ConflictException, ServerException {
checkName(name);
if (Path.of(name).length() > 1) {
throw new ServerException(String.format("Invalid name '%s'", name));
}
if (parent.isFolder()) {
final Path newPath = parent.getPath().newPath(name);
final File newIoFile = new File(ioRoot, toIoPath(newPath));
try {
if (!newIoFile.createNewFile()) {
throw new ConflictException(String.format("Item '%s' already exists", newPath));
}
} catch (IOException e) {
String errorMessage = String.format("Unable create new file '%s'", newPath);
LOG.error(errorMessage + "\n" + e.getMessage(), e);
throw new ServerException(errorMessage);
}
final LocalVirtualFile newVirtualFile = new LocalVirtualFile(newIoFile, newPath, this);
if (content != null) {
doUpdateContent(newVirtualFile, content);
}
addInSearcher(newVirtualFile);
return newVirtualFile;
} else {
throw new ForbiddenException("Unable create new file. Item specified as parent is not a folder");
}
}
Aggregations