001
014
015 package com.liferay.portlet.bookmarks.service.impl;
016
017 import com.liferay.portal.kernel.dao.orm.QueryDefinition;
018 import com.liferay.portal.kernel.exception.PortalException;
019 import com.liferay.portal.kernel.exception.SystemException;
020 import com.liferay.portal.kernel.workflow.WorkflowConstants;
021 import com.liferay.portal.security.permission.ActionKeys;
022 import com.liferay.portal.service.ServiceContext;
023 import com.liferay.portlet.bookmarks.model.BookmarksFolder;
024 import com.liferay.portlet.bookmarks.service.base.BookmarksFolderServiceBaseImpl;
025 import com.liferay.portlet.bookmarks.service.permission.BookmarksFolderPermission;
026
027 import java.util.List;
028
029
032 public class BookmarksFolderServiceImpl extends BookmarksFolderServiceBaseImpl {
033
034 public BookmarksFolder addFolder(
035 long parentFolderId, String name, String description,
036 ServiceContext serviceContext)
037 throws PortalException, SystemException {
038
039 BookmarksFolderPermission.check(
040 getPermissionChecker(), serviceContext.getScopeGroupId(),
041 parentFolderId, ActionKeys.ADD_FOLDER);
042
043 return bookmarksFolderLocalService.addFolder(
044 getUserId(), parentFolderId, name, description, serviceContext);
045 }
046
047 public void deleteFolder(long folderId)
048 throws PortalException, SystemException {
049
050 BookmarksFolder folder = bookmarksFolderLocalService.getFolder(
051 folderId);
052
053 BookmarksFolderPermission.check(
054 getPermissionChecker(), folder, ActionKeys.DELETE);
055
056 bookmarksFolderLocalService.deleteFolder(folderId);
057 }
058
059 public void deleteFolder(long folderId, boolean includeTrashedEntries)
060 throws PortalException, SystemException {
061
062 BookmarksFolder folder = bookmarksFolderLocalService.getFolder(
063 folderId);
064
065 BookmarksFolderPermission.check(
066 getPermissionChecker(), folder, ActionKeys.DELETE);
067
068 bookmarksFolderLocalService.deleteFolder(
069 folderId, includeTrashedEntries);
070 }
071
072 public BookmarksFolder getFolder(long folderId)
073 throws PortalException, SystemException {
074
075 BookmarksFolder folder = bookmarksFolderLocalService.getFolder(
076 folderId);
077
078 BookmarksFolderPermission.check(
079 getPermissionChecker(), folder, ActionKeys.VIEW);
080
081 return folder;
082 }
083
084 public List<BookmarksFolder> getFolders(long groupId)
085 throws SystemException {
086
087 return bookmarksFolderPersistence.filterFindByGroupId(groupId);
088 }
089
090 public List<BookmarksFolder> getFolders(long groupId, long parentFolderId)
091 throws SystemException {
092
093 return bookmarksFolderPersistence.filterFindByG_P_S(
094 groupId, parentFolderId, WorkflowConstants.STATUS_APPROVED);
095 }
096
097 public List<BookmarksFolder> getFolders(
098 long groupId, long parentFolderId, int start, int end)
099 throws SystemException {
100
101 return getFolders(
102 groupId, parentFolderId, WorkflowConstants.STATUS_APPROVED, start,
103 end);
104 }
105
106 public List<BookmarksFolder> getFolders(
107 long groupId, long parentFolderId, int status, int start, int end)
108 throws SystemException {
109
110 if (status == WorkflowConstants.STATUS_ANY) {
111 return bookmarksFolderPersistence.filterFindByG_P(
112 groupId, parentFolderId, start, end);
113 }
114 else {
115 return bookmarksFolderPersistence.filterFindByG_P_S(
116 groupId, parentFolderId, status, start, end);
117 }
118 }
119
120 public List<Object> getFoldersAndEntries(long groupId, long folderId)
121 throws SystemException {
122
123 return getFoldersAndEntries(
124 groupId, folderId, WorkflowConstants.STATUS_ANY);
125 }
126
127 public List<Object> getFoldersAndEntries(
128 long groupId, long folderId, int status)
129 throws SystemException {
130
131 QueryDefinition queryDefinition = new QueryDefinition(status);
132
133 return bookmarksFolderFinder.filterFindBF_E_ByG_F(
134 groupId, folderId, queryDefinition);
135 }
136
137 public List<Object> getFoldersAndEntries(
138 long groupId, long folderId, int status, int start, int end)
139 throws SystemException {
140
141 QueryDefinition queryDefinition = new QueryDefinition(
142 status, start, end, null);
143
144 return bookmarksFolderFinder.filterFindBF_E_ByG_F(
145 groupId, folderId, queryDefinition);
146 }
147
148 public int getFoldersAndEntriesCount(long groupId, long folderId)
149 throws SystemException {
150
151 return getFoldersAndEntriesCount(
152 groupId, folderId, WorkflowConstants.STATUS_ANY);
153 }
154
155 public int getFoldersAndEntriesCount(
156 long groupId, long folderId, int status)
157 throws SystemException {
158
159 QueryDefinition queryDefinition = new QueryDefinition(status);
160
161 return bookmarksFolderFinder.filterCountF_E_ByG_F(
162 groupId, folderId, queryDefinition);
163 }
164
165 public int getFoldersCount(long groupId, long parentFolderId)
166 throws SystemException {
167
168 return getFoldersCount(
169 groupId, parentFolderId, WorkflowConstants.STATUS_APPROVED);
170 }
171
172 public int getFoldersCount(long groupId, long parentFolderId, int status)
173 throws SystemException {
174
175 if (status == WorkflowConstants.STATUS_ANY) {
176 return bookmarksFolderPersistence.filterCountByG_P(
177 groupId, parentFolderId);
178 }
179 else {
180 return bookmarksFolderPersistence.filterCountByG_P_S(
181 groupId, parentFolderId, status);
182 }
183 }
184
185 public void getSubfolderIds(
186 List<Long> folderIds, long groupId, long folderId)
187 throws SystemException {
188
189 List<BookmarksFolder> folders =
190 bookmarksFolderPersistence.filterFindByG_P_S(
191 groupId, folderId, WorkflowConstants.STATUS_APPROVED);
192
193 for (BookmarksFolder folder : folders) {
194 folderIds.add(folder.getFolderId());
195
196 getSubfolderIds(
197 folderIds, folder.getGroupId(), folder.getFolderId());
198 }
199 }
200
201 public BookmarksFolder moveFolder(long folderId, long parentFolderId)
202 throws PortalException, SystemException {
203
204 BookmarksFolder folder = bookmarksFolderLocalService.getFolder(
205 folderId);
206
207 BookmarksFolderPermission.check(
208 getPermissionChecker(), folder, ActionKeys.UPDATE);
209
210 return bookmarksFolderLocalService.moveFolder(folderId, parentFolderId);
211 }
212
213 public BookmarksFolder moveFolderFromTrash(
214 long folderId, long parentFolderId)
215 throws PortalException, SystemException {
216
217 BookmarksFolder folder = bookmarksFolderLocalService.getFolder(
218 folderId);
219
220 BookmarksFolderPermission.check(
221 getPermissionChecker(), folder, ActionKeys.UPDATE);
222
223 return bookmarksFolderLocalService.moveFolderFromTrash(
224 getUserId(), folderId, parentFolderId);
225 }
226
227 public void moveFolderToTrash(long folderId)
228 throws PortalException, SystemException {
229
230 BookmarksFolder folder = bookmarksFolderLocalService.getFolder(
231 folderId);
232
233 BookmarksFolderPermission.check(
234 getPermissionChecker(), folder, ActionKeys.DELETE);
235
236 bookmarksFolderLocalService.moveFolderToTrash(getUserId(), folderId);
237 }
238
239 public void restoreFolderFromTrash(long folderId)
240 throws PortalException, SystemException {
241
242 BookmarksFolder folder = bookmarksFolderLocalService.getFolder(
243 folderId);
244
245 BookmarksFolderPermission.check(
246 getPermissionChecker(), folder, ActionKeys.UPDATE);
247
248 bookmarksFolderLocalService.restoreFolderFromTrash(
249 getUserId(), folderId);
250 }
251
252 public void subscribeFolder(long groupId, long folderId)
253 throws PortalException, SystemException {
254
255 BookmarksFolderPermission.check(
256 getPermissionChecker(), groupId, folderId, ActionKeys.SUBSCRIBE);
257
258 bookmarksFolderLocalService.subscribeFolder(
259 getUserId(), groupId, folderId);
260 }
261
262 public void unsubscribeFolder(long groupId, long folderId)
263 throws PortalException, SystemException {
264
265 BookmarksFolderPermission.check(
266 getPermissionChecker(), groupId, folderId, ActionKeys.SUBSCRIBE);
267
268 bookmarksFolderLocalService.unsubscribeFolder(
269 getUserId(), groupId, folderId);
270 }
271
272 public BookmarksFolder updateFolder(
273 long folderId, long parentFolderId, String name, String description,
274 boolean mergeWithParentFolder, ServiceContext serviceContext)
275 throws PortalException, SystemException {
276
277 BookmarksFolder folder = bookmarksFolderLocalService.getFolder(
278 folderId);
279
280 BookmarksFolderPermission.check(
281 getPermissionChecker(), folder, ActionKeys.UPDATE);
282
283 return bookmarksFolderLocalService.updateFolder(
284 getUserId(), folderId, parentFolderId, name, description,
285 mergeWithParentFolder, serviceContext);
286 }
287
288 }