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.trash;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.trash.TrashActionKeys;
020    import com.liferay.portal.model.ContainerModel;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portal.service.ServiceContext;
023    import com.liferay.portlet.bookmarks.model.BookmarksEntry;
024    import com.liferay.portlet.bookmarks.model.BookmarksFolder;
025    import com.liferay.portlet.bookmarks.service.BookmarksEntryLocalServiceUtil;
026    import com.liferay.portlet.bookmarks.service.permission.BookmarksEntryPermission;
027    import com.liferay.portlet.bookmarks.util.BookmarksUtil;
028    
029    import javax.portlet.PortletRequest;
030    
031    /**
032     * Represents the trash handler for bookmarks entries entity.
033     *
034     * @author Levente Hudák
035     * @author Zsolt Berentey
036     */
037    public class BookmarksEntryTrashHandler extends BookmarksBaseTrashHandler {
038    
039            public void deleteTrashEntry(long classPK)
040                    throws PortalException, SystemException {
041    
042                    BookmarksEntryLocalServiceUtil.deleteEntry(classPK);
043            }
044    
045            public String getClassName() {
046                    return BookmarksEntry.class.getName();
047            }
048    
049            @Override
050            public ContainerModel getParentContainerModel(long classPK)
051                    throws PortalException, SystemException {
052    
053                    BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
054    
055                    long parentFolderId = entry.getFolderId();
056    
057                    if (parentFolderId <= 0) {
058                            return null;
059                    }
060    
061                    return getContainerModel(parentFolderId);
062            }
063    
064            @Override
065            public String getRestoreLink(PortletRequest portletRequest, long classPK)
066                    throws PortalException, SystemException {
067    
068                    BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
069    
070                    return BookmarksUtil.getControlPanelLink(
071                            portletRequest, entry.getFolderId());
072            }
073    
074            @Override
075            public String getRestoreMessage(PortletRequest portletRequest, long classPK)
076                    throws PortalException, SystemException {
077    
078                    BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
079    
080                    return BookmarksUtil.getAbsolutePath(
081                            portletRequest, entry.getFolderId());
082            }
083    
084            @Override
085            public ContainerModel getTrashContainer(long classPK)
086                    throws PortalException, SystemException {
087    
088                    BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
089    
090                    return entry.getTrashContainer();
091            }
092    
093            @Override
094            public boolean hasTrashPermission(
095                            PermissionChecker permissionChecker, long groupId, long classPK,
096                            String trashActionId)
097                    throws PortalException, SystemException {
098    
099                    if (trashActionId.equals(TrashActionKeys.MOVE)) {
100                            return true;
101                    }
102    
103                    return super.hasTrashPermission(
104                            permissionChecker, groupId, classPK, trashActionId);
105            }
106    
107            public boolean isInTrash(long classPK)
108                    throws PortalException, SystemException {
109    
110                    BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
111    
112                    return entry.isInTrash();
113            }
114    
115            @Override
116            public boolean isInTrashContainer(long classPK)
117                    throws PortalException, SystemException {
118    
119                    BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
120    
121                    return entry.isInTrashContainer();
122            }
123    
124            @Override
125            public boolean isRestorable(long classPK)
126                    throws PortalException, SystemException {
127    
128                    BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
129    
130                    return !entry.isInTrashContainer();
131            }
132    
133            @Override
134            public void moveEntry(
135                            long userId, long classPK, long containerModelId,
136                            ServiceContext serviceContext)
137                    throws PortalException, SystemException {
138    
139                    BookmarksEntryLocalServiceUtil.moveEntry(classPK, containerModelId);
140            }
141    
142            @Override
143            public void moveTrashEntry(
144                            long userId, long classPK, long containerId,
145                            ServiceContext serviceContext)
146                    throws PortalException, SystemException {
147    
148                    BookmarksEntryLocalServiceUtil.moveEntryFromTrash(
149                            userId, classPK, containerId);
150            }
151    
152            public void restoreTrashEntry(long userId, long classPK)
153                    throws PortalException, SystemException {
154    
155                    BookmarksEntryLocalServiceUtil.restoreEntryFromTrash(userId, classPK);
156            }
157    
158            @Override
159            protected BookmarksFolder getBookmarksFolder(long classPK)
160                    throws PortalException, SystemException {
161    
162                    BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
163    
164                    return entry.getFolder();
165            }
166    
167            @Override
168            protected boolean hasPermission(
169                            PermissionChecker permissionChecker, long classPK, String actionId)
170                    throws PortalException, SystemException {
171    
172                    BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
173    
174                    return BookmarksEntryPermission.contains(
175                            permissionChecker, entry, actionId);
176            }
177    
178    }