use of javax.ws.rs.Produces in project che by eclipse.
the class StackService method uploadIcon.
@POST
@Path("/{id}/icon")
@Consumes(MULTIPART_FORM_DATA)
@Produces(TEXT_PLAIN)
@GenerateLink(rel = LINK_REL_UPLOAD_ICON)
@ApiOperation(value = "Upload icon for required stack", notes = "This operation can be performed only by authorized stack owner")
@ApiResponses({ @ApiResponse(code = 200, message = "Image was successfully uploaded"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access upload image for stack with required id"), @ApiResponse(code = 404, message = "The stack doesn't exist"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public Response uploadIcon(@ApiParam("The image for stack") final Iterator<FileItem> formData, @ApiParam("The stack id") @PathParam("id") final String id) throws NotFoundException, ServerException, BadRequestException, ForbiddenException, ConflictException {
if (formData.hasNext()) {
FileItem fileItem = formData.next();
StackIcon stackIcon = new StackIcon(fileItem.getName(), fileItem.getContentType(), fileItem.get());
StackImpl stack = stackDao.getById(id);
stack.setStackIcon(stackIcon);
stackDao.update(stack);
}
return Response.ok().build();
}
use of javax.ws.rs.Produces in project che by eclipse.
the class StackService method createStack.
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@GenerateLink(rel = LINK_REL_CREATE_STACK)
@ApiOperation(value = "Create a new stack", notes = "This operation can be performed only by authorized user", response = StackDto.class)
@ApiResponses({ @ApiResponse(code = 201, message = "The stack successfully created"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to create a new stack"), @ApiResponse(code = 409, message = "Conflict error occurred during the stack creation" + "(e.g. The stack with such name already exists)"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public Response createStack(@ApiParam("The new stack") final StackDto stackDto) throws ApiException {
stackValidator.check(stackDto);
final String userId = EnvironmentContext.getCurrent().getSubject().getUserId();
final StackImpl newStack = StackImpl.builder().generateId().setName(stackDto.getName()).setDescription(stackDto.getDescription()).setScope(stackDto.getScope()).setCreator(userId).setTags(stackDto.getTags()).setWorkspaceConfig(stackDto.getWorkspaceConfig()).setSource(stackDto.getSource()).setComponents(stackDto.getComponents()).build();
stackDao.create(newStack);
return Response.status(CREATED).entity(asStackDto(newStack)).build();
}
use of javax.ws.rs.Produces in project che by eclipse.
the class StackService method updateStack.
@PUT
@Path("/{id}")
@Produces(APPLICATION_JSON)
@Consumes(APPLICATION_JSON)
@GenerateLink(rel = LINK_REL_UPDATE_STACK)
@ApiOperation(value = "Update the stack by replacing all the existing data (exclude field \"creator\") with update")
@ApiResponses({ @ApiResponse(code = 200, message = "The stack 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 stack"), @ApiResponse(code = 409, message = "Conflict error occurred during stack update" + "(e.g. Stack with such name already exists)"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public StackDto updateStack(@ApiParam(value = "The stack update", required = true) final StackDto updateDto, @ApiParam(value = "The stack id", required = true) @PathParam("id") final String id) throws ApiException {
stackValidator.check(updateDto);
final StackImpl stack = stackDao.getById(id);
StackImpl stackForUpdate = StackImpl.builder().setId(id).setName(updateDto.getName()).setDescription(updateDto.getDescription()).setScope(updateDto.getScope()).setCreator(stack.getCreator()).setTags(updateDto.getTags()).setWorkspaceConfig(updateDto.getWorkspaceConfig()).setSource(updateDto.getSource()).setComponents(updateDto.getComponents()).build();
return asStackDto(stackDao.update(stackForUpdate));
}
use of javax.ws.rs.Produces in project che by eclipse.
the class SshService method createPair.
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_HTML)
@GenerateLink(rel = Constants.LINK_REL_CREATE_PAIR)
public Response createPair(Iterator<FileItem> formData) throws BadRequestException, ServerException, ConflictException {
String service = null;
String name = null;
String privateKey = null;
String publicKey = null;
while (formData.hasNext()) {
FileItem item = formData.next();
String fieldName = item.getFieldName();
switch(fieldName) {
case "service":
service = item.getString();
break;
case "name":
name = item.getString();
break;
case "privateKey":
privateKey = item.getString();
break;
case "publicKey":
publicKey = item.getString();
break;
default:
}
}
requiredNotNull(service, "Service name required");
requiredNotNull(name, "Name required");
if (privateKey == null && publicKey == null) {
throw new BadRequestException("Key content was not provided.");
}
sshManager.createPair(new SshPairImpl(getCurrentUserId(), service, name, publicKey, privateKey));
// through specific of html form that doesn't invoke complete submit handler
return Response.ok("", MediaType.TEXT_HTML).build();
}
use of javax.ws.rs.Produces in project che by eclipse.
the class ProfileService method updateAttributesById.
@PUT
@Path("/{id}/attributes")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update the profile attributes of the user with requested identifier", notes = "The replace strategy is used for the update, so all the existing profile " + "attributes will be override by the profile update")
@ApiResponses({ @ApiResponse(code = 200, message = "The profile successfully updated and the response contains " + "newly updated profile entity"), @ApiResponse(code = 404, message = "When profile for the user with requested identifier doesn't exist"), @ApiResponse(code = 500, message = "Couldn't retrieve profile due to internal server error") })
public ProfileDto updateAttributesById(@ApiParam("Id of the user") @PathParam("id") String userId, @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(userId)), getServiceContext());
}
Aggregations