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 java.util.List;
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
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;
36 import org.collectionspace.ecm.platform.quote.service.QuoteServiceConfig;
38 public class QuoteRemovedEventListener extends AbstractQuoteListener
39 implements EventListener {
41 private static final Log log = LogFactory.getLog(QuoteRemovedEventListener.class);
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);
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");
64 Statement pattern = new StatementImpl(quoteRes, null, null);
65 List<Statement> statementList = relationManager.getStatements(
66 config.graphName, pattern);
67 relationManager.remove(config.graphName, statementList);