Class CommentResource

    • Constructor Detail

      • CommentResource

        public CommentResource()
    • Method Detail

      • getComment

        @GET
        @Path("{commentId}")
        @Produces("application/json")
        public CommentEntity getComment​(@PathParam("commentId")
                                        String onCommentId)
        Gets the JSON representation of the specified existing comment. If the comment doesn't exist, a 404 HTTP code is returned. If the user isn't authentified, a 401 HTTP code is returned. If the user isn't authorized to access the comment, a 403 is returned. If a problem occurs when processing the request, a 503 HTTP code is returned.
        Parameters:
        onCommentId - the unique identifier of the comment.
        Returns:
        the response to the HTTP GET request with the JSON representation of the asked comment.
      • getAllComments

        @GET
        @Produces("application/json")
        public CommentEntity[] getAllComments()
        Gets the JSON representation of all the comments on refered the resource. If the user isn't authentified, a 401 HTTP code is returned. If the user isn't authorized to access the comment, a 403 is returned. If a problem occurs when processing the request, a 503 HTTP code is returned.
        Returns:
        the response to the HTTP GET request with the JSON representation of the comments on the refered resource.
      • saveNewComment

        @POST
        @Produces("application/json")
        @Consumes("application/json")
        public javax.ws.rs.core.Response saveNewComment​(CommentEntity commentToSave)
        Creates a new comment from its JSON representation and returns it with its URI identifying it in Silverpeas. The unique identifier of the comment isn't taken into account, so if the comment already exist, it is then cloned with a new identifier (thus with a new URI). If the user isn't authentified, a 401 HTTP code is returned. If the user isn't authorized to save the comment, a 403 is returned. If a problem occurs when processing the request, a 503 HTTP code is returned.
        Parameters:
        commentToSave - the comment to save in Silverpeas.
        Returns:
        the response to the HTTP POST request with the JSON representation of the saved comment.
      • updateComment

        @PUT
        @Produces("application/json")
        @Consumes("application/json")
        @Path("{commentId}")
        public CommentEntity updateComment​(@PathParam("commentId")
                                           String commentId,
                                           CommentEntity commentToUpdate)
        Updates the comment from its JSON representation and returns it once updated. If the comment to update doesn't match with the requested one, a 400 HTTP code is returned. If the comment doesn't exist, a 404 HTTP code is returned. If the user isn't authentified, a 401 HTTP code is returned. If the user isn't authorized to save the comment, a 403 is returned. If a problem occurs when processing the request, a 503 HTTP code is returned.
        Parameters:
        commentId - the unique identifier of the comment to update.
        commentToUpdate - the comment to update in Silverpeas.
        Returns:
        the response to the HTTP PUT request with the JSON representation of the updated comment.
      • deleteComment

        @DELETE
        @Path("{commentId}")
        public void deleteComment​(@PathParam("commentId")
                                  String onCommentId)
        Deletes the specified existing comment. If the comment doesn't exist, nothing is done, so that the HTTP DELETE request remains indempotent as defined in the HTTP specification.. If the user isn't authentified, a 401 HTTP code is returned. If the user isn't authorized to access the comment, a 403 is returned. If a problem occurs when processing the request, a 503 HTTP code is returned.
        Parameters:
        onCommentId - the unique identifier of the comment to delete.
      • inComponentId

        protected String inComponentId()
        Gets the identifier of the Silverpeas instance to which the commented content belongs.
        Returns:
        the Silverpeas component instance identifier.
      • onContentType

        protected String onContentType()
        Gets the type of the content that is commentable.
        Returns:
        the type of the commentable content.
      • onContentId

        protected String onContentId()
        Gets the identifier of the content that is commentable.
        Returns:
        the identifier of the commentable content.
      • commentService

        protected CommentService commentService()
        Gets a business service on comments.
        Returns:
        a comment service instance.
      • asWebEntities

        protected CommentEntity[] asWebEntities​(List<Comment> comments)
        Converts the specified list of comments into their corresponding web entities.
        Parameters:
        comments - the comments to convert.
        Returns:
        an array with the corresponding comment entities.
      • asWebEntity

        protected CommentEntity asWebEntity​(Comment comment,
                                            URI commentURI)
        Converts the comment into its corresponding web entity.
        Parameters:
        comment - the comment to convert.
        commentURI - the URI of the comment.
        Returns:
        the corresponding comment entity.
      • identifiedBy

        protected URI identifiedBy​(URI uri)
      • getComponentId

        public String getComponentId()
        Description copied from interface: SilverpeasWebResource
        Gets the identifier of the component instance to which the requested resource belongs to.
        Returns:
        the identifier of the Silverpeas component instance.
      • getContentType

        protected String getContentType()
      • getContentId

        protected String getContentId()
      • checkIsValid

        protected void checkIsValid​(CommentEntity theComment)
        Check the specified comment is valid. A comment is valid if the following attributes are set: componentId, resourceId, text and its author identifier.
        Parameters:
        theComment - the comment to validate.
      • validateUserAuthorization

        public void validateUserAuthorization​(UserPrivilegeValidation validation)
        Description copied from interface: ProtectedWebResource
        Validates the authorization of the user to request this web service. For doing, the user must have the rights to access the component instance that manages this web resource. If no such component instance exists, a Not Found HTTP error is thrown (status code 404). Otherwise the validation is delegated to the validation service by passing it the required information.

        This method should be invoked for web service requiring an authorized access. For doing, the authentication of the user must be first valdiated. Otherwise, the annotation Authorized can be also used instead at class level for both authentication and authorization.

        Parameters:
        validation - the validation instance to use.
        See Also:
        UserPrivilegeValidator