cancel
Showing results for 
Search instead for 
Did you mean: 

How to list Folder Comments using Alfresco JAVA API

ravichandanani
Champ in-the-making
Champ in-the-making
I am searching for sample code to list down all the comments for particular node .

I found some webscript to list down the comments of the folder but could not find the sample code for JAVA API.




public class CommentsController extends AbstractWebScript {

   private ServiceRegistry serviceRegistry;

   @Override
   public void execute(WebScriptRequest req, WebScriptResponse res)
         throws IOException {
      
      WebScriptServletRequest servletRequest = (WebScriptServletRequest) req;

      
      response.setContentType("application/json");

                 String nodeId = "afef8c4e-2022-49dd-8427-9321d4f84491";
//                write the json object for all the comments

}
}      




I want create custom webscript to list down the comments of the folder.
Can anyone help me please.
3 REPLIES 3

mitpatoliya
Star Collaborator
Star Collaborator
By comment you mean description of the node?

Got The way to lsit the comments posted on folder / node.

Node stores comments as following way,
The node will have child node discussion, discussion will have child node topic and the topic will have all the comments as its child nodes.


<java>
/* List all the child of the node, as all the comments are stored in node -> discussion -> topic -> comments(list) */   
      List<ChildAssociationRef> childList = serviceRegistry
      .getNodeService().getChildAssocs(node);

      for (ChildAssociationRef s : childList) {
         if (ForumModel.ASSOC_DISCUSSION.equals(s.getTypeQName())) {
            List<ChildAssociationRef> topicList = serviceRegistry
                  .getNodeService().getChildAssocs(s.getChildRef());
            for (ChildAssociationRef topic : topicList) {
      
               if (ForumModel.TYPE_TOPIC.equals(serviceRegistry
                     .getNodeService().getType(topic.getChildRef()))) {
                  
                  /* list of all the comments node */
                  List<ChildAssociationRef> postList = serviceRegistry
                        .getNodeService().getChildAssocs(
                              topic.getChildRef());
      
                  /* read the last comment posted on the node */
                  String latestCommentHtml = serviceRegistry
                        .getContentService()
                        .getReader(
                              postList.get(postList.size() - 1)
                                    .getChildRef(),
                              ContentModel.PROP_CONTENT)
                        .getReader().getContentString();
                  
                  latestCommentHtml= "<div class='comment-content'>"+comment+"</div>";
                  latestCommentHtml= HtmlUtils.htmlUnescape(comment);
      

                  return latestCommentHtml;
               }
            }
         }
      }

</java>


There is also a javascript data webscript to list down all the comments of the node.
http://localhost:8080/share/page/components/node/workspace/SpacesStore/910d38f8-a897-491f-aa2d-1d48d...