001/*
002 * (C) Copyright 2007-2016 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 */
019package org.nuxeo.ecm.platform.comment.impl;
020
021import java.util.List;
022
023import org.nuxeo.ecm.core.api.DocumentModel;
024import org.nuxeo.ecm.platform.comment.api.CommentManager;
025import org.nuxeo.ecm.platform.comment.api.CommentableDocument;
026import org.nuxeo.runtime.api.Framework;
027
028/**
029 * @author <a href="mailto:glefter@nuxeo.com">George Lefter</a>
030 */
031public class CommentableDocumentAdapter implements CommentableDocument {
032
033    private static final long serialVersionUID = 2996381735762615450L;
034
035    final DocumentModel docModel;
036
037    final CommentManager commentManager;
038
039    public CommentableDocumentAdapter(DocumentModel docModel) {
040        this.commentManager = Framework.getService(CommentManager.class);
041        this.docModel = docModel;
042    }
043
044    public DocumentModel addComment(DocumentModel comment) {
045        return commentManager.createComment(docModel, comment);
046    }
047
048    public DocumentModel addComment(DocumentModel comment, String path) {
049        return commentManager.createLocatedComment(docModel, comment, path);
050    }
051
052    public DocumentModel addComment(DocumentModel parent, DocumentModel comment) {
053        return commentManager.createComment(docModel, parent, comment);
054    }
055
056    public void removeComment(DocumentModel comment) {
057        commentManager.deleteComment(docModel, comment);
058    }
059
060    public List<DocumentModel> getComments() {
061        return commentManager.getComments(docModel);
062    }
063
064    public List<DocumentModel> getComments(DocumentModel parent) {
065        return commentManager.getComments(docModel, parent);
066    }
067
068}