Moderation of User Comments In AEM through Custom Workflow

27 / May / 2015 by Anshika Dhingra 0 comments

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 the vistors 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:

Screenshot from 2015-05-26 11:14:32

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.

Screenshot from 2015-05-24 19:08:08

The comment is Reverse Replicated for approval from Admin.

Admin can approve or disapprove the comment.

Screenshot from 2015-05-13 16:18:15

1.Custom Workflow for Comment Approval

[java]
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);
}
}
[/java]

2. Custom Workflow for Comment Rejection

[java]
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);
}
}
[/java]

Either, if the comment is approved, it is published or else the jcr node is deleted.

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *