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;
25 import org.nuxeo.ecm.core.api.CoreSession;
26 import org.nuxeo.ecm.core.api.DocumentModel;
27 import org.nuxeo.ecm.core.api.event.DocumentEventTypes;
28 import org.nuxeo.ecm.core.event.Event;
29 import org.nuxeo.ecm.core.event.EventBundle;
30 import org.nuxeo.ecm.core.event.EventContext;
31 import org.nuxeo.ecm.core.event.impl.DocumentEventContext;
32 import org.nuxeo.ecm.platform.relations.api.RelationManager;
33 import org.nuxeo.runtime.api.Framework;
35 import org.collectionspace.ecm.platform.quote.service.QuoteServiceConfig;
36 import org.collectionspace.ecm.platform.quote.service.QuoteServiceHelper;
38 public abstract class AbstractQuoteListener {
40 private static final Log log = LogFactory.getLog(AbstractQuoteListener.class);
42 public void handleEvent(EventBundle events) {
43 for (Event event : events) {
48 public void handleEvent(Event event) {
49 if (DocumentEventTypes.DOCUMENT_REMOVED.equals(event.getName())) {
50 EventContext ctx = event.getContext();
51 if (ctx instanceof DocumentEventContext) {
52 DocumentEventContext docCtx = (DocumentEventContext) ctx;
53 DocumentModel doc = docCtx.getSourceDocument();
54 CoreSession coreSession = docCtx.getCoreSession();
55 QuoteServiceConfig config = QuoteServiceHelper.getQuoteService().getConfig();
57 RelationManager relationManager = Framework.getService(RelationManager.class);
58 doProcess(coreSession, relationManager, config, doc);
61 log.error("Error during message processing", e);
68 protected abstract void doProcess(CoreSession coreSession,
69 RelationManager relationManager, QuoteServiceConfig config,
70 DocumentModel docMessage) throws Exception;