Class AbstractComment

java.lang.Object
org.ametys.cms.repository.comment.AbstractComment
All Implemented Interfaces:
ReactionableObject, ReportableObject
Direct Known Subclasses:
Comment, RichTextComment

public abstract class AbstractComment extends Object implements ReactionableObject, ReportableObject
  • Field Details

  • Constructor Details

    • AbstractComment

      public AbstractComment(ModifiableModelLessDataHolder rootDataHolder, String commentId)
      Retrieves a comment by its id
      Parameters:
      rootDataHolder - The root data holder hosting the first level of comments
      commentId - The id of the comment to retrieve
      Throws:
      AmetysRepositoryException - if an error occurred
    • AbstractComment

      Creates a new comment
      Parameters:
      dataHolder - The data holder where to add the new comment
    • AbstractComment

      public AbstractComment(ModifiableModelLessDataHolder dataHolder, String commentId, ZonedDateTime creationDate)
      Creates a new comment, with the given id and creation date This method allows to create a comment from existing data (ex: data import from archive) The id is not generated here, the source is trusted. Be careful using this method
      Parameters:
      dataHolder - The data holder where to add the new comment
      commentId - the comment's id
      creationDate - the comment's creation date
    • AbstractComment

      protected AbstractComment(ModifiableModelLessDataHolder dataHolder, Optional<String> commentId, Optional<ZonedDateTime> creationDate)
      Creates a new comment on the content, with the given id and creation date This method allow to create a comment from existing data (ex: data import from archive) The id is not generated here, the source is trusted. Be careful using this method
      Parameters:
      dataHolder - The data holder of the content where to add the new comment
      commentId - the comment's id
      creationDate - the comment's creation date
    • AbstractComment

      Creates a new sub comment of the comment
      Parameters:
      comment - The parent comment
    • AbstractComment

      public AbstractComment(AbstractComment comment, String commentId, ZonedDateTime creationDate)
      Creates a new sub comment of the comment, with the given id and creation date This method allow to create a sub comment from existing data (ex: data import from archive) The id is not generated here, the source is trusted. Be careful using this method
      Parameters:
      comment - The parent comment
      commentId - the sub comment's id
      creationDate - the sub comment's creation date
    • AbstractComment

      protected AbstractComment(AbstractComment comment, Optional<String> commentId, Optional<ZonedDateTime> creationDate)
      Creates a new sub comment of the comment, with the given id and creation date This method allow to create a sub comment from existing data (ex: data import from archive) The id is not generated here, the source is trusted. Be careful using this method
      Parameters:
      comment - The parent comment
      commentId - the sub comment's id
      creationDate - the sub comment's creation date
  • Method Details

    • getCommentDataPath

      protected String getCommentDataPath(String commentId)
      Retrieves the path of the comment with the given identifier
      Parameters:
      commentId - the comment identifier
      Returns:
      the path of the comment
    • getRepositoryData

      Retrieves the repository data of the AbstractComment
      Returns:
      the repository data of the AbstractComment
    • getId

      public String getId()
      The comment id (unique to the ametys object)
      Returns:
      The id. Cannot be null.
    • getCreationDate

      Get the date and time the comment was created
      Returns:
      The non null date of creation of the comment.
    • getAuthor

      Get the comment's author
      Returns:
      the comment's author
    • setAuthor

      public void setAuthor(UserIdentity author)
      Set the comment's author.
      Parameters:
      author - the author. Can be null to remove the name.
    • getAuthorName

      Get the readable name of the author.
      Returns:
      The full name. Can be null.
    • setAuthorName

      public void setAuthorName(String name)
      Set the readable name of the author.
      Parameters:
      name - The full name. Can be null to remove the name.
    • getAuthorEmail

      Get the email of the author.
      Returns:
      The ameil. Can be null.
    • setAuthorEmail

      public void setAuthorEmail(String email)
      Set the email of the author.
      Parameters:
      email - The email. Can be null to remove the email.
    • getAuthorURL

      public String getAuthorURL()
      Get the url given by the author as its personal site url.
      Returns:
      The url. Can be null.
    • setAuthorURL

      public void setAuthorURL(String url)
      Set the personal site url of the author
      Parameters:
      url - The url. Can be null to remove url.
    • isEmailHidden

      public boolean isEmailHidden()
      Does the email of the authors have to be hidden ?
      Returns:
      true (default value) if the email does not have to appears to others users. Can still be used for administration.
    • setEmailHiddenStatus

      public void setEmailHiddenStatus(boolean hideEmail)
      Set the email hidden status.
      Parameters:
      hideEmail - true to set the email as hidden.
    • isEdited

      public boolean isEdited()
      Does the comment is edited
      Returns:
      true the email is edited
    • setEdited

      public void setEdited(boolean isEdited)
      Set the comment to edited.
      Parameters:
      isEdited - true to set the comment to edited.
    • isDeleted

      public boolean isDeleted()
      Does the comment is deleted
      Returns:
      true the comment is deleted
    • setDeleted

      public void setDeleted(boolean isEdited)
      Set the comment to deleted.
      Parameters:
      isEdited - true to set the comment to deleted.
    • getContent

      public String getContent()
      Get the content of the comment. A simple String (with \n or \t).
      Returns:
      The content. Can be null.
    • setContent

      public void setContent(String content)
      Set the content of the comment.
      Parameters:
      content - The content to set. Can be null to remove the content. Have to be a simple String (with \n or \t).
    • extractMentions

      Extract users mentioned in the comment
      Returns:
      the mentioned users
    • isValidated

      public boolean isValidated()
      Is the comment validated
      Returns:
      the status of validation of the comment
    • setValidated

      public void setValidated(boolean validated)
      Set the validation status of the comment
      Parameters:
      validated - true the comment is validated
    • addReport

      public void addReport()
      Description copied from interface: ReportableObject
      Add a report to the object
      Specified by:
      addReport in interface ReportableObject
    • setReportsCount

      public void setReportsCount(long reportsCount)
      Description copied from interface: ReportableObject
      Sets the number of reports on the object
      Specified by:
      setReportsCount in interface ReportableObject
      Parameters:
      reportsCount - the number of reports to set
    • clearReports

      public void clearReports()
      Description copied from interface: ReportableObject
      Remove all reports on the object
      Specified by:
      clearReports in interface ReportableObject
    • getReportsCount

      public long getReportsCount()
      Description copied from interface: ReportableObject
      Retrieves the number of reports on the object
      Specified by:
      getReportsCount in interface ReportableObject
      Returns:
      the number of reports
    • remove

      public void remove()
      Remove the comment.
    • getSubComment

      public abstract <T extends AbstractComment> List<T> getSubComment(boolean includeNotValidatedComments, boolean includeValidatedComments)
      Get sub comments of the comment
      Type Parameters:
      T - type of the value to retrieve
      Parameters:
      includeNotValidatedComments - True to include the comments that are not validated
      includeValidatedComments - True to include the comments that are validated
      Returns:
      the list of comments
    • createSubComment

      public abstract <T extends AbstractComment> T createSubComment()
      Create sub comment from this comment
      Type Parameters:
      T - type of the value to retrieve
      Returns:
      the sub comment
    • createSubComment

      public abstract <T extends AbstractComment> T createSubComment(String commentId, ZonedDateTime creationDate)
      Creates a sub comment from this comment, with the given id and creation date This method allow to create a sub comment from existing data (ex: data import from archive) The id is not generated here, the source is trusted. Be careful using this method
      Type Parameters:
      T - type of the value to retrieve
      Parameters:
      commentId - the comment's id
      creationDate - the comment's creation date
      Returns:
      the new comment
    • update

      protected abstract void update()
      Update the comment tag statistics
    • getComments

      public static <T extends AbstractComment> List<T> getComments(T parentComment, boolean includeNotValidatedComments, boolean includeValidatedComments, BiFunction<ModifiableModelLessDataHolder,String,T> commentCreator) throws AmetysRepositoryException
      Get the sub comments of the given comment
      Type Parameters:
      T - type of the value to retrieve
      Parameters:
      parentComment - The parent comment
      includeNotValidatedComments - True to include the comments that are not validated
      includeValidatedComments - True to include the comments that are validated
      commentCreator - function to create new comment
      Returns:
      the list of sub comments
      Throws:
      AmetysRepositoryException - If an error occurred
    • getComments

      public static <T extends AbstractComment> List<T> getComments(AbstractComment parentComment, boolean includeNotValidatedComments, boolean includeValidatedComments, boolean withSubComment, BiFunction<ModifiableModelLessDataHolder,String,T> commentCreator) throws AmetysRepositoryException
      Get the sub comments of the given comment
      Type Parameters:
      T - type of the value to retrieve
      Parameters:
      parentComment - The parent comment
      includeNotValidatedComments - True to include the comments that are not validated
      includeValidatedComments - True to include the comments that are validated
      withSubComment - true if we want to get all child comments
      commentCreator - function to create new comment
      Returns:
      the list of comments
      Throws:
      AmetysRepositoryException - If an error occurred
    • getComments

      public static <T extends AbstractComment> List<T> getComments(ModifiableModelLessDataHolder rootDataHolder, boolean includeNotValidatedComments, boolean includeValidatedComments, BiFunction<ModifiableModelLessDataHolder,String,T> commentCreator) throws AmetysRepositoryException
      Get the comments in the given root data holder
      Type Parameters:
      T - type of the value to retrieve
      Parameters:
      rootDataHolder - The root data holder
      includeNotValidatedComments - True to include the comments that are not validated
      includeValidatedComments - True to include the comments that are validated
      commentCreator - function to create new comment
      Returns:
      the list of comments
      Throws:
      AmetysRepositoryException - If an error occurred
    • getComments

      public static <T extends AbstractComment> List<T> getComments(ModifiableModelLessDataHolder rootDataHolder, boolean includeNotValidatedComments, boolean includeValidatedComments, boolean isRecursive, BiFunction<ModifiableModelLessDataHolder,String,T> commentCreator) throws AmetysRepositoryException
      Get the comments in the given root data holder
      Type Parameters:
      T - type of the value to retrieve
      Parameters:
      rootDataHolder - The root data holder
      includeNotValidatedComments - True to include the comments that are not validated
      includeValidatedComments - True to include the comments that are validated
      isRecursive - true if we want to have sub comments
      commentCreator - function to create new comment
      Returns:
      the list of comments
      Throws:
      AmetysRepositoryException - If an error occurred
    • addReaction

      public void addReaction(UserIdentity user, ReactionableObject.ReactionType reactionType)
      Description copied from interface: ReactionableObject
      Add the user reaction
      Specified by:
      addReaction in interface ReactionableObject
      Parameters:
      user - the user
      reactionType - the reaction type
    • removeReaction

      public void removeReaction(UserIdentity user, ReactionableObject.ReactionType reactionType)
      Description copied from interface: ReactionableObject
      Remove the user reaction
      Specified by:
      removeReaction in interface ReactionableObject
      Parameters:
      user - the user
      reactionType - the reaction type
    • getReactionUsers

      Description copied from interface: ReactionableObject
      Get the list of users who react
      Specified by:
      getReactionUsers in interface ReactionableObject
      Parameters:
      reactionType - the reaction type
      Returns:
      the list of users
    • getCommentParent

      public abstract <T extends AbstractComment> T getCommentParent()
      Get parent of comment if exists
      Type Parameters:
      T - type of the value to retrieve
      Returns:
      the comment parent. null if the comment is not a sub comment
    • isSubComment

      public boolean isSubComment()
      Check if the comment is a sub-comment from an other comment
      Returns:
      true if the comment is a sub-comment
    • hasSubComments

      public boolean hasSubComments()
      Check if the comment have any sub-comments
      Returns:
      true if the comment have any sub-comments
    • isAccepted

      public boolean isAccepted()
      Is the comment the accepted answer
      Returns:
      true if the comment is the accepted answer
    • setAccepted

      public void setAccepted(boolean isAccepted)
      Set the comment as accepted answer.
      Parameters:
      isAccepted - true to set the comment as accepted answer.