use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.
the class KBArticleStagedModelDataHandler method doExportStagedModel.
@Override
protected void doExportStagedModel(PortletDataContext portletDataContext, KBArticle kbArticle) throws Exception {
if (kbArticle.getParentResourcePrimKey() != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
long kbArticleClassNameId = PortalUtil.getClassNameId(KBArticleConstants.getClassName());
if (kbArticle.getParentResourceClassNameId() == kbArticleClassNameId) {
KBArticle parentKBArticle = KBArticleLocalServiceUtil.getLatestKBArticle(kbArticle.getParentResourcePrimKey(), WorkflowConstants.STATUS_APPROVED);
StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, kbArticle, parentKBArticle, PortletDataContext.REFERENCE_TYPE_PARENT);
} else {
KBFolder parentKBFolder = KBFolderLocalServiceUtil.getKBFolder(kbArticle.getParentResourcePrimKey());
StagedModelDataHandlerUtil.exportReferenceStagedModel(portletDataContext, kbArticle, parentKBFolder, PortletDataContext.REFERENCE_TYPE_PARENT);
}
}
Element kbArticleElement = portletDataContext.getExportDataElement(kbArticle);
exportKBArticleAttachments(portletDataContext, kbArticleElement, kbArticle);
portletDataContext.addClassedModel(kbArticleElement, ExportImportPathUtil.getModelPath(kbArticle), kbArticle);
}
use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.
the class KBFolderStagedModelDataHandler method doImportStagedModel.
@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, KBFolder kbFolder) throws Exception {
long userId = portletDataContext.getUserId(kbFolder.getUserUuid());
if (kbFolder.getParentKBFolderId() != KBFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
StagedModelDataHandlerUtil.importReferenceStagedModels(portletDataContext, kbFolder, KBFolder.class);
}
ServiceContext serviceContext = portletDataContext.createServiceContext(kbFolder);
KBFolder importedKBFolder = null;
if (portletDataContext.isDataStrategyMirror()) {
KBFolder existingKBFolder = KBFolderUtil.fetchByUUID_G(kbFolder.getUuid(), portletDataContext.getScopeGroupId());
if (existingKBFolder == null) {
importedKBFolder = KBFolderLocalServiceUtil.addKBFolder(userId, portletDataContext.getScopeGroupId(), kbFolder.getClassNameId(), kbFolder.getParentKBFolderId(), kbFolder.getName(), kbFolder.getDescription(), serviceContext);
} else {
importedKBFolder = KBFolderLocalServiceUtil.updateKBFolder(kbFolder.getClassNameId(), kbFolder.getParentKBFolderId(), kbFolder.getKbFolderId(), kbFolder.getName(), kbFolder.getDescription());
}
} else {
importedKBFolder = KBFolderLocalServiceUtil.addKBFolder(userId, portletDataContext.getScopeGroupId(), kbFolder.getClassNameId(), kbFolder.getParentKBFolderId(), kbFolder.getName(), kbFolder.getDescription(), serviceContext);
}
portletDataContext.importClassedModel(kbFolder, importedKBFolder);
Map<Long, Long> kbFolderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(KBFolder.class);
kbFolderIds.put(kbFolder.getKbFolderId(), importedKBFolder.getKbFolderId());
}
use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.
the class KBFolderPermission method check.
public static void check(PermissionChecker permissionChecker, long kbFolderId, String actionId) throws PortalException, SystemException {
KBFolder kbFolder = KBFolderLocalServiceUtil.getKBFolder(kbFolderId);
check(permissionChecker, kbFolder, actionId);
}
use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.
the class KBFolderPersistenceImpl method fetchByG_P_UT.
/**
* Returns the k b folder where groupId = ? and parentKBFolderId = ? and urlTitle = ? 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 urlTitle the url title
* @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_UT(long groupId, long parentKBFolderId, String urlTitle, boolean retrieveFromCache) throws SystemException {
Object[] finderArgs = new Object[] { groupId, parentKBFolderId, urlTitle };
Object result = null;
if (retrieveFromCache) {
result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_P_UT, finderArgs, this);
}
if (result instanceof KBFolder) {
KBFolder kbFolder = (KBFolder) result;
if ((groupId != kbFolder.getGroupId()) || (parentKBFolderId != kbFolder.getParentKBFolderId()) || !Validator.equals(urlTitle, kbFolder.getUrlTitle())) {
result = null;
}
}
if (result == null) {
StringBundler query = new StringBundler(5);
query.append(_SQL_SELECT_KBFOLDER_WHERE);
query.append(_FINDER_COLUMN_G_P_UT_GROUPID_2);
query.append(_FINDER_COLUMN_G_P_UT_PARENTKBFOLDERID_2);
boolean bindUrlTitle = false;
if (urlTitle == null) {
query.append(_FINDER_COLUMN_G_P_UT_URLTITLE_1);
} else if (urlTitle.equals(StringPool.BLANK)) {
query.append(_FINDER_COLUMN_G_P_UT_URLTITLE_3);
} else {
bindUrlTitle = true;
query.append(_FINDER_COLUMN_G_P_UT_URLTITLE_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 (bindUrlTitle) {
qPos.add(urlTitle);
}
List<KBFolder> list = q.list();
if (list.isEmpty()) {
FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_UT, finderArgs, list);
} else {
if ((list.size() > 1) && _log.isWarnEnabled()) {
_log.warn("KBFolderPersistenceImpl.fetchByG_P_UT(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.getUrlTitle() == null) || !kbFolder.getUrlTitle().equals(urlTitle)) {
FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_P_UT, finderArgs, kbFolder);
}
}
} catch (Exception e) {
FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_P_UT, 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 KBFolderPersistenceImpl method findByUuid_C_Last.
/**
* Returns the last k b folder in the ordered set where uuid = ? and companyId = ?.
*
* @param uuid the uuid
* @param companyId the company ID
* @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
* @return the last 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 findByUuid_C_Last(String uuid, long companyId, OrderByComparator orderByComparator) throws NoSuchFolderException, SystemException {
KBFolder kbFolder = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
if (kbFolder != null) {
return kbFolder;
}
StringBundler msg = new StringBundler(6);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("uuid=");
msg.append(uuid);
msg.append(", companyId=");
msg.append(companyId);
msg.append(StringPool.CLOSE_CURLY_BRACE);
throw new NoSuchFolderException(msg.toString());
}
Aggregations