Esempio n. 1
0
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    try {
      ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

      int status = getStatus(renderRequest);

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_STATUS, status);

      KBArticle kbArticle = null;

      long resourcePrimKey = getResourcePrimKey(renderRequest);

      if (resourcePrimKey > 0) {
        kbArticle = KBArticleServiceUtil.getLatestKBArticle(resourcePrimKey, status);
      } else {
        List<KBArticle> kbArticles =
            KBArticleLocalServiceUtil.getGroupKBArticles(
                themeDisplay.getScopeGroupId(), status, 0, 1, new KBArticlePriorityComparator());

        if (!kbArticles.isEmpty()) {
          kbArticle = kbArticles.get(0);
        }
      }

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle);
    } catch (Exception e) {
      if (e instanceof NoSuchArticleException || e instanceof PrincipalException) {

        SessionErrors.add(renderRequest, e.getClass());

        SessionMessages.add(
            renderRequest,
            PortalUtil.getPortletId(renderRequest)
                + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
      } else {
        throw new PortletException(e);
      }
    }

    super.render(renderRequest, renderResponse);
  }
  @Override
  public void render(RenderRequest renderRequest, RenderResponse renderResponse)
      throws IOException, PortletException {

    try {
      ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);

      int status = getStatus(renderRequest);

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_STATUS, status);

      KBArticle kbArticle = null;

      Tuple resourceTuple = getResourceTuple(renderRequest);

      long resourcePrimKey = (Long) resourceTuple.getObject(1);

      if (resourcePrimKey != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        long resourceClassNameId = (Long) resourceTuple.getObject(0);

        long kbFolderClassNameId = PortalUtil.getClassNameId(KBFolderConstants.getClassName());

        if (resourceClassNameId == kbFolderClassNameId) {
          PortalPreferences portalPreferences =
              PortletPreferencesFactoryUtil.getPortalPreferences(renderRequest);

          String preferredKBFolderURLTitle =
              portalPreferences.getValue(
                  PortletKeys.KNOWLEDGE_BASE_DISPLAY, "preferredKBFolderURLTitle");

          kbArticle =
              getKBFolderKBArticle(
                  themeDisplay.getScopeGroupId(), resourcePrimKey, preferredKBFolderURLTitle);
        } else {
          kbArticle = KBArticleServiceUtil.fetchLatestKBArticle(resourcePrimKey, status);
        }
      } else {
        long parentResourcePrimKey =
            ParamUtil.getLong(
                renderRequest, "parentResourcePrimKey", KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);

        if (parentResourcePrimKey == KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

          List<KBArticle> kbArticles =
              KBArticleLocalServiceUtil.getGroupKBArticles(
                  themeDisplay.getScopeGroupId(),
                  status,
                  0,
                  1,
                  new KBArticlePriorityComparator(true));

          if (!kbArticles.isEmpty()) {
            kbArticle = kbArticles.get(0);
          }
        }
      }

      renderRequest.setAttribute(WebKeys.KNOWLEDGE_BASE_KB_ARTICLE, kbArticle);
    } catch (Exception e) {
      if (e instanceof NoSuchArticleException || e instanceof PrincipalException) {

        SessionErrors.add(renderRequest, e.getClass());

        SessionMessages.add(
            renderRequest,
            PortalUtil.getPortletId(renderRequest)
                + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_ERROR_MESSAGE);
      } else {
        throw new PortletException(e);
      }
    }

    super.render(renderRequest, renderResponse);
  }