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.LayoutPrototype;
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.LayoutPrototypeLocalServiceBaseImpl;
28
29 import java.util.List;
30 import java.util.Locale;
31 import java.util.Map;
32
33
40 public class LayoutPrototypeLocalServiceImpl
41 extends LayoutPrototypeLocalServiceBaseImpl {
42
43 public LayoutPrototype addLayoutPrototype(
44 long userId, long companyId, Map<Locale, String> nameMap,
45 String description, boolean active)
46 throws PortalException, SystemException {
47
48
50 long layoutPrototypeId = counterLocalService.increment();
51
52 LayoutPrototype layoutPrototype = layoutPrototypePersistence.create(
53 layoutPrototypeId);
54
55 layoutPrototype.setCompanyId(companyId);
56 layoutPrototype.setNameMap(nameMap);
57 layoutPrototype.setDescription(description);
58 layoutPrototype.setActive(active);
59
60 layoutPrototypePersistence.update(layoutPrototype, false);
61
62
64 if (userId > 0) {
65 resourceLocalService.addResources(
66 companyId, 0, userId, LayoutPrototype.class.getName(),
67 layoutPrototype.getLayoutPrototypeId(), false, false, false);
68 }
69
70
72 String friendlyURL =
73 "/template-" + layoutPrototype.getLayoutPrototypeId();
74
75 Group group = groupLocalService.addGroup(
76 userId, LayoutPrototype.class.getName(),
77 layoutPrototype.getLayoutPrototypeId(),
78 layoutPrototype.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,
86 String.valueOf(layoutPrototype.getLayoutPrototypeId()), null, null,
87 LayoutConstants.TYPE_PORTLET, false, "/layout", serviceContext);
88
89 return layoutPrototype;
90 }
91
92 public void deleteLayoutPrototype(long layoutPrototypeId)
93 throws PortalException, SystemException {
94
95 LayoutPrototype layoutPrototype =
96 layoutPrototypePersistence.findByPrimaryKey(layoutPrototypeId);
97
98
100 Group group = layoutPrototype.getGroup();
101
102 groupLocalService.deleteGroup(group.getGroupId());
103
104
106 resourceLocalService.deleteResource(
107 layoutPrototype.getCompanyId(), LayoutPrototype.class.getName(),
108 ResourceConstants.SCOPE_INDIVIDUAL,
109 layoutPrototype.getLayoutPrototypeId());
110
111
113 layoutPrototypePersistence.remove(layoutPrototype);
114
115
117 PermissionCacheUtil.clearCache();
118 }
119
120 public List<LayoutPrototype> search(
121 long companyId, Boolean active, int start, int end,
122 OrderByComparator obc)
123 throws SystemException {
124
125 if (active != null) {
126 return layoutPrototypePersistence.findByC_A(
127 companyId, active, start, end, obc);
128 }
129 else {
130 return layoutPrototypePersistence.findByCompanyId(
131 companyId, start, end, obc);
132 }
133 }
134
135 public int searchCount(long companyId, Boolean active)
136 throws SystemException {
137
138 if (active != null) {
139 return layoutPrototypePersistence.countByC_A(companyId, active);
140 }
141 else {
142 return layoutPrototypePersistence.countByCompanyId(companyId);
143 }
144 }
145
146 public LayoutPrototype updateLayoutPrototype(
147 long layoutPrototypeId, Map<Locale, String> nameMap,
148 String description, boolean active)
149 throws PortalException, SystemException {
150
151
153 LayoutPrototype layoutPrototype =
154 layoutPrototypePersistence.findByPrimaryKey(layoutPrototypeId);
155
156 layoutPrototype.setNameMap(nameMap);
157 layoutPrototype.setDescription(description);
158 layoutPrototype.setActive(active);
159
160 layoutPrototypePersistence.update(layoutPrototype, false);
161
162
164 Group group = groupLocalService.getLayoutPrototypeGroup(
165 layoutPrototype.getCompanyId(), layoutPrototypeId);
166
167 group.setName(layoutPrototype.getName(LocaleUtil.getDefault()));
168
169 groupPersistence.update(group, false);
170
171 return layoutPrototype;
172 }
173
174 }