@SuppressWarnings("unchecked")
  private void setUpForNotes(Sample sample) {
    noteIdToIndicatorMap = new HashMap<String, String>();

    List<Result> results = resultDAO.getResultsForSample(sample);
    History searchHistory = new History();
    searchHistory.setReferenceTable(NOTE_TABLE_ID);
    historyList = new ArrayList<History>();

    Note searchNote = new Note();
    searchNote.setReferenceTableId(RESULT_TABLE_ID);
    for (Result result : results) {
      searchNote.setReferenceId(result.getId());

      List<Note> notes = noteDAO.getAllNotesByRefIdRefTable(searchNote);

      for (Note note : notes) {
        searchHistory.setReferenceId(note.getId());
        noteIdToIndicatorMap.put(
            note.getId(), TestService.getLocalizedTestName(result.getAnalysis().getTest()));
        historyList.addAll(auditTrailDAO.getHistoryByRefIdAndRefTableId(searchHistory));
      }
    }

    newValueMap = new HashMap<String, String>();
  }
  @Override
  protected ActionForward performAction(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    String forward = FWD_SUCCESS;

    List<IResultUpdate> updaters = ValidationUpdateRegister.getRegisteredUpdaters();
    boolean areListeners = updaters != null && !updaters.isEmpty();

    request.getSession().setAttribute(SAVE_DISABLED, "true");

    BaseActionForm dynaForm = (BaseActionForm) form;

    ResultValidationPaging paging = new ResultValidationPaging();
    paging.updatePagedResults(request, dynaForm);
    List<AnalysisItem> resultItemList = paging.getResults(request);

    String testSectionName = (String) dynaForm.get("testSection");
    String testName = (String) dynaForm.get("testName");
    setRequestType(testSectionName);

    ActionMessages errors = validateModifiedItems(resultItemList);

    if (errors.size() > 0) {
      saveErrors(request, errors);
      request.setAttribute(Globals.ERROR_KEY, errors);
      return mapping.findForward(FWD_VALIDATION_ERROR);
    }

    createSystemUser();
    setSampleFinishedStatuses();

    noteUpdateList = new ArrayList<Note>();
    resultUpdateList = new ArrayList<Result>();
    analysisUpdateList = new ArrayList<Analysis>();
    modifiedResultSet = new ArrayList<ResultSet>();
    newResultSet = new ArrayList<ResultSet>();
    deletableList = new ArrayList<Result>();

    if (testSectionName.equals("serology")) {
      createUpdateElisaList(resultItemList);
    } else {
      createUpdateList(resultItemList, areListeners);
    }

    Transaction tx = HibernateUtil.getSession().beginTransaction();

    try {
      ResultSaveService.removeDeletedResultsInTransaction(deletableList, currentUserId);

      // update analysis
      for (Analysis analysis : analysisUpdateList) {
        analysisDAO.updateData(analysis);
      }

      for (Result result : resultUpdateList) {
        if (result.getId() != null) {
          resultDAO.updateData(result);
        } else {
          resultDAO.insertData(result);
        }
      }

      checkIfSamplesFinished(resultItemList);

      // update finished samples
      for (Sample sample : sampleUpdateList) {
        sampleDAO.updateData(sample);
      }

      // create or update notes
      for (Note note : noteUpdateList) {
        if (note != null) {
          if (note.getId() == null) {
            noteDAO.insertData(note);
          } else {
            noteDAO.updateData(note);
          }
        }
      }

      for (IResultUpdate updater : updaters) {
        updater.transactionalUpdate(this);
      }

      tx.commit();

    } catch (LIMSRuntimeException lre) {
      tx.rollback();
    }

    for (IResultUpdate updater : updaters) {
      updater.postTransactionalCommitUpdate(this);
    }

    if (isBlankOrNull(testSectionName)) {
      return mapping.findForward(forward);
    } else {
      Map<String, String> params = new HashMap<String, String>();
      params.put("type", testSectionName);
      params.put("test", testName);
      params.put("forward", forward);

      return getForwardWithParameters(mapping.findForward(forward), params);
    }
  }