Search in sources :

Example 6 with UserComment

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

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 7 with UserComment

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

the class OLATUpgrade_7_1_1 method mergeCommentsToFinalStruct.

private void mergeCommentsToFinalStruct(PortfolioStructure finalStruct, List<PortfolioStructure> wrongStructs) {
    if (wrongStructs == null || wrongStructs.isEmpty())
        return;
    List<UserComment> collectedComments = new ArrayList<UserComment>();
    // collect all comments out there
    for (PortfolioStructure portfolioStructure : wrongStructs) {
        // no comments on StructureElements!
        if (!(portfolioStructure instanceof EPPage))
            return;
        List<UserComment> oldComments = commentAndRatingService.getComments(portfolioStructure.getRootMap(), portfolioStructure.getKey().toString());
        collectedComments.addAll(oldComments);
        commentAndRatingService.deleteAllComments(portfolioStructure.getRootMap(), portfolioStructure.getKey().toString());
    }
    log.audit("       found " + collectedComments.size() + " comments for this structure, will be merged to new destination.");
    if (collectedComments.size() == 0)
        return;
    Identity ident = collectedComments.get(0).getCreator();
    UserComment topComment = commentAndRatingService.createComment(ident, finalStruct.getRootMap(), finalStruct.getKey().toString(), "The following comments were restored from a migration task to rescue lost data.");
    // attach all to this info-comment
    for (UserComment userComment : collectedComments) {
        UserComment attachedComment = commentAndRatingService.replyTo(topComment, userComment.getCreator(), userComment.getComment());
        // set original date
        attachedComment.setCreationDate(userComment.getCreationDate());
        commentAndRatingService.updateComment(attachedComment, attachedComment.getComment());
    }
}
Also used : EPPage(org.olat.portfolio.model.structel.EPPage) UserComment(org.olat.core.commons.services.commentAndRating.model.UserComment) ArrayList(java.util.ArrayList) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) Identity(org.olat.core.id.Identity)

Example 8 with UserComment

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

the class UserCommentDisplayController method buildReplyComments.

/**
 * Internal helper to build the view controller for the replies
 * @param ureq
 */
private void buildReplyComments(UserRequest ureq) {
    // First remove all old replies
    for (Controller replyController : replyControllers) {
        removeAsListenerAndDispose(replyController);
    }
    replyControllers.clear();
    // Build replies again
    for (UserComment reply : allComments) {
        if (reply.getParent() == null)
            continue;
        if (reply.getParent().getKey().equals(userComment.getKey())) {
            // Create child controller
            UserCommentDisplayController replyCtr = new UserCommentDisplayController(ureq, getWindowControl(), reply, allComments, ores, resSubPath, securityCallback);
            replyControllers.add(replyCtr);
            listenTo(replyCtr);
            userCommentDisplayVC.put(replyCtr.getViewCompName(), replyCtr.getInitialComponent());
        }
    }
}
Also used : UserComment(org.olat.core.commons.services.commentAndRating.model.UserComment) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) DialogBoxController(org.olat.core.gui.control.generic.modal.DialogBoxController) TitledWrapperController(org.olat.core.gui.control.generic.title.TitledWrapperController) Controller(org.olat.core.gui.control.Controller) BasicController(org.olat.core.gui.control.controller.BasicController)

Example 9 with UserComment

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

the class UserCommentDisplayController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.components.Component,
 *      org.olat.core.gui.control.Event)
 */
@Override
protected void event(UserRequest ureq, Component source, Event event) {
    if (source == replyLink) {
        // Init reply workflow
        replyCommentFormCtr = new UserCommentFormController(ureq, getWindowControl(), userComment, null, ores, resSubPath);
        listenTo(replyCommentFormCtr);
        User parentUser = userComment.getCreator().getUser();
        String title = translate("comments.coment.reply.title", new String[] { parentUser.getProperty(UserConstants.FIRSTNAME, null), parentUser.getProperty(UserConstants.LASTNAME, null) });
        TitleInfo titleInfo = new TitleInfo(null, title);
        replyTitledWrapperCtr = new TitledWrapperController(ureq, getWindowControl(), replyCommentFormCtr, null, titleInfo);
        listenTo(replyTitledWrapperCtr);
        replyCmc = new CloseableModalController(getWindowControl(), "close", replyTitledWrapperCtr.getInitialComponent());
        replyCmc.activate();
    } else if (source == deleteLink) {
        // Init delete workflow
        List<String> buttonLabels = new ArrayList<String>();
        boolean hasReplies = false;
        for (UserComment comment : allComments) {
            if (comment.getParent() != null && comment.getParent().getKey().equals(userComment.getKey())) {
                hasReplies = true;
                break;
            }
        }
        if (hasReplies) {
            buttonLabels.add(translate("comments.button.delete.without.replies"));
            buttonLabels.add(translate("comments.button.delete.with.replies"));
        } else {
            buttonLabels.add(translate("delete"));
        }
        buttonLabels.add(translate("cancel"));
        String deleteText;
        if (hasReplies) {
            deleteText = translate("comments.dialog.delete.with.replies");
        } else {
            deleteText = translate("comments.dialog.delete");
        }
        deleteDialogCtr = DialogBoxUIFactory.createGenericDialog(ureq, getWindowControl(), translate("comments.dialog.delete.title"), deleteText, buttonLabels);
        listenTo(deleteDialogCtr);
        deleteDialogCtr.activate();
        // Add replies info as user object to retrieve it later when evaluating the events
        deleteDialogCtr.setUserObject(Boolean.valueOf(hasReplies));
    }
}
Also used : User(org.olat.core.id.User) TitledWrapperController(org.olat.core.gui.control.generic.title.TitledWrapperController) UserComment(org.olat.core.commons.services.commentAndRating.model.UserComment) TitleInfo(org.olat.core.gui.control.generic.title.TitleInfo) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) ArrayList(java.util.ArrayList) List(java.util.List)

Example 10 with UserComment

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

the class UserCommentsController method buildTopLevelComments.

/**
 * Internal helper to build the view controller for the direct comments
 * (without replies)
 *
 * @param ureq
 * @param initDatamodel true: load datamodel from database; false: just rebuild GUI with existing datamodel
 */
private void buildTopLevelComments(UserRequest ureq, boolean initDatamodel) {
    // First remove all old replies
    for (Controller commentController : commentControllers) {
        removeAsListenerAndDispose(commentController);
    }
    commentControllers.clear();
    if (initDatamodel) {
        allComments = commentAndRatingService.getComments(ores, resSubPath);
    }
    // Build replies again
    for (UserComment comment : allComments) {
        if (comment.getParent() == null) {
            // Create top level comment controller
            UserCommentDisplayController commentController = new UserCommentDisplayController(ureq, getWindowControl(), comment, allComments, ores, resSubPath, securityCallback);
            commentControllers.add(commentController);
            listenTo(commentController);
            userCommentsVC.put(commentController.getViewCompName(), commentController.getInitialComponent());
        }
    }
}
Also used : UserComment(org.olat.core.commons.services.commentAndRating.model.UserComment) Controller(org.olat.core.gui.control.Controller) BasicController(org.olat.core.gui.control.controller.BasicController)

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