Class DefaultCommentService

  • All Implemented Interfaces:
    ComponentInstanceDeletion, CommentService

    @Service
    @Named("commentService")
    public class DefaultCommentService
    extends Object
    implements CommentService, ComponentInstanceDeletion
    A service that provide the features to handle the comments in Silverpeas. Such features are, for example, retrieving comments on a given content, creating a comment into the business layer, indexing them, notifying components interested by the creation or the deletion of a comment, and so on. A comment is text written by users about a content published in Silverpeas. Such comment, as any other contents in Silverpeas, can be indexed in order to be found by the Silverpeas search engine. This service is managed by an IoC container and this be retrieved by dependency injection.
    • Constructor Detail

      • DefaultCommentService

        protected DefaultCommentService()
        Constructs a new DefaultCommentService instance.
    • Method Detail

      • getCommentDAO

        protected CommentDAO getCommentDAO()
        Gets the comment DAO with wich operations with the underlying data source can be performed.
        Returns:
        the DAO on the comments.
      • createComment

        public Comment createComment​(Comment cmt)
        Description copied from interface: CommentService
        Persists the specified comment and notifies any observers about the comment creation.
        Specified by:
        createComment in interface CommentService
        Parameters:
        cmt - the comment to save.
        Returns:
        the created comment with its unique identifier.
      • createAndIndexComment

        public Comment createAndIndexComment​(Comment cmt)
        Description copied from interface: CommentService
        Persists and indexes the specified comment and notifies any observers about the comment creation.
        Specified by:
        createAndIndexComment in interface CommentService
        Parameters:
        cmt - the comment to save and to index.
        Returns:
        the created comment with its unique identifier.
      • deleteComment

        public void deleteComment​(CommentId commentId)
        Description copied from interface: CommentService
        Deletes the comment identified by the specified identifier and notifies any observers about the comment deletion. Any indexes on it are removed. If no such comment exists with the specified identifier, then a CommentRuntimeException is thrown.
        Specified by:
        deleteComment in interface CommentService
        Parameters:
        commentId - the unique identifier of the comment to remove.
      • deleteAllCommentsOnResource

        public void deleteAllCommentsOnResource​(String resourceType,
                                                ResourceReference resourceRef)
        Description copied from interface: CommentService
        Deletes all the comments on the specified resource and notifies any observers about those comments deletion. If no such resource exists with the specified identifier then a CommentRuntimeException is thrown.
        Specified by:
        deleteAllCommentsOnResource in interface CommentService
        Parameters:
        resourceType - the type of the commented resource.
        resourceRef - a reference to the resource the comments are on.
      • deleteComment

        public void deleteComment​(Comment comment)
        Description copied from interface: CommentService
        Deletes the specified comment and notifies about any observers about his deletion. Any indexes on it are removed. If no such comment exists with the specified identifier, then a CommentRuntimeException is thrown.
        Specified by:
        deleteComment in interface CommentService
        Parameters:
        comment - the comment to remove.
      • moveComments

        public void moveComments​(String resourceType,
                                 ResourceReference fromResource,
                                 ResourceReference toResource)
        Description copied from interface: CommentService
        Moves the comments on the specified resource to the another specified resource. The resulting operation is that the comments will be on the other resource and all the previous indexes on them are removed. If at least one of the resources doesn't exist then a CommentRuntimeException is thrown.
        Specified by:
        moveComments in interface CommentService
        Parameters:
        resourceType - the type of the commented resource. Both the source and target resources have to be of the same type.
        fromResource - a reference to the source resource.
        toResource - a reference to the destination resource.
      • moveAndReindexComments

        public void moveAndReindexComments​(String resourceType,
                                           ResourceReference fromResource,
                                           ResourceReference toResource)
        Description copied from interface: CommentService
        Moves the comments on the specified resource to the another specified resource and indexes them again. The resulting operation is that the comments are on the other resource and they are indexed again (or simply indexed if not already) accordingly to the new resource. If at least one of the resources doesn't exist then a CommentRuntimeException is thrown.
        Specified by:
        moveAndReindexComments in interface CommentService
        Parameters:
        resourceType - the type of the commented resource. Both the source and target resources have to be of the same type.
        fromResource - a reference to the source resource.
        toResource - a reference to the destination resource.
      • updateComment

        public void updateComment​(Comment cmt)
        Description copied from interface: CommentService
        Updates the specified comment in the business layer. The comment to update is identified by its unique identifier and the update information are carried by the given Comment instance.
        Specified by:
        updateComment in interface CommentService
        Parameters:
        cmt - the updated comment.
      • updateAndIndexComment

        public void updateAndIndexComment​(Comment cmt)
        Description copied from interface: CommentService
        Updates and indexes the specified comment in the business layer. The comment to update in the business layer is identified by its unique identifier and the update information are carried by the given Comment instance.
        Specified by:
        updateAndIndexComment in interface CommentService
        Parameters:
        cmt - the comment to update and to index.
      • getComment

        public Comment getComment​(CommentId commentId)
        Description copied from interface: CommentService
        Gets the comment that identified by the specified identifier. If no such comment exists with the specified identifier, then a CommentRuntimeException is thrown.
        Specified by:
        getComment in interface CommentService
        Parameters:
        commentId - the identifier of the comment in the business layer.
        Returns:
        the comment.
      • getAllCommentsOnResource

        public List<Comment> getAllCommentsOnResource​(String resourceType,
                                                      ResourceReference resourceRef)
        Description copied from interface: CommentService
        Gets all the comments on the resource identified by the resource type and the specified reference. If no such publication exists with the specified resource reference, then a CommentRuntimeException is thrown.
        Specified by:
        getAllCommentsOnResource in interface CommentService
        Parameters:
        resourceType - the type of the commented resource.
        resourceRef - a reference to the resource.
        Returns:
        a list of the comments on the given resource. The list is empty if the resource isn't commented.
      • getMostCommentedPublicationsInfo

        public List<CommentedPublicationInfo> getMostCommentedPublicationsInfo​(String resourceType,
                                                                               List<ResourceReference> resourceRefs)
        Description copied from interface: CommentService
        Gets information about the commented resources among the specified ones. The resource information are returned ordered down to the lesser commented resource.
        Specified by:
        getMostCommentedPublicationsInfo in interface CommentService
        Parameters:
        resourceType - the type of the commented resource.
        resourceRefs - a collection of reference to the resources to get information and to order by comments count.
        Returns:
        an ordered list of information about the most commented resource. The list is sorted by their comments count in a descendent order.
      • getMostCommentedPublicationsInfo

        public List<CommentedPublicationInfo> getMostCommentedPublicationsInfo​(String resourceType)
        Description copied from interface: CommentService
        Gets information about the most commented resources of the specified type. The resource information are returned ordered down to the lesser commented resource.
        Specified by:
        getMostCommentedPublicationsInfo in interface CommentService
        Parameters:
        resourceType - the type of the commented resource.
        Returns:
        an ordered list of information about the most commented resources. The list is sorted by their comments count in a descendent order.
      • getAllMostCommentedPublicationsInfo

        public List<CommentedPublicationInfo> getAllMostCommentedPublicationsInfo()
        Description copied from interface: CommentService
        Gets information about all the commented resources in Silverpeas. The resource information are returned ordered down to the lesser commented resource.
        Specified by:
        getAllMostCommentedPublicationsInfo in interface CommentService
        Returns:
        an ordered list of information about the most commented resources. The list is sorted by their comments count in a descendent order.
      • getCommentsCountOnResource

        public int getCommentsCountOnResource​(String resourceType,
                                              ResourceReference ref)
        Description copied from interface: CommentService
        Gets the count of comments on the resource identifier by the resource type and the specified reference.
        Specified by:
        getCommentsCountOnResource in interface CommentService
        Parameters:
        resourceType - the type of the commented resource.
        ref - a reference on the resource.
        Returns:
        the number of comments on the resource.
      • getCommentCountIndexedByResource

        public Map<ResourceReference,​Integer> getCommentCountIndexedByResource​(String resourceType,
                                                                                     String instanceId)
        Description copied from interface: CommentService
        Gets the number of comments by resources of resource type and hosted by the specified component instance.
        Specified by:
        getCommentCountIndexedByResource in interface CommentService
        Parameters:
        resourceType - type of the commented publication.
        instanceId - identifier of aimed component instance.
        Returns:
        a map containing the number of comments by resources.
      • indexAllCommentsOnPublication

        public void indexAllCommentsOnPublication​(String resourceType,
                                                  ResourceReference ref)
        Description copied from interface: CommentService
        Indexes all the comments on the resource identified by the resource type and the specified reference. If no such resource exists with the specified reference, then a CommentRuntimeException is thrown.
        Specified by:
        indexAllCommentsOnPublication in interface CommentService
        Parameters:
        resourceType - the type of the commented resource.
        ref - a reference on the resource.
      • unindexAllCommentsOnPublication

        public void unindexAllCommentsOnPublication​(String resourceType,
                                                    ResourceReference ref)
        Description copied from interface: CommentService
        Removes the indexes on all the comments of the resource identified by the resource type and the specified reference. If no such resource exists with the specified reference, then a CommentRuntimeException is thrown.
        Specified by:
        unindexAllCommentsOnPublication in interface CommentService
        Parameters:
        resourceType - the type of the commented publication.
        ref - a reference on the resource.
      • getOrganisationController

        protected OrganizationController getOrganisationController()
        Gets an organization controller.
        Returns:
        an OrganizationController instance.
      • delete

        public void delete​(String componentInstanceId)
        Description copied from interface: ComponentInstanceDeletion
        Deletes the resources belonging to the specified component instance. This method is invoked by Silverpeas when a component instance is being deleted.
        Specified by:
        delete in interface ComponentInstanceDeletion
        Parameters:
        componentInstanceId - the unique identifier of a component instance.