Search in sources :

Example 1 with KBArticleVersionComparator

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);
}
Also used : KBArticle(com.liferay.knowledgebase.model.KBArticle) KBArticleVersionComparator(com.liferay.knowledgebase.util.comparator.KBArticleVersionComparator) OrderByComparator(com.liferay.portal.kernel.util.OrderByComparator)

Example 2 with KBArticleVersionComparator

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);
    }
}
Also used : KBArticle(com.liferay.knowledgebase.model.KBArticle) KBArticleVersionComparator(com.liferay.knowledgebase.util.comparator.KBArticleVersionComparator) JSONObject(com.liferay.portal.kernel.json.JSONObject)

Example 3 with KBArticleVersionComparator

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));
        }
    };
}
Also used : KBArticleVersionComparator(com.liferay.knowledgebase.util.comparator.KBArticleVersionComparator) DynamicQuery(com.liferay.portal.kernel.dao.orm.DynamicQuery) KBTemplateExportActionableDynamicQuery(com.liferay.knowledgebase.service.persistence.KBTemplateExportActionableDynamicQuery) KBArticleExportActionableDynamicQuery(com.liferay.knowledgebase.service.persistence.KBArticleExportActionableDynamicQuery) KBCommentExportActionableDynamicQuery(com.liferay.knowledgebase.service.persistence.KBCommentExportActionableDynamicQuery) ActionableDynamicQuery(com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery) KBArticleExportActionableDynamicQuery(com.liferay.knowledgebase.service.persistence.KBArticleExportActionableDynamicQuery)

Aggregations

KBArticleVersionComparator (com.liferay.knowledgebase.util.comparator.KBArticleVersionComparator)3 KBArticle (com.liferay.knowledgebase.model.KBArticle)2 KBArticleExportActionableDynamicQuery (com.liferay.knowledgebase.service.persistence.KBArticleExportActionableDynamicQuery)1 KBCommentExportActionableDynamicQuery (com.liferay.knowledgebase.service.persistence.KBCommentExportActionableDynamicQuery)1 KBTemplateExportActionableDynamicQuery (com.liferay.knowledgebase.service.persistence.KBTemplateExportActionableDynamicQuery)1 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)1 DynamicQuery (com.liferay.portal.kernel.dao.orm.DynamicQuery)1 JSONObject (com.liferay.portal.kernel.json.JSONObject)1 OrderByComparator (com.liferay.portal.kernel.util.OrderByComparator)1