Search in sources :

Example 1 with UserComment

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

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

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

the class UserCommentDisplayController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
 *      org.olat.core.gui.control.Controller,
 *      org.olat.core.gui.control.Event)
 */
protected void event(UserRequest ureq, Controller source, Event event) {
    if (source == deleteDialogCtr) {
        boolean hasReplies = ((Boolean) deleteDialogCtr.getUserObject()).booleanValue();
        if (DialogBoxUIFactory.isClosedEvent(event)) {
        // Nothing to do
        } else {
            int buttonPos = DialogBoxUIFactory.getButtonPos(event);
            if (buttonPos == 0) {
                // Do delete
                commentAndRatingService.deleteComment(userComment, false);
                allComments.remove(userComment);
                fireEvent(ureq, DELETED_EVENT);
                // Inform top level view that it needs to rebuild due to comments that are now unlinked
                if (hasReplies) {
                    fireEvent(ureq, COMMENT_DATAMODEL_DIRTY);
                }
            } else if (buttonPos == 1 && hasReplies) {
                // Delete current comment and all replies. Notify parent, probably needs full redraw
                commentAndRatingService.deleteComment(userComment, true);
                allComments.remove(userComment);
                fireEvent(ureq, DELETED_EVENT);
            } else if (buttonPos == 1 && !hasReplies) {
            // Nothing to do, cancel button
            }
        }
        // Cleanup delete dialog
        removeAsListenerAndDispose(deleteDialogCtr);
        deleteDialogCtr = null;
    } else if (source == replyCmc) {
        // User closed modal dialog (cancel)
        removeAsListenerAndDispose(replyCmc);
        replyCmc = null;
        removeAsListenerAndDispose(replyCommentFormCtr);
        replyCommentFormCtr = null;
        removeAsListenerAndDispose(replyTitledWrapperCtr);
        replyTitledWrapperCtr = null;
    } else if (source == replyCommentFormCtr) {
        // User Saved or canceled form
        replyCmc.deactivate();
        if (event == Event.CHANGED_EVENT) {
            // Update view
            UserComment newReply = replyCommentFormCtr.getComment();
            allComments.add(newReply);
            // Create child controller
            UserCommentDisplayController replyCtr = new UserCommentDisplayController(ureq, getWindowControl(), newReply, allComments, ores, resSubPath, securityCallback);
            replyControllers.add(replyCtr);
            listenTo(replyCtr);
            userCommentDisplayVC.put(replyCtr.getViewCompName(), replyCtr.getInitialComponent());
            // notify parent
            fireEvent(ureq, COMMENT_COUNT_CHANGED);
        } else if (event == Event.FAILED_EVENT) {
            // Reply failed - reload everything
            fireEvent(ureq, COMMENT_DATAMODEL_DIRTY);
        }
        removeAsListenerAndDispose(replyCmc);
        replyCmc = null;
        removeAsListenerAndDispose(replyCommentFormCtr);
        replyCommentFormCtr = null;
        removeAsListenerAndDispose(replyTitledWrapperCtr);
        replyTitledWrapperCtr = null;
    } else if (source instanceof UserCommentDisplayController) {
        UserCommentDisplayController replyCtr = (UserCommentDisplayController) source;
        if (event == DELETED_EVENT) {
            // Remove comment from view and re-render.
            replyControllers.remove(replyCtr);
            userCommentDisplayVC.remove(replyCtr.getInitialComponent());
            removeAsListenerAndDispose(replyCtr);
            // Notify parent about this - probably needs complete reload of data model
            fireEvent(ureq, COMMENT_COUNT_CHANGED);
        } else if (event == COMMENT_COUNT_CHANGED || event == COMMENT_DATAMODEL_DIRTY) {
            // Forward to parent, nothing to do here
            fireEvent(ureq, event);
        }
    }
}
Also used : UserComment(org.olat.core.commons.services.commentAndRating.model.UserComment)

Example 3 with UserComment

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

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)

Example 4 with UserComment

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

the class UserCommentsDAO method deleteComment.

public int deleteComment(UserComment comment, boolean deleteReplies) {
    int counter = 0;
    // First reload parent from cache to prevent stale object or cache issues
    comment = reloadComment(comment);
    if (comment == null) {
        // Original comment has been deleted in the meantime. Don't delete it again.
        return 0;
    }
    // First deal with all direct replies
    List<UserComment> replies = dbInstance.getCurrentEntityManager().createQuery("select comment from usercomment as comment where parent=:parent", UserComment.class).setParameter("parent", comment).getResultList();
    if (deleteReplies) {
        // the replies to prevent foreign key constraints
        for (UserComment reply : replies) {
            counter += deleteComment(reply, true);
        }
    } else {
        // of the original comment for each reply
        for (UserComment reply : replies) {
            reply.setParent(comment.getParent());
            dbInstance.getCurrentEntityManager().merge(reply);
        }
    }
    // Now delete this comment and finish
    dbInstance.getCurrentEntityManager().remove(comment);
    // do Logging
    OLATResourceable ores = OresHelper.createOLATResourceableInstance(comment.getResName(), comment.getResId());
    updateDelegateRatings(ores, comment.getResSubPath());
    ThreadLocalUserActivityLogger.log(CommentAndRatingLoggingAction.COMMENT_DELETED, getClass(), CoreLoggingResourceable.wrap(ores, OlatResourceableType.feedItem));
    return counter + 1;
}
Also used : UserComment(org.olat.core.commons.services.commentAndRating.model.UserComment) OLATResourceable(org.olat.core.id.OLATResourceable)

Example 5 with UserComment

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

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)

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