use of org.olat.core.commons.services.commentAndRating.model.UserCommentImpl in project OpenOLAT by OpenOLAT.
the class UserCommentsDAO method deleteAllComments.
/**
* @see org.olat.core.commons.services.commentAndRating.UserCommentsManager#deleteAllComments()
*/
public int deleteAllComments(OLATResourceable ores, String resSubPath) {
EntityManager em = dbInstance.getCurrentEntityManager();
// special query when sub path is null
List<UserCommentImpl> comments;
if (resSubPath == null) {
StringBuilder sb = new StringBuilder();
sb.append("select comment from usercomment comment").append(" where resName=:resName and resId=:resId and resSubPath is null").append(" order by creationDate desc");
comments = em.createQuery(sb.toString(), UserCommentImpl.class).setParameter("resName", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId()).getResultList();
} else {
StringBuilder sb = new StringBuilder();
sb.append("select comment from usercomment comment").append(" where resName=:resName and resId=:resId and resSubPath=:resSubPath").append(" order by creationDate desc");
comments = em.createQuery(sb.toString(), UserCommentImpl.class).setParameter("resName", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId()).setParameter("resSubPath", resSubPath).getResultList();
}
if (comments != null && !comments.isEmpty()) {
for (UserCommentImpl comment : comments) {
em.remove(comment);
}
}
updateDelegateRatings(ores, resSubPath);
return comments == null ? 0 : comments.size();
}
use of org.olat.core.commons.services.commentAndRating.model.UserCommentImpl in project OpenOLAT by OpenOLAT.
the class UserCommentsDAO method deleteAllCommentsIgnoringSubPath.
/**
* Don't limit to subpath. Ignore if null or not, just delete on the resource
* @see org.olat.core.commons.services.commentAndRating.UserCommentsManager#deleteAllCommentsIgnoringSubPath()
*/
public int deleteAllCommentsIgnoringSubPath(OLATResourceable ores) {
EntityManager em = dbInstance.getCurrentEntityManager();
StringBuilder sb = new StringBuilder();
sb.append("select comment from usercomment comment").append(" where resName=:resName and resId=:resId").append(" order by creationDate desc");
List<UserCommentImpl> comments = em.createQuery(sb.toString(), UserCommentImpl.class).setParameter("resName", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId()).getResultList();
for (UserCommentImpl comment : comments) {
em.remove(comment);
}
updateDelegateRatings(ores, null);
return comments.size();
}
use of org.olat.core.commons.services.commentAndRating.model.UserCommentImpl in project openolat by klemens.
the class UserCommentsDAO method deleteAllCommentsIgnoringSubPath.
/**
* Don't limit to subpath. Ignore if null or not, just delete on the resource
* @see org.olat.core.commons.services.commentAndRating.UserCommentsManager#deleteAllCommentsIgnoringSubPath()
*/
public int deleteAllCommentsIgnoringSubPath(OLATResourceable ores) {
EntityManager em = dbInstance.getCurrentEntityManager();
StringBuilder sb = new StringBuilder();
sb.append("select comment from usercomment comment").append(" where resName=:resName and resId=:resId").append(" order by creationDate desc");
List<UserCommentImpl> comments = em.createQuery(sb.toString(), UserCommentImpl.class).setParameter("resName", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId()).getResultList();
for (UserCommentImpl comment : comments) {
em.remove(comment);
}
updateDelegateRatings(ores, null);
return comments.size();
}
use of org.olat.core.commons.services.commentAndRating.model.UserCommentImpl in project OpenOLAT by OpenOLAT.
the class UserCommentsDAO method createComment.
public UserComment createComment(Identity creator, OLATResourceable ores, String resSubPath, String commentText) {
UserComment comment = new UserCommentImpl(ores, resSubPath, creator, commentText);
dbInstance.getCurrentEntityManager().persist(comment);
updateDelegateRatings(ores, resSubPath);
// do Logging
ThreadLocalUserActivityLogger.log(CommentAndRatingLoggingAction.COMMENT_CREATED, getClass(), CoreLoggingResourceable.wrap(ores, OlatResourceableType.feedItem));
return comment;
}
use of org.olat.core.commons.services.commentAndRating.model.UserCommentImpl in project OpenOLAT by OpenOLAT.
the class UserCommentsDAO method replyTo.
public UserComment replyTo(UserComment originalComment, Identity creator, String replyCommentText) {
// First reload parent from cache to prevent stale object or cache issues
originalComment = reloadComment(originalComment);
if (originalComment == null) {
// Original comment has been deleted in the meantime. Don't create a reply
return null;
}
OLATResourceable ores = OresHelper.createOLATResourceableInstance(originalComment.getResName(), originalComment.getResId());
UserCommentImpl reply = new UserCommentImpl(ores, originalComment.getResSubPath(), creator, replyCommentText);
reply.setParent(originalComment);
dbInstance.getCurrentEntityManager().persist(reply);
updateDelegateRatings(ores, originalComment.getResSubPath());
return reply;
}
Aggregations