use of org.olat.core.commons.services.commentAndRating.model.UserComment in project openolat by klemens.
the class CommentAndRatingServiceImpl method replyTo.
@Override
public UserComment replyTo(UserComment originalComment, Identity creator, String replyCommentText) {
UserComment reply = userCommentsDao.replyTo(originalComment, creator, replyCommentText);
markPublisherNews(reply);
return reply;
}
use of org.olat.core.commons.services.commentAndRating.model.UserComment in project openolat by klemens.
the class CommentAndRatingServiceImpl method updateComment.
@Override
public UserComment updateComment(UserComment comment, String newCommentText) {
UserComment updatedComment = userCommentsDao.updateComment(comment, newCommentText);
markPublisherNews(updatedComment);
return updatedComment;
}
use of org.olat.core.commons.services.commentAndRating.model.UserComment in project OpenOLAT by OpenOLAT.
the class FeedNotificationsHandler method appendSubscriptionItem.
private void appendSubscriptionItem(Item item, Publisher p, Date compareDate, Translator translator, List<SubscriptionListItem> items) {
String title = item.getTitle();
String author = item.getAuthor();
String businessPath = p.getBusinessPath();
String urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
String iconCssClass = item.extraCSSClass();
Date publishDate = item.getPublishDate();
if (publishDate != null) {
if (compareDate.before(publishDate)) {
String desc = translator.translate("notifications.entry.published", new String[] { title, author });
items.add(new SubscriptionListItem(desc, urlToSend, businessPath, publishDate, iconCssClass));
}
// modified date.
if (item.getModifierKey() != null || (item.getFeed().isExternal() && !item.getCreationDate().equals(item.getLastModified()) && item.getPublishDate().before(item.getLastModified()))) {
Date modDate = item.getLastModified();
if (compareDate.before(modDate)) {
String desc;
String modifier = item.getModifier();
if (StringHelper.containsNonWhitespace(modifier)) {
desc = translator.translate("notifications.entry.modified", new String[] { title, modifier });
} else {
desc = translator.translate("notifications.entry.modified", new String[] { title, "???" });
}
items.add(new SubscriptionListItem(desc, urlToSend, businessPath, modDate, iconCssClass));
}
}
List<UserComment> comments = commentAndRatingService.getComments(item.getFeed(), item.getGuid());
for (UserComment comment : comments) {
if (compareDate.before(comment.getCreationDate())) {
String desc;
String modifier = UserManager.getInstance().getUserDisplayName(comment.getCreator().getKey());
if (StringHelper.containsNonWhitespace(modifier)) {
desc = translator.translate("notifications.entry.commented", new String[] { title, modifier });
} else {
desc = translator.translate("notifications.entry.commented", new String[] { title, "???" });
}
items.add(new SubscriptionListItem(desc, urlToSend, businessPath, comment.getCreationDate(), iconCssClass));
}
}
}
}
use of org.olat.core.commons.services.commentAndRating.model.UserComment in project OpenOLAT by OpenOLAT.
the class UserCommentsDAOTest method testCRUDComment.
@Test
public void testCRUDComment() {
// init
OLATResourceable ores = JunitTestHelper.createRandomResource();
Identity ident1 = JunitTestHelper.createAndPersistIdentityAsUser("ucar-crud-1-" + UUID.randomUUID().toString());
Identity ident2 = JunitTestHelper.createAndPersistIdentityAsUser("ucar-crud-2-" + UUID.randomUUID().toString());
// check if there is any comments
assertEquals(0, userCommentsDao.countComments(ores, null));
assertEquals(0, userCommentsDao.countComments(ores, "blubli"));
// add comments
UserComment comment1 = userCommentsDao.createComment(ident1, ores, null, "Hello World");
UserComment comment2 = userCommentsDao.createComment(ident1, ores, "blubli", "Hello World with subpath");
// count must be 1 now. count without subpath should not include the results with subpath
assertEquals(1, userCommentsDao.countComments(ores, null));
assertEquals(1, userCommentsDao.countComments(ores, "blubli"));
//
UserComment comment3 = userCommentsDao.createComment(ident2, ores, null, "Hello World");
Assert.assertNotNull(comment3);
UserComment comment4 = userCommentsDao.createComment(ident2, ores, "blubli", "Hello World with subpath");
Assert.assertNotNull(comment4);
Assert.assertEquals(2, userCommentsDao.countComments(ores, null));
Assert.assertEquals(2, userCommentsDao.countComments(ores, "blubli"));
// Same with get method
List<UserComment> commentList = userCommentsDao.getComments(ores, null);
assertEquals(2, commentList.size());
List<UserComment> commentList2 = userCommentsDao.getComments(ores, "blubli");
assertEquals(2, commentList2.size());
// Create a reply to the first comments
userCommentsDao.replyTo(comment1, ident2, "Reply 1");
userCommentsDao.replyTo(comment2, ident2, "Reply 1 with subpath");
Assert.assertEquals(3, userCommentsDao.countComments(ores, null));
Assert.assertEquals(3, userCommentsDao.countComments(ores, "blubli"));
// Delete first created coment with one reply each
userCommentsDao.deleteComment(comment1, true);
userCommentsDao.deleteComment(comment2, true);
Assert.assertEquals(1, userCommentsDao.countComments(ores, null));
Assert.assertEquals(1, userCommentsDao.countComments(ores, "blubli"));
// Create reply to a comment that does not exis anymore -> should not create anything
Assert.assertNull(userCommentsDao.replyTo(comment1, ident2, "Reply 1"));
Assert.assertNull(userCommentsDao.replyTo(comment2, ident2, "Reply 1 with subpath"));
// Recreate first comment
comment1 = userCommentsDao.createComment(ident1, ores, null, "Hello World");
comment2 = userCommentsDao.createComment(ident1, ores, "blubli", "Hello World with subpath");
// Recreate a reply to the first comments
userCommentsDao.replyTo(comment1, ident2, "Reply 1");
userCommentsDao.replyTo(comment2, ident2, "Reply 1 with subpath");
assertEquals(3, userCommentsDao.countComments(ores, null));
assertEquals(3, userCommentsDao.countComments(ores, "blubli"));
// Delete first created coment without the reply
userCommentsDao.deleteComment(comment1, false);
userCommentsDao.deleteComment(comment2, false);
assertEquals(2, userCommentsDao.countComments(ores, null));
assertEquals(2, userCommentsDao.countComments(ores, "blubli"));
// Delete all comments without subpath
assertEquals(2, userCommentsDao.deleteAllComments(ores, null));
assertEquals(0, userCommentsDao.countComments(ores, null));
assertEquals(2, userCommentsDao.countComments(ores, "blubli"));
// add a comment without subpath
comment1 = userCommentsDao.createComment(ident1, ores, null, "Hello World");
// Delete all comments with subpath
assertEquals(2, userCommentsDao.deleteAllComments(ores, "blubli"));
assertEquals(1, userCommentsDao.countComments(ores, null));
assertEquals(0, userCommentsDao.countComments(ores, "blubli"));
// add a comment with subpath
comment2 = userCommentsDao.createComment(ident2, ores, "blubli", "Hello World with subpath 2");
// Delete ignoring subpath
assertEquals(1, userCommentsDao.countComments(ores, null));
assertEquals(1, userCommentsDao.countComments(ores, "blubli"));
assertEquals(2, userCommentsDao.deleteAllCommentsIgnoringSubPath(ores));
assertEquals(0, userCommentsDao.countComments(ores, null));
assertEquals(0, userCommentsDao.countComments(ores, "blubli"));
}
use of org.olat.core.commons.services.commentAndRating.model.UserComment 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;
}
Aggregations