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