cancel
Showing results for 
Search instead for 
Did you mean: 

get comments from a document

iry_
Champ on-the-rise
Champ on-the-rise

How can i get comments data from a DocumentModel?

1 ACCEPTED ANSWER

Arnaud_Kervern
Confirmed Champ
Confirmed Champ

Hello,

You've got a getComments(DocumentModel) method exposed by the CommentManager service. I hope it will help you.

View answer in original post

3 REPLIES 3

Arnaud_Kervern
Confirmed Champ
Confirmed Champ

Hello,

You've got a getComments(DocumentModel) method exposed by the CommentManager service. I hope it will help you.

Yes, thank you but I want to get the comment from the event to send it in the email notification

Pierre_Jenicot1
Star Contributor
Star Contributor

/** * */

package org.nuxeo.yourcompany.automation;

import java.util.List;

import org.nuxeo.ecm.automation.core.Constants; import org.nuxeo.ecm.automation.core.annotations.Context; import org.nuxeo.ecm.automation.core.annotations.Operation; import org.nuxeo.ecm.automation.core.annotations.OperationMethod; import org.nuxeo.ecm.automation.core.collectors.DocumentModelListCollector; import org.nuxeo.ecm.core.api.CoreSession; import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.impl.DocumentModelListImpl; import org.nuxeo.ecm.platform.comment.api.CommentManager; import org.nuxeo.runtime.api.Framework;

/**

  • @author pjenicot */ @Operation(id=GetComments.ID, category=Constants.CAT_DOCUMENT, label="GetComments", description="Renvoie les commentaires d'un document") public class GetComments {

    public static final String ID = "Document.GetComments";

    @Context protected CoreSession session;

    protected CommentManager commentManager;

    private static CommentManager getCommentManager() { try { return ((CommentManager)Framework.getService(CommentManager.class)); } catch (Exception e) {}

     return null;
    

    }

    @OperationMethod(collector=DocumentModelListCollector.class) public DocumentModelList run(DocumentModel doc) throws Exception {

     DocumentModelListImpl docs = new DocumentModelListImpl();
    
     CommentManager commentManager = getCommentManager();
     List<DocumentModel> comments = commentManager.getComments(doc);
    
     if (!comments.isEmpty())
     {	
     	for(DocumentModel comment : comments)
     		docs.add(comment);
     }
     return docs;
    

    }

}