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.sampledomain.action.SampleDomainUpdateAction.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 SampleDomain. // If there is a parameter present, we should bring up an existing // SampleDomain 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;/*ww w.j a v a2 s.com*/ } 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"); // System.out.println("This is ID from request " + id); SampleDomain sampleDomain = new SampleDomain(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); sampleDomain.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); // populate valueholder from form PropertyUtils.copyProperties(sampleDomain, dynaForm); try { SampleDomainDAO sampleDomainDAO = new SampleDomainDAOImpl(); if (!isNew) { // UPDATE sampleDomainDAO.updateData(sampleDomain); } else { // INSERT sampleDomainDAO.insertData(sampleDomain); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("SampleDomainUpdateAction", "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 = "sampledomain.sampledomain"; 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, sampleDomain); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (sampleDomain.getId() != null && !sampleDomain.getId().equals("0")) { request.setAttribute(ID, sampleDomain.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.sampledomain.daoimpl.SampleDomainDAOImpl.java
public void getData(SampleDomain sampleDomain) throws LIMSRuntimeException { try {/*from ww w . j av a 2 s . co m*/ SampleDomain sampleDom = (SampleDomain) HibernateUtil.getSession().get(SampleDomain.class, sampleDomain.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (sampleDom != null) { //System.out.println("Just read prog " + sampleDomain.getId() + " " // + sampleDom.getDescription()); PropertyUtils.copyProperties(sampleDomain, sampleDom); } else { sampleDomain.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("SampleDomainDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in SampleDomain getData()", e); } }
From source file:us.mn.state.health.lims.samplehuman.daoimpl.SampleHumanDAOImpl.java
public void getData(SampleHuman sampleHuman) throws LIMSRuntimeException { try {/*from w w w. j a va 2 s . c o m*/ SampleHuman sampHuman = (SampleHuman) HibernateUtil.getSession().get(SampleHuman.class, sampleHuman.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (sampHuman != null) { PropertyUtils.copyProperties(sampleHuman, sampHuman); } else { sampleHuman.setId(null); } } catch (Exception e) { // bugzilla 2154 LogEvent.logError("SampleHumanDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in SampleHuman getData()", e); } }
From source file:us.mn.state.health.lims.samplehuman.daoimpl.SampleHumanDAOImpl.java
public void getDataBySample(SampleHuman sampleHuman) throws LIMSRuntimeException { try {/*from w w w.j av a 2 s . c o m*/ String sql = "from SampleHuman sh where samp_id = :param"; Query query = HibernateUtil.getSession().createQuery(sql); query.setInteger("param", Integer.parseInt(sampleHuman.getSampleId())); List list = query.list(); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); SampleHuman sh = null; if (list.size() > 0) { sh = (SampleHuman) list.get(0); PropertyUtils.copyProperties(sampleHuman, sh); } } catch (Exception e) { LogEvent.logError("SampleHumanDAOImpl", "getDataBySample()", e.toString()); throw new LIMSRuntimeException("Error in SampleHuman getDataBySample()", e); } }
From source file:us.mn.state.health.lims.sampleitem.daoimpl.SampleItemDAOImpl.java
public void getData(SampleItem sampleItem) throws LIMSRuntimeException { try {/*from w ww .j a v a 2s. co m*/ SampleItem sampleIt = (SampleItem) HibernateUtil.getSession().get(SampleItem.class, sampleItem.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (sampleIt != null) { PropertyUtils.copyProperties(sampleItem, sampleIt); } else { sampleItem.setId(null); } } catch (Exception e) { LogEvent.logError("SampleItemDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in SampleItem getData()", e); } }
From source file:us.mn.state.health.lims.sampleitem.daoimpl.SampleItemDAOImpl.java
public void getDataBySample(SampleItem sampleItem) throws LIMSRuntimeException { // Use an expression to read in the Sample_Item by SAMP_ID try {//from w w w. j av a 2s . c o m String sql = "from SampleItem si where samp_id = :param"; Query query = HibernateUtil.getSession().createQuery(sql); query.setInteger("param", Integer.parseInt(sampleItem.getSample().getId())); @SuppressWarnings("unchecked") List<SampleItem> list = query.list(); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); SampleItem si = null; if (!list.isEmpty()) { si = list.get(0); TypeOfSample tos = null; if (si.getTypeOfSampleId() != null) { tos = (TypeOfSample) HibernateUtil.getSession().get(TypeOfSample.class, si.getTypeOfSampleId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); si.setTypeOfSample(tos); } SourceOfSample sos = null; if (si.getSourceOfSampleId() != null) { sos = (SourceOfSample) HibernateUtil.getSession().get(SourceOfSample.class, si.getSourceOfSampleId()); si.setSourceOfSample(sos); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); } PropertyUtils.copyProperties(sampleItem, si); } } catch (Exception e) { LogEvent.logError("SampleItemDAOImpl", "getDataBySample()", e.toString()); throw new LIMSRuntimeException("Error in SampleItem getDataBySample()", e); } }
From source file:us.mn.state.health.lims.samplenewborn.daoimpl.SampleNewbornDAOImpl.java
public void getData(SampleNewborn sampleNewborn) throws LIMSRuntimeException { try {//w w w . ja v a 2 s .c o m SampleNewborn sampNewborn = (SampleNewborn) HibernateUtil.getSession().get(SampleNewborn.class, sampleNewborn.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (sampNewborn != null) { String locale = SystemConfiguration.getInstance().getDefaultLocale().toString(); sampNewborn.setDateFirstFeedingForDisplay( DateUtil.convertTimestampToStringDate(sampNewborn.getDateFirstFeeding(), locale)); sampNewborn.setDateTransfutionForDisplay( DateUtil.convertTimestampToStringDate(sampNewborn.getDateTransfution(), locale)); PropertyUtils.copyProperties(sampleNewborn, sampNewborn); } else { sampleNewborn.setId(null); } } catch (Exception e) { LogEvent.logError("SampleNewbornDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in SampleNewborn getData()", e); } }
From source file:us.mn.state.health.lims.sampleorganization.daoimpl.SampleOrganizationDAOImpl.java
public void getData(SampleOrganization sampleOrg) throws LIMSRuntimeException { try {//from ww w .j a v a 2s .c o m SampleOrganization data = (SampleOrganization) HibernateUtil.getSession().get(SampleOrganization.class, sampleOrg.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (data != null) { PropertyUtils.copyProperties(sampleOrg, data); } else { sampleOrg.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("SampleOrganizationDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in SampleOrganization getData()", e); } }
From source file:us.mn.state.health.lims.sampleorganization.daoimpl.SampleOrganizationDAOImpl.java
public void getDataBySample(SampleOrganization sampleOrganization) throws LIMSRuntimeException { try {//from w w w. j av a 2 s . c o m String sql = "from SampleOrganization so where samp_id = :param"; Query query = HibernateUtil.getSession().createQuery(sql); query.setInteger("param", Integer.valueOf(sampleOrganization.getSampleId())); List list = query.list(); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); SampleOrganization so = null; if (list.size() > 0) { so = (SampleOrganization) list.get(0); PropertyUtils.copyProperties(sampleOrganization, so); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("SampleOrganizationDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in SampleOrganization getData()", e); } }
From source file:us.mn.state.health.lims.sampleproject.daoimpl.SampleProjectDAOImpl.java
public void getData(SampleProject sampleProj) throws LIMSRuntimeException { try {//from w w w. j a v a 2s . c o m SampleProject data = (SampleProject) HibernateUtil.getSession().get(SampleProject.class, sampleProj.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (data != null) { PropertyUtils.copyProperties(sampleProj, data); } else { sampleProj.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("SampleProjectDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in SampleProject getData()", e); } }