/** * @param commentId * @param userId - request owner * @throws BetException */ @Override public void deleteComment(Long commentId, Long userId) throws BetException { Comment c = getCommentById(commentId); checkUpdateRights(c, userId); c.setStatus(Comment.STATUS_DELETED); c = em.merge(c); }
@Override public void updateComment(Long commentId, Long ownerId, String newMessage) throws BetException { Comment c = getCommentById(commentId); checkUpdateRights(c, ownerId); c.setMessage(newMessage); c = em.merge(c); }
// TODO: change this metod for admin private void checkUpdateRights(Comment c, Long reqOwnerId) throws BetException { if (c == null) { throw new BetException("comment is not specified"); } if (reqOwnerId == null) { throw new BetException("request owner is not specified"); } if (!c.getUserId().equals(reqOwnerId)) { throw new BetException("Access denied"); } }
@Override public List<SimpleComment> getSimpleBetComments(Long betId, Long ownerId) throws BetException { List<SimpleComment> sbList = new ArrayList(); List<Comment> list = getBetComments(betId, ownerId); for (Comment c : list) { sbList.add( new SimpleComment( c.getMessage(), userMan.getVkIdByUserId(c.getUserId()), c.getBetId(), c.getCreationDate() == null ? null : c.getCreationDate().getTime(), c.getId())); } return sbList; }