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
A comment on a
CommentableAmetysObject-
Nested Class Summary
Nested classes/interfaces inherited from interface org.ametys.cms.repository.ReactionableObject
ReactionableObject.ReactionType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ModifiableModelLessCompositeThe node of the commentprotected StringThe id of the comment (unique in the ametys object)protected ModifiableModelLessDataHolderThe root data holder where to store the first level of commentsstatic final StringConstant for the prefix of comments' namestatic final StringConstants for the separatorstatic final StringConstants for author Metadatastatic final StringConstants for author email Metadatastatic final StringConstants for author email hidden Metadatastatic final StringConstants for author name Metadatastatic final StringConstants for author url Metadatastatic final StringConstants for the content Metadatastatic final StringConstants for creation Metadatastatic final StringConstants for the is marked status Metadatastatic final StringConstants for the is deleted status Metadatastatic final StringConstants for the is edited status Metadatastatic final StringConstants for last modification Metadatastatic final StringConstants for the validated status Metadatastatic final StringConstants for comments Metadata validatedstatic final StringConstants for comments Metadata not validtedstatic final StringConstants for sub comments data name -
Constructor Summary
ConstructorsModifierConstructorDescriptionAbstractComment(AbstractComment comment) Creates a new sub comment of the commentAbstractComment(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.protectedAbstractComment(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.AbstractComment(ModifiableModelLessDataHolder dataHolder) Creates a new commentAbstractComment(ModifiableModelLessDataHolder rootDataHolder, String commentId) Retrieves a comment by its idAbstractComment(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.protectedAbstractComment(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. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddReaction(UserIdentity user, ReactionableObject.ReactionType reactionType) Add the user reactionvoidAdd a report to the objectvoidRemove all reports on the objectabstract <T extends AbstractComment>
TCreate sub comment from this commentabstract <T extends AbstractComment>
TcreateSubComment(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.Get the comment's authorGet the email of the author.Get the readable name of the author.Get the url given by the author as its personal site url.protected StringgetCommentDataPath(String commentId) Retrieves the path of the comment with the given identifierabstract <T extends AbstractComment>
TGet parent of comment if existsstatic <T extends AbstractComment>
List<T> getComments(AbstractComment parentComment, boolean includeNotValidatedComments, boolean includeValidatedComments, boolean withSubComment, BiFunction<ModifiableModelLessDataHolder, String, T> commentCreator) Get the sub comments of the given commentstatic <T extends AbstractComment>
List<T> getComments(ModifiableModelLessDataHolder rootDataHolder, boolean includeNotValidatedComments, boolean includeValidatedComments, boolean isRecursive, BiFunction<ModifiableModelLessDataHolder, String, T> commentCreator) Get the comments in the given root data holderstatic <T extends AbstractComment>
List<T> getComments(ModifiableModelLessDataHolder rootDataHolder, boolean includeNotValidatedComments, boolean includeValidatedComments, BiFunction<ModifiableModelLessDataHolder, String, T> commentCreator) Get the comments in the given root data holderstatic <T extends AbstractComment>
List<T> getComments(T parentComment, boolean includeNotValidatedComments, boolean includeValidatedComments, BiFunction<ModifiableModelLessDataHolder, String, T> commentCreator) Get the sub comments of the given commentGet the content of the comment.Get the date and time the comment was createdgetId()The comment id (unique to the ametys object)Get the date and time the comment was last modifiedgetReactionUsers(ReactionableObject.ReactionType reactionType) Get the list of users who reactlongRetrieves the number of reports on the objectRetrieves the repository data of theAbstractCommentabstract <T extends AbstractComment>
List<T> getSubComment(boolean includeNotValidatedComments, boolean includeValidatedComments) Get sub comments of the commentbooleanCheck if the comment have any sub-commentsbooleanIs the comment the accepted answerbooleanDoes the comment is deletedbooleanisEdited()Does the comment is editedbooleanDoes the email of the authors have to be hidden ?booleanCheck if the comment is a sub-comment from an other commentbooleanIs the comment validatedvoidremove()Remove the comment.voidremoveReaction(UserIdentity user, ReactionableObject.ReactionType reactionType) Remove the user reactionvoidsetAccepted(boolean isAccepted) Set the comment as accepted answer.voidsetAuthor(UserIdentity author) Set the comment's author.voidsetAuthorEmail(String email) Set the email of the author.voidsetAuthorName(String name) Set the readable name of the author.voidsetAuthorURL(String url) Set the personal site url of the authorvoidsetContent(String content) Set the content of the comment.voidsetDeleted(boolean isEdited) Set the comment to deleted.voidsetEdited(boolean isEdited) Set the comment to edited.voidsetEmailHiddenStatus(boolean hideEmail) Set the email hidden status.voidsetLastModificationDate(ZonedDateTime lastModificationDate) Set the date and time the comment was last modifiedvoidsetReportsCount(long reportsCount) Sets the number of reports on the objectvoidsetValidated(boolean validated) Set the validation status of the commentprotected abstract voidupdate()Update the comment tag statistics
-
Field Details
-
METADATA_COMMENTS_VALIDATED
Constants for comments Metadata not validted- See Also:
-
METADATA_COMMENTS_NOTVALIDATED
Constants for comments Metadata validated- See Also:
-
SUB_COMMENTS_DATA_NAME
Constants for sub comments data name- See Also:
-
METADATA_COMMENT_CREATIONDATE
Constants for creation Metadata- See Also:
-
METADATA_COMMENT_LAST_MODIFICATION_DATE
Constants for last modification Metadata- See Also:
-
METADATA_COMMENT_AUTHOR
Constants for author Metadata- See Also:
-
METADATA_COMMENT_AUTHORNAME
Constants for author name Metadata- See Also:
-
METADATA_COMMENT_AUTHOREMAIL
Constants for author email Metadata- See Also:
-
METADATA_COMMENT_AUTHOREMAIL_HIDDEN
Constants for author email hidden Metadata- See Also:
-
METADATA_COMMENT_AUTHORURL
Constants for author url Metadata- See Also:
-
METADATA_COMMENT_CONTENT
Constants for the content Metadata- See Also:
-
METADATA_COMMENT_VALIDATED
Constants for the validated status Metadata- See Also:
-
METADATA_COMMENT_IS_EDITED
Constants for the is edited status Metadata- See Also:
-
METADATA_COMMENT_IS_DELETED
Constants for the is deleted status Metadata- See Also:
-
METADATA_COMMENT_IS_ACCEPTED
Constants for the is marked status Metadata- See Also:
-
COMMENT_NAME_PREFIX
Constant for the prefix of comments' name- See Also:
-
ID_SEPARATOR
Constants for the separator- See Also:
-
_rootDataHolder
The root data holder where to store the first level of comments -
_commentComposite
The node of the comment -
_id
The id of the comment (unique in the ametys object)
-
-
Constructor Details
-
AbstractComment
Retrieves a comment by its id- Parameters:
rootDataHolder- The root data holder hosting the first level of commentscommentId- 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 commentcommentId- the comment's idcreationDate- 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 commentcommentId- the comment's idcreationDate- the comment's creation date
-
AbstractComment
Creates a new sub comment of the comment- Parameters:
comment- The parent comment
-
AbstractComment
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 commentcommentId- the sub comment's idcreationDate- 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 commentcommentId- the sub comment's idcreationDate- the sub comment's creation date
-
-
Method Details
-
getCommentDataPath
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 theAbstractComment- Returns:
- the repository data of the
AbstractComment
-
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.
-
getLastModificationDate
Get the date and time the comment was last modified- Returns:
- The non null date of last modification of the comment.
-
setLastModificationDate
Set the date and time the comment was last modified- Parameters:
lastModificationDate- the last modification date
-
getAuthor
Get the comment's author- Returns:
- the comment's author
-
setAuthor
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
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
Set the email of the author.- Parameters:
email- The email. Can be null to remove the email.
-
getAuthorURL
Get the url given by the author as its personal site url.- Returns:
- The url. Can be null.
-
setAuthorURL
Set the personal site url of the author- Parameters:
url- The url. Can be null to remove url.
-
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
Set the email hidden status.- Parameters:
hideEmail- true to set the email as hidden.
-
isEdited
Does the comment is edited- Returns:
- true the email is edited
-
setEdited
Set the comment to edited.- Parameters:
isEdited- true to set the comment to edited.
-
isDeleted
Does the comment is deleted- Returns:
- true the comment is deleted
-
setDeleted
Set the comment to deleted.- Parameters:
isEdited- true to set the comment to deleted.
-
getContent
Get the content of the comment. A simple String (with \n or \t).- Returns:
- The content. Can be null.
-
setContent
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).
-
isValidated
Is the comment validated- Returns:
- the status of validation of the comment
-
setValidated
Set the validation status of the comment- Parameters:
validated- true the comment is validated
-
addReport
Description copied from interface:ReportableObjectAdd a report to the object- Specified by:
addReportin interfaceReportableObject
-
setReportsCount
Description copied from interface:ReportableObjectSets the number of reports on the object- Specified by:
setReportsCountin interfaceReportableObject- Parameters:
reportsCount- the number of reports to set
-
clearReports
Description copied from interface:ReportableObjectRemove all reports on the object- Specified by:
clearReportsin interfaceReportableObject
-
getReportsCount
Description copied from interface:ReportableObjectRetrieves the number of reports on the object- Specified by:
getReportsCountin interfaceReportableObject- Returns:
- the number of reports
-
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 validatedincludeValidatedComments- True to include the comments that are validated- Returns:
- the list of comments
-
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 idcreationDate- the comment's creation date- Returns:
- the new comment
-
update
Update the comment tag statistics -
getComments
public static <T extends AbstractComment> List<T> getComments(T parentComment, boolean includeNotValidatedComments, boolean includeValidatedComments, BiFunction<ModifiableModelLessDataHolder, String, throws AmetysRepositoryExceptionT> commentCreator) Get the sub comments of the given comment- Type Parameters:
T- type of the value to retrieve- Parameters:
parentComment- The parent commentincludeNotValidatedComments- True to include the comments that are not validatedincludeValidatedComments- True to include the comments that are validatedcommentCreator- 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, throws AmetysRepositoryExceptionT> commentCreator) Get the sub comments of the given comment- Type Parameters:
T- type of the value to retrieve- Parameters:
parentComment- The parent commentincludeNotValidatedComments- True to include the comments that are not validatedincludeValidatedComments- True to include the comments that are validatedwithSubComment- true if we want to get all child commentscommentCreator- 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, throws AmetysRepositoryExceptionT> commentCreator) Get the comments in the given root data holder- Type Parameters:
T- type of the value to retrieve- Parameters:
rootDataHolder- The root data holderincludeNotValidatedComments- True to include the comments that are not validatedincludeValidatedComments- True to include the comments that are validatedcommentCreator- 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, throws AmetysRepositoryExceptionT> commentCreator) Get the comments in the given root data holder- Type Parameters:
T- type of the value to retrieve- Parameters:
rootDataHolder- The root data holderincludeNotValidatedComments- True to include the comments that are not validatedincludeValidatedComments- True to include the comments that are validatedisRecursive- true if we want to have sub commentscommentCreator- function to create new comment- Returns:
- the list of comments
- Throws:
AmetysRepositoryException- If an error occurred
-
addReaction
Description copied from interface:ReactionableObjectAdd the user reaction- Specified by:
addReactionin interfaceReactionableObject- Parameters:
user- the userreactionType- the reaction type
-
removeReaction
Description copied from interface:ReactionableObjectRemove the user reaction- Specified by:
removeReactionin interfaceReactionableObject- Parameters:
user- the userreactionType- the reaction type
-
getReactionUsers
Description copied from interface:ReactionableObjectGet the list of users who react- Specified by:
getReactionUsersin interfaceReactionableObject- Parameters:
reactionType- the reaction type- Returns:
- the list of users
-
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
Check if the comment is a sub-comment from an other comment- Returns:
- true if the comment is a sub-comment
-
hasSubComments
Check if the comment have any sub-comments- Returns:
- true if the comment have any sub-comments
-
isAccepted
Is the comment the accepted answer- Returns:
- true if the comment is the accepted answer
-
setAccepted
Set the comment as accepted answer.- Parameters:
isAccepted- true to set the comment as accepted answer.
-