예제 #1
0
  public UserComment createEntryComment(String userId, long partId, UserComment newComment) {
    Entry entry = dao.get(partId);
    if (entry == null) return null;

    authorization.canRead(userId, entry);
    Account account = accountController.getByEmail(userId);
    Comment comment = new Comment();
    comment.setAccount(account);
    comment.setEntry(entry);
    comment.setBody(newComment.getMessage());
    comment.setCreationTime(new Date());
    comment = commentDAO.create(comment);

    if (newComment.getSamples() != null) {
      SampleDAO sampleDAO = DAOFactory.getSampleDAO();
      for (PartSample partSample : newComment.getSamples()) {
        Sample sample = sampleDAO.get(partSample.getId());
        if (sample == null) continue;
        comment.getSamples().add(sample);
        sample.getComments().add(comment);
      }
    }

    comment = commentDAO.update(comment);
    return comment.toDataTransferObject();
  }
예제 #2
0
  public UserComment updateEntryComment(
      String userId, long partId, long commentId, UserComment userComment) {
    Entry entry = dao.get(partId);
    if (entry == null) return null;

    authorization.canRead(userId, entry);
    Comment comment = commentDAO.get(commentId);
    if (comment == null) return createEntryComment(userId, partId, userComment);

    if (comment.getEntry().getId() != partId) return null;

    if (userComment.getMessage() == null || userComment.getMessage().isEmpty()) return null;

    comment.setBody(userComment.getMessage());
    comment.setModificationTime(new Date());
    return commentDAO.update(comment).toDataTransferObject();
  }