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