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.typeofsample.daoimpl.TypeOfSampleTestDAOImpl.java
public void getData(TypeOfSampleTest typeOfSample) throws LIMSRuntimeException { try {// w ww . j ava2 s.c o m TypeOfSampleTest tos = (TypeOfSampleTest) HibernateUtil.getSession().get(TypeOfSampleTest.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 TypeOfSampleTest getData()", e); } }
From source file:us.mn.state.health.lims.typeoftestresult.action.TypeOfTestResultAction.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 TypeOfTestResult. // If there is a parameter present, we should bring up an existing // TypeOfTestResult to edit. String id = request.getParameter(ID); String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); DynaActionForm dynaForm = (DynaActionForm) form; // initialize the form dynaForm.initialize(mapping);// w w w .ja va2 s.com TypeOfTestResult typeOfTestResult = new TypeOfTestResult(); System.out.println("I am in TypeOfTestResultAction and this is id " + id); if ((id != null) && (!"0".equals(id))) { // this is an existing // typeOfTestResult typeOfTestResult.setId(id); TypeOfTestResultDAO typeOfTestResultDAO = new TypeOfTestResultDAOImpl(); typeOfTestResultDAO.getData(typeOfTestResult); isNew = false; // this is to set correct page title // do we need to enable next or previous? //bugzilla 1427 pass in desc not id List typeOfTestResults = typeOfTestResultDAO .getNextTypeOfTestResultRecord(typeOfTestResult.getDescription()); if (typeOfTestResults.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } //bugzilla 1427 pass in desc not id typeOfTestResults = typeOfTestResultDAO .getPreviousTypeOfTestResultRecord(typeOfTestResult.getDescription()); if (typeOfTestResults.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new typeOfTestResult isNew = true; // this is to set correct page title } if (typeOfTestResult.getId() != null && !typeOfTestResult.getId().equals("0")) { request.setAttribute(ID, typeOfTestResult.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, typeOfTestResult); System.out.println("I am in TypeOfTestResultAction this is forward " + forward); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.typeoftestresult.action.TypeOfTestResultUpdateAction.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 TypeOfTestResult. // If there is a parameter present, we should bring up an existing // TypeOfTestResult 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 va 2 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"); TypeOfTestResult typeOfTestResult = new TypeOfTestResult(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); typeOfTestResult.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); // populate valueholder from form PropertyUtils.copyProperties(typeOfTestResult, dynaForm); try { TypeOfTestResultDAO typeOfTestResultDAO = new TypeOfTestResultDAOImpl(); if (!isNew) { // UPDATE typeOfTestResultDAO.updateData(typeOfTestResult); } else { // INSERT typeOfTestResultDAO.insertData(typeOfTestResult); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("TypeOfTestResultUpdateAction", "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 = "typeoftestresult.testResultType"; 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"); 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, typeOfTestResult); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (typeOfTestResult.getId() != null && !typeOfTestResult.getId().equals("0")) { request.setAttribute(ID, typeOfTestResult.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.typeoftestresult.daoimpl.TypeOfTestResultDAOImpl.java
public void getData(TypeOfTestResult typeOfTestResult) throws LIMSRuntimeException { try {/*from w w w . j av a2s. co m*/ TypeOfTestResult sc = (TypeOfTestResult) HibernateUtil.getSession().get(TypeOfTestResult.class, typeOfTestResult.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (sc != null) { PropertyUtils.copyProperties(typeOfTestResult, sc); } else { typeOfTestResult.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("TypeOfTestResultDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in TypeOfTestResult getData()", e); } }
From source file:us.mn.state.health.lims.unitofmeasure.action.UnitOfMeasureAction.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 UnitOfMeasure. // If there is a parameter present, we should bring up an existing // UnitOfMeasure to edit. String id = request.getParameter(ID); String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); DynaActionForm dynaForm = (DynaActionForm) form; // initialize the form dynaForm.initialize(mapping);/* w w w. ja v a2s .c o m*/ UnitOfMeasure unitOfMeasure = new UnitOfMeasure(); if ((id != null) && (!"0".equals(id))) { // this is an existing // unitOfMeasure unitOfMeasure.setId(id); UnitOfMeasureDAO unitOfMeasureDAO = new UnitOfMeasureDAOImpl(); unitOfMeasureDAO.getData(unitOfMeasure); 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 unitOfMeasures = unitOfMeasureDAO.getNextUnitOfMeasureRecord(unitOfMeasure.getUnitOfMeasureName()); if (unitOfMeasures.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } //bugzilla 1427 pass in name not id unitOfMeasures = unitOfMeasureDAO.getPreviousUnitOfMeasureRecord(unitOfMeasure.getUnitOfMeasureName()); if (unitOfMeasures.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new unitOfMeasure isNew = true; // this is to set correct page title } if (unitOfMeasure.getId() != null && !unitOfMeasure.getId().equals("0")) { request.setAttribute(ID, unitOfMeasure.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, unitOfMeasure); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.unitofmeasure.action.UnitOfMeasureUpdateAction.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 UnitOfMeasure. // If there is a parameter present, we should bring up an existing // UnitOfMeasure 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 .j av a 2 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"); UnitOfMeasure unitOfMeasure = new UnitOfMeasure(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); unitOfMeasure.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); // populate valueholder from form PropertyUtils.copyProperties(unitOfMeasure, dynaForm); try { UnitOfMeasureDAO unitOfMeasureDAO = new UnitOfMeasureDAOImpl(); if (!isNew) { // UPDATE unitOfMeasureDAO.updateData(unitOfMeasure); } else { // INSERT unitOfMeasureDAO.insertData(unitOfMeasure); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("UnitOfMeasureUpdateAction", "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 = "unitofmeasure.unitOfMeasureName"; 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, unitOfMeasure); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (unitOfMeasure.getId() != null && !unitOfMeasure.getId().equals("0")) { request.setAttribute(ID, unitOfMeasure.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.unitofmeasure.daoimpl.UnitOfMeasureDAOImpl.java
public void getData(UnitOfMeasure unitOfMeasure) throws LIMSRuntimeException { try {//from w w w . j a va2s. c o m UnitOfMeasure uom = (UnitOfMeasure) HibernateUtil.getSession().get(UnitOfMeasure.class, unitOfMeasure.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (uom != null) { PropertyUtils.copyProperties(unitOfMeasure, uom); } else { unitOfMeasure.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("UnitOfMeasureDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in UnitOfMeasure getData()", e); } }
From source file:us.mn.state.health.lims.userrole.daoimpl.UserRoleDAOImpl.java
public void getData(UserRole role) throws LIMSRuntimeException { try {//from ww w . j a v a2 s . c om UserRole tmpUserRole = (UserRole) HibernateUtil.getSession().get(UserRole.class, role.getCompoundId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (tmpUserRole != null) { PropertyUtils.copyProperties(role, tmpUserRole); } else { role.setCompoundId(null); } } catch (Exception e) { LogEvent.logError("UserRolesDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in UserRole getData()", e); } }