2 * (C) Copyright 2006-2009 Nuxeo SAS (http://nuxeo.com/) and contributors.
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the GNU Lesser General Public License
6 * (LGPL) version 2.1 which accompanies this distribution, and is available at
7 * http://www.gnu.org/licenses/lgpl.html
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
15 * Nuxeo - initial API and implementation
20 package org.collectionspace.ecm.platform.quote.listener;
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.nuxeo.ecm.core.api.CoreSession;
25 import org.nuxeo.ecm.core.api.DocumentModel;
26 import org.nuxeo.ecm.core.api.event.DocumentEventTypes;
27 import org.nuxeo.ecm.core.event.Event;
28 import org.nuxeo.ecm.core.event.EventBundle;
29 import org.nuxeo.ecm.core.event.EventContext;
30 import org.nuxeo.ecm.core.event.impl.DocumentEventContext;
31 import org.nuxeo.ecm.platform.relations.api.RelationManager;
32 import org.nuxeo.runtime.api.Framework;
34 import org.collectionspace.ecm.platform.quote.service.QuoteServiceConfig;
35 import org.collectionspace.ecm.platform.quote.service.QuoteServiceHelper;
37 public abstract class AbstractQuoteListener {
39 private static final Log log = LogFactory.getLog(AbstractQuoteListener.class);
41 public void handleEvent(EventBundle events) {
42 for (Event event : events) {
47 public void handleEvent(Event event) {
48 if (DocumentEventTypes.DOCUMENT_REMOVED.equals(event.getName())) {
49 EventContext ctx = event.getContext();
50 if (ctx instanceof DocumentEventContext) {
51 DocumentEventContext docCtx = (DocumentEventContext) ctx;
52 DocumentModel doc = docCtx.getSourceDocument();
53 CoreSession coreSession = docCtx.getCoreSession();
54 QuoteServiceConfig config = QuoteServiceHelper.getQuoteService().getConfig();
56 RelationManager relationManager = Framework.getService(RelationManager.class);
57 doProcess(coreSession, relationManager, config, doc);
60 log.error("Error during message processing", e);
67 protected abstract void doProcess(CoreSession coreSession,
68 RelationManager relationManager, QuoteServiceConfig config,
69 DocumentModel docMessage) throws Exception;