Exemple #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();
  }
Exemple #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();
  }
Exemple #3
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;
  }
Exemple #4
0
  public PartStatistics retrieveEntryStatistics(String userId, long entryId) {
    Entry entry = dao.get(entryId);
    if (entry == null) return null;

    authorization.expectRead(userId, entry);

    PartStatistics statistics = new PartStatistics();
    statistics.setEntryId(entryId);
    statistics.setCommentCount(commentDAO.getCommentCount(entry));
    int traceSequenceCount = DAOFactory.getTraceSequenceDAO().getTraceSequenceCount(entry);
    statistics.setTraceSequenceCount(traceSequenceCount);
    int sampleCount = DAOFactory.getSampleDAO().getSampleCount(entry);
    statistics.setSampleCount(sampleCount);
    int historyCount = DAOFactory.getAuditDAO().getHistoryCount(entry);
    statistics.setHistoryCount(historyCount);
    int eddCount = DAOFactory.getExperimentDAO().getExperimentCount(entryId);
    statistics.setExperimentalDataCount(eddCount);
    return statistics;
  }