use of com.liferay.knowledgebase.util.comparator.KBArticleVersionComparator in project liferay-ide by liferay.
the class KBArticleLocalServiceImpl method fetchLatestKBArticleByUrlTitle.
@Override
public KBArticle fetchLatestKBArticleByUrlTitle(long groupId, long kbFolderId, String urlTitle, int status) throws SystemException {
urlTitle = StringUtil.replaceFirst(urlTitle, StringPool.SLASH, StringPool.BLANK);
List<KBArticle> kbArticles = null;
OrderByComparator orderByComparator = new KBArticleVersionComparator();
if (status == WorkflowConstants.STATUS_ANY) {
kbArticles = kbArticlePersistence.findByG_KBFI_UT(groupId, kbFolderId, urlTitle, 0, 1, orderByComparator);
} else {
kbArticles = kbArticlePersistence.findByG_KBFI_UT_ST(groupId, kbFolderId, urlTitle, status, 0, 1, orderByComparator);
}
if (kbArticles.isEmpty()) {
return null;
}
return kbArticles.get(0);
}
use of com.liferay.knowledgebase.util.comparator.KBArticleVersionComparator in project liferay-ide by liferay.
the class KBArticleLocalServiceImpl method moveKBArticle.
@Override
public void moveKBArticle(long userId, long resourcePrimKey, long parentResourceClassNameId, long parentResourcePrimKey, double priority) throws PortalException, SystemException {
// KB article
validate(priority);
updatePermissionFields(resourcePrimKey, parentResourceClassNameId, parentResourcePrimKey);
long kbFolderClassNameId = classNameLocalService.getClassNameId(KBFolderConstants.getClassName());
long kbFolderId = KBFolderConstants.DEFAULT_PARENT_FOLDER_ID;
if (parentResourceClassNameId == kbFolderClassNameId) {
kbFolderId = parentResourcePrimKey;
} else {
KBArticle latestKBArticle = getLatestKBArticle(parentResourcePrimKey, WorkflowConstants.STATUS_ANY);
kbFolderId = latestKBArticle.getKbFolderId();
}
List<KBArticle> kbArticles = getKBArticleVersions(resourcePrimKey, WorkflowConstants.STATUS_ANY, QueryUtil.ALL_POS, QueryUtil.ALL_POS, new KBArticleVersionComparator());
for (KBArticle curKBArticle : kbArticles) {
curKBArticle.setParentResourceClassNameId(parentResourceClassNameId);
curKBArticle.setParentResourcePrimKey(parentResourcePrimKey);
curKBArticle.setKbFolderId(kbFolderId);
curKBArticle.setPriority(priority);
kbArticlePersistence.update(curKBArticle);
}
KBArticle kbArticle = getLatestKBArticle(resourcePrimKey, WorkflowConstants.STATUS_ANY);
if (kbArticle.getKbFolderId() != kbFolderId) {
List<KBArticle> descendantKBArticles = getAllDescendantKBArticles(resourcePrimKey, WorkflowConstants.STATUS_ANY, null);
for (KBArticle curKBArticle : descendantKBArticles) {
List<KBArticle> kbArticleVersions = getKBArticleVersions(curKBArticle.getResourcePrimKey(), WorkflowConstants.STATUS_ANY, QueryUtil.ALL_POS, QueryUtil.ALL_POS, new KBArticleVersionComparator());
for (KBArticle kbArticleVersion : kbArticleVersions) {
kbArticleVersion.setKbFolderId(kbFolderId);
kbArticlePersistence.update(kbArticleVersion);
}
}
}
// Social
KBArticle latestKBArticle = getLatestKBArticle(resourcePrimKey, WorkflowConstants.STATUS_ANY);
JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();
extraDataJSONObject.put("title", latestKBArticle.getTitle());
if (latestKBArticle.isApproved() || !latestKBArticle.isFirstVersion()) {
socialActivityLocalService.addActivity(userId, latestKBArticle.getGroupId(), KBArticle.class.getName(), resourcePrimKey, AdminActivityKeys.MOVE_KB_ARTICLE, extraDataJSONObject.toString(), 0);
}
}
use of com.liferay.knowledgebase.util.comparator.KBArticleVersionComparator in project liferay-ide by liferay.
the class AdminPortletDataHandler method getKBArticleActionableDynamicQuery.
protected ActionableDynamicQuery getKBArticleActionableDynamicQuery(final PortletDataContext portletDataContext) throws Exception {
return new KBArticleExportActionableDynamicQuery(portletDataContext) {
@Override
protected void addCriteria(DynamicQuery dynamicQuery) {
super.addCriteria(dynamicQuery);
OrderFactoryUtil.addOrderByComparator(dynamicQuery, new KBArticleVersionComparator(true));
}
};
}
Aggregations