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
Fields Modifier and Type Field Description protected Context
_context
The avalon contextprotected ObservationManager
_observationManager
The observation managerprotected ReactionableObjectHelper
_reactionableHelper
Helper for reactionable objectprotected AmetysObjectResolver
_resolver
The Ametys object resolverprotected RightManager
_rightManager
The right managerprotected UserHelper
_userHelper
The user helperprotected UserManager
_userManager
The user managerprotected CurrentUserProvider
_userProvider
The currenrt user providerstatic String
FORM_AUTHOR_EMAIL
The form input name for author emailstatic String
FORM_AUTHOR_HIDEEMAIL
The form input name for author email to hidestatic String
FORM_AUTHOR_NAME
The form input name for author namestatic String
FORM_AUTHOR_URL
The form input name for author urlstatic String
FORM_CAPTCHA_KEY
The form input name for captchastatic String
FORM_CAPTCHA_VALUE
The form input name for captchastatic String
FORM_CONTENTTEXT
The form input name for contentstatic String
ROLE
The Avalon rolestatic Pattern
URL_VALIDATOR
The pattern to check url
-
Constructor Summary
Constructors Constructor Description CommentsDAO()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Map<String,Object>
_setCommentAttributes(CommentableContent content, Comment comment, Map<String,Object> formValues)
Set comment attributesMap<String,Object>
addComment(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)
Map<String,Object>
deleteComment(String contentId, String commentId)
Delete a commentMap<String,Object>
getComment(Comment comment, int level, Map<String,Object> contextualParameters)
Get JSON representation of a commentList<Map<String,Object>>
getComments(String contentId, Map<String,Object> contextualParameters)
Get the content's commentsprotected CommentableContent
getContent(String contentId)
Get the commentable contentprotected UserIdentity
getCurrentUser()
Get the current userList<I18nizableText>
getErrors(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 listenersMap<String,Object>
likeOrUnlikeComment(String contentId, String commentId)
React (like or unlike) to a commentMap<String,Object>
likeOrUnlikeComment(String contentId, String commentId, Boolean remove)
React (like or unlike) to a commentMap<String,Object>
reportComment(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 Detail
-
FORM_AUTHOR_NAME
public static final String FORM_AUTHOR_NAME
The form input name for author name- See Also:
- Constant Field Values
-
FORM_AUTHOR_EMAIL
public static final String FORM_AUTHOR_EMAIL
The form input name for author email- See Also:
- Constant Field Values
-
FORM_AUTHOR_HIDEEMAIL
public static final String FORM_AUTHOR_HIDEEMAIL
The form input name for author email to hide- See Also:
- Constant Field Values
-
FORM_AUTHOR_URL
public static final String FORM_AUTHOR_URL
The form input name for author url- See Also:
- Constant Field Values
-
FORM_CONTENTTEXT
public static final String FORM_CONTENTTEXT
The form input name for content- See Also:
- Constant Field Values
-
FORM_CAPTCHA_KEY
public static final String FORM_CAPTCHA_KEY
The form input name for captcha- See Also:
- Constant Field Values
-
FORM_CAPTCHA_VALUE
public static final String FORM_CAPTCHA_VALUE
The form input name for captcha- See Also:
- Constant Field Values
-
URL_VALIDATOR
public static final Pattern URL_VALIDATOR
The pattern to check url
-
_resolver
protected AmetysObjectResolver _resolver
The Ametys object resolver
-
_observationManager
protected ObservationManager _observationManager
The observation manager
-
_userProvider
protected CurrentUserProvider _userProvider
The currenrt user provider
-
_userHelper
protected UserHelper _userHelper
The user helper
-
_rightManager
protected RightManager _rightManager
The right manager
-
_reactionableHelper
protected ReactionableObjectHelper _reactionableHelper
Helper for reactionable object
-
_userManager
protected UserManager _userManager
The user manager
-
-
Constructor Detail
-
CommentsDAO
public CommentsDAO()
-
-
Method Detail
-
service
public void service(ServiceManager smanager) throws ServiceException
- Specified by:
service
in interfaceServiceable
- Throws:
ServiceException
-
contextualize
public void contextualize(Context context) throws ContextException
- 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
public boolean canDeleteComment(String contentId)
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
protected CommentableContent getContent(String contentId)
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
public Map<String,Object> reportComment(String contentId, String commentId)
Report a comment- Parameters:
contentId
- the content idcommentId
- the comment id- Returns:
- the results
-
isValidatedByDefault
public boolean isValidatedByDefault(Content content)
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
public boolean isCaptchaRequired(Content content)
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
public List<I18nizableText> getErrors(CommentableContent content, Map<String,Object> formValues)
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
protected UserIdentity 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
-
-