Example #1
0
  private void addAnalyzerResultFromLine(List<AnalyzerResults> results, String line) {
    String[] fields = StringUtil.separateCSVWithMixedEmbededQuotes(line);

    // This insures that the row has not been truncated
    if (fields.length < maxViewedIndex) {
      return;
    }

    AnalyzerReaderUtil readerUtil = new AnalyzerReaderUtil();
    String analyzerAccessionNumber = fields[Sample_ID].replace("\"", "");
    analyzerAccessionNumber = StringUtil.strip(analyzerAccessionNumber, " ");

    String date = fields[Date_Analyzed].replace("\"", "");

    // this is sort of dumb, we have the indexes we are interested in
    for (int i = 0; i < testNameIndex.length; i++) {
      if (!GenericValidator.isBlankOrNull(testNameIndex[i])) {
        MappedTestName mappedName =
            AnalyzerTestNameCache.instance()
                .getMappedTest(AnalyzerType.FACSCANTO, testNameIndex[i].replace("\"", ""));

        if (mappedName == null) {
          mappedName =
              AnalyzerTestNameCache.instance()
                  .getEmptyMappedTestName(
                      AnalyzerType.FACSCANTO, testNameIndex[i].replace("\"", ""));
        }

        AnalyzerResults analyzerResults = new AnalyzerResults();

        analyzerResults.setAnalyzerId(mappedName.getAnalyzerId());

        String result = fields[i].replace("\"", "");
        result = roundTwoDigits(result);
        analyzerResults.setResult(result);
        analyzerResults.setUnits(unitsIndex[i]);

        analyzerResults.setCompleteDate(
            DateUtil.convertStringDateToTimestampWithPatternNoLocale(date, DATE_PATTERN));
        // analyzerResults.setCompleteTime(DateUtil.convertStringDateToTimestamp(date));
        analyzerResults.setTestId(mappedName.getTestId());
        analyzerResults.setAccessionNumber(analyzerAccessionNumber);
        analyzerResults.setTestName(mappedName.getOpenElisTestName());

        if (analyzerAccessionNumber != null) {
          analyzerResults.setIsControl(
              analyzerAccessionNumber.startsWith(CONTROL_ACCESSION_PREFIX));
        } else {
          analyzerResults.setIsControl(false);
        }

        results.add(analyzerResults);

        AnalyzerResults resultFromDB = readerUtil.createAnalyzerResultFromDB(analyzerResults);
        if (resultFromDB != null) {
          results.add(resultFromDB);
        }
      }
    }
  }
  public String validateAndUpdateAnalyzerTestName(
      ActionMapping mapping, HttpServletRequest request, BaseActionForm dynaForm) {
    String forward = FWD_SUCCESS_INSERT;
    String analyzerId = dynaForm.getString("analyzerId");
    String testId = dynaForm.getString("testId");
    String analyzerTestName = dynaForm.getString("analyzerTestName");
    boolean newMapping = "0".equals(request.getParameter("ID"));

    ActionMessages errors = new ActionMessages();

    AnalyzerTestMapping analyzerTestNameMapping =
        validateAnalyzerAndTestName(analyzerId, analyzerTestName, testId, errors, newMapping);

    if (errors.size() > 0) {
      saveErrors(request, errors);
      return FWD_FAIL;
    }

    if (newMapping) {
      analyzerTestNameMapping = new AnalyzerTestMapping();
      analyzerTestNameMapping.setAnalyzerId(analyzerId);
      analyzerTestNameMapping.setAnalyzerTestName(analyzerTestName);
      analyzerTestNameMapping.setTestId(testId);
    }

    AnalyzerTestMappingDAO mappingDAO = new AnalyzerTestMappingDAOImpl();

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

    try {
      if (newMapping) {
        mappingDAO.insertData(analyzerTestNameMapping, currentUserId);
      } else {
        mappingDAO.updateMapping(analyzerTestNameMapping, currentUserId);
      }

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

      ActionError error = null;
      if (lre.getException() instanceof org.hibernate.StaleObjectStateException) {
        error = new ActionError("errors.OptimisticLockException", null, null);
      } else {
        error = new ActionError("errors.UpdateException", null, null);
      }

      persisteError(request, error);

      disableNavigationButtons(request);
      forward = FWD_FAIL;
    } finally {
      if (!tx.wasRolledBack()) {
        tx.commit();
      }
      HibernateUtil.closeSession();
    }

    AnalyzerTestNameCache.instance().reloadCache();

    return forward;
  }