April 10, 2020
Estimated Post Reading Time ~

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 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:
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
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.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.