001/*
002 * (C) Copyright 2007 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 * $Id$
020 */
021
022package org.nuxeo.ecm.platform.comment.impl;
023
024import java.util.List;
025
026import org.nuxeo.ecm.core.api.DocumentModel;
027import org.nuxeo.ecm.platform.comment.api.CommentManager;
028import org.nuxeo.ecm.platform.comment.api.CommentableDocument;
029import org.nuxeo.runtime.api.Framework;
030
031/**
032 * @author <a href="mailto:glefter@nuxeo.com">George Lefter</a>
033 */
034public class CommentableDocumentAdapter implements CommentableDocument {
035
036    private static final long serialVersionUID = 2996381735762615450L;
037
038    final DocumentModel docModel;
039
040    public CommentableDocumentAdapter(DocumentModel docModel) {
041        this.docModel = docModel;
042    }
043
044    public DocumentModel addComment(DocumentModel comment) {
045        CommentManager commentManager = Framework.getService(CommentManager.class);
046        return commentManager.createComment(docModel, comment);
047    }
048
049    @Deprecated
050    public DocumentModel addComment(String comment) {
051        CommentManager commentManager = Framework.getService(CommentManager.class);
052        return commentManager.createComment(docModel, comment);
053    }
054
055    public DocumentModel addComment(DocumentModel parent, DocumentModel comment) {
056        CommentManager commentManager = Framework.getService(CommentManager.class);
057        return commentManager.createComment(docModel, parent, comment);
058    }
059
060    public void removeComment(DocumentModel comment) {
061        CommentManager commentManager = Framework.getService(CommentManager.class);
062        commentManager.deleteComment(docModel, comment);
063    }
064
065    public List<DocumentModel> getComments() {
066        CommentManager commentManager = Framework.getService(CommentManager.class);
067        return commentManager.getComments(docModel);
068    }
069
070    public List<DocumentModel> getComments(DocumentModel parent) {
071        CommentManager commentManager = Framework.getService(CommentManager.class);
072        return commentManager.getComments(docModel, parent);
073    }
074
075}