get comments from a document

How can i get comments data from a DocumentModel?

0 votes

2 answers

1560 views

ANSWER



Hello,

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

1 votes



iry
Yes, thank you but I want to get the comment from the event to send it in the email notification
09/28/2011


/**

  • */

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;
    

    }

}

0 votes