protected ActionForward performAction(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

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

    BaseActionForm dynaForm = (BaseActionForm) form;
    // server-side validation (validation.xml)
    ActionMessages errors = dynaForm.validate(mapping, request);

    // bugzilla 2614 allow for NB domain samples
    String selectedTestId = "";

    String referenceTableId = SystemConfiguration.getInstance().getResultReferenceTableId();
    String refId = (String) dynaForm.get("noteRefId");

    String noteIds = (String) dynaForm.get("noteIds");
    String noteSubjects = (String) dynaForm.get("noteSubjects");
    String noteTexts = (String) dynaForm.get("noteTexts");
    String noteTypes = (String) dynaForm.get("noteTypes");
    String noteLastupdateds = (String) dynaForm.get("noteLastupdateds");

    List noteIdList = new ArrayList();
    List noteSubjectList = new ArrayList();
    List noteTextList = new ArrayList();
    List noteTypeList = new ArrayList();
    List noteLastupdatedList = new ArrayList();

    String textSeparator = SystemConfiguration.getInstance().getDefaultTextSeparator();

    NoteDAO noteDAO = new NoteDAOImpl();
    SystemUserDAO systemUserDAO = new SystemUserDAOImpl();
    // bugzilla 2571 go through ReferenceTablesDAO to get reference tables info
    ReferenceTablesDAO referenceTablesDAO = new ReferenceTablesDAOImpl();

    // get sysUserId from login module
    UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
    String sysUserId = String.valueOf(usd.getSystemUserId());
    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();

    try {

      textSeparator = StringUtil.convertStringToRegEx(textSeparator);

      SystemUser systemUser = new SystemUser();
      systemUser.setId(sysUserId);
      systemUserDAO.getData(systemUser);

      // get all the data required to forward to correct page

      // get analysis id from result
      ResultDAO resultDAO = new ResultDAOImpl();
      Result result = new Result();
      result.setId(refId);
      resultDAO.getData(result);

      String analysisId = result.getAnalysis().getId();

      AnalysisDAO analysisDAO = new AnalysisDAOImpl();
      Analysis analysis = new Analysis();
      analysis.setId(analysisId);
      analysisDAO.getData(analysis);

      // get test id from analysis
      selectedTestId = analysis.getTest().getId();

      // get domain from sample
      SampleItemDAO sampleItemDAO = new SampleItemDAOImpl();
      SampleItem sampleItem = new SampleItem();
      sampleItem.setId(analysis.getSampleItem().getId());
      sampleItemDAO.getData(sampleItem);

      SampleDAO sampleDAO = new SampleDAOImpl();
      Sample sample = new Sample();
      // bugzilla 1773 need to store sample not sampleId for use in sorting
      sample.setId(sampleItem.getSample().getId());
      sampleDAO.getData(sample);

      // bugzilla 2614 allow for NB domain samples
      // now that we have the domain (for forwarding to correct fail page)
      // validate note popup form data!
      try {
        // bugzilla 2254 moved loadListFromStringOfElements to StringUtil
        noteIdList = StringUtil.loadListFromStringOfElements(noteIds, textSeparator, false);
        noteLastupdatedList =
            StringUtil.loadListFromStringOfElements(noteLastupdateds, textSeparator, false);
        // these three need to be validated for empty strings
        noteSubjectList =
            StringUtil.loadListFromStringOfElements(noteSubjects, textSeparator, true);
        noteTextList = StringUtil.loadListFromStringOfElements(noteTexts, textSeparator, true);
        noteTypeList = StringUtil.loadListFromStringOfElements(noteTypes, textSeparator, true);

      } catch (Exception e) {
        // bugzilla 2154
        LogEvent.logError("ResultsEntryNotesUpdateAction", "performAction()", e.toString());
        String messageKey = "note.note";
        ActionError error = new ActionError("errors.invalid", getMessageForKey(messageKey), null);
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
        saveErrors(request, errors);
        forward = FWD_FAIL;

        return mapping.findForward(forward);
      }

      for (int i = 0; i < noteIdList.size(); i++) {
        Note note = new Note();

        String noteId = (String) noteIdList.get(i);
        note.setReferenceId(refId);
        // bugzilla 1922
        // bugzilla 2571 go through ReferenceTablesDAO to get reference tables info
        ReferenceTables referenceTables = new ReferenceTables();
        referenceTables.setId(referenceTableId);
        // bugzilla 2571
        referenceTablesDAO.getData(referenceTables);
        note.setReferenceTables(referenceTables);
        note.setSystemUser(systemUser);
        note.setSystemUserId(sysUserId);
        // 1926 for audit trail
        note.setSysUserId(sysUserId);

        if (noteId != null && !noteId.equals("0")) {
          note.setId((String) noteIdList.get(i));
          note.setSubject((String) noteSubjectList.get(i));
          note.setText((String) noteTextList.get(i));
          note.setNoteType((String) noteTypeList.get(i));

          Timestamp noteTimestamp = null;
          if (!StringUtil.isNullorNill((String) noteLastupdatedList.get(i))) {

            noteTimestamp = DateUtil.formatStringToTimestamp((String) noteLastupdatedList.get(i));
          }

          note.setLastupdated(noteTimestamp);

          // UPDATE
          noteDAO.updateData(note);
          // }

        } else {
          // this is a new note
          note.setSubject((String) noteSubjectList.get(i));
          note.setText((String) noteTextList.get(i));
          note.setNoteType((String) noteTypeList.get(i));
          // INSERT
          noteDAO.insertData(note);
        }
      }

      tx.commit();

      return getForward(mapping.findForward(forward), selectedTestId, analysisId);

    } catch (LIMSRuntimeException lre) {
      // bugzilla 2154
      LogEvent.logError("ResultsEntryNotesUpdateAction", "performAction()", lre.toString());
      tx.rollback();
      errors = new ActionMessages();
      ActionError error = null;
      if (lre.getException() instanceof org.hibernate.StaleObjectStateException) {
        error = new ActionError("errors.OptimisticLockException", null, null);
      } else {
        if (lre.getException() instanceof LIMSDuplicateRecordException) {
          java.util.Locale locale =
              (java.util.Locale)
                  request.getSession().getAttribute("org.apache.struts.action.LOCALE");
          String messageKey = "note.note";
          String msg =
              ResourceLocator.getInstance().getMessageResources().getMessage(locale, messageKey);
          error = new ActionError("errors.DuplicateRecord", msg, null);

        } else {
          error = new ActionError("errors.UpdateException", null, null);
        }
      }
      errors.add(ActionMessages.GLOBAL_MESSAGE, error);
      saveErrors(request, errors);
      request.setAttribute(Globals.ERROR_KEY, errors);

      // disable previous and next
      request.setAttribute(PREVIOUS_DISABLED, "true");
      request.setAttribute(NEXT_DISABLED, "true");

      // default forward fail
      forward = FWD_FAIL;

    } finally {
      HibernateUtil.closeSession();
    }
    if (forward.equals(FWD_FAIL)
        || forward.equals(FWD_FAIL_HUMAN)
        || forward.equals(FWD_FAIL_ANIMAL)) return mapping.findForward(forward);

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

    // we need this for subsequent actions to
    // get data related to note parent for forwarding to next page
    request.setAttribute("refId", refId);
    request.setAttribute(SELECTED_TEST_ID, selectedTestId);

    return mapping.findForward(forward);
  }
  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;
  }
  protected ActionForward performAction(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

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

    BaseActionForm dynaForm = (BaseActionForm) form;

    ActionMessages errors = dynaForm.validate(mapping, request);

    UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
    String sysUserId = String.valueOf(usd.getSystemUserId());

    String birthDateForDisplay = dynaForm.getString("birthDateForDisplay");
    String birthTimeForDisplay = dynaForm.getString("birthTimeForDisplay");
    String format = "MM/dd/yyyy";
    java.sql.Timestamp dob = null;
    if ((birthDateForDisplay != null) && (birthDateForDisplay.length() > 0)) {
      java.text.SimpleDateFormat f = new java.text.SimpleDateFormat(format);
      dob = new java.sql.Timestamp(f.parse(birthDateForDisplay).getTime());

      if ((birthTimeForDisplay != null) && (birthTimeForDisplay.length() > 0)) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(dob);
        cal.set(
            Calendar.HOUR_OF_DAY, Integer.valueOf(birthTimeForDisplay.substring(0, 2)).intValue());
        cal.set(Calendar.MINUTE, Integer.valueOf(birthTimeForDisplay.substring(3, 5)).intValue());
        dob = new java.sql.Timestamp(cal.getTimeInMillis());
      }
    }

    String dateFirstFeedingForDisplay = dynaForm.getString("dateFirstFeedingForDisplay");
    String timeFirstFeedingForDisplay = dynaForm.getString("timeFirstFeedingForDisplay");
    java.sql.Timestamp dateFirstFeeding = null;
    if ((dateFirstFeedingForDisplay != null) && (dateFirstFeedingForDisplay.length() > 0)) {
      java.text.SimpleDateFormat f = new java.text.SimpleDateFormat(format);
      dateFirstFeeding = new java.sql.Timestamp(f.parse(dateFirstFeedingForDisplay).getTime());

      if ((timeFirstFeedingForDisplay != null) && (timeFirstFeedingForDisplay.length() > 0)) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(dob);
        cal.set(
            Calendar.HOUR_OF_DAY,
            Integer.valueOf(timeFirstFeedingForDisplay.substring(0, 2)).intValue());
        cal.set(
            Calendar.MINUTE,
            Integer.valueOf(timeFirstFeedingForDisplay.substring(3, 5)).intValue());
        dateFirstFeeding = new java.sql.Timestamp(cal.getTimeInMillis());
      }
    }

    String collectionDateForDisplay = dynaForm.getString("collectionDateForDisplay");
    String collectionTimeForDisplay = dynaForm.getString("collectionTimeForDisplay");
    java.sql.Timestamp collDate = null;
    if ((collectionDateForDisplay != null) && (collectionDateForDisplay.length() > 0)) {
      java.text.SimpleDateFormat f = new java.text.SimpleDateFormat(format);
      collDate = new java.sql.Timestamp(f.parse(collectionDateForDisplay).getTime());

      if ((collectionTimeForDisplay != null) && (collectionTimeForDisplay.length() > 0)) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(collDate);
        cal.set(
            Calendar.HOUR_OF_DAY,
            Integer.valueOf(collectionTimeForDisplay.substring(0, 2)).intValue());
        cal.set(
            Calendar.MINUTE, Integer.valueOf(collectionTimeForDisplay.substring(3, 5)).intValue());
        collDate = new java.sql.Timestamp(cal.getTimeInMillis());
      }
    }

    String dateTransfutionForDisplay = (String) dynaForm.getString("dateTransfutionForDisplay");
    java.sql.Timestamp dateTransfution = null;
    if ((dateTransfutionForDisplay != null) && (dateTransfutionForDisplay.length() > 0)) {
      java.text.SimpleDateFormat f = new java.text.SimpleDateFormat(format);
      dateTransfution = new java.sql.Timestamp(f.parse(dateTransfutionForDisplay).getTime());
    }

    String motherBirthDateForDisplay = (String) dynaForm.get("motherBirthDateForDisplay");
    java.sql.Timestamp motherBirthDate = null;
    if ((motherBirthDateForDisplay != null) && (motherBirthDateForDisplay.length() > 0)) {
      java.text.SimpleDateFormat f = new java.text.SimpleDateFormat(format);
      motherBirthDate = new java.sql.Timestamp(f.parse(motherBirthDateForDisplay).getTime());
    }

    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();
    String accessionNumber = (String) dynaForm.get("accessionNumber");
    try {
      // Sample
      Sample sample = new Sample();
      SampleDAO sampleDAO = new SampleDAOImpl();
      sample.setSysUserId(sysUserId);
      sample.setAccessionNumber(accessionNumber);
      sampleDAO.getSampleByAccessionNumber(sample);
      sample.setBarCode((String) dynaForm.get("barcode"));
      sample.setStatus(SystemConfiguration.getInstance().getSampleStatusEntry2Complete());
      sample.setCollectionDate(collDate);
      sampleDAO.updateData(sample);

      // SampleHuman
      SampleHumanDAO sampleHumanDAO = new SampleHumanDAOImpl();
      SampleHuman sampleHuman = new SampleHuman();
      sampleHuman.setSampleId(sample.getId());
      sampleHumanDAO.getDataBySample(sampleHuman);

      // Patient - child
      Patient childPatient = new Patient();
      PatientDAO patientDAO = new PatientDAOImpl();
      Person childPerson = new Person();
      childPatient.setId(sampleHuman.getPatientId());
      patientDAO.getData(childPatient);

      // Person - child
      PersonDAO personDAO = new PersonDAOImpl();
      childPerson = childPatient.getPerson();
      personDAO.getData(childPerson);
      childPerson.setSysUserId(sysUserId);
      childPerson.setLastName((String) dynaForm.get("lastName"));
      childPerson.setFirstName((String) dynaForm.get("firstName"));
      personDAO.updateData(childPerson);

      childPatient.setSysUserId(sysUserId);
      childPatient.setBirthDate(dob);
      childPatient.setGender((String) dynaForm.get("gender"));
      patientDAO.updateData(childPatient);

      // PatientRelation
      PatientRelation patientRelation = new PatientRelation();
      PatientRelationDAO patientRelationDAO = new PatientRelationDAOImpl();
      patientRelation.setPatientIdSource(childPatient.getId());
      patientRelation = patientRelationDAO.getPatientRelationByChildId(patientRelation);
      Person motherPerson = new Person();
      Patient motherPatient = new Patient();
      if (!StringUtil.isNullorNill(patientRelation.getId())) {
        motherPatient.setId(patientRelation.getPatientId());
        patientDAO.getData(motherPatient);
        motherPerson = motherPatient.getPerson();
        personDAO.getData(motherPerson);
      }
      motherPerson.setLastName((String) dynaForm.get("motherLastName"));
      motherPerson.setFirstName((String) dynaForm.get("motherFirstName"));
      String motherHomePhone = (String) dynaForm.get("motherPhoneNumber");
      if ((motherHomePhone != null) && (motherHomePhone.length() > 0))
        motherHomePhone = StringUtil.formatPhone(motherHomePhone, null);
      motherPerson.setHomePhone(motherHomePhone);
      motherPerson.setStreetAddress((String) dynaForm.get("motherStreetAddress"));
      motherPerson.setCity((String) dynaForm.get("city"));
      motherPerson.setState((String) dynaForm.get("state"));
      motherPerson.setZipCode((String) dynaForm.get("zipCode"));
      motherPerson.setSysUserId(sysUserId);
      if (!StringUtil.isNullorNill(motherPerson.getId())) personDAO.updateData(motherPerson);
      else personDAO.insertData(motherPerson);

      motherPatient.setBirthDate(motherBirthDate);
      motherPatient.setPerson(motherPerson);
      motherPatient.setSysUserId(sysUserId);
      if (!StringUtil.isNullorNill(motherPatient.getId())) patientDAO.updateData(motherPatient);
      else patientDAO.insertData(motherPatient);

      patientRelation.setSysUserId(sysUserId);
      patientRelation.setPatientId(motherPatient.getId());

      String motherRelation = SystemConfiguration.getInstance().getNewbornPatientRelation();
      patientRelation.setRelation(motherRelation);
      if (!StringUtil.isNullorNill(patientRelation.getId()))
        patientRelationDAO.updateData(patientRelation);
      else patientRelationDAO.insertData(patientRelation);

      // SampleNewborn
      SampleNewborn sampleNewborn = new SampleNewborn();
      SampleNewbornDAO sampleNewbornDAO = new SampleNewbornDAOImpl();
      sampleNewborn.setId(sampleHuman.getId());
      sampleNewbornDAO.getData(sampleNewborn);
      sampleNewborn.setSysUserId(sysUserId);
      sampleNewborn.setMedicalRecordNumber((String) dynaForm.get("medicalRecordNumber"));
      sampleNewborn.setYnumber((String) dynaForm.get("ynumber"));
      sampleNewborn.setYellowCard((String) dynaForm.get("yellowCard"));
      sampleNewborn.setWeight((String) dynaForm.get("birthWeight"));
      sampleNewborn.setMultiBirth((String) dynaForm.get("multipleBirth"));
      sampleNewborn.setBirthOrder((String) dynaForm.get("birthOrder"));
      sampleNewborn.setGestationalWeek((Double) dynaForm.get("gestationalWeek"));
      sampleNewborn.setDateFirstFeeding(dateFirstFeeding);
      sampleNewborn.setBreast((String) dynaForm.get("breast"));
      sampleNewborn.setTpn((String) dynaForm.get("tpn"));
      sampleNewborn.setFormula((String) dynaForm.get("formula"));
      sampleNewborn.setMilk((String) dynaForm.get("milk"));
      sampleNewborn.setSoy((String) dynaForm.get("soy"));
      sampleNewborn.setJaundice((String) dynaForm.get("jaundice"));
      sampleNewborn.setAntibiotic((String) dynaForm.get("antibiotic"));
      sampleNewborn.setTransfused((String) dynaForm.get("transfused"));
      sampleNewborn.setNicu((String) dynaForm.get("nicuPatient"));
      sampleNewborn.setBirthDefect((String) dynaForm.get("birthDefect"));
      sampleNewborn.setPregnancyComplication((String) dynaForm.get("pregnancyComplication"));
      sampleNewborn.setDeceasedSibling((String) dynaForm.get("deceasedSibling"));
      sampleNewborn.setCauseOfDeath((String) dynaForm.get("causeOfDeath"));
      sampleNewborn.setFamilyHistory((String) dynaForm.get("familyHistory"));
      sampleNewborn.setOther((String) dynaForm.get("other"));
      sampleNewborn.setDateTransfution(dateTransfution);
      if (!StringUtil.isNullorNill(sampleNewborn.getId()))
        sampleNewbornDAO.updateData(sampleNewborn);
      else {
        sampleNewborn.setId(sampleHuman.getId());
        sampleNewbornDAO.insertData(sampleNewborn);
      }

      // Provider
      Provider provider = new Provider();
      Person providerPerson = new Person();
      ProviderDAO providerDAO = new ProviderDAOImpl();
      if (!StringUtil.isNullorNill(sampleHuman.getProviderId())) {
        provider.setId(sampleHuman.getProviderId());
        providerDAO.getData(provider);
      }

      if (!StringUtil.isNullorNill(sampleHuman.getProviderId())) {
        provider.setId(sampleHuman.getProviderId());
        providerDAO.getData(provider);
        providerPerson = (Person) provider.getPerson();
      }

      // SampleOrganization
      Organization o = new Organization();
      OrganizationDAO organizationDAO = new OrganizationDAOImpl();
      o.setOrganizationLocalAbbreviation((String) dynaForm.get("submitterNumber"));
      o = organizationDAO.getOrganizationByLocalAbbreviation(o, true);
      SampleOrganization sampleOrganization = new SampleOrganization();
      SampleOrganizationDAO sampleOrganizationDAO = new SampleOrganizationDAOImpl();
      sampleOrganizationDAO.getDataBySample(sampleOrganization);
      sampleOrganization.setSample(sample);
      sampleOrganization.setOrganization(o);
      sampleOrganization.setSysUserId(sysUserId);
      if (!StringUtil.isNullorNill(sampleOrganization.getId()))
        sampleOrganizationDAO.updateData(sampleOrganization);
      else sampleOrganizationDAO.insertData(sampleOrganization);

      // Person - provider
      providerPerson.setSysUserId(sysUserId);
      providerPerson.setFirstName((String) dynaForm.get("physicianFirstName"));
      providerPerson.setLastName((String) dynaForm.get("physicianLastName"));
      String providerHomePhone = (String) dynaForm.get("physicianPhoneNumber");
      if ((providerHomePhone != null) && (providerHomePhone.length() > 0))
        providerHomePhone = StringUtil.formatPhone(providerHomePhone, null);
      providerPerson.setHomePhone(providerHomePhone);
      if (!StringUtil.isNullorNill(providerPerson.getId())) personDAO.updateData(providerPerson);
      else personDAO.insertData(providerPerson);

      provider.setPerson(providerPerson);
      provider.setExternalId(BLANK);
      provider.setSysUserId(sysUserId);
      if (!StringUtil.isNullorNill(provider.getId())) providerDAO.updateData(provider);
      else providerDAO.insertData(provider);

      sampleHuman.setProviderId(provider.getId());
      sampleHuman.setSysUserId(sysUserId);
      sampleHumanDAO.updateData(sampleHuman);

      tx.commit();
    } catch (LIMSRuntimeException lre) {
      LogEvent.logError("NewbornSampleFullUpdateAction", "performAction()", lre.toString());
      tx.rollback();
      errors = new ActionMessages();
      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);
      }
      errors.add(ActionMessages.GLOBAL_MESSAGE, error);
      saveErrors(request, errors);
      request.setAttribute(Globals.ERROR_KEY, errors);
      request.setAttribute(ALLOW_EDITS_KEY, "false");
      forward = FWD_FAIL;

    } finally {
      HibernateUtil.closeSession();
    }
    if (forward.equals(FWD_FAIL)) return mapping.findForward(forward);

    // Trigger QA if birthWeight < 200 grams
    int birthWeight = Integer.parseInt((String) dynaForm.get("birthWeight"));
    if ((birthWeight > 0) && (birthWeight < 200)) {
      forward = FWD_SUCCESS_QA_EVENTS_ENTRY;
      return getForward(mapping.findForward(forward), accessionNumber);
    }

    return mapping.findForward(FWD_SUCCESS);
  }
  protected ActionForward performAction(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    String forward = "success";

    DynaActionForm dynaForm = (DynaActionForm) form;

    String[] selectedIDs = (String[]) dynaForm.get("selectedIDs");

    String sysUserId = getSysUserId(request);

    boolean permisionAgentIsUser =
        SystemConfiguration.getInstance().getPermissionAgent().equals("USER");
    List permissionAgentModules = new ArrayList();

    for (int i = 0; i < selectedIDs.length; i++) {
      PermissionModule permissionAgentModule =
          permisionAgentIsUser ? new SystemUserModule() : new RoleModule();
      permissionAgentModule.setId(selectedIDs[i]);
      permissionAgentModule.setSysUserId(sysUserId);
      permissionAgentModules.add(permissionAgentModule);
    }

    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();
    ActionMessages errors = null;
    try {
      PermissionAgentModuleDAO permissionAgentModuleDAO =
          permisionAgentIsUser ? new SystemUserModuleDAOImpl() : new RoleModuleDAOImpl();
      permissionAgentModuleDAO.deleteData(permissionAgentModules);
      // initialize the form
      dynaForm.initialize(mapping);
      tx.commit();
    } catch (LIMSRuntimeException lre) {
      // bugzilla 2154
      LogEvent.logError("SystemUserModuleDeleteAction", "performAction()", lre.toString());
      tx.rollback();

      errors = new ActionMessages();
      ActionError error = null;
      if (lre.getException() instanceof org.hibernate.StaleObjectStateException) {
        error = new ActionError("errors.OptimisticLockException", null, null);
      } else {
        error = new ActionError("errors.DeleteException", null, null);
      }
      errors.add(ActionMessages.GLOBAL_MESSAGE, error);
      saveErrors(request, errors);
      request.setAttribute(Globals.ERROR_KEY, errors);
      forward = FWD_FAIL;

    } finally {
      HibernateUtil.closeSession();
    }
    if (forward.equals(FWD_FAIL)) return mapping.findForward(forward);

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

    request.setAttribute("menuDefinition", "SystemUserModuleMenuDefinition");

    return mapping.findForward(forward);
  }