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 PopulationContextHelper
The population context helperprotected ReactionableObjectHelper
Helper for reactionable objectprotected AmetysObjectResolver
The Ametys object resolverprotected RightManager
The right managerprotected UserHelper
The user helperprotected UserManager
The user managerprotected UserPopulationDAO
The user population DAOprotected 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 commentboolean
canDeleteComment
(Content content, Comment comment) Determines if current user is allowed to delete a commentvoid
contextualize
(Context context) deleteComment
(String contentId, String commentId) Delete a commentGet JSON representation of a commentgetCommentAuthor
(Comment comment, Map<String, Object> contextualParameters) Get JSON representation of a comment's authorgetComments
(String contentId, Map<String, Object> contextualParameters) Get the content's commentsprotected CommentableContent
getContent
(String contentId) Get the commentable contentgetContributorComments
(String contentId, Map<String, Object> contextualParameters) Get the content's contributor commentsprotected UserIdentity
Get the current usergetErrors
(CommentableContent content, Map<String, Object> formValues) Get errors when submitting commentgetUserByEmail
(String userEmail, Map<String, Object> contextualParameters) Get the author as a User if existsgetUserIdentityProperties
(UserIdentity userIdentity, Map<String, Object> contextualParameters) Get JSON representation of a user identity.getUserPopulationsContexts
(Request request, Map<String, Object> contextualParameters) Get the user population contextsgetUserProperties
(User user, Map<String, Object> contextualParameters) Get JSON representation of a usergetUserPropertiesFromIdentity
(UserIdentity userIdentity, Map<String, Object> contextualParameters) Get JSON representation of a user from its identity.boolean
isCaptchaRequired
(Content content, Map<String, Object> formValues) 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, Map<String, Object> contextualParameters) SAX a commentprotected void
saxCommentAdditionalProperties
(ContentHandler contentHandler, Comment comment, int level, Map<String, Object> contextualParameters) SAX additional comment propertiesprotected void
saxUserIdentity
(ContentHandler contentHandler, UserIdentity userIdentity, String tagName) Generate SAX events for all known data of the given user identityvoid
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 -
_populationContextHelper
The population context helper -
_userPopulationDAO
The user population DAO -
_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) throws IllegalAccessExceptionGet the content's comments- Parameters:
contentId
- the content idcontextualParameters
- the contextual parameters- Returns:
- the comments
- Throws:
IllegalAccessException
- if user is not allowed to get comments
-
getContributorComments
public List<Map<String,Object>> getContributorComments(String contentId, Map<String, Object> contextualParameters) Get the content's contributor 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, throws IllegalAccessExceptionObject> 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
- Throws:
IllegalAccessException
- if anonymous or current user has no access to the content
-
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
-
canDeleteComment
Determines if current user is allowed to delete a comment- Parameters:
content
- the contentcomment
- the comment- 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 or user has no access to the content
-
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 or user has no access to the content
-
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
public Map<String,Object> reportComment(String contentId, String commentId) throws IllegalAccessException Report a comment- Parameters:
contentId
- the content idcommentId
- the comment id- Returns:
- the results
- Throws:
IllegalAccessException
- if anonymous or current user has no access to the content
-
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 commentformValues
- The form values- Returns:
- true if the comments have to be protected by a captcha or false otherwise
-
getErrors
public List<Map<String,Object>> 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
Get the current user- Returns:
- The current user
-
getComment
public Map<String,Object> getComment(Content content, Comment comment, int level, Map<String, Object> contextualParameters) Get JSON representation of a comment- Parameters:
content
- The contentcomment
- the commentlevel
- the level of comment (0 for parent comment, 1 for sub-comment, etc ....)contextualParameters
- the contextual parameters- Returns:
- the comment as JSON
-
getCommentAuthor
protected Map<String,Object> getCommentAuthor(Comment comment, Map<String, Object> contextualParameters) Get JSON representation of a comment's author- Parameters:
comment
- the commentcontextualParameters
- the contextual parameters- Returns:
- the comment's author as JSON
-
getUserByEmail
Get the author as a User if exists- Parameters:
userEmail
- the email of the user to retrievecontextualParameters
- the contextual parameters- Returns:
- the user or null
-
getUserPropertiesFromIdentity
protected Map<String,Object> getUserPropertiesFromIdentity(UserIdentity userIdentity, Map<String, Object> contextualParameters) Get JSON representation of a user from its identity. If the user does not exist, get all known identity properties- Parameters:
userIdentity
- the user identitycontextualParameters
- the contextual parameters- Returns:
- the user as JSON
-
getUserProperties
Get JSON representation of a user- Parameters:
user
- the usercontextualParameters
- the contextual parameters- Returns:
- the user as JSON
-
getUserIdentityProperties
protected Map<String,Object> getUserIdentityProperties(UserIdentity userIdentity, Map<String, Object> contextualParameters) Get JSON representation of a user identity. Put all known data in the json result- Parameters:
userIdentity
- the user identitycontextualParameters
- the contextual parameters- Returns:
- the user identity as JSON
-
getUserPopulationsContexts
protected List<String> getUserPopulationsContexts(Request request, Map<String, Object> contextualParameters) Get the user population contexts- Parameters:
request
- The requestcontextualParameters
- The contextual parameters- Returns:
- The contexts
- Throws:
IllegalArgumentException
- If there is no context set
-
saxComment
public void saxComment(ContentHandler contentHandler, Comment comment, int level, Map<String, Object> contextualParameters) throws SAXExceptionSAX a comment- Parameters:
contentHandler
- the content handlercomment
- the commentlevel
- the level of commentcontextualParameters
- the contextual parameters- Throws:
SAXException
- if an error occurred hile saxing
-
saxUserIdentity
protected void saxUserIdentity(ContentHandler contentHandler, UserIdentity userIdentity, String tagName) throws SAXException Generate SAX events for all known data of the given user identity- Parameters:
contentHandler
- the content handleruserIdentity
- the user identitytagName
- The XML tag for saxed user- Throws:
SAXException
- if an error occurred while generating SAX events
-
saxCommentAdditionalProperties
protected void saxCommentAdditionalProperties(ContentHandler contentHandler, Comment comment, int level, Map<String, Object> contextualParameters) throws SAXExceptionSAX additional comment properties- Parameters:
contentHandler
- the content handlercomment
- the commentlevel
- the level of commentcontextualParameters
- the contextual parameters- Throws:
SAXException
- if an error occurred while saxing
-