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.sampleqaevent.daoimpl.SampleQaEventDAOImpl.java
public void getData(SampleQaEvent sampleQaEvent) throws LIMSRuntimeException { try {//w w w . ja va2 s . c om SampleQaEvent data = (SampleQaEvent) HibernateUtil.getSession().get(SampleQaEvent.class, sampleQaEvent.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (data != null) { PropertyUtils.copyProperties(sampleQaEvent, data); } else { sampleQaEvent.setId(null); } } catch (Exception e) { //buzilla 2154 LogEvent.logError("SampleQaEventDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in SampleQaEvent getData()", e); } }
From source file:us.mn.state.health.lims.sampleqaeventaction.daoimpl.SampleQaEventActionDAOImpl.java
public void getData(SampleQaEventAction sampleQaEventAction) throws LIMSRuntimeException { try {//from w w w . ja v a2s .c o m SampleQaEventAction data = (SampleQaEventAction) HibernateUtil.getSession() .get(SampleQaEventAction.class, sampleQaEventAction.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (data != null) { PropertyUtils.copyProperties(sampleQaEventAction, data); } else { sampleQaEventAction.setId(null); } } catch (Exception e) { //buzilla 2154 LogEvent.logError("SampleQaEventActionDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in SampleQaEventAction getData()", e); } }
From source file:us.mn.state.health.lims.scriptlet.action.ScriptletAction.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 Scriptlet. // If there is a parameter present, we should bring up an existing // Scriptlet 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"); BaseActionForm dynaForm = (BaseActionForm) form; // initialize the form dynaForm.initialize(mapping);/*from w ww. j av a2 s . c om*/ Scriptlet scriptlet = new Scriptlet(); if ((id != null) && (!"0".equals(id))) { // this is an existing // scriptlet scriptlet.setId(id); ScriptletDAO scriptletDAO = new ScriptletDAOImpl(); scriptletDAO.getData(scriptlet); 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 scriptlets = scriptletDAO.getNextScriptletRecord(scriptlet.getScriptletName()); if (scriptlets.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } //bugzilla 1427 pass in name not id scriptlets = scriptletDAO.getPreviousScriptletRecord(scriptlet.getScriptletName()); if (scriptlets.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new scriptlet isNew = true; // this is to set correct page title } if (scriptlet.getId() != null && !scriptlet.getId().equals("0")) { request.setAttribute(ID, scriptlet.getId()); } // populate form from valueholder PropertyUtils.copyProperties(dynaForm, scriptlet); //System.out // .println("I am in ScriptletAction this is forward " + forward); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.scriptlet.action.ScriptletUpdateAction.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 Scriptlet. // If there is a parameter present, we should bring up an existing // Scriptlet 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 va 2s . 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"); Scriptlet scriptlet = new Scriptlet(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); scriptlet.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); // populate valueholder from form PropertyUtils.copyProperties(scriptlet, dynaForm); try { ScriptletDAO scriptletDAO = new ScriptletDAOImpl(); if (!isNew) { // UPDATE scriptletDAO.updateData(scriptlet); } else { // INSERT scriptletDAO.insertData(scriptlet); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("ScriptletUpdateAction", "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 = "scriptlet.scriptletName"; 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, scriptlet); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (scriptlet.getId() != null && !scriptlet.getId().equals("0")) { request.setAttribute(ID, scriptlet.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.scriptlet.daoimpl.ScriptletDAOImpl.java
public void getData(Scriptlet scriptlet) throws LIMSRuntimeException { try {/*from www . jav a 2 s . c o m*/ Scriptlet sc = (Scriptlet) HibernateUtil.getSession().get(Scriptlet.class, scriptlet.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (sc != null) { PropertyUtils.copyProperties(scriptlet, sc); } else { scriptlet.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("ScriptletDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in Scriptlet getData()", e); } }
From source file:us.mn.state.health.lims.siteinformation.daoimpl.SiteInformationDAOImpl.java
public void getData(SiteInformation siteInformation) throws LIMSRuntimeException { try {/*from w w w . j av a2 s . co m*/ SiteInformation tmpSiteInformation = (SiteInformation) HibernateUtil.getSession() .get(SiteInformation.class, siteInformation.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (tmpSiteInformation != null) { PropertyUtils.copyProperties(siteInformation, tmpSiteInformation); } else { siteInformation.setId(null); } } catch (Exception e) { LogEvent.logError("SiteInformationsDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in SiteInformation getData()", e); } }
From source file:us.mn.state.health.lims.sourceofsample.action.SourceOfSampleAction.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 SourceOfSample. // If there is a parameter present, we should bring up an existing // SourceOfSample 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 .jav a 2s . c o m SourceOfSample sourceOfSample = new SourceOfSample(); if ((id != null) && (!"0".equals(id))) { // this is an existing // sourceOfSample sourceOfSample.setId(id); SourceOfSampleDAO sourceOfSampleDAO = new SourceOfSampleDAOImpl(); sourceOfSampleDAO.getData(sourceOfSample); isNew = false; // this is to set correct page title // do we need to enable next or previous? List sourceOfSamples = sourceOfSampleDAO.getNextSourceOfSampleRecord(sourceOfSample.getId()); if (sourceOfSamples.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } sourceOfSamples = sourceOfSampleDAO.getPreviousSourceOfSampleRecord(sourceOfSample.getId()); if (sourceOfSamples.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new sourceOfSample isNew = true; // this is to set correct page title } if (sourceOfSample.getId() != null && !sourceOfSample.getId().equals("0")) { request.setAttribute(ID, sourceOfSample.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, sourceOfSample); SampleDomainDAO sampleDomainDAO = new SampleDomainDAOImpl(); List domains = sampleDomainDAO.getAllSampleDomains(); PropertyUtils.setProperty(form, "domains", domains); //System.out.println("I am in SourceOfSampleAction this is forward " // + forward); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.sourceofsample.action.SourceOfSampleUpdateAction.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 SourceOfSample. // If there is a parameter present, we should bring up an existing // SourceOfSample 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 www . ja v a2 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) { 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"); SourceOfSample sourceOfSample = new SourceOfSample(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); sourceOfSample.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); String domain = (String) dynaForm.get("domain"); 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(sourceOfSample, dynaForm); try { SourceOfSampleDAO sourceOfSampleDAO = new SourceOfSampleDAOImpl(); if (!isNew) { // UPDATE sourceOfSampleDAO.updateData(sourceOfSample); } else { // INSERT sourceOfSampleDAO.insertData(sourceOfSample); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("SourceOfSampleUpdateAction", "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 = "sourceofsample.sourceofsample"; 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, sourceOfSample); PropertyUtils.setProperty(dynaForm, "domains", domains); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (sourceOfSample.getId() != null && !sourceOfSample.getId().equals("0")) { request.setAttribute(ID, sourceOfSample.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.sourceofsample.daoimpl.SourceOfSampleDAOImpl.java
public void getData(SourceOfSample sourceOfSample) throws LIMSRuntimeException { try {/*from w w w .j a v a 2 s .c o m*/ SourceOfSample sos = (SourceOfSample) HibernateUtil.getSession().get(SourceOfSample.class, sourceOfSample.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (sos != null) { PropertyUtils.copyProperties(sourceOfSample, sos); } else { sourceOfSample.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("SourceOfSampleDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in SourceOfSample getData()", e); } }
From source file:us.mn.state.health.lims.statusofsample.action.StatusOfSampleAction.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 SourceOfSample. // If there is a parameter present, we should bring up an existing // SourceOfSample 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 . j ava 2s . com*/ StatusOfSample statusOfSample = new StatusOfSample(); StatusOfSampleDAO statusOfSampleDAO = new StatusOfSampleDAOImpl(); //bugzilla 2154 LogEvent.logDebug("StatusOfSampleAction", "performAction()", "In StatusOfSampleAction..."); if ((id != null) && (!"0".equals(id))) { // this is an existing // StatusOfSample statusOfSample.setId(id); statusOfSampleDAO.getData(statusOfSample); isNew = false; // this is to set correct page title // do we need to enable next or previous? List statusOfSamples = statusOfSampleDAO.getNextStatusOfSampleRecord(statusOfSample.getId()); if (statusOfSamples.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } statusOfSamples = statusOfSampleDAO.getPreviousStatusOfSampleRecord(statusOfSample.getId()); if (statusOfSamples.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new statusOfSample isNew = true; // this is to set correct page title } if (statusOfSample.getId() != null && !statusOfSample.getId().equals("0")) { request.setAttribute(ID, statusOfSample.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, statusOfSample); //bugzilla 2154 LogEvent.logDebug("StatusOfSampleAction", "performAction()", "End of StatusOfSampleAction forwarding to: " + forward); return mapping.findForward(forward); }