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.language.LanguageUtil;
020 import com.liferay.portal.kernel.util.GetterUtil;
021 import com.liferay.portal.kernel.util.LocaleUtil;
022 import com.liferay.portal.model.Layout;
023 import com.liferay.portal.model.LayoutSet;
024 import com.liferay.portal.model.LayoutSetPrototype;
025 import com.liferay.portal.service.LayoutLocalServiceUtil;
026 import com.liferay.portal.service.LayoutSetPrototypeLocalServiceUtil;
027 import com.liferay.portal.service.ServiceContext;
028 import com.liferay.portal.service.UserLocalServiceUtil;
029 import com.liferay.portal.util.PortletKeys;
030
031 import java.util.HashMap;
032 import java.util.List;
033 import java.util.Locale;
034 import java.util.Map;
035
036
039 public class AddDefaultLayoutSetPrototypesAction
040 extends BaseDefaultLayoutPrototypesAction {
041
042 @Override
043 public void run(String[] ids) throws ActionException {
044 try {
045 doRun(GetterUtil.getLong(ids[0]));
046 }
047 catch (Exception e) {
048 throw new ActionException(e);
049 }
050 }
051
052 protected LayoutSet addLayoutSetPrototype(
053 long companyId, long defaultUserId, String nameKey,
054 String descriptionKey, List<LayoutSetPrototype> layoutSetPrototypes)
055 throws Exception {
056
057 String name = LanguageUtil.get(LocaleUtil.getDefault(), nameKey);
058 String description = LanguageUtil.get(
059 LocaleUtil.getDefault(), descriptionKey);
060
061 for (LayoutSetPrototype layoutSetPrototype : layoutSetPrototypes) {
062 String curName = layoutSetPrototype.getName(
063 LocaleUtil.getDefault());
064 String curDescription = layoutSetPrototype.getDescription(
065 LocaleUtil.getDefault());
066
067 if (name.equals(curName) && description.equals(curDescription)) {
068 return null;
069 }
070 }
071
072 Map<Locale, String> nameMap = new HashMap<Locale, String>();
073 Map<Locale, String> descriptionMap = new HashMap<Locale, String>();
074
075 Locale[] locales = LanguageUtil.getAvailableLocales();
076
077 for (Locale locale : locales) {
078 nameMap.put(locale, LanguageUtil.get(locale, nameKey));
079 descriptionMap.put(
080 locale, LanguageUtil.get(locale, descriptionKey));
081 }
082
083 LayoutSetPrototype layoutSetPrototype =
084 LayoutSetPrototypeLocalServiceUtil.addLayoutSetPrototype(
085 defaultUserId, companyId, nameMap, descriptionMap, true, true,
086 new ServiceContext());
087
088 LayoutSet layoutSet = layoutSetPrototype.getLayoutSet();
089
090 ServiceContext serviceContext = new ServiceContext();
091
092 LayoutLocalServiceUtil.deleteLayouts(
093 layoutSet.getGroupId(), layoutSet.isPrivateLayout(),
094 serviceContext);
095
096 return layoutSetPrototype.getLayoutSet();
097 }
098
099 protected void addPrivateSite(
100 long companyId, long defaultUserId,
101 List<LayoutSetPrototype> layoutSetPrototypes)
102 throws Exception {
103
104 LayoutSet layoutSet = addLayoutSetPrototype(
105 companyId, defaultUserId,
106 "layout-set-prototype-intranet-site-title",
107 "layout-set-prototype-intranet-site-description",
108 layoutSetPrototypes);
109
110 if (layoutSet == null) {
111 return;
112 }
113
114
115
116 Layout layout = addLayout(layoutSet, "home", "/home", "2_columns_i");
117
118 String portletId = addPortletId(layout, PortletKeys.SEARCH, "column-2");
119
120 Map<String, String> preferences = new HashMap<String, String>();
121
122 preferences.put("portletSetupShowBorders", Boolean.FALSE.toString());
123
124 updatePortletSetup(layout, portletId, preferences);
125
126 portletId = addPortletId(layout, PortletKeys.LANGUAGE, "column-2");
127
128 preferences = new HashMap<String, String>();
129
130 preferences.put("displayStyle", "3");
131
132 updatePortletSetup(layout, portletId, preferences);
133
134 portletId = addPortletId(
135 layout, PortletKeys.ASSET_PUBLISHER, "column-2");
136
137 preferences = new HashMap<String, String>();
138
139 Locale[] locales = LanguageUtil.getAvailableLocales();
140
141 for (Locale locale : locales) {
142 preferences.put(
143 "portletSetupTitle_" + locale,
144 LanguageUtil.get(locale, "recent-content"));
145 }
146
147 preferences.put("portletSetupUseCustomTitle", Boolean.TRUE.toString());
148
149 updatePortletSetup(layout, portletId, preferences);
150
151
152
153 layout = addLayout(
154 layoutSet, "documents-and-media", "/documents", "1_column");
155
156 portletId = addPortletId(
157 layout, PortletKeys.DOCUMENT_LIBRARY, "column-1");
158
159 preferences = new HashMap<String, String>();
160
161 preferences.put("portletSetupShowBorders", Boolean.FALSE.toString());
162
163 updatePortletSetup(layout, portletId, preferences);
164
165 portletId = addPortletId(
166 layout, PortletKeys.ASSET_PUBLISHER, "column-2");
167
168 preferences = new HashMap<String, String>();
169
170 preferences.put("anyAssetType", Boolean.FALSE.toString());
171
172 for (Locale locale : locales) {
173 preferences.put(
174 "portletSetupTitle_" + locale,
175 LanguageUtil.get(locale, "upcoming-events"));
176 }
177
178 preferences.put("portletSetupUseCustomTitle", Boolean.TRUE.toString());
179
180 updatePortletSetup(layout, portletId, preferences);
181
182
183
184 layout = addLayout(layoutSet, "news", "/news", "2_columns_iii");
185
186 portletId = addPortletId(layout, PortletKeys.RSS, "column-1");
187
188 preferences = new HashMap<String, String>();
189
190 preferences.put("expandedEntriesPerFeed", "3");
191
192 for (Locale locale : locales) {
193 preferences.put(
194 "portletSetupTitle_" + locale,
195 LanguageUtil.get(locale, "technology-news"));
196 }
197
198 preferences.put("portletSetupUseCustomTitle", Boolean.TRUE.toString());
199 preferences.put(
200 "urls", "http:
201
202 updatePortletSetup(layout, portletId, preferences);
203
204 portletId = addPortletId(layout, PortletKeys.RSS, "column-2");
205
206 preferences = new HashMap<String, String>();
207
208 preferences.put("expandedEntriesPerFeed", "0");
209
210 for (Locale locale : locales) {
211 preferences.put(
212 "portletSetupTitle_" + locale,
213 LanguageUtil.get(locale, "liferay-news"));
214 }
215
216 preferences.put("portletSetupUseCustomTitle", Boolean.TRUE.toString());
217 preferences.put(
218 "urls", "http:
219 preferences.put("titles", "Liferay Press Releases");
220
221 updatePortletSetup(layout, portletId, preferences);
222 }
223
224 protected void addPublicSite(
225 long companyId, long defaultUserId,
226 List<LayoutSetPrototype> layoutSetPrototypes)
227 throws Exception {
228
229 LayoutSet layoutSet = addLayoutSetPrototype(
230 companyId, defaultUserId,
231 "layout-set-prototype-community-site-title",
232 "layout-set-prototype-community-site-description",
233 layoutSetPrototypes);
234
235 if (layoutSet == null) {
236 return;
237 }
238
239
240
241 Layout layout = addLayout(layoutSet, "home", "/home", "2_columns_iii");
242
243 addPortletId(layout, PortletKeys.MESSAGE_BOARDS, "column-1");
244
245 String portletId = addPortletId(layout, PortletKeys.SEARCH, "column-2");
246
247 Map<String, String> preferences = new HashMap<String, String>();
248
249 preferences.put("portletSetupShowBorders", Boolean.FALSE.toString());
250
251 updatePortletSetup(layout, portletId, preferences);
252
253 addPortletId(layout, PortletKeys.USER_STATISTICS, "column-2");
254
255 portletId = addPortletId(
256 layout, PortletKeys.ASSET_PUBLISHER, "column-2");
257
258 preferences = new HashMap<String, String>();
259
260 preferences.put("anyAssetType", Boolean.FALSE.toString());
261
262 Locale[] locales = LanguageUtil.getAvailableLocales();
263
264 for (Locale locale : locales) {
265 preferences.put(
266 "portletSetupTitle_" + locale,
267 LanguageUtil.get(locale, "upcoming-events"));
268 }
269
270 preferences.put("portletSetupUseCustomTitle", Boolean.TRUE.toString());
271
272 updatePortletSetup(layout, portletId, preferences);
273
274
275
276 layout = addLayout(layoutSet, "wiki", "/wiki", "2_columns_iii");
277
278 addPortletId(layout, PortletKeys.WIKI, "column-1");
279 addPortletId(
280 layout, PortletKeys.ASSET_CATEGORIES_NAVIGATION, "column-2");
281 addPortletId(layout, PortletKeys.TAGS_CLOUD, "column-2");
282 }
283
284 protected void doRun(long companyId) throws Exception {
285 long defaultUserId = UserLocalServiceUtil.getDefaultUserId(companyId);
286
287 List<LayoutSetPrototype> layoutSetPrototypes =
288 LayoutSetPrototypeLocalServiceUtil.search(
289 companyId, null, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
290
291 addPublicSite(companyId, defaultUserId, layoutSetPrototypes);
292 addPrivateSite(companyId, defaultUserId, layoutSetPrototypes);
293 }
294
295 }