1
14
15 package com.liferay.portal.service.impl;
16
17 import com.liferay.portal.kernel.exception.PortalException;
18 import com.liferay.portal.kernel.exception.SystemException;
19 import com.liferay.portal.kernel.util.LocaleUtil;
20 import com.liferay.portal.kernel.util.OrderByComparator;
21 import com.liferay.portal.model.Group;
22 import com.liferay.portal.model.LayoutConstants;
23 import com.liferay.portal.model.LayoutSetPrototype;
24 import com.liferay.portal.model.ResourceConstants;
25 import com.liferay.portal.security.permission.PermissionCacheUtil;
26 import com.liferay.portal.service.ServiceContext;
27 import com.liferay.portal.service.base.LayoutSetPrototypeLocalServiceBaseImpl;
28
29 import java.util.List;
30 import java.util.Locale;
31 import java.util.Map;
32
33
39 public class LayoutSetPrototypeLocalServiceImpl
40 extends LayoutSetPrototypeLocalServiceBaseImpl {
41
42 public LayoutSetPrototype addLayoutSetPrototype(
43 long userId, long companyId, Map<Locale, String> nameMap,
44 String description, boolean active)
45 throws PortalException, SystemException {
46
47
49 long layoutSetPrototypeId = counterLocalService.increment();
50
51 LayoutSetPrototype layoutSetPrototype =
52 layoutSetPrototypePersistence.create(layoutSetPrototypeId);
53
54 layoutSetPrototype.setCompanyId(companyId);
55 layoutSetPrototype.setNameMap(nameMap);
56 layoutSetPrototype.setDescription(description);
57 layoutSetPrototype.setActive(active);
58
59 layoutSetPrototypePersistence.update(layoutSetPrototype, false);
60
61
63 if (userId > 0) {
64 resourceLocalService.addResources(
65 companyId, 0, userId, LayoutSetPrototype.class.getName(),
66 layoutSetPrototype.getLayoutSetPrototypeId(), false, false,
67 false);
68 }
69
70
72 String friendlyURL =
73 "/template-" + layoutSetPrototype.getLayoutSetPrototypeId();
74
75 Group group = groupLocalService.addGroup(
76 userId, LayoutSetPrototype.class.getName(),
77 layoutSetPrototype.getLayoutSetPrototypeId(),
78 layoutSetPrototype.getName(LocaleUtil.getDefault()), null, 0,
79 friendlyURL, true, null);
80
81 ServiceContext serviceContext = new ServiceContext();
82
83 layoutLocalService.addLayout(
84 userId, group.getGroupId(), true,
85 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID, "home", null, null,
86 LayoutConstants.TYPE_PORTLET, false, "/home", serviceContext);
87
88 return layoutSetPrototype;
89 }
90
91 public void deleteLayoutSetPrototype(long layoutSetPrototypeId)
92 throws PortalException, SystemException {
93
94 LayoutSetPrototype layoutSetPrototype =
95 layoutSetPrototypePersistence.findByPrimaryKey(
96 layoutSetPrototypeId);
97
98
100 Group group = layoutSetPrototype.getGroup();
101
102 groupLocalService.deleteGroup(group.getGroupId());
103
104
106 resourceLocalService.deleteResource(
107 layoutSetPrototype.getCompanyId(),
108 LayoutSetPrototype.class.getName(),
109 ResourceConstants.SCOPE_INDIVIDUAL,
110 layoutSetPrototype.getLayoutSetPrototypeId());
111
112
114 layoutSetPrototypePersistence.remove(layoutSetPrototype);
115
116
118 PermissionCacheUtil.clearCache();
119 }
120
121 public List<LayoutSetPrototype> search(
122 long companyId, Boolean active, int start, int end,
123 OrderByComparator obc)
124 throws SystemException {
125
126 if (active != null) {
127 return layoutSetPrototypePersistence.findByC_A(
128 companyId, active, start, end, obc);
129 }
130 else {
131 return layoutSetPrototypePersistence.findByCompanyId(
132 companyId, start, end, obc);
133 }
134 }
135
136 public int searchCount(long companyId, Boolean active)
137 throws SystemException {
138
139 if (active != null) {
140 return layoutSetPrototypePersistence.countByC_A(companyId, active);
141 }
142 else {
143 return layoutSetPrototypePersistence.countByCompanyId(companyId);
144 }
145 }
146
147 public LayoutSetPrototype updateLayoutSetPrototype(
148 long layoutSetPrototypeId, Map<Locale, String> nameMap,
149 String description, boolean active)
150 throws PortalException, SystemException {
151
152
154 LayoutSetPrototype layoutSetPrototype =
155 layoutSetPrototypePersistence.findByPrimaryKey(
156 layoutSetPrototypeId);
157
158 layoutSetPrototype.setNameMap(nameMap);
159 layoutSetPrototype.setDescription(description);
160 layoutSetPrototype.setActive(active);
161
162 layoutSetPrototypePersistence.update(layoutSetPrototype, false);
163
164
166 Group group = groupLocalService.getLayoutSetPrototypeGroup(
167 layoutSetPrototype.getCompanyId(), layoutSetPrototypeId);
168
169 group.setName(layoutSetPrototype.getName(LocaleUtil.getDefault()));
170
171 groupPersistence.update(group, false);
172
173 return layoutSetPrototype;
174 }
175
176 }