Search in sources :

Example 16 with BadRequestException

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

the class ProjectManager method validateProjectConfigurations.

private void validateProjectConfigurations(List<? extends NewProjectConfig> projectConfigList, boolean rewrite) throws NotFoundException, ServerException, ConflictException, ForbiddenException, BadRequestException {
    for (NewProjectConfig projectConfig : projectConfigList) {
        final String pathToProject = projectConfig.getPath();
        if (isNullOrEmpty(pathToProject)) {
            throw new BadRequestException("Path for new project should be defined");
        }
        final String path = ProjectRegistry.absolutizePath(pathToProject);
        final RegisteredProject registeredProject = projectRegistry.getProject(path);
        if (registeredProject != null && rewrite) {
            delete(path);
        } else if (registeredProject != null) {
            throw new ConflictException(format("Project config already exists for %s", path));
        }
        final String projectTypeId = projectConfig.getType();
        if (isNullOrEmpty(projectTypeId)) {
            projectConfig.setType(BaseProjectType.ID);
        }
    }
}
Also used : ConflictException(org.eclipse.che.api.core.ConflictException) BadRequestException(org.eclipse.che.api.core.BadRequestException) NewProjectConfig(org.eclipse.che.api.core.model.project.NewProjectConfig)

Example 17 with BadRequestException

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

the class WsAgentLauncherTest method shouldThrowExceptionIfMachineManagerExecInDevMachineThrowsBadRequestException.

@Test(expectedExceptions = ServerException.class, expectedExceptionsMessageRegExp = "Test exception")
public void shouldThrowExceptionIfMachineManagerExecInDevMachineThrowsBadRequestException() throws Exception {
    Mockito.when(machineProcessManager.exec(Matchers.anyString(), Matchers.anyString(), Matchers.any(Command.class), Matchers.anyString())).thenThrow(new BadRequestException("Test exception"));
    wsAgentLauncher.launch(machine, agent);
    Mockito.verify(machineProcessManager).exec(Matchers.anyString(), Matchers.anyString(), Matchers.any(Command.class), Matchers.anyString());
}
Also used : Command(org.eclipse.che.api.core.model.machine.Command) BadRequestException(org.eclipse.che.api.core.BadRequestException) Test(org.testng.annotations.Test)

Example 18 with BadRequestException

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

the class WorkspaceService method updateProject.

@PUT
@Path("/{id}/project/{path:.*}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update the workspace project by replacing it with a new one", notes = "This operation can be performed only by the workspace owner")
@ApiResponses({ @ApiResponse(code = 200, message = "The project 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 project"), @ApiResponse(code = 404, message = "The workspace or the project not found"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public WorkspaceDto updateProject(@ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The path to the project") @PathParam("path") String path, @ApiParam(value = "The project update", required = true) ProjectConfigDto update) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException {
    requiredNotNull(update, "Project config");
    final WorkspaceImpl workspace = workspaceManager.getWorkspace(id);
    final List<ProjectConfigImpl> projects = workspace.getConfig().getProjects();
    final String normalizedPath = path.startsWith("/") ? path : '/' + path;
    if (!projects.removeIf(project -> project.getPath().equals(normalizedPath))) {
        throw new NotFoundException(format("Workspace '%s' doesn't contain project with path '%s'", id, normalizedPath));
    }
    projects.add(new ProjectConfigImpl(update));
    validator.validateConfig(workspace.getConfig());
    return linksInjector.injectLinks(asDto(workspaceManager.updateWorkspace(id, workspace)), getServiceContext());
}
Also used : EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) ApiParam(io.swagger.annotations.ApiParam) ApiOperation(io.swagger.annotations.ApiOperation) QueryParam(javax.ws.rs.QueryParam) Service(org.eclipse.che.api.core.rest.Service) Consumes(javax.ws.rs.Consumes) Example(io.swagger.annotations.Example) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) WsAgentHealthChecker(org.eclipse.che.api.agent.server.WsAgentHealthChecker) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) ImmutableMap(com.google.common.collect.ImmutableMap) LINK_REL_GET_WORKSPACES(org.eclipse.che.api.workspace.shared.Constants.LINK_REL_GET_WORKSPACES) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) WsAgentHealthStateDto(org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto) LINK_REL_GET_BY_NAMESPACE(org.eclipse.che.api.workspace.shared.Constants.LINK_REL_GET_BY_NAMESPACE) String.format(java.lang.String.format) SnapshotDto(org.eclipse.che.api.machine.shared.dto.SnapshotDto) List(java.util.List) BadRequestException(org.eclipse.che.api.core.BadRequestException) DtoConverter.asDto(org.eclipse.che.api.workspace.server.DtoConverter.asDto) Response(javax.ws.rs.core.Response) EnvironmentRecipeDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) ConflictException(org.eclipse.che.api.core.ConflictException) Api(io.swagger.annotations.Api) Named(javax.inject.Named) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) Collections.emptyMap(java.util.Collections.emptyMap) POST(javax.ws.rs.POST) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) CHE_WORKSPACE_AUTO_START(org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_START) Maps(com.google.common.collect.Maps) NotFoundException(org.eclipse.che.api.core.NotFoundException) Collectors.toList(java.util.stream.Collectors.toList) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) ServerException(org.eclipse.che.api.core.ServerException) ApiResponse(io.swagger.annotations.ApiResponse) ExampleProperty(io.swagger.annotations.ExampleProperty) CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) CHE_WORKSPACE_AUTO_SNAPSHOT(org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_SNAPSHOT) PUT(javax.ws.rs.PUT) CHE_WORKSPACE_AUTO_RESTORE(org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_RESTORE) LINK_REL_CREATE_WORKSPACE(org.eclipse.che.api.workspace.shared.Constants.LINK_REL_CREATE_WORKSPACE) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 19 with BadRequestException

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

the class SshService method createPair.

@POST
@Consumes(APPLICATION_JSON)
@GenerateLink(rel = Constants.LINK_REL_CREATE_PAIR)
@ApiOperation(value = "Create a new ssh pair", notes = "This operation can be performed only by authorized user," + "this user will be the owner of the created ssh pair")
@ApiResponses({ @ApiResponse(code = 204, message = "The ssh pair successfully created"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 409, message = "Conflict error occurred during the ssh pair creation" + "(e.g. The Ssh pair with such name and service already exists)"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public void createPair(@ApiParam(value = "The ssh pair to create", required = true) SshPairDto sshPair) throws BadRequestException, ServerException, ConflictException {
    requiredNotNull(sshPair, "Ssh pair required");
    requiredNotNull(sshPair.getService(), "Service name required");
    requiredNotNull(sshPair.getName(), "Name required");
    if (sshPair.getPublicKey() == null && sshPair.getPrivateKey() == null) {
        throw new BadRequestException("Key content was not provided.");
    }
    sshManager.createPair(new SshPairImpl(getCurrentUserId(), sshPair));
}
Also used : SshPairImpl(org.eclipse.che.api.ssh.server.model.impl.SshPairImpl) BadRequestException(org.eclipse.che.api.core.BadRequestException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) ApiResponses(io.swagger.annotations.ApiResponses)

Example 20 with BadRequestException

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

the class RemoteOAuthTokenProvider method getToken.

/** {@inheritDoc} */
@Override
public OAuthToken getToken(String oauthProviderName, String userId) throws IOException {
    if (userId.isEmpty()) {
        return null;
    }
    try {
        UriBuilder ub = UriBuilder.fromUri(apiEndpoint).path(OAuthAuthenticationService.class).path(OAuthAuthenticationService.class, "token").queryParam("oauth_provider", oauthProviderName);
        Link getTokenLink = DtoFactory.newDto(Link.class).withHref(ub.build().toString()).withMethod("GET");
        return httpJsonRequestFactory.fromLink(getTokenLink).request().asDto(OAuthToken.class);
    } catch (NotFoundException ne) {
        LOG.warn("Token not found for user {}", userId);
        return null;
    } catch (ServerException | UnauthorizedException | ForbiddenException | ConflictException | BadRequestException e) {
        LOG.warn("Exception on token retrieval, message : {}", e.getLocalizedMessage());
        return null;
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) UnauthorizedException(org.eclipse.che.api.core.UnauthorizedException) NotFoundException(org.eclipse.che.api.core.NotFoundException) BadRequestException(org.eclipse.che.api.core.BadRequestException) UriBuilder(javax.ws.rs.core.UriBuilder) Link(org.eclipse.che.api.core.rest.shared.dto.Link)

Aggregations

BadRequestException (org.eclipse.che.api.core.BadRequestException)20 ServerException (org.eclipse.che.api.core.ServerException)9 ConflictException (org.eclipse.che.api.core.ConflictException)7 NotFoundException (org.eclipse.che.api.core.NotFoundException)7 Consumes (javax.ws.rs.Consumes)6 POST (javax.ws.rs.POST)6 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)6 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 IOException (java.io.IOException)5 Map (java.util.Map)5 Produces (javax.ws.rs.Produces)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 GenerateLink (org.eclipse.che.api.core.rest.annotations.GenerateLink)4 Api (io.swagger.annotations.Api)3 ApiParam (io.swagger.annotations.ApiParam)3 ApiResponse (io.swagger.annotations.ApiResponse)3 String.format (java.lang.String.format)3 Collectors.toList (java.util.stream.Collectors.toList)3