Search in sources :

Example 11 with UserComment

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;
}
Also used : UserComment(org.olat.core.commons.services.commentAndRating.model.UserComment)

Example 12 with UserComment

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;
}
Also used : UserComment(org.olat.core.commons.services.commentAndRating.model.UserComment)

Example 13 with UserComment

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));
            }
        }
    }
}
Also used : SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) UserComment(org.olat.core.commons.services.commentAndRating.model.UserComment) Date(java.util.Date)

Example 14 with UserComment

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"));
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) UserComment(org.olat.core.commons.services.commentAndRating.model.UserComment) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

Example 15 with UserComment

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;
}
Also used : UserComment(org.olat.core.commons.services.commentAndRating.model.UserComment) UserCommentImpl(org.olat.core.commons.services.commentAndRating.model.UserCommentImpl)

Aggregations

UserComment (org.olat.core.commons.services.commentAndRating.model.UserComment)24 ArrayList (java.util.ArrayList)4 Controller (org.olat.core.gui.control.Controller)4 BasicController (org.olat.core.gui.control.controller.BasicController)4 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)4 TitledWrapperController (org.olat.core.gui.control.generic.title.TitledWrapperController)4 Identity (org.olat.core.id.Identity)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 Date (java.util.Date)2 List (java.util.List)2 Test (org.junit.Test)2 UserCommentImpl (org.olat.core.commons.services.commentAndRating.model.UserCommentImpl)2 SubscriptionListItem (org.olat.core.commons.services.notifications.model.SubscriptionListItem)2 DialogBoxController (org.olat.core.gui.control.generic.modal.DialogBoxController)2 TitleInfo (org.olat.core.gui.control.generic.title.TitleInfo)2 User (org.olat.core.id.User)2 EPPage (org.olat.portfolio.model.structel.EPPage)2 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)2