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());
}
}
}
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);
}
}
}
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());
}
}
}
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;
}
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());
}
}
Aggregations