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

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

Introduction

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

Prototype

public static void setProperty(Object bean, String name, Object value)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException 

Source Link

Document

Set the value of the specified property of the specified bean, no matter which property reference format is used, with no type conversions.

For more details see PropertyUtilsBean.

Usage

From source file:us.mn.state.health.lims.qaevent.action.QaEventsEntryViewAction.java

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

    String forward = FWD_SUCCESS;
    BaseActionForm dynaForm = (BaseActionForm) form;
    HttpSession session = request.getSession();

    //bugzilla 2501
    String multipleSampleMode = (String) dynaForm.get("multipleSampleMode");
    String qaEventCategoryId = (String) dynaForm.get("selectedQaEventsCategoryId");
    String currentCount = (String) dynaForm.get("currentCount");
    String totalCount = (String) dynaForm.get("totalCount");
    //bugzilla 2502
    String viewMode = (String) dynaForm.get("viewMode");
    String fullScreenSection = (String) dynaForm.get("fullScreenSection");
    //bugzilla 2501
    DictionaryDAO dictionaryDAO = new DictionaryDAOImpl();
    List categoryDictionaries = dictionaryDAO.getDictionaryEntrysByCategory(
            SystemConfiguration.getInstance().getQaEventDictionaryCategoryCategory());
    List testQaEvents = new ArrayList();
    //bugzila 2501
    List sampleQaEvents = new ArrayList();

    //get accession number from one of these 3 in this order
    //1) if from PositionToRecord: attribute
    //2) if passing in accession number from another module: parameter
    //3) else form

    //if accession number is an attribute -> then we are coming from PositionToRecord and also need the requestedAccessionNumber to display warning if needed
    String requestedAccessionNumber = (String) request.getAttribute(ACCESSION_NUMBER_REQUESTED);
    String accessionNumber = (String) request.getAttribute(ACCESSION_NUMBER);
    if (StringUtil.isNullorNill(accessionNumber)) {
        accessionNumber = (String) request.getParameter(ACCESSION_NUMBER);
    }//from w  w  w.  j a  va2 s . c  om
    if (StringUtil.isNullorNill(accessionNumber)) {
        accessionNumber = (String) dynaForm.get("accessionNumber");
    }

    //this was set in PositionToRecord action
    String nextDisabled = (String) request.getAttribute(NEXT_DISABLED);
    String previousDisabled = (String) request.getAttribute(PREVIOUS_DISABLED);

    // server side validation of accessionNumber
    //this may already have an error or warning from another action
    ActionMessages errors = (ActionMessages) request.getAttribute(Globals.ERROR_KEY);
    if (errors == null) {
        errors = new ActionMessages();
    }

    try {
        //only do this if we don't have an error already to display:
        if (errors == null || errors.size() <= 0) {
            errors = validateAccessionNumber(request, errors, dynaForm);
        }
    } catch (Exception e) {
        //bugzilla 2154
        LogEvent.logError("ActionUpdateAction", "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);
        request.setAttribute(ALLOW_EDITS_KEY, "false");
        //load collection for fail page
        PropertyUtils.setProperty(dynaForm, "categoryDictionaries", categoryDictionaries);
        //bugzilla 2501
        if (!StringUtil.isNullorNill(requestedAccessionNumber) && !StringUtil.isNullorNill(accessionNumber)
                && !requestedAccessionNumber.equals(accessionNumber)) {
            forward = FWD_FAIL;
        } else {
            return mapping.findForward(FWD_FAIL);
        }
    }

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

    Sample sample = new Sample();
    SampleDAO sampleDAO = new SampleDAOImpl();
    sample.setAccessionNumber(accessionNumber);

    try {
        sampleDAO.getSampleByAccessionNumber(sample);

    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("ActionUpdateAction", "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);

    }

    //bugzilla 2566 for now qa events is for human and newborn
    Patient patient = new Patient();
    Person person = new Person();
    SampleHuman sampleHuman = new SampleHuman();
    SampleOrganization sampleOrganization = new SampleOrganization();
    Organization organization = new Organization();
    List sampleProjects = new ArrayList();
    Project project = new Project();
    Project project2 = new Project();
    SampleItem sampleItem = new SampleItem();
    List analyses = new ArrayList();
    String[] selectedAnalysisQaEventIdsForCompletion = null;
    //bugzilla 2501
    String[] selectedSampleQaEventIdsForCompletion = null;

    try {

        PatientDAO patientDAO = new PatientDAOImpl();
        SampleItemDAO sampleItemDAO = new SampleItemDAOImpl();
        SampleHumanDAO sampleHumanDAO = new SampleHumanDAOImpl();
        SampleOrganizationDAO sampleOrganizationDAO = new SampleOrganizationDAOImpl();
        AnalysisDAO analysisDAO = new AnalysisDAOImpl();
        AnalysisQaEventDAO analysisQaEventDAO = new AnalysisQaEventDAOImpl();
        //bugzilla 2501
        SampleQaEventDAO sampleQaEventDAO = new SampleQaEventDAOImpl();
        AnalysisQaEventActionDAO analysisQaEventActionDAO = new AnalysisQaEventActionDAOImpl();
        SampleQaEventActionDAO sampleQaEventActionDAO = new SampleQaEventActionDAOImpl();
        NoteDAO noteDAO = new NoteDAOImpl();

        if (!StringUtil.isNullorNill(sample.getId())) {
            sampleHuman.setSampleId(sample.getId());
            sampleHumanDAO.getDataBySample(sampleHuman);
            sampleOrganization.setSampleId(sample.getId());
            sampleOrganizationDAO.getDataBySample(sampleOrganization);
            sampleItem.setSample(sample);
            sampleItemDAO.getDataBySample(sampleItem);

            if (sampleHuman != null) {
                if (sampleHuman.getPatientId() != null) {
                    patient.setId(sampleHuman.getPatientId());
                    patientDAO.getData(patient);
                    person = patient.getPerson();
                }
            }
            //bugzilla 2227
            analyses = analysisDAO.getMaxRevisionAnalysesBySample(sampleItem);
        }
        organization = (Organization) sampleOrganization.getOrganization();
        sampleProjects = sample.getSampleProjects();

        if (sampleProjects != null && sampleProjects.size() > 0) {
            SampleProject sampleProject = (SampleProject) sampleProjects.get(0);
            project = sampleProject.getProject();
            if (sampleProjects.size() > 1) {
                SampleProject sampleProject2 = (SampleProject) sampleProjects.get(1);
                project2 = sampleProject2.getProject();
            }
        }

        //bugzilla 2500 get sample qa events
        SampleQaEvent sampleQaEvent = new SampleQaEvent();
        sampleQaEvent.setSample(sample);

        List allQaEventsForSample = sampleQaEventDAO.getSampleQaEventsBySample(sampleQaEvent);

        List actionsForSampleQaEvent = new ArrayList();

        for (int j = 0; j < allQaEventsForSample.size(); j++) {
            SampleQaEvent sampQaEvent = (SampleQaEvent) allQaEventsForSample.get(j);
            // get action/note info for each qaEvent for this test
            SampleQaEventAction sampleQaEventAction = new SampleQaEventAction();
            sampleQaEventAction.setSampleQaEvent(sampQaEvent);
            actionsForSampleQaEvent = sampleQaEventActionDAO
                    .getSampleQaEventActionsBySampleQaEvent(sampleQaEventAction);

            Sample_QaEvent_Actions sampleQaEventActions = new Sample_QaEvent_Actions();
            sampleQaEventActions.setQaEvent(sampQaEvent);
            // convert list to array
            SampleQaEventAction[] actionsForSampleQaEventArray = null;
            if (actionsForSampleQaEvent != null && actionsForSampleQaEvent.size() > 0) {
                actionsForSampleQaEventArray = new SampleQaEventAction[actionsForSampleQaEvent.size()];
                for (int x = 0; x < actionsForSampleQaEvent.size(); x++) {
                    actionsForSampleQaEventArray[x] = (SampleQaEventAction) actionsForSampleQaEvent.get(x);
                }

            }

            sampleQaEventActions.setActions(actionsForSampleQaEventArray);
            List[] notes = null;

            if (actionsForSampleQaEventArray != null) {
                // now get the notes for this action if exist
                Note note = new Note();
                List notesBySampleQaEventAction = new ArrayList();
                notes = new ArrayList[actionsForSampleQaEventArray.length];

                for (int x = 0; x < actionsForSampleQaEventArray.length; x++) {
                    SampleQaEventAction act = (SampleQaEventAction) actionsForSampleQaEventArray[x];
                    note.setReferenceId(act.getId());
                    //bugzilla 2571 go through ReferenceTablesDAO to get reference tables info
                    ReferenceTables referenceTables = new ReferenceTables();
                    referenceTables
                            .setId(SystemConfiguration.getInstance().getSampleQaEventActionReferenceTableId());
                    //bugzilla 2571 go through ReferenceTablesDAO to get reference tables info
                    note.setReferenceTables(referenceTables);
                    notesBySampleQaEventAction = noteDAO.getAllNotesByRefIdRefTable(note);
                    if (notesBySampleQaEventAction != null && notesBySampleQaEventAction.size() > 0) {
                        notes[x] = notesBySampleQaEventAction;
                    } else {
                        notes[x] = new ArrayList();
                    }

                }
            }
            sampleQaEventActions.setNotes(notes);
            sampleQaEvents.add(sampleQaEventActions);

        }

        //end bugzilla 2500

        for (int i = 0; i < analyses.size(); i++) {
            Analysis analysis = (Analysis) analyses.get(i);
            AnalysisQaEvent analysisQaEvent = new AnalysisQaEvent();
            analysisQaEvent.setAnalysis(analysis);
            List allQaEventsForTest = analysisQaEventDAO.getAnalysisQaEventsByAnalysis(analysisQaEvent);

            List qaEventsForTest = new ArrayList();
            List actionsForQaEvent = new ArrayList();

            for (int j = 0; j < allQaEventsForTest.size(); j++) {
                AnalysisQaEvent aQaEvent = (AnalysisQaEvent) allQaEventsForTest.get(j);
                // get action/note info for each qaEvent for this test
                AnalysisQaEventAction analysisQaEventAction = new AnalysisQaEventAction();
                analysisQaEventAction.setAnalysisQaEvent(aQaEvent);
                actionsForQaEvent = analysisQaEventActionDAO
                        .getAnalysisQaEventActionsByAnalysisQaEvent(analysisQaEventAction);

                //bugzilla 2501
                Test_QaEvent_Actions analysisQaEventActions = new Test_QaEvent_Actions();
                analysisQaEventActions.setQaEvent(aQaEvent);
                // convert list to array
                AnalysisQaEventAction[] actionsForQaEventArray = null;
                if (actionsForQaEvent != null && actionsForQaEvent.size() > 0) {
                    actionsForQaEventArray = new AnalysisQaEventAction[actionsForQaEvent.size()];
                    for (int x = 0; x < actionsForQaEvent.size(); x++) {
                        actionsForQaEventArray[x] = (AnalysisQaEventAction) actionsForQaEvent.get(x);
                    }

                }

                //bugzilla 2501
                analysisQaEventActions.setActions(actionsForQaEventArray);
                List[] notes = null;

                if (actionsForQaEventArray != null) {
                    // now get the notes for this action if exist
                    Note note = new Note();
                    List notesByAnalysisQaEventAction = new ArrayList();
                    notes = new ArrayList[actionsForQaEventArray.length];

                    for (int x = 0; x < actionsForQaEventArray.length; x++) {
                        AnalysisQaEventAction act = (AnalysisQaEventAction) actionsForQaEventArray[x];
                        note.setReferenceId(act.getId());
                        //bugzilla 2571 go through ReferenceTablesDAO to get reference tables info
                        ReferenceTables referenceTables = new ReferenceTables();
                        referenceTables.setId(SystemConfiguration.getInstance().getInstance()
                                .getAnalysisQaEventActionReferenceTableId());
                        //bugzilla 2571 go through ReferenceTablesDAO to get reference tables info
                        note.setReferenceTables(referenceTables);
                        notesByAnalysisQaEventAction = noteDAO.getAllNotesByRefIdRefTable(note);
                        if (notesByAnalysisQaEventAction != null && notesByAnalysisQaEventAction.size() > 0) {
                            notes[x] = notesByAnalysisQaEventAction;
                        } else {
                            notes[x] = new ArrayList();
                        }

                    }
                }
                //bugzilla 2501
                analysisQaEventActions.setNotes(notes);
                qaEventsForTest.add(analysisQaEventActions);

            }

            Test_QaEvents tQaEvents = new Test_QaEvents();
            tQaEvents.setAnalysis(analysis);
            tQaEvents.setQaEvents(qaEventsForTest);

            testQaEvents.add(tQaEvents);

        }
        //bugzilla 1856
        Collections.sort(testQaEvents, Test_QaEventComparator.DESCRIPTION_COMPARATOR);

    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("ActionUpdateAction", "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);

    }

    // populate form from valueholder
    PropertyUtils.setProperty(dynaForm, "patientFirstName", person.getFirstName());
    PropertyUtils.setProperty(dynaForm, "patientLastName", person.getLastName());
    PropertyUtils.setProperty(dynaForm, "patientId", patient.getExternalId());
    PropertyUtils.setProperty(dynaForm, "birthDateForDisplay", (String) patient.getBirthDateForDisplay());
    TypeOfSample typeOfSample = sampleItem.getTypeOfSample();
    SourceOfSample sourceOfSample = sampleItem.getSourceOfSample();
    if (typeOfSample == null) {
        PropertyUtils.setProperty(dynaForm, "typeOfSample", new TypeOfSample());
    } else {
        PropertyUtils.setProperty(dynaForm, "typeOfSample", typeOfSample);
    }
    if (sourceOfSample == null) {
        PropertyUtils.setProperty(dynaForm, "sourceOfSample", new SourceOfSample());
    } else {
        PropertyUtils.setProperty(dynaForm, "sourceOfSample", sourceOfSample);
    }

    PropertyUtils.setProperty(dynaForm, "sourceOther", sampleItem.getSourceOther());
    PropertyUtils.setProperty(dynaForm, "receivedDateForDisplay", (String) sample.getReceivedDateForDisplay());
    PropertyUtils.setProperty(dynaForm, "collectionDateForDisplay",
            (String) sample.getCollectionDateForDisplay());
    PropertyUtils.setProperty(dynaForm, "referredCultureFlag", (String) sample.getReferredCultureFlag());

    if (organization == null) {
        PropertyUtils.setProperty(dynaForm, "organization", new Organization());
    } else {
        PropertyUtils.setProperty(dynaForm, "organization", organization);
    }

    if (project == null) {
        PropertyUtils.setProperty(dynaForm, "project", new Project());
    } else {
        PropertyUtils.setProperty(dynaForm, "project", project);
    }

    if (project2 == null) {
        PropertyUtils.setProperty(dynaForm, "project2", new Project());
    } else {
        PropertyUtils.setProperty(dynaForm, "project2", project2);
    }
    PropertyUtils.setProperty(dynaForm, "testQaEvents", testQaEvents);
    //bugzilla 2501
    PropertyUtils.setProperty(dynaForm, "categoryDictionaries", categoryDictionaries);

    // reload accession number
    PropertyUtils.setProperty(dynaForm, "accessionNumber", accessionNumber);
    //bug 2566
    //PropertyUtils.setProperty(dynaForm, "domain", domain);

    //bugzilla 2501
    if (StringUtil.isNullorNill(multipleSampleMode)) {
        PropertyUtils.setProperty(dynaForm, "currentCount", "1");
        PropertyUtils.setProperty(dynaForm, "totalCount", "1");
        request.setAttribute(PREVIOUS_DISABLED, TRUE);
        request.setAttribute(NEXT_DISABLED, TRUE);
    } else {
        PropertyUtils.setProperty(dynaForm, "currentCount", currentCount);
        PropertyUtils.setProperty(dynaForm, "totalCount", totalCount);
        PropertyUtils.setProperty(dynaForm, "selectedQaEventsCategoryId", qaEventCategoryId);
        request.setAttribute(PREVIOUS_DISABLED, previousDisabled);
        request.setAttribute(NEXT_DISABLED, nextDisabled);
    }

    //bugzilla 2500
    PropertyUtils.setProperty(dynaForm, "sampleQaEvents", sampleQaEvents);
    PropertyUtils.setProperty(dynaForm, "multipleSampleMode", multipleSampleMode);
    //bugzilla 2502
    //set hidden form variables
    if (!StringUtil.isNullorNill(viewMode)) {
        PropertyUtils.setProperty(dynaForm, "viewMode", viewMode);
    } else {
        PropertyUtils.setProperty(dynaForm, "viewMode", QAEVENTS_ENTRY_NORMAL_VIEW);
    }

    if (!StringUtil.isNullorNill(fullScreenSection)) {
        PropertyUtils.setProperty(dynaForm, "fullScreenSection", fullScreenSection);
    } else {
        PropertyUtils.setProperty(dynaForm, "fullScreenSection",
                QAEVENTS_ENTRY_FULL_SCREEN_VIEW_SAMPLE_SECTION);
    }

    //this request attribute is used to find out if we need to disable category dropdown on the form
    if (!StringUtil.isNullorNill(multipleSampleMode)) {
        request.setAttribute(MULTIPLE_SAMPLE_MODE, TRUE);
    } else {
        request.setAttribute(MULTIPLE_SAMPLE_MODE, FALSE);
    }

    //bugzilla 2502
    if (!StringUtil.isNullorNill(viewMode)) {
        request.setAttribute(QAEVENTS_ENTRY_PARAM_VIEW_MODE, viewMode);
    } else {
        request.setAttribute(QAEVENTS_ENTRY_PARAM_VIEW_MODE, QAEVENTS_ENTRY_NORMAL_VIEW);
    }

    //if in full screen mode then default is sample section maximized
    if (!StringUtil.isNullorNill(fullScreenSection)) {
        request.setAttribute(QAEVENTS_ENTRY_FULL_SCREEN_VIEW_SECTION, fullScreenSection);
    } else {
        request.setAttribute(QAEVENTS_ENTRY_FULL_SCREEN_VIEW_SECTION,
                QAEVENTS_ENTRY_FULL_SCREEN_VIEW_SAMPLE_SECTION);
    }

    //bugzilla 2504
    forward = FWD_SUCCESS;

    if (viewMode != null && viewMode.equals(QAEVENTS_ENTRY_FULL_SCREEN_VIEW)) {
        if (fullScreenSection != null
                && fullScreenSection.equals(QAEVENTS_ENTRY_FULL_SCREEN_VIEW_SAMPLE_SECTION)) {
            forward = FWD_SUCCESS_FULL_SCREEN_VIEW_SAMPLE_SECTION;
        } else {
            forward = FWD_SUCCESS_FULL_SCREEN_VIEW_TEST_SECTION;
        }
    }

    //bugzilla 2622
    //forward = FWD_SUCCESS;
    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.qaevent.action.QaEventsEntryViewLineListingAction.java

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

    String forward = FWD_SUCCESS;
    BaseActionForm dynaForm = (BaseActionForm) form;
    ActionMessages errors = null;//from  ww w  .j  a va  2  s . com

    HttpSession session = request.getSession();

    String selectedCategoryIdFromRouting = (String) session
            .getAttribute(QAEVENTS_ENTRY_LINELISTING_PARAM_QAEVENT_CATEGORY_ID);
    String viewModeFromRouting = (String) session.getAttribute(QAEVENTS_ENTRY_PARAM_VIEW_MODE);
    //bugzilla 2502
    String fullScreenSectionFromRouting = (String) session
            .getAttribute(QAEVENTS_ENTRY_FULL_SCREEN_VIEW_SECTION);

    String qaEventCategoryId = "";
    //initialize to NORMAL MODE
    String viewMode = QAEVENTS_ENTRY_NORMAL_VIEW;
    //initialize to SAMPLE SECTION MAXIMIZED for full screen view
    String fullScreenSection = QAEVENTS_ENTRY_FULL_SCREEN_VIEW_SAMPLE_SECTION;
    if (!StringUtil.isNullorNill(selectedCategoryIdFromRouting)) {
        qaEventCategoryId = selectedCategoryIdFromRouting;
        //bugzilla 2504
        if (!StringUtil.isNullorNill(viewModeFromRouting))
            viewMode = viewModeFromRouting;
        if (!StringUtil.isNullorNill(fullScreenSectionFromRouting))
            fullScreenSection = fullScreenSectionFromRouting;
        session.setAttribute(QAEVENTS_ENTRY_LINELISTING_PARAM_QAEVENT_CATEGORY_ID, null);
        //bugzilla 2504
        session.setAttribute(QAEVENTS_ENTRY_PARAM_VIEW_MODE, null);
        //bugzilla 2502
        session.setAttribute(QAEVENTS_ENTRY_FULL_SCREEN_VIEW_SECTION, null);
    } else {
        qaEventCategoryId = (String) dynaForm.get("selectedQaEventsCategoryId");
        //bugzila 2504
        if (request.getParameter(QAEVENTS_ENTRY_PARAM_VIEW_MODE) != null) {
            viewMode = (String) request.getParameter(QAEVENTS_ENTRY_PARAM_VIEW_MODE);
        }
        if (request.getParameter(QAEVENTS_ENTRY_FULL_SCREEN_VIEW_SECTION) != null) {
            fullScreenSection = (String) request.getParameter(QAEVENTS_ENTRY_FULL_SCREEN_VIEW_SECTION);
        }
    }

    //bugzilla 2566 for now qa events is for human and newborn
    String accessionNumber = request.getParameter(ACCESSION_NUMBER);
    String totalRecords = "0";

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

    List samples = new ArrayList();
    List samplesWithPendingQaEvents = new ArrayList();
    List categoryDictionaries = new ArrayList();

    try {
        SampleDAO sampleDAO = new SampleDAOImpl();
        Sample samp = new Sample();
        //bugzilla 2566 for now qa events is for human and newborn
        //added filterbyDomain parameter
        if (!StringUtil.isNullorNill(qaEventCategoryId)) {
            samples = sampleDAO.getSamplesWithPendingQaEvents(samp, true, qaEventCategoryId, false);
        } else {
            samples = sampleDAO.getSamplesWithPendingQaEvents(samp, false, null, false);
        }

        DictionaryDAO dictionaryDAO = new DictionaryDAOImpl();
        categoryDictionaries = dictionaryDAO.getDictionaryEntrysByCategory(
                SystemConfiguration.getInstance().getQaEventDictionaryCategoryCategory());

        PatientDAO patientDAO = new PatientDAOImpl();
        SampleItemDAO sampleItemDAO = new SampleItemDAOImpl();
        SampleHumanDAO sampleHumanDAO = new SampleHumanDAOImpl();
        SampleOrganizationDAO sampleOrganizationDAO = new SampleOrganizationDAOImpl();
        AnalysisDAO analysisDAO = new AnalysisDAOImpl();
        AnalysisQaEventDAO analysisQaEventDAO = new AnalysisQaEventDAOImpl();
        SampleQaEventDAO sampleQaEventDAO = new SampleQaEventDAOImpl();

        if (samples != null && samples.size() > 0) {
            for (int x = 0; x < samples.size(); x++) {
                Sample sample = (Sample) samples.get(x);

                List sampleQaEvents = new ArrayList();
                List testQaEvents = new ArrayList();

                QaEventLineListingViewData record = new QaEventLineListingViewData();

                Patient patient = new Patient();
                Person person = new Person();
                SampleHuman sampleHuman = new SampleHuman();
                SampleItem sampleItem = new SampleItem();
                List analyses = new ArrayList();

                if (!StringUtil.isNullorNill(sample.getId())) {
                    sampleHuman.setSampleId(sample.getId());
                    sampleHumanDAO.getDataBySample(sampleHuman);
                    sampleItem.setSample(sample);
                    sampleItemDAO.getDataBySample(sampleItem);

                    if (sampleHuman != null) {
                        if (sampleHuman.getPatientId() != null) {
                            patient.setId(sampleHuman.getPatientId());
                            patientDAO.getData(patient);
                            person = patient.getPerson();
                        }
                    }
                    analyses = analysisDAO.getMaxRevisionAnalysesBySample(sampleItem);
                }

                SampleQaEvent sampleQaEvent = new SampleQaEvent();
                sampleQaEvent.setSample(sample);

                List allQaEventsForSample = sampleQaEventDAO.getSampleQaEventsBySample(sampleQaEvent);

                for (int i = 0; i < analyses.size(); i++) {
                    Analysis analysis = (Analysis) analyses.get(i);
                    AnalysisQaEvent analysisQaEvent = new AnalysisQaEvent();
                    analysisQaEvent.setAnalysis(analysis);
                    List allQaEventsForTest = analysisQaEventDAO.getAnalysisQaEventsByAnalysis(analysisQaEvent);
                    testQaEvents.addAll(allQaEventsForTest);
                }

                record.setSample(sample);
                record.setPatient(patient);
                record.setTestQaEvents(testQaEvents);
                record.setSampleQaEvents(allQaEventsForSample);
                samplesWithPendingQaEvents.add(record);
            }

        }
    } catch (LIMSRuntimeException lre) {
        // bugzilla 2154
        LogEvent.logError("QaEventsEntryViewLineListingAction", "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);

    }

    PropertyUtils.setProperty(dynaForm, "categoryDictionaries", categoryDictionaries);
    PropertyUtils.setProperty(dynaForm, "samplesWithPendingQaEvents", samplesWithPendingQaEvents);
    if (samplesWithPendingQaEvents != null && samplesWithPendingQaEvents.size() > 0) {
        PropertyUtils.setProperty(dynaForm, "totalCount", String.valueOf(samplesWithPendingQaEvents.size()));
    } else {
        PropertyUtils.setProperty(dynaForm, "totalCount", "0");
    }
    PropertyUtils.setProperty(dynaForm, "selectedQaEventsCategoryId", qaEventCategoryId);

    forward = FWD_SUCCESS;

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.qaevent.action.QaEventUpdateAction.java

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

    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;//from w ww.  ja  va 2s.c o  m
    } else {
        isNew = false;
    }

    BaseActionForm dynaForm = (BaseActionForm) form;

    // server-side validation (validation.xml)
    ActionMessages errors = dynaForm.validate(mapping, request);
    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 start = (String) request.getParameter("startingRecNo");
    String direction = (String) request.getParameter("direction");

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

    // populate valueholder from form
    PropertyUtils.copyProperties(qaEvent, dynaForm);
    String selectedTestId = dynaForm.getString("selectedTestId");
    // Bugzilla 2246 added variable selectedTypeId
    String selectedTypeId = dynaForm.getString("selectedTypeId");
    //bugzilla 2506      
    String selectedCategoryId = dynaForm.getString("selectedCategoryId");

    QaEventDAO qaEventDAO = new QaEventDAOImpl();
    TestDAO testDAO = new TestDAOImpl();
    DictionaryDAO dictionaryDAO = new DictionaryDAOImpl();

    try {

        if (!StringUtil.isNullorNill(selectedTestId)) {
            Test selectedTest = new Test();
            selectedTest.setId(selectedTestId);
            testDAO.getData(selectedTest);
            qaEvent.setTest(selectedTest);
        }
        // Bugzilla 2246 set the type value for the valueholder 
        if (!StringUtil.isNullorNill(selectedTypeId)) {
            Dictionary selectedDictionary = new Dictionary();
            selectedDictionary.setId(selectedTypeId);
            dictionaryDAO.getData(selectedDictionary);
            qaEvent.setType(selectedDictionary);
        }

        // Bugzilla 2506 set the category value for the valueholder 
        if (!StringUtil.isNullorNill(selectedCategoryId)) {
            Dictionary selectedDictionary = new Dictionary();
            selectedDictionary.setId(selectedCategoryId);
            dictionaryDAO.getData(selectedDictionary);
            qaEvent.setCategory(selectedDictionary);
        }

        if (!isNew) {
            // UPDATE
            qaEventDAO.updateData(qaEvent);
        } else {
            // INSERT
            qaEventDAO.insertData(qaEvent);
        }
        tx.commit();
    } catch (LIMSRuntimeException lre) {
        //bugzilla 2154
        LogEvent.logError("QaEventUpdateAction", "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 = "qaevent.name";
                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");
        forward = FWD_FAIL;

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

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

    //Get tests by user system id
    //bugzilla 2160
    UserTestSectionDAO userTestSectionDAO = new UserTestSectionDAOImpl();
    //bugzilla 2291
    List tests = userTestSectionDAO.getAllUserTests(request, true);
    //bugzilla 1856
    Collections.sort(tests, TestComparator.DESCRIPTION_COMPARATOR);
    List dictionaries = dictionaryDAO.getDictionaryEntrysByCategory(
            SystemConfiguration.getInstance().getQaEventDictionaryCategoryType());
    //bugzilla 2506
    List dictionaries2 = dictionaryDAO.getDictionaryEntrysByCategory(
            SystemConfiguration.getInstance().getQaEventDictionaryCategoryCategory());

    // repopulate the form from valueholder
    PropertyUtils.copyProperties(dynaForm, qaEvent);
    PropertyUtils.setProperty(form, "tests", tests);
    PropertyUtils.setProperty(form, "dictionaries", dictionaries);
    //bugzilla 2506
    PropertyUtils.setProperty(form, "dictionaries2", dictionaries2);

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

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

    }

    if (isNew)
        forward = FWD_SUCCESS_INSERT;
    return getForward(mapping.findForward(forward), id, start, direction);
}

From source file:us.mn.state.health.lims.qaevent.action.retroCI.NonConformityAction.java

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

    useSiteList = FormFields.getInstance().useField(Field.NON_CONFORMITY_SITE_LIST);

    BaseActionForm dynaForm = (BaseActionForm) form;

    dynaForm.initialize(mapping);/*from ww w .  j a  v a 2 s.  c  om*/

    readOnly = Boolean.FALSE;

    request.getSession().setAttribute(SAVE_DISABLED, TRUE);

    String labNumber = request.getParameter("labNo");

    if (!GenericValidator.isBlankOrNull(labNumber)) {

        sample = getSampleForLabNumber(labNumber);

        sampleFound = !(sample == null || GenericValidator.isBlankOrNull(sample.getId()));

        PropertyUtils.setProperty(dynaForm, "labNo", labNumber);
        Date today = Calendar.getInstance().getTime();
        PropertyUtils.setProperty(dynaForm, "date", DateUtil.formatDateAsText(today));
        if (FormFields.getInstance().useField(Field.QATimeWithDate)) {
            PropertyUtils.setProperty(dynaForm, "time", DateUtil.nowTimeAsText());
        }

        if (sampleFound) {
            createForExistingSample(dynaForm);
        }

        setProjectList(dynaForm);

        PropertyUtils.setProperty(dynaForm, "sampleItemsTypeOfSampleIds", getSampleTypeOfSamplesString());
        PropertyUtils.setProperty(dynaForm, "sections", createSectionList());
        PropertyUtils.setProperty(dynaForm, "qaEventTypes", DisplayListService.getList(ListType.QA_EVENTS));
        PropertyUtils.setProperty(dynaForm, "qaEvents", getSampleQaEventItems(sample));

        PropertyUtils.setProperty(dynaForm, "typeOfSamples", DisplayListService.getList(ListType.SAMPLE_TYPE));

        PropertyUtils.setProperty(dynaForm, "readOnly", readOnly);
        PropertyUtils.setProperty(dynaForm, "siteList",
                DisplayListService.getFreshList(ListType.SAMPLE_PATIENT_REFERRING_CLINIC));
        Provider provider = getProvider();
        if (provider != null) {
            PropertyUtils.setProperty(dynaForm, "providerNew", Boolean.FALSE.toString());
            Person providerPerson = getProviderPerson(provider);
            if (providerPerson != null
                    && !providerPerson.getId().equals(PatientUtil.getUnknownPerson().getId())) {
                PersonService personService = new PersonService(providerPerson);
                PropertyUtils.setProperty(dynaForm, "providerFirstName", personService.getFirstName());
                PropertyUtils.setProperty(dynaForm, "providerLastName", personService.getLastName());
                PropertyUtils.setProperty(dynaForm, "providerWorkPhone", personService.getPhone());
                Map<String, String> addressComponents = personService.getAddressComponents();

                PropertyUtils.setProperty(dynaForm, "providerStreetAddress", addressComponents.get("Street"));
                PropertyUtils.setProperty(dynaForm, "providerCity", addressComponents.get("village"));
                PropertyUtils.setProperty(dynaForm, "providerCommune", addressComponents.get("commune"));
                PropertyUtils.setProperty(dynaForm, "providerDepartment", addressComponents.get("department"));
            }
        } else {
            PropertyUtils.setProperty(dynaForm, "providerNew", Boolean.TRUE.toString());
            PropertyUtils.setProperty(dynaForm, "requesterSampleID", "");
            PropertyUtils.setProperty(dynaForm, "providerFirstName", "");
            PropertyUtils.setProperty(dynaForm, "providerLastName", "");
            PropertyUtils.setProperty(dynaForm, "providerWorkPhone", "");
        }

        PropertyUtils.setProperty(dynaForm, "departments",
                DisplayListService.getList(ListType.HAITI_DEPARTMENTS));
    }

    return mapping.findForward(FWD_SUCCESS);
}

From source file:us.mn.state.health.lims.qaevent.action.retroCI.NonConformityAction.java

private void createForExistingSample(BaseActionForm dynaForm)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    getPatient(sample);/*from ww w.j a v  a  2 s  .c o  m*/
    getObservationHistory(sample);
    getSampleQaEvents(sample);
    PropertyUtils.setProperty(dynaForm, "sampleId", sample.getId());
    PropertyUtils.setProperty(dynaForm, "patientId", patientService.getPatientId());

    Project project = getProjectForSample(sample);
    if (project != null) {
        PropertyUtils.setProperty(dynaForm, "projectId", project.getId());
        PropertyUtils.setProperty(dynaForm, "project", project.getLocalizedName());
    }

    String subjectNo = patientService.getSubjectNumber();
    if (!GenericValidator.isBlankOrNull(subjectNo)) {
        PropertyUtils.setProperty(dynaForm, "subjectNew", Boolean.FALSE);
        PropertyUtils.setProperty(dynaForm, "subjectNo", subjectNo);
    }

    String STNo = patientService.getSTNumber();
    if (!GenericValidator.isBlankOrNull(STNo)) {
        PropertyUtils.setProperty(dynaForm, "newSTNumber", Boolean.FALSE);
        PropertyUtils.setProperty(dynaForm, "STNumber", STNo);
    }

    String nationalId = patientService.getNationalId();
    if (!GenericValidator.isBlankOrNull(nationalId)) {
        PropertyUtils.setProperty(dynaForm, "nationalIdNew", Boolean.FALSE);
        PropertyUtils.setProperty(dynaForm, "nationalId", nationalId);
    }

    ObservationHistory doctorObservation = getRefererObservation(sample);
    if (doctorObservation != null) {
        PropertyUtils.setProperty(dynaForm, "doctorNew", Boolean.FALSE);
        PropertyUtils.setProperty(dynaForm, "doctor", doctorObservation.getValue());
    }

    if (useSiteList) {
        PropertyUtils.setProperty(dynaForm, "serviceNew", Boolean.FALSE);
        PropertyUtils.setProperty(dynaForm, "service", getSampleRequesterOrganizationName());
    } else {
        ObservationHistory serviceObservation = getServiceObservation(sample);
        if (serviceObservation != null) {
            PropertyUtils.setProperty(dynaForm, "serviceNew", Boolean.FALSE);
            PropertyUtils.setProperty(dynaForm, "service", serviceObservation.getValue());
        }
    }

    PropertyUtils.setProperty(dynaForm, "comment", getNoteForSample(sample));

    PropertyUtils.setProperty(dynaForm, "requesterSampleID", sample.getReferringId());
}

From source file:us.mn.state.health.lims.qaevent.action.retroCI.NonConformityAction.java

private void setProjectList(BaseActionForm dynaForm)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    ProjectDAO projectDAO = new ProjectDAOImpl();
    List<Project> projects = projectDAO.getAllProjects();
    PropertyUtils.setProperty(dynaForm, "projects", projects);
}

From source file:us.mn.state.health.lims.receivercodeelement.action.ReceiverCodeElementAction.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 ReceiverCodeElement.
    // If there is a parameter present, we should bring up an existing
    // ReceiverCodeElement 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  ww  w  .  ja  va2 s. c  om

    ReceiverCodeElement receiverCodeElement = new ReceiverCodeElement();

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

        receiverCodeElement.setId(id);
        ReceiverCodeElementDAO receiverCodeElementDAO = new ReceiverCodeElementDAOImpl();
        receiverCodeElementDAO.getData(receiverCodeElement);

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

        // initialize selectedMessageOrganizationId
        if (receiverCodeElement.getMessageOrganization() != null) {
            receiverCodeElement
                    .setSelectedMessageOrganizationId(receiverCodeElement.getMessageOrganization().getId());
        }
        if (receiverCodeElement.getCodeElementType() != null) {
            receiverCodeElement.setSelectedCodeElementTypeId(receiverCodeElement.getCodeElementType().getId());
        }

        // do we need to enable next or previous?
        //bugzilla 1427 pass in name not id
        List receiverCodeElements = receiverCodeElementDAO
                .getNextReceiverCodeElementRecord(receiverCodeElement.getId());
        if (receiverCodeElements.size() > 0) {
            // enable next button
            request.setAttribute(NEXT_DISABLED, "false");
        }
        //bugzilla 1427 pass in name not id
        receiverCodeElements = receiverCodeElementDAO
                .getPreviousReceiverCodeElementRecord(receiverCodeElement.getId());
        if (receiverCodeElements.size() > 0) {
            // enable next button
            request.setAttribute(PREVIOUS_DISABLED, "false");
        }
        // end of logic to enable next or previous button
    } else { // this is a new receiverCodeElement

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

        //this is additional functionality to keep previously selected messageOrganizationId and codeElementTypeId for convenience
        String selectedMessageOrganizationId = (String) request.getParameter("selectedMessageOrganizationId");
        if (!StringUtil.isNullorNill(selectedMessageOrganizationId)) {
            receiverCodeElement.setSelectedMessageOrganizationId(selectedMessageOrganizationId);
        }
        String selectedCodeElementTypeId = (String) request.getParameter("selectedCodeElementTypeId");
        if (!StringUtil.isNullorNill(selectedCodeElementTypeId)) {
            receiverCodeElement.setSelectedCodeElementTypeId(selectedCodeElementTypeId);
        }

    }

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

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

    MessageOrganizationDAO messageOrganizationDAO = new MessageOrganizationDAOImpl();
    List messageOrganizations = messageOrganizationDAO.getAllMessageOrganizations();
    PropertyUtils.setProperty(form, "messageOrganizations", messageOrganizations);

    CodeElementTypeDAO codeElementTypeDAO = new CodeElementTypeDAOImpl();
    List codeElementTypes = codeElementTypeDAO.getAllCodeElementTypes();
    PropertyUtils.setProperty(form, "codeElementTypes", codeElementTypes);

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.referral.action.ReferredOutAction.java

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

    DynaActionForm dynaForm = (DynaActionForm) form;

    request.getSession().setAttribute(SAVE_DISABLED, TRUE);

    List<ReferralItem> referralItems = getReferralItems();
    PropertyUtils.setProperty(dynaForm, "referralItems", referralItems);
    PropertyUtils.setProperty(dynaForm, "referralReasons",
            DisplayListService.getList(DisplayListService.ListType.REFERRAL_REASONS));
    PropertyUtils.setProperty(dynaForm, "referralOrganizations",
            DisplayListService.getListWithLeadingBlank(DisplayListService.ListType.REFERRAL_ORGANIZATIONS));

    //remove at some point
    nonNumericTests = getNonNumericTests(referralItems);

    fillInDictionaryValuesForReferralItems(referralItems);

    return mapping.findForward(IActionConstants.FWD_SUCCESS);
}

From source file:us.mn.state.health.lims.reports.action.AuditTrailReportBySampleProcessAction.java

protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String forward = FWD_SUCCESS;
    BaseActionForm dynaForm = (BaseActionForm) form;
    ActionMessages errors = null;//from w w w. ja  va 2s.  c om

    request.setAttribute(ALLOW_EDITS_KEY, "false");
    request.setAttribute(PREVIOUS_DISABLED, "true");
    request.setAttribute(NEXT_DISABLED, "true");

    String accessionNumber = (String) dynaForm.getString("accessionNumber");
    SampleXmlHelper sampleXmlHelper = new SampleXmlHelper();

    if (!StringUtil.isNullorNill(accessionNumber)) {
        Sample sample = new Sample();
        SampleDAO sampleDAO = new SampleDAOImpl();
        sample.setAccessionNumber(accessionNumber);

        List testTestAnalytes = new ArrayList();
        try {
            sampleDAO.getSampleByAccessionNumber(sample);

            if (!StringUtil.isNullorNill(sample.getStatus()) && sample.getStatus()
                    .equals(SystemConfiguration.getInstance().getSampleStatusLabelPrinted())) {
                dynaForm.set("accessionNumber", accessionNumber);
                request.setAttribute(ALLOW_EDITS_KEY, "false");
                return mapping.findForward(FWD_FAIL);
            }

        } catch (LIMSRuntimeException lre) {

            LogEvent.logError("AuditTrailReportBySampleProcessAction", "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);

        }

        String domain = sample.getDomain();

        String humanDomain = SystemConfiguration.getInstance().getHumanDomain();

        String animalDomain = SystemConfiguration.getInstance().getAnimalDomain();

        if (domain != null && domain.equals(humanDomain)) {
            // go to human view

            Patient patient = new Patient();
            Person patientPerson = new Person();
            Provider provider = new Provider();
            Person providerPerson = new Person();
            SampleHuman sampleHuman = new SampleHuman();
            SampleOrganization sampleOrganization = new SampleOrganization();
            Organization organization = new Organization();
            List sampleProjects = new ArrayList();
            Project project = new Project();
            Project project2 = new Project();
            SampleItem sampleItem = new SampleItem();

            try {

                PatientDAO patientDAO = new PatientDAOImpl();
                ProviderDAO providerDAO = new ProviderDAOImpl();
                SampleItemDAO sampleItemDAO = new SampleItemDAOImpl();
                SampleHumanDAO sampleHumanDAO = new SampleHumanDAOImpl();
                SampleOrganizationDAO sampleOrganizationDAO = new SampleOrganizationDAOImpl();
                AuditTrailDAO auditTrailDAO = new AuditTrailDAOImpl();
                SystemUserDAO systemUserDAO = new SystemUserDAOImpl();

                if (!StringUtil.isNullorNill(sample.getId())) {
                    sampleHuman.setSampleId(sample.getId());
                    sampleHumanDAO.getDataBySample(sampleHuman);
                    sampleOrganization.setSampleId(sample.getId());
                    sampleOrganizationDAO.getDataBySample(sampleOrganization);
                    sampleItem.setSample(sample);
                    sampleItemDAO.getDataBySample(sampleItem);

                    if (sampleHuman != null) {
                        if (sampleHuman.getPatientId() != null) {
                            patient.setId(sampleHuman.getPatientId());
                            patientDAO.getData(patient);
                            patientPerson = patient.getPerson();
                            provider.setId(sampleHuman.getProviderId());
                            providerDAO.getData(provider);
                            providerPerson = provider.getPerson();

                        }
                    }

                }
                organization = (Organization) sampleOrganization.getOrganization();
                sampleProjects = sample.getSampleProjects();

                if (sampleProjects != null && sampleProjects.size() > 0) {
                    SampleProject sampleProject = (SampleProject) sampleProjects.get(0);
                    project = sampleProject.getProject();
                    if (sampleProjects.size() > 1) {
                        SampleProject sampleProject2 = (SampleProject) sampleProjects.get(1);
                        project2 = sampleProject2.getProject();
                    }
                }

                String tableName = "SAMPLE";
                ReferenceTablesDAO referenceTablesDAO = new ReferenceTablesDAOImpl();
                ReferenceTables referenceTables = new ReferenceTables();
                referenceTables.setTableName(tableName);
                ReferenceTables rt = referenceTablesDAO.getReferenceTableByName(referenceTables);

                PropertyUtils.copyProperties(sampleXmlHelper, sample);

                //String data = auditTrailDAO.retrieveBlobData(sample.getId());
                //String data = auditTrailDAO.retrieveBlobData("9446");
                History history = new History();
                history.setReferenceId(sample.getId());
                history.setReferenceTable(rt.getId());
                List historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history);

                List sampleHistoryRecords = populateHistoryList(request, historyRecords, "sample",
                        "sampleHistoryMapping.xsl");
                sampleXmlHelper.setHistoryRecords((ArrayList) sampleHistoryRecords);

                tableName = "SAMPLE_ITEM";
                referenceTables = new ReferenceTables();
                referenceTables.setTableName(tableName);
                rt = referenceTablesDAO.getReferenceTableByName(referenceTables);
                history = new History();
                history.setReferenceId(sampleItem.getId());
                history.setReferenceTable(rt.getId());
                historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history);

                List sampleItemHistoryRecords = populateHistoryList(request, historyRecords, "sampleItem",
                        "sampleItemHistoryMapping.xsl");
                sampleXmlHelper.addHistoryRecords((ArrayList) sampleItemHistoryRecords);

                tableName = "PATIENT";
                referenceTables = new ReferenceTables();
                referenceTables.setTableName(tableName);
                rt = referenceTablesDAO.getReferenceTableByName(referenceTables);
                history = new History();
                history.setReferenceId(patient.getId());
                history.setReferenceTable(rt.getId());
                historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history);

                List patientHistoryRecords = populateHistoryList(request, historyRecords, "patient",
                        "patientHistoryMapping.xsl");
                sampleXmlHelper.addHistoryRecords((ArrayList) patientHistoryRecords);

                tableName = "PERSON";
                referenceTables = new ReferenceTables();
                referenceTables.setTableName(tableName);
                rt = referenceTablesDAO.getReferenceTableByName(referenceTables);
                history = new History();
                history.setReferenceId(patientPerson.getId());
                history.setReferenceTable(rt.getId());
                historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history);

                //List patientPersonHistoryRecords = populateHistoryList(request, historyRecords, "person", "personHistoryMapping.xsl");
                //sampleXmlHelper.addHistoryRecords((ArrayList)patientPersonHistoryRecords);

                tableName = "PERSON";
                referenceTables = new ReferenceTables();
                referenceTables.setTableName(tableName);
                rt = referenceTablesDAO.getReferenceTableByName(referenceTables);
                history = new History();
                history.setReferenceId(providerPerson.getId());
                history.setReferenceTable(rt.getId());
                historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history);

                //List providerPersonHistoryRecords = populateHistoryList(request, historyRecords, "person", "personHistoryMapping.xsl");
                //sampleXmlHelper.addHistoryRecords((ArrayList)providerPersonHistoryRecords);

                tableName = "SAMPLE_PROJECTS";
                referenceTables = new ReferenceTables();
                referenceTables.setTableName(tableName);
                rt = referenceTablesDAO.getReferenceTableByName(referenceTables);
                history = new History();
                history.setReferenceId(providerPerson.getId());
                history.setReferenceTable(rt.getId());
                historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history);

                List sampleProjectHistoryRecords = populateHistoryList(request, historyRecords, "sampleProject",
                        "sampleProjectHistoryMapping.xsl");
                sampleXmlHelper.addHistoryRecords((ArrayList) sampleProjectHistoryRecords);

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

                tableName = "SAMPLE_ORGANIZATION";
                referenceTables = new ReferenceTables();
                referenceTables.setTableName(tableName);
                rt = referenceTablesDAO.getReferenceTableByName(referenceTables);
                history = new History();
                history.setReferenceId(sampleOrganization.getId());
                history.setReferenceTable(rt.getId());
                historyRecords = auditTrailDAO.getHistoryByRefIdAndRefTableId(history);

                List sampleOrganizationHistoryRecords = populateHistoryList(request, historyRecords,
                        "sampleOrganization", "sampleOrganizationHistoryMapping.xsl");
                sampleXmlHelper.addHistoryRecords((ArrayList) sampleOrganizationHistoryRecords);

                List historyRecordsForSorting = sampleXmlHelper.getHistoryRecords();

                Collections.sort(historyRecordsForSorting, HistoryComparator.NAME_COMPARATOR);

                String savedUserName = "";
                List dateSortList = new ArrayList();
                List finalList = new ArrayList();
                //now within name sort by date desc
                for (int i = 0; i < historyRecordsForSorting.size(); i++) {
                    //break down into chunks by name
                    HistoryXmlHelper hist = (HistoryXmlHelper) historyRecordsForSorting.get(i);

                    if (i > 0 && !hist.getUserName().equals(savedUserName)) {
                        //now sort chunk so far
                        Collections.sort(dateSortList, HistoryComparator.DATE_COMPARATOR);
                        finalList.addAll(dateSortList);
                        dateSortList.clear();
                    }
                    dateSortList.add(hist);
                    savedUserName = hist.getUserName();
                }

                if (dateSortList != null && dateSortList.size() > 0) {
                    Collections.sort(dateSortList, HistoryComparator.DATE_COMPARATOR);
                    finalList.addAll(dateSortList);
                    dateSortList.clear();
                }

                sampleXmlHelper.setHistoryRecords((ArrayList) finalList);

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

            } catch (LIMSRuntimeException lre) {
                // if error then forward to fail and don't update to blank
                // page
                // = false
                //bugzilla 2154
                LogEvent.logError("ResultsEntryViewAction", "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);

            }

            // populate form from valueholder
            //PropertyUtils.setProperty(dynaForm, "sampleLastupdated", sample
            //.getLastupdated());
            PropertyUtils.setProperty(dynaForm, "patientFirstName", patientPerson.getFirstName());
            PropertyUtils.setProperty(dynaForm, "patientLastName", patientPerson.getLastName());
            PropertyUtils.setProperty(dynaForm, "patientId", patient.getExternalId());

            PropertyUtils.setProperty(dynaForm, "gender", patient.getGender());

            PropertyUtils.setProperty(dynaForm, "chartNumber", patient.getChartNumber());

            PropertyUtils.setProperty(dynaForm, "birthDateForDisplay",
                    (String) patient.getBirthDateForDisplay());
            TypeOfSample typeOfSample = sampleItem.getTypeOfSample();
            SourceOfSample sourceOfSample = sampleItem.getSourceOfSample();
            if (typeOfSample == null) {
                PropertyUtils.setProperty(dynaForm, "typeOfSample", new TypeOfSample());
            } else {
                PropertyUtils.setProperty(dynaForm, "typeOfSample", typeOfSample);
            }
            if (sourceOfSample == null) {
                PropertyUtils.setProperty(dynaForm, "sourceOfSample", new SourceOfSample());
            } else {
                PropertyUtils.setProperty(dynaForm, "sourceOfSample", sourceOfSample);
            }

            PropertyUtils.setProperty(dynaForm, "sourceOther", sampleItem.getSourceOther());
            PropertyUtils.setProperty(dynaForm, "receivedDateForDisplay",
                    (String) sample.getReceivedDateForDisplay());
            PropertyUtils.setProperty(dynaForm, "collectionDateForDisplay",
                    (String) sample.getCollectionDateForDisplay());

            PropertyUtils.setProperty(dynaForm, "collectionTimeForDisplay",
                    (String) sample.getCollectionTimeForDisplay());

            PropertyUtils.setProperty(dynaForm, "referredCultureFlag",
                    (String) sample.getReferredCultureFlag());

            PropertyUtils.setProperty(dynaForm, "stickerReceivedFlag",
                    (String) sample.getStickerReceivedFlag());

            if (organization == null) {
                PropertyUtils.setProperty(dynaForm, "organization", new Organization());
            } else {
                PropertyUtils.setProperty(dynaForm, "organization", organization);
            }

            if (project == null) {
                PropertyUtils.setProperty(dynaForm, "project", new Project());
            } else {
                PropertyUtils.setProperty(dynaForm, "project", project);
            }

            if (project2 == null) {
                PropertyUtils.setProperty(dynaForm, "project2", new Project());
            } else {
                PropertyUtils.setProperty(dynaForm, "project2", project2);
            }

            // reload accession number
            PropertyUtils.setProperty(dynaForm, "accessionNumber", accessionNumber);
            PropertyUtils.setProperty(dynaForm, "domain", domain);

            PropertyUtils.setProperty(dynaForm, "sampleXmlHelper", sampleXmlHelper);

            forward = FWD_SUCCESS_HUMAN;
        } else if (domain != null && domain.equals(animalDomain)) {
            // go to animal view
            // System.out.println("Going to animal view");
            forward = FWD_SUCCESS_ANIMAL;
        } else {
            forward = FWD_SUCCESS;
        }

    }

    return mapping.findForward(forward);
}

From source file:us.mn.state.health.lims.reports.action.AuditTrailSystemTestAction.java

protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String forward = FWD_SUCCESS;
    BaseActionForm dynaForm = (BaseActionForm) form;

    request.setAttribute(ALLOW_EDITS_KEY, "false");
    request.setAttribute(PREVIOUS_DISABLED, "true");
    request.setAttribute(NEXT_DISABLED, "true");

    // initialize the form
    dynaForm.initialize(mapping);//  w  w  w.  j av  a2 s  .  c om

    // default date modified to today's date
    Date today = Calendar.getInstance().getTime();
    Locale locale = (Locale) request.getSession().getAttribute("org.apache.struts.action.LOCALE");

    String dateAsText = DateUtil.formatDateAsText(today, locale);
    PropertyUtils.setProperty(form, "dateModified", dateAsText);

    ReferenceTablesDAO referenceTablesDAO = new ReferenceTablesDAOImpl();
    List referenceTableList = referenceTablesDAO.getAllReferenceTables();
    Collections.sort(referenceTableList, ReferenceTablesComparator.NAME_COMPARATOR);
    PropertyUtils.setProperty(form, "referenceTableList", referenceTableList);

    SystemUserDAO sysUserDAO = new SystemUserDAOImpl();
    List systemUsers = sysUserDAO.getAllSystemUsers();
    Collections.sort(systemUsers, SystemUserComparator.NAME_COMPARATOR);
    PropertyUtils.setProperty(form, "systemUsers", systemUsers);

    return mapping.findForward(forward);
}