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.systemusermodule.daoimpl.RoleModuleDAOImpl.java
public void getData(PermissionModule systemUserModule) throws LIMSRuntimeException { try {// w w w. ja va2 s .c om RoleModule sysUserModule = (RoleModule) HibernateUtil.getSession().get(RoleModule.class, systemUserModule.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (sysUserModule != null) { PropertyUtils.copyProperties(systemUserModule, sysUserModule); } else { systemUserModule.setId(null); } } catch (Exception e) { LogEvent.logError("RoleModuleDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in RoleModule getData()", e); } }
From source file:us.mn.state.health.lims.systemusermodule.daoimpl.SystemUserModuleDAOImpl.java
public void getData(PermissionModule systemUserModule) throws LIMSRuntimeException { try {//from w w w .ja va2s. c om SystemUserModule sysUserModule = (SystemUserModule) HibernateUtil.getSession() .get(SystemUserModule.class, systemUserModule.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (sysUserModule != null) { PropertyUtils.copyProperties(systemUserModule, sysUserModule); } else { systemUserModule.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("SystemUserModuleDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in SystemUserModule getData()", e); } }
From source file:us.mn.state.health.lims.systemusersection.action.SystemUserSectionAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String id = request.getParameter("ID"); String forward = FWD_SUCCESS; request.setAttribute(IActionConstants.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 av a 2s. c o m*/ SystemUserSection systemUserSection = new SystemUserSection(); //bugzilla 2154 LogEvent.logDebug("SystemUserSectionAction", "performAction()", "I am in SystemUserSectionAction and this is id " + id); if ((id != null) && (!"0".equals(id))) { systemUserSection.setId(id); SystemUserSectionDAO systemUserSectionDAO = new SystemUserSectionDAOImpl(); systemUserSectionDAO.getData(systemUserSection); isNew = false; List systemUserSections = systemUserSectionDAO .getNextSystemUserSectionRecord(systemUserSection.getId()); if (systemUserSections.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } systemUserSections = systemUserSectionDAO.getPreviousSystemUserSectionRecord(systemUserSection.getId()); if (systemUserSections.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { isNew = true; // this is to set correct page title } if (systemUserSection.getId() != null && !systemUserSection.getId().equals("0")) { request.setAttribute("ID", systemUserSection.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, systemUserSection); SystemUserDAO systemUserDAO = new SystemUserDAOImpl(); List systemUsers = systemUserDAO.getAllSystemUsers(); //Get testsections by user system id //bugzilla 2160 UserTestSectionDAO userTestSectionDAO = new UserTestSectionDAOImpl(); List testSections = userTestSectionDAO.getAllUserTestSections(request); if (systemUserSection.getSystemUser() != null) PropertyUtils.setProperty(form, "systemUserId", systemUserSection.getSystemUser().getId()); else PropertyUtils.setProperty(form, "systemUserId", ""); if (systemUserSection.getTestSection() != null) PropertyUtils.setProperty(form, "testSectionId", systemUserSection.getTestSection().getId()); else PropertyUtils.setProperty(form, "testSectionId", ""); PropertyUtils.setProperty(form, "systemusers", systemUsers); PropertyUtils.setProperty(form, "testsections", testSections); //bugzilla 2154 LogEvent.logDebug("SystemUserSectionAction", "performAction()", "I am in SystemUserSectionAction this is forward " + forward); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.systemusersection.action.SystemUserSectionUpdateAction.java
protected ActionForward performAction(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String forward = FWD_SUCCESS; request.setAttribute(IActionConstants.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;/*from w ww . 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) { 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"); SystemUserSection systemUserSection = new SystemUserSection(); systemUserSection.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); // populate valueholder from form PropertyUtils.copyProperties(systemUserSection, dynaForm); String systemUserId = (String) dynaForm.get("systemUserId"); List systemUsers = new ArrayList(); if (dynaForm.get("systemusers") != null) { systemUsers = (List) dynaForm.get("systemusers"); } else { SystemUserDAO systemUserDAO = new SystemUserDAOImpl(); systemUsers = systemUserDAO.getAllSystemUsers(); } SystemUser systemUser = null; for (int i = 0; i < systemUsers.size(); i++) { SystemUser sysUser = (SystemUser) systemUsers.get(i); if (sysUser.getId().equals(systemUserId)) { systemUser = sysUser; break; } } String testSectionId = (String) dynaForm.get("testSectionId"); List testSections = new ArrayList(); if (dynaForm.get("testsections") != null) { testSections = (List) dynaForm.get("testsections"); } else { //Get testsections by user system id //bugzilla 2160 UserTestSectionDAO userTestSectionDAO = new UserTestSectionDAOImpl(); testSections = userTestSectionDAO.getAllUserTestSections(request); } TestSection testSection = null; for (int i = 0; i < testSections.size(); i++) { TestSection testSect = (TestSection) testSections.get(i); if (testSect.getId().equals(testSectionId)) { testSection = testSect; break; } } systemUserSection.setSystemUser(systemUser); systemUserSection.setTestSection(testSection); try { SystemUserSectionDAO systemUserSectionDAO = new SystemUserSectionDAOImpl(); if (!isNew) { // UPDATE systemUserSectionDAO.updateData(systemUserSection); } else { // INSERT systemUserSectionDAO.insertData(systemUserSection); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("SystemUserSectionUpdateAction", "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) { error = new ActionError("errors.OptimisticLockException", null, null); } else { if (lre.getException() instanceof LIMSDuplicateRecordException) { String messageKey = "systemmodule.name"; 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, systemUserSection); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (systemUserSection.getId() != null && !systemUserSection.getId().equals("0")) { request.setAttribute("ID", systemUserSection.getId()); } if (isNew) forward = FWD_SUCCESS_INSERT; return getForward(mapping.findForward(forward), id, start, direction); }
From source file:us.mn.state.health.lims.systemusersection.daoimpl.SystemUserSectionDAOImpl.java
public void getData(SystemUserSection systemUserSection) throws LIMSRuntimeException { try {//from w ww . j a v a 2 s .com SystemUserSection sysUserSection = (SystemUserSection) HibernateUtil.getSession() .get(SystemUserSection.class, systemUserSection.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (sysUserSection != null) { PropertyUtils.copyProperties(systemUserSection, sysUserSection); } else { systemUserSection.setId(null); } } catch (Exception e) { //bugzilla 2154 LogEvent.logError("SystemUserSectionDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in SystemUserSection getData()", e); } }
From source file:us.mn.state.health.lims.test.action.TestAction.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 Test. // If there is a parameter present, we should bring up an existing // Test 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; //AIS - bugzilla 1562 List scriptlets = new ArrayList(); ScriptletDAO scriptletDAO = new ScriptletDAOImpl(); scriptlets = scriptletDAO.getAllScriptlets(); List labels = new ArrayList(); LabelDAO labelDAO = new LabelDAOImpl(); labels = labelDAO.getAllLabels();// w w w.j a v a2 s .c om // initialize the form dynaForm.initialize(mapping); Test test = new Test(); if ((id != null) && (!"0".equals(id))) { // this is an existing // test test.setId(id); TestDAO testDAO = new TestDAOImpl(); testDAO.getData(test); // initialize methodName try { if (test.getMethod() != null) { test.setMethodName(test.getMethod().getMethodName()); } } catch (org.hibernate.ObjectNotFoundException onfe) { //bugzilla 2154 LogEvent.logError("TestAction", "performAction()", onfe.toString()); //Null object doesn't work } // initialize labelName try { if (test.getLabel() != null) { test.setLabelName(test.getLabel().getLabelName()); } } catch (org.hibernate.ObjectNotFoundException onfe) { //bugzilla 2154 LogEvent.logError("TestAction", "performAction()", onfe.toString()); //Null object doesn't work } // initialize testTrailerName try { if (test.getTestTrailer() != null) { test.setTestTrailerName(test.getTestTrailer().getTestTrailerName()); } } catch (org.hibernate.ObjectNotFoundException onfe) { //bugzilla 2154 LogEvent.logError("TestAction", "performAction()", onfe.toString()); //Null object doesn't work } // initialize testSectionName try { if (test.getTestSection() != null) { test.setTestSectionName(test.getTestSection().getTestSectionName()); } } catch (org.hibernate.ObjectNotFoundException onfe) { //bugzilla 2154 LogEvent.logError("TestAction", "performAction()", onfe.toString()); //Null object doesn't work } // initialize scriptletName try { if (test.getScriptlet() != null) { test.setScriptletName(test.getScriptlet().getScriptletName()); } } catch (org.hibernate.ObjectNotFoundException onfe) { //bugzilla 2154 LogEvent.logError("TestAction", "performAction()", onfe.toString()); //Null object doesn't work } isNew = false; // this is to set correct page title // do we need to enable next or previous? List tests = testDAO.getNextTestRecord(test.getId()); if (tests.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } tests = testDAO.getPreviousTestRecord(test.getId()); if (tests.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new test // bugzilla 1401 default isActive to 'Y' test.setIsActive(YES); //bugzilla 1784 test.setIsReportable(YES); isNew = true; // this is to set correct page title } if (test.getId() != null && !test.getId().equals("0")) { request.setAttribute(ID, test.getId()); } // populate form from valueholder //AIS - bugzilla 1562 Collections.sort(labels, LabelComparator.NAME_COMPARATOR); PropertyUtils.setProperty(form, "scriptlets", scriptlets); PropertyUtils.setProperty(form, "labels", labels); PropertyUtils.copyProperties(dynaForm, test); //System.out.println("I am in TestAction this is forward " + forward); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.test.action.TestSectionAction.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 TestSection. // If there is a parameter present, we should bring up an existing // TestSection 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 . ja v a 2s . co m TestSection testSection = new TestSection(); if ((id != null) && (!"0".equals(id))) { // this is an existing // testSection testSection.setId(id); TestSectionDAO testSectionDAO = new TestSectionDAOImpl(); testSectionDAO.getData(testSection); // initialize selectedOrganizationId if (testSection.getOrganization() != null) { testSection.setSelectedOrganizationId(testSection.getOrganization().getId()); } // bugzilla 2025 if (testSection.getParentTestSection() != null) { testSection.setSelectedParentTestSectionId(testSection.getParentTestSection().getId()); } isNew = false; // this is to set correct page title // do we need to enable next or previous? List testSections = testSectionDAO.getNextTestSectionRecord(testSection.getId()); if (testSections.size() > 0) { // enable next button request.setAttribute(NEXT_DISABLED, "false"); } testSections = testSectionDAO.getPreviousTestSectionRecord(testSection.getId()); if (testSections.size() > 0) { // enable next button request.setAttribute(PREVIOUS_DISABLED, "false"); } // end of logic to enable next or previous button } else { // this is a new testSection // default isExternal to 'N' testSection.setIsExternal(NO); isNew = true; // this is to set correct page title } if (testSection.getId() != null && !testSection.getId().equals("0")) { request.setAttribute(ID, testSection.getId()); } // populate form from valueholder PropertyUtils.copyProperties(form, testSection); OrganizationDAO orgDAO = new OrganizationDAOImpl(); List orgs = orgDAO.getAllOrganizations(); // set organizationName String organizationName = null; for (int i = 0; i < orgs.size(); i++) { Organization organization = (Organization) orgs.get(i); if (organization.getId().equals(testSection.getSelectedOrganizationId())) { organizationName = organization.getOrganizationName(); } } // bugzilla 2025 get parentTestSectionName TestSectionDAO testSecDAO = new TestSectionDAOImpl(); List parentTestSecs = testSecDAO.getAllTestSections(); //set parentTestSectionName String parentTestSectionName = null; for (int i = 0; i < parentTestSecs.size(); i++) { TestSection parentTestSection = (TestSection) parentTestSecs.get(i); if (parentTestSection.getId().equals(testSection.getSelectedParentTestSectionId())) { parentTestSectionName = parentTestSection.getTestSectionName(); } } PropertyUtils.setProperty(form, "organizations", orgs); PropertyUtils.setProperty(form, "organizationName", organizationName); //bugzilla 2025 PropertyUtils.setProperty(form, "parentTestSections", parentTestSecs); PropertyUtils.setProperty(form, "parentTestSectionName", parentTestSectionName); return mapping.findForward(forward); }
From source file:us.mn.state.health.lims.test.action.TestSectionUpdateAction.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 TestSection. // If there is a parameter present, we should bring up an existing // TestSection 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 v a 2s . c o m } 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("TestSectionUpdateAction", "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); TestSection testSection = new TestSection(); //get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); testSection.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); // String selectedTestSectionId = (String) // dynaForm.get("selectedTestSectionId"); String organizationName = (String) dynaForm.get("organizationName"); List orgs = new ArrayList(); if (dynaForm.get("organizations") != null) { orgs = (List) dynaForm.get("organizations"); } else { OrganizationDAO orgDAO = new OrganizationDAOImpl(); orgs = orgDAO.getAllOrganizations(); } Organization org = null; // get the right organizationion to update testSection with for (int i = 0; i < orgs.size(); i++) { Organization o = (Organization) orgs.get(i); if (o.getOrganizationName().equals(organizationName)) { org = o; break; } } // bugzilla 2025 String parentTestSectionName = (String) dynaForm.get("parentTestSectionName"); List parentTestSecs = new ArrayList(); if (dynaForm.get("parentTestSections") != null) { parentTestSecs = (List) dynaForm.get("parentTestSections"); } else { TestSectionDAO parentTestSecDAO = new TestSectionDAOImpl(); parentTestSecs = parentTestSecDAO.getAllTestSections(); } TestSection pTestSec = null; for (int i = 0; i < parentTestSecs.size(); i++) { TestSection pts = (TestSection) parentTestSecs.get(i); if (pts.getTestSectionName().equals(parentTestSectionName)) { pTestSec = pts; break; } } // populate valueholder from form PropertyUtils.copyProperties(testSection, dynaForm); testSection.setOrganization(org); //bugzilla 2025 testSection.setParentTestSection(pTestSec); try { TestSectionDAO testSectionDAO = new TestSectionDAOImpl(); if (!isNew) { // UPDATE testSectionDAO.updateData(testSection); } else { // INSERT testSectionDAO.insertData(testSection); } tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("TestSectionUpdateAction", "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 = "testsection.testsection"; 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, testSection); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (testSection.getId() != null && !testSection.getId().equals("0")) { request.setAttribute(ID, testSection.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.test.action.TestUpdateAction.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 Test. // If there is a parameter present, we should bring up an existing // Test 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 . 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); try { errors = validateAll(request, errors, dynaForm); } catch (Exception e) { //bugzilla 2154 LogEvent.logError("TestUpdateAction", "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); // 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"); Test test = new Test(); // get sysUserId from login module UserSessionData usd = (UserSessionData) request.getSession().getAttribute(USER_SESSION_DATA); String sysUserId = String.valueOf(usd.getSystemUserId()); test.setSysUserId(sysUserId); org.hibernate.Transaction tx = HibernateUtil.getSession().beginTransaction(); Method method = new Method(); String methodName = (String) dynaForm.get("methodName"); method.setMethodName((methodName == null) ? "" : methodName); MethodDAO methodDAO = new MethodDAOImpl(); Method meth = methodDAO.getMethodByName(method); Label label = new Label(); String labelName = (String) dynaForm.get("labelName"); label.setLabelName((labelName == null) ? "" : labelName); LabelDAO labelDAO = new LabelDAOImpl(); Label lab = labelDAO.getLabelByName(label); TestTrailer testTrailer = new TestTrailer(); String testTrailerName = (String) dynaForm.get("testTrailerName"); testTrailer.setTestTrailerName((testTrailerName == null) ? "" : testTrailerName); TestTrailerDAO testTrailerDAO = new TestTrailerDAOImpl(); TestTrailer tt = testTrailerDAO.getTestTrailerByName(testTrailer); TestSection testSection = new TestSection(); String testSectionName = (String) dynaForm.get("testSectionName"); testSection.setTestSectionName(testSectionName); TestSectionDAO testSectionDAO = new TestSectionDAOImpl(); TestSection ts = testSectionDAO.getTestSectionByName(testSection); Scriptlet scriptlet = new Scriptlet(); String scriptletName = (String) dynaForm.get("scriptletName"); scriptlet.setScriptletName((scriptletName == null) ? "" : scriptletName); ScriptletDAO scriptletDAO = new ScriptletDAOImpl(); Scriptlet s = scriptletDAO.getScriptletByName(scriptlet); // populate valueholder from form PropertyUtils.copyProperties(test, dynaForm); test.setMethod(meth); test.setLabel(lab); test.setTestTrailer(tt); test.setTestSection(ts); test.setScriptlet(s); try { TestDAO testDAO = new TestDAOImpl(); if (!isNew) { // bugzilla 1401 removed system.out that caused nullpointer // UPDATE testDAO.updateData(test); // if we rewrite a test, we can't rely on the cache of tests for a type of sample (used in sample entry). } else { // INSERT testDAO.insertData(test); } TypeOfSampleUtil.clearTestCache(); tx.commit(); } catch (LIMSRuntimeException lre) { //bugzilla 2154 LogEvent.logError("TestUpdateAction", "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 { if (lre.getException() instanceof LIMSDuplicateRecordException) { java.util.Locale locale = (java.util.Locale) request.getSession() .getAttribute("org.apache.struts.action.LOCALE"); //bugzilla 2459 (added dup check for description) String messageKey = "test.testNameOrDescription"; 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); //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, test); if ("true".equalsIgnoreCase(request.getParameter("close"))) { forward = FWD_CLOSE; } if (test.getId() != null && !test.getId().equals("0")) { request.setAttribute(ID, test.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.test.daoimpl.TestDAOImpl.java
public void getData(Test test) throws LIMSRuntimeException { try {//w ww. j a va 2s . co m Test testClone = (Test) HibernateUtil.getSession().get(Test.class, test.getId()); HibernateUtil.getSession().flush(); HibernateUtil.getSession().clear(); if (testClone != null) { PropertyUtils.copyProperties(test, testClone); } else { test.setId(null); } } catch (Exception e) { // bugzilla 2154 LogEvent.logError("TestDAOImpl", "getData()", e.toString()); throw new LIMSRuntimeException("Error in Test getData()", e); } }