001
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.model.ContainerModel;
020 import com.liferay.portal.security.permission.PermissionChecker;
021 import com.liferay.portal.service.ServiceContext;
022 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
023 import com.liferay.portlet.bookmarks.model.BookmarksFolder;
024 import com.liferay.portlet.bookmarks.service.BookmarksEntryLocalServiceUtil;
025 import com.liferay.portlet.bookmarks.service.BookmarksEntryServiceUtil;
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
036 public class BookmarksEntryTrashHandler extends BookmarksBaseTrashHandler {
037
038 public static final String CLASS_NAME = BookmarksEntry.class.getName();
039
040 public void deleteTrashEntries(long[] classPKs, boolean checkPermission)
041 throws PortalException, SystemException {
042
043 for (long classPK : classPKs) {
044 if (checkPermission) {
045 BookmarksEntryServiceUtil.deleteEntry(classPK);
046 }
047 else {
048 BookmarksEntryLocalServiceUtil.deleteEntry(classPK);
049 }
050 }
051 }
052
053 public String getClassName() {
054 return CLASS_NAME;
055 }
056
057 @Override
058 public ContainerModel getParentContainerModel(long classPK)
059 throws PortalException, SystemException {
060
061 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
062
063 long parentFolderId = entry.getFolderId();
064
065 if (parentFolderId <= 0) {
066 return null;
067 }
068
069 return getContainerModel(parentFolderId);
070 }
071
072 @Override
073 public String getRestoreLink(PortletRequest portletRequest, long classPK)
074 throws PortalException, SystemException {
075
076 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
077
078 return BookmarksUtil.getControlPanelLink(
079 portletRequest, entry.getFolderId());
080 }
081
082 @Override
083 public String getRestoreMessage(PortletRequest portletRequest, long classPK)
084 throws PortalException, SystemException {
085
086 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
087
088 return BookmarksUtil.getAbsolutePath(
089 portletRequest, entry.getFolderId());
090 }
091
092 @Override
093 public boolean hasPermission(
094 PermissionChecker permissionChecker, long classPK, String actionId)
095 throws PortalException, SystemException {
096
097 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
098
099 return BookmarksEntryPermission.contains(
100 permissionChecker, entry, actionId);
101 }
102
103 public boolean isInTrash(long classPK)
104 throws PortalException, SystemException {
105
106 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
107
108 return entry.isInTrash();
109 }
110
111 @Override
112 public boolean isRestorable(long classPK)
113 throws PortalException, SystemException {
114
115 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
116
117 return !entry.isInTrashContainer();
118 }
119
120 @Override
121 public void moveEntry(
122 long classPK, long containerModelId, ServiceContext serviceContext)
123 throws PortalException, SystemException {
124
125 BookmarksEntryServiceUtil.moveEntry(classPK, containerModelId);
126 }
127
128 @Override
129 public void moveTrashEntry(
130 long classPK, long containerId, ServiceContext serviceContext)
131 throws PortalException, SystemException {
132
133 BookmarksEntryServiceUtil.moveEntryFromTrash(classPK, containerId);
134 }
135
136 public void restoreTrashEntries(long[] classPKs)
137 throws PortalException, SystemException {
138
139 for (long classPK : classPKs) {
140 BookmarksEntryServiceUtil.restoreEntryFromTrash(classPK);
141 }
142 }
143
144 @Override
145 protected BookmarksFolder getBookmarksFolder(long classPK)
146 throws PortalException, SystemException {
147
148 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
149
150 return entry.getFolder();
151 }
152
153 }