1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
30
31
32
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
57 if(initialPortals.contains(portalName)) return;
58 DocumentContext.getCurrent().getAttributes().put(DocumentContext.IS_SKIP_RAISE_ACT, true);
59
60
61 for (CreatePortalPlugin plugin : artifactPlugins.values()) {
62 if (portalTemplateName != null && plugin.getName().startsWith(portalTemplateName)) {
63 plugin.deployToPortal(sessionProvider, portalName);
64 }
65 }
66
67
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
79
80 @Override
81 public HashMap<String, CreatePortalPlugin> getArtifactPlugins() {
82 return artifactPlugins;
83 }
84 }