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 getRestoreContainerModelLink(
070 PortletRequest portletRequest, long classPK)
071 throws PortalException, SystemException {
072
073 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
074
075 return BookmarksUtil.getControlPanelLink(
076 portletRequest, entry.getFolderId());
077 }
078
079 @Override
080 public String getRestoreMessage(PortletRequest portletRequest, long classPK)
081 throws PortalException, SystemException {
082
083 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
084
085 return BookmarksUtil.getAbsolutePath(
086 portletRequest, entry.getFolderId());
087 }
088
089 @Override
090 public ContainerModel getTrashContainer(long classPK)
091 throws PortalException, SystemException {
092
093 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
094
095 return entry.getTrashContainer();
096 }
097
098 @Override
099 public boolean hasTrashPermission(
100 PermissionChecker permissionChecker, long groupId, long classPK,
101 String trashActionId)
102 throws PortalException, SystemException {
103
104 if (trashActionId.equals(TrashActionKeys.MOVE)) {
105 return BookmarksFolderPermission.contains(
106 permissionChecker, groupId, classPK, ActionKeys.ADD_ENTRY);
107 }
108
109 return super.hasTrashPermission(
110 permissionChecker, groupId, classPK, trashActionId);
111 }
112
113 @Override
114 public boolean isInTrash(long classPK)
115 throws PortalException, SystemException {
116
117 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
118
119 return entry.isInTrash();
120 }
121
122 @Override
123 public boolean isInTrashContainer(long classPK)
124 throws PortalException, SystemException {
125
126 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
127
128 return entry.isInTrashContainer();
129 }
130
131 @Override
132 public boolean isRestorable(long classPK)
133 throws PortalException, SystemException {
134
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, SystemException {
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, SystemException {
161
162 BookmarksEntryLocalServiceUtil.moveEntryFromTrash(
163 userId, classPK, containerId);
164 }
165
166 @Override
167 public void restoreTrashEntry(long userId, long classPK)
168 throws PortalException, SystemException {
169
170 BookmarksEntryLocalServiceUtil.restoreEntryFromTrash(userId, classPK);
171 }
172
173 @Override
174 protected long getGroupId(long classPK)
175 throws PortalException, SystemException {
176
177 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
178
179 return entry.getGroupId();
180 }
181
182 @Override
183 protected boolean hasPermission(
184 PermissionChecker permissionChecker, long classPK, String actionId)
185 throws PortalException, SystemException {
186
187 BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(classPK);
188
189 return BookmarksEntryPermission.contains(
190 permissionChecker, entry, actionId);
191 }
192
193 }