Class CommentsDAO
java.lang.Object
org.ametys.runtime.plugin.component.AbstractLogEnabled
org.ametys.cms.repository.comment.CommentsDAO
- All Implemented Interfaces:
LogEnabled
,Component
,Contextualizable
,Serviceable
- Direct Known Subclasses:
CommentsDAO
public class CommentsDAO
extends AbstractLogEnabled
implements Component, Serviceable, Contextualizable
DAO for content's comments
-
Field Summary
Modifier and TypeFieldDescriptionprotected Context
The avalon contextprotected ObservationManager
The observation managerprotected ReactionableObjectHelper
Helper for reactionable objectprotected AmetysObjectResolver
The Ametys object resolverprotected RightManager
The right managerprotected UserHelper
The user helperprotected UserManager
The user managerprotected CurrentUserProvider
The currenrt user providerstatic final String
The form input name for author emailstatic final String
The form input name for author email to hidestatic final String
The form input name for author namestatic final String
The form input name for author urlstatic final String
The form input name for captchastatic final String
The form input name for captchastatic final String
The form input name for contentstatic final String
The Avalon rolestatic final Pattern
The pattern to check url -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription_setCommentAttributes
(CommentableContent content, Comment comment, Map<String, Object> formValues) Set comment attributesaddComment
(String contentId, String commentId, Map<String, Object> formValues, Map<String, Object> contextualParameters) Add a new commentboolean
canDeleteComment
(String contentId) Determines if current user is allowed to delete a commentvoid
contextualize
(Context context) deleteComment
(String contentId, String commentId) Delete a commentgetComment
(Comment comment, int level, Map<String, Object> contextualParameters) Get JSON representation of a commentgetComments
(String contentId, Map<String, Object> contextualParameters) Get the content's commentsprotected CommentableContent
getContent
(String contentId) Get the commentable contentprotected UserIdentity
Get the current usergetErrors
(CommentableContent content, Map<String, Object> formValues) Get errors when submitting commentboolean
isCaptchaRequired
(Content content) Checks if a captcha have to be checked.boolean
isValidatedByDefault
(Content content) Get the validation flag default value for a content asking all listenerslikeOrUnlikeComment
(String contentId, String commentId) React (like or unlike) to a commentlikeOrUnlikeComment
(String contentId, String commentId, Boolean remove) React (like or unlike) to a commentreportComment
(String contentId, String commentId) Report a commentvoid
saxComment
(ContentHandler contentHandler, Comment comment, int level) SAX a commentprotected void
saxCommentAdditionalProperties
(ContentHandler contentHandler, Comment comment, int level) SAX additional comment propertiesvoid
service
(ServiceManager smanager) Methods inherited from class org.ametys.runtime.plugin.component.AbstractLogEnabled
getLogger, setLogger
-
Field Details
-
ROLE
The Avalon role -
FORM_AUTHOR_NAME
The form input name for author name- See Also:
-
FORM_AUTHOR_EMAIL
The form input name for author email- See Also:
-
FORM_AUTHOR_HIDEEMAIL
The form input name for author email to hide- See Also:
-
FORM_AUTHOR_URL
The form input name for author url- See Also:
-
FORM_CONTENTTEXT
The form input name for content- See Also:
-
FORM_CAPTCHA_KEY
The form input name for captcha- See Also:
-
FORM_CAPTCHA_VALUE
The form input name for captcha- See Also:
-
URL_VALIDATOR
The pattern to check url -
_resolver
The Ametys object resolver -
_observationManager
The observation manager -
_userProvider
The currenrt user provider -
_userHelper
The user helper -
_rightManager
The right manager -
_reactionableHelper
Helper for reactionable object -
_userManager
The user manager -
_context
The avalon context
-
-
Constructor Details
-
CommentsDAO
public CommentsDAO()
-
-
Method Details
-
service
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
contextualize
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
getComments
public List<Map<String,Object>> getComments(String contentId, Map<String, Object> contextualParameters) Get the content's comments- Parameters:
contentId
- the content idcontextualParameters
- the contextual parameters- Returns:
- the comments
-
addComment
public Map<String,Object> addComment(String contentId, String commentId, Map<String, Object> formValues, Map<String, Object> contextualParameters) Add a new comment- Parameters:
contentId
- the content idcommentId
- the id of of parent comment. Can be null if it is not a subcommentformValues
- the form's valuescontextualParameters
- the contextual parameters- Returns:
- the results
-
deleteComment
public Map<String,Object> deleteComment(String contentId, String commentId) throws IllegalAccessException Delete a comment- Parameters:
contentId
- the content idcommentId
- the comment id to remove- Returns:
- the results
- Throws:
IllegalAccessException
- if current user is null
-
canDeleteComment
Determines if current user is allowed to delete a comment- Parameters:
contentId
- the content id- Returns:
- true if the current user is allowed
-
likeOrUnlikeComment
public Map<String,Object> likeOrUnlikeComment(String contentId, String commentId) throws IllegalAccessException React (like or unlike) to a comment- Parameters:
contentId
- the content idcommentId
- the comment id- Returns:
- the results
- Throws:
IllegalAccessException
- if current user is null
-
likeOrUnlikeComment
public Map<String,Object> likeOrUnlikeComment(String contentId, String commentId, Boolean remove) throws IllegalAccessException React (like or unlike) to a comment- Parameters:
contentId
- the content idcommentId
- the comment idremove
- true to remove the reaction, false to add reaction. If null, check if the current user has already like the comment.- Returns:
- the results
- Throws:
IllegalAccessException
- if current user is null
-
getContent
Get the commentable content- Parameters:
contentId
- The content id- Returns:
- The content
-
_setCommentAttributes
protected Map<String,Object> _setCommentAttributes(CommentableContent content, Comment comment, Map<String, Object> formValues) Set comment attributes- Parameters:
content
- the contentcomment
- the commentformValues
- the form's values- Returns:
- the result
-
reportComment
Report a comment- Parameters:
contentId
- the content idcommentId
- the comment id- Returns:
- the results
-
isValidatedByDefault
Get the validation flag default value for a content asking all listeners- Parameters:
content
- The content having a new comment- Returns:
- a positive value if the comments have to be validated by default or a negative value in the other case. The absolute value is the priority of your listener. E.G. If a listener set +1 and another -10: the sum is negative (so comments not validated be default).
-
isCaptchaRequired
Checks if a captcha have to be checked.- Parameters:
content
- The content to comment- Returns:
- true if the comments have to be protected by a captcha or false otherwise
-
getErrors
Get errors when submitting comment- Parameters:
content
- The content to commentformValues
- The form values to submit a comment- Returns:
- An list of error messages (empty if no errors)
-
getCurrentUser
Get the current user- Returns:
- The current user
-
getComment
public Map<String,Object> getComment(Comment comment, int level, Map<String, Object> contextualParameters) Get JSON representation of a comment- Parameters:
comment
- the commentlevel
- the level of comment (0 for parent comment, 1 for sub-comment, etc ....)contextualParameters
- the contextual parameters- Returns:
- the comment as JSON
-
saxComment
public void saxComment(ContentHandler contentHandler, Comment comment, int level) throws SAXException SAX a comment- Parameters:
contentHandler
- the content handlercomment
- the commentlevel
- the level of comment- Throws:
SAXException
- if an error occurred hile saxing
-
saxCommentAdditionalProperties
protected void saxCommentAdditionalProperties(ContentHandler contentHandler, Comment comment, int level) throws SAXException SAX additional comment properties- Parameters:
contentHandler
- the content handlercomment
- the commentlevel
- the level of comment- Throws:
SAXException
- if an error occurred hile saxing
-