Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserAction.java =================================================================== diff -u -rf1c9a47571045019bf62e662210df629c0217980 -r93201ac4b55c13e6d9a2a4a39941996d91793d13 --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserAction.java (.../UserAction.java) (revision f1c9a47571045019bf62e662210df629c0217980) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserAction.java (.../UserAction.java) (revision 93201ac4b55c13e6d9a2a4a39941996d91793d13) @@ -48,7 +48,6 @@ import org.lamsfoundation.lams.util.ConfigurationKeys; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.action.LamsDispatchAction; -import org.lamsfoundation.lams.web.util.HttpSessionManager; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; @@ -71,17 +70,9 @@ public class UserAction extends LamsDispatchAction { private static Logger log = Logger.getLogger(UserAction.class); - private static WebApplicationContext ctx = WebApplicationContextUtils - .getWebApplicationContext(HttpSessionManager.getInstance() - .getServletContext()); - private static IUserManagementService service = (IUserManagementService) ctx - .getBean("userManagementServiceTarget"); - private static List allRoles = service.findAll(Role.class); - private static List locales = service.findAll(SupportedLocale.class); - static { - Collections.sort(allRoles); - Collections.sort(locales); - } + private static IUserManagementService service; + private static List allRoles; + private static List locales; public ActionForward edit(ActionMapping mapping, ActionForm form, @@ -94,8 +85,8 @@ } // remove sysadmin from role list for non-sysadmin users - User requestor = (User)service.getUserByLogin(request.getRemoteUser()); - if(!service.isUserInRole(requestor.getUserId(),service.getRootOrganisation().getOrganisationId(),Role.SYSADMIN)){ + User requestor = (User)getService().getUserByLogin(request.getRemoteUser()); + if(!getService().isUserInRole(requestor.getUserId(),getService().getRootOrganisation().getOrganisationId(),Role.SYSADMIN)){ Role sysadmin = new Role(); sysadmin.setRoleId(Role.ROLE_SYSADMIN); allRoles.remove(sysadmin); @@ -108,7 +99,7 @@ DynaActionForm userForm = (DynaActionForm)form; if(userId != null) { log.debug("got userid to edit: "+userId); - User user = (User)service.findById(User.class,userId); + User user = (User)getService().findById(User.class,userId); BeanUtils.copyProperties(userForm, user); userForm.set("password",null); @@ -130,7 +121,7 @@ break; } } - SupportedLocale locale = service.getSupportedLocale(user.getLocaleLanguage(),user.getLocaleCountry()); + SupportedLocale locale = getService().getSupportedLocale(user.getLocaleLanguage(),user.getLocaleCountry()); userForm.set("localeId",locale.getLocaleId()); }else{ @@ -139,14 +130,14 @@ try{ String defaultLocale = Configuration.get(ConfigurationKeys.SERVER_LANGUAGE); log.debug("defaultLocale: "+defaultLocale); - SupportedLocale locale = service.getSupportedLocale(defaultLocale.substring(0,2),defaultLocale.substring(3)); + SupportedLocale locale = getService().getSupportedLocale(defaultLocale.substring(0,2),defaultLocale.substring(3)); userForm.set("localeId",locale.getLocaleId()); }catch(Exception e){ log.debug(e); } } - Organisation org = (Organisation)service.findById(Organisation.class,orgId); + Organisation org = (Organisation)getService().findById(Organisation.class,orgId); Organisation parentOrg = org.getParentOrganisation(); if(parentOrg!=null){ request.setAttribute("pOrgId",parentOrg.getOrganisationId()); @@ -164,9 +155,21 @@ HttpServletResponse response) throws Exception { Integer userId = WebUtil.readIntParam(request,"userId",true); log.debug("removing userid: "+userId); - service.deleteById(User.class,userId); + getService().deleteById(User.class,userId); Integer orgId = WebUtil.readIntParam(request,"orgId"); request.setAttribute("org",orgId); return mapping.findForward("userlist"); } + + private IUserManagementService getService(){ + if(service==null){ + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); + service = (IUserManagementService) ctx.getBean("userManagementServiceTarget"); + allRoles = getService().findAll(Role.class); + locales = getService().findAll(SupportedLocale.class); + Collections.sort(allRoles); + Collections.sort(locales); + } + return service; + } } Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserManageAction.java =================================================================== diff -u -r97f34e32e359c8bc50394be756e4f1efa109f832 -r93201ac4b55c13e6d9a2a4a39941996d91793d13 --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserManageAction.java (.../UserManageAction.java) (revision 97f34e32e359c8bc50394be756e4f1efa109f832) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserManageAction.java (.../UserManageAction.java) (revision 93201ac4b55c13e6d9a2a4a39941996d91793d13) @@ -44,7 +44,6 @@ import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.WebUtil; -import org.lamsfoundation.lams.web.util.HttpSessionManager; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; @@ -66,11 +65,7 @@ public class UserManageAction extends Action { private static final Logger log = Logger.getLogger(UserManageAction.class); - private static WebApplicationContext ctx = WebApplicationContextUtils - .getWebApplicationContext(HttpSessionManager.getInstance() - .getServletContext()); - private static IUserManagementService service = (IUserManagementService)ctx - .getBean("userManagementServiceTarget"); + private static IUserManagementService service; public ActionForward execute(ActionMapping mapping, ActionForm form, @@ -91,7 +86,7 @@ log.debug("orgId: "+orgId); // get org name - Organisation organisation = (Organisation)service.findById(Organisation.class,orgId); + Organisation organisation = (Organisation)getService().findById(Organisation.class,orgId); if(organisation==null) { errors.add("org",new ActionMessage("error.org.invalid")); saveErrors(request,errors); @@ -100,11 +95,11 @@ String orgName = organisation.getName(); log.debug("orgName: "+orgName); - Integer userId = service.getUserByLogin(request.getRemoteUser()).getUserId(); + Integer userId = getService().getUserByLogin(request.getRemoteUser()).getUserId(); // check permission if(request.isUserInRole(Role.SYSADMIN)){ request.setAttribute("canAdd",true); - }else if(!service.isUserInRole(userId,orgId,Role.COURSE_ADMIN)){ + }else if(!getService().isUserInRole(userId,orgId,Role.COURSE_ADMIN)){ errors.add("authorisation",new ActionMessage("error.authorisation")); saveErrors(request,errors); return mapping.findForward("error"); @@ -113,7 +108,7 @@ } // get list of users in org - List users = service.getUsersFromOrganisation(orgId); + List users = getService().getUsersFromOrganisation(orgId); if(users==null){ errors.add("org",new ActionMessage("error.org.invalid")); saveErrors(request,errors); @@ -133,7 +128,7 @@ BeanUtils.copyProperties(userManageBean, user); List roles; try{ - roles = service.getRolesForUserByOrganisation(user, orgId); + roles = getService().getRolesForUserByOrganisation(user, orgId); Collections.sort(roles); } catch(NullPointerException e){ roles = new ArrayList(); @@ -155,4 +150,12 @@ return mapping.findForward("userlist"); } + + private IUserManagementService getService(){ + if(service==null){ + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); + service = (IUserManagementService) ctx.getBean("userManagementServiceTarget"); + } + return service; + } } Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserOrgAction.java =================================================================== diff -u -r97f34e32e359c8bc50394be756e4f1efa109f832 -r93201ac4b55c13e6d9a2a4a39941996d91793d13 --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserOrgAction.java (.../UserOrgAction.java) (revision 97f34e32e359c8bc50394be756e4f1efa109f832) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserOrgAction.java (.../UserOrgAction.java) (revision 93201ac4b55c13e6d9a2a4a39941996d91793d13) @@ -44,7 +44,6 @@ import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.WebUtil; -import org.lamsfoundation.lams.web.util.HttpSessionManager; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; @@ -67,11 +66,7 @@ public class UserOrgAction extends Action { private static final Logger log = Logger.getLogger(UserOrgAction.class); - private static WebApplicationContext ctx = WebApplicationContextUtils - .getWebApplicationContext(HttpSessionManager.getInstance() - .getServletContext()); - private static IUserManagementService service = (IUserManagementService)ctx - .getBean("userManagementServiceTarget"); + private static IUserManagementService service; public ActionForward execute(ActionMapping mapping, ActionForm form, @@ -82,7 +77,7 @@ Integer orgId = WebUtil.readIntParam(request,"orgId",true); log.debug("orgId: "+orgId); // get org name - Organisation organisation = (Organisation)service.findById(Organisation.class,orgId); + Organisation organisation = (Organisation)getService().findById(Organisation.class,orgId); if((orgId==null)||(orgId<=0)||organisation==null){ errors.add("orgId",new ActionMessage("error.org.invalid")); @@ -101,18 +96,18 @@ request.setAttribute("orgType",orgType); // get list of users in org - User user = (User)service.getUserByLogin(request.getRemoteUser()); + User user = (User)getService().getUserByLogin(request.getRemoteUser()); List users = new ArrayList(); if(request.isUserInRole(Role.SYSADMIN)){ - users = service.findAll(User.class); - }else if(service.isUserInRole(user.getUserId(),orgId,Role.COURSE_ADMIN)){ + users = getService().findAll(User.class); + }else if(getService().isUserInRole(user.getUserId(),orgId,Role.COURSE_ADMIN)){ if(organisation.getCourseAdminCanAddNewUsers()){ if(organisation.getCourseAdminCanBrowseAllUsers()){ - users = service.findAll(User.class); + users = getService().findAll(User.class); }else if(orgType.equals(new Integer(OrganisationType.CLASS_TYPE))){ - users = service.getUsersFromOrganisation(parentOrg.getOrganisationId()); + users = getService().getUsersFromOrganisation(parentOrg.getOrganisationId()); }else if(orgType.equals(new Integer(OrganisationType.COURSE_TYPE))){ - users = service.getUsersFromOrganisation(orgId); + users = getService().getUsersFromOrganisation(orgId); } }else{ errors.add("authorisation",new ActionMessage("error.authorisation")); @@ -128,7 +123,7 @@ userOrgForm.set("orgName",orgName); // create list of userids, members of this org - List memberUsers = service.getUsersFromOrganisation(orgId); + List memberUsers = getService().getUsersFromOrganisation(orgId); String[] userIds = new String[memberUsers.size()]; for(int i=0; i orgs = new ArrayList(); orgs.add(orgId); log.debug("organisation: "+orgId); // if user is to be added to a class, make user a member of parent course also - Organisation org = (Organisation)service.findById(Organisation.class,orgId); + Organisation org = (Organisation)getService().findById(Organisation.class,orgId); if(org.getOrganisationType().getOrganisationTypeId().equals(new Integer(OrganisationType.CLASS_TYPE))){ Integer courseOrgId = org.getParentOrganisation().getOrganisationId(); orgs.add(courseOrgId); log.debug("organisation: "+courseOrgId); } for(Integer id:orgs){ - UserOrganisation uo = new UserOrganisation(user, (Organisation)service.findById(Organisation.class,id)); + UserOrganisation uo = new UserOrganisation(user, (Organisation)getService().findById(Organisation.class,id)); uos.add(uo); - service.save(uo); + getService().save(uo); log.debug("userOrganisation: "+uo); for(int i=0; i locales = service.findAll(SupportedLocale.class); + List locales = getService().findAll(SupportedLocale.class); Collections.sort(locales); request.setAttribute("locales",locales); - List allRoles = service.findAll(Role.class); + List allRoles = getService().findAll(Role.class); Collections.sort(allRoles); request.setAttribute("rolelist",allRoles); return mapping.findForward("user"); } } + + private IUserManagementService getService(){ + if(service==null){ + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); + service = (IUserManagementService) ctx.getBean("userManagementServiceTarget"); + } + return service; + } }