View Javadoc
1   /*
2    * Copyright (C) 2003-2008 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.portal.artifacts;
18  
19  import org.exoplatform.services.context.DocumentContext;
20  import org.exoplatform.services.jcr.ext.common.SessionProvider;
21  import org.exoplatform.services.listener.ListenerService;
22  
23  import java.util.ArrayList;
24  import java.util.HashMap;
25  import java.util.LinkedHashMap;
26  import java.util.List;
27  
28  /**
29   * Created by The eXo Platform SAS
30   * Author : Hoa Pham
31   *          hoa.phamvu@exoplatform.com
32   * Oct 22, 2008
33   */
34  public class CreatePortalArtifactsServiceImpl implements CreatePortalArtifactsService {
35  
36    public static final String CREATE_PORTAL_EVENT = "PortalArtifactsInitializerServiceImpl.portal.onCreate";
37    private HashMap<String,CreatePortalPlugin> artifactPlugins = new LinkedHashMap<String,CreatePortalPlugin>();
38    private List<String> initialPortals = new ArrayList<String>();
39    private ListenerService listenerService;
40  
41    public CreatePortalArtifactsServiceImpl(ListenerService listenerService) {
42      this.listenerService = listenerService;
43    }
44    public void addPlugin(CreatePortalPlugin artifactsPlugin) throws Exception {
45      artifactPlugins.put(artifactsPlugin.getName(),artifactsPlugin);
46    }
47  
48    public void addIgnorePortalPlugin(IgnorePortalPlugin ignorePortalPlugin) throws Exception {
49      List<String> ignoredPortals = ignorePortalPlugin.getIgnorePortals();
50      if (ignoredPortals != null && !ignoredPortals.isEmpty()) {
51        initialPortals.addAll(ignoredPortals);
52      }
53    }
54  
55    public void deployArtifactsToPortal(SessionProvider sessionProvider, String portalName, String portalTemplateName) throws Exception {
56      //Do not initalize portal artifact for predefined portal
57      if(initialPortals.contains(portalName)) return;
58      DocumentContext.getCurrent().getAttributes().put(DocumentContext.IS_SKIP_RAISE_ACT, true);
59  
60      // Call CreatePortalPlugin plugins for specific portal template
61      for (CreatePortalPlugin plugin : artifactPlugins.values()) {
62        if (portalTemplateName != null && plugin.getName().startsWith(portalTemplateName)) {
63          plugin.deployToPortal(sessionProvider, portalName);
64        }
65      }
66  
67      // Call common CreatePortalPlugin plugins
68      for (CreatePortalPlugin plugin : artifactPlugins.values()) {
69        if (!plugin.getName().startsWith("template")) {
70          plugin.deployToPortal(sessionProvider, portalName);
71        }
72      }
73  
74      listenerService.broadcast(CREATE_PORTAL_EVENT, portalName, sessionProvider);
75    }
76  
77     /**
78     * {@inheritDoc}
79     */
80     @Override
81     public HashMap<String, CreatePortalPlugin> getArtifactPlugins() {
82       return artifactPlugins;
83     }
84  }