@Override
  public TrashEntry getTrashEntry() throws PortalException {
    if (!isInTrash()) {
      return null;
    }

    TrashEntry trashEntry =
        TrashEntryLocalServiceUtil.fetchEntry(getModelClassName(), getTrashEntryClassPK());

    if (trashEntry != null) {
      return trashEntry;
    }

    TrashHandler trashHandler = getTrashHandler();

    if (!Validator.isNull(trashHandler.getContainerModelClassName(getPrimaryKey()))) {
      ContainerModel containerModel = null;

      try {
        containerModel = trashHandler.getParentContainerModel(this);
      } catch (NoSuchModelException nsme) {
        return null;
      }

      while (containerModel != null) {
        if (containerModel instanceof TrashedModel) {
          TrashedModel trashedModel = (TrashedModel) containerModel;

          return trashedModel.getTrashEntry();
        }

        trashHandler =
            TrashHandlerRegistryUtil.getTrashHandler(
                trashHandler.getContainerModelClassName(containerModel.getContainerModelId()));

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

        containerModel = trashHandler.getContainerModel(containerModel.getParentContainerModelId());
      }
    }

    return null;
  }
Exemplo n.º 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);
  }