@Override
public Either<PostReplyError, URI> postReply(final URI baseUri,
final Iterable<String> itemPath,
final String comment)
{
checkArgument(size(itemPath) == 2, "Item path must contain exactly 2 parts.");
int reviewId = Integer.parseInt(get(itemPath, 0));
int commentId = Integer.parseInt(get(itemPath, 1));
FecruUser user = cenquaUserManager.getUser(salUserManager.getRemoteUsername());
Review review = reviewManager.getReviewById(reviewId);
if (review == null)
{
return left(new PostReplyError(DELETED_OR_PERMISSION_DENIED));
}
else if (!permissionAccessor.currentUserCanComment(review))
{
return left(new PostReplyError(UNAUTHORIZED));
}
Comment replyToComment = commentManager.getById(commentId);
if (replyToComment == null)
{
return left(new PostReplyError(DELETED_OR_PERMISSION_DENIED));
}
else if (!permissionAccessor.currentUserCanReplyToComment(replyToComment))
{
return left(new PostReplyError(UNAUTHORIZED));
}
Comment newComment = addReply(comment, replyToComment, review, user);
return right(uriProvider.getCommentUri(baseUri, newComment));
}