@OPTIONS public ApiInfo info() throws ServerException { ApiInfo myApiInfo = apiInfo; if (myApiInfo == null) { apiInfo = myApiInfo = readApiInfo(); } return myApiInfo; }
/** * Invalidate OAuth token for user. * * @param oauthProvider OAuth provider name */ @DELETE @Path("token") public void invalidate(@Required @QueryParam("oauth_provider") String oauthProvider) throws UnauthorizedException, NotFoundException, ServerException, ForbiddenException { oAuthAPI.invalidateToken(oauthProvider); } }
@DELETE @Path("/{id}") @GenerateLink(rel = LINK_REL_REMOVE_STACK) @ApiOperation(value = "Removes the stack") @ApiResponses({ @ApiResponse(code = 204, message = "The stack successfully removed"), @ApiResponse(code = 403, message = "The user does not have access to remove the stack"), @ApiResponse(code = 404, message = "The stack doesn't exist"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public void removeStack(@ApiParam("The stack id") @PathParam("id") final String id) throws ApiException { stackDao.remove(id); }
private ServiceDescriptor generateServiceDescriptor( UriInfo uriInfo, Class<? extends Service> service) { final List<Link> links = new ArrayList<>(); for (Method method : service.getMethods()) { final GenerateLink generateLink = method.getAnnotation(GenerateLink.class); if (generateLink != null) { try { links.add(generateLinkForMethod(uriInfo, generateLink.rel(), method)); } catch (RuntimeException ignored) { } } } final Description description = service.getAnnotation(Description.class); final ServiceDescriptor dto = createServiceDescriptor() .withHref(uriInfo.getRequestUriBuilder().replaceQuery(null).build().toString()) .withLinks(links) .withVersion(Constants.API_VERSION); if (description != null) { dto.setDescription(description.value()); } return dto; }
@GET @Path("/{id}") @Produces(APPLICATION_JSON) @GenerateLink(rel = LINK_REL_GET_STACK_BY_ID) @ApiOperation( value = "Get the stack by id", notes = "This operation can be performed for stack owner, or for predefined stacks") @ApiResponses({ @ApiResponse(code = 200, message = "The response contains requested stack entity"), @ApiResponse(code = 404, message = "The requested stack was not found"), @ApiResponse(code = 403, message = "The user has not permission get requested stack"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public StackDto getStack(@ApiParam("The stack id") @PathParam("id") final String id) throws ApiException { return asStackDto(stackDao.getById(id)); }
/** * Gets OAuth token for user. * * @param oauthProvider OAuth provider name * @return OAuthToken * @throws ServerException */ @GET @Path("token") @Produces(MediaType.APPLICATION_JSON) public OAuthToken token(@Required @QueryParam("oauth_provider") String oauthProvider) throws ServerException, UnauthorizedException, NotFoundException, ForbiddenException, BadRequestException, ConflictException { return oAuthAPI.getToken(oauthProvider); }
@OPTIONS @Produces(MediaType.APPLICATION_JSON) public ServiceDescriptor getServiceDescriptor() { return generateServiceDescriptor(uriInfo, getClass()); }
@DELETE @Path("/{id}/icon") @GenerateLink(rel = LINK_REL_DELETE_ICON) @ApiOperation( value = "Delete icon for required stack", notes = "This operation can be performed only by authorized stack owner") @ApiResponses({ @ApiResponse(code = 204, message = "Icon was successfully removed"), @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 or icon doesn't exist"), @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 void removeIcon(@ApiParam("The stack Id") @PathParam("id") final String id) throws NotFoundException, ServerException, ConflictException, ForbiddenException, BadRequestException { StackImpl stack = stackDao.getById(id); stack.setStackIcon(null); stackDao.update(stack); }
@GET @Path("edits") @Produces(MediaType.APPLICATION_JSON) public List<EditedRegion> getEditedRegions(@Required @QueryParam("filePath") String file) throws ApiException { requiredNotNull(file, "File path"); try (GitConnection gitConnection = getGitConnection()) { return gitConnection.getEditedRegions(file); } }
@GET @Produces(APPLICATION_JSON) @GenerateLink(rel = LINK_REL_SEARCH_STACKS) @ApiOperation( value = "Get the list stacks with required tags",
@GET @Path("/{id}/icon") @Produces("image/*") @GenerateLink(rel = LINK_REL_GET_ICON) @ApiOperation( value = "Get icon by stack id", notes = "This operation can be performed only by authorized user", response = byte[].class) @ApiResponses({ @ApiResponse(code = 200, message = "The response contains requested image entity"), @ApiResponse(code = 403, message = "The user does not have access to get image entity"), @ApiResponse(code = 500, message = "Internal server error occurred") }) public Response getIcon(@ApiParam("The stack id") @PathParam("id") final String id) throws NotFoundException, ServerException, BadRequestException { StackImpl stack = stackDao.getById(id); if (stack == null) { throw new NotFoundException("Stack with id '" + id + "' was not found."); } StackIcon image = stack.getStackIcon(); if (image == null) { throw new NotFoundException("Image for stack with id '" + id + "' was not found."); } return Response.ok(image.getData(), image.getMediaType()).build(); }
@Consumes(MULTIPART_FORM_DATA) @Produces(TEXT_PLAIN) @GenerateLink(rel = LINK_REL_UPLOAD_ICON) @ApiOperation( value = "Upload icon for required stack",
@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)); }
@Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @GenerateLink(rel = Constants.LINK_REL_GENERATE_PAIR) @ApiOperation( value = "Generate and stores ssh pair based on the request",
@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 {
@Produces(APPLICATION_JSON) @Consumes(APPLICATION_JSON) @GenerateLink(rel = LINK_REL_UPDATE_STACK) @ApiOperation( value =
@POST @Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON) @GenerateLink(rel = LINK_REL_CREATE_STACK) @ApiOperation( value = "Create a new stack",