Search in sources :

Example 1 with KBComment

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

the class KBCommentStagedModelDataHandler method doImportStagedModel.

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, KBComment kbComment) throws Exception {
    long userId = portletDataContext.getUserId(kbComment.getUserUuid());
    Map<Long, Long> relatedClassPKs = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(kbComment.getClassName());
    long newClassPK = MapUtil.getLong(relatedClassPKs, kbComment.getClassPK(), kbComment.getClassPK());
    ServiceContext serviceContext = portletDataContext.createServiceContext(kbComment);
    KBComment importedKBComment = null;
    if (portletDataContext.isDataStrategyMirror()) {
        KBComment existingKBComment = KBCommentUtil.fetchByUUID_G(kbComment.getUuid(), portletDataContext.getScopeGroupId());
        if (existingKBComment == null) {
            serviceContext.setUuid(kbComment.getUuid());
            importedKBComment = KBCommentLocalServiceUtil.addKBComment(userId, kbComment.getClassNameId(), newClassPK, kbComment.getContent(), kbComment.getUserRating(), serviceContext);
        } else {
            importedKBComment = KBCommentLocalServiceUtil.updateKBComment(existingKBComment.getKbCommentId(), kbComment.getClassNameId(), newClassPK, kbComment.getContent(), kbComment.getUserRating(), kbComment.getStatus(), serviceContext);
        }
    } else {
        importedKBComment = KBCommentLocalServiceUtil.addKBComment(userId, kbComment.getClassNameId(), newClassPK, kbComment.getContent(), kbComment.getUserRating(), serviceContext);
    }
    portletDataContext.importClassedModel(kbComment, importedKBComment);
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment) ServiceContext(com.liferay.portal.service.ServiceContext) Map(java.util.Map)

Example 2 with KBComment

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

the class AdminActivityInterpreter method getEntryTitle.

@Override
protected String getEntryTitle(SocialActivity activity, ServiceContext serviceContext) throws Exception {
    String title = StringPool.BLANK;
    String className = activity.getClassName();
    if (className.equals(KBArticle.class.getName())) {
        KBArticle kbArticle = KBArticleLocalServiceUtil.getLatestKBArticle(activity.getClassPK(), WorkflowConstants.STATUS_APPROVED);
        title = kbArticle.getTitle();
    } else if (className.equals(KBComment.class.getName())) {
        KBComment kbComment = KBCommentLocalServiceUtil.getKBComment(activity.getClassPK());
        String kbCommentClassName = kbComment.getClassName();
        if (kbCommentClassName.equals(KBArticle.class.getName())) {
            KBArticle kbArticle = KBArticleLocalServiceUtil.getLatestKBArticle(kbComment.getClassPK(), WorkflowConstants.STATUS_APPROVED);
            title = kbArticle.getTitle();
        } else if (kbCommentClassName.equals(KBTemplate.class.getName())) {
            KBTemplate kbTemplate = KBTemplateLocalServiceUtil.getKBTemplate(kbComment.getClassPK());
            title = kbTemplate.getTitle();
        }
    } else if (className.equals(KBTemplate.class.getName())) {
        KBTemplate kbTemplate = KBTemplateLocalServiceUtil.getKBTemplate(activity.getClassPK());
        title = kbTemplate.getTitle();
    }
    return getJSONValue(activity.getExtraData(), "title", title);
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment) KBArticle(com.liferay.knowledgebase.model.KBArticle) KBTemplate(com.liferay.knowledgebase.model.KBTemplate)

Example 3 with KBComment

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

the class KBCommentModifiedDateComparator method compare.

@Override
public int compare(Object obj1, Object obj2) {
    KBComment kbComment1 = (KBComment) obj1;
    KBComment kbComment2 = (KBComment) obj2;
    int value = DateUtil.compareTo(kbComment1.getModifiedDate(), kbComment2.getModifiedDate());
    if (_ascending) {
        return value;
    } else {
        return -value;
    }
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment)

Example 4 with KBComment

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

the class KBCommentPersistenceImpl method findByG_S_Last.

/**
 * Returns the last k b comment in the ordered set where groupId = &#63; and status = &#63;.
 *
 * @param groupId the group ID
 * @param status the status
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the last matching k b comment
 * @throws com.liferay.knowledgebase.NoSuchCommentException if a matching k b comment could not be found
 * @throws SystemException if a system exception occurred
 */
@Override
public KBComment findByG_S_Last(long groupId, int status, OrderByComparator orderByComparator) throws NoSuchCommentException, SystemException {
    KBComment kbComment = fetchByG_S_Last(groupId, status, orderByComparator);
    if (kbComment != null) {
        return kbComment;
    }
    StringBundler msg = new StringBundler(6);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("groupId=");
    msg.append(groupId);
    msg.append(", status=");
    msg.append(status);
    msg.append(StringPool.CLOSE_CURLY_BRACE);
    throw new NoSuchCommentException(msg.toString());
}
Also used : KBComment(com.liferay.knowledgebase.model.KBComment) NoSuchCommentException(com.liferay.knowledgebase.NoSuchCommentException) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 5 with KBComment

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

the class KBCommentPersistenceImpl method findByC_C_S.

/**
 * Returns an ordered range of all the k b comments where classNameId = &#63; and classPK = &#63; and status = any &#63;.
 *
 * <p>
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.knowledgebase.model.impl.KBCommentModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param classNameId the class name ID
 * @param classPK the class p k
 * @param statuses the statuses
 * @param start the lower bound of the range of k b comments
 * @param end the upper bound of the range of k b comments (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @return the ordered range of matching k b comments
 * @throws SystemException if a system exception occurred
 */
@Override
public List<KBComment> findByC_C_S(long classNameId, long classPK, int[] statuses, int start, int end, OrderByComparator orderByComparator) throws SystemException {
    if ((statuses != null) && (statuses.length == 1)) {
        return findByC_C_S(classNameId, classPK, statuses[0], start, end, orderByComparator);
    }
    boolean pagination = true;
    Object[] finderArgs = null;
    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderArgs = new Object[] { classNameId, classPK, StringUtil.merge(statuses) };
    } else {
        finderArgs = new Object[] { classNameId, classPK, StringUtil.merge(statuses), start, end, orderByComparator };
    }
    List<KBComment> list = (List<KBComment>) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S, finderArgs, this);
    if ((list != null) && !list.isEmpty()) {
        for (KBComment kbComment : list) {
            if ((classNameId != kbComment.getClassNameId()) || (classPK != kbComment.getClassPK()) || !ArrayUtil.contains(statuses, kbComment.getStatus())) {
                list = null;
                break;
            }
        }
    }
    if (list == null) {
        StringBundler query = new StringBundler();
        query.append(_SQL_SELECT_KBCOMMENT_WHERE);
        boolean conjunctionable = false;
        if (conjunctionable) {
            query.append(WHERE_AND);
        }
        query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_5);
        conjunctionable = true;
        if (conjunctionable) {
            query.append(WHERE_AND);
        }
        query.append(_FINDER_COLUMN_C_C_S_CLASSPK_5);
        conjunctionable = true;
        if ((statuses == null) || (statuses.length > 0)) {
            if (conjunctionable) {
                query.append(WHERE_AND);
            }
            query.append(StringPool.OPEN_PARENTHESIS);
            for (int i = 0; i < statuses.length; i++) {
                query.append(_FINDER_COLUMN_C_C_S_STATUS_5);
                if ((i + 1) < statuses.length) {
                    query.append(WHERE_OR);
                }
            }
            query.append(StringPool.CLOSE_PARENTHESIS);
            conjunctionable = true;
        }
        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(KBCommentModelImpl.ORDER_BY_JPQL);
        }
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            qPos.add(classNameId);
            qPos.add(classPK);
            if (statuses != null) {
                qPos.add(statuses);
            }
            if (!pagination) {
                list = (List<KBComment>) QueryUtil.list(q, getDialect(), start, end, false);
                Collections.sort(list);
                list = new UnmodifiableList<KBComment>(list);
            } else {
                list = (List<KBComment>) QueryUtil.list(q, getDialect(), start, end);
            }
            cacheResult(list);
            FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S, finderArgs, list);
        } catch (Exception e) {
            FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return list;
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) StringBundler(com.liferay.portal.kernel.util.StringBundler) SystemException(com.liferay.portal.kernel.exception.SystemException) NoSuchCommentException(com.liferay.knowledgebase.NoSuchCommentException) KBComment(com.liferay.knowledgebase.model.KBComment) ArrayList(java.util.ArrayList) UnmodifiableList(com.liferay.portal.kernel.util.UnmodifiableList) List(java.util.List) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) Session(com.liferay.portal.kernel.dao.orm.Session)

Aggregations

KBComment (com.liferay.knowledgebase.model.KBComment)60 NoSuchCommentException (com.liferay.knowledgebase.NoSuchCommentException)38 StringBundler (com.liferay.portal.kernel.util.StringBundler)36 Session (com.liferay.portal.kernel.dao.orm.Session)21 SystemException (com.liferay.portal.kernel.exception.SystemException)21 Query (com.liferay.portal.kernel.dao.orm.Query)19 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)18 KBCommentImpl (com.liferay.knowledgebase.model.impl.KBCommentImpl)11 UnmodifiableList (com.liferay.portal.kernel.util.UnmodifiableList)11 ArrayList (java.util.ArrayList)11 List (java.util.List)11 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)9 JSONObject (com.liferay.portal.kernel.json.JSONObject)2 ServiceContext (com.liferay.portal.service.ServiceContext)2 KBArticle (com.liferay.knowledgebase.model.KBArticle)1 KBTemplate (com.liferay.knowledgebase.model.KBTemplate)1 User (com.liferay.portal.model.User)1 ThemeDisplay (com.liferay.portal.theme.ThemeDisplay)1 Date (java.util.Date)1 Map (java.util.Map)1