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());
  }
  @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;
    }
  }
  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());
  }
예제 #5
0
  @Override
  public PortletURL getViewContentURL(HttpServletRequest request, String className, long classPK)
      throws PortalException {

    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)) {
      TrashEntry trashEntry = trashHandler.getTrashEntry(classPK);

      className = trashEntry.getClassName();
      classPK = trashEntry.getClassPK();

      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;
  }
예제 #6
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);
  }
  @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;
  }
  @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;
  }
  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());
  }
  @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;
  }
예제 #11
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);
  }
  /**
   * 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
   */
  @Override
  @Transactional(noRollbackFor = {TrashPermissionException.class})
  public void deleteEntries(long groupId) throws PortalException {
    boolean throwTrashPermissionException = false;

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

    PermissionChecker permissionChecker = getPermissionChecker();

    for (TrashEntry entry : entries) {
      entry = trashEntryPersistence.fetchByPrimaryKey(entry.getEntryId());

      if (entry == null) {
        continue;
      }

      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);
    }
  }