List of usage examples for org.apache.commons.beanutils PropertyUtils setProperty
public static void setProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
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
.
From source file:us.mn.state.health.lims.provider.action.ProviderUpdateAction.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 Provider. // If there is a parameter present, we should bring up an existing // Provider 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;/*from w w w. ja v a 2 s . c o m*/ } else { isNew = false; } // System.out.println("I am in ProviderUpdateAction"); 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"); // System.out.println("This is ID from request " + id); Provider provider = new Provider(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); provider.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); String selectedPersonId = (String) dynaForm.get("selectedPersonId"); List persons = new ArrayList(); if (dynaForm.get("persons") != null) { persons = (List) dynaForm.get("persons"); } else { PersonDAO personDAO = new PersonDAOImpl(); persons = personDAO.getAllPersons(); } Person person = null; // get the right person to update provider with for (int i = 0; i < persons.size(); i++) { Person p = (Person) persons.get(i); if (p.getId().equals(selectedPersonId)) { person = p; break; } } // populate valueholder from form PropertyUtils.copyProperties(provider, dynaForm); provider.setPerson(person); try { ProviderDAO providerDAO = new ProviderDAOImpl(); if (!isNew) { // UPDATE providerDAO.updateData(provider); if (FWD_NEXT.equals(direction)) { List providers = providerDAO.getNextProviderRecord(provider.getId()); if (providers != null && providers.size() > 0) { provider = (Provider) providers.get(0); providerDAO.getData(provider); if (providers.size() < 2) { // disable next button request.setAttribute(NEXT_DISABLED, "true"); } id = provider.getId(); } else { // disable next button request.setAttribute(NEXT_DISABLED, "true"); } forward = FWD_NEXT; } if (FWD_PREVIOUS.equals(direction)) { List providers = providerDAO.getPreviousProviderRecord(provider.getId()); if (providers != null && providers.size() > 0) { provider = (Provider) providers.get(0); providerDAO.getData(provider); if (providers.size() < 2) { // disable previous button request.setAttribute(PREVIOUS_DISABLED, "true"); } id = provider.getId(); } else { // disable previous button request.setAttribute(PREVIOUS_DISABLED, "true"); } forward = FWD_PREVIOUS; } } else { // INSERT providerDAO.insertData(provider); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("ProviderUpdateAction", "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, provider); PropertyUtils.setProperty(dynaForm, "persons", persons); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (provider.getId() != null && !provider.getId().equals("0")) { request.setAttribute(ID, provider.getId()); } //bugzilla 1400 if (isNew) forward = FWD_SUCCESS_INSERT; return getForward(mapping.findForward(forward), id, start); }
From source file:us.mn.state.health.lims.qaevent.action.BatchQaEventsEntryAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); BaseActionForm dynaForm = (BaseActionForm) form; // initialize the form dynaForm.initialize(mapping);/*w w w .j a v a 2s . c o m*/ String fromAccessionNumber = ""; String toAccessionNumber = ""; String skipAccessionNumber = ""; QaEventDAO qaEventDAO = new QaEventDAOImpl(); List qaEvents = new ArrayList(); qaEvents = qaEventDAO.getAllQaEvents(); Collections.sort(qaEvents, QaEventComparator.NAME_COMPARATOR); PropertyUtils.setProperty(dynaForm, "SelectList", qaEvents); PropertyUtils.setProperty(dynaForm, "pickIds", ""); PropertyUtils.setProperty(dynaForm, "fromAccessionNumber", fromAccessionNumber); PropertyUtils.setProperty(dynaForm, "toAccessionNumber", toAccessionNumber); PropertyUtils.setProperty(dynaForm, "skipAccessionNumber", skipAccessionNumber); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.qaevent.action.QaEventAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 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 ww . java 2s . com QaEvent qaEvent = new QaEvent(); TestDAO testDAO = new TestDAOImpl(); DictionaryDAO dictionaryDAO = new DictionaryDAOImpl(); if ((id != null) && (!"0".equals(id))) { // this is an existing // qaEvent qaEvent.setId(id); QaEventDAO qaEventDAO = new QaEventDAOImpl(); qaEventDAO.getData(qaEvent); isNew = false; // this is to set correct page title // do we need to enable next or previous? List qaEvents = qaEventDAO.getNextQaEventRecord(qaEvent.getQaEventName()); if (qaEvents.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } qaEvents = qaEventDAO.getPreviousQaEventRecord(qaEvent.getQaEventName()); if (qaEvents.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new qaEvent isNew = true; // this is to set correct page title } if (qaEvent.getId() != null && !qaEvent.getId().equals("0")) { request.setAttribute(ID, qaEvent.getId()); } //Get tests by user system id //bugzilla 2160 UserTestSectionDAO userTestSectionDAO = new UserTestSectionDAOImpl(); //bugzilla 2291 List tests = userTestSectionDAO.getAllUserTests(request, true); List dictionaries = dictionaryDAO.getDictionaryEntrysByCategory( SystemConfiguration.getInstance().getQaEventDictionaryCategoryType()); //bugzilla 2506 List dictionaries2 = dictionaryDAO.getDictionaryEntrysByCategory( SystemConfiguration.getInstance().getQaEventDictionaryCategoryCategory()); //bugzilla 1856 Collections.sort(tests, TestComparator.DESCRIPTION_COMPARATOR); // populate form from valueholder PropertyUtils.copyProperties(form, qaEvent); PropertyUtils.setProperty(form, "tests", tests); PropertyUtils.setProperty(form, "dictionaries", dictionaries); //bugzilla 2506 PropertyUtils.setProperty(form, "dictionaries2", dictionaries2); Test qaEventTest = (Test) qaEvent.getTest(); // bugzilla 2246 changed name selectedTest to selectedTestId String selectedTestId = null; if (qaEventTest != null) selectedTestId = qaEventTest.getId(); PropertyUtils.setProperty(form, "selectedTestId", selectedTestId); Dictionary type = (Dictionary) qaEvent.getType(); String selectedTypeId = null; if (type != null) selectedTypeId = type.getId(); // bugzilla 2246 PropertyUtils.setProperty(form, "selectedTypeId", selectedTypeId); //bugzilla 2506 Dictionary category = (Dictionary) qaEvent.getCategory(); String selectedCategoryId = null; if (category != null) selectedCategoryId = category.getId(); PropertyUtils.setProperty(form, "selectedCategoryId", selectedCategoryId); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.qaevent.action.QaEventsEntryAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { 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"); //bugzilla 2501 request.setAttribute(MULTIPLE_SAMPLE_MODE, "false"); HttpSession session = request.getSession(); //bugzila 2053 QaEventRoutingSwitchSessionHandler.switchAllOff(session); DynaActionForm dynaForm = (DynaActionForm) form; // initialize the form dynaForm.initialize(mapping);/*from w w w. j av a2s. c o m*/ DictionaryDAO dictionaryDAO = new DictionaryDAOImpl(); List categoryDictionaries = dictionaryDAO.getDictionaryEntrysByCategory( SystemConfiguration.getInstance().getQaEventDictionaryCategoryCategory()); PropertyUtils.setProperty(form, "testQaEvents", new ArrayList()); PropertyUtils.setProperty(form, "organization", new Organization()); PropertyUtils.setProperty(form, "project", new Project()); PropertyUtils.setProperty(form, "typeOfSample", new TypeOfSample()); PropertyUtils.setProperty(form, "sourceOfSample", new SourceOfSample()); PropertyUtils.setProperty(form, "categoryDictionaries", categoryDictionaries); PropertyUtils.setProperty(form, "currentCount", "0"); PropertyUtils.setProperty(form, "totalCount", "0"); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.qaevent.action.QaEventsEntryAddActionsToQaEventsPopupAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); // bugzilla 2503 String filterString = (String) request.getParameter("filterString"); String doingSearch = (String) request.getParameter("search"); BaseActionForm dynaForm = (BaseActionForm) form; // initialize the form dynaForm.initialize(mapping);//from w ww .j ava 2 s. com Sample sample = new Sample(); SampleItem sampleItem = new SampleItem(); List analyses = new ArrayList(); SampleDAO sampleDAO = new SampleDAOImpl(); SampleItemDAO sampleItemDAO = new SampleItemDAOImpl(); AnalysisDAO analysisDAO = new AnalysisDAOImpl(); AnalysisQaEventDAO analysisQaEventDAO = new AnalysisQaEventDAOImpl(); List analysisQaEvents = new ArrayList(); List totalAnalysisQaEvents = new ArrayList(); //standardize request parameter naming String accessionNumber = request.getParameter(ACCESSION_NUMBER); sample.setAccessionNumber(accessionNumber); sampleDAO.getSampleByAccessionNumber(sample); if (!StringUtil.isNullorNill(sample.getId())) { sampleItem.setSample(sample); sampleItemDAO.getDataBySample(sampleItem); if (sampleItem.getId() != null) { //bugzilla 2227 analyses = analysisDAO.getMaxRevisionAnalysesBySample(sampleItem); } } if (analyses != null) { // there is one Analysis per Test for (int i = 0; i < analyses.size(); i++) { Analysis analysis = (Analysis) analyses.get(i); AnalysisQaEvent analysisQaEvent = new AnalysisQaEvent(); analysisQaEvent.setAnalysis(analysis); analysisQaEvents = analysisQaEventDAO.getAnalysisQaEventsByAnalysis(analysisQaEvent); for (int j = 0; j < analysisQaEvents.size(); j++) { AnalysisQaEvent analQaEvent = (AnalysisQaEvent) analysisQaEvents.get(j); if (analQaEvent.getCompletedDate() == null) { //pick ones with null completed date totalAnalysisQaEvents.add(analQaEvent); } } } } ActionDAO actionDAO = new ActionDAOImpl(); List actions = new ArrayList(); //bugzilla 2503 if (!StringUtil.isNullorNill(doingSearch) && doingSearch.equals(YES)) actions = actionDAO.getAllActionsByFilter(filterString); else actions = actionDAO.getAllActions(); Collections.sort(totalAnalysisQaEvents, AnalysisQaEventComparator.NAME_COMPARATOR); Collections.sort(actions, ActionComparator.NAME_COMPARATOR); PropertyUtils.setProperty(dynaForm, "SelectList", actions); PropertyUtils.setProperty(dynaForm, "PickList", totalAnalysisQaEvents); //bugzilla 2503 request.setAttribute(POPUPFORM_FILTER_BY_TABLE_COLUMN, "action.description"); if (!StringUtil.isNullorNill(doingSearch) && doingSearch.equals(YES)) { request.setAttribute(IN_POPUP_FORM_SEARCH, "true"); request.setAttribute(POPUP_FORM_SEARCH_STRING, filterString); } return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.qaevent.action.QaEventsEntryAddActionsToSampleQaEventsPopupAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); BaseActionForm dynaForm = (BaseActionForm) form; // initialize the form dynaForm.initialize(mapping);// ww w . j ava 2s . c om Sample sample = new Sample(); SampleDAO sampleDAO = new SampleDAOImpl(); SampleQaEventDAO sampleQaEventDAO = new SampleQaEventDAOImpl(); List sampleQaEvents = new ArrayList(); //standardize request parameter naming String accessionNumber = request.getParameter(ACCESSION_NUMBER); sample.setAccessionNumber(accessionNumber); sampleDAO.getSampleByAccessionNumber(sample); if (!StringUtil.isNullorNill(sample.getId())) { SampleQaEvent sampleQaEvent = new SampleQaEvent(); sampleQaEvent.setSample(sample); sampleQaEvents = sampleQaEventDAO.getSampleQaEventsBySample(sampleQaEvent); } ActionDAO actionDAO = new ActionDAOImpl(); List actions = new ArrayList(); actions = actionDAO.getAllActions(); Collections.sort(sampleQaEvents, SampleQaEventComparator.NAME_COMPARATOR); Collections.sort(actions, ActionComparator.NAME_COMPARATOR); PropertyUtils.setProperty(dynaForm, "SelectList", actions); PropertyUtils.setProperty(dynaForm, "PickList", sampleQaEvents); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.qaevent.action.QaEventsEntryAddQaEventsToSamplePopupAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); BaseActionForm dynaForm = (BaseActionForm) form; // initialize the form dynaForm.initialize(mapping);// ww w . j av a2 s .co m Sample sample = new Sample(); SampleItem sampleItem = new SampleItem(); List analyses = new ArrayList(); SampleDAO sampleDAO = new SampleDAOImpl(); SampleItemDAO sampleItemDAO = new SampleItemDAOImpl(); AnalysisDAO analysisDAO = new AnalysisDAOImpl(); List tests = new ArrayList(); //standardize request parameter naming String accessionNumber = request.getParameter(ACCESSION_NUMBER); sample.setAccessionNumber(accessionNumber); sampleDAO.getSampleByAccessionNumber(sample); QaEventDAO qaEventDAO = new QaEventDAOImpl(); List qaEvents = new ArrayList(); qaEvents = qaEventDAO.getAllQaEvents(); Collections.sort(qaEvents, QaEventComparator.NAME_COMPARATOR); PropertyUtils.setProperty(dynaForm, "SelectList", qaEvents); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.qaevent.action.QaEventsEntryAddQaEventsToTestsPopupAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); BaseActionForm dynaForm = (BaseActionForm) form; // initialize the form dynaForm.initialize(mapping);/*w w w. j a v a 2s . c o m*/ Sample sample = new Sample(); SampleItem sampleItem = new SampleItem(); List analyses = new ArrayList(); SampleDAO sampleDAO = new SampleDAOImpl(); SampleItemDAO sampleItemDAO = new SampleItemDAOImpl(); AnalysisDAO analysisDAO = new AnalysisDAOImpl(); List tests = new ArrayList(); //standardize request parameter naming String accessionNumber = request.getParameter(ACCESSION_NUMBER); sample.setAccessionNumber(accessionNumber); sampleDAO.getSampleByAccessionNumber(sample); if (!StringUtil.isNullorNill(sample.getId())) { sampleItem.setSample(sample); sampleItemDAO.getDataBySample(sampleItem); if (sampleItem.getId() != null) { //bugzilla 2227 analyses = analysisDAO.getMaxRevisionAnalysesBySample(sampleItem); } } if (analyses != null) { // there is one Analysis per Test for (int i = 0; i < analyses.size(); i++) { Analysis analysis = (Analysis) analyses.get(i); //only if test is not released and printed date is null if (!StringUtil.isNullorNill(analysis.getStatus()) && !analysis.getStatus() .equals(SystemConfiguration.getInstance().getAnalysisStatusReleased()) && analysis.getPrintedDate() == null) { Test t = (Test) analysis.getTest(); tests.add(t); } } } QaEventDAO qaEventDAO = new QaEventDAOImpl(); List qaEvents = new ArrayList(); qaEvents = qaEventDAO.getAllQaEvents(); //bugzilla 1856 Collections.sort(tests, TestComparator.DESCRIPTION_COMPARATOR); Collections.sort(qaEvents, QaEventComparator.NAME_COMPARATOR); PropertyUtils.setProperty(dynaForm, "SelectList", qaEvents); PropertyUtils.setProperty(dynaForm, "PickList", tests); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.qaevent.action.QaEventsEntryPositionToRecordAction.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 Analyte. // If there is a parameter present, we should bring up an existing // Analyte to edit. String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "false"); request.setAttribute(NEXT_DISABLED, "false"); BaseActionForm dynaForm = (BaseActionForm) form; // server side validation of accessionNumber ActionMessages errors = null;// w ww . ja va 2 s. c o m //bugzilla 2501 HttpSession session = request.getSession(); String multipleSampleModeFromSessionRouting = (String) session .getAttribute(QAEVENTS_ENTRY_PARAM_MULTIPLE_SAMPLE_MODE); String selectedCategoryIdFromRouting = (String) session .getAttribute(QAEVENTS_ENTRY_PARAM_QAEVENT_CATEGORY_ID); //bugzilla 2504 String viewModeFromRouting = (String) session.getAttribute(QAEVENTS_ENTRY_PARAM_VIEW_MODE); //bugzilla 2502 String fullScreenSectionFromRouting = (String) session .getAttribute(QAEVENTS_ENTRY_FULL_SCREEN_VIEW_SECTION); String multipleSampleMode = ""; String qaEventCategoryId = ""; //bugzilla 2504 String viewMode = QAEVENTS_ENTRY_NORMAL_VIEW; //bugzilla 2502 String fullScreenSection = ""; if (!StringUtil.isNullorNill(multipleSampleModeFromSessionRouting)) { multipleSampleMode = multipleSampleModeFromSessionRouting; qaEventCategoryId = selectedCategoryIdFromRouting; //bugzilla 2504 if (!StringUtil.isNullorNill(viewModeFromRouting)) viewMode = viewModeFromRouting; if (!StringUtil.isNullorNill(fullScreenSectionFromRouting)) fullScreenSection = fullScreenSectionFromRouting; session.setAttribute(QAEVENTS_ENTRY_PARAM_MULTIPLE_SAMPLE_MODE, null); session.setAttribute(QAEVENTS_ENTRY_PARAM_QAEVENT_CATEGORY_ID, null); //bugzilla 2504 session.setAttribute(QAEVENTS_ENTRY_PARAM_VIEW_MODE, null); session.setAttribute(QAEVENTS_ENTRY_FULL_SCREEN_VIEW_SECTION, null); } else { multipleSampleMode = (String) dynaForm.get("multipleSampleMode"); qaEventCategoryId = (String) dynaForm.get("selectedQaEventsCategoryId"); viewMode = (String) dynaForm.get("viewMode"); fullScreenSection = (String) dynaForm.get("fullScreenSection"); } //for now qa events is for both human and Newborn String accessionNumber = request.getParameter(ACCESSION_NUMBER); String requestedAccessionNumber = BLANK; //the direction is only used for NEXT and PREVIOUS functionality String direction = (String) request.getParameter("direction"); String nextDisabled = FALSE; String previousDisabled = FALSE; String currentRecord = "0"; String totalRecords = "0"; try { SampleDAO sampleDAO = new SampleDAOImpl(); List samples = new ArrayList(); Sample sample = new Sample(); sample.setAccessionNumber(accessionNumber); //bugzilla 2502 (in full screen mode after bad filter there is no accession number if (!StringUtil.isNullorNill(sample.getAccessionNumber())) { sampleDAO.getSampleByAccessionNumber(sample); } if (!StringUtil.isNullorNill(qaEventCategoryId)) { samples = sampleDAO.getSamplesWithPendingQaEvents(sample, true, qaEventCategoryId, false); } else { samples = sampleDAO.getSamplesWithPendingQaEvents(sample, false, null, false); } if (samples != null && samples.size() > 0) { //this is for next, previous and current if (sample != null && !StringUtil.isNullorNill(sample.getId())) { //NEXT button was pressed if (FWD_NEXT.equals(direction)) { sample = getNextSampleFromList(samples, sample); int position = getPosition(samples, sample); if (sample != null && position >= 0) { currentRecord = String.valueOf(position + 1); totalRecords = String.valueOf(samples.size()); } else { //the sample was not found (why was NEXT not disabled?? Or has this sample //been modified to complete qa events? sample = (Sample) samples.get(samples.size() - 1); accessionNumber = sample.getAccessionNumber(); position = samples.size(); currentRecord = String.valueOf(samples.size()); totalRecords = String.valueOf(samples.size()); } if (position >= (samples.size() - 1)) { nextDisabled = TRUE; } if (position == 0) { previousDisabled = TRUE; } accessionNumber = sample.getAccessionNumber(); //position to previous record } else if (FWD_PREVIOUS.equals(direction)) { sample = getPreviousSampleFromList(samples, sample); int position = getPosition(samples, sample); if (sample != null && position >= 0) { currentRecord = String.valueOf(position + 1); totalRecords = String.valueOf(samples.size()); } else { //the sample was not found (why was PREVIOUS not disabled?? Or has this sample //been modified to complete qa events? sample = (Sample) samples.get(0); accessionNumber = sample.getAccessionNumber(); position = 0; currentRecord = "1"; totalRecords = String.valueOf(samples.size()); } if (position >= (samples.size() - 1)) { nextDisabled = TRUE; } if (position == 0) { previousDisabled = TRUE; } accessionNumber = sample.getAccessionNumber(); //position to current record } else if (StringUtil.isNullorNill(direction)) { boolean recordNotFound = false; requestedAccessionNumber = sample.getAccessionNumber(); recordNotFound = getCurrentSampleFromList(samples, sample, true); int position = getPosition(samples, sample); if (sample != null && position >= 0) { currentRecord = String.valueOf(position + 1); totalRecords = String.valueOf(samples.size()); if (position >= (samples.size() - 1)) { nextDisabled = TRUE; } if (position == 0) { previousDisabled = TRUE; } accessionNumber = sample.getAccessionNumber(); } if (recordNotFound) { //display a simple warning message ActionError error = new ActionError( "qaeventsentry.message.error.record.not.found.position.to.next", requestedAccessionNumber, null); errors = new ActionMessages(); errors.add(ActionMessages.GLOBAL_MESSAGE, error); saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); } } } else { //position to first record sample = (Sample) samples.get(0); int position = 0; if (sample != null && position >= 0) { currentRecord = String.valueOf(position + 1); totalRecords = String.valueOf(samples.size()); if (position > (samples.size() - 1)) { nextDisabled = TRUE; } if (position == 0) { previousDisabled = TRUE; } accessionNumber = sample.getAccessionNumber(); } } } else { //samples is null (there are no pending qa events ---> go to empty page //display error ActionError error = new ActionError("qaeventsentry.message.error.no.data", null, null); errors = new ActionMessages(); errors.add(ActionMessages.GLOBAL_MESSAGE, error); saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); } //get multipleSampleMode and selectedQaEventCategoryId from session (in case routing) //and set as form variables for ViewAction PropertyUtils.setProperty(dynaForm, "currentCount", currentRecord); PropertyUtils.setProperty(dynaForm, "totalCount", totalRecords); PropertyUtils.setProperty(dynaForm, "selectedQaEventsCategoryId", qaEventCategoryId); PropertyUtils.setProperty(dynaForm, "multipleSampleMode", multipleSampleMode); //bugzilla 2502 PropertyUtils.setProperty(dynaForm, "viewMode", viewMode); PropertyUtils.setProperty(dynaForm, "fullScreenSection", fullScreenSection); if (!StringUtil.isNullorNill(accessionNumber)) { request.setAttribute(ACCESSION_NUMBER, accessionNumber); } if (!StringUtil.isNullorNill(requestedAccessionNumber)) { request.setAttribute(ACCESSION_NUMBER_REQUESTED, requestedAccessionNumber); } if (!StringUtil.isNullorNill(nextDisabled)) { request.setAttribute(NEXT_DISABLED, nextDisabled); } if (!StringUtil.isNullorNill(previousDisabled)) { request.setAttribute(PREVIOUS_DISABLED, previousDisabled); } //bugzilla 2504 if (!StringUtil.isNullorNill(viewMode)) { request.setAttribute(QAEVENTS_ENTRY_PARAM_VIEW_MODE, viewMode); } //bugzilla 2502 if (!StringUtil.isNullorNill(fullScreenSection)) { request.setAttribute(QAEVENTS_ENTRY_FULL_SCREEN_VIEW_SECTION, fullScreenSection); } } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("QaEventsEntryPositionToRecordAction", "performAction()", lre.toString()); request.setAttribute(ALLOW_EDITS_KEY, "false"); // disable previous and next request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); forward = FWD_FAIL; } return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.qaevent.action.QaEventsEntryUpdateAction.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, "true"); request.setAttribute(NEXT_DISABLED, "true"); BaseActionForm dynaForm = (BaseActionForm) form; String accessionNumber = (String) dynaForm.get("accessionNumber"); String[] selectedAnalysisQaEventIdsForCompletion = (String[]) dynaForm .get("selectedAnalysisQaEventIdsForCompletion"); List testQaEvents = (List) dynaForm.get("testQaEvents"); //bugzilla 2500 String[] selectedSampleQaEventIdsForCompletion = (String[]) dynaForm .get("selectedSampleQaEventIdsForCompletion"); List sampleQaEvents = (List) dynaForm.get("sampleQaEvents"); //bugzilla 2566 for now qa events is for both humand and newborn //bugzilla 2501 String multipleSampleMode = (String) dynaForm.get("multipleSampleMode"); String qaEventCategoryId = (String) dynaForm.get("selectedQaEventsCategoryId"); //bugzilla 2500 String addQaEventPopupSelectedQaEventIdsForSample = (String) dynaForm .get("addQaEventPopupSelectedQaEventIdsForSample"); StringTokenizer qaEventIdTokenizerForSample = new StringTokenizer( addQaEventPopupSelectedQaEventIdsForSample, SystemConfiguration.getInstance().getDefaultIdSeparator()); List listOfAddedQaEventIdsForSample = new ArrayList(); while (qaEventIdTokenizerForSample.hasMoreElements()) { String qaEventIdForSample = (String) qaEventIdTokenizerForSample.nextElement(); listOfAddedQaEventIdsForSample.add(qaEventIdForSample); }/*from w w w . ja v a2 s .co m*/ String addActionSelectedActionIdsForSample = (String) dynaForm .get("addActionPopupSelectedActionIdsForSample"); String addActionSelectedSampleQaEventIds = (String) dynaForm.get("addActionPopupSelectedSampleQaEventIds"); StringTokenizer actionIdTokenizerForSample = new StringTokenizer(addActionSelectedActionIdsForSample, SystemConfiguration.getInstance().getDefaultIdSeparator()); List listOfAddedActionIdsForSample = new ArrayList(); while (actionIdTokenizerForSample.hasMoreElements()) { String actionIdForSample = (String) actionIdTokenizerForSample.nextElement(); listOfAddedActionIdsForSample.add(actionIdForSample); } StringTokenizer sampleQaEventIdTokenizer = new StringTokenizer(addActionSelectedSampleQaEventIds, SystemConfiguration.getInstance().getDefaultIdSeparator()); List listOfSampleQaEventIds = new ArrayList(); while (sampleQaEventIdTokenizer.hasMoreElements()) { String sampleQaEventId = (String) sampleQaEventIdTokenizer.nextElement(); listOfSampleQaEventIds.add(sampleQaEventId); } //end bugzilla 2500 String addQaEventSelectedTestIds = (String) dynaForm.get("addQaEventPopupSelectedTestIds"); String addQaEventSelectedQaEventIds = (String) dynaForm.get("addQaEventPopupSelectedQaEventIds"); StringTokenizer testIdTokenizer = new StringTokenizer(addQaEventSelectedTestIds, SystemConfiguration.getInstance().getDefaultIdSeparator()); List listOfTestIds = new ArrayList(); while (testIdTokenizer.hasMoreElements()) { String testId = (String) testIdTokenizer.nextElement(); listOfTestIds.add(testId); } StringTokenizer qaEventIdTokenizer = new StringTokenizer(addQaEventSelectedQaEventIds, SystemConfiguration.getInstance().getDefaultIdSeparator()); List listOfAddedQaEventIds = new ArrayList(); while (qaEventIdTokenizer.hasMoreElements()) { String qaEventId = (String) qaEventIdTokenizer.nextElement(); listOfAddedQaEventIds.add(qaEventId); } String addActionSelectedActionIds = (String) dynaForm.get("addActionPopupSelectedActionIds"); String addActionSelectedAnalysisQaEventIds = (String) dynaForm .get("addActionPopupSelectedAnalysisQaEventIds"); StringTokenizer actionIdTokenizer = new StringTokenizer(addActionSelectedActionIds, SystemConfiguration.getInstance().getDefaultIdSeparator()); List listOfActionIds = new ArrayList(); while (actionIdTokenizer.hasMoreElements()) { String actionId = (String) actionIdTokenizer.nextElement(); listOfActionIds.add(actionId); } StringTokenizer analysisQaEventIdTokenizer = new StringTokenizer(addActionSelectedAnalysisQaEventIds, SystemConfiguration.getInstance().getDefaultIdSeparator()); List listOfAnalysisQaEventIds = new ArrayList(); while (analysisQaEventIdTokenizer.hasMoreElements()) { String analysisQaEventId = (String) analysisQaEventIdTokenizer.nextElement(); listOfAnalysisQaEventIds.add(analysisQaEventId); } // server side validation of accessionNumber // validate on server-side sample accession number ActionMessages errors = null; try { errors = new ActionMessages(); errors = validateAccessionNumber(request, errors, dynaForm); } catch (Exception e) { //bugzilla 2154 LogEvent.logError("QaEventsEntryUpdateAction", "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); } // initialize the form dynaForm.initialize(mapping); // 1926 get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); //bugzilla 2481 Action Owner SystemUser systemUser = new SystemUser(); systemUser.setId(sysUserId); SystemUserDAO systemUserDAO = new SystemUserDAOImpl(); systemUserDAO.getData(systemUser); Date today = Calendar.getInstance().getTime(); Locale locale = (Locale) request.getSession().getAttribute("org.apache.struts.action.LOCALE"); String dateAsText = DateUtil.formatDateAsText(today, locale); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); AnalysisQaEventDAO analysisQaEventDAO = new AnalysisQaEventDAOImpl(); SampleDAO sampleDAO = new SampleDAOImpl(); SampleItemDAO sampleItemDAO = new SampleItemDAOImpl(); AnalysisDAO analysisDAO = new AnalysisDAOImpl(); QaEventDAO qaEventDAO = new QaEventDAOImpl(); ActionDAO actionDAO = new ActionDAOImpl(); AnalysisQaEventActionDAO analysisQaEventActionDAO = new AnalysisQaEventActionDAOImpl(); //bugzilla 2501 SampleQaEventDAO sampleQaEventDAO = new SampleQaEventDAOImpl(); SampleQaEventActionDAO sampleQaEventActionDAO = new SampleQaEventActionDAOImpl(); if (!StringUtil.isNullorNill(accessionNumber)) { try { //bugzilla 2500 first update completed dates for sample if (selectedSampleQaEventIdsForCompletion != null && selectedSampleQaEventIdsForCompletion.length > 0) { for (int i = 0; i < selectedSampleQaEventIdsForCompletion.length; i++) { String sampleQaEventId = selectedSampleQaEventIdsForCompletion[i]; SampleQaEvent sampleQaEvent = new SampleQaEvent(); sampleQaEvent.setId(sampleQaEventId); sampleQaEventDAO.getData(sampleQaEvent); if (sampleQaEvent.getCompletedDate() == null) { sampleQaEvent.setCompletedDateForDisplay(dateAsText); sampleQaEvent.setSysUserId(sysUserId); sampleQaEventDAO.updateData(sampleQaEvent); } } } //first update completed dates if (selectedAnalysisQaEventIdsForCompletion != null && selectedAnalysisQaEventIdsForCompletion.length > 0) { for (int i = 0; i < selectedAnalysisQaEventIdsForCompletion.length; i++) { String analysisQaEventId = selectedAnalysisQaEventIdsForCompletion[i]; AnalysisQaEvent analysisQaEvent = new AnalysisQaEvent(); analysisQaEvent.setId(analysisQaEventId); analysisQaEventDAO.getData(analysisQaEvent); if (analysisQaEvent.getCompletedDate() == null) { analysisQaEvent.setCompletedDateForDisplay(dateAsText); analysisQaEvent.setSysUserId(sysUserId); analysisQaEventDAO.updateData(analysisQaEvent); } } } //bug 2500 now check if we added new Qa Events for sample if (listOfAddedQaEventIdsForSample != null && listOfAddedQaEventIdsForSample.size() > 0) { Sample sample = new Sample(); sample.setAccessionNumber(accessionNumber); sampleDAO.getSampleByAccessionNumber(sample); if (!StringUtil.isNullorNill(sample.getId())) { //insert all qaEvents selected for this sample if doesn't exist already for (int j = 0; j < listOfAddedQaEventIdsForSample.size(); j++) { //if this doesn't exist in in SAMPLE_QAEVENT already then insert it QaEvent qaEvent = new QaEvent(); qaEvent.setId((String) listOfAddedQaEventIdsForSample.get(j)); qaEventDAO.getData(qaEvent); if (qaEvent != null) { SampleQaEvent sampleQaEvent = new SampleQaEvent(); sampleQaEvent.setSample(sample); sampleQaEvent.setQaEvent(qaEvent); sampleQaEvent = sampleQaEventDAO.getSampleQaEventBySampleAndQaEvent(sampleQaEvent); if (sampleQaEvent != null) { //do nothing } else { //insert this new analysis qa event sampleQaEvent = new SampleQaEvent(); sampleQaEvent.setSample(sample); sampleQaEvent.setQaEvent(qaEvent); sampleQaEvent.setSysUserId(sysUserId); sampleQaEventDAO.insertData(sampleQaEvent); } } } } } //now check if we added new Actions if (listOfSampleQaEventIds != null && listOfSampleQaEventIds.size() > 0 && listOfAddedActionIdsForSample != null && listOfAddedActionIdsForSample.size() > 0) { Sample sample = new Sample(); sample.setAccessionNumber(accessionNumber); sampleDAO.getSampleByAccessionNumber(sample); if (!StringUtil.isNullorNill(sample.getId())) { SampleQaEvent sampleQaEvent = new SampleQaEvent(); sampleQaEvent.setSample(sample); sampleQaEvents = sampleQaEventDAO.getSampleQaEventsBySample(sampleQaEvent); for (int j = 0; j < sampleQaEvents.size(); j++) { SampleQaEvent sampQaEvent = (SampleQaEvent) sampleQaEvents.get(j); if (listOfSampleQaEventIds.contains(sampQaEvent.getId())) { for (int k = 0; k < listOfAddedActionIdsForSample.size(); k++) { Action action = new Action(); action.setId((String) listOfAddedActionIdsForSample.get(k)); actionDAO.getData(action); //if this analysis qa event action doesn't already exist in ANALYSIS_QA_EVENT_ACTION then insert it if (action != null) { SampleQaEventAction sampQaEventAction = new SampleQaEventAction(); sampQaEventAction.setAction(action); sampQaEventAction.setSampleQaEvent(sampQaEvent); sampQaEventAction = sampleQaEventActionDAO .getSampleQaEventActionBySampleQaEventAndAction(sampQaEventAction); if (sampQaEventAction != null) { //do nothing if already exists } else { //insert this new analysis qa event action sampQaEventAction = new SampleQaEventAction(); sampQaEventAction.setSampleQaEvent(sampQaEvent); sampQaEventAction.setAction(action); sampQaEventAction.setCreatedDateForDisplay(dateAsText); sampQaEventAction.setSysUserId(sysUserId); //bugzilla 2481 sampQaEventAction.setSystemUser(systemUser); sampleQaEventActionDAO.insertData(sampQaEventAction); } } } } } } } //end 2500 //now check if we added new Qa Events if (listOfAddedQaEventIds != null && listOfAddedQaEventIds.size() > 0 && listOfTestIds != null && listOfTestIds.size() > 0) { Sample sample = new Sample(); sample.setAccessionNumber(accessionNumber); sampleDAO.getSampleByAccessionNumber(sample); List analyses = new ArrayList(); if (!StringUtil.isNullorNill(sample.getId())) { SampleItem sampleItem = new SampleItem(); sampleItem.setSample(sample); sampleItemDAO.getDataBySample(sampleItem); if (sampleItem.getId() != null) { //bugzilla 2227 analyses = analysisDAO.getMaxRevisionAnalysesBySample(sampleItem); } } if (analyses != null) { for (int i = 0; i < analyses.size(); i++) { Analysis analysis = (Analysis) analyses.get(i); if (listOfTestIds.contains(analysis.getTest().getId())) { //insert all qaEvents selected for this test if doesn't exist already for (int j = 0; j < listOfAddedQaEventIds.size(); j++) { //if this doesn't exist in in ANALYSIS_QAEVENT already then insert it QaEvent qaEvent = new QaEvent(); qaEvent.setId((String) listOfAddedQaEventIds.get(j)); qaEventDAO.getData(qaEvent); if (qaEvent != null) { AnalysisQaEvent analysisQaEvent = new AnalysisQaEvent(); analysisQaEvent.setAnalysis(analysis); analysisQaEvent.setQaEvent(qaEvent); analysisQaEvent = analysisQaEventDAO .getAnalysisQaEventByAnalysisAndQaEvent(analysisQaEvent); if (analysisQaEvent != null) { //do nothing } else { //insert this new analysis qa event analysisQaEvent = new AnalysisQaEvent(); analysisQaEvent.setAnalysis(analysis); analysisQaEvent.setQaEvent(qaEvent); analysisQaEvent.setSysUserId(sysUserId); analysisQaEventDAO.insertData(analysisQaEvent); } } } } } } } //now check if we added new Actions if (listOfAnalysisQaEventIds != null && listOfAnalysisQaEventIds.size() > 0 && listOfActionIds != null && listOfActionIds.size() > 0) { Sample sample = new Sample(); sample.setAccessionNumber(accessionNumber); sampleDAO.getSampleByAccessionNumber(sample); List analyses = new ArrayList(); if (!StringUtil.isNullorNill(sample.getId())) { SampleItem sampleItem = new SampleItem(); sampleItem.setSample(sample); sampleItemDAO.getDataBySample(sampleItem); if (sampleItem.getId() != null) { //bugzilla 2227 analyses = analysisDAO.getMaxRevisionAnalysesBySample(sampleItem); } } if (analyses != null) { for (int i = 0; i < analyses.size(); i++) { Analysis analysis = (Analysis) analyses.get(i); AnalysisQaEvent analysisQaEvent = new AnalysisQaEvent(); analysisQaEvent.setAnalysis(analysis); List analysisQaEvents = analysisQaEventDAO .getAnalysisQaEventsByAnalysis(analysisQaEvent); for (int j = 0; j < analysisQaEvents.size(); j++) { AnalysisQaEvent analQaEvent = (AnalysisQaEvent) analysisQaEvents.get(j); if (listOfAnalysisQaEventIds.contains(analQaEvent.getId())) { for (int k = 0; k < listOfActionIds.size(); k++) { Action action = new Action(); action.setId((String) listOfActionIds.get(k)); actionDAO.getData(action); //if this analysis qa event action doesn't already exist in ANALYSIS_QA_EVENT_ACTION then insert it if (action != null) { AnalysisQaEventAction analQaEventAction = new AnalysisQaEventAction(); analQaEventAction.setAction(action); analQaEventAction.setAnalysisQaEvent(analQaEvent); analQaEventAction = analysisQaEventActionDAO .getAnalysisQaEventActionByAnalysisQaEventAndAction( analQaEventAction); if (analQaEventAction != null) { //do nothing if already exists } else { //insert this new analysis qa event action analQaEventAction = new AnalysisQaEventAction(); analQaEventAction.setAnalysisQaEvent(analQaEvent); analQaEventAction.setAction(action); analQaEventAction.setCreatedDateForDisplay(dateAsText); analQaEventAction.setSysUserId(sysUserId); //bugzilla 2481 analQaEventAction.setSystemUser(systemUser); analysisQaEventActionDAO.insertData(analQaEventAction); } } } } } } } } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("QaEventsEntryUpdateAction", "performAction()", lre.toString()); tx.rollback(); errors = new ActionMessages(); ActionError error = null; if (lre.getException() instanceof org.hibernate.StaleObjectStateException) { error = new ActionError("errors.OptimisticLockException", null, null); } else { error = new ActionError("errors.UpdateException", null, null); } errors.add(ActionMessages.GLOBAL_MESSAGE, error); saveErrors(request, errors); request.setAttribute(Globals.ERROR_KEY, errors); forward = FWD_FAIL; } finally { HibernateUtil.closeSession(); } } PropertyUtils.setProperty(dynaForm, "accessionNumber", accessionNumber); PropertyUtils.setProperty(dynaForm, "selectedAnalysisQaEventIdsForCompletion", selectedAnalysisQaEventIdsForCompletion); //bugzilla 2500 PropertyUtils.setProperty(dynaForm, "selectedSampleQaEventIdsForCompletion", selectedSampleQaEventIdsForCompletion); //bugzilla 2566 for now qa events is for human and newborn //PropertyUtils.setProperty(dynaForm, "domain", domain); PropertyUtils.setProperty(dynaForm, "testQaEvents", testQaEvents); //bugzilla 2501 PropertyUtils.setProperty(dynaForm, "multipleSampleMode", multipleSampleMode); PropertyUtils.setProperty(dynaForm, "selectedQaEventsCategoryId", qaEventCategoryId); return mapping.findForward(forward); }