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.dictionarycategory.daoimpl.DictionaryCategoryDAOImpl.java
public void getData(DictionaryCategory dictionaryCategory) throws LIMSRuntimeException { try {/*from w ww . jav a2 s.c om*/ DictionaryCategory cc = (DictionaryCategory) HibernateUtil.getSession().get(DictionaryCategory.class, dictionaryCategory.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (cc != null) { PropertyUtils.copyProperties(dictionaryCategory, cc); } else { dictionaryCategory.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("DictionaryCategoryDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in DictionaryCategory getData()", e); } }
From source file:us.mn.state.health.lims.gender.action.GenderAction.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 Gender. // If there is a parameter present, we should bring up an existing // Gender 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 va 2 s . c o m Gender gender = new Gender(); //System.out.println("I am in GenderAction and this is id " + id); if ((id != null) && (!"0".equals(id))) { // this is an existing // gender gender.setId(id); GenderDAO genderDAO = new GenderDAOImpl(); genderDAO.getData(gender); isNew = false; // this is to set correct page title // do we need to enable next or previous? List genders = genderDAO.getNextGenderRecord(gender.getId()); if (genders.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } genders = genderDAO.getPreviousGenderRecord(gender.getId()); if (genders.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new gender isNew = true; // this is to set correct page title } if (gender.getId() != null && !gender.getId().equals("0")) { request.setAttribute(ID, gender.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, gender); //System.out.println("I am in GenderAction this is forward " + forward); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.gender.action.GenderUpdateAction.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 Gender. // If there is a parameter present, we should bring up an existing // Gender 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); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); if (StringUtil.isNullorNill(id) || "0".equals(id)) { isNew = true;//www .j a va 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"); Gender gender = new Gender(); gender.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); // populate valueholder from form PropertyUtils.copyProperties(gender, dynaForm); try { GenderDAO genderDAO = new GenderDAOImpl(); if (!isNew) { // UPDATE genderDAO.updateData(gender); } else { // INSERT genderDAO.insertData(gender); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("GenderUpdateAction", "performAction()", lre.toString()); tx.rollback(); errors = new ActionMessages(); //bugzilla 1482 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 = "gender.genderType"; 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, gender); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (gender.getId() != null && !gender.getId().equals("0")) { request.setAttribute(ID, gender.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.gender.daoimpl.GenderDAOImpl.java
public void getData(Gender gender) throws LIMSRuntimeException { try {/*from w w w. j av a 2s . co m*/ Gender gen = (Gender) HibernateUtil.getSession().get(Gender.class, gender.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (gen != null) { PropertyUtils.copyProperties(gender, gen); } else { gender.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("GenderDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in Gender getData()", e); } }
From source file:us.mn.state.health.lims.healthcenter.action.HealthCenterUpdateAction.java
private ActionForward performGet(ActionMapping mapping, ActionForm form, HttpServletRequest request) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { request.setAttribute("currentAction", "edit"); setGlobalMessage(new ActionMessage("healthcenter.edit.title", null, null), request); HealthCenterDAO healthCenterDAO = new HealthCenterDAOImpl(); HealthCenter healthCenter = healthCenterDAO.getByName(request.getParameter("name")); PropertyUtils.copyProperties(form, healthCenter); return mapping.findForward("success"); //To change body of implemented methods use File | Settings | File Templates. }
From source file:us.mn.state.health.lims.healthcenter.action.HealthCenterUpdateAction.java
private void updateHealthCenter(HttpServletRequest request, BaseActionForm form) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { HealthCenterDAO healthCenterDAO = new HealthCenterDAOImpl(); HealthCenter healthCenter = healthCenterDAO.getByName(request.getParameter("name")); if (healthCenter != null) { PropertyUtils.copyProperties(healthCenter, form); healthCenterDAO.update(healthCenter); }//from w w w . j a v a2s . co m }
From source file:us.mn.state.health.lims.inventory.daoimpl.InventoryItemDAOImpl.java
public void getData(InventoryItem inventoryItem) throws LIMSRuntimeException { try {/*from ww w. jav a 2s . c o m*/ InventoryItem tmpInventoryItem = (InventoryItem) HibernateUtil.getSession().get(InventoryItem.class, inventoryItem.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (tmpInventoryItem != null) { PropertyUtils.copyProperties(inventoryItem, tmpInventoryItem); } else { inventoryItem.setId(null); } } catch (Exception e) { LogEvent.logError("InventoryItemDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in InventoryItem getData()", e); } }
From source file:us.mn.state.health.lims.inventory.daoimpl.InventoryLocationDAOImpl.java
public void getData(InventoryLocation inventoryItem) throws LIMSRuntimeException { try {/*from w ww. j av a 2 s. c om*/ InventoryLocation tmpInventoryLocation = (InventoryLocation) HibernateUtil.getSession() .get(InventoryLocation.class, inventoryItem.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (tmpInventoryLocation != null) { PropertyUtils.copyProperties(inventoryItem, tmpInventoryLocation); } else { inventoryItem.setId(null); } } catch (Exception e) { LogEvent.logError("InventoryLocationDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in InventoryLocation getData()", e); } }
From source file:us.mn.state.health.lims.inventory.daoimpl.InventoryReceiptDAOImpl.java
public void getData(InventoryReceipt inventoryReceipt) throws LIMSRuntimeException { try {// w w w .j a v a2s .c o m InventoryReceipt tmpInventoryReceipt = (InventoryReceipt) HibernateUtil.getSession() .get(InventoryReceipt.class, inventoryReceipt.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (tmpInventoryReceipt != null) { PropertyUtils.copyProperties(inventoryReceipt, tmpInventoryReceipt); } else { inventoryReceipt.setId(null); } } catch (Exception e) { LogEvent.logError("InventoryReceiptDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in InventoryReceipt getData()", e); } }
From source file:us.mn.state.health.lims.label.action.LabelAction.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 Label. // If there is a parameter present, we should bring up an existing // Label 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; //AIS - bugzilla 1562 List scriptlets = new ArrayList(); ScriptletDAO scriptletDAO = new ScriptletDAOImpl(); scriptlets = scriptletDAO.getAllScriptlets(); // initialize the form dynaForm.initialize(mapping);// ww w. j ava2 s . c o m Label label = new Label(); if ((id != null) && (!"0".equals(id))) { // this is an existing // label label.setId(id); LabelDAO labelDAO = new LabelDAOImpl(); labelDAO.getData(label); // initialize selectedLabelId if (label.getScriptlet() != null) { label.setScriptletName(label.getScriptlet().getScriptletName()); } 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 labels = labelDAO.getNextLabelRecord(label.getLabelName()); if (labels.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } //bugzilla 1427 pass in name not id labels = labelDAO.getPreviousLabelRecord(label.getLabelName()); if (labels.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new label isNew = true; // this is to set correct page title } if (label.getId() != null && !label.getId().equals("0")) { request.setAttribute(ID, label.getId()); } // populate form from valueholder //AIS - bugzilla 1562 PropertyUtils.setProperty(form, "scriptlets", scriptlets); PropertyUtils.copyProperties(form, label); return mapping.findForward(forward); }