001/* 002 * (C) Copyright 2013 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 * Thomas Roger 018 */ 019 020package org.nuxeo.ecm.platform.picture.listener; 021 022import static org.nuxeo.ecm.platform.picture.api.ImagingDocumentConstants.UPDATE_PICTURE_VIEW_EVENT; 023 024import org.nuxeo.ecm.core.api.DocumentModel; 025import org.nuxeo.ecm.core.event.Event; 026import org.nuxeo.ecm.core.event.EventBundle; 027import org.nuxeo.ecm.core.event.EventContext; 028import org.nuxeo.ecm.core.event.PostCommitFilteringEventListener; 029import org.nuxeo.ecm.core.event.impl.DocumentEventContext; 030import org.nuxeo.ecm.core.work.api.WorkManager; 031import org.nuxeo.ecm.platform.picture.PictureViewsGenerationWork; 032import org.nuxeo.runtime.api.Framework; 033 034/** 035 * Listener generating picture views. 036 * 037 * @since 5.7.2 038 * @deprecated since 7.2 039 */ 040@Deprecated 041public class PictureViewListener implements PostCommitFilteringEventListener { 042 @Override 043 public void handleEvent(EventBundle events) { 044 for (Event event : events) { 045 if (UPDATE_PICTURE_VIEW_EVENT.equals(event.getName())) { 046 handleEvent(event); 047 } 048 } 049 } 050 051 private void handleEvent(Event event) { 052 EventContext ctx = event.getContext(); 053 if (!(ctx instanceof DocumentEventContext)) { 054 return; 055 } 056 057 DocumentEventContext docCtx = (DocumentEventContext) ctx; 058 DocumentModel doc = docCtx.getSourceDocument(); 059 060 // launch work doing the actual views generation 061 PictureViewsGenerationWork work = new PictureViewsGenerationWork(doc.getRepositoryName(), 062 doc.getRef().toString(), "file:content"); 063 WorkManager workManager = Framework.getLocalService(WorkManager.class); 064 workManager.schedule(work, WorkManager.Scheduling.IF_NOT_SCHEDULED, true); 065 } 066 067 @Override 068 public boolean acceptEvent(Event event) { 069 return UPDATE_PICTURE_VIEW_EVENT.equals(event.getName()); 070 } 071}