Exemple #1
0
  protected void addBreadcrumbEntries(
      HttpServletRequest request,
      String className,
      long classPK,
      String paramName,
      PortletURL containerModelURL)
      throws PortalException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    List<ContainerModel> containerModels = trashHandler.getParentContainerModels(classPK);

    Collections.reverse(containerModels);

    containerModelURL.setParameter("struts_action", "/trash/view");

    PortalUtil.addPortletBreadcrumbEntry(
        request,
        LanguageUtil.get(themeDisplay.getLocale(), "recycle-bin"),
        containerModelURL.toString());

    for (ContainerModel containerModel : containerModels) {
      TrashHandler containerModelTrashHandler =
          TrashHandlerRegistryUtil.getTrashHandler(containerModel.getModelClassName());

      if (!containerModelTrashHandler.isInTrash(containerModel.getContainerModelId())) {

        continue;
      }

      containerModelURL.setParameter("struts_action", "/trash/view_content");

      containerModelURL.setParameter(
          paramName, String.valueOf(containerModel.getContainerModelId()));

      String name = containerModel.getContainerModelName();

      if (containerModelTrashHandler.isInTrash(containerModel.getContainerModelId())) {

        name = TrashUtil.getOriginalTitle(name);
      }

      PortalUtil.addPortletBreadcrumbEntry(request, name, containerModelURL.toString());
    }

    TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

    PortalUtil.addPortletBreadcrumbEntry(
        request, trashRenderer.getTitle(themeDisplay.getLocale()), null);
  }
Exemple #2
0
  protected String getLink(SocialActivity activity, ServiceContext serviceContext)
      throws Exception {

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(activity.getClassName());

    long classPK = activity.getClassPK();

    if ((trashHandler != null)
        && (trashHandler.isInTrash(classPK) || trashHandler.isInTrashContainer(classPK))) {

      PortletURL portletURL =
          TrashUtil.getViewContentURL(
              serviceContext.getRequest(), activity.getClassName(), classPK);

      if (portletURL == null) {
        return null;
      }

      return portletURL.toString();
    }

    String path = getPath(activity, serviceContext);

    if (Validator.isNull(path)) {
      return null;
    }

    if (!path.startsWith(StringPool.SLASH)) {
      return path;
    }

    return serviceContext.getPortalURL() + serviceContext.getPathMain() + path;
  }
  protected void addBreadcrumbEntries(
      HttpServletRequest request,
      LiferayPortletResponse liferayPortletResponse,
      String className,
      long classPK,
      String paramName,
      PortletURL containerModelURL,
      boolean checkInTrashContainers)
      throws PortalException, PortletException {

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    PortletURL portletURL = PortletURLUtil.clone(containerModelURL, liferayPortletResponse);

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    List<ContainerModel> containerModels = trashHandler.getParentContainerModels(classPK);

    Collections.reverse(containerModels);

    for (ContainerModel containerModel : containerModels) {
      TrashHandler containerModelTrashHandler =
          TrashHandlerRegistryUtil.getTrashHandler(containerModel.getModelClassName());

      if (checkInTrashContainers
          && !containerModelTrashHandler.isInTrash(containerModel.getContainerModelId())) {

        continue;
      }

      portletURL.setParameter(paramName, String.valueOf(containerModel.getContainerModelId()));

      String name = containerModel.getContainerModelName();

      if (containerModelTrashHandler.isInTrash(containerModel.getContainerModelId())) {

        name = TrashUtil.getOriginalTitle(name);
      }

      PortalUtil.addPortletBreadcrumbEntry(request, name, portletURL.toString());
    }

    TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

    PortalUtil.addPortletBreadcrumbEntry(
        request, trashRenderer.getTitle(themeDisplay.getLocale()), null);
  }
Exemple #4
0
  @Override
  public boolean isInTrash(String className, long classPK) throws PortalException {

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    if (trashHandler == null) {
      return false;
    }

    return trashHandler.isInTrash(classPK);
  }
  /**
   * 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.
   *
   * <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:
   *
   * <ul>
   *   <li>{@link TrashPermissionException#MOVE} - if the user did not have permission to move the
   *       trash entry to the new destination
   *   <li>{@link TrashPermissionException#RESTORE} - if the user did not have permission to restore
   *       the trash entry
   * </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>)
   * @throws PortalException if a matching trash entry could not be found, if the user did not have
   *     permission to move the trash entry to the new location, if the user did not have permission
   *     to restore the trash entry, if a duplicate trash entry exists at the new location, or if a
   *     portal exception occurred
   * @throws SystemException if a system exception occurred
   */
  @Override
  public void moveEntry(
      String className,
      long classPK,
      long destinationContainerModelId,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    PermissionChecker permissionChecker = getPermissionChecker();

    TrashEntry entry = trashEntryLocalService.getEntry(className, classPK);

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    if (!trashHandler.hasTrashPermission(
        permissionChecker, entry.getGroupId(), destinationContainerModelId, TrashActionKeys.MOVE)) {

      throw new TrashPermissionException(TrashPermissionException.MOVE);
    }

    if (trashHandler.isInTrash(classPK)
        && !trashHandler.hasTrashPermission(
            permissionChecker, 0, classPK, TrashActionKeys.RESTORE)) {

      throw new TrashPermissionException(TrashPermissionException.RESTORE);
    }

    trashHandler.checkDuplicateTrashEntry(entry, destinationContainerModelId, StringPool.BLANK);

    if (trashHandler.isInTrash(classPK)) {
      trashHandler.moveTrashEntry(
          getUserId(), classPK, destinationContainerModelId, serviceContext);
    } else {
      trashHandler.moveEntry(getUserId(), classPK, destinationContainerModelId, serviceContext);
    }
  }
  public boolean isInTrash(String className, long classPK) throws PortalException, SystemException {

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    if (trashHandler == null) {
      return false;
    }

    if (trashHandler.isInTrash(classPK) || trashHandler.isInTrashContainer(classPK)) {

      return true;
    }

    return false;
  }
  /**
   * 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.
   *
   * <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:
   *
   * <ul>
   *   <li>{@link TrashPermissionException#MOVE} - if the user did not have permission to move the
   *       trash entry to the new destination
   *   <li>{@link TrashPermissionException#RESTORE} - if the user did not have permission to restore
   *       the trash entry
   * </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>)
   * @throws PortalException if a matching trash entry could not be found, if the user did not have
   *     permission to move the trash entry to the new location, if the user did not have permission
   *     to restore the trash entry, if a duplicate trash entry exists at the new location, or if a
   *     portal exception occurred
   */
  @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 = trashHandler.getTrashEntry(classPK);

    if (trashEntry.isTrashEntry(className, classPK)) {
      trashHandler.checkRestorableEntry(trashEntry, destinationContainerModelId, StringPool.BLANK);
    } else {
      trashHandler.checkRestorableEntry(classPK, destinationContainerModelId, StringPool.BLANK);
    }

    trashHandler.moveTrashEntry(getUserId(), classPK, destinationContainerModelId, serviceContext);
  }