protected ActionForward performAction(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    // The first job is to determine if we are coming to this action with an
    // ID parameter in the request. If there is no parameter, we are
    // creating a new Sample.
    // If there is a parameter present, we should bring up an existing
    // Sample to edit.

    String forward = FWD_SUCCESS;
    request.setAttribute(ALLOW_EDITS_KEY, "true");

    String id = request.getParameter(ID);

    if (StringUtil.isNullorNill(id) || "0".equals(id)) {
      isNew = true;
    } else {
      isNew = false;
    }

    BaseActionForm dynaForm = (BaseActionForm) form;

    // first get the accessionNumber and whether we are on blank page or not
    String accessionNumber = (String) dynaForm.get("accessionNumber");
    // bugzilla 2154
    LogEvent.logDebug(
        "HumanSampleTwoPopulateHashMapFromDE1Action",
        "performAction()",
        "accessionNumber coming in: " + accessionNumber);
    String start = (String) request.getParameter("startingRecNo");

    String typeOfSample = (String) dynaForm.get("typeOfSampleDesc");
    String sourceOfSample = (String) dynaForm.get("sourceOfSampleDesc");

    List typeOfSamples = new ArrayList();
    List sourceOfSamples = new ArrayList();

    if (dynaForm.get("typeOfSamples") != null) {
      typeOfSamples = (List) dynaForm.get("typeOfSamples");
    } else {
      TypeOfSampleDAO typeOfSampleDAO = new TypeOfSampleDAOImpl();
      typeOfSamples = typeOfSampleDAO.getAllTypeOfSamples();
    }
    if (dynaForm.get("sourceOfSamples") != null) {
      sourceOfSamples = (List) dynaForm.get("sourceOfSamples");
    } else {
      SourceOfSampleDAO sourceOfSampleDAO = new SourceOfSampleDAOImpl();
      sourceOfSamples = sourceOfSampleDAO.getAllSourceOfSamples();
    }

    HashMap humanSampleOneMap = new HashMap();
    if (dynaForm.get("humanSampleOneMap") != null) {
      humanSampleOneMap = (HashMap) dynaForm.get("humanSampleOneMap");
    }

    String projectIdOrName = (String) dynaForm.get("projectIdOrName");
    String project2IdOrName = (String) dynaForm.get("project2IdOrName");

    String projectNameOrId = (String) dynaForm.get("projectNameOrId");
    String project2NameOrId = (String) dynaForm.get("project2NameOrId");

    String projectId = null;
    String project2Id = null;
    if (projectIdOrName != null && projectNameOrId != null) {
      try {
        Integer i = Integer.valueOf(projectIdOrName);
        projectId = projectIdOrName;

      } catch (NumberFormatException nfe) {
        // bugzilla 2154
        LogEvent.logError(
            "HumanSampleTwoPopulateHashMapFromDE1Action", "performAction()", nfe.toString());
        projectId = projectNameOrId;
      }
    }

    if (project2IdOrName != null && project2NameOrId != null) {
      try {
        Integer i = Integer.valueOf(project2IdOrName);
        project2Id = project2IdOrName;

      } catch (NumberFormatException nfe) {
        // bugzilla 2154
        LogEvent.logError(
            "HumanSampleTwoPopulateHashMapFromDE1Action", "performAction()", nfe.toString());
        project2Id = project2NameOrId;
      }
    }

    // bugzilla 2154
    LogEvent.logDebug(
        "HumanSampleTwoPopulateHashMapFromDE1Action",
        "performAction()",
        "ProjectId is: " + projectId + " Project2Id is: " + project2Id);

    // set current date for validation of dates
    Date today = Calendar.getInstance().getTime();
    Locale locale = (Locale) request.getSession().getAttribute("org.apache.struts.action.LOCALE");
    String dateAsText = DateUtil.formatDateAsText(today, locale);

    Patient patient = new Patient();
    Person person = new Person();
    Provider provider = new Provider();
    Person providerPerson = new Person();
    Sample sample = new Sample();
    SampleHuman sampleHuman = new SampleHuman();
    SampleOrganization sampleOrganization = new SampleOrganization();
    List sampleProjects = new ArrayList();
    List updatedSampleProjects = new ArrayList();
    SampleItem sampleItem = new SampleItem();
    // TODO need to populate this with tests entered in HSE I
    List analyses = new ArrayList();

    // tests are not handled in HSE II
    /*
     * String stringOfTestIds = (String) dynaForm.get("selectedTestIds");
     *
     * String[] listOfTestIds = stringOfTestIds.split(SystemConfiguration
     * .getInstance().getDefaultIdSeparator(), -1);
     *
     * List analyses = new ArrayList(); for (int i = 0; i <
     * listOfTestIds.length; i++) { if
     * (!StringUtil.isNullorNill(listOfTestIds[i])) { Analysis analysis =
     * new Analysis(); analysis.setTestId(listOfTestIds[i]); // TODO: need
     * to populate this with actual data!!!
     * analysis.setAnalysisType("TEST"); analyses.add(analysis); } }
     */

    ActionMessages errors = null;

    // validate on server-side sample accession number

    try {
      errors = new ActionMessages();
      errors = validateAccessionNumber(request, errors, dynaForm);
      // System.out.println("Just validated accessionNumber");
    } catch (Exception e) {
      // bugzilla 2154
      LogEvent.logError(
          "HumanSampleTwoPopulateHashMapFromDE1Action", "performAction()", e.toString());
      ActionError error = new ActionError("errors.ValidationException", null, null);
      errors.add(ActionMessages.GLOBAL_MESSAGE, error);
    }
    // System.out.println("This is errors after validation of accn Number "
    // + errors);
    if (errors != null && errors.size() > 0) {
      saveErrors(request, errors);
      // initialize the form but retain the invalid accessionNumber
      dynaForm.initialize(mapping);
      dynaForm.set("accessionNumber", accessionNumber);

      // repopulate lists
      PropertyUtils.setProperty(dynaForm, "typeOfSamples", typeOfSamples);
      PropertyUtils.setProperty(dynaForm, "sourceOfSamples", sourceOfSamples);
      request.setAttribute(ALLOW_EDITS_KEY, "false");

      return mapping.findForward(FWD_FAIL);
    }
    // System.out.println("Now try to get data for accession number ");
    try {

      PatientDAO patientDAO = new PatientDAOImpl();
      PersonDAO personDAO = new PersonDAOImpl();
      ProviderDAO providerDAO = new ProviderDAOImpl();
      SampleDAO sampleDAO = new SampleDAOImpl();
      SampleItemDAO sampleItemDAO = new SampleItemDAOImpl();
      SampleHumanDAO sampleHumanDAO = new SampleHumanDAOImpl();
      SampleOrganizationDAO sampleOrganizationDAO = new SampleOrganizationDAOImpl();
      AnalysisDAO analysisDAO = new AnalysisDAOImpl();

      sample.setAccessionNumber(accessionNumber);
      sampleDAO.getSampleByAccessionNumber(sample);
      if (!StringUtil.isNullorNill(sample.getId())) {
        sampleHuman.setSampleId(sample.getId());
        sampleHumanDAO.getDataBySample(sampleHuman);
        sampleOrganization.setSampleId(sample.getId());
        sampleOrganizationDAO.getDataBySample(sampleOrganization);
        // bugzilla 1773 need to store sample not sampleId for use in
        // sorting
        sampleItem.setSample(sample);
        sampleItemDAO.getDataBySample(sampleItem);
        patient.setId(sampleHuman.getPatientId());
        patientDAO.getData(patient);
        person = patient.getPerson();
        personDAO.getData(person);

        provider.setId(sampleHuman.getProviderId());
        providerDAO.getData(provider);
        providerPerson = provider.getPerson();
        personDAO.getData(providerPerson);
        // bugzilla 2227
        analyses = analysisDAO.getMaxRevisionAnalysesBySample(sampleItem);

        humanSampleOneMap =
            populateHumanSampleOneMap(
                patient,
                person,
                provider,
                providerPerson,
                sample,
                sampleHuman,
                sampleOrganization,
                sampleItem,
                analyses);
      }

    } catch (LIMSRuntimeException lre) {
      // if error then forward to fail and don't update to blank page
      // = false
      // bugzilla 2154
      LogEvent.logError(
          "HumanSampleTwoPopulateHashMapFromDE1Action", "performAction()", lre.toString());
      errors = new ActionMessages();
      ActionError error = null;
      if (lre.getException() instanceof org.hibernate.StaleObjectStateException) {
        // how can I get popup instead of struts error at the top of
        // page?
        // ActionMessages errors = dynaForm.validate(mapping,
        // request);
        error = new ActionError("errors.OptimisticLockException", null, null);
        // bugzilla 2154
        LogEvent.logError(
            "HumanSampleTwoPopulateHashMapFromDE1Action",
            "performAction()",
            "errors.OptimisticLockException");
      } else {
        error = new ActionError("errors.GetException", null, null);
        // bugzilla 2154
        LogEvent.logError(
            "HumanSampleTwoPopulateHashMapFromDE1Action", "performAction()", "errors.GetException");
      }
      errors.add(ActionMessages.GLOBAL_MESSAGE, error);
      saveErrors(request, errors);
      request.setAttribute(Globals.ERROR_KEY, errors);
      request.setAttribute(ALLOW_EDITS_KEY, "false");
      return mapping.findForward(FWD_FAIL);
    }

    // initialize the form
    dynaForm.initialize(mapping);

    // set lastupdated fields
    dynaForm.set("lastupdated", sample.getLastupdated());
    dynaForm.set("personLastupdated", person.getLastupdated());
    dynaForm.set("patientLastupdated", patient.getLastupdated());
    dynaForm.set("providerPersonLastupdated", providerPerson.getLastupdated());
    dynaForm.set("providerLastupdated", provider.getLastupdated());
    dynaForm.set("sampleItemLastupdated", sampleItem.getLastupdated());
    dynaForm.set("sampleHumanLastupdated", sampleHuman.getLastupdated());
    dynaForm.set("sampleOrganizationLastupdated", sampleOrganization.getLastupdated());

    if (updatedSampleProjects != null && updatedSampleProjects.size() > 0) {
      if (updatedSampleProjects.size() == 1) {
        SampleProject sp = (SampleProject) updatedSampleProjects.get(0);
        dynaForm.set("sampleProject1Lastupdated", sp.getLastupdated());
        // bugzilla 1857 deprecated stuff
        // System.out.println("This is sp ts "
        //		+ StringUtil.formatDateAsText(sp.getLastupdated(),
        //				SystemConfiguration.getInstance()
        //						.getDefaultLocale()));
      }
      if (updatedSampleProjects.size() == 2) {
        SampleProject sp2 = (SampleProject) updatedSampleProjects.get(1);
        dynaForm.set("sampleProject2Lastupdated", sp2.getLastupdated());
        // bugzilla 1857 deprecated stuff
        // System.out.println("This is sp2 ts "
        //		+ StringUtil.formatDateAsText(sp2.getLastupdated(),
        //				SystemConfiguration.getInstance()
        //						.getDefaultLocale()));
      }
    }

    if (dynaForm.get("sampleProject1Lastupdated") == null) {
      PropertyUtils.setProperty(
          form, "sampleProject1Lastupdated", new Timestamp(System.currentTimeMillis()));
    }
    if (dynaForm.get("sampleProject2Lastupdated") == null) {
      PropertyUtils.setProperty(
          form, "sampleProject2Lastupdated", new Timestamp(System.currentTimeMillis()));
    }

    PropertyUtils.setProperty(dynaForm, "currentDate", dateAsText);
    PropertyUtils.setProperty(dynaForm, "accessionNumber", sample.getAccessionNumber());
    // set receivedDate
    PropertyUtils.setProperty(
        dynaForm, "receivedDateForDisplay", (String) sample.getReceivedDateForDisplay());

    PropertyUtils.setProperty(dynaForm, "typeOfSamples", typeOfSamples);
    PropertyUtils.setProperty(dynaForm, "sourceOfSamples", sourceOfSamples);
    PropertyUtils.setProperty(dynaForm, "humanSampleOneMap", humanSampleOneMap);

    if ("true".equalsIgnoreCase(request.getParameter("close"))) {
      forward = FWD_CLOSE;
    }

    if (sample.getId() != null && !sample.getId().equals("0")) {
      request.setAttribute(ID, sample.getId());
    }

    if (forward.equals(FWD_SUCCESS)) {
      request.setAttribute("menuDefinition", "default");
    }

    // bugzilla 2154
    LogEvent.logDebug(
        "HumanSampleTwoPopulateHashMapFromDE1Action",
        "performAction()",
        "forwarding to: " + forward);

    // pdf - get accession number List
    if (SystemConfiguration.getInstance().getEnabledSamplePdf().equals(YES)) {
      String status =
          SystemConfiguration.getInstance().getSampleStatusEntry1Complete(); // status = 2
      String humanDomain = SystemConfiguration.getInstance().getHumanDomain();
      UserTestSectionDAO userTestSectionDAO = new UserTestSectionDAOImpl();
      List accessionNumberListTwo =
          userTestSectionDAO.getSamplePdfList(request, locale, status, humanDomain);
      PropertyUtils.setProperty(form, "accessionNumberListTwo", accessionNumberListTwo);
    }

    // return getForward(mapping.findForward(forward), id, start);
    return mapping.findForward(forward);
  }