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.kernel.trash.TrashActionKeys;
020 import com.liferay.portal.model.ContainerModel;
021 import com.liferay.portal.security.permission.ActionKeys;
022 import com.liferay.portal.security.permission.PermissionChecker;
023 import com.liferay.portal.service.ServiceContext;
024 import com.liferay.portlet.bookmarks.model.BookmarksEntry;
025 import com.liferay.portlet.bookmarks.service.BookmarksEntryLocalServiceUtil;
026 import com.liferay.portlet.bookmarks.service.BookmarksFolderLocalServiceUtil;
027 import com.liferay.portlet.bookmarks.service.permission.BookmarksEntryPermission;
028 import com.liferay.portlet.bookmarks.service.permission.BookmarksFolderPermission;
029 import com.liferay.portlet.bookmarks.util.BookmarksUtil;
030
031 import javax.portlet.PortletRequest;
032
033
039 public class BookmarksEntryTrashHandler extends BookmarksBaseTrashHandler {
040
041 @Override
042 public void deleteTrashEntry(long classPK)
043 throws PortalException, SystemException {
044
045 BookmarksEntryLocalServiceUtil.deleteEntry(classPK);
046 }
047
048 @Override
049 public String getClassName() {
050 return BookmarksEntry.class.getName();
051 }
052
053 @Override
054 public ContainerModel getParentContainerModel(long classPK)
055 throws PortalException, SystemException {
056
057 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
058
059 long parentFolderId = entry.getFolderId();
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 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
073
074 return BookmarksUtil.getControlPanelLink(
075 portletRequest, entry.getFolderId());
076 }
077
078 @Override
079 public String getRestoreMessage(PortletRequest portletRequest, long classPK)
080 throws PortalException, SystemException {
081
082 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
083
084 return BookmarksUtil.getAbsolutePath(
085 portletRequest, entry.getFolderId());
086 }
087
088 @Override
089 public ContainerModel getTrashContainer(long classPK)
090 throws PortalException, SystemException {
091
092 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
093
094 return entry.getTrashContainer();
095 }
096
097 @Override
098 public boolean hasTrashPermission(
099 PermissionChecker permissionChecker, long groupId, long classPK,
100 String trashActionId)
101 throws PortalException, SystemException {
102
103 if (trashActionId.equals(TrashActionKeys.MOVE)) {
104 return BookmarksFolderPermission.contains(
105 permissionChecker, groupId, classPK, ActionKeys.ADD_ENTRY);
106 }
107
108 return super.hasTrashPermission(
109 permissionChecker, groupId, classPK, trashActionId);
110 }
111
112 @Override
113 public boolean isInTrash(long classPK)
114 throws PortalException, SystemException {
115
116 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
117
118 return entry.isInTrash();
119 }
120
121 @Override
122 public boolean isInTrashContainer(long classPK)
123 throws PortalException, SystemException {
124
125 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
126
127 return entry.isInTrashContainer();
128 }
129
130 @Override
131 public boolean isRestorable(long classPK)
132 throws PortalException, SystemException {
133
134 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
135
136 if ((entry.getFolderId() > 0) &&
137 (BookmarksFolderLocalServiceUtil.fetchBookmarksFolder(
138 entry.getFolderId()) == null)) {
139
140 return false;
141 }
142
143 return !entry.isInTrashContainer();
144 }
145
146 @Override
147 public void moveEntry(
148 long userId, long classPK, long containerModelId,
149 ServiceContext serviceContext)
150 throws PortalException, SystemException {
151
152 BookmarksEntryLocalServiceUtil.moveEntry(classPK, containerModelId);
153 }
154
155 @Override
156 public void moveTrashEntry(
157 long userId, long classPK, long containerId,
158 ServiceContext serviceContext)
159 throws PortalException, SystemException {
160
161 BookmarksEntryLocalServiceUtil.moveEntryFromTrash(
162 userId, classPK, containerId);
163 }
164
165 @Override
166 public void restoreTrashEntry(long userId, long classPK)
167 throws PortalException, SystemException {
168
169 BookmarksEntryLocalServiceUtil.restoreEntryFromTrash(userId, classPK);
170 }
171
172 @Override
173 protected long getGroupId(long classPK)
174 throws PortalException, SystemException {
175
176 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
177
178 return entry.getGroupId();
179 }
180
181 @Override
182 protected boolean hasPermission(
183 PermissionChecker permissionChecker, long classPK, String actionId)
184 throws PortalException, SystemException {
185
186 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
187
188 return BookmarksEntryPermission.contains(
189 permissionChecker, entry, actionId);
190 }
191
192 }