Example usage for org.apache.commons.beanutils PropertyUtils copyProperties

List of usage examples for org.apache.commons.beanutils PropertyUtils copyProperties

Introduction

In this page you can find the example usage for org.apache.commons.beanutils PropertyUtils copyProperties.

Prototype

public static void copyProperties(Object dest, Object orig)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Copy property values from the "origin" bean to the "destination" bean for all cases where the property names are the same (even though the actual getter and setter methods might have been customized via BeanInfo classes).

For more details see PropertyUtilsBean.

Usage

From source file:us.mn.state.health.lims.test.daoimpl.TestSectionDAOImpl.java

public void getData(TestSection testSection) throws LIMSRuntimeException {
    try {/*from w  w  w  .  j a v a2s.c o  m*/
        TestSection testSec = (TestSection) HibernateUtil.getSession().get(TestSection.class,
                testSection.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        if (testSec != null) {
            PropertyUtils.copyProperties(testSection, testSec);
        } else {
            testSection.setId(null);
        }
    } catch (Exception e) {
        LogEvent.logError("TestSectionDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in TestSection getData()", e);
    }
}

From source file:us.mn.state.health.lims.testanalyte.action.TestAnalyteAction.java

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 TestAnalyte.
    // If there is a parameter present, we should bring up an existing
    // TestAnalyte to edit.
    String id = request.getParameter(ID);

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

    DynaActionForm dynaForm = (DynaActionForm) form;

    // initialize the form
    dynaForm.initialize(mapping);//from w  w w.j av  a2s .c o m

    TestAnalyte testAnalyte = new TestAnalyte();

    if ((id != null) && (!"0".equals(id))) { // this is an existing
        // testAnalyte

        testAnalyte.setId(id);
        TestAnalyteDAO testAnalyteDAO = new TestAnalyteDAOImpl();
        testAnalyteDAO.getData(testAnalyte);

        // initialize testName
        if (testAnalyte.getTest() != null) {
            testAnalyte.setTestName(TestService.getLocalizedTestName(testAnalyte.getTest()));
        }

        // initialize analyteName
        if (testAnalyte.getAnalyte() != null) {
            testAnalyte.setAnalyteName(testAnalyte.getAnalyte().getAnalyteName());
        }

        isNew = false; // this is to set correct page title

        // do we need to enable next or previous?
        List testAnalytes = testAnalyteDAO.getNextTestAnalyteRecord(testAnalyte.getId());
        if (testAnalytes.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        testAnalytes = testAnalyteDAO.getPreviousTestAnalyteRecord(testAnalyte.getId());
        if (testAnalytes.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button
    } else { // this is a new testAnalyte

        isNew = true; // this is to set correct page title
    }

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

    // populate form from valueholder
    PropertyUtils.copyProperties(form, testAnalyte);

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.testanalyte.action.TestAnalyteUpdateAction.java

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 TestAnalyte.
    // If there is a parameter present, we should bring up an existing
    // TestAnalyte to edit.

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

    String id = request.getParameter(ID);

    if (StringUtil.isNullorNill(id) || "0".equals(id)) {
        isNew = true;/* w w w .jav  a 2  s  .com*/
    } else {
        isNew = false;
    }

    BaseActionForm dynaForm = (BaseActionForm) form;

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

    try {
        errors = validateAll(request, errors, dynaForm);
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("TestAnalyteUpdateAction", "performAction()", e.toString());
        ActionError error = new ActionError("errors.ValidationException", null, null);
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
    }

    if (errors != null && errors.size() > 0) {
        // System.out.println("Server side validation errors "
        // + errors.toString());
        saveErrors(request, errors);
        // since we forward to jsp - not Action we don't need to repopulate
        // the lists here
        return mapping.findForward(FWD_FAIL);
    }

    String start = (String) request.getParameter("startingRecNo");
    String direction = (String) request.getParameter("direction");

    // System.out.println("This is ID from request " + id);
    TestAnalyte testAnalyte = new TestAnalyte();
    //get sysUserId from login module
    UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA);
    String sysUserId = String.valueOf(usd.getSystemUserId());
    testAnalyte.setSysUserId(sysUserId);
    org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction();

    // set test object
    Test test = new Test();
    String testName = (String) dynaForm.get("testName");
    test.setTestName(testName);

    TestDAO testDAO = new TestDAOImpl();
    test = testDAO.getTestByName(test);

    // set analyte object
    Analyte analyte = new Analyte();
    String analyteName = (String) dynaForm.get("analyteName");
    analyte.setAnalyteName(analyteName);

    AnalyteDAO analyteDAO = new AnalyteDAOImpl();
    //bugzilla 1367
    analyte = analyteDAO.getAnalyteByName(analyte, false);

    // populate valueholder from form
    PropertyUtils.copyProperties(testAnalyte, dynaForm);

    testAnalyte.setTest(test);
    testAnalyte.setAnalyte(analyte);

    try {

        TestAnalyteDAO testAnalyteDAO = new TestAnalyteDAOImpl();
        if (!isNew) {
            // UPDATE
            testAnalyteDAO.updateData(testAnalyte);
            if (FWD_NEXT.equals(direction)) {
                List testAnalytes = testAnalyteDAO.getNextTestAnalyteRecord(testAnalyte.getId());
                if (testAnalytes != null && testAnalytes.size() > 0) {
                    testAnalyte = (TestAnalyte) testAnalytes.get(0);
                    testAnalyteDAO.getData(testAnalyte);
                    if (testAnalytes.size() < 2) {
                        // disable next button
                        request.setAttribute(NEXT_DISABLED, "true");
                    }
                    id = testAnalyte.getId();
                } else {
                    // just disable next button
                    request.setAttribute(NEXT_DISABLED, "true");
                }
                forward = FWD_NEXT;
            }

            if (FWD_PREVIOUS.equals(direction)) {
                List testAnalytes = testAnalyteDAO.getPreviousTestAnalyteRecord(testAnalyte.getId());
                if (testAnalytes != null && testAnalytes.size() > 0) {
                    testAnalyte = (TestAnalyte) testAnalytes.get(0);
                    testAnalyteDAO.getData(testAnalyte);
                    if (testAnalytes.size() < 2) {
                        // disable previous button
                        request.setAttribute(PREVIOUS_DISABLED, "true");
                    }
                    id = testAnalyte.getId();
                } else {
                    // just disable next button
                    request.setAttribute(PREVIOUS_DISABLED, "true");
                }
                forward = FWD_PREVIOUS;
            }
        } else {
            // INSERT

            testAnalyteDAO.insertData(testAnalyte);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("TestAnalyteUpdateAction", "performAction()", lre.toString());
        tx.rollback();
        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);

        } 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");
        // disable previous and next
        request.setAttribute(PREVIOUS_DISABLED, "true");
        request.setAttribute(NEXT_DISABLED, "true");
        forward = FWD_FAIL;

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

    // initialize the form
    dynaForm.initialize(mapping);
    // repopulate the form from valueholder
    PropertyUtils.copyProperties(dynaForm, testAnalyte);

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

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

    }

    //bugzilla 1400
    if (isNew)
        forward = FWD_SUCCESS_INSERT;
    return getForward(mapping.findForward(forward), id, start);

}

From source file:us.mn.state.health.lims.testanalyte.daoimpl.TestAnalyteDAOImpl.java

public TestAnalyte getData(TestAnalyte testAnalyte) throws LIMSRuntimeException {
    try {/*ww w  .  ja v a  2  s. c  o  m*/
        TestAnalyte anal = (TestAnalyte) HibernateUtil.getSession().get(TestAnalyte.class, testAnalyte.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        if (anal != null) {
            PropertyUtils.copyProperties(testAnalyte, anal);
        } else {
            testAnalyte.setId(null);
        }

        return anal;
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("TestAnalyteDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in TestAnalyte getData()", e);
    }
}

From source file:us.mn.state.health.lims.testanalyte.daoimpl.TestAnalyteTestResultDAOImpl.java

public void updateData(Test test, List allOldTestAnalytes, List allOldTestResults, List allNewTestAnalytes,
        List allNewTestResults) throws LIMSRuntimeException {

    Transaction tx = null;/*from  www .  jav  a  2  s . c  o m*/
    Session session = null;

    try {
        session = HibernateUtil.getSession();
        tx = session.beginTransaction();

        // this stores all testResult Ids (test results can be shared
        // amongst components)
        Hashtable allOldTestResultsForTest = new Hashtable();
        Hashtable allNewTestResultsForTest = new Hashtable();

        // load hashtables
        if (allNewTestResults != null) {
            for (int j = 0; j < allNewTestResults.size(); j++) {
                TestResult tr = (TestResult) allNewTestResults.get(j);
                if (!StringUtil.isNullorNill(tr.getId())) {
                    allNewTestResultsForTest.put(tr.getId(), tr);
                }
            }
        }

        if ((allOldTestResults != null) && (allOldTestResults.size() > 0)) {

            for (int j = 0; j < allOldTestResults.size(); j++) {
                TestResult tr = (TestResult) allOldTestResults.get(j);
                allOldTestResultsForTest.put(tr.getId(), tr);
            }

        }

        // Get a List of allNewTrIds (all new test result Ids) from
        // Hashtable allNewTestResultsForTest
        // Note : this does not include new ones that don't have an id yet!!
        Set allNewTrIdsSet = (Set) allNewTestResultsForTest.keySet();
        Iterator allNewTrIdsIt = allNewTrIdsSet.iterator();
        List allNewTrIds = new ArrayList();

        while (allNewTrIdsIt.hasNext()) {
            allNewTrIds.add(allNewTrIdsIt.next());
        }

        // Get a List of allOldTrIds (all old test result Ids) from
        // Hashtable allOldTestResultsForTest
        Set allOldTrIdsSet = (Set) allOldTestResultsForTest.keySet();
        Iterator allOldTrIdsIt = allOldTrIdsSet.iterator();
        List allOldTrIds = new ArrayList();

        while (allOldTrIdsIt.hasNext()) {
            allOldTrIds.add(allOldTrIdsIt.next());
        }

        // Loop through all new test analytes
        for (int i = 0; i < allNewTestAnalytes.size(); i++) {
            TestAnalyte testAnalyte = (TestAnalyte) allNewTestAnalytes.get(i);
            List testResults = new ArrayList();
            List oldTestResults = new ArrayList();
            TestAnalyte testAnalyteClone;
            //bug#1342
            String analyteType;

            if (!StringUtil.isNullorNill(testAnalyte.getId())) {
                // UPDATE
                testAnalyteClone = readTestAnalyte(testAnalyte.getId());
                oldTestResults = testAnalyteClone.getTestResults();

                //bug#1342 recover old test analyte type (R/N) as this is not submitted
                //correctly when select is disabled and User re-sorts
                analyteType = testAnalyteClone.getTestAnalyteType();
                PropertyUtils.copyProperties(testAnalyteClone, testAnalyte);

                //bug#1342 recover old test analyte type (R/N) as this is not submitted
                //correctly when select is disabled and User resorts
                if (testAnalyte.getTestAnalyteType() == null) {
                    testAnalyteClone.setTestAnalyteType(analyteType);
                }
                // list of testResults
                testResults = testAnalyteClone.getTestResults();

                session.merge(testAnalyteClone);
                session.flush();
                session.clear();

            } else {
                // INSERT
                testAnalyte.setId(null);

                // list of testResults
                testResults = testAnalyte.getTestResults();

                session.save(testAnalyte);
                session.flush();
                session.clear();

            }

            List newIds = new ArrayList();
            List oldIds = new ArrayList();

            if (testResults != null) {
                for (int j = 0; j < testResults.size(); j++) {
                    TestResult tr = (TestResult) testResults.get(j);
                    newIds.add(tr.getId());
                }
            }

            if ((oldTestResults != null) && (oldTestResults.size() > 0)) {
                List listOfOldOnesToRemove = new ArrayList();
                for (int j = 0; j < oldTestResults.size(); j++) {
                    TestResult tr = (TestResult) oldTestResults.get(j);
                    oldIds.add(tr.getId());
                    if (!newIds.contains(tr.getId())) {
                        // remove ones that are to be deleted
                        listOfOldOnesToRemove.add(new Integer(j));
                    }
                }

                int decreaseOTRIndexBy = 0;
                int decreaseOIIndexBy = 0;
                for (int j = 0; j < listOfOldOnesToRemove.size(); j++) {
                    oldTestResults
                            .remove(((Integer) listOfOldOnesToRemove.get(j)).intValue() - decreaseOTRIndexBy++);
                    oldIds.remove(((Integer) listOfOldOnesToRemove.get(j)).intValue() - decreaseOIIndexBy++);

                }
            }

            //Loop through new testResults for this particular testAnalyte
            if (testResults != null) {
                for (int j = 0; j < testResults.size(); j++) {
                    TestResult teRe = (TestResult) testResults.get(j);

                    int index = oldIds.indexOf(teRe.getId());

                    if (!StringUtil.isNullorNill(teRe.getId())
                            && allOldTestResultsForTest.containsKey(teRe.getId())) {
                        //UPDATE
                        TestResult testResultClone = readTestResult(teRe.getId());
                        PropertyUtils.copyProperties(testResultClone, teRe);
                        if (index >= 0) {
                            oldTestResults.set(index, testResultClone);
                        } else {
                            oldTestResults.add(testResultClone);
                        }
                        session.merge(teRe);
                        session.flush();
                        session.clear();

                    } else {
                        //INSERT
                        oldTestResults.add(teRe);
                        session.save(teRe);
                        session.flush();
                        session.clear();
                    }

                }

            }

            // remove test analytes from total list which holds all test analytes to be deleted (this is not a
            // candidate for delete because it is amongst the new test
            // analytes list!)
            if (allOldTestAnalytes != null) {
                for (int x = 0; x < allOldTestAnalytes.size(); x++) {
                    TestAnalyte ta = (TestAnalyte) allOldTestAnalytes.get(x);
                    if (ta.getId().equals(testAnalyte.getId())) {
                        allOldTestAnalytes.remove(x);
                        break;
                    }
                }
            }
        }

        // BEGIN OF DELETE

        // Delete any left-over old test analytes
        if ((allOldTestAnalytes != null) && (allOldTestAnalytes.size() > 0)) {
            for (int i = 0; i < allOldTestAnalytes.size(); i++) {
                TestAnalyte testAnalyte = (TestAnalyte) allOldTestAnalytes.get(i);

                session.delete(testAnalyte);
                session.flush();
                session.clear();
            }
        }

        // Delete any left-over old test results
        if ((allOldTrIds != null) && (allOldTrIds.size() > 0)) {
            for (int i = 0; i < allOldTrIds.size(); i++) {
                if (!allNewTrIds.contains(allOldTrIds.get(i))) {
                    TestResult testResult = (TestResult) allOldTestResultsForTest.get(allOldTrIds.get(i));

                    session.delete(testResult);
                    session.flush();
                    session.clear();
                }
            }
        }
        // END OF DELETE

        tx.commit();

    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("TestAnalyteTestResultDAOImpl", "updateData()", e.toString());
        if (tx != null)
            tx.rollback();
        throw new LIMSRuntimeException("Error in TestAnalyteTestResult updateData()", e);
    }
}

From source file:us.mn.state.health.lims.testmanagement.action.SampleDemographicsUpdateAction.java

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

    //System.out.println("I am in SampleDemographicsUpdateAction ");

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

    // server-side validation (validation.xml)
    ActionMessages errors = testManagementForm.validate(mapping, request);
    try {/* w w  w .java  2  s  . c om*/
        errors = validateAll(request, errors, testManagementForm);
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("SampleDemographicsUpdateAction", "performAction()", e.toString());
        ActionError error = new ActionError("errors.ValidationException", null, null);
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
    }
    // end of zip/city combination check

    if (errors != null && errors.size() > 0) {
        saveErrors(request, errors);
        // since we forward to jsp - not Action we don't need to repopulate
        // the lists here
        return mapping.findForward(FWD_FAIL);
    }

    String accessionNumber = (String) testManagementForm.get("accessionNumber");

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

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

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

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

    String projectNameOrId = (String) testManagementForm.get("projectNameOrId");
    String project2NameOrId = (String) testManagementForm.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("SampleDemographicsUpdateAction", "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("SampleDemographicsUpdateAction", "performAction()", nfe.toString());
            project2Id = project2NameOrId;
        }
    }

    // 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);

    PersonDAO personDAO = new PersonDAOImpl();
    PatientDAO patientDAO = new PatientDAOImpl();
    ProviderDAO providerDAO = new ProviderDAOImpl();
    SampleDAO sampleDAO = new SampleDAOImpl();
    SampleItemDAO sampleItemDAO = new SampleItemDAOImpl();
    SampleHumanDAO sampleHumanDAO = new SampleHumanDAOImpl();
    SampleOrganizationDAO sampleOrganizationDAO = new SampleOrganizationDAOImpl();
    AnalysisDAO analysisDAO = new AnalysisDAOImpl();
    SampleProjectDAO sampleProjectDAO = new SampleProjectDAOImpl();
    ProjectDAO projectDAO = new ProjectDAOImpl();
    AnalysisQaEventDAO analysisQaEventDAO = new AnalysisQaEventDAOImpl();
    AnalysisQaEventActionDAO analysisQaEventActionDAO = new AnalysisQaEventActionDAOImpl();
    QaEventDAO qaEventDAO = new QaEventDAOImpl();
    ActionDAO actionDAO = new ActionDAOImpl();

    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 oldSampleProjects = new ArrayList();
    List newSampleProjects = new ArrayList();
    SampleItem sampleItem = new SampleItem();

    List analyses = new ArrayList();

    // GET ORIGINAL DATA
    try {

        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);

            oldSampleProjects = sample.getSampleProjects();

        }

    } catch (LIMSRuntimeException lre) {
        // if error then forward to fail and don't update to blank page
        // = false
        //bugzilla 2154
        LogEvent.logError("SampleDemographicsUpdateAction", "performAction()", lre.toString());
        errors = new ActionMessages();
        ActionError error = null;
        error = new ActionError("errors.GetException", null, null);
        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);

    }

    // UPDATE DATA FROM FORM
    // populate valueholder from form
    PropertyUtils.copyProperties(sample, testManagementForm);
    PropertyUtils.copyProperties(person, testManagementForm);
    PropertyUtils.copyProperties(patient, testManagementForm);
    PropertyUtils.copyProperties(provider, testManagementForm);
    PropertyUtils.copyProperties(sampleHuman, testManagementForm);
    PropertyUtils.copyProperties(sampleOrganization, testManagementForm);
    PropertyUtils.copyProperties(sampleItem, testManagementForm);

    TypeOfSample typeOfSamp = null;

    // get the right typeOfSamp to update sampleitem with
    for (int i = 0; i < typeOfSamples.size(); i++) {
        TypeOfSample s = (TypeOfSample) typeOfSamples.get(i);
        if (s.getDescription().equalsIgnoreCase(typeOfSample)) {
            typeOfSamp = s;
            break;
        }
    }

    SourceOfSample sourceOfSamp = null;

    // get the right sourceOfSamp to update sampleitem with
    for (int i = 0; i < sourceOfSamples.size(); i++) {
        SourceOfSample s = (SourceOfSample) sourceOfSamples.get(i);
        if (s.getDescription().equalsIgnoreCase(sourceOfSample)) {
            sourceOfSamp = s;
            break;
        }
    }

    Organization org = new Organization();
    //bugzilla 2069
    org.setOrganizationLocalAbbreviation((String) testManagementForm.get("organizationLocalAbbreviation"));
    OrganizationDAO organizationDAO = new OrganizationDAOImpl();
    org = organizationDAO.getOrganizationByLocalAbbreviation(org, true);
    sampleOrganization.setOrganization(org);

    // if there was a first sampleProject id entered
    // ****Added a Try catch block to validate integer because..
    // ****When a project is deleted, the name of the project is passed in
    // as its id which causes error
    try {
        Integer i = Integer.valueOf(projectId);

        if (!StringUtil.isNullorNill(projectId)) {
            SampleProject sampleProject = new SampleProject();
            Project p = new Project();
            //bugzilla 2438
            p.setLocalAbbreviation(projectId);
            p = projectDAO.getProjectByLocalAbbreviation(p, true);
            sampleProject.setProject(p);
            sampleProject.setSample(sample);
            sampleProject.setIsPermanent(NO);
            newSampleProjects.add(sampleProject);

        }

    } catch (NumberFormatException nfe) {
        //bugzilla 2154
        LogEvent.logError("SampleDemographicsUpdateAction", "performAction()", nfe.toString());
    }

    // in case there was a second sampleProject id entered
    try {
        Integer i = Integer.valueOf(project2Id);

        if (!StringUtil.isNullorNill(project2Id)) {
            SampleProject sampleProject2 = new SampleProject();
            Project p2 = new Project();
            //bugzilla 2438
            p2.setLocalAbbreviation(project2Id);
            p2 = projectDAO.getProjectByLocalAbbreviation(p2, true);
            sampleProject2.setProject(p2);
            sampleProject2.setSample(sample);
            sampleProject2.setIsPermanent(NO);
            newSampleProjects.add(sampleProject2);
        }

    } catch (NumberFormatException nfe) {
        //bugzilla 2154
        LogEvent.logError("SampleDemographicsUpdateAction", "performAction()", nfe.toString());
    }

    // set the provider person manually as we have two Person
    // valueholders
    // to populate and copyProperties() can only handle one per form
    providerPerson.setFirstName((String) testManagementForm.get("providerFirstName"));
    providerPerson.setLastName((String) testManagementForm.get("providerLastName"));

    // format workPhone for storage
    String workPhone = (String) testManagementForm.get("providerWorkPhone");
    String ext = (String) testManagementForm.get("providerWorkPhoneExtension");
    String formattedPhone = StringUtil.formatPhone(workPhone, ext);
    // phone is stored as 999/999-9999.9999
    // area code/phone - number.extension
    providerPerson.setWorkPhone(formattedPhone);

    String date = (String) testManagementForm.get("collectionDateForDisplay");

    if (!StringUtil.isNullorNill(date)) {
        //System.out.println("I am here");
        // set collection time
        String time = (String) testManagementForm.get("collectionTimeForDisplay");
        if (StringUtil.isNullorNill(time)) {
            time = "00:00";
        }
        sample.setCollectionTimeForDisplay(time);
        sample.setCollectionDateForDisplay(date);

        Timestamp d = sample.getCollectionDate();
        if (time.indexOf(":") > 0) {
            // bugzilla 1857 deprecated stuff
            Calendar cal = Calendar.getInstance();
            cal.setTime(d);
            cal.set(Calendar.HOUR_OF_DAY, Integer.valueOf(time.substring(0, 2)).intValue());
            cal.set(Calendar.MINUTE, Integer.valueOf(time.substring(3, 5)).intValue());
            // d.setHours(Integer.valueOf(time.substring(0, 2)).intValue());
            // d.setMinutes(Integer.valueOf(time.substring(3,
            // 5)).intValue());
            d = new Timestamp(cal.getTimeInMillis());
            sample.setCollectionDate(d);
        }
    }

    // sampleItem
    sampleItem.setSortOrder("1");
    // set the typeOfSample
    sampleItem.setTypeOfSample(typeOfSamp);
    // set the sourceOfSample
    sampleItem.setSourceOfSample(sourceOfSamp);
    sample.setSampleProjects(newSampleProjects);

    // 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();

    //bugzilla 2481, 2496 Action Owner
    SystemUser systemUser = new SystemUser();
    systemUser.setId(sysUserId);
    SystemUserDAO systemUserDAO = new SystemUserDAOImpl();
    systemUserDAO.getData(systemUser);

    List newIds = new ArrayList();
    List oldIds = new ArrayList();

    if (newSampleProjects != null) {
        for (int i = 0; i < newSampleProjects.size(); i++) {
            SampleProject sp = (SampleProject) newSampleProjects.get(i);
            newIds.add(sp.getId());
        }
    }

    if (oldSampleProjects != null) {

        List listOfOldOnesToRemove = new ArrayList();
        for (int i = 0; i < oldSampleProjects.size(); i++) {
            SampleProject sp = (SampleProject) oldSampleProjects.get(i);
            oldIds.add(sp.getId());
            if (!newIds.contains(sp.getId())) {
                // remove ones that are to be deleted
                listOfOldOnesToRemove.add(new Integer(i));
            }
        }

        int decreaseOSPIndexBy = 0;
        int decreaseOIIndexBy = 0;
        List listOfSampleProjectObjectsToDelete = new ArrayList();
        for (int i = 0; i < listOfOldOnesToRemove.size(); i++) {
            SampleProject sp = (SampleProject) oldSampleProjects
                    .remove(((Integer) listOfOldOnesToRemove.get(i)).intValue() - decreaseOSPIndexBy++);
            //bugzilla 1926
            sp.setSysUserId(sysUserId);
            listOfSampleProjectObjectsToDelete.add(sp);
            oldIds.remove(((Integer) listOfOldOnesToRemove.get(i)).intValue() - decreaseOIIndexBy++);

        }
        sampleProjectDAO.deleteData(listOfSampleProjectObjectsToDelete);
    }

    if (newSampleProjects != null) {
        for (int j = 0; j < newSampleProjects.size(); j++) {
            SampleProject saPr = (SampleProject) newSampleProjects.get(j);

            int index = oldIds.indexOf(saPr.getId());
            if (index >= 0) {
                SampleProject sampleProjectClone = (SampleProject) oldSampleProjects.get(index);
                PropertyUtils.copyProperties(sampleProjectClone, saPr);
                Sample smplClone = (Sample) sampleProjectClone.getSample();
                sampleProjectClone.setSample(smplClone);
                Project pClone = (Project) sampleProjectClone.getProject();
                sampleProjectClone.setProject(pClone);
                PropertyUtils.setProperty(sampleProjectClone, "lastupdated",
                        (Timestamp) testManagementForm.get("sampleProject1Lastupdated"));

                sampleProjectClone.setSysUserId(sysUserId);
                sampleProjectDAO.updateData(sampleProjectClone);
                oldSampleProjects.set(index, sampleProjectClone);
            } else {
                SampleProject sampleProjectClone = new SampleProject();
                PropertyUtils.copyProperties(sampleProjectClone, saPr);
                Sample smplClone = (Sample) sampleProjectClone.getSample();
                sampleProjectClone.setSample(smplClone);
                Project pClone = (Project) sampleProjectClone.getProject();
                sampleProjectClone.setProject(pClone);
                PropertyUtils.setProperty(sampleProjectClone, "lastupdated",
                        (Timestamp) testManagementForm.get("sampleProject2Lastupdated"));
                //bugzilla 1926
                sampleProjectClone.setSysUserId(sysUserId);
                sampleProjectDAO.insertData(sampleProjectClone);
                oldSampleProjects.add(sampleProjectClone);
            }
        }
    }

    sample.setSampleProjects(oldSampleProjects);
    // END DIANE

    try {

        // set last updated from form
        PropertyUtils.setProperty(person, "lastupdated",
                (Timestamp) testManagementForm.get("personLastupdated"));
        PropertyUtils.setProperty(patient, "lastupdated",
                (Timestamp) testManagementForm.get("patientLastupdated"));
        PropertyUtils.setProperty(sample, "lastupdated", (Timestamp) testManagementForm.get("lastupdated"));
        PropertyUtils.setProperty(providerPerson, "lastupdated",
                (Timestamp) testManagementForm.get("providerPersonLastupdated"));
        PropertyUtils.setProperty(provider, "lastupdated",
                (Timestamp) testManagementForm.get("providerLastupdated"));
        PropertyUtils.setProperty(sampleItem, "lastupdated",
                (Timestamp) testManagementForm.get("sampleItemLastupdated"));
        PropertyUtils.setProperty(sampleHuman, "lastupdated",
                (Timestamp) testManagementForm.get("sampleHumanLastupdated"));
        PropertyUtils.setProperty(sampleOrganization, "lastupdated",
                (Timestamp) testManagementForm.get("sampleOrganizationLastupdated"));

        person.setSysUserId(sysUserId);
        patient.setSysUserId(sysUserId);
        providerPerson.setSysUserId(sysUserId);
        provider.setSysUserId(sysUserId);
        sample.setSysUserId(sysUserId);
        sampleHuman.setSysUserId(sysUserId);
        sampleOrganization.setSysUserId(sysUserId);
        sampleItem.setSysUserId(sysUserId);
        personDAO.updateData(person);
        patient.setPerson(person);

        patientDAO.updateData(patient);
        personDAO.updateData(providerPerson);
        provider.setPerson(providerPerson);
        providerDAO.updateData(provider);
        sampleDAO.updateData(sample);

        sampleHuman.setSampleId(sample.getId());
        sampleHuman.setPatientId(patient.getId());
        sampleHuman.setProviderId(provider.getId());
        sampleHumanDAO.updateData(sampleHuman);
        sampleOrganization.setSampleId(sample.getId());
        sampleOrganization.setSample(sample);
        sampleOrganizationDAO.updateData(sampleOrganization);
        // bugzilla 1773 need to store sample not sampleId for use in
        // sorting
        sampleItem.setSample(sample);

        sampleItemDAO.updateData(sampleItem);

        // Analysis table
        for (int i = 0; i < analyses.size(); i++) {
            Analysis analysis = (Analysis) analyses.get(i);
            analysis.setSampleItem(sampleItem);
            analysis.setSysUserId(sysUserId);
            analysisDAO.updateData(analysis);
        }

        // bugzilla 3032/2028 qa event logic needs to be executed for new and
        // existing analyses for this sample
        // ADDITIONAL REQUIREMENT ADDED 8/30: only for HSE2 Completed Status (see bugzilla 2032)
        boolean isSampleStatusReadyForQaEvent = false;
        if (!StringUtil.isNullorNill(sample.getStatus())
                && (sample.getStatus().equals(SystemConfiguration.getInstance().getSampleStatusReleased()))
                || sample.getStatus()
                        .equals(SystemConfiguration.getInstance().getSampleStatusEntry2Complete())) {
            isSampleStatusReadyForQaEvent = true;
        }
        if (isSampleStatusReadyForQaEvent) {

            // bugzilla 2028 need additional information for qa events
            typeOfSamp = sampleItem.getTypeOfSample();
            sampleOrganization.setSampleId(sample.getId());
            sampleOrganizationDAO.getDataBySample(sampleOrganization);
            //bugzilla 2589
            String submitterNumber = "";
            if (sampleOrganization != null && sampleOrganization.getOrganization() != null) {
                submitterNumber = sampleOrganization.getOrganization().getId();
            }

            //bugzilla 2227
            List allAnalysesForSample = analysisDAO.getMaxRevisionAnalysesBySample(sampleItem);

            // bugzilla 2028 get the possible qa events
            QaEvent qaEventForNoCollectionDate = new QaEvent();
            qaEventForNoCollectionDate.setQaEventName(
                    SystemConfiguration.getInstance().getQaEventCodeForRequestNoCollectionDate());
            qaEventForNoCollectionDate = qaEventDAO.getQaEventByName(qaEventForNoCollectionDate);

            QaEvent qaEventForNoSampleType = new QaEvent();
            qaEventForNoSampleType
                    .setQaEventName(SystemConfiguration.getInstance().getQaEventCodeForRequestNoSampleType());
            qaEventForNoSampleType = qaEventDAO.getQaEventByName(qaEventForNoSampleType);

            QaEvent qaEventForUnknownSubmitter = new QaEvent();
            qaEventForUnknownSubmitter.setQaEventName(
                    SystemConfiguration.getInstance().getQaEventCodeForRequestUnknownSubmitter());
            qaEventForUnknownSubmitter = qaEventDAO.getQaEventByName(qaEventForUnknownSubmitter);
            // end bugzilla 2028

            // bugzilla 2028 get the possible qa event actions
            Action actionForNoCollectionDate = new Action();
            actionForNoCollectionDate.setCode(
                    SystemConfiguration.getInstance().getQaEventActionCodeForRequestNoCollectionDate());
            actionForNoCollectionDate = actionDAO.getActionByCode(actionForNoCollectionDate);

            Action actionForNoSampleType = new Action();
            actionForNoSampleType
                    .setCode(SystemConfiguration.getInstance().getQaEventActionCodeForRequestNoSampleType());
            actionForNoSampleType = actionDAO.getActionByCode(actionForNoSampleType);

            Action actionForUnknownSubmitter = new Action();
            actionForUnknownSubmitter.setCode(
                    SystemConfiguration.getInstance().getQaEventActionCodeForRequestUnknownSubmitter());
            actionForUnknownSubmitter = actionDAO.getActionByCode(actionForUnknownSubmitter);
            // end bugzilla 2028

            for (int i = 0; i < allAnalysesForSample.size(); i++) {
                Analysis analysis = (Analysis) allAnalysesForSample.get(i);
                // bugzilla 2028 QA_EVENT COLLECTIONDATE
                if (sample.getCollectionDate() == null) {
                    AnalysisQaEvent analysisQaEvent = new AnalysisQaEvent();
                    analysisQaEvent.setAnalysis(analysis);
                    analysisQaEvent.setQaEvent(qaEventForNoCollectionDate);
                    analysisQaEvent = analysisQaEventDAO
                            .getAnalysisQaEventByAnalysisAndQaEvent(analysisQaEvent);

                    if (analysisQaEvent == null) {
                        analysisQaEvent = new AnalysisQaEvent();
                        analysisQaEvent.setAnalysis(analysis);
                        analysisQaEvent.setQaEvent(qaEventForNoCollectionDate);
                        analysisQaEvent.setCompletedDate(null);
                        analysisQaEvent.setSysUserId(sysUserId);
                        analysisQaEventDAO.insertData(analysisQaEvent);
                    } else {
                        if (analysisQaEvent.getCompletedDate() != null) {
                            analysisQaEvent.setCompletedDate(null);
                            analysisQaEvent.setSysUserId(sysUserId);
                            analysisQaEventDAO.updateData(analysisQaEvent);
                        }

                    }
                } else {
                    AnalysisQaEvent analysisQaEvent = new AnalysisQaEvent();
                    analysisQaEvent.setAnalysis(analysis);
                    analysisQaEvent.setQaEvent(qaEventForNoCollectionDate);
                    analysisQaEvent = analysisQaEventDAO
                            .getAnalysisQaEventByAnalysisAndQaEvent(analysisQaEvent);

                    // if we don't find a record in ANALYSIS_QAEVENT (or
                    // completed date is not null) then this is already
                    // fixed
                    if (analysisQaEvent != null && analysisQaEvent.getCompletedDate() == null) {
                        AnalysisQaEventAction analysisQaEventAction = new AnalysisQaEventAction();
                        analysisQaEventAction.setAnalysisQaEvent(analysisQaEvent);
                        analysisQaEventAction.setAction(actionForNoCollectionDate);
                        analysisQaEventAction = analysisQaEventActionDAO
                                .getAnalysisQaEventActionByAnalysisQaEventAndAction(analysisQaEventAction);

                        // if we found a record in ANALYSIS_QAEVENT_ACTION
                        // then this has been fixed
                        if (analysisQaEventAction == null) {
                            // insert a record in ANALYSIS_QAEVENT_ACTION
                            AnalysisQaEventAction analQaEventAction = new AnalysisQaEventAction();
                            analQaEventAction.setAnalysisQaEvent(analysisQaEvent);
                            analQaEventAction.setAction(actionForNoCollectionDate);
                            analQaEventAction.setCreatedDateForDisplay(dateAsText);
                            analQaEventAction.setSysUserId(sysUserId);
                            //bugzilla 2496
                            analQaEventAction.setSystemUser(systemUser);
                            analysisQaEventActionDAO.insertData(analQaEventAction);
                        }
                        // update the found
                        // ANALYSIS_QAEVENT.COMPLETED_DATE with current
                        // date stamp
                        analysisQaEvent.setCompletedDateForDisplay(dateAsText);
                        analysisQaEvent.setSysUserId(sysUserId);
                        analysisQaEventDAO.updateData(analysisQaEvent);
                    }

                }

                // bugzilla 2028 QA_EVENT SAMPLETYPE
                if (typeOfSamp.getDescription().equals(SAMPLE_TYPE_NOT_GIVEN)) {
                    AnalysisQaEvent analysisQaEvent = new AnalysisQaEvent();
                    analysisQaEvent.setAnalysis(analysis);
                    analysisQaEvent.setQaEvent(qaEventForNoSampleType);
                    analysisQaEvent = analysisQaEventDAO
                            .getAnalysisQaEventByAnalysisAndQaEvent(analysisQaEvent);

                    if (analysisQaEvent == null) {
                        analysisQaEvent = new AnalysisQaEvent();
                        analysisQaEvent.setAnalysis(analysis);
                        analysisQaEvent.setQaEvent(qaEventForNoSampleType);
                        analysisQaEvent.setCompletedDate(null);
                        analysisQaEvent.setSysUserId(sysUserId);
                        analysisQaEventDAO.insertData(analysisQaEvent);
                    } else {
                        if (analysisQaEvent.getCompletedDate() != null) {
                            analysisQaEvent.setCompletedDate(null);
                            analysisQaEvent.setSysUserId(sysUserId);
                            analysisQaEventDAO.updateData(analysisQaEvent);
                        }

                    }
                } else {
                    AnalysisQaEvent analysisQaEvent = new AnalysisQaEvent();
                    analysisQaEvent.setAnalysis(analysis);
                    analysisQaEvent.setQaEvent(qaEventForNoSampleType);
                    analysisQaEvent = analysisQaEventDAO
                            .getAnalysisQaEventByAnalysisAndQaEvent(analysisQaEvent);

                    // if we don't find a record in ANALYSIS_QAEVENT (or
                    // completed date is not null) then this is already
                    // fixed
                    if (analysisQaEvent != null && analysisQaEvent.getCompletedDate() == null) {
                        AnalysisQaEventAction analysisQaEventAction = new AnalysisQaEventAction();
                        analysisQaEventAction.setAnalysisQaEvent(analysisQaEvent);
                        analysisQaEventAction.setAction(actionForNoSampleType);
                        analysisQaEventAction = analysisQaEventActionDAO
                                .getAnalysisQaEventActionByAnalysisQaEventAndAction(analysisQaEventAction);

                        // if we found a record in ANALYSIS_QAEVENT_ACTION
                        // then this has been fixed
                        if (analysisQaEventAction == null) {
                            // insert a record in ANALYSIS_QAEVENT_ACTION
                            AnalysisQaEventAction analQaEventAction = new AnalysisQaEventAction();
                            analQaEventAction.setAnalysisQaEvent(analysisQaEvent);
                            analQaEventAction.setAction(actionForNoSampleType);
                            analQaEventAction.setCreatedDateForDisplay(dateAsText);
                            analQaEventAction.setSysUserId(sysUserId);
                            //bugzilla 2496
                            analQaEventAction.setSystemUser(systemUser);
                            analysisQaEventActionDAO.insertData(analQaEventAction);
                        }
                        // update the found
                        // ANALYSIS_QAEVENT.COMPLETED_DATE with current
                        // date stamp
                        analysisQaEvent.setCompletedDateForDisplay(dateAsText);
                        analysisQaEvent.setSysUserId(sysUserId);
                        analysisQaEventDAO.updateData(analysisQaEvent);
                    }

                }

                // bugzilla 2028 QA_EVENT UNKNOWN SUBMITTER
                //bugzilla 2589
                if (submitterNumber
                        .equals(SystemConfiguration.getInstance().getUnknownSubmitterNumberForQaEvent())) {
                    AnalysisQaEvent analysisQaEvent = new AnalysisQaEvent();
                    analysisQaEvent.setAnalysis(analysis);
                    analysisQaEvent.setQaEvent(qaEventForUnknownSubmitter);
                    analysisQaEvent = analysisQaEventDAO
                            .getAnalysisQaEventByAnalysisAndQaEvent(analysisQaEvent);

                    if (analysisQaEvent == null) {
                        analysisQaEvent = new AnalysisQaEvent();
                        analysisQaEvent.setAnalysis(analysis);
                        analysisQaEvent.setQaEvent(qaEventForUnknownSubmitter);
                        analysisQaEvent.setCompletedDate(null);
                        analysisQaEvent.setSysUserId(sysUserId);
                        analysisQaEventDAO.insertData(analysisQaEvent);
                    } else {
                        if (analysisQaEvent.getCompletedDate() != null) {
                            analysisQaEvent.setCompletedDate(null);
                            analysisQaEvent.setSysUserId(sysUserId);
                            analysisQaEventDAO.updateData(analysisQaEvent);
                        }

                    }
                } else {
                    AnalysisQaEvent analysisQaEvent = new AnalysisQaEvent();
                    analysisQaEvent.setAnalysis(analysis);
                    analysisQaEvent.setQaEvent(qaEventForUnknownSubmitter);
                    analysisQaEvent = analysisQaEventDAO
                            .getAnalysisQaEventByAnalysisAndQaEvent(analysisQaEvent);

                    // if we don't find a record in ANALYSIS_QAEVENT (or
                    // completed date is not null) then this is already
                    // fixed
                    if (analysisQaEvent != null && analysisQaEvent.getCompletedDate() == null) {
                        AnalysisQaEventAction analysisQaEventAction = new AnalysisQaEventAction();
                        analysisQaEventAction.setAnalysisQaEvent(analysisQaEvent);
                        analysisQaEventAction.setAction(actionForUnknownSubmitter);
                        analysisQaEventAction = analysisQaEventActionDAO
                                .getAnalysisQaEventActionByAnalysisQaEventAndAction(analysisQaEventAction);

                        // if we found a record in ANALYSIS_QAEVENT_ACTION
                        // then this has been fixed
                        if (analysisQaEventAction == null) {
                            // insert a record in ANALYSIS_QAEVENT_ACTION
                            AnalysisQaEventAction analQaEventAction = new AnalysisQaEventAction();
                            analQaEventAction.setAnalysisQaEvent(analysisQaEvent);
                            analQaEventAction.setAction(actionForUnknownSubmitter);
                            analQaEventAction.setCreatedDateForDisplay(dateAsText);
                            analQaEventAction.setSysUserId(sysUserId);
                            //bugzilla 2496
                            analQaEventAction.setSystemUser(systemUser);
                            analysisQaEventActionDAO.insertData(analQaEventAction);
                        }
                        // update the found
                        // ANALYSIS_QAEVENT.COMPLETED_DATE with current
                        // date stamp
                        analysisQaEvent.setCompletedDateForDisplay(dateAsText);
                        analysisQaEvent.setSysUserId(sysUserId);
                        analysisQaEventDAO.updateData(analysisQaEvent);
                    }
                }

            }
        }

        tx.commit();
        // done updating return to menu
        forward = FWD_CLOSE;

    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("SampleDemographicsUpdateAction", "performAction()", lre.toString());
        tx.rollback();
        // if error then forward to fail and don't update to blank page
        // = false
        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 = testManagementForm.validate(mapping,
            // request);
            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(FWD_FAIL);

    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");
    }

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.testreflex.action.TestReflexAction.java

@SuppressWarnings("unchecked")
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 TestReflex.
    // If there is a parameter present, we should bring up an existing
    // TestReflex to edit.
    String id = request.getParameter(ID);

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

    DynaActionForm dynaForm = (DynaActionForm) form;

    // initialize the form
    dynaForm.initialize(mapping);/* w w w  . j a  v a  2 s  .com*/
    isNew = id == null || id.equals("0");

    TestReflex testReflex = new TestReflex();

    if (!isNew) {

        testReflex.setId(id);
        TestReflexDAO testReflexDAO = new TestReflexDAOImpl();
        testReflexDAO.getData(testReflex);

        // initialize testResultId & testAnalyteId
        // initialize testId & addedTestId
        if (testReflex.getTestResult() != null) {
            testReflex.setTestResultId(testReflex.getTestResult().getId());
        }

        if (testReflex.getTestAnalyte() != null) {
            testReflex.setTestAnalyteId(testReflex.getTestAnalyte().getId());
        }

        if (testReflex.getTest() != null) {
            testReflex.setTestId(testReflex.getTest().getId());
        }

        if (testReflex.getAddedTest() != null) {
            testReflex.setAddedTestId(testReflex.getAddedTest().getId());
        }

        // do we need to enable next or previous?
        List testReflexs = testReflexDAO.getNextTestReflexRecord(testReflex.getId());
        if (testReflexs.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        testReflexs = testReflexDAO.getPreviousTestReflexRecord(testReflex.getId());
        if (testReflexs.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button
    }

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

    // populate form from valueholder
    PropertyUtils.copyProperties(form, testReflex);

    TestDAO testDAO = new TestDAOImpl();
    TestAnalyteDAO testAnalyteDAO = new TestAnalyteDAOImpl();
    TestResultDAO testResultDAO = new TestResultDAOImpl();
    DictionaryDAO dictDAO = new DictionaryDAOImpl();

    //Get tests by user system id
    //bugzilla 2160
    UserTestSectionDAO userTestSectionDAO = new UserTestSectionDAOImpl();
    //2291 replaces 2223 (filter out tests not setup yet
    List tests = userTestSectionDAO.getAllUserTests(request, true);
    ScriptletDAO scriptletDAO = new ScriptletDAOImpl();
    List<Scriptlet> scriptletList = scriptletDAO.getAllScriptlets();

    //bugzilla 1844 - no longer sort by name but by description
    Collections.sort(tests, TestComparator.DESCRIPTION_COMPARATOR);

    List testAnalytes = new ArrayList();
    List testResults = new ArrayList();
    if (testReflex.getTest() != null) {
        testAnalytes = testAnalyteDAO.getAllTestAnalytesPerTest(testReflex.getTest());
        Collections.sort(testAnalytes, TestAnalyteComparator.NAME_COMPARATOR);
    } else {
        // testAnalytes = testAnalyteDAO.getAllTestAnalytes();
    }

    if (testReflex.getTestAnalyte() != null) {
        testResults = testResultDAO.getTestResultsByTestAndResultGroup(testReflex.getTestAnalyte());
    } else {
        // testResults = testResultDAO.getAllTestResults();
    }

    // for testResults load the value field with dict entry if needed
    List newListOfTestResults = new ArrayList();
    for (int i = 0; i < testResults.size(); i++) {
        TestResult tr = new TestResult();
        tr = (TestResult) testResults.get(i);
        if (tr.getTestResultType().equals(SystemConfiguration.getInstance().getDictionaryType())) {
            // get from dictionary
            Dictionary dictionary = new Dictionary();
            dictionary.setId(tr.getValue());
            dictDAO.getData(dictionary);

            //bugzilla 1847: use dictEntryDisplayValue
            tr.setValue(dictionary.getDictEntryDisplayValue());

        }
        newListOfTestResults.add(tr);
    }

    Collections.sort(newListOfTestResults, TestResultComparator.VALUE_COMPARATOR);

    PropertyUtils.setProperty(form, "tests", tests);
    PropertyUtils.setProperty(form, "testAnalytes", testAnalytes);
    PropertyUtils.setProperty(form, "testResults", newListOfTestResults);
    PropertyUtils.setProperty(form, "addedTests", tests);
    PropertyUtils.setProperty(form, "actionScriptlets", scriptletList);

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.testreflex.action.TestReflexUpdateAction.java

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 TestReflex.
    // If there is a parameter present, we should bring up an existing
    // TestReflex to edit.

    String forward = FWD_SUCCESS;
    request.setAttribute(ALLOW_EDITS_KEY, "true");
    request.setAttribute(PREVIOUS_DISABLED, "false");
    request.setAttribute(NEXT_DISABLED, "false");
    TestDAO testDAO = new TestDAOImpl();
    ScriptletDAO scriptletDAO = new ScriptletDAOImpl();

    BaseActionForm dynaForm = (BaseActionForm) form;

    String id = request.getParameter(ID);
    isNew = StringUtil.isNullorNill(id) || "0".equals(id);

    useSecondTest = (Boolean) dynaForm.get("useSecondTest");

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

    try {// w  w w .j a  v a  2s.c o  m
        errors = validateAll(request, errors, dynaForm);
    } catch (Exception e) {
        // bugzilla 2154
        LogEvent.logError("TestReflexUpdateAction", "performAction()", e.toString());
        ActionError error = new ActionError("errors.ValidationException", null, null);
        errors.add(ActionMessages.GLOBAL_MESSAGE, error);
    }

    if (errors != null && errors.size() > 0) {
        saveErrors(request, errors);
        return mapping.findForward(FWD_FAIL);
    }

    String start = (String) request.getParameter("startingRecNo");
    String direction = (String) request.getParameter("direction");

    TestReflex testReflex = new TestReflex();
    TestReflex secondTestReflex = null;

    String loggedOnUserId = getSysUserId(request);

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

    Test reflexTest = loadTest(testDAO, dynaForm.getString("addedTestId"));
    Scriptlet reflexScriptlet = loadScriptlet(scriptletDAO, dynaForm.getString("actionScriptletId"));

    loadPrimaryTestReflex(testDAO, dynaForm, testReflex, loggedOnUserId, reflexTest, reflexScriptlet);

    if (useSecondTest) {
        secondTestReflex = new TestReflex();
        loadSecondaryTestReflex(testDAO, dynaForm, secondTestReflex, loggedOnUserId, reflexTest);
    }

    try {

        TestReflexDAO testReflexDAO = new TestReflexDAOImpl();

        if (!isNew) {
            testReflexDAO.updateData(testReflex);
        } else {
            testReflexDAO.insertData(testReflex);

            if (secondTestReflex != null) {

                secondTestReflex.setSiblingReflexId(testReflex.getId());
                testReflexDAO.insertData(secondTestReflex);

                testReflex.setSiblingReflexId(secondTestReflex.getId());
                testReflexDAO.updateData(testReflex);
            }
        }

        tx.commit();
    } catch (LIMSRuntimeException lre) {
        // bugzilla 2154
        LogEvent.logError("TestReflexUpdateAction", "performAction()", lre.toString());
        tx.rollback();
        errors = new ActionMessages();
        java.util.Locale locale = (java.util.Locale) request.getSession()
                .getAttribute("org.apache.struts.action.LOCALE");
        ActionError error = null;
        if (lre.getException() instanceof org.hibernate.StaleObjectStateException) {
            error = new ActionError("errors.OptimisticLockException", null, null);
        } else {
            if (lre.getException() instanceof LIMSDuplicateRecordException) {
                String messageKey = "testreflex.testreflex";
                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);

        request.setAttribute(PREVIOUS_DISABLED, "true");
        request.setAttribute(NEXT_DISABLED, "true");
        forward = FWD_FAIL;

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

    // initialize the form
    dynaForm.initialize(mapping);
    PropertyUtils.copyProperties(dynaForm, testReflex);

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

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

    }

    if (isNew) {
        forward = FWD_SUCCESS_INSERT;
    }

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

}

From source file:us.mn.state.health.lims.testreflex.daoimpl.TestReflexDAOImpl.java

public void getData(TestReflex testReflex) throws LIMSRuntimeException {
    try {/*from  w w w .j av a  2s  .co m*/
        TestReflex tr = (TestReflex) HibernateUtil.getSession().get(TestReflex.class, testReflex.getId());
        HibernateUtil.getSession().flush();
        HibernateUtil.getSession().clear();
        if (tr != null) {
            PropertyUtils.copyProperties(testReflex, tr);
        } else {
            testReflex.setId(null);
        }
    } catch (Exception e) {
        // bugzilla 2154
        LogEvent.logError("TestReflexDAOImpl", "getData()", e.toString());
        throw new LIMSRuntimeException("Error in TestReflex getData()", e);
    }
}

From source file:us.mn.state.health.lims.testresult.action.TestResultAction.java

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 TestResult.
    // If there is a parameter present, we should bring up an existing
    // TestResult to edit.
    String id = request.getParameter(ID);

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

    DynaActionForm dynaForm = (DynaActionForm) form;

    // initialize the form
    dynaForm.initialize(mapping);/*from   www. j a  v a 2s  .  com*/

    TestResult testResult = new TestResult();

    if ((id != null) && (!"0".equals(id))) { // this is an existing
        // testResult

        testResult.setId(id);
        TestResultDAO testResultDAO = new TestResultDAOImpl();
        testResultDAO.getData(testResult);

        // initialize testName
        if (testResult.getTest() != null) {
            testResult.setTestName(TestService.getLocalizedTestName(testResult.getTest()));
        }

        // initialize scriptletName
        if (testResult.getScriptlet() != null) {
            testResult.setScriptletName(testResult.getScriptlet().getScriptletName());
        }

        isNew = false; // this is to set correct page title

        // do we need to enable next or previous?
        List testResults = testResultDAO.getNextTestResultRecord(testResult.getId());
        if (testResults.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        testResults = testResultDAO.getPreviousTestResultRecord(testResult.getId());
        if (testResults.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button
    } else { // this is a new testResult

        isNew = true; // this is to set correct page title
    }

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

    // populate form from valueholder
    PropertyUtils.copyProperties(form, testResult);

    return mapping.findForward(forward);
}