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.TrashRenderer;
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.asset.BookmarksFolderAssetRenderer;
024    import com.liferay.portlet.bookmarks.model.BookmarksFolder;
025    import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
026    import com.liferay.portlet.bookmarks.service.permission.BookmarksFolderPermission;
027    import com.liferay.portlet.bookmarks.util.BookmarksUtil;
028    
029    import javax.portlet.PortletRequest;
030    
031    /**
032     * Represents the trash handler for bookmarks folder entity.
033     *
034     * @author Eudaldo Alonso
035     */
036    public class BookmarksFolderTrashHandler extends BookmarksBaseTrashHandler {
037    
038            public void deleteTrashEntry(long classPK)
039                    throws PortalException, SystemException {
040    
041                    BookmarksFolderLocalServiceUtil.deleteFolder(classPK, false);
042            }
043    
044            public String getClassName() {
045                    return BookmarksFolder.class.getName();
046            }
047    
048            @Override
049            public String getDeleteMessage() {
050                    return "found-in-deleted-folder-x";
051            }
052    
053            @Override
054            public ContainerModel getParentContainerModel(long classPK)
055                    throws PortalException, SystemException {
056    
057                    BookmarksFolder folder = getBookmarksFolder(classPK);
058    
059                    long parentFolderId = folder.getParentFolderId();
060    
061                    if (parentFolderId <= 0) {
062                            return null;
063                    }
064    
065                    return getContainerModel(parentFolderId);
066            }
067    
068            @Override
069            public String getRestoreLink(PortletRequest portletRequest, long classPK)
070                    throws PortalException, SystemException {
071    
072                    BookmarksFolder folder = getBookmarksFolder(classPK);
073    
074                    return BookmarksUtil.getControlPanelLink(
075                            portletRequest, folder.getParentFolderId());
076            }
077    
078            @Override
079            public String getRestoreMessage(PortletRequest portletRequest, long classPK)
080                    throws PortalException, SystemException {
081    
082                    BookmarksFolder folder = getBookmarksFolder(classPK);
083    
084                    return BookmarksUtil.getAbsolutePath(
085                            portletRequest, folder.getParentFolderId());
086            }
087    
088            @Override
089            public ContainerModel getTrashContainer(long classPK)
090                    throws PortalException, SystemException {
091    
092                    BookmarksFolder folder = getBookmarksFolder(classPK);
093    
094                    return folder.getTrashContainer();
095            }
096    
097            @Override
098            public TrashRenderer getTrashRenderer(long classPK)
099                    throws PortalException, SystemException {
100    
101                    BookmarksFolder folder = getBookmarksFolder(classPK);
102    
103                    return new BookmarksFolderAssetRenderer(folder);
104            }
105    
106            @Override
107            public boolean isContainerModel() {
108                    return true;
109            }
110    
111            public boolean isInTrash(long classPK)
112                    throws PortalException, SystemException {
113    
114                    BookmarksFolder folder = getBookmarksFolder(classPK);
115    
116                    return folder.isInTrash();
117            }
118    
119            @Override
120            public boolean isInTrashContainer(long classPK)
121                    throws PortalException, SystemException {
122    
123                    BookmarksFolder folder = getBookmarksFolder(classPK);
124    
125                    return folder.isInTrashContainer();
126            }
127    
128            @Override
129            public boolean isRestorable(long classPK)
130                    throws PortalException, SystemException {
131    
132                    BookmarksFolder folder = getBookmarksFolder(classPK);
133    
134                    return !folder.isInTrashContainer();
135            }
136    
137            @Override
138            public void moveEntry(
139                            long userId, long classPK, long containerModelId,
140                            ServiceContext serviceContext)
141                    throws PortalException, SystemException {
142    
143                    BookmarksFolderLocalServiceUtil.moveFolder(classPK, containerModelId);
144            }
145    
146            @Override
147            public void moveTrashEntry(
148                            long userId, long classPK, long containerId,
149                            ServiceContext serviceContext)
150                    throws PortalException, SystemException {
151    
152                    BookmarksFolderLocalServiceUtil.moveFolderFromTrash(
153                            userId, classPK, containerId);
154            }
155    
156            public void restoreTrashEntry(long userId, long classPK)
157                    throws PortalException, SystemException {
158    
159                    BookmarksFolderLocalServiceUtil.restoreFolderFromTrash(userId, classPK);
160            }
161    
162            @Override
163            protected BookmarksFolder getBookmarksFolder(long classPK)
164                    throws PortalException, SystemException {
165    
166                    return BookmarksFolderLocalServiceUtil.getFolder(classPK);
167            }
168    
169            @Override
170            protected boolean hasPermission(
171                            PermissionChecker permissionChecker, long classPK, String actionId)
172                    throws PortalException, SystemException {
173    
174                    BookmarksFolder folder = getBookmarksFolder(classPK);
175    
176                    return BookmarksFolderPermission.contains(
177                            permissionChecker, folder, actionId);
178            }
179    
180    }