Class CommentResource
- java.lang.Object
-
- org.silverpeas.core.web.rs.RESTWebService
-
- org.silverpeas.core.webapi.comment.CommentResource
-
- All Implemented Interfaces:
ProtectedWebResource
,WebAuthenticationValidation
,WebAuthorizationValidation
,SilverpeasWebResource
@RequestScoped @Path("comments/{componentId}/{contentType}/{contentId}") @Authorized public class CommentResource extends RESTWebService
A REST Web resource representing a given comment. It is a web service that provides access to a comment referenced by its URL.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.silverpeas.core.web.rs.RESTWebService
RESTWebService.WebProcess<R>, RESTWebService.WebTreatment<R>
-
-
Field Summary
-
Fields inherited from class org.silverpeas.core.web.rs.RESTWebService
RESPONSE_HEADER_ARRAYSIZE
-
Fields inherited from interface org.silverpeas.core.web.SilverpeasWebResource
BASE_PATH
-
-
Constructor Summary
Constructors Constructor Description CommentResource()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CommentEntity[]
asWebEntities(List<Comment> comments)
Converts the specified list of comments into their corresponding web entities.protected CommentEntity
asWebEntity(Comment comment, URI commentURI)
Converts the comment into its corresponding web entity.protected void
checkIsValid(CommentEntity theComment)
Check the specified comment is valid.protected CommentService
commentService()
Gets a business service on comments.void
deleteComment(String onCommentId)
Deletes the specified existing comment.CommentEntity[]
getAllComments()
Gets the JSON representation of all the comments on referred the resource.CommentEntity
getComment(String onCommentId)
Gets the JSON representation of the specified existing comment.String
getComponentId()
Gets the identifier of the component instance to which the requested resource belongs to.protected String
getContentId()
protected String
getContentType()
protected String
getResourceBasePath()
Gets the base path of the web resource relative to the root path of all the web resources in Silverpeas as given bySilverpeasWebResource.getBasePath()
.protected URI
identifiedBy(URI uri)
protected String
inComponentId()
Gets the identifier of the Silverpeas instance to which the commented content belongs.protected String
onContentId()
Gets the identifier of the content that is commentable.protected String
onContentType()
Gets the type of the content that is commentable.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.CommentEntity
updateComment(String commentId, CommentEntity commentToUpdate)
Updates the comment from its JSON representation and returns it once updated.void
validateUserAuthorization(UserPrivilegeValidation validation)
Validates the authorization of the user to request this web service.-
Methods inherited from class org.silverpeas.core.web.rs.RESTWebService
createWebResourceUri, fromPage, getBundle, getBundleLocation, getHighestUserRole, getHttpRequest, getHttpServletRequest, getHttpServletResponse, getOrganisationController, getSilverpeasContext, getUri, getUser, getUserPreferences, getUserRoles, identifiedBy, identifiedBy, initContext, initWebResourceUri, isUserDefined, process
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.silverpeas.core.web.rs.WebAuthenticationValidation
validateUserAuthentication
-
-
-
-
Method Detail
-
getResourceBasePath
protected String getResourceBasePath()
Description copied from class:RESTWebService
Gets the base path of the web resource relative to the root path of all the web resources in Silverpeas as given bySilverpeasWebResource.getBasePath()
.- Specified by:
getResourceBasePath
in classRESTWebService
- Returns:
- the relative path that identifies this REST web service among all other REST web services.
-
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 authenticated, 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 referred the resource. If the user isn't authenticated, 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 referred 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 authenticated, 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 authenticated, 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 idempotent as defined in the HTTP specification. If the user isn't authenticated, 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.
-
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
-
-