]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
fe4157b5b70be76876f2e72d24a9d292ed98b47c
[tmp/jakarta-migration.git] /
1 /*
2  * (C) Copyright 2006-2009 Nuxeo SAS (http://nuxeo.com/) and contributors.
3  *
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
8  *
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.
13  *
14  * Contributors:
15  *     Nuxeo - initial API and implementation
16  *
17  * $Id$
18  */
19
20 package org.collectionspace.ecm.platform.quote.listener;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
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;
34
35 import org.collectionspace.ecm.platform.quote.service.QuoteServiceConfig;
36 import org.collectionspace.ecm.platform.quote.service.QuoteServiceHelper;
37
38 public abstract class AbstractQuoteListener {
39
40      private static final Log log = LogFactory.getLog(AbstractQuoteListener.class);
41
42         public void handleEvent(EventBundle events) {
43             for (Event event : events) {
44                 handleEvent(event);
45             }
46         }
47
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();
56                     try {
57                         RelationManager relationManager = Framework.getService(RelationManager.class);
58                         doProcess(coreSession, relationManager, config, doc);
59                     }
60                     catch (Exception e) {
61                         log.error("Error during message processing", e);
62                     }
63                     return;
64                 }
65             }
66         }
67
68         protected abstract void doProcess(CoreSession coreSession,
69             RelationManager relationManager, QuoteServiceConfig config,
70             DocumentModel docMessage) throws Exception;
71
72 }