Search in sources :

Example 11 with GenerateLink

use of org.eclipse.che.api.core.rest.annotations.GenerateLink in project che by eclipse.

the class ProfileService method updateAttributes.

@PUT
@Path("/attributes")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@GenerateLink(rel = LINK_REL_CURRENT_PROFILE_ATTRIBUTES)
@ApiOperation(value = "Update the profile attributes of the currently logged in user", notes = "The replace strategy is used for the update, so all the existing profile " + "attributes will be override with incoming values")
public ProfileDto updateAttributes(@ApiParam("New profile attributes") Map<String, String> updates) throws NotFoundException, ServerException, BadRequestException {
    checkAttributes(updates);
    final ProfileImpl profile = new ProfileImpl(profileManager.getById(userId()));
    profile.setAttributes(updates);
    profileManager.update(profile);
    return linksInjector.injectLinks(asDto(profile, userManager.getById(profile.getUserId())), getServiceContext());
}
Also used : ProfileImpl(org.eclipse.che.api.user.server.model.impl.ProfileImpl) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) PUT(javax.ws.rs.PUT)

Example 12 with GenerateLink

use of org.eclipse.che.api.core.rest.annotations.GenerateLink in project che by eclipse.

the class ProfileService method removeAttributes.

@DELETE
@Path("/attributes")
@GenerateLink(rel = LINK_REL_CURRENT_PROFILE_ATTRIBUTES)
@Consumes(APPLICATION_JSON)
@ApiOperation(value = "Remove profile attributes which names are equal to given", notes = "If names list is not send, all the attributes will be removed, " + "if there are no attributes which names equal to some of the given names, " + "then those names are skipped.")
@ApiResponses({ @ApiResponse(code = 204, message = "Attributes successfully removed"), @ApiResponse(code = 500, message = "Couldn't remove attributes due to internal server error") })
public void removeAttributes(@ApiParam("The names of the profile attributes to remove") List<String> names) throws NotFoundException, ServerException {
    final Profile profile = profileManager.getById(userId());
    final Map<String, String> attributes = profile.getAttributes();
    if (names == null) {
        attributes.clear();
    } else {
        names.forEach(attributes::remove);
    }
    profileManager.update(profile);
}
Also used : Profile(org.eclipse.che.api.core.model.user.Profile) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) 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 13 with GenerateLink

use of org.eclipse.che.api.core.rest.annotations.GenerateLink in project che by eclipse.

the class UserService method create.

@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@GenerateLink(rel = LINK_REL_USER)
@ApiOperation(value = "Create a new user", response = UserDto.class)
@ApiResponses({ @ApiResponse(code = 201, message = "User successfully created, response contains created entity"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 401, message = "Missed token parameter"), @ApiResponse(code = 500, message = "Couldn't create user due to internal server error") })
public Response create(@ApiParam("New user") UserDto userDto, @ApiParam("Authentication token") @QueryParam("token") String token, @ApiParam("User type") @QueryParam("temporary") @DefaultValue("false") Boolean isTemporary) throws BadRequestException, UnauthorizedException, ConflictException, ServerException {
    if (userDto != null) {
        //should be generated by userManager
        userDto.setId(null);
    }
    final User newUser = token == null ? userDto : tokenValidator.validateToken(token);
    userValidator.checkUser(newUser);
    return Response.status(CREATED).entity(linksInjector.injectLinks(asDto(userManager.create(newUser, isTemporary)), getServiceContext())).build();
}
Also used : User(org.eclipse.che.api.core.model.user.User) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) ApiResponses(io.swagger.annotations.ApiResponses)

Example 14 with GenerateLink

use of org.eclipse.che.api.core.rest.annotations.GenerateLink in project che by eclipse.

the class UserService method updatePassword.

@POST
@Path("/password")
@Consumes(APPLICATION_FORM_URLENCODED)
@GenerateLink(rel = LINK_REL_CURRENT_USER_PASSWORD)
@ApiOperation(value = "Update password of logged in user", notes = "Password must contain at least 8 characters, " + "passport must contain letters and digits")
@ApiResponses({ @ApiResponse(code = 204, message = "Password successfully updated"), @ApiResponse(code = 400, message = "Incoming password is invalid value." + "Valid password must contain at least 8 character " + "which are letters and digits"), @ApiResponse(code = 500, message = "Couldn't update password due to internal server error") })
public void updatePassword(@ApiParam(value = "New password", required = true) @FormParam("password") String password) throws NotFoundException, BadRequestException, ServerException, ConflictException {
    userValidator.checkPassword(password);
    final UserImpl user = new UserImpl(userManager.getById(userId()));
    user.setPassword(password);
    userManager.update(user);
}
Also used : UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Path(javax.ws.rs.Path) 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 15 with GenerateLink

use of org.eclipse.che.api.core.rest.annotations.GenerateLink in project che by eclipse.

the class SshService method generatePair.

@POST
@Path("generate")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@GenerateLink(rel = Constants.LINK_REL_GENERATE_PAIR)
@ApiOperation(value = "Generate and stores ssh pair based on the request", notes = "This operation can be performed only by authorized user," + "this user will be the owner of the created ssh pair", response = SshPairDto.class)
@ApiResponses({ @ApiResponse(code = 201, message = "The ssh pair successfully generated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 409, message = "Conflict error occurred during the ssh pair generation" + "(e.g. The Ssh pair with such name and service already exists)"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public Response generatePair(@ApiParam(value = "The configuration to generate the new ssh pair", required = true) GenerateSshPairRequest request) throws BadRequestException, ServerException, ConflictException {
    requiredNotNull(request, "Generate ssh pair request required");
    requiredNotNull(request.getService(), "Service name required");
    requiredNotNull(request.getName(), "Name required");
    final SshPairImpl generatedPair = sshManager.generatePair(getCurrentUserId(), request.getService(), request.getName());
    return Response.status(Response.Status.CREATED).entity(asDto(injectLinks(asDto(generatedPair)))).build();
}
Also used : SshPairImpl(org.eclipse.che.api.ssh.server.model.impl.SshPairImpl) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

GenerateLink (org.eclipse.che.api.core.rest.annotations.GenerateLink)16 ApiOperation (io.swagger.annotations.ApiOperation)14 ApiResponses (io.swagger.annotations.ApiResponses)13 Consumes (javax.ws.rs.Consumes)13 Produces (javax.ws.rs.Produces)11 POST (javax.ws.rs.POST)10 Path (javax.ws.rs.Path)9 StackImpl (org.eclipse.che.api.workspace.server.model.impl.stack.StackImpl)5 SshPairImpl (org.eclipse.che.api.ssh.server.model.impl.SshPairImpl)3 ArrayList (java.util.ArrayList)2 DELETE (javax.ws.rs.DELETE)2 PUT (javax.ws.rs.PUT)2 FileItem (org.apache.commons.fileupload.FileItem)2 BadRequestException (org.eclipse.che.api.core.BadRequestException)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 StackIcon (org.eclipse.che.api.workspace.server.stack.image.StackIcon)2 NewProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.NewProjectConfigDto)2 ProjectConfigDto (org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto)2 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1