Esempio n. 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();
  }
Esempio n. 2
0
  public ArrayList<UserComment> retrieveEntryComments(String userId, long partId) {
    Entry entry = dao.get(partId);
    if (entry == null) return null;

    authorization.expectRead(userId, entry);

    // comments
    ArrayList<Comment> comments = commentDAO.retrieveComments(entry);
    ArrayList<UserComment> userComments = new ArrayList<>();

    for (Comment comment : comments) {
      userComments.add(comment.toDataTransferObject());
    }
    return userComments;
  }