]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
a1a662e4c2bd91a2e3cd63d988a04db42ed09f5f
[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 java.util.List;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27 import org.nuxeo.ecm.core.api.ClientException;
28 import org.nuxeo.ecm.core.api.CoreSession;
29 import org.nuxeo.ecm.core.api.DocumentModel;
30 import org.nuxeo.ecm.core.event.EventListener;
31 import org.nuxeo.ecm.platform.relations.api.RelationManager;
32 import org.nuxeo.ecm.platform.relations.api.Resource;
33 import org.nuxeo.ecm.platform.relations.api.Statement;
34 import org.nuxeo.ecm.platform.relations.api.impl.StatementImpl;
35
36 import org.collectionspace.ecm.platform.quote.service.QuoteServiceConfig;
37
38 public class QuoteRemovedEventListener extends AbstractQuoteListener
39         implements EventListener {
40
41     private static final Log log = LogFactory.getLog(QuoteRemovedEventListener.class);
42
43     @Override
44     protected void doProcess(CoreSession coreSession,
45             RelationManager relationManager, QuoteServiceConfig config,
46             DocumentModel docMessage) throws Exception {
47         log.debug("Processing relations cleanup on Comment removal");
48         String typeName = docMessage.getType();
49         if ("Comment".equals(typeName) || "Post".equals(typeName)) {
50             onQuoteRemoved(relationManager, config, docMessage);
51         }
52     }
53
54     private static void onQuoteRemoved(RelationManager relationManager,
55             QuoteServiceConfig config, DocumentModel docModel)
56             throws ClientException {
57         Resource quoteRes = relationManager.getResource(
58                 config.commentNamespace, docModel, null);
59         if (quoteRes == null) {
60             log.warn("Could not adapt document model to relation resource; "
61                     + "check the service relation adapters configuration");
62             return;
63         }
64         Statement pattern = new StatementImpl(quoteRes, null, null);
65         List<Statement> statementList = relationManager.getStatements(
66                 config.graphName, pattern);
67         relationManager.remove(config.graphName, statementList);
68     }
69
70 }