com.silverpeas.comment.web
Class CommentResource

java.lang.Object
  extended by com.silverpeas.web.RESTWebService
      extended by com.silverpeas.comment.web.CommentResource

@Service
@RequestScoped
@Authorized
public class CommentResource
extends RESTWebService

A REST Web resource representing a given comment. It is a web service that provides an access to a comment referenced by its URL.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.silverpeas.web.RESTWebService
RESTWebService.WebProcess<RETURN_VALUE>, RESTWebService.WebTreatment<RETURN_VALUE>
 
Field Summary
 
Fields inherited from class com.silverpeas.web.RESTWebService
RESPONSE_HEADER_ARRAYSIZE, REST_WEB_SERVICES_URI_BASE
 
Constructor Summary
CommentResource()
           
 
Method Summary
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 static Comparator<Comment> byId()
          Gets a comparator of comments by their identifier, from the lower to the higher one.
protected  CommentPK byPK(String id, String componentId)
          Gets the primary key of the specified resource.
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 refered 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  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.
 
Methods inherited from class com.silverpeas.web.RESTWebService
getBundle, getBundleLocation, getGreaterUserRole, getHttpRequest, getHttpServletRequest, getHttpServletResponse, getOrganisationController, getUriInfo, getUserDetail, getUserPreferences, getUserRoles, process, validateUserAuthentication, validateUserAuthorization
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommentResource

public CommentResource()
Method Detail

getComment

public CommentEntity getComment(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

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

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

public CommentEntity updateComment(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

public void deleteComment(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.

byPK

protected CommentPK byPK(String id,
                         String componentId)
Gets the primary key of the specified resource.

Parameters:
id - the unique identifier of the resource.
componentId - the unique identifier of the component instance to which the resource belongs.
Returns:
the primary key of the resource.

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 class: RESTWebService
Gets the identifier of the component instance to which the requested resource belongs to.

Specified by:
getComponentId in class RESTWebService
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.

byId

protected static Comparator<Comment> byId()
Gets a comparator of comments by their identifier, from the lower to the higher one.

Returns:
a comparator of comments.


Copyright © 2016 Silverpeas. All Rights Reserved.