コード例 #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 PortletURL getKBArticleURL(
      long plid, String portletId, KBArticle kbArticle, HttpServletRequest request)
      throws Exception {

    long resourcePrimKey = ParamUtil.getLong(request, "resourcePrimKey");

    String mvcPath = null;

    String rootPortletId = PortletConstants.getRootPortletId(portletId);

    if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_ARTICLE)) {
      mvcPath = "/article/view_article.jsp";
    } else if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_SECTION)) {
      mvcPath = "/section/view_article.jsp";
    }

    PortletURL portletURL =
        PortletURLFactoryUtil.create(request, portletId, plid, PortletRequest.RENDER_PHASE);

    if (mvcPath != null) {
      portletURL.setParameter("mvcPath", mvcPath);
    }

    if ((kbArticle == null) || Validator.isNull(kbArticle.getUrlTitle())) {
      portletURL.setParameter("resourcePrimKey", String.valueOf(resourcePrimKey));
    } else {
      portletURL.setParameter("urlTitle", kbArticle.getUrlTitle());

      if (kbArticle.getKbFolderId() != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        KBFolder kbFolder = KBFolderLocalServiceUtil.getKBFolder(kbArticle.getKbFolderId());

        portletURL.setParameter("kbFolderUrlTitle", String.valueOf(kbFolder.getUrlTitle()));
      }
    }

    portletURL.setPortletMode(PortletMode.VIEW);

    portletURL.setWindowState(LiferayWindowState.NORMAL);

    if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_SECTION)) {
      portletURL.setWindowState(LiferayWindowState.MAXIMIZED);
    }

    return portletURL;
  }
コード例 #3
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;
  }