Moderation of User Comments In AEM through Custom Workflow
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:
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
[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.