Search in sources :

Example 1 with UserCommentsCountImpl

use of org.olat.core.commons.services.commentAndRating.model.UserCommentsCountImpl in project OpenOLAT by OpenOLAT.

the class UserCommentsDAO method countCommentsWithSubPath.

public List<UserCommentsCount> countCommentsWithSubPath(OLATResourceable ores, String resSubPath) {
    if (resSubPath != null) {
        UserCommentsCount count = new UserCommentsCountImpl(ores, resSubPath, countComments(ores, resSubPath));
        return Collections.singletonList(count);
    }
    StringBuilder sb = new StringBuilder();
    sb.append("select comment.resSubPath, count(comment.key) from usercomment as comment ").append(" where comment.resName=:resname AND comment.resId=:resId").append(" group by comment.resSubPath");
    List<Object[]> counts = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("resname", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId()).getResultList();
    Set<String> countMap = new HashSet<String>();
    List<UserCommentsCount> countList = new ArrayList<UserCommentsCount>();
    for (Object[] count : counts) {
        Object subPath = count[0] == null ? "" : count[0];
        if (!countMap.contains(subPath)) {
            UserCommentsCount c = new UserCommentsCountImpl(ores, (String) count[0], (Long) count[1]);
            countList.add(c);
        }
    }
    return countList;
}
Also used : UserCommentsCountImpl(org.olat.core.commons.services.commentAndRating.model.UserCommentsCountImpl) ArrayList(java.util.ArrayList) UserCommentsCount(org.olat.core.commons.services.commentAndRating.model.UserCommentsCount) HashSet(java.util.HashSet)

Example 2 with UserCommentsCountImpl

use of org.olat.core.commons.services.commentAndRating.model.UserCommentsCountImpl in project openolat by klemens.

the class UserCommentsDAO method countCommentsWithSubPath.

public List<UserCommentsCount> countCommentsWithSubPath(OLATResourceable ores, String resSubPath) {
    if (resSubPath != null) {
        UserCommentsCount count = new UserCommentsCountImpl(ores, resSubPath, countComments(ores, resSubPath));
        return Collections.singletonList(count);
    }
    StringBuilder sb = new StringBuilder();
    sb.append("select comment.resSubPath, count(comment.key) from usercomment as comment ").append(" where comment.resName=:resname AND comment.resId=:resId").append(" group by comment.resSubPath");
    List<Object[]> counts = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("resname", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId()).getResultList();
    Set<String> countMap = new HashSet<String>();
    List<UserCommentsCount> countList = new ArrayList<UserCommentsCount>();
    for (Object[] count : counts) {
        Object subPath = count[0] == null ? "" : count[0];
        if (!countMap.contains(subPath)) {
            UserCommentsCount c = new UserCommentsCountImpl(ores, (String) count[0], (Long) count[1]);
            countList.add(c);
        }
    }
    return countList;
}
Also used : UserCommentsCountImpl(org.olat.core.commons.services.commentAndRating.model.UserCommentsCountImpl) ArrayList(java.util.ArrayList) UserCommentsCount(org.olat.core.commons.services.commentAndRating.model.UserCommentsCount) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 UserCommentsCount (org.olat.core.commons.services.commentAndRating.model.UserCommentsCount)2 UserCommentsCountImpl (org.olat.core.commons.services.commentAndRating.model.UserCommentsCountImpl)2