Comments, reviews & feedbacks are some of the vital functionalities required in almost every website these days. Leveraging the comments section is very important.
All those comments made by visitors cannot be published. You may have to select the comments that are to be published according to your content and its purpose.
An AEM Comment Moderation System gives the admin the authority to select or reject comments and go ahead with only those found relevant.
The flowchart below describes the process:
Normally when a user writes a comment and submits it, the comment is stored as a node under content/usergenerated/content/comments/blog as cq:Comment.
The comment is Reverse Replicated for approval from Admin.
Admin can approve or disapprove the comment.
1.Custom Workflow for Comment Approval
1
2
3
4
5
6
7
8
9
10
11
| String path = workItem.getWorkflowData().getPayload().toString(); ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver. class ); Session session = resourceResolver.adaptTo(Session. class ); if (session.itemExists(path)) { Node node = (Node) session.getItem(path); node.setProperty( "display" , true ); session.save(); if (slingSettingsService.getRunModes().contains( "author" )) { replicator.replicate(session, ReplicationActionType.ACTIVATE, path); } } |
2. Custom Workflow for Comment Rejection
1
2
3
4
5
6
7
8
9
10
11
12
| String path = workItem.getWorkflowData().getPayload().toString(); ResourceResolver resourceResolver = workflowSession.adaptTo(ResourceResolver. class ); Session session = resourceResolver.adaptTo(Session. class ); if (session.itemExists(path)) { Node node = (Node) session.getItem(path); String parent = node.getParent().getPath(); node.remove(); session.save(); if (slingSettingsService.getRunModes().contains( "author" )) { replicator.replicate(session, ReplicationActionType.ACTIVATE, parent); } } |
Either, if the comment is approved, it is published or else the jcr node is deleted.
No comments:
Post a Comment
If you have any doubts or questions, please let us know.