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