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