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:grenard@nuxeo.com">Guillaume</a>
016 */
017package org.nuxeo.ecm.collections.core.worker;
018
019import org.apache.commons.logging.Log;
020import org.apache.commons.logging.LogFactory;
021import org.nuxeo.ecm.collections.api.CollectionManager;
022import org.nuxeo.ecm.collections.core.listener.CollectionAsynchrnonousQuery;
023import org.nuxeo.ecm.core.api.DocumentModel;
024import org.nuxeo.runtime.api.Framework;
025
026/**
027 * @since 5.9.3
028 */
029public class RemovedCollectionWork extends RemovedAbstractWork {
030
031    private static final Log log = LogFactory.getLog(RemovedCollectionWork.class);
032
033    public RemovedCollectionWork() {
034        super();
035    }
036
037    protected RemovedCollectionWork(final long offset) {
038        super(offset);
039    }
040
041    private static final long serialVersionUID = -1771698891732664092L;
042
043    public static final String CATEGORY = "removedCollection";
044
045    protected static final String TITLE = "Removed Collection Work";
046
047    @Override
048    public String getTitle() {
049        return TITLE;
050    }
051
052    @Override
053    public String getCategory() {
054        return CATEGORY;
055    }
056
057    @Override
058    protected String getQuery() {
059        return CollectionAsynchrnonousQuery.QUERY_FOR_COLLECTION_REMOVED;
060    }
061
062    @Override
063    protected void updateDocument(final DocumentModel collectionMember) {
064        log.trace(String.format("Worker %s, updating CollectionMember %s", getId(), collectionMember.getTitle()));
065
066        Framework.getLocalService(CollectionManager.class).doRemoveFromCollection(collectionMember, docId, session);
067    }
068
069}