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.testresult.action.TestResultUpdateAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // The first job is to determine if we are coming to this action with an // ID parameter in the request. If there is no parameter, we are // creating a new TestResult. // If there is a parameter present, we should bring up an existing // TestResult to edit. String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "false"); request.setAttribute(NEXT_DISABLED, "false"); String id = request.getParameter(ID); if (StringUtil.isNullorNill(id) || "0".equals(id)) { isNew = true;/*w ww .ja va 2 s . c om*/ } 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("TestResultUpdateAction", "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); TestResult testResult = new TestResult(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); testResult.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); Test test = new Test(); String testName = (String) dynaForm.get("testName"); test.setTestName(testName); TestDAO testDAO = new TestDAOImpl(); test = testDAO.getTestByName(test); Scriptlet scriptlet = new Scriptlet(); String scriptletName = (String) dynaForm.get("scriptletName"); scriptlet.setScriptletName(scriptletName); ScriptletDAO scriptletDAO = new ScriptletDAOImpl(); Scriptlet s = scriptletDAO.getScriptletByName(scriptlet); // populate valueholder from form PropertyUtils.copyProperties(testResult, dynaForm); testResult.setTest(test); testResult.setScriptlet(s); try { TestResultDAO testResultDAO = new TestResultDAOImpl(); if (!isNew) { // UPDATE testResultDAO.updateData(testResult); if (FWD_NEXT.equals(direction)) { List testResults = testResultDAO.getNextTestResultRecord(testResult.getId()); if (testResults != null && testResults.size() > 0) { testResult = (TestResult) testResults.get(0); testResultDAO.getData(testResult); if (testResults.size() < 2) { // disable next button request.setAttribute(NEXT_DISABLED, "true"); } id = testResult.getId(); } else { // just disable next button request.setAttribute(NEXT_DISABLED, "true"); } forward = FWD_NEXT; } if (FWD_PREVIOUS.equals(direction)) { List testResults = testResultDAO.getPreviousTestResultRecord(testResult.getId()); if (testResults != null && testResults.size() > 0) { testResult = (TestResult) testResults.get(0); testResultDAO.getData(testResult); if (testResults.size() < 2) { // disable previous button request.setAttribute(PREVIOUS_DISABLED, "true"); } id = testResult.getId(); } else { // just disable next button request.setAttribute(PREVIOUS_DISABLED, "true"); } forward = FWD_PREVIOUS; } } else { // INSERT testResultDAO.insertData(testResult); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("TestResultUpdateAction", "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, testResult); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (testResult.getId() != null && !testResult.getId().equals("0")) { request.setAttribute(ID, testResult.getId()); } //bugzilla 1400 if (isNew) forward = FWD_SUCCESS_INSERT; return getForward(mapping.findForward(forward), id, start); }
From source file:us.mn.state.health.lims.testresult.daoimpl.TestResultDAOImpl.java
public void getData(TestResult testResult) throws LIMSRuntimeException { try {//from w w w . ja va2 s . co m TestResult tr = (TestResult) HibernateUtil.getSession().get(TestResult.class, testResult.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (tr != null) { PropertyUtils.copyProperties(testResult, tr); } else { testResult.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("TestResultDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in TestResult getData()", e); } }
From source file:us.mn.state.health.lims.testtrailer.action.TestTrailerAction.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 TestTrailer. // If there is a parameter present, we should bring up an existing // TestTrailer to edit. String id = request.getParameter(ID); String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); DynaActionForm dynaForm = (DynaActionForm) form; // initialize the form dynaForm.initialize(mapping);//from w w w. j a v a 2s . com TestTrailer testTrailer = new TestTrailer(); if ((id != null) && (!"0".equals(id))) { // this is an existing // testTrailer testTrailer.setId(id); TestTrailerDAO testTrailerDAO = new TestTrailerDAOImpl(); testTrailerDAO.getData(testTrailer); isNew = false; // this is to set correct page title // do we need to enable next or previous? //bugzilla 1427 pass in name not id List testTrailers = testTrailerDAO.getNextTestTrailerRecord(testTrailer.getTestTrailerName()); if (testTrailers.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } //bugzilla 1427 pass in name not id testTrailers = testTrailerDAO.getPreviousTestTrailerRecord(testTrailer.getTestTrailerName()); if (testTrailers.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new testTrailer isNew = true; // this is to set correct page title } if (testTrailer.getId() != null && !testTrailer.getId().equals("0")) { request.setAttribute(ID, testTrailer.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, testTrailer); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.testtrailer.action.TestTrailerUpdateAction.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 TestTrailer. // If there is a parameter present, we should bring up an existing // TestTrailer 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 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"); TestTrailer testTrailer = new TestTrailer(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); testTrailer.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); // populate valueholder from form PropertyUtils.copyProperties(testTrailer, dynaForm); try { TestTrailerDAO testTrailerDAO = new TestTrailerDAOImpl(); if (!isNew) { // UPDATE testTrailerDAO.updateData(testTrailer); } else { // INSERT testTrailerDAO.insertData(testTrailer); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("TestTrailerUpdateAction", "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 = "testtrailer.testTrailerName"; 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, testTrailer); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (testTrailer.getId() != null && !testTrailer.getId().equals("0")) { request.setAttribute(ID, testTrailer.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.testtrailer.daoimpl.TestTrailerDAOImpl.java
public void getData(TestTrailer testTrailer) throws LIMSRuntimeException { try {/*from w w w. j ava 2 s .c o m*/ TestTrailer uom = (TestTrailer) HibernateUtil.getSession().get(TestTrailer.class, testTrailer.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (uom != null) { PropertyUtils.copyProperties(testTrailer, uom); } else { testTrailer.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("TestTrailerDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in TestTrailer getData()", e); } }
From source file:us.mn.state.health.lims.typeofsample.action.TypeOfSampleAction.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 TypeOfSample. // If there is a parameter present, we should bring up an existing // TypeOfSample to edit. String id = request.getParameter(ID); String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); DynaActionForm dynaForm = (DynaActionForm) form; // initialize the form dynaForm.initialize(mapping);//from w w w . j av a2 s .co m TypeOfSample typeOfSample = new TypeOfSample(); if ((id != null) && (!"0".equals(id))) { // this is an existing // typeOfSample typeOfSample.setId(id); TypeOfSampleDAO typeOfSampleDAO = new TypeOfSampleDAOImpl(); typeOfSampleDAO.getData(typeOfSample); isNew = false; // this is to set correct page title // do we need to enable next or previous? List typeOfSamples = typeOfSampleDAO.getNextTypeOfSampleRecord(typeOfSample.getId()); if (typeOfSamples.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } typeOfSamples = typeOfSampleDAO.getPreviousTypeOfSampleRecord(typeOfSample.getId()); if (typeOfSamples.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new typeOfSample isNew = true; // this is to set correct page title } if (typeOfSample.getId() != null && !typeOfSample.getId().equals("0")) { request.setAttribute(ID, typeOfSample.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, typeOfSample); SampleDomainDAO sampleDomainDAO = new SampleDomainDAOImpl(); List domains = sampleDomainDAO.getAllSampleDomains(); PropertyUtils.setProperty(form, "domains", domains); //System.out.println("I am in TypeOfSampleAction this is forward " // + forward); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.typeofsample.action.TypeOfSampleUpdateAction.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 TypeOfSample. // If there is a parameter present, we should bring up an existing // TypeOfSample 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 ww. ja v a2 s. 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"); TypeOfSample typeOfSample = new TypeOfSample(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); typeOfSample.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); List domains = new ArrayList(); if (dynaForm.get("domains") != null) { domains = (List) dynaForm.get("domains"); } else { SampleDomainDAO sampleDomainDAO = new SampleDomainDAOImpl(); domains = sampleDomainDAO.getAllSampleDomains(); } // populate valueholder from form PropertyUtils.copyProperties(typeOfSample, form); try { TypeOfSampleDAO typeOfSampleDAO = new TypeOfSampleDAOImpl(); if (!isNew) { // UPDATE typeOfSampleDAO.updateData(typeOfSample); } else { // INSERT typeOfSampleDAO.insertData(typeOfSample); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("TypeOfSampleUpdateAction", "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 = "typeofsample.typeofsample"; 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, typeOfSample); PropertyUtils.setProperty(form, "domains", domains); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (typeOfSample.getId() != null && !typeOfSample.getId().equals("0")) { request.setAttribute(ID, typeOfSample.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.typeofsample.daoimpl.TypeOfSampleDAOImpl.java
public void getData(TypeOfSample typeOfSample) throws LIMSRuntimeException { try {// w w w. j a va 2 s . com TypeOfSample tos = (TypeOfSample) HibernateUtil.getSession().get(TypeOfSample.class, typeOfSample.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (tos != null) { PropertyUtils.copyProperties(typeOfSample, tos); } else { typeOfSample.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("TypeOfSampleDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in TypeOfSample getData()", e); } }
From source file:us.mn.state.health.lims.typeofsample.daoimpl.TypeOfSamplePanelDAOImpl.java
public void getData(TypeOfSamplePanel typeOfSamplePanel) throws LIMSRuntimeException { try {/*w w w. j av a 2 s.c om*/ TypeOfSamplePanel tos = (TypeOfSamplePanel) HibernateUtil.getSession().get(TypeOfSamplePanel.class, typeOfSamplePanel.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (tos != null) { PropertyUtils.copyProperties(typeOfSamplePanel, tos); } else { typeOfSamplePanel.setId(null); } } catch (Exception e) { LogEvent.logError("TypeOfSamplePanelDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in TypeOfSamplePanel getData()", e); } }
From source file:us.mn.state.health.lims.typeofsample.daoimpl.TypeOfSampleSourceDAOImpl.java
public void getData(TypeOfSampleSource typeOfSampleSource) throws LIMSRuntimeException { try {/*from www. j a va 2 s. c o m*/ TypeOfSampleSource tos = (TypeOfSampleSource) HibernateUtil.getSession().get(TypeOfSampleSource.class, typeOfSampleSource.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (tos != null) { PropertyUtils.copyProperties(typeOfSampleSource, tos); } else { typeOfSampleSource.setId(null); } } catch (Exception e) { LogEvent.logError("TypeOfSampleSourceDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in TypeOfSampleSource getData()", e); } }