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.core.adapter.Collection;
022import org.nuxeo.ecm.collections.core.listener.CollectionAsynchrnonousQuery;
023import org.nuxeo.ecm.core.api.DocumentModel;
024
025/**
026 * @since 5.9.3
027 */
028public class RemovedCollectionMemberWork extends RemovedAbstractWork {
029
030    public RemovedCollectionMemberWork() {
031        super();
032    }
033
034    protected RemovedCollectionMemberWork(long offset) {
035        super(offset);
036    }
037
038    private static final Log log = LogFactory.getLog(RemovedCollectionMemberWork.class);
039
040    private static final long serialVersionUID = 6944563540430297431L;
041
042    public static final String CATEGORY = "removedCollectionMember";
043
044    protected static final String TITLE = "Remove CollectionMember Work";
045
046    @Override
047    public String getTitle() {
048        return TITLE;
049    }
050
051    @Override
052    public String getCategory() {
053        return CATEGORY;
054    }
055
056    @Override
057    protected String getQuery() {
058        return CollectionAsynchrnonousQuery.QUERY_FOR_COLLECTION_MEMBER_REMOVED;
059    }
060
061    @Override
062    protected void updateDocument(final DocumentModel collection) {
063        log.trace(String.format("Worker %s, updating Collection %s", getId(), collection.getTitle()));
064
065        Collection collectionAdapter = collection.getAdapter(Collection.class);
066        collectionAdapter.removeDocument(docId);
067        session.saveDocument(collection);
068    }
069
070}