001/*
002 * (C) Copyright 2014 Nuxeo SA (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-2.1.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 *     <a href="mailto:glefevre@nuxeo.com">Gildas</a>
016 */
017package org.nuxeo.ecm.collections.core.automation;
018
019import org.nuxeo.ecm.automation.core.Constants;
020import org.nuxeo.ecm.automation.core.annotations.Context;
021import org.nuxeo.ecm.automation.core.annotations.Operation;
022import org.nuxeo.ecm.automation.core.annotations.OperationMethod;
023import org.nuxeo.ecm.automation.core.annotations.Param;
024import org.nuxeo.ecm.collections.api.CollectionManager;
025import org.nuxeo.ecm.core.api.CoreSession;
026import org.nuxeo.ecm.core.api.DocumentModel;
027import org.nuxeo.ecm.core.api.DocumentModelList;
028
029/**
030 * Class for the operation to remove a list of documents in a Collection.
031 *
032 * @since 5.9.4
033 */
034@Operation(id = RemoveFromCollectionOperation.ID, category = Constants.CAT_DOCUMENT, label = "Remove from collection", description = "Remove a list of documents from a collection. "
035        + "No value is returned.")
036public class RemoveFromCollectionOperation {
037    public static final String ID = "Collection.RemoveFromCollection";
038
039    @Context
040    protected CoreSession session;
041
042    @Context
043    protected CollectionManager collectionManager;
044
045    @Param(name = "collection")
046    protected DocumentModel collection;
047
048    @OperationMethod
049    public DocumentModelList run(DocumentModelList docs) {
050        for (DocumentModel doc : docs) {
051            collectionManager.removeFromCollection(collection, doc, session);
052        }
053
054        return docs;
055    }
056
057    @OperationMethod
058    public DocumentModel run(DocumentModel doc) {
059        collectionManager.removeFromCollection(collection, doc, session);
060
061        return doc;
062    }
063}