001
014
015 package com.liferay.portal.service.impl;
016
017 import com.liferay.portal.RequiredLayoutSetPrototypeException;
018 import com.liferay.portal.kernel.exception.PortalException;
019 import com.liferay.portal.kernel.exception.SystemException;
020 import com.liferay.portal.kernel.util.LocaleUtil;
021 import com.liferay.portal.kernel.util.OrderByComparator;
022 import com.liferay.portal.kernel.util.UnicodeProperties;
023 import com.liferay.portal.model.Group;
024 import com.liferay.portal.model.GroupConstants;
025 import com.liferay.portal.model.LayoutConstants;
026 import com.liferay.portal.model.LayoutSetPrototype;
027 import com.liferay.portal.model.ResourceConstants;
028 import com.liferay.portal.model.User;
029 import com.liferay.portal.security.permission.PermissionCacheUtil;
030 import com.liferay.portal.service.ServiceContext;
031 import com.liferay.portal.service.base.LayoutSetPrototypeLocalServiceBaseImpl;
032
033 import java.util.Date;
034 import java.util.List;
035 import java.util.Locale;
036 import java.util.Map;
037
038
042 public class LayoutSetPrototypeLocalServiceImpl
043 extends LayoutSetPrototypeLocalServiceBaseImpl {
044
045 public LayoutSetPrototype addLayoutSetPrototype(
046 long userId, long companyId, Map<Locale, String> nameMap,
047 String description, boolean active, boolean layoutsUpdateable,
048 ServiceContext serviceContext)
049 throws PortalException, SystemException {
050
051
052
053 User user = userPersistence.findByPrimaryKey(userId);
054 Date now = new Date();
055
056 long layoutSetPrototypeId = counterLocalService.increment();
057
058 LayoutSetPrototype layoutSetPrototype =
059 layoutSetPrototypePersistence.create(layoutSetPrototypeId);
060
061 layoutSetPrototype.setUuid(serviceContext.getUuid());
062 layoutSetPrototype.setCompanyId(companyId);
063 layoutSetPrototype.setUserId(userId);
064 layoutSetPrototype.setUserName(user.getFullName());
065 layoutSetPrototype.setCreateDate(serviceContext.getCreateDate(now));
066 layoutSetPrototype.setModifiedDate(serviceContext.getModifiedDate(now));
067 layoutSetPrototype.setNameMap(nameMap);
068 layoutSetPrototype.setDescription(description);
069 layoutSetPrototype.setActive(active);
070
071 UnicodeProperties settingsProperties =
072 layoutSetPrototype.getSettingsProperties();
073
074 settingsProperties.put(
075 "layoutsUpdateable", String.valueOf(layoutsUpdateable));
076
077 layoutSetPrototype.setSettingsProperties(settingsProperties);
078
079 layoutSetPrototypePersistence.update(layoutSetPrototype);
080
081
082
083 if (userId > 0) {
084 resourceLocalService.addResources(
085 companyId, 0, userId, LayoutSetPrototype.class.getName(),
086 layoutSetPrototype.getLayoutSetPrototypeId(), false, false,
087 false);
088 }
089
090
091
092 String friendlyURL =
093 "/template-" + layoutSetPrototype.getLayoutSetPrototypeId();
094
095 Group group = groupLocalService.addGroup(
096 userId, GroupConstants.DEFAULT_PARENT_GROUP_ID,
097 LayoutSetPrototype.class.getName(),
098 layoutSetPrototype.getLayoutSetPrototypeId(),
099 GroupConstants.DEFAULT_LIVE_GROUP_ID,
100 layoutSetPrototype.getName(LocaleUtil.getDefault()), null, 0,
101 friendlyURL, false, true, serviceContext);
102
103 layoutLocalService.addLayout(
104 userId, group.getGroupId(), true,
105 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "home", null, null,
106 LayoutConstants.TYPE_PORTLET, false, "/home", serviceContext);
107
108 return layoutSetPrototype;
109 }
110
111 @Override
112 public LayoutSetPrototype deleteLayoutSetPrototype(
113 LayoutSetPrototype layoutSetPrototype)
114 throws PortalException, SystemException {
115
116
117
118 if (layoutSetPersistence.countByLayoutSetPrototypeUuid(
119 layoutSetPrototype.getUuid()) > 0) {
120
121 throw new RequiredLayoutSetPrototypeException();
122 }
123
124 Group group = layoutSetPrototype.getGroup();
125
126 groupLocalService.deleteGroup(group);
127
128
129
130 resourceLocalService.deleteResource(
131 layoutSetPrototype.getCompanyId(),
132 LayoutSetPrototype.class.getName(),
133 ResourceConstants.SCOPE_INDIVIDUAL,
134 layoutSetPrototype.getLayoutSetPrototypeId());
135
136
137
138 layoutSetPrototypePersistence.remove(layoutSetPrototype);
139
140
141
142 PermissionCacheUtil.clearCache();
143
144 return layoutSetPrototype;
145 }
146
147 @Override
148 public LayoutSetPrototype deleteLayoutSetPrototype(
149 long layoutSetPrototypeId)
150 throws PortalException, SystemException {
151
152 LayoutSetPrototype layoutSetPrototype =
153 layoutSetPrototypePersistence.findByPrimaryKey(
154 layoutSetPrototypeId);
155
156 return deleteLayoutSetPrototype(layoutSetPrototype);
157 }
158
159 public LayoutSetPrototype fetchLayoutSetPrototypeByUuidAndCompanyId(
160 String uuid, long companyId)
161 throws SystemException {
162
163 return layoutSetPrototypePersistence.fetchByUuid_C_First(
164 uuid, companyId, null);
165 }
166
167
171 public LayoutSetPrototype getLayoutSetPrototypeByUuid(String uuid)
172 throws PortalException, SystemException {
173
174 return layoutSetPrototypePersistence.findByUuid_First(uuid, null);
175 }
176
177 public LayoutSetPrototype getLayoutSetPrototypeByUuidAndCompanyId(
178 String uuid, long companyId)
179 throws PortalException, SystemException {
180
181 return layoutSetPrototypePersistence.findByUuid_C_First(
182 uuid, companyId, null);
183 }
184
185 public List<LayoutSetPrototype> search(
186 long companyId, Boolean active, int start, int end,
187 OrderByComparator obc)
188 throws SystemException {
189
190 if (active != null) {
191 return layoutSetPrototypePersistence.findByC_A(
192 companyId, active, start, end, obc);
193 }
194 else {
195 return layoutSetPrototypePersistence.findByCompanyId(
196 companyId, start, end, obc);
197 }
198 }
199
200 public int searchCount(long companyId, Boolean active)
201 throws SystemException {
202
203 if (active != null) {
204 return layoutSetPrototypePersistence.countByC_A(companyId, active);
205 }
206 else {
207 return layoutSetPrototypePersistence.countByCompanyId(companyId);
208 }
209 }
210
211 public LayoutSetPrototype updateLayoutSetPrototype(
212 long layoutSetPrototypeId, Map<Locale, String> nameMap,
213 String description, boolean active, boolean layoutsUpdateable,
214 ServiceContext serviceContext)
215 throws PortalException, SystemException {
216
217
218
219 LayoutSetPrototype layoutSetPrototype =
220 layoutSetPrototypePersistence.findByPrimaryKey(
221 layoutSetPrototypeId);
222
223 layoutSetPrototype.setModifiedDate(
224 serviceContext.getModifiedDate(new Date()));
225 layoutSetPrototype.setNameMap(nameMap);
226 layoutSetPrototype.setDescription(description);
227 layoutSetPrototype.setActive(active);
228
229 UnicodeProperties settingsProperties =
230 layoutSetPrototype.getSettingsProperties();
231
232 settingsProperties.put(
233 "layoutsUpdateable", String.valueOf(layoutsUpdateable));
234
235 layoutSetPrototype.setSettingsProperties(settingsProperties);
236
237 layoutSetPrototypePersistence.update(layoutSetPrototype);
238
239
240
241 Group group = groupLocalService.getLayoutSetPrototypeGroup(
242 layoutSetPrototype.getCompanyId(), layoutSetPrototypeId);
243
244 group.setName(layoutSetPrototype.getName(LocaleUtil.getDefault()));
245
246 groupPersistence.update(group);
247
248 return layoutSetPrototype;
249 }
250
251 public LayoutSetPrototype updateLayoutSetPrototype(
252 long layoutSetPrototypeId, String settings)
253 throws PortalException, SystemException {
254
255
256
257 LayoutSetPrototype layoutSetPrototype =
258 layoutSetPrototypePersistence.findByPrimaryKey(
259 layoutSetPrototypeId);
260
261 layoutSetPrototype.setModifiedDate(new Date());
262 layoutSetPrototype.setSettings(settings);
263
264 layoutSetPrototypePersistence.update(layoutSetPrototype);
265
266
267
268 UnicodeProperties settingsProperties =
269 layoutSetPrototype.getSettingsProperties();
270
271 if (!settingsProperties.containsKey("customJspServletContextName")) {
272 return layoutSetPrototype;
273 }
274
275 Group group = groupLocalService.getLayoutSetPrototypeGroup(
276 layoutSetPrototype.getCompanyId(), layoutSetPrototypeId);
277
278 UnicodeProperties typeSettingsProperties =
279 group.getTypeSettingsProperties();
280
281 typeSettingsProperties.setProperty(
282 "customJspServletContextName",
283 settingsProperties.getProperty("customJspServletContextName"));
284
285 group.setTypeSettings(typeSettingsProperties.toString());
286
287 groupPersistence.update(group);
288
289 return layoutSetPrototype;
290 }
291
292 }