001
014
015 package com.liferay.portal.events;
016
017 import com.liferay.portal.kernel.dao.orm.QueryUtil;
018 import com.liferay.portal.kernel.events.ActionException;
019 import com.liferay.portal.kernel.util.GetterUtil;
020 import com.liferay.portal.kernel.util.LocaleUtil;
021 import com.liferay.portal.model.Layout;
022 import com.liferay.portal.model.LayoutSet;
023 import com.liferay.portal.model.LayoutSetPrototype;
024 import com.liferay.portal.service.LayoutLocalServiceUtil;
025 import com.liferay.portal.service.LayoutSetPrototypeLocalServiceUtil;
026 import com.liferay.portal.service.ServiceContext;
027 import com.liferay.portal.service.UserLocalServiceUtil;
028 import com.liferay.portal.util.PortletKeys;
029
030 import java.util.HashMap;
031 import java.util.List;
032 import java.util.Locale;
033 import java.util.Map;
034
035
038 public class AddDefaultLayoutSetPrototypesAction
039 extends BaseDefaultLayoutPrototypesAction {
040
041 @Override
042 public void run(String[] ids) throws ActionException {
043 try {
044 doRun(GetterUtil.getLong(ids[0]));
045 }
046 catch (Exception e) {
047 throw new ActionException(e);
048 }
049 }
050
051 protected LayoutSet addLayoutSetPrototype(
052 long companyId, long defaultUserId, String name, String description,
053 List<LayoutSetPrototype> layoutSetPrototypes)
054 throws Exception {
055
056 for (LayoutSetPrototype layoutSetPrototype : layoutSetPrototypes) {
057 String curName = layoutSetPrototype.getName(
058 LocaleUtil.getDefault());
059 String curDescription = layoutSetPrototype.getDescription();
060
061 if (name.equals(curName) && description.equals(curDescription)) {
062 return null;
063 }
064 }
065
066 Map<Locale, String> nameMap = new HashMap<Locale, String>();
067
068 nameMap.put(LocaleUtil.getDefault(), name);
069
070 LayoutSetPrototype layoutSetPrototype =
071 LayoutSetPrototypeLocalServiceUtil.addLayoutSetPrototype(
072 defaultUserId, companyId, nameMap, description, true, true,
073 new ServiceContext());
074
075 LayoutSet layoutSet = layoutSetPrototype.getLayoutSet();
076
077 ServiceContext serviceContext = new ServiceContext();
078
079 LayoutLocalServiceUtil.deleteLayouts(
080 layoutSet.getGroupId(), layoutSet.isPrivateLayout(),
081 serviceContext);
082
083 return layoutSetPrototype.getLayoutSet();
084 }
085
086 protected void addPrivateSite(
087 long companyId, long defaultUserId, List<LayoutSetPrototype>
088 layoutSetPrototypes)
089 throws Exception {
090
091 LayoutSet layoutSet = addLayoutSetPrototype(
092 companyId, defaultUserId, "Intranet Site",
093 "Site with Documents and News", layoutSetPrototypes);
094
095 if (layoutSet == null) {
096 return;
097 }
098
099
100
101 Layout layout = addLayout(layoutSet, "Home", "/home", "2_columns_i");
102
103 addPortletId(layout, PortletKeys.ACTIVITIES, "column-1");
104
105 String portletId = addPortletId(layout, PortletKeys.SEARCH, "column-2");
106
107 Map<String, String> preferences = new HashMap<String, String>();
108
109 preferences.put("portletSetupShowBorders", Boolean.FALSE.toString());
110
111 updatePortletSetup(layout, portletId, preferences);
112
113 portletId = addPortletId(layout, PortletKeys.LANGUAGE, "column-2");
114
115 preferences = new HashMap<String, String>();
116
117 preferences.put("displayStyle", "3");
118
119 updatePortletSetup(layout, portletId, preferences);
120
121 portletId = addPortletId(
122 layout, PortletKeys.ASSET_PUBLISHER, "column-2");
123
124 preferences = new HashMap<String, String>();
125
126 preferences.put(
127 "portletSetupTitle_" + LocaleUtil.getDefault(), "Recent Content");
128 preferences.put("portletSetupUseCustomTitle", Boolean.TRUE.toString());
129
130 updatePortletSetup(layout, portletId, preferences);
131
132
133
134 layout = addLayout(
135 layoutSet, "Documents and Media", "/documents", "1_column");
136
137 portletId = addPortletId(
138 layout, PortletKeys.DOCUMENT_LIBRARY, "column-1");
139
140 preferences = new HashMap<String, String>();
141
142 preferences.put("portletSetupShowBorders", Boolean.FALSE.toString());
143
144 updatePortletSetup(layout, portletId, preferences);
145
146 portletId = addPortletId(
147 layout, PortletKeys.ASSET_PUBLISHER, "column-2");
148
149 preferences = new HashMap<String, String>();
150
151 preferences.put("anyAssetType", Boolean.FALSE.toString());
152
153 preferences.put(
154 "portletSetupTitle_" + LocaleUtil.getDefault(), "Upcoming Events");
155 preferences.put("portletSetupUseCustomTitle", Boolean.TRUE.toString());
156
157 updatePortletSetup(layout, portletId, preferences);
158
159
160
161 layout = addLayout(layoutSet, "News", "/news", "2_columns_iii");
162
163 portletId = addPortletId(layout, PortletKeys.RSS, "column-1");
164
165 preferences = new HashMap<String, String>();
166
167 preferences.put("expandedEntriesPerFeed", "3");
168 preferences.put(
169 "portletSetupTitle_" + LocaleUtil.getDefault(), "Technology news");
170 preferences.put("portletSetupUseCustomTitle", Boolean.TRUE.toString());
171 preferences.put(
172 "urls", "http:
173
174 updatePortletSetup(layout, portletId, preferences);
175
176 portletId = addPortletId(layout, PortletKeys.RSS, "column-2");
177
178 preferences = new HashMap<String, String>();
179
180 preferences.put("expandedEntriesPerFeed", "0");
181 preferences.put(
182 "portletSetupTitle_" + LocaleUtil.getDefault(), "Liferay news");
183 preferences.put("portletSetupUseCustomTitle", Boolean.TRUE.toString());
184 preferences.put(
185 "urls", "http:
186 preferences.put("titles", "Liferay Press Releases");
187
188 updatePortletSetup(layout, portletId, preferences);
189 }
190
191 protected void addPublicSite(
192 long companyId, long defaultUserId, List<LayoutSetPrototype>
193 layoutSetPrototypes)
194 throws Exception {
195
196 LayoutSet layoutSet = addLayoutSetPrototype(
197 companyId, defaultUserId, "Community Site",
198 "Site with Forums and Wiki", layoutSetPrototypes);
199
200 if (layoutSet == null) {
201 return;
202 }
203
204
205
206 Layout layout = addLayout(layoutSet, "Home", "/home", "2_columns_iii");
207
208 addPortletId(layout, PortletKeys.MESSAGE_BOARDS, "column-1");
209
210 String portletId = addPortletId(layout, PortletKeys.SEARCH, "column-2");
211
212 Map<String, String> preferences = new HashMap<String, String>();
213
214 preferences.put("portletSetupShowBorders", Boolean.FALSE.toString());
215
216 updatePortletSetup(layout, portletId, preferences);
217
218 addPortletId(layout, PortletKeys.POLLS_DISPLAY, "column-2");
219 addPortletId(layout, PortletKeys.USER_STATISTICS, "column-2");
220
221 portletId = addPortletId(
222 layout, PortletKeys.ASSET_PUBLISHER, "column-2");
223
224 preferences = new HashMap<String, String>();
225
226 preferences.put("anyAssetType", Boolean.FALSE.toString());
227
228 preferences.put(
229 "portletSetupTitle_" + LocaleUtil.getDefault(), "Upcoming Events");
230 preferences.put("portletSetupUseCustomTitle", Boolean.TRUE.toString());
231
232 updatePortletSetup(layout, portletId, preferences);
233
234
235
236 layout = addLayout(layoutSet, "Wiki", "/wiki", "2_columns_iii");
237
238 addPortletId(layout, PortletKeys.WIKI, "column-1");
239 addPortletId(
240 layout, PortletKeys.ASSET_CATEGORIES_NAVIGATION, "column-2");
241 addPortletId(layout, PortletKeys.TAGS_CLOUD, "column-2");
242 }
243
244 protected void doRun(long companyId) throws Exception {
245 long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId);
246
247 List<LayoutSetPrototype> layoutSetPrototypes =
248 LayoutSetPrototypeLocalServiceUtil.search(
249 companyId, null, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
250
251 addPublicSite(companyId, defaultUserId, layoutSetPrototypes);
252 addPrivateSite(companyId, defaultUserId, layoutSetPrototypes);
253 }
254
255 }