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