]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
32e056c4cec3ace8b19027cea52d0b99d877302b
[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 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;
33
34 import org.collectionspace.ecm.platform.quote.service.QuoteServiceConfig;
35 import org.collectionspace.ecm.platform.quote.service.QuoteServiceHelper;
36
37 public abstract class AbstractQuoteListener {
38
39      private static final Log log = LogFactory.getLog(AbstractQuoteListener.class);
40
41         public void handleEvent(EventBundle events) {
42             for (Event event : events) {
43                 handleEvent(event);
44             }
45         }
46
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();
55                     try {
56                         RelationManager relationManager = Framework.getService(RelationManager.class);
57                         doProcess(coreSession, relationManager, config, doc);
58                     }
59                     catch (Exception e) {
60                         log.error("Error during message processing", e);
61                     }
62                     return;
63                 }
64             }
65         }
66
67         protected abstract void doProcess(CoreSession coreSession,
68             RelationManager relationManager, QuoteServiceConfig config,
69             DocumentModel docMessage) throws Exception;
70
71 }