View Javadoc
1   /*
2    * Copyright (C) 2003-2009 eXo Platform SAS.
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Affero General Public License
6    * as published by the Free Software Foundation; either version 3
7    * of the License, or (at your option) any later version.
8    *
9    * This program 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
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, see<http://www.gnu.org/licenses/>.
16   */
17  package org.exoplatform.services.wcm.category;
18  
19  import javax.jcr.Node;
20  
21  import org.exoplatform.container.configuration.ConfigurationManager;
22  import org.exoplatform.container.xml.InitParams;
23  import org.exoplatform.services.cms.actions.ActionServiceContainer;
24  import org.exoplatform.services.cms.taxonomy.TaxonomyService;
25  import org.exoplatform.services.jcr.RepositoryService;
26  import org.exoplatform.services.jcr.ext.common.SessionProvider;
27  import org.exoplatform.services.wcm.portal.artifacts.RemovePortalPlugin;
28  
29  /**
30   * Created by The eXo Platform SAS
31   * Author : eXoPlatform
32   * chuong_phan@exoplatform.com, phan.le.thanh.chuong@gmail.com
33   * Aug 11, 2009
34   */
35  public class RemoveTaxonomyPlugin extends RemovePortalPlugin {
36  
37    /** The taxonomy service_. */
38    private TaxonomyService         taxonomyService;
39  
40    private ActionServiceContainer actionServiceContainer;
41  
42    private RepositoryService repositoryService;
43  
44    /**
45     * Instantiates a new initial taxonomy plugin.
46     *
47     * @param params the params
48     * @param configurationManager the configuration manager
49     * @param repositoryService the repository service
50     * @param taxonomyService the taxonomy service
51     * @param actionServiceContainer the action service container
52     *
53     * @throws Exception the exception
54     */
55    public RemoveTaxonomyPlugin(InitParams params,
56                                 ConfigurationManager configurationManager,
57                                 RepositoryService repositoryService,
58                                 TaxonomyService taxonomyService,
59                                 ActionServiceContainer actionServiceContainer) throws Exception {
60      super(params, configurationManager, repositoryService);
61      this.repositoryService = repositoryService;
62      this.taxonomyService = taxonomyService;
63      this.actionServiceContainer = actionServiceContainer;
64    }
65  
66    /*
67     * (non-Javadoc)
68     * @see
69     * org.exoplatform.services.wcm.portal.artifacts.BasePortalArtifactsPlugin
70     * #deployToPortal(java.lang.String,
71     * org.exoplatform.services.jcr.ext.common.SessionProvider)
72     */
73    public void invalidateFromPortal(SessionProvider sessionProvider, String portalName) throws Exception {
74      String repository = repositoryService.getCurrentRepository().getConfiguration().getName();
75      if (taxonomyService.hasTaxonomyTree(portalName)) {
76        Node taxonomyTreeNode = taxonomyService.getTaxonomyTree(portalName, true);
77        if (taxonomyTreeNode!=null) {
78          actionServiceContainer.removeAction(taxonomyTreeNode, repository);
79        }
80        taxonomyService.removeTaxonomyTree(portalName);
81      }
82    }
83  }