001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.bookmarks.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.security.permission.ActionKeys;
020    import com.liferay.portal.service.ServiceContext;
021    import com.liferay.portlet.bookmarks.model.BookmarksFolder;
022    import com.liferay.portlet.bookmarks.service.base.BookmarksFolderServiceBaseImpl;
023    import com.liferay.portlet.bookmarks.service.permission.BookmarksFolderPermission;
024    
025    import java.util.List;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class BookmarksFolderServiceImpl extends BookmarksFolderServiceBaseImpl {
031    
032            @Override
033            public BookmarksFolder addFolder(
034                            long parentFolderId, String name, String description,
035                            ServiceContext serviceContext)
036                    throws PortalException, SystemException {
037    
038                    BookmarksFolderPermission.check(
039                            getPermissionChecker(), serviceContext.getScopeGroupId(),
040                            parentFolderId, ActionKeys.ADD_FOLDER);
041    
042                    return bookmarksFolderLocalService.addFolder(
043                            getUserId(), parentFolderId, name, description, serviceContext);
044            }
045    
046            @Override
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            @Override
060            public BookmarksFolder getFolder(long folderId)
061                    throws PortalException, SystemException {
062    
063                    BookmarksFolder folder = bookmarksFolderLocalService.getFolder(
064                            folderId);
065    
066                    BookmarksFolderPermission.check(
067                            getPermissionChecker(), folder, ActionKeys.VIEW);
068    
069                    return folder;
070            }
071    
072            @Override
073            public List<BookmarksFolder> getFolders(long groupId)
074                    throws SystemException {
075    
076                    return bookmarksFolderPersistence.filterFindByGroupId(groupId);
077            }
078    
079            @Override
080            public List<BookmarksFolder> getFolders(long groupId, long parentFolderId)
081                    throws SystemException {
082    
083                    return bookmarksFolderPersistence.filterFindByG_P(
084                            groupId, parentFolderId);
085            }
086    
087            @Override
088            public List<BookmarksFolder> getFolders(
089                            long groupId, long parentFolderId, int start, int end)
090                    throws SystemException {
091    
092                    return bookmarksFolderPersistence.filterFindByG_P(
093                            groupId, parentFolderId, start, end);
094            }
095    
096            @Override
097            public int getFoldersCount(long groupId, long parentFolderId)
098                    throws SystemException {
099    
100                    return bookmarksFolderPersistence.filterCountByG_P(
101                            groupId, parentFolderId);
102            }
103    
104            @Override
105            public void getSubfolderIds(
106                            List<Long> folderIds, long groupId, long folderId)
107                    throws SystemException {
108    
109                    List<BookmarksFolder> folders =
110                            bookmarksFolderPersistence.filterFindByG_P(groupId, folderId);
111    
112                    for (BookmarksFolder folder : folders) {
113                            folderIds.add(folder.getFolderId());
114    
115                            getSubfolderIds(
116                                    folderIds, folder.getGroupId(), folder.getFolderId());
117                    }
118            }
119    
120            @Override
121            public BookmarksFolder updateFolder(
122                            long folderId, long parentFolderId, String name, String description,
123                            boolean mergeWithParentFolder, ServiceContext serviceContext)
124                    throws PortalException, SystemException {
125    
126                    BookmarksFolder folder = bookmarksFolderLocalService.getFolder(
127                            folderId);
128    
129                    BookmarksFolderPermission.check(
130                            getPermissionChecker(), folder, ActionKeys.UPDATE);
131    
132                    return bookmarksFolderLocalService.updateFolder(
133                            folderId, parentFolderId, name, description, mergeWithParentFolder,
134                            serviceContext);
135            }
136    
137    }