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));
}
}
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());
}
}
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())));
}
}
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);
}
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");
}
Aggregations