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.kernel.util.ArrayUtil;
020    import com.liferay.portal.kernel.util.OrderByComparator;
021    import com.liferay.portal.security.permission.ActionKeys;
022    import com.liferay.portal.service.ServiceContext;
023    import com.liferay.portlet.bookmarks.model.BookmarksEntry;
024    import com.liferay.portlet.bookmarks.service.base.BookmarksEntryServiceBaseImpl;
025    import com.liferay.portlet.bookmarks.service.permission.BookmarksEntryPermission;
026    import com.liferay.portlet.bookmarks.service.permission.BookmarksFolderPermission;
027    import com.liferay.portlet.bookmarks.util.comparator.EntryModifiedDateComparator;
028    
029    import java.util.List;
030    
031    /**
032     * @author Brian Wing Shun Chan
033     */
034    public class BookmarksEntryServiceImpl extends BookmarksEntryServiceBaseImpl {
035    
036            @Override
037            public BookmarksEntry addEntry(
038                            long groupId, long folderId, String name, String url,
039                            String description, ServiceContext serviceContext)
040                    throws PortalException, SystemException {
041    
042                    BookmarksFolderPermission.check(
043                            getPermissionChecker(), groupId, folderId, ActionKeys.ADD_ENTRY);
044    
045                    return bookmarksEntryLocalService.addEntry(
046                            getUserId(), groupId, folderId, name, url, description,
047                            serviceContext);
048            }
049    
050            @Override
051            public void deleteEntry(long entryId)
052                    throws PortalException, SystemException {
053    
054                    BookmarksEntryPermission.check(
055                            getPermissionChecker(), entryId, ActionKeys.DELETE);
056    
057                    bookmarksEntryLocalService.deleteEntry(entryId);
058            }
059    
060            @Override
061            public List<BookmarksEntry> getEntries(
062                            long groupId, long folderId, int start, int end)
063                    throws SystemException {
064    
065                    return bookmarksEntryPersistence.filterFindByG_F(
066                            groupId, folderId, start, end);
067            }
068    
069            @Override
070            public List<BookmarksEntry> getEntries(
071                            long groupId, long folderId, int start, int end,
072                            OrderByComparator orderByComparator)
073                    throws SystemException {
074    
075                    return bookmarksEntryPersistence.filterFindByG_F(
076                            groupId, folderId, start, end, orderByComparator);
077            }
078    
079            @Override
080            public int getEntriesCount(long groupId, long folderId)
081                    throws SystemException {
082    
083                    return bookmarksEntryPersistence.filterCountByG_F(groupId, folderId);
084            }
085    
086            @Override
087            public BookmarksEntry getEntry(long entryId)
088                    throws PortalException, SystemException {
089    
090                    BookmarksEntryPermission.check(
091                            getPermissionChecker(), entryId, ActionKeys.VIEW);
092    
093                    return bookmarksEntryLocalService.getEntry(entryId);
094            }
095    
096            @Override
097            public int getFoldersEntriesCount(long groupId, List<Long> folderIds)
098                    throws SystemException {
099    
100                    return bookmarksEntryPersistence.filterCountByG_F(
101                            groupId,
102                            ArrayUtil.toArray(folderIds.toArray(new Long[folderIds.size()])));
103            }
104    
105            @Override
106            public List<BookmarksEntry> getGroupEntries(
107                            long groupId, int start, int end)
108                    throws SystemException {
109    
110                    return bookmarksEntryPersistence.filterFindByGroupId(
111                            groupId, start, end, new EntryModifiedDateComparator());
112            }
113    
114            @Override
115            public List<BookmarksEntry> getGroupEntries(
116                            long groupId, long userId, int start, int end)
117                    throws SystemException {
118    
119                    OrderByComparator orderByComparator = new EntryModifiedDateComparator();
120    
121                    if (userId <= 0) {
122                            return bookmarksEntryPersistence.filterFindByGroupId(
123                                    groupId, start, end, orderByComparator);
124                    }
125                    else {
126                            return bookmarksEntryPersistence.filterFindByG_U(
127                                    groupId, userId, start, end, orderByComparator);
128                    }
129            }
130    
131            @Override
132            public int getGroupEntriesCount(long groupId) throws SystemException {
133                    return bookmarksEntryPersistence.filterCountByGroupId(groupId);
134            }
135    
136            @Override
137            public int getGroupEntriesCount(long groupId, long userId)
138                    throws SystemException {
139    
140                    if (userId <= 0) {
141                            return bookmarksEntryPersistence.filterCountByGroupId(groupId);
142                    }
143                    else {
144                            return bookmarksEntryPersistence.filterCountByG_U(groupId, userId);
145                    }
146            }
147    
148            @Override
149            public BookmarksEntry openEntry(long entryId)
150                    throws PortalException, SystemException {
151    
152                    BookmarksEntryPermission.check(
153                            getPermissionChecker(), entryId, ActionKeys.VIEW);
154    
155                    return bookmarksEntryLocalService.openEntry(
156                            getGuestOrUserId(), entryId);
157            }
158    
159            @Override
160            public BookmarksEntry updateEntry(
161                            long entryId, long groupId, long folderId, String name, String url,
162                            String description, ServiceContext serviceContext)
163                    throws PortalException, SystemException {
164    
165                    BookmarksEntryPermission.check(
166                            getPermissionChecker(), entryId, ActionKeys.UPDATE);
167    
168                    return bookmarksEntryLocalService.updateEntry(
169                            getUserId(), entryId, groupId, folderId, name, url, description,
170                            serviceContext);
171            }
172    
173    }