Search in sources :

Example 16 with KBFolder

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

the class KBFolderPersistenceImpl method fetchByG_P_N.

/**
 * Returns the k b folder where groupId = &#63; and parentKBFolderId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param groupId the group ID
 * @param parentKBFolderId the parent k b folder ID
 * @param name the name
 * @param retrieveFromCache whether to use the finder cache
 * @return the matching k b folder, or <code>null</code> if a matching k b folder could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public KBFolder fetchByG_P_N(long groupId, long parentKBFolderId, String name, boolean retrieveFromCache) throws SystemException {
    Object[] finderArgs = new Object[] { groupId, parentKBFolderId, name };
    Object result = null;
    if (retrieveFromCache) {
        result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_N, finderArgs, this);
    }
    if (result instanceof KBFolder) {
        KBFolder kbFolder = (KBFolder) result;
        if ((groupId != kbFolder.getGroupId()) || (parentKBFolderId != kbFolder.getParentKBFolderId()) || !Validator.equals(name, kbFolder.getName())) {
            result = null;
        }
    }
    if (result == null) {
        StringBundler query = new StringBundler(5);
        query.append(_SQL_SELECT_KBFOLDER_WHERE);
        query.append(_FINDER_COLUMN_G_P_N_GROUPID_2);
        query.append(_FINDER_COLUMN_G_P_N_PARENTKBFOLDERID_2);
        boolean bindName = false;
        if (name == null) {
            query.append(_FINDER_COLUMN_G_P_N_NAME_1);
        } else if (name.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_G_P_N_NAME_3);
        } else {
            bindName = true;
            query.append(_FINDER_COLUMN_G_P_N_NAME_2);
        }
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            qPos.add(groupId);
            qPos.add(parentKBFolderId);
            if (bindName) {
                qPos.add(name);
            }
            List<KBFolder> list = q.list();
            if (list.isEmpty()) {
                FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, finderArgs, list);
            } else {
                if ((list.size() > 1) && _log.isWarnEnabled()) {
                    _log.warn("KBFolderPersistenceImpl.fetchByG_P_N(long, long, String, boolean) with parameters (" + StringUtil.merge(finderArgs) + ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
                }
                KBFolder kbFolder = list.get(0);
                result = kbFolder;
                cacheResult(kbFolder);
                if ((kbFolder.getGroupId() != groupId) || (kbFolder.getParentKBFolderId() != parentKBFolderId) || (kbFolder.getName() == null) || !kbFolder.getName().equals(name)) {
                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_N, finderArgs, kbFolder);
                }
            }
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_N, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    if (result instanceof List<?>) {
        return null;
    } else {
        return (KBFolder) result;
    }
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) SQLQuery(com.liferay.portal.kernel.dao.orm.SQLQuery) Query(com.liferay.portal.kernel.dao.orm.Query) ArrayList(java.util.ArrayList) UnmodifiableList(com.liferay.portal.kernel.util.UnmodifiableList) List(java.util.List) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchFolderException(com.liferay.knowledgebase.NoSuchFolderException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 17 with KBFolder

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

the class KBArticleURLHelper method createViewURL.

public PortletURL createViewURL(KBArticle kbArticle) throws PortalException, SystemException {
    PortletURL portletURL = _renderResponse.createRenderURL();
    String portletId = PortalUtil.getPortletId(_renderRequest);
    if (portletId.startsWith(PortletKeys.KNOWLEDGE_BASE_ADMIN) || portletId.startsWith(PortletKeys.KNOWLEDGE_BASE_SECTION)) {
        portletURL.setParameter("mvcPath", _templatePath + "view_article.jsp");
    }
    if (portletId.startsWith(PortletKeys.KNOWLEDGE_BASE_ADMIN)) {
        portletURL.setParameter("redirect", PortalUtil.getCurrentURL(_renderRequest));
    }
    if (Validator.isNull(kbArticle.getUrlTitle()) || portletId.equals(PortletKeys.KNOWLEDGE_BASE_ADMIN)) {
        portletURL.setParameter("resourceClassNameId", String.valueOf(kbArticle.getClassNameId()));
        portletURL.setParameter("resourcePrimKey", String.valueOf(kbArticle.getResourcePrimKey()));
    } else {
        portletURL.setParameter("urlTitle", kbArticle.getUrlTitle());
        if (kbArticle.getKbFolderId() != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
            KBFolder kbFolder = KBFolderServiceUtil.getKBFolder(kbArticle.getKbFolderId());
            portletURL.setParameter("kbFolderUrlTitle", kbFolder.getUrlTitle());
        }
    }
    return portletURL;
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder) PortletURL(javax.portlet.PortletURL)

Example 18 with KBFolder

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

the class KBNavigationDisplayContext method getPageTitle.

public String getPageTitle() throws PortalException, SystemException {
    long rootResourcePrimKey = getRootResourcePrimKey();
    String pageTitle = null;
    if (rootResourcePrimKey != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        KBFolder kbFolder = KBFolderServiceUtil.getKBFolder(rootResourcePrimKey);
        pageTitle = getContentRootPrefix() + " " + kbFolder.getName();
        if (_kbArticle != null) {
            pageTitle = _kbArticle.getTitle() + " - " + pageTitle;
        }
    } else {
        if (_kbArticle != null) {
            pageTitle = _kbArticle.getTitle();
        }
    }
    return pageTitle;
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder)

Example 19 with KBFolder

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

the class KBNavigationDisplayContext method getCurrentKBFolderURLTitle.

public String getCurrentKBFolderURLTitle() throws PortalException, SystemException {
    String currentKBFolderURLTitle = KnowledgeBaseUtil.getPreferredKBFolderURLTitle(_portalPreferences, getContentRootPrefix());
    long rootResourcePrimKey = getRootResourcePrimKey();
    if (rootResourcePrimKey != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        KBFolder kbFolder = KBFolderServiceUtil.getKBFolder(rootResourcePrimKey);
        currentKBFolderURLTitle = kbFolder.getUrlTitle();
    }
    return currentKBFolderURLTitle;
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder)

Example 20 with KBFolder

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

the class KnowledgeBaseUtil method getAlternateRootKBFolders.

public static List<KBFolder> getAlternateRootKBFolders(long groupId, long kbFolderId) throws PortalException, SystemException {
    List<KBFolder> kbFolders = KBFolderServiceUtil.getKBFolders(groupId, kbFolderId, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
    kbFolders = new ArrayList<KBFolder>(kbFolders);
    Iterator<KBFolder> itr = kbFolders.iterator();
    while (itr.hasNext()) {
        KBFolder kbFolder = itr.next();
        if (kbFolder.isEmpty()) {
            itr.remove();
        }
    }
    return ListUtil.sort(kbFolders, new Comparator<KBFolder>() {

        @Override
        public int compare(KBFolder kbFolder1, KBFolder kbFolder2) {
            String name1 = kbFolder1.getName();
            String name2 = kbFolder2.getName();
            return name1.compareTo(name2) * -1;
        }
    });
}
Also used : KBFolder(com.liferay.knowledgebase.model.KBFolder)

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