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