List of usage examples for com.liferay.portal.kernel.trash TrashHandler getTrashEntry
public default TrashEntry getTrashEntry(long classPK) throws PortalException
From source file:com.liferay.trash.internal.TrashHelperImpl.java
License:Open Source License
@Override public PortletURL getViewContentURL(HttpServletRequest request, String className, long classPK) throws PortalException { TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className); if (trashHandler.isInTrashContainer(classPK)) { com.liferay.trash.kernel.model.TrashEntry trashEntry = trashHandler.getTrashEntry(classPK); className = trashEntry.getClassName(); classPK = trashEntry.getClassPK(); trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className); }/*from w ww. j ava 2 s .com*/ TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK); if (trashRenderer == null) { return null; } ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); PortletURL portletURL = PortletProviderUtil.getPortletURL(request, TrashEntry.class.getName(), PortletProvider.Action.VIEW); portletURL.setParameter("mvcPath", "/view_content.jsp"); portletURL.setParameter("redirect", themeDisplay.getURLCurrent()); TrashEntry trashEntry = _trashEntryLocalService.getEntry(className, classPK); if (trashEntry.getRootEntry() != null) { portletURL.setParameter("className", className); portletURL.setParameter("classPK", String.valueOf(classPK)); } else { portletURL.setParameter("trashEntryId", String.valueOf(trashEntry.getEntryId())); } portletURL.setParameter("showAssetMetadata", Boolean.TRUE.toString()); return portletURL; }
From source file:com.liferay.trash.service.impl.TrashEntryServiceImpl.java
License:Open Source License
/** * Moves the trash entry with the entity class name and primary key, * restoring it to a new location identified by the destination container * model ID.//w w w . j a v a2 s . co m * * <p> * This method throws a {@link TrashPermissionException} if the user did not * have the permission to perform one of the necessary operations. The * exception is created with a type specific to the operation: * </p> * * <ul> * <li> * {@link TrashPermissionException#MOVE} - if the user did not have * permission to move the trash entry to the new * destination * </li> * <li> * {@link TrashPermissionException#RESTORE} - if the user did not have * permission to restore the trash entry * </li> * </ul> * * @param className the class name of the entity * @param classPK the primary key of the entity * @param destinationContainerModelId the primary key of the new location * @param serviceContext the service context to be applied (optionally * <code>null</code>) */ @Override public void moveEntry(String className, long classPK, long destinationContainerModelId, ServiceContext serviceContext) throws PortalException { PermissionChecker permissionChecker = getPermissionChecker(); long scopeGroupId = 0; if (serviceContext != null) { scopeGroupId = serviceContext.getScopeGroupId(); } TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className); destinationContainerModelId = trashHandler.getDestinationContainerModelId(classPK, destinationContainerModelId); if (!trashHandler.hasTrashPermission(permissionChecker, scopeGroupId, destinationContainerModelId, TrashActionKeys.MOVE)) { throw new TrashPermissionException(TrashPermissionException.MOVE); } if (trashHandler.isInTrash(classPK) && !trashHandler.hasTrashPermission(permissionChecker, 0, classPK, TrashActionKeys.RESTORE)) { throw new TrashPermissionException(TrashPermissionException.RESTORE); } TrashEntry trashEntry = ModelAdapterUtil.adapt(TrashEntry.class, trashHandler.getTrashEntry(classPK)); if (trashEntry.isTrashEntry(className, classPK)) { trashHandler.checkRestorableEntry( ModelAdapterUtil.adapt(com.liferay.trash.kernel.model.TrashEntry.class, trashEntry), destinationContainerModelId, StringPool.BLANK); } else { trashHandler.checkRestorableEntry(classPK, destinationContainerModelId, StringPool.BLANK); } trashHandler.moveTrashEntry(getUserId(), classPK, destinationContainerModelId, serviceContext); }