Search in sources :

Example 1 with PortalPreferences

use of com.liferay.portlet.PortalPreferences in project liferay-ide by liferay.

the class DisplayPortlet method getPreferredKBFolderUrlTitle.

protected String getPreferredKBFolderUrlTitle(RenderRequest renderRequest, PortletPreferences portletPreferences) throws PortalException, SystemException {
    PortalPreferences portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(renderRequest);
    String contentRootPrefix = GetterUtil.getString(portletPreferences.getValue("contentRootPrefix", null));
    return KnowledgeBaseUtil.getPreferredKBFolderURLTitle(portalPreferences, contentRootPrefix);
}
Also used : PortalPreferences(com.liferay.portlet.PortalPreferences)

Example 2 with PortalPreferences

use of com.liferay.portlet.PortalPreferences in project liferay-ide by liferay.

the class DisplayPortlet method updateRootKBFolderId.

public void updateRootKBFolderId(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, PortalException, SystemException {
    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));
    PortletPreferences portletPreferences = actionRequest.getPreferences();
    String contentRootPrefix = GetterUtil.getString(portletPreferences.getValue("contentRootPrefix", null));
    String previousPreferredKBFolderURLTitle = KnowledgeBaseUtil.getPreferredKBFolderURLTitle(portalPreferences, contentRootPrefix);
    KnowledgeBaseUtil.setPreferredKBFolderURLTitle(portalPreferences, contentRootPrefix, 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) {
        if (Validator.isNull(previousPreferredKBFolderURLTitle)) {
            return;
        }
        kbArticle = findClosestMatchingKBArticle(kbFolder.getGroupId(), previousPreferredKBFolderURLTitle, kbFolder.getKbFolderId(), urlTitle);
        if (kbArticle == null) {
            return;
        }
    }
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    if (!KBArticlePermission.contains(themeDisplay.getPermissionChecker(), kbArticle, ActionKeys.VIEW)) {
        return;
    }
    PortletURL redirectURL = PortletURLFactoryUtil.create(actionRequest, PortletKeys.KNOWLEDGE_BASE_DISPLAY, themeDisplay.getPlid(), PortletRequest.RENDER_PHASE);
    redirectURL.setParameter("kbFolderUrlTitle", kbFolder.getUrlTitle());
    redirectURL.setParameter("urlTitle", kbArticle.getUrlTitle());
    actionResponse.sendRedirect(redirectURL.toString());
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) KBArticle(com.liferay.knowledgebase.model.KBArticle) PortalPreferences(com.liferay.portlet.PortalPreferences) PortletPreferences(javax.portlet.PortletPreferences) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay) PortletURL(javax.portlet.PortletURL)

Example 3 with PortalPreferences

use of com.liferay.portlet.PortalPreferences in project liferay-ide by liferay.

the class KnowledgeBaseUtil method getCurrentRootKBFolder.

private static long getCurrentRootKBFolder(PortletRequest portletRequest, long groupId, long kbFolderId) throws PortalException, SystemException {
    PortalPreferences portalPreferences = PortletPreferencesFactoryUtil.getPortalPreferences(portletRequest);
    PortletPreferences portletPreferences = portletRequest.getPreferences();
    String contentRootPrefix = GetterUtil.getString(portletPreferences.getValue("contentRootPrefix", null));
    String kbFolderURLTitle = getPreferredKBFolderURLTitle(portalPreferences, contentRootPrefix);
    long childKbFolderId = KBFolderConstants.DEFAULT_PARENT_FOLDER_ID;
    if (kbFolderURLTitle == null) {
        List<KBFolder> kbFolders = getAlternateRootKBFolders(groupId, kbFolderId);
        if (!kbFolders.isEmpty()) {
            KBFolder kbFolder = kbFolders.get(0);
            childKbFolderId = kbFolder.getKbFolderId();
        }
    } else {
        KBFolder kbFolder = KBFolderServiceUtil.fetchKBFolderByUrlTitle(groupId, kbFolderId, kbFolderURLTitle);
        if (kbFolder != null) {
            childKbFolderId = kbFolder.getKbFolderId();
        }
    }
    return childKbFolderId;
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) PortalPreferences(com.liferay.portlet.PortalPreferences) PortletPreferences(javax.portlet.PortletPreferences)

Aggregations

PortalPreferences (com.liferay.portlet.PortalPreferences)3 KBFolder (com.liferay.knowledgebase.model.KBFolder)2 PortletPreferences (javax.portlet.PortletPreferences)2 KBArticle (com.liferay.knowledgebase.model.KBArticle)1 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)1 PortletURL (javax.portlet.PortletURL)1