List of usage examples for org.apache.commons.beanutils PropertyUtils copyProperties
public static void copyProperties(Object dest, Object orig) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Copy property values from the "origin" bean to the "destination" bean for all cases where the property names are the same (even though the actual getter and setter methods might have been customized via BeanInfo
classes).
For more details see PropertyUtilsBean
.
From source file:us.mn.state.health.lims.panel.action.PanelUpdateAction.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 Panel. // If there is a parameter present, we should bring up an existing // Panel 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 .java 2 s .c om } else { isNew = false; } BaseActionForm dynaForm = (BaseActionForm) form; // server-side validation (validation.xml) ActionMessages errors = dynaForm.validate(mapping, request); if (errors != null && errors.size() > 0) { // System.out.println("Server side validation errors " // + errors.toString()); saveErrors(request, errors); // since we forward to jsp - not Action we don't need to repopulate // the lists here return mapping.findForward(FWD_FAIL); } String start = (String) request.getParameter("startingRecNo"); String direction = (String) request.getParameter("direction"); // System.out.println("This is ID from request " + id); Panel panel = new Panel(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); panel.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); // populate valueholder from form PropertyUtils.copyProperties(panel, dynaForm); try { PanelDAO panelDAO = new PanelDAOImpl(); if (!isNew) { // UPDATE panelDAO.updateData(panel); } else { // INSERT panelDAO.insertData(panel); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("PanelUpdateAction", "performAction()", lre.toString()); tx.rollback(); errors = new ActionMessages(); java.util.Locale locale = (java.util.Locale) request.getSession() .getAttribute("org.apache.struts.action.LOCALE"); ActionError error = null; if (lre.getException() instanceof org.hibernate.StaleObjectStateException) { // 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 { // bugzilla 1482 if (lre.getException() instanceof LIMSDuplicateRecordException) { //AIS - bugzilla 1563 String messageKey = ""; if (lre.getException().getMessage() .equalsIgnoreCase("Duplicate record exists for panel description")) { messageKey = "panel.description"; } else { messageKey = "panel.panelName"; } 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); //bugzilla 1485: allow change and try updating again (enable save button) //request.setAttribute(IActionConstants.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, panel); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (panel.getId() != null && !panel.getId().equals("0")) { request.setAttribute(ID, panel.getId()); } //bugzilla 1400 if (isNew) forward = FWD_SUCCESS_INSERT; //bugzilla 1467 added direction for redirect to NextPreviousAction return getForward(mapping.findForward(forward), id, start, direction); }
From source file:us.mn.state.health.lims.panel.daoimpl.PanelDAOImpl.java
public void getData(Panel panel) throws LIMSRuntimeException { try {// w w w. j a va2s . c o m Panel pan = (Panel) HibernateUtil.getSession().get(Panel.class, panel.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (pan != null) { PropertyUtils.copyProperties(panel, pan); } else { panel.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("PanelDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in Panel getData()", e); } }
From source file:us.mn.state.health.lims.panelitem.action.PanelItemAction.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 PanelItem. // If there is a parameter present, we should bring up an existing // PanelItem to edit. String id = request.getParameter(ID); String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); DynaActionForm dynaForm = (DynaActionForm) form; // initialize the form dynaForm.initialize(mapping);//from www. j ava 2s . c o m PanelItem panelItem = new PanelItem(); if ((id != null) && (!"0".equals(id))) { // this is an existing // panelItem panelItem.setId(id); PanelItemDAO panelItemDAO = new PanelItemDAOImpl(); panelItemDAO.getData(panelItem); // initialize selectedPanelItemId if (panelItem.getPanel() != null) { panelItem.setSelectedPanelId(panelItem.getPanel().getId()); } isNew = false; // this is to set correct page title // do we need to enable next or previous? List panelItems = panelItemDAO.getNextPanelItemRecord(panelItem.getId()); if (panelItems.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } panelItems = panelItemDAO.getPreviousPanelItemRecord(panelItem.getId()); if (panelItems.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new panelItem isNew = true; // this is to set correct page title } if (panelItem.getId() != null && !panelItem.getId().equals("0")) { request.setAttribute(ID, panelItem.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, panelItem); PanelDAO panelDAO = new PanelDAOImpl(); MethodDAO methodDAO = new MethodDAOImpl(); TestDAO testDAO = new TestDAOImpl(); List parentPanels = panelDAO.getAllActivePanels(); List methods = methodDAO.getAllMethods(); //Get tests by user system id //bugzilla 2160 UserTestSectionDAO userTestSectionDAO = new UserTestSectionDAOImpl(); //bugzilla 2291 List tests = userTestSectionDAO.getAllUserTests(request, true); // set parentPanelName String parentPanelName = null; for (int i = 0; i < parentPanels.size(); i++) { Panel parentPanel = (Panel) parentPanels.get(i); if (parentPanel.getId().equals(panelItem.getSelectedPanelId())) { parentPanelName = parentPanel.getPanelName(); } } PropertyUtils.setProperty(form, "parentPanels", parentPanels); PropertyUtils.setProperty(form, "parentPanelName", parentPanelName); PropertyUtils.setProperty(form, "methods", methods); PropertyUtils.setProperty(form, "tests", tests); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.panelitem.action.PanelItemUpdateAction.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 PanelItem. // If there is a parameter present, we should bring up an existing // PanelItem 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 .j a v a 2 s. c o m*/ } else { isNew = false; } BaseActionForm dynaForm = (BaseActionForm) form; // server-side validation (validation.xml) ActionMessages errors = dynaForm.validate(mapping, request); try { errors = validateAll(request, errors, dynaForm); } catch (Exception e) { //bugzilla 2154 LogEvent.logError("PanelItemUpdateAction", "performAction()", e.toString()); ActionError error = new ActionError("errors.ValidationException", null, null); errors.add(ActionMessages.GLOBAL_MESSAGE, error); } if (errors != null && errors.size() > 0) { // System.out.println("Server side validation errors " // + errors.toString()); saveErrors(request, errors); // since we forward to jsp - not Action we don't need to repopulate // the lists here return mapping.findForward(FWD_FAIL); } String start = (String) request.getParameter("startingRecNo"); String direction = (String) request.getParameter("direction"); // System.out.println("This is ID from request " + id); PanelItem panelItem = new PanelItem(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); panelItem.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); // String selectedPanelItemId = (String) // dynaForm.get("selectedPanelItemId"); String parentPanelName = (String) dynaForm.get("parentPanelName"); List methods = new ArrayList(); List tests = new ArrayList(); if (dynaForm.get("methods") != null) { methods = (List) dynaForm.get("methods"); } else { MethodDAO methodDAO = new MethodDAOImpl(); methods = methodDAO.getAllMethods(); } if (dynaForm.get("tests") != null) { tests = (List) dynaForm.get("tests"); } else { //Get tests by user system id //bugzilla 2160 UserTestSectionDAO userTestSectionDAO = new UserTestSectionDAOImpl(); //bugzilla 2291 tests = userTestSectionDAO.getAllUserTests(request, true); } // System.out.println("This is selectedPanelItemId " // + dynaForm.get("selectedPanelItemId")); List pans = new ArrayList(); if (dynaForm.get("parentPanels") != null) { pans = (List) dynaForm.get("parentPanels"); } else { PanelDAO panDAO = new PanelDAOImpl(); pans = panDAO.getAllActivePanels(); } Panel parentPanel = null; //System.out.println("Try to find parentPanelName " + parentPanelName // + " in this list "); // get the right parentPanel to update panelItem with for (int i = 0; i < pans.size(); i++) { Panel o = (Panel) pans.get(i); // if (o.getId().equals(selectedPanelItemId)) { //System.out.println("This " + o.getPanelName()); if (o.getPanelName().equals(parentPanelName)) { parentPanel = o; break; } } // populate valueholder from form PropertyUtils.copyProperties(panelItem, dynaForm); //System.out.println("Setting parent panel teo " + parentPanel); if (parentPanel != null) { //System.out.println("This is id " + parentPanel.getId()); } panelItem.setPanel(parentPanel); try { PanelItemDAO panelItemDAO = new PanelItemDAOImpl(); if (!isNew) { // UPDATE panelItemDAO.updateData(panelItem); } else { // INSERT panelItemDAO.insertData(panelItem); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("PanelItemUpdateAction", "performAction()", lre.toString()); tx.rollback(); errors = new ActionMessages(); java.util.Locale locale = (java.util.Locale) request.getSession() .getAttribute("org.apache.struts.action.LOCALE"); ActionError error = null; if (lre.getException() instanceof org.hibernate.StaleObjectStateException) { // 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 { // bugzilla 1482 if (lre.getException() instanceof LIMSDuplicateRecordException) { String messageKey = "panelitem.panelitem"; 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); //bugzilla 1485: allow change and try updating again (enable save button) //request.setAttribute(IActionConstants.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, panelItem); // need to repopulate in case of FWD_FAIL? PropertyUtils.setProperty(form, "parentPanels", pans); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (panelItem.getId() != null && !panelItem.getId().equals("0")) { request.setAttribute(ID, panelItem.getId()); } //bugzilla 1400 if (isNew) forward = FWD_SUCCESS_INSERT; //bugzilla 1467 added direction for redirect to NextPreviousAction return getForward(mapping.findForward(forward), id, start, direction); }
From source file:us.mn.state.health.lims.panelitem.daoimpl.PanelItemDAOImpl.java
public void getData(PanelItem panelItem) throws LIMSRuntimeException { try {//from ww w.j a v a 2s . c om PanelItem data = (PanelItem) HibernateUtil.getSession().get(PanelItem.class, panelItem.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (data != null) { PropertyUtils.copyProperties(panelItem, data); } else { panelItem.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("PanelItemDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in PanelItem getData()", e); } }
From source file:us.mn.state.health.lims.patient.action.PatientAction.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 Patient. // If there is a parameter present, we should bring up an existing // Patient to edit. String id = request.getParameter(ID); String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); DynaActionForm dynaForm = (DynaActionForm) form; // initialize the form dynaForm.initialize(mapping);/* w ww . ja v a2s .c o m*/ Patient patient = new Patient(); //System.out.println("I am in PatientAction and this is id " + id); if ((id != null) && (!"0".equals(id))) { // this is an existing // patient patient.setId(id); PatientDAO patientDAO = new PatientDAOImpl(); patientDAO.getData(patient); // initialize selectedPersonId if (patient.getPerson() != null) { patient.setSelectedPersonId(patient.getPerson().getId()); } isNew = false; // this is to set correct page title // do we need to enable next or previous? List patients = patientDAO.getNextPatientRecord(patient.getId()); if (patients.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } patients = patientDAO.getPreviousPatientRecord(patient.getId()); if (patients.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new patient isNew = true; // this is to set correct page title } if (patient.getId() != null && !patient.getId().equals("0")) { request.setAttribute(ID, patient.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, patient); PersonDAO personDAO = new PersonDAOImpl(); GenderDAO genderDAO = new GenderDAOImpl(); List persons = personDAO.getAllPersons(); List genders = genderDAO.getAllGenders(); PropertyUtils.setProperty(form, "persons", persons); PropertyUtils.setProperty(form, "genders", genders); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.patient.action.PatientManagementUpdateAction.java
private void copyFormBeanToValueHolders(PatientManagementInfo patientInfo) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { PropertyUtils.copyProperties(patient, patientInfo); PropertyUtils.copyProperties(person, patientInfo); }
From source file:us.mn.state.health.lims.patient.action.PatientUpdateAction.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 Patient. // If there is a parameter present, we should bring up an existing // Patient 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 . j av a2 s.co 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"); Patient patient = new Patient(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); patient.setSysUserId(sysUserId); Transaction tx = HibernateUtil.getSession().beginTransaction(); String selectedPersonId = (String) dynaForm.get("selectedPersonId"); List persons = new ArrayList(); List genders = new ArrayList(); if (dynaForm.get("persons") != null) { persons = (List) dynaForm.get("persons"); } else { PersonDAO personDAO = new PersonDAOImpl(); persons = personDAO.getAllPersons(); } if (dynaForm.get("genders") != null) { genders = (List) dynaForm.get("genders"); } else { GenderDAO genderDAO = new GenderDAOImpl(); genders = genderDAO.getAllGenders(); } Person person = null; // get the right person to update patient 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(patient, dynaForm); patient.setPerson(person); try { PatientDAO patientDAO = new PatientDAOImpl(); if (!isNew) { // UPDATE patientDAO.updateData(patient); if (FWD_NEXT.equals(direction)) { List patients = patientDAO.getNextPatientRecord(patient.getId()); if (patients != null && patients.size() > 0) { patient = (Patient) patients.get(0); patientDAO.getData(patient); if (patients.size() < 2) { // disable next button request.setAttribute(NEXT_DISABLED, "true"); } id = patient.getId(); } else { // disable next button request.setAttribute(NEXT_DISABLED, "true"); } forward = FWD_NEXT; } if (FWD_PREVIOUS.equals(direction)) { List patients = patientDAO.getPreviousPatientRecord(patient.getId()); if (patients != null && patients.size() > 0) { patient = (Patient) patients.get(0); patientDAO.getData(patient); if (patients.size() < 2) { // disable previous button request.setAttribute(PREVIOUS_DISABLED, "true"); } id = patient.getId(); } else { // disable previous button request.setAttribute(PREVIOUS_DISABLED, "true"); } forward = FWD_PREVIOUS; } } else { // INSERT patientDAO.insertData(patient); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("PatientUpdateAction", "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, patient); PropertyUtils.setProperty(dynaForm, "persons", persons); PropertyUtils.setProperty(dynaForm, "genders", genders); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (patient.getId() != null && !patient.getId().equals("0")) { request.setAttribute(ID, patient.getId()); } //bugzilla 1400 if (isNew) forward = FWD_SUCCESS_INSERT; return getForward(mapping.findForward(forward), id, start); }
From source file:us.mn.state.health.lims.patient.daoimpl.PatientDAOImpl.java
public void getData(Patient patient) throws LIMSRuntimeException { try {//w w w .j a va2 s . c o m Patient pat = (Patient) HibernateUtil.getSession().get(Patient.class, patient.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (pat != null) { updateDisplayValues(pat); PropertyUtils.copyProperties(patient, pat); } else { patient.setId(null); } } catch (Exception e) { LogEvent.logError("PatientDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in Patient getData()", e); } }
From source file:us.mn.state.health.lims.patient.saving.Accessioner.java
/** * Assume all the fields on the dynaForm have the right names (see code) and * @throws IllegalAccessException//from ww w . j ava 2 s. c o m * @throws InvocationTargetException * @throws NoSuchMethodException */ protected void populatePatientData() throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { DynaBean dynaForm = projectFormMapper.getDynaBean(); Timestamp lastupdated1 = patientInDB.getLastupdated(); PropertyUtils.copyProperties(patientInDB, dynaForm); patientInDB.setLastupdated(lastupdated1); Person person = patientInDB.getPerson(); PropertyUtils.copyProperties(person, dynaForm); patientInDB.setNationalId(convertEmptyToNull((String) dynaForm.get("subjectNumber"))); patientInDB.setExternalId(convertEmptyToNull((String) dynaForm.get("siteSubjectNumber"))); populatePatientBirthDate((String) dynaForm.get("birthDateForDisplay")); projectData = (ProjectData) dynaForm.get("ProjectData"); if (projectData != null) { person.setHomePhone(convertEmptyToNull(projectData.getPhoneNumber())); person.setFax(convertEmptyToNull(projectData.getFaxNumber())); person.setEmail(convertEmptyToNull(projectData.getEmail())); person.setStreetAddress(convertEmptyToNull(projectData.getAddress())); } }