use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class StackLoaderTest method predefinedStackWithValidJsonShouldBeCreated.
@Test
public void predefinedStackWithValidJsonShouldBeCreated() throws ServerException, NotFoundException, ConflictException {
URL url = Resources.getResource("stacks.json");
URL urlFolder = Thread.currentThread().getContextClassLoader().getResource("stack_img");
doThrow(new NotFoundException("Stack is already exist")).when(stackDao).update(any());
stackLoader = new StackLoader(url.getPath(), urlFolder.getPath(), stackDao, null);
stackLoader.start();
verify(stackDao, times(5)).update(any());
verify(stackDao, times(5)).create(any());
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class WorkspaceService method updateCommand.
@PUT
@Path("/{id}/command/{name}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update the workspace command by replacing the command with a new one", notes = "This operation can be performed only by the workspace owner")
@ApiResponses({ @ApiResponse(code = 200, message = "The command successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to update the workspace"), @ApiResponse(code = 404, message = "The workspace or the command not found"), @ApiResponse(code = 409, message = "The Command with such name already exists"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public WorkspaceDto updateCommand(@ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The name of the command") @PathParam("name") String cmdName, @ApiParam(value = "The command update", required = true) CommandDto update) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException {
requiredNotNull(update, "Command update");
final WorkspaceImpl workspace = workspaceManager.getWorkspace(id);
final List<CommandImpl> commands = workspace.getConfig().getCommands();
if (!commands.removeIf(cmd -> cmd.getName().equals(cmdName))) {
throw new NotFoundException(format("Workspace '%s' doesn't contain command '%s'", id, cmdName));
}
commands.add(new CommandImpl(update));
validator.validateConfig(workspace.getConfig());
return linksInjector.injectLinks(asDto(workspaceManager.updateWorkspace(workspace.getId(), workspace)), getServiceContext());
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class WorkspaceService method updateEnvironment.
@PUT
@Path("/{id}/environment/{name}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update the workspace environment by replacing it with a new one", notes = "This operation can be performed only by the workspace owner")
@ApiResponses({ @ApiResponse(code = 200, message = "The environment successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to update the environment"), @ApiResponse(code = 404, message = "The workspace or the environment not found"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public WorkspaceDto updateEnvironment(@ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The name of the environment") @PathParam("name") String envName, @ApiParam(value = "The environment update", required = true) EnvironmentDto update) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException {
requiredNotNull(update, "Environment description");
relativizeRecipeLinks(update);
final WorkspaceImpl workspace = workspaceManager.getWorkspace(id);
EnvironmentImpl previous = workspace.getConfig().getEnvironments().put(envName, new EnvironmentImpl(update));
if (previous == null) {
throw new NotFoundException(format("Workspace '%s' doesn't contain environment '%s'", id, envName));
}
validator.validateConfig(workspace.getConfig());
return linksInjector.injectLinks(asDto(workspaceManager.updateWorkspace(id, workspace)), getServiceContext());
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class JpaStackDao method doUpdate.
@Transactional
protected StackImpl doUpdate(StackImpl update) throws NotFoundException {
final EntityManager manager = managerProvider.get();
if (manager.find(StackImpl.class, update.getId()) == null) {
throw new NotFoundException(format("Workspace with id '%s' doesn't exist", update.getId()));
}
if (update.getWorkspaceConfig() != null) {
update.getWorkspaceConfig().getProjects().forEach(ProjectConfigImpl::prePersistAttributes);
}
StackImpl merged = manager.merge(update);
manager.flush();
return merged;
}
use of org.eclipse.che.api.core.NotFoundException in project che by eclipse.
the class JpaWorkspaceDao method get.
@Override
@Transactional
public WorkspaceImpl get(String name, String namespace) throws NotFoundException, ServerException {
requireNonNull(name, "Required non-null name");
requireNonNull(namespace, "Required non-null namespace");
try {
return new WorkspaceImpl(managerProvider.get().createNamedQuery("Workspace.getByName", WorkspaceImpl.class).setParameter("namespace", namespace).setParameter("name", name).getSingleResult());
} catch (NoResultException noResEx) {
throw new NotFoundException(format("Workspace with name '%s' in namespace '%s' doesn't exist", name, namespace));
} catch (RuntimeException x) {
throw new ServerException(x.getLocalizedMessage(), x);
}
}
Aggregations