コード例 #1
0
  public void updateRootKBFolderId(ActionRequest actionRequest, ActionResponse actionResponse)
      throws PortalException {

    long kbFolderId = ParamUtil.getLong(actionRequest, "rootKBFolderId");

    if (kbFolderId == KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
      return;
    }

    KBFolder kbFolder = KBFolderServiceUtil.getKBFolder(kbFolderId);

    PortalPreferences portalPreferences =
        PortletPreferencesFactoryUtil.getPortalPreferences(
            PortalUtil.getLiferayPortletRequest(actionRequest));

    portalPreferences.setValue(
        PortletKeys.KNOWLEDGE_BASE_DISPLAY, "preferredKBFolderURLTitle", kbFolder.getUrlTitle());

    String urlTitle = ParamUtil.getString(actionRequest, "urlTitle");

    if (Validator.isNull(urlTitle)) {
      return;
    }

    KBArticle kbArticle =
        KBArticleLocalServiceUtil.fetchKBArticleByUrlTitle(
            kbFolder.getGroupId(), kbFolder.getUrlTitle(), urlTitle);

    if (kbArticle == null) {
      return;
    }

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

    if (!KBArticlePermission.contains(
        themeDisplay.getPermissionChecker(), kbArticle, ActionKeys.VIEW)) {

      return;
    }

    actionResponse.setRenderParameter("kbFolderUrlTitle", kbFolder.getUrlTitle());
    actionResponse.setRenderParameter("urlTitle", urlTitle);
  }
コード例 #2
0
  protected KBArticle getKBFolderKBArticle(long groupId, long kbFolderId, String kbFolderUrlTitle)
      throws PortalException {

    if (Validator.isNotNull(kbFolderUrlTitle)) {
      KBFolder kbFolder =
          KBFolderServiceUtil.fetchKBFolderByUrlTitle(groupId, kbFolderId, kbFolderUrlTitle);

      if (kbFolder != null) {
        kbFolderId = kbFolder.getKbFolderId();
      }
    }

    List<KBArticle> kbArticles =
        KBArticleServiceUtil.getKBArticles(
            groupId,
            kbFolderId,
            WorkflowConstants.STATUS_APPROVED,
            0,
            1,
            new KBArticlePriorityComparator(true));

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

    List<KBFolder> kbFolders = KnowledgeBaseUtil.getAlternateRootKBFolders(groupId, kbFolderId);

    for (KBFolder kbFolder : kbFolders) {
      KBArticle kbArticle =
          getKBFolderKBArticle(groupId, kbFolder.getKbFolderId(), kbFolder.getUrlTitle());

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

    return null;
  }