Search in sources :

Example 1 with LayoutTypePortlet

use of com.liferay.portal.model.LayoutTypePortlet in project liferay-ide by liferay.

the class FindKBArticleAction method getKBArticleURL.

protected PortletURL getKBArticleURL(long plid, boolean privateLayout, KBArticle kbArticle, HttpServletRequest request) throws Exception {
    PortletURL firstMatchPortletURL = null;
    List<Layout> layouts = getCandidateLayouts(plid, privateLayout, kbArticle);
    for (Layout layout : layouts) {
        LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType();
        List<Portlet> portlets = layoutTypePortlet.getAllPortlets();
        for (Portlet portlet : portlets) {
            String rootPortletId = PortletConstants.getRootPortletId(portlet.getPortletId());
            if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_DISPLAY)) {
                PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup(layout, portlet.getPortletId(), StringPool.BLANK);
                long kbFolderClassNameId = PortalUtil.getClassNameId(KBFolderConstants.getClassName());
                long resourceClassNameId = GetterUtil.getLong(portletPreferences.getValue("resourceClassNameId", null), kbFolderClassNameId);
                long resourcePrimKey = GetterUtil.getLong(portletPreferences.getValue("resourcePrimKey", null), KBFolderConstants.DEFAULT_PARENT_FOLDER_ID);
                if (resourceClassNameId == kbFolderClassNameId) {
                    if (isParentFolder(resourcePrimKey, kbArticle.getKbFolderId())) {
                        return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                    }
                } else if (resourcePrimKey == kbArticle.getResourcePrimKey()) {
                    return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
                if (firstMatchPortletURL == null) {
                    firstMatchPortletURL = getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
            }
            if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_SECTION)) {
                PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup(layout, portlet.getPortletId(), StringPool.BLANK);
                String[] kbArticlesSections = portletPreferences.getValues("kbArticlesSections", new String[0]);
                KBArticle rootKBArticle = KBArticleLocalServiceUtil.fetchLatestKBArticle(kbArticle.getRootResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);
                if (rootKBArticle == null) {
                    continue;
                }
                String[] sections = AdminUtil.unescapeSections(rootKBArticle.getSections());
                for (String section : sections) {
                    if (!ArrayUtil.contains(kbArticlesSections, section)) {
                        continue;
                    }
                    return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
            }
            if (rootPortletId.equals(PortletKeys.KNOWLEDGE_BASE_ARTICLE)) {
                PortletPreferences portletPreferences = PortletPreferencesFactoryUtil.getPortletSetup(layout, portlet.getPortletId(), StringPool.BLANK);
                long resourcePrimKey = GetterUtil.getLong(portletPreferences.getValue("resourcePrimKey", null));
                KBArticle selKBArticle = KBArticleLocalServiceUtil.fetchLatestKBArticle(resourcePrimKey, WorkflowConstants.STATUS_APPROVED);
                if (selKBArticle == null) {
                    continue;
                }
                long rootResourcePrimKey = kbArticle.getRootResourcePrimKey();
                long selRootResourcePrimKey = selKBArticle.getRootResourcePrimKey();
                if (rootResourcePrimKey == selRootResourcePrimKey) {
                    return getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
                if (firstMatchPortletURL == null) {
                    firstMatchPortletURL = getKBArticleURL(layout.getPlid(), portlet.getPortletId(), kbArticle, request);
                }
            }
        }
    }
    return firstMatchPortletURL;
}
Also used : LayoutTypePortlet(com.liferay.portal.model.LayoutTypePortlet) LayoutTypePortlet(com.liferay.portal.model.LayoutTypePortlet) Portlet(com.liferay.portal.model.Portlet) KBArticle(com.liferay.knowledgebase.model.KBArticle) Layout(com.liferay.portal.model.Layout) PortletPreferences(javax.portlet.PortletPreferences) PortletURL(javax.portlet.PortletURL)

Aggregations

KBArticle (com.liferay.knowledgebase.model.KBArticle)1 Layout (com.liferay.portal.model.Layout)1 LayoutTypePortlet (com.liferay.portal.model.LayoutTypePortlet)1 Portlet (com.liferay.portal.model.Portlet)1 PortletPreferences (javax.portlet.PortletPreferences)1 PortletURL (javax.portlet.PortletURL)1