Search in sources :

Example 56 with KBFolder

use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.

the class KBFolderPersistenceImpl method findByG_P_N.

/**
 * Returns the k b folder where groupId = ? and parentKBFolderId = ? and name = ? or throws a {@link com.liferay.knowledgebase.NoSuchFolderException} if it could not be found.
 *
 * @param groupId the group ID
 * @param parentKBFolderId the parent k b folder ID
 * @param name the name
 * @return the matching k b folder
 * @throws com.liferay.knowledgebase.NoSuchFolderException if a matching k b folder could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public KBFolder findByG_P_N(long groupId, long parentKBFolderId, String name) throws NoSuchFolderException, SystemException {
    KBFolder kbFolder = fetchByG_P_N(groupId, parentKBFolderId, name);
    if (kbFolder == null) {
        StringBundler msg = new StringBundler(8);
        msg.append(_NO_SUCH_ENTITY_WITH_KEY);
        msg.append("groupId=");
        msg.append(groupId);
        msg.append(", parentKBFolderId=");
        msg.append(parentKBFolderId);
        msg.append(", name=");
        msg.append(name);
        msg.append(StringPool.CLOSE_CURLY_BRACE);
        if (_log.isWarnEnabled()) {
            _log.warn(msg.toString());
        }
        throw new NoSuchFolderException(msg.toString());
    }
    return kbFolder;
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) NoSuchFolderException(com.liferay.knowledgebase.NoSuchFolderException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 57 with KBFolder

use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.

the class KBNavigationDisplayContext method hasMultipleDescendantKBArticles.

protected boolean hasMultipleDescendantKBArticles() throws PortalException, SystemException {
    long scopeGroupId = PortalUtil.getScopeGroupId(_portletRequest);
    long kbFolderClassNameId = PortalUtil.getClassNameId(KBFolderConstants.getClassName());
    if (getResourceClassNameId() == kbFolderClassNameId) {
        List<KBFolder> kbFolders = KnowledgeBaseUtil.getAlternateRootKBFolders(scopeGroupId, getResourcePrimKey());
        if (kbFolders.size() > 1) {
            int maxKBArticlesCount = 0;
            for (KBFolder kbFolder : kbFolders) {
                int kbArticlesCount = KBArticleLocalServiceUtil.getKBFolderKBArticlesCount(scopeGroupId, kbFolder.getKbFolderId(), WorkflowConstants.STATUS_APPROVED);
                if (kbArticlesCount > maxKBArticlesCount) {
                    maxKBArticlesCount = kbArticlesCount;
                }
            }
            if (maxKBArticlesCount > 1) {
                return true;
            }
            return false;
        }
    }
    boolean showNavigation = true;
    long rootResourcePrimKey = getRootResourcePrimKey();
    int kbArticlesCount = KBArticleLocalServiceUtil.getKBArticlesCount(scopeGroupId, rootResourcePrimKey, WorkflowConstants.STATUS_APPROVED);
    if (kbArticlesCount == 0) {
        showNavigation = false;
    } else if (kbArticlesCount == 1) {
        List<KBArticle> kbArticles = KBArticleLocalServiceUtil.getKBArticles(scopeGroupId, rootResourcePrimKey, WorkflowConstants.STATUS_APPROVED, 0, 1, null);
        KBArticle navigationKBArticle = kbArticles.get(0);
        int navigationKBArticleChildCount = KBArticleLocalServiceUtil.getKBArticlesCount(scopeGroupId, navigationKBArticle.getResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);
        if (navigationKBArticleChildCount == 0) {
            showNavigation = false;
        }
    }
    return showNavigation;
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) KBArticle(com.liferay.knowledgebase.model.KBArticle) ArrayList(java.util.ArrayList) List(java.util.List)

Example 58 with KBFolder

use of com.liferay.knowledgebase.model.KBFolder 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)

Example 59 with KBFolder

use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.

the class KnowledgeBaseUtil method addPortletBreadcrumbEntries.

protected static void addPortletBreadcrumbEntries(Map<String, Object> parameters, HttpServletRequest request, RenderResponse renderResponse) throws PortalException, SystemException {
    PortletURL portletURL = renderResponse.createRenderURL();
    for (Map.Entry<String, Object> entry : parameters.entrySet()) {
        Object value = entry.getValue();
        portletURL.setParameter(entry.getKey(), value.toString());
    }
    long kbFolderClassNameId = PortalUtil.getClassNameId(KBFolderConstants.getClassName());
    long parentResourceClassNameId = (Long) parameters.get("parentResourceClassNameId");
    long parentResourcePrimKey = (Long) parameters.get("parentResourcePrimKey");
    String mvcPath = (String) parameters.get("mvcPath");
    if (parentResourcePrimKey == KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
        PortalUtil.addPortletBreadcrumbEntry(request, themeDisplay.translate("home"), portletURL.toString());
    } else if (parentResourceClassNameId == kbFolderClassNameId) {
        KBFolder kbFolder = KBFolderServiceUtil.getKBFolder(parentResourcePrimKey);
        addPortletBreadcrumbEntries(kbFolder.getClassNameId(), kbFolder.getParentKBFolderId(), mvcPath, request, renderResponse);
        PortalUtil.addPortletBreadcrumbEntry(request, kbFolder.getName(), portletURL.toString());
    } else {
        KBArticle kbArticle = KBArticleServiceUtil.getLatestKBArticle(parentResourcePrimKey, WorkflowConstants.STATUS_ANY);
        addPortletBreadcrumbEntries(kbArticle.getParentResourceClassNameId(), kbArticle.getParentResourcePrimKey(), mvcPath, request, renderResponse);
        PortalUtil.addPortletBreadcrumbEntry(request, kbArticle.getTitle(), portletURL.toString());
    }
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) KBArticle(com.liferay.knowledgebase.model.KBArticle) JSONObject(com.liferay.portal.kernel.json.JSONObject) PortletURL(javax.portlet.PortletURL) Map(java.util.Map) HashMap(java.util.HashMap) ThemeDisplay(com.liferay.portal.theme.ThemeDisplay)

Aggregations

KBFolder (com.liferay.knowledgebase.model.KBFolder)59 NoSuchFolderException (com.liferay.knowledgebase.NoSuchFolderException)24 StringBundler (com.liferay.portal.kernel.util.StringBundler)21 Session (com.liferay.portal.kernel.dao.orm.Session)14 SystemException (com.liferay.portal.kernel.exception.SystemException)14 SQLQuery (com.liferay.portal.kernel.dao.orm.SQLQuery)12 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)11 Query (com.liferay.portal.kernel.dao.orm.Query)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)8 KBArticle (com.liferay.knowledgebase.model.KBArticle)7 KBFolderImpl (com.liferay.knowledgebase.model.impl.KBFolderImpl)7 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)4 PortletURL (javax.portlet.PortletURL)4 Element (com.liferay.portal.kernel.xml.Element)2 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)2 PortalPreferences (com.liferay.portlet.PortalPreferences)2 Date (java.util.Date)2 Map (java.util.Map)2