Index: lams_central/src/java/org/lamsfoundation/lams/webservice/RegisterServiceSoapBindingImpl.java =================================================================== diff -u -r169c2cd235e498d0ee81804b7178ca4dd9686bf0 -rd7db13b29b096fc286293559dbc3c753f7880d26 --- lams_central/src/java/org/lamsfoundation/lams/webservice/RegisterServiceSoapBindingImpl.java (.../RegisterServiceSoapBindingImpl.java) (revision 169c2cd235e498d0ee81804b7178ca4dd9686bf0) +++ lams_central/src/java/org/lamsfoundation/lams/webservice/RegisterServiceSoapBindingImpl.java (.../RegisterServiceSoapBindingImpl.java) (revision d7db13b29b096fc286293559dbc3c753f7880d26) @@ -8,7 +8,6 @@ package org.lamsfoundation.lams.webservice; import java.util.Date; -import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -34,108 +33,116 @@ import org.lamsfoundation.lams.util.ConfigurationKeys; import org.springframework.web.context.support.WebApplicationContextUtils; -public class RegisterServiceSoapBindingImpl implements Register{ - +public class RegisterServiceSoapBindingImpl implements Register { + Logger log = Logger.getLogger(RegisterServiceSoapBindingImpl.class); - + private static final String DEMO_ORG_NAME = "Demo Course"; - + private static MessageContext context = MessageContext.getCurrentContext(); - private static IUserManagementService service = (IUserManagementService) WebApplicationContextUtils.getRequiredWebApplicationContext(((HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET)).getServletContext()).getBean("userManagementService"); - private static ILessonService lessonService = (ILessonService) WebApplicationContextUtils.getRequiredWebApplicationContext(((HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET)).getServletContext()).getBean("lessonService"); + private static IUserManagementService service = (IUserManagementService) WebApplicationContextUtils + .getRequiredWebApplicationContext( + ((HttpServlet) context.getProperty(HTTPConstants.MC_HTTP_SERVLET)) + .getServletContext()).getBean("userManagementService"); - public boolean createUser(String username, String password, String firstName, String lastName, String email) throws java.rmi.RemoteException { + private static ILessonService lessonService = (ILessonService) WebApplicationContextUtils + .getRequiredWebApplicationContext( + ((HttpServlet) context.getProperty(HTTPConstants.MC_HTTP_SERVLET)) + .getServletContext()).getBean("lessonService"); + + public boolean createUser(String username, String password, String firstName, String lastName, + String email) throws java.rmi.RemoteException { try { - if(service.getUserByLogin(username)!= null) return false; + if (service.getUserByLogin(username) != null) + return false; User user = new User(); user.setLogin(username); user.setPassword(password); user.setFirstName(firstName); user.setLastName(lastName); user.setEmail(email); - user.setAuthenticationMethod((AuthenticationMethod)service.findById(AuthenticationMethod.class, AuthenticationMethod.DB)); + user.setAuthenticationMethod((AuthenticationMethod) service.findById( + AuthenticationMethod.class, AuthenticationMethod.DB)); user.setCreateDate(new Date()); user.setDisabledFlag(false); user.setLocale(getLocale()); String flashName = Configuration.get(ConfigurationKeys.DEFAULT_FLASH_THEME); List list = service.findByProperty(CSSThemeVisualElement.class, "name", flashName); - if (list!=null && list.size()>0) { - CSSThemeVisualElement flashTheme = (CSSThemeVisualElement)list.get(0); + if (list != null && list.size() > 0) { + CSSThemeVisualElement flashTheme = (CSSThemeVisualElement) list.get(0); user.setFlashTheme(flashTheme); } String htmlName = Configuration.get(ConfigurationKeys.DEFAULT_HTML_THEME); list = service.findByProperty(CSSThemeVisualElement.class, "name", htmlName); - if (list!=null && list.size()>0) { - CSSThemeVisualElement htmlTheme = (CSSThemeVisualElement)list.get(0); + if (list != null && list.size() > 0) { + CSSThemeVisualElement htmlTheme = (CSSThemeVisualElement) list.get(0); user.setHtmlTheme(htmlTheme); } service.save(user); Organisation org = getDemoOrg(user); - addMemberships(user,org); - addUsersToLessonClasses(org); + addMemberships(user, org); + addUserToLessons(user, org); return true; } catch (Exception e) { log.debug(e.getMessage(), e); throw new java.rmi.RemoteException(e.getMessage()); } - } + } - private SupportedLocale getLocale(){ + private SupportedLocale getLocale() { String defaultLocale = Configuration.get(ConfigurationKeys.SERVER_LANGUAGE); - return service.getSupportedLocale(defaultLocale.substring(0,2), defaultLocale.substring(3)); + return service + .getSupportedLocale(defaultLocale.substring(0, 2), defaultLocale.substring(3)); } - + @SuppressWarnings("unchecked") - private void addMemberships(User user, Organisation org){ - log.debug("adding memberships for user "+user.getUserId()+" in "+org.getName()); - UserOrganisation uo = new UserOrganisation(user,org); + private void addMemberships(User user, Organisation org) { + log.debug("adding memberships for user " + user.getUserId() + " in " + org.getName()); + UserOrganisation uo = new UserOrganisation(user, org); service.save(uo); - Integer[] roles = new Integer[]{Role.ROLE_AUTHOR, Role.ROLE_MONITOR, Role.ROLE_COURSE_MANAGER, Role.ROLE_LEARNER}; - for(Integer roleId:roles){ - UserOrganisationRole uor = new UserOrganisationRole(uo,(Role)service.findById(Role.class,roleId)); + Integer[] roles = new Integer[] { Role.ROLE_AUTHOR, Role.ROLE_MONITOR, + Role.ROLE_COURSE_MANAGER, Role.ROLE_LEARNER }; + for (Integer roleId : roles) { + UserOrganisationRole uor = new UserOrganisationRole(uo, (Role) service.findById( + Role.class, roleId)); service.save(uor); uo.addUserOrganisationRole(uor); } user.addUserOrganisation(uo); service.save(user); } - - private void addUsersToLessonClasses(Organisation org){ - List list = service.findByProperty(UserOrganisation.class, "organisation.organisationId", org.getOrganisationId()); - if(list != null){ - log.debug(list.size()+" user(s) in the org"); - if(org.getLessons()!=null){ - for(int i=0; i 0){ - org = (Organisation)list.get(0); + if (list != null && list.size() > 0) { + org = (Organisation) list.get(0); } - if(org == null){ + if (org == null) { org = new Organisation(); org.setName(DEMO_ORG_NAME); org.setParentOrganisation(service.getRootOrganisation()); - org.setOrganisationType((OrganisationType)service.findById(OrganisationType.class,OrganisationType.COURSE_TYPE)); - org.setOrganisationState((OrganisationState)service.findById(OrganisationState.class,OrganisationState.ACTIVE)); + org.setOrganisationType((OrganisationType) service.findById(OrganisationType.class, + OrganisationType.COURSE_TYPE)); + org.setOrganisationState((OrganisationState) service.findById(OrganisationState.class, + OrganisationState.ACTIVE)); org.setLocale(getLocale()); service.saveOrganisation(org, user.getUserId()); } - log.debug(" Got org "+org.getOrganisationId()); + log.debug(" Got org " + org.getOrganisationId()); return org; }