示例#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();
  }