@Override
  protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);

    DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
    int noteId = fp.getInt(NOTE_ID, true);

    DiscrepancyNoteBean note = (DiscrepancyNoteBean) dndao.findByPK(noteId);

    String entityType = note.getEntityType();
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());

    ArrayList notes = dndao.findAllEntityByPK(note.getEntityType(), noteId);

    Date lastUpdatedDate = note.getCreatedDate();
    UserAccountBean lastUpdator = (UserAccountBean) udao.findByPK(note.getOwnerId());

    for (int i = 0; i < notes.size(); i++) {
      DiscrepancyNoteBean n = (DiscrepancyNoteBean) notes.get(i);
      int pId = n.getParentDnId();
      if (pId == 0) {
        note = n;
        note.setLastUpdator((UserAccountBean) udao.findByPK(n.getOwnerId()));
        note.setLastDateUpdated(n.getCreatedDate());
        lastUpdatedDate = note.getLastDateUpdated();
        lastUpdator = note.getLastUpdator();
      }
    }

    for (int i = 0; i < notes.size(); i++) {
      DiscrepancyNoteBean n = (DiscrepancyNoteBean) notes.get(i);
      int pId = n.getParentDnId();
      if (pId > 0) {
        note.getChildren().add(n);
        if (!n.getCreatedDate().before(lastUpdatedDate)) {
          lastUpdatedDate = n.getCreatedDate();
          lastUpdator = (UserAccountBean) udao.findByPK(n.getOwnerId());
          note.setLastUpdator(lastUpdator);
          note.setLastDateUpdated(lastUpdatedDate);
          note.setResolutionStatusId(n.getResolutionStatusId());
          note.setResStatus(ResolutionStatus.get(n.getResolutionStatusId()));
        }
      }
    }
    note.setNumChildren(note.getChildren().size());
    note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
    logger.info("Just set Note: " + note.getCrfName() + " column " + note.getColumn());
    request.setAttribute(DIS_NOTE, note);
    forwardPage(Page.VIEW_SINGLE_NOTE);
  }
  /**
   * Determines if a discrepancy note is closed or not. The note is closed if it has status closed,
   * or any of its children have closed status.
   *
   * @param note The discrepancy note. The children should already be set.
   * @return <code>true</code> if the note is closed, <code>false</code> otherwise.
   */
  public static boolean noteIsClosed(DiscrepancyNoteBean note) {
    if (note.getResolutionStatusId() == ResolutionStatus.CLOSED.getId()) {
      return true;
    }

    ArrayList children = note.getChildren();
    for (int i = 0; i < children.size(); i++) {
      DiscrepancyNoteBean child = (DiscrepancyNoteBean) children.get(i);
      if (child.getResolutionStatusId() == ResolutionStatus.CLOSED.getId()) {
        return true;
      }
    }

    return false;
  }