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.analyte.action.AnalyteUpdateAction.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"); String id = request.getParameter(ID); if (StringUtil.isNullorNill(id) || "0".equals(id)) { isNew = true;//from w w w.j av a2s.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("AnalyteUpdateAction", "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); Analyte analyte = new Analyte(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); analyte.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); // String selectedAnalyteId = (String) // dynaForm.get("selectedAnalyteId"); String parentAnalyteName = (String) dynaForm.get("parentAnalyteName"); // System.out.println("This is selectedAnalyteId " // + dynaForm.get("selectedAnalyteId")); List anals = new ArrayList(); if (dynaForm.get("parentAnalytes") != null) { anals = (List) dynaForm.get("parentAnalytes"); } else { AnalyteDAO analDAO = new AnalyteDAOImpl(); anals = analDAO.getAllAnalytes(); } Analyte parentAnalyte = null; // get the right parentAnalyte to update analyte with for (int i = 0; i < anals.size(); i++) { Analyte o = (Analyte) anals.get(i); // if (o.getId().equals(selectedAnalyteId)) { if ((o != null) && (parentAnalyteName != null)) { if (o.getAnalyteName().equals(parentAnalyteName)) { parentAnalyte = o; break; } } } // populate valueholder from form PropertyUtils.copyProperties(analyte, dynaForm); analyte.setAnalyte(parentAnalyte); try { AnalyteDAO analyteDAO = new AnalyteDAOImpl(); if (!isNew) { // UPDATE analyteDAO.updateData(analyte); } else { // INSERT analyteDAO.insertData(analyte); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("AnalyteUpdateAction", "performAction()", lre.toString()); tx.rollback(); errors = new ActionMessages(); ActionError error = null; //bugzilla 1482 java.util.Locale locale = (java.util.Locale) request.getSession() .getAttribute("org.apache.struts.action.LOCALE"); 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) { //bugzilla 2432 String messageKey = "analyte.analyteNameOrLocalAbbreviation"; String msg = ResourceLocator.getInstance().getMessageResources().getMessage(locale, messageKey); error = new ActionError("errors.DuplicateRecord.activate", 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(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, analyte); // need to repopulate in case of FWD_FAIL? PropertyUtils.setProperty(form, "parentAnalytes", anals); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (analyte.getId() != null && !analyte.getId().equals("0")) { request.setAttribute(ID, analyte.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.analyte.daoimpl.AnalyteDAOImpl.java
public void getData(Analyte analyte) throws LIMSRuntimeException { try {//from www .j a v a2 s . co m Analyte anal = (Analyte) HibernateUtil.getSession().get(Analyte.class, analyte.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (anal != null) { PropertyUtils.copyProperties(analyte, anal); } else { analyte.setId(null); } } catch (Exception e) { //buzilla 2154 LogEvent.logError("AnalyteDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in Analyte getData()", e); } }
From source file:us.mn.state.health.lims.analyzer.daoimpl.AnalyzerDAOImpl.java
public void getData(Analyzer analyzer) throws LIMSRuntimeException { try {/* w w w .j a v a 2s. c om*/ Analyzer tmpAnalyzer = (Analyzer) HibernateUtil.getSession().get(Analyzer.class, analyzer.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (tmpAnalyzer != null) { PropertyUtils.copyProperties(analyzer, tmpAnalyzer); } else { analyzer.setId(null); } } catch (Exception e) { LogEvent.logError("AnalyzerDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in Analyzer getData()", e); } }
From source file:us.mn.state.health.lims.analyzerresults.daoimpl.AnalyzerResultsDAOImpl.java
public void getData(AnalyzerResults analyzerResults) throws LIMSRuntimeException { try {//from w w w . ja va 2 s . c om AnalyzerResults analyzerResultsClone = (AnalyzerResults) HibernateUtil.getSession() .get(AnalyzerResults.class, analyzerResults.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (analyzerResultsClone != null) { PropertyUtils.copyProperties(analyzerResults, analyzerResultsClone); } else { analyzerResults.setId(null); } } catch (Exception e) { LogEvent.logError("AnalyzerResultsDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in AnalyzerResults getData()", e); } }
From source file:us.mn.state.health.lims.city.action.CityAction.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 City. // If there is a parameter present, we should bring up an existing // City to edit. String id = request.getParameter(ID); String forward = FWD_SUCCESS; request.setAttribute(RECORD_FROZEN_EDIT_DISABLED_KEY, "false"); request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "true"); request.setAttribute(NEXT_DISABLED, "true"); BaseActionForm dynaForm = (BaseActionForm) form; // initialize the form dynaForm.initialize(mapping);//from w ww . j av a 2 s . com Dictionary dictionary = new Dictionary(); DictionaryDAO dictionaryDAO = new DictionaryDAOImpl(); isNew = (id == null) || "0".equals(id); if (!isNew) { dictionary.setId(id); dictionaryDAO.getData(dictionary); } else { // this is a new city; default isActive to 'Y' dictionary.setIsActive(YES); } if (dictionary.getId() != null && !dictionary.getId().equals("0")) { request.setAttribute(ID, dictionary.getId()); } PropertyUtils.copyProperties(form, dictionary); PropertyUtils.setProperty(form, "cityName", dictionary.getDictEntry()); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.city.action.CityUpdateAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; request.setAttribute(ALLOW_EDITS_KEY, "true"); request.setAttribute(PREVIOUS_DISABLED, "false"); request.setAttribute(NEXT_DISABLED, "false"); String id = request.getParameter(ID); isNew = (StringUtil.isNullorNill(id) || "0".equals(id)); BaseActionForm dynaForm = (BaseActionForm) form; // server-side validation (validation.xml) ActionMessages errors = dynaForm.validate(mapping, request); if (errors != null && errors.size() > 0) { saveErrors(request, errors);/* ww w . j a v a 2s.c om*/ return mapping.findForward(FWD_FAIL); } String start = (String) request.getParameter("startingRecNo"); String direction = (String) request.getParameter("direction"); String cityName = (String) dynaForm.get("cityName"); String cityIsActive = (String) dynaForm.get("isActive"); DictionaryCategoryDAO dictionaryCategoryDAO = new DictionaryCategoryDAOImpl(); Dictionary dictionary = new Dictionary(); dictionary.setId(id); dictionaryDAO.getData(dictionary); dictionary.setDictEntry(cityName); dictionary.setIsActive(cityIsActive); DictionaryCategory dictionaryCategory = new DictionaryCategory(); dictionaryCategory.setId(String.valueOf(IActionConstants.CITY_CATEGORY_ID)); dictionaryCategoryDAO.getData(dictionaryCategory); dictionary.setDictionaryCategory(dictionaryCategory); dictionary.setSortOrder(IActionConstants.CITY_SORT_ORDER); dictionary.setSysUserId(currentUserId); PropertyUtils.copyProperties(dictionary, dynaForm); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); try { if (!isNew) { dictionaryDAO.updateData(dictionary, false); } else { dictionaryDAO.insertData(dictionary); } tx.commit(); } catch (LIMSRuntimeException lre) { LogEvent.logError("CityUpdateAction", "performAction()", lre.toString()); tx.rollback(); errors = new ActionMessages(); ActionError error = null; if (lre.getException() instanceof org.hibernate.StaleObjectStateException) { error = new ActionError("errors.OptimisticLockException", null, null); } else { if (lre.getException() instanceof LIMSDuplicateRecordException) { java.util.Locale locale = (java.util.Locale) request.getSession() .getAttribute("org.apache.struts.action.LOCALE"); String messageKey = "city.city"; String msg = ResourceLocator.getInstance().getMessageResources().getMessage(locale, messageKey); error = new ActionError("errors.DuplicateRecord.activeonly", 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); 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); dynaForm.initialize(mapping); PropertyUtils.copyProperties(dynaForm, dictionary); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (dictionary.getId() != null && !dictionary.getId().equals("0")) { request.setAttribute(ID, dictionary.getId()); } if (isNew) { forward = FWD_SUCCESS_INSERT; } return getForward(mapping.findForward(forward), id, start, direction); }
From source file:us.mn.state.health.lims.codeelementtype.action.CodeElementTypeAction.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 CodeElementType. // If there is a parameter present, we should bring up an existing // CodeElementType 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);//ww w . j a v a 2s . c o m CodeElementType codeElementType = new CodeElementType(); if ((id != null) && (!"0".equals(id))) { // this is an existing // codeElementType codeElementType.setId(id); CodeElementTypeDAO codeElementTypeDAO = new CodeElementTypeDAOImpl(); codeElementTypeDAO.getData(codeElementType); // initialize referenceTableId //bugzilla 2571 go through ReferenceTablesDAO to get reference tables info if (codeElementType.getReferenceTables() != null) { codeElementType.setReferenceTableId(codeElementType.getReferenceTables().getId()); } 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 codeElementTypes = codeElementTypeDAO.getNextCodeElementTypeRecord(codeElementType.getText()); if (codeElementTypes.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } //bugzilla 1427 pass in name not id codeElementTypes = codeElementTypeDAO.getPreviousCodeElementTypeRecord(codeElementType.getText()); if (codeElementTypes.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new codeElementType isNew = true; // this is to set correct page title } if (codeElementType.getId() != null && !codeElementType.getId().equals("0")) { request.setAttribute(ID, codeElementType.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, codeElementType); //bugzilla 2571 go through ReferenceTablesDAO to get reference tables info ReferenceTablesDAO referenceTablesDAO = new ReferenceTablesDAOImpl(); List referenceTableList = referenceTablesDAO.getAllReferenceTablesForHl7Encoding(); PropertyUtils.setProperty(form, "referenceTableList", referenceTableList); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.codeelementtype.action.CodeElementTypeUpdateAction.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 CodeElementType. // If there is a parameter present, we should bring up an existing // CodeElementType 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 ww w . java 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) { // 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); CodeElementType codeElementType = new CodeElementType(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); codeElementType.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); String referenceTableId = (String) dynaForm.get("referenceTableId"); //bugzilla 2571 go through ReferenceTablesDAO to get reference tables info List refTables = new ArrayList(); if (dynaForm.get("referenceTableList") != null) { refTables = (List) dynaForm.get("referenceTableList"); } else { //bugzilla 2571 go through ReferenceTablesDAO to get reference tables info ReferenceTablesDAO referenceTablesDAO = new ReferenceTablesDAOImpl(); refTables = referenceTablesDAO.getAllReferenceTablesForHl7Encoding(); } //bugzilla 2571 go through ReferenceTablesDAO to get reference tables info ReferenceTables referenceTables = null; //bugzilla 2571 go through ReferenceTablesDAO to get reference tables info for (int i = 0; i < refTables.size(); i++) { ReferenceTables refTbl = (ReferenceTables) refTables.get(i); if (refTbl.getId().equals(referenceTableId)) { referenceTables = refTbl; break; } } // populate valueholder from form PropertyUtils.copyProperties(codeElementType, dynaForm); // set the referenceTable //bugzilla 2571 go through ReferenceTablesDAO to get reference tables info codeElementType.setReferenceTables(referenceTables); try { CodeElementTypeDAO codeElementTypeDAO = new CodeElementTypeDAOImpl(); if (!isNew) { // UPDATE codeElementTypeDAO.updateData(codeElementType); } else { // INSERT codeElementTypeDAO.insertData(codeElementType); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("CodeElementTypeUpdateAction", "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 = "codeelementtype.codeElementType"; 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(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, codeElementType); // need to repopulate in case of FWD_FAIL? //bugzilla 2571 go through ReferenceTablesDAO to get reference tables info PropertyUtils.setProperty(dynaForm, "referenceTableList", refTables); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (codeElementType.getId() != null && !codeElementType.getId().equals("0")) { request.setAttribute(ID, codeElementType.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.codeelementtype.daoimpl.CodeElementTypeDAOImpl.java
public void getData(CodeElementType codeElementType) throws LIMSRuntimeException { try {//w w w. jav a 2 s . c o m CodeElementType pan = (CodeElementType) HibernateUtil.getSession().get(CodeElementType.class, codeElementType.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (pan != null) { PropertyUtils.copyProperties(codeElementType, pan); } else { codeElementType.setId(null); } } catch (Exception e) { //buzilla 2154 LogEvent.logError("CodeElementType", "getData()", e.toString()); throw new LIMSRuntimeException("Error in CodeElementType getData()", e); } }
From source file:us.mn.state.health.lims.codeelementxref.daoimpl.CodeElementXrefDAOImpl.java
public void getData(CodeElementXref codeElementXref) throws LIMSRuntimeException { try {// w ww. j a v a2 s . c o m CodeElementXref pan = (CodeElementXref) HibernateUtil.getSession().get(CodeElementXref.class, codeElementXref.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (pan != null) { PropertyUtils.copyProperties(codeElementXref, pan); } else { codeElementXref.setId(null); } } catch (Exception e) { //buzilla 2154 LogEvent.logError("CodeElementXref", "getData()", e.toString()); throw new LIMSRuntimeException("Error in CodeElementXref getData()", e); } }