001
014
015 package com.liferay.portal.service.impl;
016
017 import com.liferay.portal.RequiredLayoutPrototypeException;
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.model.Group;
023 import com.liferay.portal.model.LayoutConstants;
024 import com.liferay.portal.model.LayoutPrototype;
025 import com.liferay.portal.model.ResourceConstants;
026 import com.liferay.portal.security.permission.PermissionCacheUtil;
027 import com.liferay.portal.service.ServiceContext;
028 import com.liferay.portal.service.base.LayoutPrototypeLocalServiceBaseImpl;
029
030 import java.util.List;
031 import java.util.Locale;
032 import java.util.Map;
033
034
039 public class LayoutPrototypeLocalServiceImpl
040 extends LayoutPrototypeLocalServiceBaseImpl {
041
042 @Override
043 public LayoutPrototype addLayoutPrototype(
044 long userId, long companyId, Map<Locale, String> nameMap,
045 String description, boolean active)
046 throws PortalException, SystemException {
047
048
049
050 long layoutPrototypeId = counterLocalService.increment();
051
052 LayoutPrototype layoutPrototype = layoutPrototypePersistence.create(
053 layoutPrototypeId);
054
055 layoutPrototype.setCompanyId(companyId);
056 layoutPrototype.setNameMap(nameMap);
057 layoutPrototype.setDescription(description);
058 layoutPrototype.setActive(active);
059
060 layoutPrototypePersistence.update(layoutPrototype, false);
061
062
063
064 if (userId > 0) {
065 resourceLocalService.addResources(
066 companyId, 0, userId, LayoutPrototype.class.getName(),
067 layoutPrototype.getLayoutPrototypeId(), false, false, false);
068 }
069
070
071
072 String friendlyURL =
073 "/template-" + layoutPrototype.getLayoutPrototypeId();
074
075 Group group = groupLocalService.addGroup(
076 userId, LayoutPrototype.class.getName(),
077 layoutPrototype.getLayoutPrototypeId(),
078 layoutPrototype.getName(LocaleUtil.getDefault()), null, 0,
079 friendlyURL, false, true, null);
080
081 ServiceContext serviceContext = new ServiceContext();
082
083 layoutLocalService.addLayout(
084 userId, group.getGroupId(), true,
085 LayoutConstants.DEFAULT_PARENT_LAYOUT_ID,
086 layoutPrototype.getName(LocaleUtil.getDefault()), null, null,
087 LayoutConstants.TYPE_PORTLET, false, "/layout", serviceContext);
088
089 return layoutPrototype;
090 }
091
092 @Override
093 public LayoutPrototype deleteLayoutPrototype(
094 LayoutPrototype layoutPrototype)
095 throws PortalException, SystemException {
096
097
098
099 if (layoutPersistence.countByLayoutPrototypeUuid(
100 layoutPrototype.getUuid()) > 0) {
101
102 throw new RequiredLayoutPrototypeException();
103 }
104
105 Group group = layoutPrototype.getGroup();
106
107 groupLocalService.deleteGroup(group);
108
109
110
111 resourceLocalService.deleteResource(
112 layoutPrototype.getCompanyId(), LayoutPrototype.class.getName(),
113 ResourceConstants.SCOPE_INDIVIDUAL,
114 layoutPrototype.getLayoutPrototypeId());
115
116
117
118 layoutPrototypePersistence.remove(layoutPrototype);
119
120
121
122 PermissionCacheUtil.clearCache();
123
124 return layoutPrototype;
125 }
126
127 @Override
128 public LayoutPrototype deleteLayoutPrototype(long layoutPrototypeId)
129 throws PortalException, SystemException {
130
131 LayoutPrototype layoutPrototype =
132 layoutPrototypePersistence.findByPrimaryKey(layoutPrototypeId);
133
134 return deleteLayoutPrototype(layoutPrototype);
135 }
136
137 @Override
138 public LayoutPrototype getLayoutPrototypeByUuid(String uuid)
139 throws PortalException, SystemException {
140
141 return layoutPrototypePersistence.findByUuid_First(uuid, null);
142 }
143
144 @Override
145 public List<LayoutPrototype> search(
146 long companyId, Boolean active, int start, int end,
147 OrderByComparator obc)
148 throws SystemException {
149
150 if (active != null) {
151 return layoutPrototypePersistence.findByC_A(
152 companyId, active, start, end, obc);
153 }
154 else {
155 return layoutPrototypePersistence.findByCompanyId(
156 companyId, start, end, obc);
157 }
158 }
159
160 @Override
161 public int searchCount(long companyId, Boolean active)
162 throws SystemException {
163
164 if (active != null) {
165 return layoutPrototypePersistence.countByC_A(companyId, active);
166 }
167 else {
168 return layoutPrototypePersistence.countByCompanyId(companyId);
169 }
170 }
171
172 @Override
173 public LayoutPrototype updateLayoutPrototype(
174 long layoutPrototypeId, Map<Locale, String> nameMap,
175 String description, boolean active)
176 throws PortalException, SystemException {
177
178
179
180 LayoutPrototype layoutPrototype =
181 layoutPrototypePersistence.findByPrimaryKey(layoutPrototypeId);
182
183 layoutPrototype.setNameMap(nameMap);
184 layoutPrototype.setDescription(description);
185 layoutPrototype.setActive(active);
186
187 layoutPrototypePersistence.update(layoutPrototype, false);
188
189
190
191 Group group = groupLocalService.getLayoutPrototypeGroup(
192 layoutPrototype.getCompanyId(), layoutPrototypeId);
193
194 group.setName(layoutPrototype.getName(LocaleUtil.getDefault()));
195
196 groupPersistence.update(group, false);
197
198 return layoutPrototype;
199 }
200
201 }