Example #1
0
  protected String getOriginalTitle(String title, String paramName, String prefix) {

    if (!isValidTrashTitle(title, 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(paramName);
      } else {
        title = trashEntry.getTypeSettingsProperty(paramName);
      }
    } catch (Exception e) {
      if (_log.isDebugEnabled()) {
        _log.debug("No trash entry or trash version exists with ID " + trashEntryId);
      }
    }

    return title;
  }
Example #2
0
  @Override
  public PortletURL getViewContentURL(HttpServletRequest request, long trashEntryId)
      throws PortalException {

    TrashEntry trashEntry = TrashEntryLocalServiceUtil.fetchEntry(trashEntryId);

    return getViewContentURL(request, trashEntry.getClassName(), trashEntry.getClassPK());
  }
  @Override
  public MBThread moveThreadToTrash(long userId, MBThread thread) throws PortalException {

    // Thread

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

      return thread;
    }

    int oldStatus = thread.getStatus();

    if (oldStatus == WorkflowConstants.STATUS_PENDING) {
      thread.setStatus(WorkflowConstants.STATUS_DRAFT);

      mbThreadPersistence.update(thread);
    }

    thread = updateStatus(userId, thread.getThreadId(), WorkflowConstants.STATUS_IN_TRASH);

    // Trash

    TrashEntry trashEntry =
        trashEntryLocalService.addTrashEntry(
            userId,
            thread.getGroupId(),
            MBThread.class.getName(),
            thread.getThreadId(),
            thread.getUuid(),
            null,
            oldStatus,
            null,
            null);

    // Messages

    moveDependentsToTrash(thread.getGroupId(), thread.getThreadId(), trashEntry.getEntryId());

    // Social

    MBMessage message = mbMessageLocalService.getMBMessage(thread.getRootMessageId());

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("rootMessageId", thread.getRootMessageId());
    extraDataJSONObject.put("title", message.getSubject());

    SocialActivityManagerUtil.addActivity(
        userId,
        thread,
        SocialActivityConstants.TYPE_MOVE_TO_TRASH,
        extraDataJSONObject.toString(),
        0);

    return thread;
  }
Example #4
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<>();
    List<Long> restoreTrashEntryIds = new ArrayList<>();
    List<String> titles = new ArrayList<>();

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

    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);
  }
  @Override
  public void restoreThreadFromTrash(long userId, long threadId) throws PortalException {

    // Thread

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

    // Messages

    restoreDependentsFromTrash(thread.getGroupId(), threadId);

    // Trash

    trashEntryLocalService.deleteEntry(trashEntry.getEntryId());

    // Social

    MBMessage message = mbMessageLocalService.getMBMessage(thread.getRootMessageId());

    JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

    extraDataJSONObject.put("rootMessageId", thread.getRootMessageId());
    extraDataJSONObject.put("title", message.getSubject());

    SocialActivityManagerUtil.addActivity(
        userId,
        thread,
        SocialActivityConstants.TYPE_RESTORE_FROM_TRASH,
        extraDataJSONObject.toString(),
        0);
  }
Example #6
0
  @Override
  public PortletURL getViewContentURL(HttpServletRequest request, String className, long classPK)
      throws PortalException {

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

    String portletId =
        PortletProviderUtil.getPortletId(TrashEntry.class.getName(), PortletProvider.Action.VIEW);

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

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

    PortletURL portletURL =
        PortalUtil.getControlPanelPortletURL(request, portletId, PortletRequest.RENDER_PHASE);

    portletURL.setParameter("mvcPath", "/view_content.jsp");
    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("showAssetMetadata", Boolean.TRUE.toString());

    return portletURL;
  }
Example #7
0
  @Override
  public List<TrashEntry> getEntries(Hits hits) {
    List<TrashEntry> entries = new ArrayList<>();

    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.setUserName(userName);
          entry.setCreateDate(removedDate);

          TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(entryClassName);

          TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

          entry.setClassName(trashRenderer.getClassName());
          entry.setClassPK(trashRenderer.getClassPK());

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