Search in sources :

Example 36 with ConflictException

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) {
    }
}
Also used : NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) ConflictException(org.eclipse.che.api.core.ConflictException) NotFoundException(org.eclipse.che.api.core.NotFoundException) Test(org.junit.Test)

Example 37 with ConflictException

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());
    }
}
Also used : ConflictException(org.eclipse.che.api.core.ConflictException) ArrayList(java.util.ArrayList) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig) Test(org.junit.Test)

Example 38 with ConflictException

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;
    }
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) IOException(java.io.IOException)

Example 39 with ConflictException

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");
    }
}
Also used : Path(org.eclipse.che.api.vfs.Path) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ConflictException(org.eclipse.che.api.core.ConflictException) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) File(java.io.File)

Example 40 with ConflictException

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");
    }
}
Also used : Path(org.eclipse.che.api.vfs.Path) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) IOException(java.io.IOException) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) File(java.io.File)

Aggregations

ConflictException (org.eclipse.che.api.core.ConflictException)81 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)28 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)25 ServerException (org.eclipse.che.api.core.ServerException)24 Test (org.junit.Test)24 NotFoundException (org.eclipse.che.api.core.NotFoundException)17 Path (org.eclipse.che.api.vfs.Path)12 IOException (java.io.IOException)10 NewProjectConfig (org.eclipse.che.api.core.model.project.NewProjectConfig)8 Unlocker (org.eclipse.che.commons.lang.concurrent.Unlocker)8 ArrayList (java.util.ArrayList)7 BadRequestException (org.eclipse.che.api.core.BadRequestException)7 MachineException (org.eclipse.che.api.machine.server.exception.MachineException)7 File (java.io.File)6 ProjectConfig (org.eclipse.che.api.core.model.project.ProjectConfig)6 CommandImpl (org.eclipse.che.api.machine.server.model.impl.CommandImpl)6 List (java.util.List)5 Map (java.util.Map)5 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)5 String.format (java.lang.String.format)4