Search in sources :

Example 21 with ConflictException

use of org.eclipse.che.api.core.ConflictException in project che by eclipse.

the class Workspace method createResource.

public void createResource(IResource resource, int updateFlags) throws CoreException {
    try {
        IPath path = resource.getFullPath();
        switch(resource.getType()) {
            case IResource.FILE:
                String newName = path.lastSegment();
                VirtualFileEntry child = getProjectsRoot().getChild(path.removeLastSegments(1).toOSString());
                if (child == null) {
                    throw new NotFoundException("Can't find parent folder: " + path.removeLastSegments(1).toOSString());
                }
                FolderEntry entry = (FolderEntry) child;
                entry.createFile(newName, new byte[0]);
                break;
            case IResource.FOLDER:
                getProjectsRoot().createFolder(path.toOSString());
                break;
            case IResource.PROJECT:
                ProjectConfigImpl projectConfig = new ProjectConfigImpl();
                projectConfig.setPath(resource.getName());
                projectConfig.setName(resource.getName());
                projectConfig.setType(BaseProjectType.ID);
                projectManager.get().createProject(projectConfig, new HashMap<>());
                break;
            default:
                throw new UnsupportedOperationException();
        }
    } catch (ForbiddenException | ConflictException | ServerException | NotFoundException e) {
        throw new CoreException(new Status(0, ResourcesPlugin.getPluginId(), e.getMessage(), e));
    }
}
Also used : MultiStatus(org.eclipse.core.runtime.MultiStatus) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IResourceStatus(org.eclipse.core.resources.IResourceStatus) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) IPath(org.eclipse.core.runtime.IPath) ConflictException(org.eclipse.che.api.core.ConflictException) VirtualFileEntry(org.eclipse.che.api.project.server.VirtualFileEntry) NotFoundException(org.eclipse.che.api.core.NotFoundException) CoreException(org.eclipse.core.runtime.CoreException) FolderEntry(org.eclipse.che.api.project.server.FolderEntry) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl)

Example 22 with ConflictException

use of org.eclipse.che.api.core.ConflictException in project che by eclipse.

the class MemoryVirtualFileTest method failsMoveFolderWhenTargetFolderContainsItemWithTheSameNameAndOverwritingIsDisabled.

@Test
public void failsMoveFolderWhenTargetFolderContainsItemWithTheSameNameAndOverwritingIsDisabled() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
    VirtualFile conflictFolder = targetFolder.createFolder(folder.getName());
    try {
        folder.moveTo(targetFolder);
        thrown.expect(ConflictException.class);
    } catch (ConflictException expected) {
        assertNull(getRoot().getChild(conflictFolder.getPath().newPath(file.getName())));
        assertNotNull(getRoot().getChild(folder.getPath()));
        assertEquals(DEFAULT_CONTENT, file.getContentAsString());
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ConflictException(org.eclipse.che.api.core.ConflictException) Test(org.junit.Test)

Example 23 with ConflictException

use of org.eclipse.che.api.core.ConflictException in project che by eclipse.

the class MemoryVirtualFileTest method failsCopyFolderWhenTargetFolderContainsItemWithSameNameAndOverwritingIsDisabled.

@Test
public void failsCopyFolderWhenTargetFolderContainsItemWithSameNameAndOverwritingIsDisabled() throws Exception {
    VirtualFile folder = getRoot().createFolder(generateFolderName());
    VirtualFile file = folder.createFile(generateFileName(), DEFAULT_CONTENT);
    VirtualFile targetFolder = getRoot().createFolder(generateFolderName());
    VirtualFile conflictFolder = targetFolder.createFolder(folder.getName());
    try {
        folder.copyTo(targetFolder);
        thrown.expect(ConflictException.class);
    } catch (ConflictException expected) {
        assertNull(getRoot().getChild(conflictFolder.getPath().newPath(file.getName())));
    }
}
Also used : VirtualFile(org.eclipse.che.api.vfs.VirtualFile) ConflictException(org.eclipse.che.api.core.ConflictException) Test(org.junit.Test)

Example 24 with ConflictException

use of org.eclipse.che.api.core.ConflictException in project che by eclipse.

the class WorkspaceManager method stopWorkspace.

/**
     * Asynchronously stops the workspace,
     * creates a snapshot of it if {@code createSnapshot} is set to true.
     *
     * @param workspaceId
     *         the id of the workspace to stop
     * @param createSnapshot
     *         true if create snapshot, false if don't,
     *         null if default behaviour should be used
     * @throws ServerException
     *         when any server error occurs
     * @throws NullPointerException
     *         when {@code workspaceId} is null
     * @throws NotFoundException
     *         when workspace {@code workspaceId} doesn't have runtime
     */
public void stopWorkspace(String workspaceId, @Nullable Boolean createSnapshot) throws ConflictException, NotFoundException, ServerException {
    requireNonNull(workspaceId, "Required non-null workspace id");
    final WorkspaceImpl workspace = workspaceDao.get(workspaceId);
    workspace.setStatus(runtimes.getStatus(workspaceId));
    if (workspace.getStatus() != WorkspaceStatus.RUNNING && workspace.getStatus() != WorkspaceStatus.STARTING) {
        throw new ConflictException(format("Could not stop the workspace '%s/%s' because its status is '%s'. " + "Workspace must be either 'STARTING' or 'RUNNING'", workspace.getNamespace(), workspace.getConfig().getName(), workspace.getStatus()));
    }
    stopAsync(workspace, createSnapshot);
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ConflictException(org.eclipse.che.api.core.ConflictException)

Example 25 with ConflictException

use of org.eclipse.che.api.core.ConflictException in project che by eclipse.

the class UserServiceTest method shouldNotCreateUserIfTokenIsNotValid.

@Test
public void shouldNotCreateUserIfTokenIsNotValid() throws Exception {
    when(tokenValidator.validateToken("token_value")).thenThrow(new ConflictException("error"));
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).when().contentType("application/json").post(SECURE_PATH + "/user?token=token_value");
    assertEquals(response.statusCode(), 409);
    assertEquals(unwrapError(response), "error");
}
Also used : Response(com.jayway.restassured.response.Response) ConflictException(org.eclipse.che.api.core.ConflictException) Test(org.testng.annotations.Test)

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