public void restoreFolderFromTrash(long userId, Folder folder)
      throws PortalException, SystemException {

    // Folder

    TrashEntry trashEntry =
        trashEntryLocalService.getEntry(DLFolderConstants.getClassName(), folder.getFolderId());

    DLFolder dlFolder =
        dlFolderLocalService.updateStatus(
            userId,
            folder.getFolderId(),
            WorkflowConstants.STATUS_APPROVED,
            new HashMap<String, Serializable>(),
            new ServiceContext());

    dlFolder.setName(DLAppUtil.stripTrashNamespace(dlFolder.getName()));

    dlFolderPersistence.update(dlFolder, false);

    // File rank

    dlFileRankLocalService.enableFileRanksByFolderId(folder.getFolderId());

    // Trash

    trashEntryLocalService.deleteEntry(trashEntry.getEntryId());
  }
예제 #2
0
  protected String getOriginalTitle(String title, String prefix) {
    if (!title.startsWith(prefix)) {
      return title;
    }

    title = title.substring(prefix.length());

    long trashEntryId = GetterUtil.getLong(title);

    if (trashEntryId <= 0) {
      return title;
    }

    try {
      TrashEntry trashEntry = TrashEntryLocalServiceUtil.fetchEntry(trashEntryId);

      if (trashEntry == null) {
        TrashVersion trashVersion = TrashVersionLocalServiceUtil.getTrashVersion(trashEntryId);

        title = trashVersion.getTypeSettingsProperty("title");
      } else {
        title = trashEntry.getTypeSettingsProperty("title");
      }
    } catch (Exception e) {
      if (_log.isDebugEnabled()) {
        _log.debug("No trash entry or trash version exists with ID " + trashEntryId);
      }
    }

    return title;
  }
  @Override
  public void checkDuplicateTrashEntry(TrashEntry trashEntry, long containerModelId, String newName)
      throws PortalException, SystemException {

    WikiPage page = WikiPageLocalServiceUtil.getPage(trashEntry.getClassPK());

    if (containerModelId == TrashEntryConstants.DEFAULT_CONTAINER_ID) {
      containerModelId = page.getNodeId();
    }

    String restoredTitle = page.getTitle();

    if (Validator.isNotNull(newName)) {
      restoredTitle = newName;
    }

    String originalTitle = TrashUtil.stripTrashNamespace(restoredTitle);

    WikiPageResource pageResource =
        WikiPageResourceLocalServiceUtil.fetchPageResource(containerModelId, originalTitle);

    if (pageResource != null) {
      DuplicateEntryException dee = new DuplicateEntryException();

      WikiPage duplicatePage = WikiPageLocalServiceUtil.getPage(pageResource.getResourcePrimKey());

      dee.setDuplicateEntryId(duplicatePage.getPageId());
      dee.setOldName(duplicatePage.getTitle());
      dee.setTrashEntryId(trashEntry.getEntryId());

      throw dee;
    }
  }
  /**
   * Deletes the trash entries with the matching group ID considering permissions.
   *
   * @param groupId the primary key of the group
   * @throws PortalException if a portal exception occurred
   * @throws SystemException if a system exception occurred
   */
  @Override
  @Transactional(noRollbackFor = {TrashPermissionException.class})
  public void deleteEntries(long groupId) throws PortalException, SystemException {

    boolean throwTrashPermissionException = false;

    List<TrashEntry> entries = trashEntryPersistence.findByGroupId(groupId);

    PermissionChecker permissionChecker = getPermissionChecker();

    for (TrashEntry entry : entries) {
      try {
        TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(entry.getClassName());

        if (!trashHandler.hasTrashPermission(
            permissionChecker, 0, entry.getClassPK(), ActionKeys.VIEW)) {

          continue;
        }

        deleteEntry(entry);
      } catch (TrashPermissionException tpe) {
        throwTrashPermissionException = true;
      } catch (Exception e) {
        _log.error(e, e);
      }
    }

    if (throwTrashPermissionException) {
      throw new TrashPermissionException(TrashPermissionException.EMPTY_TRASH);
    }
  }
  public void restoreFileShortcutFromTrash(long userId, DLFileShortcut dlFileShortcut)
      throws PortalException, SystemException {

    // File shortcut

    TrashEntry trashEntry =
        trashEntryLocalService.getEntry(
            DLFileShortcut.class.getName(), dlFileShortcut.getFileShortcutId());

    dlFileShortcutLocalService.updateStatus(
        userId, dlFileShortcut.getFileShortcutId(), trashEntry.getStatus(), new ServiceContext());

    // Social

    socialActivityCounterLocalService.enableActivityCounters(
        DLFileShortcut.class.getName(), dlFileShortcut.getFileShortcutId());

    socialActivityLocalService.addActivity(
        userId,
        dlFileShortcut.getGroupId(),
        DLFileShortcut.class.getName(),
        dlFileShortcut.getFileShortcutId(),
        SocialActivityConstants.TYPE_RESTORE_FROM_TRASH,
        StringPool.BLANK,
        0);

    // Trash

    trashEntryLocalService.deleteEntry(trashEntry.getEntryId());
  }
  public void restoreFileEntryFromTrash(long userId, FileEntry fileEntry)
      throws PortalException, SystemException {

    // File entry

    DLFileEntry dlFileEntry = (DLFileEntry) fileEntry.getModel();

    dlFileEntry.setTitle(DLAppUtil.stripTrashNamespace(dlFileEntry.getTitle()));

    dlFileEntryPersistence.update(dlFileEntry, false);

    FileVersion fileVersion = new LiferayFileVersion(dlFileEntry.getLatestFileVersion(true));

    TrashEntry trashEntry =
        trashEntryLocalService.getEntry(
            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());

    // File version

    Map<String, Serializable> workflowContext = new HashMap<String, Serializable>();

    List<TrashVersion> trashVersions = trashEntryLocalService.getVersions(trashEntry.getEntryId());

    workflowContext.put("trashVersions", (Serializable) trashVersions);

    dlFileEntryLocalService.updateStatus(
        userId,
        fileVersion.getFileVersionId(),
        trashEntry.getStatus(),
        workflowContext,
        new ServiceContext());

    // File shortcut

    dlFileShortcutLocalService.enableFileShortcuts(fileEntry.getFileEntryId());

    // File rank

    dlFileRankLocalService.enableFileRanks(fileEntry.getFileEntryId());

    // Social

    socialActivityCounterLocalService.enableActivityCounters(
        DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());

    socialActivityLocalService.addActivity(
        userId,
        fileEntry.getGroupId(),
        DLFileEntryConstants.getClassName(),
        fileEntry.getFileEntryId(),
        SocialActivityConstants.TYPE_RESTORE_FROM_TRASH,
        StringPool.BLANK,
        0);

    // Trash

    trashEntryLocalService.deleteEntry(trashEntry.getClassName(), trashEntry.getClassPK());
  }
예제 #7
0
  @Override
  public PortletURL getViewContentURL(HttpServletRequest request, String className, long classPK)
      throws PortalException, SystemException {

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

    if (!themeDisplay.isSignedIn()
        || !isTrashEnabled(themeDisplay.getScopeGroupId())
        || !PortletPermissionUtil.hasControlPanelAccessPermission(
            themeDisplay.getPermissionChecker(),
            themeDisplay.getScopeGroupId(),
            PortletKeys.TRASH)) {

      return null;
    }

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    if (trashHandler.isInTrashContainer(classPK)) {
      ContainerModel containerModel = trashHandler.getTrashContainer(classPK);

      className = containerModel.getModelClassName();
      classPK = containerModel.getContainerModelId();

      trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);
    }

    TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

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

    Layout layout = themeDisplay.getLayout();

    PortletURL portletURL =
        PortalUtil.getControlPanelPortletURL(
            request, PortletKeys.TRASH, layout.getLayoutId(), PortletRequest.RENDER_PHASE);

    portletURL.setParameter("struts_action", "/trash/view_content");
    portletURL.setParameter("redirect", themeDisplay.getURLCurrent());

    TrashEntry trashEntry = TrashEntryLocalServiceUtil.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("type", trashRenderer.getType());
    portletURL.setParameter("showActions", Boolean.FALSE.toString());
    portletURL.setParameter("showAssetMetadata", Boolean.TRUE.toString());
    portletURL.setParameter("showEditURL", Boolean.FALSE.toString());

    return portletURL;
  }
예제 #8
0
  public String getViewContentURL(String className, long classPK, ThemeDisplay themeDisplay)
      throws PortalException, SystemException {

    if (!themeDisplay.isSignedIn()
        || !isTrashEnabled(themeDisplay.getScopeGroupId())
        || !PortletPermissionUtil.hasControlPanelAccessPermission(
            themeDisplay.getPermissionChecker(),
            themeDisplay.getScopeGroupId(),
            PortletKeys.TRASH)) {

      return null;
    }

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    if (trashHandler.isInTrashContainer(classPK)) {
      ContainerModel containerModel = trashHandler.getTrashContainer(classPK);

      className = containerModel.getModelClassName();
      classPK = containerModel.getContainerModelId();

      trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);
    }

    TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

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

    String namespace = PortalUtil.getPortletNamespace(PortletKeys.TRASH);

    Map<String, String[]> params = new HashMap<String, String[]>();

    params.put(namespace + "struts_action", new String[] {"/trash/view_content"});
    params.put(namespace + "redirect", new String[] {themeDisplay.getURLCurrent()});

    TrashEntry trashEntry = TrashEntryLocalServiceUtil.getEntry(className, classPK);

    if (trashEntry.getRootEntry() != null) {
      params.put(namespace + "className", new String[] {className});
      params.put(namespace + "classPK", new String[] {String.valueOf(classPK)});
    } else {
      params.put(
          namespace + "trashEntryId", new String[] {String.valueOf(trashEntry.getEntryId())});
    }

    params.put(namespace + "type", new String[] {trashRenderer.getType()});
    params.put(namespace + "showActions", new String[] {Boolean.FALSE.toString()});
    params.put(namespace + "showAssetMetadata", new String[] {Boolean.TRUE.toString()});
    params.put(namespace + "showEditURL", new String[] {Boolean.FALSE.toString()});

    return PortalUtil.getControlPanelFullURL(
        themeDisplay.getScopeGroupId(), PortletKeys.TRASH, params);
  }
  /**
   * Returns a range of all the trash entries matching the group ID.
   *
   * @param groupId the primary key of the group
   * @param start the lower bound of the range of trash entries to return
   * @param end the upper bound of the range of trash entries to return (not inclusive)
   * @param obc the comparator to order the trash entries (optionally <code>null</code>)
   * @return the range of matching trash entries ordered by comparator <code>obc</code>
   * @throws PrincipalException if a system exception occurred
   * @throws SystemException if a system exception occurred
   */
  @Override
  public TrashEntryList getEntries(long groupId, int start, int end, OrderByComparator obc)
      throws PrincipalException, SystemException {

    TrashEntryList trashEntriesList = new TrashEntryList();

    int entriesCount = trashEntryPersistence.countByGroupId(groupId);

    boolean approximate = entriesCount > PropsValues.TRASH_SEARCH_LIMIT;

    trashEntriesList.setApproximate(approximate);

    List<TrashEntry> entries =
        trashEntryPersistence.findByGroupId(groupId, 0, end + PropsValues.TRASH_SEARCH_LIMIT, obc);

    List<TrashEntry> filteredEntries = new ArrayList<TrashEntry>();

    PermissionChecker permissionChecker = getPermissionChecker();

    for (TrashEntry entry : entries) {
      String className = entry.getClassName();
      long classPK = entry.getClassPK();

      try {
        TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

        if (trashHandler.hasTrashPermission(permissionChecker, 0, classPK, ActionKeys.VIEW)) {

          filteredEntries.add(entry);
        }
      } catch (Exception e) {
        _log.error(e, e);
      }
    }

    int filteredEntriesCount = filteredEntries.size();

    if ((end != QueryUtil.ALL_POS) && (start != QueryUtil.ALL_POS)) {
      if (end > filteredEntriesCount) {
        end = filteredEntriesCount;
      }

      if (start > filteredEntriesCount) {
        start = filteredEntriesCount;
      }

      filteredEntries = filteredEntries.subList(start, end);
    }

    trashEntriesList.setArray(TrashEntrySoap.toSoapModels(filteredEntries));
    trashEntriesList.setCount(filteredEntriesCount);

    return trashEntriesList;
  }
  protected void deleteEntry(TrashEntry entry) throws PortalException {
    PermissionChecker permissionChecker = getPermissionChecker();

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

    if (!trashHandler.hasTrashPermission(
        permissionChecker, 0, entry.getClassPK(), ActionKeys.DELETE)) {

      throw new TrashPermissionException(TrashPermissionException.DELETE);
    }

    trashHandler.deleteTrashEntry(entry.getClassPK());
  }
  @Override
  public TrashEntry restoreEntry(String className, long classPK, long overrideClassPK, String name)
      throws PortalException {

    TrashEntry trashEntry =
        trashEntryPersistence.fetchByC_C(classNameLocalService.getClassNameId(className), classPK);

    if (trashEntry != null) {
      return restoreEntry(trashEntry.getEntryId(), overrideClassPK, name);
    }

    return null;
  }
예제 #12
0
  @Override
  public int compare(Object obj1, Object obj2) {
    TrashEntry entry1 = (TrashEntry) obj1;
    TrashEntry entry2 = (TrashEntry) obj2;

    int value = DateUtil.compareTo(entry1.getCreateDate(), entry2.getCreateDate());

    if (_ascending) {
      return value;
    } else {
      return -value;
    }
  }
  public void restoreCategoryFromTrash(long userId, long categoryId)
      throws PortalException, SystemException {

    // Category

    TrashEntry trashEntry = trashEntryLocalService.getEntry(MBCategory.class.getName(), categoryId);

    updateStatus(userId, categoryId, WorkflowConstants.STATUS_APPROVED);

    // Trash

    trashEntryLocalService.deleteEntry(trashEntry.getEntryId());
  }
  /**
   * Deletes the trash entry with the entity class name and class primary key.
   *
   * <p>This method throws a {@link TrashPermissionException} with type {@link
   * TrashPermissionException#DELETE} if the user did not have permission to delete the trash entry.
   *
   * @param className the class name of the entity
   * @param classPK the primary key of the entity
   * @throws PortalException if a trash entry with the entity class name and primary key could not
   *     be found or if the user did not have permission to delete the entry
   */
  @Override
  public void deleteEntry(String className, long classPK) throws PortalException {

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

    if (entry == null) {
      entry = new TrashEntryImpl();

      entry.setClassName(className);
      entry.setClassPK(classPK);
    }

    deleteEntry(entry);
  }
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public Album moveAlbumToTrash(long userId, long albumId) throws PortalException {

    ServiceContext serviceContext = new ServiceContext();

    // Folder

    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();

    Album album = albumPersistence.findByPrimaryKey(albumId);

    int oldStatus = album.getStatus();

    album.setModifiedDate(serviceContext.getModifiedDate(now));
    album.setStatus(WorkflowConstants.STATUS_IN_TRASH);
    album.setStatusByUserId(user.getUserId());
    album.setStatusByUserName(user.getFullName());
    album.setStatusDate(serviceContext.getModifiedDate(now));

    albumPersistence.update(album);

    // Asset

    assetEntryLocalService.updateVisible(Album.class.getName(), album.getAlbumId(), false);

    // Trash

    TrashEntry trashEntry =
        trashEntryLocalService.addTrashEntry(
            userId,
            album.getGroupId(),
            Album.class.getName(),
            album.getAlbumId(),
            album.getUuid(),
            null,
            oldStatus,
            null,
            null);

    // Folders and entries

    List<Song> songs = songLocalService.getSongsByAlbumId(album.getAlbumId());

    moveDependentsToTrash(songs, trashEntry.getEntryId());

    return album;
  }
  @Override
  public void restoreThreadFromTrash(long userId, long threadId)
      throws PortalException, SystemException {

    MBThread thread = getThread(threadId);

    if (thread.getCategoryId() == MBCategoryConstants.DISCUSSION_CATEGORY_ID) {

      return;
    }

    TrashEntry trashEntry = trashEntryLocalService.getEntry(MBThread.class.getName(), threadId);

    updateStatus(userId, threadId, trashEntry.getStatus(), WorkflowConstants.STATUS_ANY);
  }
  @Override
  public int compare(Object obj1, Object obj2) {
    TrashEntry entry1 = (TrashEntry) obj1;
    TrashEntry entry2 = (TrashEntry) obj2;

    String name1 = StringUtil.toLowerCase(entry1.getUserName());
    String name2 = StringUtil.toLowerCase(entry2.getUserName());

    int value = name1.compareTo(name2);

    if (_ascending) {
      return value;
    } else {
      return -value;
    }
  }
  /**
   * 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);
  }
예제 #19
0
  @Override
  public void addTrashSessionMessages(
      ActionRequest actionRequest, List<TrashedModel> trashedModels, String cmd) {

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

    List<String> classNames = new ArrayList<String>();
    List<Long> restoreTrashEntryIds = new ArrayList<Long>();
    List<String> titles = new ArrayList<String>();

    for (int i = 0; i < trashedModels.size(); i++) {
      try {
        TrashedModel trashedModel = trashedModels.get(i);

        TrashEntry trashEntry = trashedModel.getTrashEntry();

        TrashHandler trashHandler = trashedModel.getTrashHandler();

        TrashRenderer trashRenderer =
            trashHandler.getTrashRenderer(trashedModel.getTrashEntryClassPK());

        classNames.add(trashRenderer.getClassName());
        restoreTrashEntryIds.add(trashEntry.getEntryId());
        titles.add(trashRenderer.getTitle(themeDisplay.getLocale()));
      } catch (Exception e) {
      }
    }

    Map<String, String[]> data = new HashMap<String, String[]>();

    data.put(Constants.CMD, new String[] {cmd});

    data.put("deleteEntryClassName", ArrayUtil.toStringArray(classNames.toArray()));
    data.put("deleteEntryTitle", ArrayUtil.toStringArray(titles.toArray()));
    data.put("restoreTrashEntryIds", ArrayUtil.toStringArray(restoreTrashEntryIds.toArray()));

    SessionMessages.add(
        actionRequest,
        PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_DELETE_SUCCESS_DATA,
        data);
  }
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public Album restoreAlbumFromTrash(long userId, long albumId) throws PortalException {

    ServiceContext serviceContext = new ServiceContext();

    // Folder

    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();

    Album album = albumPersistence.findByPrimaryKey(albumId);

    TrashEntry trashEntry = trashEntryLocalService.getEntry(Album.class.getName(), albumId);

    album.setModifiedDate(serviceContext.getModifiedDate(now));
    album.setStatus(trashEntry.getStatus());
    album.setStatusByUserId(user.getUserId());
    album.setStatusByUserName(user.getFullName());
    album.setStatusDate(serviceContext.getModifiedDate(now));

    albumPersistence.update(album);

    assetEntryLocalService.updateVisible(Album.class.getName(), album.getAlbumId(), true);

    // Songs

    List<Song> songs =
        songLocalService.getSongsByAlbumId(
            album.getGroupId(), album.getAlbumId(), WorkflowConstants.STATUS_IN_TRASH);

    restoreDependentsFromTrash(songs, trashEntry.getEntryId());

    // Trash

    trashEntryLocalService.deleteEntry(trashEntry.getEntryId());

    return album;
  }
  protected List<TrashEntry> filterEntries(List<TrashEntry> entries) throws PrincipalException {

    List<TrashEntry> filteredEntries = new ArrayList<>();

    PermissionChecker permissionChecker = getPermissionChecker();

    for (TrashEntry entry : entries) {
      String className = entry.getClassName();
      long classPK = entry.getClassPK();

      try {
        TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

        if (trashHandler.hasTrashPermission(permissionChecker, 0, classPK, ActionKeys.VIEW)) {

          filteredEntries.add(entry);
        }
      } catch (Exception e) {
        _log.error(e, e);
      }
    }

    return filteredEntries;
  }
  /**
   * 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);
    }
  }
예제 #23
0
  @Override
  public List<TrashEntry> getEntries(Hits hits) {
    List<TrashEntry> entries = new ArrayList<TrashEntry>();

    for (Document document : hits.getDocs()) {
      String entryClassName = GetterUtil.getString(document.get(Field.ENTRY_CLASS_NAME));
      long classPK = GetterUtil.getLong(document.get(Field.ENTRY_CLASS_PK));

      try {
        TrashEntry entry = TrashEntryLocalServiceUtil.fetchEntry(entryClassName, classPK);

        if (entry == null) {
          String userName = GetterUtil.getString(document.get(Field.REMOVED_BY_USER_NAME));

          Date removedDate = document.getDate(Field.REMOVED_DATE);

          entry = new TrashEntryImpl();

          entry.setClassName(entryClassName);
          entry.setClassPK(classPK);

          entry.setUserName(userName);
          entry.setCreateDate(removedDate);

          String rootEntryClassName =
              GetterUtil.getString(document.get(Field.ROOT_ENTRY_CLASS_NAME));
          long rootEntryClassPK = GetterUtil.getLong(document.get(Field.ROOT_ENTRY_CLASS_PK));

          TrashEntry rootTrashEntry =
              TrashEntryLocalServiceUtil.fetchEntry(rootEntryClassName, rootEntryClassPK);

          if (rootTrashEntry != null) {
            entry.setRootEntry(rootTrashEntry);
          }
        }

        entries.add(entry);
      } catch (Exception e) {
        if (_log.isWarnEnabled()) {
          _log.warn(
              "Unable to find trash entry for " + entryClassName + " with primary key " + classPK);
        }
      }
    }

    return entries;
  }
  /**
   * Restores the trash entry to its original location. In order to handle a duplicate trash entry
   * already existing at the original location, either pass in the primary key of the existing trash
   * entry's entity to overwrite or pass in a new name to give to the trash entry being restored.
   *
   * <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#RESTORE} - if the user did not have permission to restore
   *       the trash entry
   *   <li>{@link TrashPermissionException#RESTORE_OVERWRITE} - if the user did not have permission
   *       to delete the existing trash entry
   *   <li>{@link TrashPermissionException#RESTORE_RENAME} - if the user did not have permission to
   *       rename the trash entry
   * </ul>
   *
   * @param entryId the primary key of the trash entry to restore
   * @param overrideClassPK the primary key of the entity to overwrite (optionally <code>0</code>)
   * @param name a new name to give to the trash entry being restored (optionally <code>null</code>)
   * @return the restored trash entry
   * @throws PortalException if a matching trash entry could not be found, if the user did not have
   *     permission to overwrite an existing trash entry, to rename the trash entry being restored,
   *     or to restore the trash entry in general
   */
  @Override
  public TrashEntry restoreEntry(long entryId, long overrideClassPK, String name)
      throws PortalException {

    PermissionChecker permissionChecker = getPermissionChecker();

    TrashEntry entry = trashEntryPersistence.findByPrimaryKey(entryId);

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

    if (!trashHandler.hasTrashPermission(
        permissionChecker, 0, entry.getClassPK(), TrashActionKeys.RESTORE)) {

      throw new TrashPermissionException(TrashPermissionException.RESTORE);
    }

    if (overrideClassPK > 0) {
      if (!trashHandler.hasTrashPermission(
          permissionChecker, 0, overrideClassPK, TrashActionKeys.OVERWRITE)) {

        throw new TrashPermissionException(TrashPermissionException.RESTORE_OVERWRITE);
      }

      trashHandler.deleteTrashEntry(overrideClassPK);

      trashHandler.checkRestorableEntry(entry, TrashEntryConstants.DEFAULT_CONTAINER_ID, null);
    } else if (name != null) {
      if (!trashHandler.hasTrashPermission(
          permissionChecker, 0, entry.getClassPK(), TrashActionKeys.RENAME)) {

        throw new TrashPermissionException(TrashPermissionException.RESTORE_RENAME);
      }

      trashHandler.checkRestorableEntry(entry, TrashEntryConstants.DEFAULT_CONTAINER_ID, name);

      trashHandler.updateTitle(entry.getClassPK(), name);
    }

    trashHandler.restoreTrashEntry(getUserId(), entry.getClassPK());

    return entry;
  }