@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;
  }
Beispiel #2
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);
  }