protected void addBreadcrumbEntries(
      HttpServletRequest request,
      String className,
      long classPK,
      String paramName,
      PortletURL containerModelURL)
      throws PortalException, SystemException {

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

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    List<ContainerModel> containerModels = trashHandler.getParentContainerModels(classPK);

    Collections.reverse(containerModels);

    for (ContainerModel containerModel : containerModels) {
      containerModelURL.setParameter(
          paramName, String.valueOf(containerModel.getContainerModelId()));

      PortalUtil.addPortletBreadcrumbEntry(
          request, containerModel.getContainerModelName(), containerModelURL.toString());
    }

    TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

    PortalUtil.addPortletBreadcrumbEntry(
        request, trashRenderer.getTitle(themeDisplay.getLocale()), null);
  }
Exemple #2
0
  @Override
  public String getNewName(
      ThemeDisplay themeDisplay, String className, long classPK, String oldName)
      throws PortalException {

    TrashRenderer trashRenderer = null;

    if (Validator.isNotNull(className) && (classPK > 0)) {
      TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

      trashRenderer = trashHandler.getTrashRenderer(classPK);
    }

    Format dateFormatDateTime =
        FastDateFormatFactoryUtil.getDateTime(themeDisplay.getLocale(), themeDisplay.getTimeZone());

    StringBundler sb = new StringBundler(3);

    sb.append(StringPool.OPEN_PARENTHESIS);
    sb.append(
        StringUtil.replace(dateFormatDateTime.format(new Date()), CharPool.SLASH, CharPool.PERIOD));
    sb.append(StringPool.CLOSE_PARENTHESIS);

    if (trashRenderer != null) {
      return trashRenderer.getNewName(oldName, sb.toString());
    } else {
      return getNewName(oldName, sb.toString());
    }
  }
Exemple #3
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;
  }
  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);
  }
Exemple #5
0
  protected void addBreadcrumbEntries(
      HttpServletRequest request,
      String className,
      long classPK,
      String paramName,
      PortletURL containerModelURL)
      throws PortalException {

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

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    List<ContainerModel> containerModels = trashHandler.getParentContainerModels(classPK);

    Collections.reverse(containerModels);

    containerModelURL.setParameter("struts_action", "/trash/view");

    PortalUtil.addPortletBreadcrumbEntry(
        request,
        LanguageUtil.get(themeDisplay.getLocale(), "recycle-bin"),
        containerModelURL.toString());

    for (ContainerModel containerModel : containerModels) {
      TrashHandler containerModelTrashHandler =
          TrashHandlerRegistryUtil.getTrashHandler(containerModel.getModelClassName());

      if (!containerModelTrashHandler.isInTrash(containerModel.getContainerModelId())) {

        continue;
      }

      containerModelURL.setParameter("struts_action", "/trash/view_content");

      containerModelURL.setParameter(
          paramName, String.valueOf(containerModel.getContainerModelId()));

      String name = containerModel.getContainerModelName();

      if (containerModelTrashHandler.isInTrash(containerModel.getContainerModelId())) {

        name = TrashUtil.getOriginalTitle(name);
      }

      PortalUtil.addPortletBreadcrumbEntry(request, name, containerModelURL.toString());
    }

    TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

    PortalUtil.addPortletBreadcrumbEntry(
        request, trashRenderer.getTitle(themeDisplay.getLocale()), null);
  }
  @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;
  }
  protected void addBreadcrumbEntries(
      HttpServletRequest request,
      LiferayPortletResponse liferayPortletResponse,
      String className,
      long classPK,
      String paramName,
      PortletURL containerModelURL,
      boolean checkInTrashContainers)
      throws PortalException, PortletException {

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

    PortletURL portletURL = PortletURLUtil.clone(containerModelURL, liferayPortletResponse);

    TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className);

    List<ContainerModel> containerModels = trashHandler.getParentContainerModels(classPK);

    Collections.reverse(containerModels);

    for (ContainerModel containerModel : containerModels) {
      TrashHandler containerModelTrashHandler =
          TrashHandlerRegistryUtil.getTrashHandler(containerModel.getModelClassName());

      if (checkInTrashContainers
          && !containerModelTrashHandler.isInTrash(containerModel.getContainerModelId())) {

        continue;
      }

      portletURL.setParameter(paramName, String.valueOf(containerModel.getContainerModelId()));

      String name = containerModel.getContainerModelName();

      if (containerModelTrashHandler.isInTrash(containerModel.getContainerModelId())) {

        name = TrashUtil.getOriginalTitle(name);
      }

      PortalUtil.addPortletBreadcrumbEntry(request, name, portletURL.toString());
    }

    TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK);

    PortalUtil.addPortletBreadcrumbEntry(
        request, trashRenderer.getTitle(themeDisplay.getLocale()), null);
  }
Exemple #8
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);
  }
Exemple #9
0
  @Override
  public List<TrashRenderer> getTrashContainerModelTrashRenderers(long classPK, int start, int end)
      throws PortalException, SystemException {

    List<TrashRenderer> trashRenderers = new ArrayList<TrashRenderer>();

    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(classPK);

    List<BookmarksFolder> folders =
        BookmarksFolderLocalServiceUtil.getFolders(folder.getGroupId(), classPK, start, end);

    for (BookmarksFolder curFolder : folders) {
      TrashHandler trashHandler =
          TrashHandlerRegistryUtil.getTrashHandler(BookmarksFolder.class.getName());

      TrashRenderer trashRenderer = trashHandler.getTrashRenderer(curFolder.getPrimaryKey());

      trashRenderers.add(trashRenderer);
    }

    return trashRenderers;
  }
  @Override
  public List<TrashRenderer> getTrashContainedModelTrashRenderers(long classPK, int start, int end)
      throws PortalException {

    List<TrashRenderer> trashRenderers = new ArrayList<TrashRenderer>();

    BookmarksFolder folder = BookmarksFolderLocalServiceUtil.getFolder(classPK);

    List<BookmarksEntry> entries =
        BookmarksEntryLocalServiceUtil.getEntries(
            folder.getGroupId(), classPK, WorkflowConstants.STATUS_IN_TRASH, start, end);

    for (BookmarksEntry entry : entries) {
      TrashHandler trashHandler =
          TrashHandlerRegistryUtil.getTrashHandler(BookmarksEntry.class.getName());

      TrashRenderer trashRenderer = trashHandler.getTrashRenderer(entry.getEntryId());

      trashRenderers.add(trashRenderer);
    }

    return trashRenderers;
  }
  @Override
  public List<TrashRenderer> getTrashContainedModelTrashRenderers(long classPK, int start, int end)
      throws PortalException, SystemException {

    List<TrashRenderer> trashRenderers = new ArrayList<TrashRenderer>();

    JournalFolder folder = JournalFolderLocalServiceUtil.getFolder(classPK);

    List<JournalArticle> articles =
        JournalArticleLocalServiceUtil.search(
            folder.getGroupId(), classPK, WorkflowConstants.STATUS_IN_TRASH, start, end);

    for (JournalArticle article : articles) {
      TrashHandler trashHandler =
          TrashHandlerRegistryUtil.getTrashHandler(JournalArticle.class.getName());

      TrashRenderer trashRenderer = trashHandler.getTrashRenderer(article.getResourcePrimKey());

      trashRenderers.add(trashRenderer);
    }

    return trashRenderers;
  }