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 = ? and parentKBFolderId = ? and name = ? 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;
}
}
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;
}
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;
}
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;
}
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;
}
});
}
Aggregations