001/*
002 * (C) Copyright 2007 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo - initial API and implementation
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.platform.comment.impl;
021
022import java.util.List;
023
024import org.nuxeo.ecm.core.api.DocumentModel;
025import org.nuxeo.ecm.platform.comment.api.CommentManager;
026import org.nuxeo.ecm.platform.comment.api.CommentableDocument;
027import org.nuxeo.runtime.api.Framework;
028
029/**
030 * @author <a href="mailto:glefter@nuxeo.com">George Lefter</a>
031 */
032public class CommentableDocumentAdapter implements CommentableDocument {
033
034    private static final long serialVersionUID = 2996381735762615450L;
035
036    final DocumentModel docModel;
037
038    public CommentableDocumentAdapter(DocumentModel docModel) {
039        this.docModel = docModel;
040    }
041
042    public DocumentModel addComment(DocumentModel comment) {
043        CommentManager commentManager = Framework.getService(CommentManager.class);
044        return commentManager.createComment(docModel, comment);
045    }
046
047    @Deprecated
048    public DocumentModel addComment(String comment) {
049        CommentManager commentManager = Framework.getService(CommentManager.class);
050        return commentManager.createComment(docModel, comment);
051    }
052
053    public DocumentModel addComment(DocumentModel parent, DocumentModel comment) {
054        CommentManager commentManager = Framework.getService(CommentManager.class);
055        return commentManager.createComment(docModel, parent, comment);
056    }
057
058    public void removeComment(DocumentModel comment) {
059        CommentManager commentManager = Framework.getService(CommentManager.class);
060        commentManager.deleteComment(docModel, comment);
061    }
062
063    public List<DocumentModel> getComments() {
064        CommentManager commentManager = Framework.getService(CommentManager.class);
065        return commentManager.getComments(docModel);
066    }
067
068    public List<DocumentModel> getComments(DocumentModel parent) {
069        CommentManager commentManager = Framework.getService(CommentManager.class);
070        return commentManager.getComments(docModel, parent);
071    }
072
073}