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.method.action.MethodAction.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 Method. // If there is a parameter present, we should bring up an existing // Method 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. ja v a2 s.c o m*/ Method method = new Method(); //System.out.println("I am in MethodAction and this is id " + id); if ((id != null) && (!"0".equals(id))) { // this is an existing // method method.setId(id); MethodDAO methodDAO = new MethodDAOImpl(); methodDAO.getData(method); 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 methods = methodDAO.getNextMethodRecord(method.getMethodName()); if (methods.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } //bugzilla 1427 pass in name not id methods = methodDAO.getPreviousMethodRecord(method.getMethodName()); if (methods.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new method // default started date to today's date Date today = Calendar.getInstance().getTime(); Locale locale = (Locale) request.getSession().getAttribute("org.apache.struts.action.LOCALE"); String dateAsText = DateUtil.formatDateAsText(today, locale); method.setActiveBeginDateForDisplay(dateAsText); // default isActive to 'Y' method.setIsActive(YES); isNew = true; // this is to set correct page title } if (method.getId() != null && !method.getId().equals("0")) { request.setAttribute(ID, method.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, method); //System.out.println("I am in MethodAction this is forward " + forward); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.method.action.MethodUpdateAction.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 Method. // If there is a parameter present, we should bring up an existing // Method 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 . ja v 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"); Method method = new Method(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); method.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); // populate valueholder from form PropertyUtils.copyProperties(method, dynaForm); try { MethodDAO methodDAO = new MethodDAOImpl(); if (!isNew) { // UPDATE methodDAO.updateData(method); } else { // INSERT methodDAO.insertData(method); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("MethodUpdateAction", "performAction()", lre.toString()); tx.rollback(); errors = new ActionMessages(); 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) { java.util.Locale locale = (java.util.Locale) request.getSession() .getAttribute("org.apache.struts.action.LOCALE"); String messageKey = "method.methodName"; 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); // in case of database exception don't allow another save without // cancel first //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, method); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (method.getId() != null && !method.getId().equals("0")) { request.setAttribute(ID, method.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.method.daoimpl.MethodDAOImpl.java
public void getData(Method method) throws LIMSRuntimeException { try {/*from w w w.j a v a 2 s. c om*/ Method meth = (Method) HibernateUtil.getSession().get(Method.class, method.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (meth != null) { // set the display dates for STARTED_DATE, COMPLETED_DATE String locale = SystemConfiguration.getInstance().getDefaultLocale().toString(); if (meth.getActiveBeginDate() != null) { meth.setActiveBeginDateForDisplay( DateUtil.convertSqlDateToStringDate(meth.getActiveBeginDate(), locale)); } if (meth.getActiveEndDate() != null) { meth.setActiveEndDateForDisplay( DateUtil.convertSqlDateToStringDate(meth.getActiveEndDate(), locale)); } PropertyUtils.copyProperties(method, meth); } else { method.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("MethodDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in Method getData()", e); } }
From source file:us.mn.state.health.lims.note.action.NoteAction.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 Note. // If there is a parameter present, we should bring up an existing // Note to edit. String id = request.getParameter(ID); String forward = FWD_SUCCESS; //bugzilla 1922 don't allow notes to be edited through master lists request.setAttribute(ALLOW_EDITS_KEY, "false"); 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 av a2 s . com Note note = new Note(); //System.out.println("I am in NoteAction and this is id " + id); if ((id != null) && (!"0".equals(id))) { // this is an existing // note note.setId(id); NoteDAO noteDAO = new NoteDAOImpl(); noteDAO.getData(note); 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 notes = noteDAO.getNextNoteRecord(note.getId()); if (notes.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } //bugzilla 1427 pass in name not id notes = noteDAO.getPreviousNoteRecord(note.getId()); if (notes.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new note isNew = true; // this is to set correct page title } if (note.getId() != null && !note.getId().equals("0")) { request.setAttribute(ID, note.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, note); //initialize id if (note.getSystemUser() != null) { PropertyUtils.setProperty(form, "systemUserId", note.getSystemUser().getId()); } //bugzilla 1922 dropdown of system users SystemUserDAO sysUserDAO = new SystemUserDAOImpl(); List sysUsers = sysUserDAO.getAllSystemUsers(); PropertyUtils.setProperty(form, "sysUsers", sysUsers); //System.out.println("I am in NoteAction this is forward " + forward); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.note.action.NoteUpdateAction.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 Note. // If there is a parameter present, we should bring up an existing // Note 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 w w . 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"); Note note = new Note(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); note.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); // populate valueholder from form PropertyUtils.copyProperties(note, dynaForm); //update SystemUser SystemUser systemUser = new SystemUser(); systemUser.setId(note.getSystemUserId()); SystemUserDAO systemUserDAO = new SystemUserDAOImpl(); systemUserDAO.getData(systemUser); note.setSystemUser(systemUser); try { NoteDAO noteDAO = new NoteDAOImpl(); if (!isNew) { // UPDATE noteDAO.updateData(note); } else { // INSERT noteDAO.insertData(note); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("NoteUpdateAction", "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 = "note.note"; 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); 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, note); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (note.getId() != null && !note.getId().equals("0")) { request.setAttribute(ID, note.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.note.daoimpl.NoteDAOImpl.java
public void getData(Note note) throws LIMSRuntimeException { try {// w w w. j a v a 2s .com Note nt = (Note) HibernateUtil.getSession().get(Note.class, note.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (nt != null) { PropertyUtils.copyProperties(note, nt); } else { note.setId(null); } } catch (Exception e) { LogEvent.logError("NoteDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in Note getData()", e); } }
From source file:us.mn.state.health.lims.organization.action.OrganizationAction.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 Organization. // If there is a parameter present, we should bring up an existing // Organization 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);/*w ww .j a v a2 s . co m*/ List<Dictionary> departmentList = getDepartmentList(); PropertyUtils.setProperty(dynaForm, "departmentList", departmentList); Organization organization = new Organization(); isNew = (id == null) || "0".equals(id); OrganizationDAO organizationDAO = new OrganizationDAOImpl(); if (!isNew) { organization.setId(id); organizationDAO.getData(organization); if (organization.getOrganization() != null) { organization.setSelectedOrgId(organization.getOrganization().getId()); } List organizations = organizationDAO.getNextOrganizationRecord(organization.getOrganizationName()); if (organizations.size() > 0) { request.setAttribute(NEXT_DISABLED, "false"); } organizations = organizationDAO.getPreviousOrganizationRecord(organization.getOrganizationName()); if (organizations.size() > 0) { request.setAttribute(PREVIOUS_DISABLED, "false"); } if (useCommune || useDepartment || useVillage) { List<OrganizationAddress> orgAddressList = orgAddressDAO.getAddressPartsByOrganizationId(id); for (OrganizationAddress orgAddress : orgAddressList) { if (useCommune && COMMUNE_ID.equals(orgAddress.getAddressPartId())) { PropertyUtils.setProperty(dynaForm, "commune", orgAddress.getValue()); } else if (useVillage && VILLAGE_ID.equals(orgAddress.getAddressPartId())) { PropertyUtils.setProperty(dynaForm, "village", orgAddress.getValue()); } else if (useDepartment && DEPARTMENT_ID.equals(orgAddress.getAddressPartId())) { PropertyUtils.setProperty(dynaForm, "department", orgAddress.getValue()); } } } } else { // this is a new organization // default isActive to 'Y' organization.setIsActive(YES); organization.setMlsSentinelLabFlag(NO); organization.setMlsLabFlag("N"); } // initialize state to MN if (organization.getState() == null) { organization.setState("MN"); } if (organization.getId() != null && !organization.getId().equals("0")) { request.setAttribute(ID, organization.getId()); } PropertyUtils.copyProperties(form, organization); if (useParentOrganization) { setParentOrganiztionName(form, organization, organizationDAO); } if (useOrganizationState) { setCityStateZipList(form); } if (useOrganizationTypeList) { List<OrganizationType> orgTypeList = getOrganizationTypeList(); String[] selectedList = new String[orgTypeList.size()]; PropertyUtils.setProperty(form, "orgTypes", orgTypeList); if (organization.getId() != null && orgTypeList != null) { if (orgTypeList.size() > 0) { OrganizationOrganizationTypeDAO ootDAO = new OrganizationOrganizationTypeDAOImpl(); List<String> selectedOrgTypeList = ootDAO.getTypeIdsForOrganizationId(organization.getId()); int index = 0; for (String orgTypeId : selectedOrgTypeList) { selectedList[index] = orgTypeId; index++; } } } PropertyUtils.setProperty(form, "selectedTypes", selectedList); } return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.organization.action.OrganizationUpdateAction.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; selectedOrgTypes = dynaForm.getStrings("selectedTypes"); ActionMessages errors = dynaForm.validate(mapping, request); try {/*w ww .j a v a 2s .c o m*/ errors = validateAll(request, errors, dynaForm); } catch (Exception e) { LogEvent.logError("OrganizationUpdateAction", "performAction()", e.toString()); ActionError error = new ActionError("errors.ValidationException", null, null); errors.add(ActionMessages.GLOBAL_MESSAGE, error); } if (errors != null && errors.size() > 0) { saveErrors(request, errors); return mapping.findForward(FWD_FAIL); } String start = (String) request.getParameter("startingRecNo"); String direction = (String) request.getParameter("direction"); Organization organization = new Organization(); organization.setSysUserId(currentUserId); List states = null; states = getPossibleStates(dynaForm, states); PropertyUtils.copyProperties(organization, dynaForm); if (FormFields.getInstance().useField(FormFields.Field.OrganizationParent)) { String parentOrgName = (String) dynaForm.get("parentOrgName"); Organization o = new Organization(); o.setOrganizationName(parentOrgName); Organization parentOrg = organizationDAO.getOrganizationByName(o, false); organization.setOrganization(parentOrg); } createAddressParts(id, dynaForm); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); try { if (!isNew) { organizationDAO.updateData(organization); } else { organizationDAO.insertData(organization); } persistAddressParts(organization); linkOrgWithOrgType(organization); tx.commit(); } catch (LIMSRuntimeException lre) { // bugzilla 2154 LogEvent.logError("OrganizationUpdateAction", "performAction()", lre.toString()); tx.rollback(); errors = new ActionMessages(); 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) { java.util.Locale locale = (java.util.Locale) request.getSession() .getAttribute("org.apache.struts.action.LOCALE"); String messageKey = "organization.organization"; 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, organization); if (states != null) { PropertyUtils.setProperty(form, "states", states); } if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (organization.getId() != null && !organization.getId().equals("0")) { request.setAttribute(ID, organization.getId()); } if (isNew) { forward = FWD_SUCCESS_INSERT; } return getForward(mapping.findForward(forward), id, start, direction); }
From source file:us.mn.state.health.lims.organization.daoimpl.OrganizationDAOImpl.java
public void getData(Organization organization) throws LIMSRuntimeException { try {//from w w w. j a v a 2 s. co m Organization org = (Organization) HibernateUtil.getSession().get(Organization.class, organization.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (org != null) { PropertyUtils.copyProperties(organization, org); } else { //bugzilla 1366 organization.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("OrganizationDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in Organization getData()", e); } }
From source file:us.mn.state.health.lims.panel.action.PanelAction.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 Panel. // If there is a parameter present, we should bring up an existing // Panel 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 www. j a v a2 s . c om*/ Panel panel = new Panel(); if ((id != null) && (!"0".equals(id))) { // this is an existing // panel panel.setId(id); PanelDAO panelDAO = new PanelDAOImpl(); panelDAO.getData(panel); 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 panels = panelDAO.getNextPanelRecord(panel.getPanelName()); if (panels.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } //bugzilla 1427 pass in name not id panels = panelDAO.getPreviousPanelRecord(panel.getPanelName()); if (panels.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new panel isNew = true; // this is to set correct page title } if (panel.getId() != null && !panel.getId().equals("0")) { request.setAttribute(ID, panel.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, panel); return mapping.findForward(forward); }