Search in sources :

Example 21 with UserComment

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

the class CommentAndRatingServiceImpl method createComment.

@Override
public UserComment createComment(Identity creator, OLATResourceable ores, String resSubPath, String commentText) {
    UserComment comment = userCommentsDao.createComment(creator, ores, resSubPath, commentText);
    markPublisherNews(comment);
    return comment;
}
Also used : UserComment(org.olat.core.commons.services.commentAndRating.model.UserComment)

Example 22 with UserComment

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

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)

Example 23 with UserComment

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

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 24 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.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)

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