String docToCommentRef = request.getParameter("docToCommentRef");
DocumentModel docToComment = session.getDocument(new IdRef(
docToCommentRef));
String commentParentRef = request.getParameter("commentParentRef");
// Create comment
CommentableDocument commentableDoc = null;
if (docToComment != null) {
commentableDoc = docToComment.getAdapter(CommentableDocument.class);
}
DocumentModel newComment;
if (commentParentRef != null) {
// if exists retrieve comment parent
DocumentModel commentParent = session.getDocument(new IdRef(
commentParentRef));
newComment = commentableDoc.addComment(commentParent, myComment);
} else {
newComment = commentableDoc.addComment(myComment);
}
// automatically validate the comments
if (CommentsConstants.COMMENT_LIFECYCLE.equals(newComment.getLifeCyclePolicy())) {
new FollowTransitionUnrestricted(ctx.getCoreSession(),
newComment.getRef(),