Index: lams_bb_integration/src/org/lamsfoundation/bb/integration/servlet/GroupDataServlet.java =================================================================== diff -u -r54843a5ae3288a977cdfa75fd43afc9c67831624 -ree84f34847defe313ee0570b67a75c41a22091c2 --- lams_bb_integration/src/org/lamsfoundation/bb/integration/servlet/GroupDataServlet.java (.../GroupDataServlet.java) (revision 54843a5ae3288a977cdfa75fd43afc9c67831624) +++ lams_bb_integration/src/org/lamsfoundation/bb/integration/servlet/GroupDataServlet.java (.../GroupDataServlet.java) (revision ee84f34847defe313ee0570b67a75c41a22091c2) @@ -129,25 +129,21 @@ // The CSV list should be the format below // ,<First name>,<Last name>,<Address>,<City>,<State>, - // <Postcode>,<Country>,<Day time number>,<Mobile number>, - // <Fax number>,<Email>,<Locale language>,<Locale country> + // <Postcode>,<Country ISO code>,<Day time number>,<Mobile number>, + // <Fax number>,<Email>,<Locale> jsonUser.addProperty("1", user.getTitle()); jsonUser.addProperty("2", user.getGivenName()); jsonUser.addProperty("3", user.getFamilyName()); jsonUser.addProperty("4", user.getStreet1() + user.getStreet2()); jsonUser.addProperty("5", user.getCity()); jsonUser.addProperty("6", user.getState()); jsonUser.addProperty("7", user.getZipCode()); - jsonUser.addProperty("8", user.getCountry()); + jsonUser.addProperty("8", LamsSecurityUtil.getCountryCode(user.getCountry())); jsonUser.addProperty("9", user.getHomePhone1()); jsonUser.addProperty("10", user.getMobilePhone()); jsonUser.addProperty("11", user.getBusinessFax()); jsonUser.addProperty("12", user.getEmailAddress()); - String locale = user.getLocale(); - String localeLang = LamsSecurityUtil.getLanguage(locale); - String localeCountry = LamsSecurityUtil.getCountry(locale); - jsonUser.addProperty("13", localeLang); - jsonUser.addProperty("14", localeCountry); + jsonUser.addProperty("13", user.getLocale()); } } } Index: lams_bb_integration/src/org/lamsfoundation/bb/integration/servlet/UserDataServlet.java =================================================================== diff -u -r54843a5ae3288a977cdfa75fd43afc9c67831624 -ree84f34847defe313ee0570b67a75c41a22091c2 --- lams_bb_integration/src/org/lamsfoundation/bb/integration/servlet/UserDataServlet.java (.../UserDataServlet.java) (revision 54843a5ae3288a977cdfa75fd43afc9c67831624) +++ lams_bb_integration/src/org/lamsfoundation/bb/integration/servlet/UserDataServlet.java (.../UserDataServlet.java) (revision ee84f34847defe313ee0570b67a75c41a22091c2) @@ -105,21 +105,18 @@ address += user.getZipCode(); // String username = u.getUserName().replaceAll(); - PrintWriter out = response.getWriter(); + String countryCode = LamsSecurityUtil.getCountryCode(user.getCountry()); - String locale = user.getLocale(); - String loc_lang = LamsSecurityUtil.getLanguage(locale); - String loc_cntry = LamsSecurityUtil.getCountry(locale); - // The CSV list should be the format below // <Title>,<First name>,<Last name>,<Address>,<City>,<State>, - // <Postcode>,<Country>,<Day time number>,<Mobile number>, - // <Fax number>,<Email>,<Locale language>,<Locale country> + // <Postcode>,<Country ISO code>,<Day time number>,<Mobile number>, + // <Fax number>,<Email>,<Locale> String[] valList = { user.getTitle(), user.getGivenName(), user.getFamilyName(), user.getStreet1() + user.getStreet2(), user.getCity(), user.getState(), user.getZipCode(), - user.getCountry(), user.getHomePhone1(), user.getMobilePhone(), user.getBusinessFax(), - user.getEmailAddress(), loc_lang, loc_cntry }; - + countryCode, user.getHomePhone1(), user.getMobilePhone(), user.getBusinessFax(), + user.getEmailAddress(), user.getLocale() }; + + PrintWriter out = response.getWriter(); out.println(CSVUtil.write(valList)); } Index: lams_bb_integration/src/org/lamsfoundation/bb/integration/util/LamsSecurityUtil.java =================================================================== diff -u -r54843a5ae3288a977cdfa75fd43afc9c67831624 -ree84f34847defe313ee0570b67a75c41a22091c2 --- lams_bb_integration/src/org/lamsfoundation/bb/integration/util/LamsSecurityUtil.java (.../LamsSecurityUtil.java) (revision 54843a5ae3288a977cdfa75fd43afc9c67831624) +++ lams_bb_integration/src/org/lamsfoundation/bb/integration/util/LamsSecurityUtil.java (.../LamsSecurityUtil.java) (revision ee84f34847defe313ee0570b67a75c41a22091c2) @@ -37,6 +37,7 @@ import java.security.NoSuchAlgorithmException; import java.util.Date; import java.util.List; +import java.util.Locale; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -107,8 +108,7 @@ String lastName = ctx.getUser().getFamilyName(); String email = ctx.getUser().getEmailAddress(); String locale = ctx.getUser().getLocale(); - String country = getCountry(locale); - String lang = getLanguage(locale); + String country = getCountryCode(ctx.getUser().getCountry()); // Even for authoring calls we still need a 'course' the user, role & organisation are all bound up together // do to be authorised to use authoring you must be in an organisation. @@ -130,7 +130,7 @@ String course = courseId != null ? "&courseid=" + URLEncoder.encode(courseId, "UTF8") : ""; url = serverAddr + "/LoginRequest?" + "&uid=" + URLEncoder.encode(username, "UTF8") + "&method=" + method + "&ts=" + timestamp + "&sid=" + serverId + "&hash=" + hash + course + "&country=" + country - + "&lang=" + lang + "&firstName=" + URLEncoder.encode(firstName, "UTF-8") + "&lastName=" + + "&lang=" + locale + "&firstName=" + URLEncoder.encode(firstName, "UTF-8") + "&lastName=" + URLEncoder.encode(lastName, "UTF-8") + "&email=" + URLEncoder.encode(email, "UTF-8"); if ("learnerStrictAuth".equals(method) || "monitor".equals(method)) { @@ -246,9 +246,8 @@ String email = user.getEmailAddress(); String hash = generateAuthenticationHash(timestamp, username, serverId); - String locale = user.getLocale(); - String country = getCountry(locale); - String lang = getLanguage(locale); + String locale = ctx.getUser().getLocale(); + String country = getCountryCode(ctx.getUser().getCountry()); // the mode to call upon learning designs final Integer MODE = 2; @@ -262,7 +261,7 @@ + "/services/xml/LearningDesignRepository?method="+method+"&datetime=" + timestamp + "&username=" + URLEncoder.encode(username, "utf8") + "&serverId=" + URLEncoder.encode(serverId, "utf8") + "&hashValue=" + hash + "&courseId=" - + URLEncoder.encode(courseId, "UTF8") + "&country=" + country + "&lang=" + lang + "&mode=" + MODE + + URLEncoder.encode(courseId, "UTF8") + "&country=" + country + "&lang=" + locale + "&mode=" + MODE + "&firstName=" + URLEncoder.encode(firstName, "UTF-8") + "&lastName=" + URLEncoder.encode(lastName, "UTF-8") + "&email=" + URLEncoder.encode(email, "UTF-8"); @@ -351,16 +350,15 @@ String hash = generateAuthenticationHash(timestamp, username, serverId); String locale = ctx.getUser().getLocale(); - String country = getCountry(locale); - String lang = getLanguage(locale); + String country = getCountryCode(ctx.getUser().getCountry()); try { String serviceURL = serverAddr + "/services/xml/LearningDesignRepository?method=deleteLearningDesignJSON&datetime=" + timestamp + "&username=" + URLEncoder.encode(username, "utf8") + "&serverId=" + URLEncoder.encode(serverId, "utf8") + "&hashValue=" + hash + "&courseId=" - + URLEncoder.encode(courseId, "UTF8") + "&country=" + country + "&lang=" + lang + + URLEncoder.encode(courseId, "UTF8") + "&country=" + country + "&lang=" + locale + "&firstName=" + URLEncoder.encode(firstName, "UTF-8") + "&lastName=" + URLEncoder.encode(lastName, "UTF-8") + "&email=" + URLEncoder.encode(email, "UTF-8") + "&learningDesignID="+ldId; @@ -431,8 +429,7 @@ String username = user.getUserName(); String locale = user.getLocale(); - String country = getCountry(locale); - String lang = getLanguage(locale); + String country = getCountryCode(user.getCountry()); String method = (isPreview) ? "preview" : "start"; if (courseId == null || serverId == null || serverAddr == null || serverSecretKey == null) { @@ -447,11 +444,10 @@ String serviceURL = serverAddr + "/services/xml/LessonManager?" + "serverId=" + URLEncoder.encode(serverId, "utf8") + "&datetime=" + timestamp + "&username=" - + URLEncoder.encode(username, "utf8") + "&hashValue=" + hash + course - + "&ldId=" + new Long(ldId).toString() + "&country=" - + country + "&lang=" + lang + "&method=" + method + "&title=" - + URLEncoder.encode(title, "utf8").trim() + "&desc=" + URLEncoder.encode(desc, "utf8").trim() - + "&enableNotifications=true"; + + URLEncoder.encode(username, "utf8") + "&hashValue=" + hash + course + "&ldId=" + + new Long(ldId).toString() + "&country=" + country + "&lang=" + locale + "&method=" + method + + "&title=" + URLEncoder.encode(title, "utf8").trim() + "&desc=" + + URLEncoder.encode(desc, "utf8").trim() + "&enableNotifications=true"; logger.info("LAMS START LESSON Req: " + serviceURL); @@ -549,8 +545,7 @@ String serverSecretKey = LamsPluginUtil.getServerSecretKey(); String username = teacher.getUserName(); String locale = teacher.getLocale(); - String country = getCountry(locale); - String lang = getLanguage(locale); + String country = getCountryCode(teacher.getCountry()); if (courseId == null || serverId == null || serverAddr == null || serverSecretKey == null) { logger.info("Unable to clone lesson, one or more lams configuration properties or the course id is null"); @@ -565,7 +560,7 @@ + URLEncoder.encode(serverId, "utf8") + "&datetime=" + timestamp + "&username=" + URLEncoder.encode(username, "utf8") + "&hashValue=" + hash + "&courseId=" + URLEncoder.encode(courseId, "UTF8") + "&country=" - + country + "&lang=" + lang + "&lsId=" + lsId + "&method=" + method; + + country + "&lang=" + locale + "&lsId=" + lsId + "&method=" + method; logger.info("LAMS clone lesson request: " + serviceURL); @@ -623,8 +618,7 @@ String serverSecretKey = LamsPluginUtil.getServerSecretKey(); String username = teacher.getUserName(); String locale = teacher.getLocale(); - String country = getCountry(locale); - String lang = getLanguage(locale); + String country = getCountryCode(teacher.getCountry()); if (courseId == null || serverId == null || serverAddr == null || serverSecretKey == null) { logger.info("Unable to import lesson, one or more lams configuration properties or the course id is null"); @@ -641,8 +635,8 @@ String serviceURL = serverAddr + "/services/xml/LessonManager?" + "serverId=" + URLEncoder.encode(serverId, "utf8") + "&datetime=" + timestamp + "&username=" + URLEncoder.encode(username, "utf8") + "&hashValue=" + hash + "&courseId=" - + URLEncoder.encode(courseId, "UTF8") + "&country=" - + country + "&lang=" + lang + "&method=import&customCSV=&filePath=" + filePathParam; + + URLEncoder.encode(courseId, "UTF8") + "&country=" + country + "&lang=" + locale + + "&method=import&customCSV=&filePath=" + filePathParam; logger.info("LAMS import lesson request: " + serviceURL); @@ -701,15 +695,13 @@ String serverSecretKey = LamsPluginUtil.getServerSecretKey(); String username = user.getUserName(); String locale = user.getLocale(); - String country = getCountry(locale); - String lang = getLanguage(locale); + String country = getCountryCode(user.getCountry()); if (serverId == null || serverAddr == null || serverSecretKey == null) { throw new RuntimeException("Unable to start lesson, one or more lams configuration properties is null"); } try { - /* * Returns a list of learners and monitors in the given course or group. */ @@ -781,9 +773,9 @@ String serviceURL = serverAddr + "/services/xml/LessonManager?" + "&serverId=" + URLEncoder.encode(serverId, "utf8") + "&datetime=" + timestamp + "&username=" + URLEncoder.encode(username, "utf8") + "&hashValue=" + hash + "&courseId=" - + URLEncoder.encode(course.getCourseId(), "utf8") + "&lsId=" + lessonId + "&country=" + country + "&lang=" - + lang + "&method=join" + "&firstNames=" - + firstNames + "&lastNames=" + lastNames + "&emails=" + emails; + + URLEncoder.encode(course.getCourseId(), "utf8") + "&lsId=" + lessonId + "&country=" + country + + "&lang=" + locale + "&method=join" + "&firstNames=" + firstNames + "&lastNames=" + lastNames + + "&emails=" + emails; if (!monitorIds.isEmpty()) { serviceURL += "&monitorIds=" + monitorIds; } @@ -863,8 +855,7 @@ String lastName = ctx.getUser().getFamilyName(); String email = ctx.getUser().getEmailAddress(); String locale = ctx.getUser().getLocale(); - String country = getCountry(locale); - String lang = getLanguage(locale); + String country = getCountryCode(ctx.getUser().getCountry()); if (serverId == null || serverAddr == null || serverSecretKey == null) { throw new RuntimeException("Unable to start lesson, one or more lams configuration properties is null"); @@ -878,7 +869,7 @@ String serviceURL = serverAddr + "/services/xml/LessonManager?method=singleStudentProgress" + "&serverId=" + URLEncoder.encode(serverId, "utf8") + "&datetime=" + timestamp + "&username=" + URLEncoder.encode(username, "utf8") + "&hashValue=" + hash + "&courseId=" - + URLEncoder.encode(courseId, "utf8") + "&country=" + country + "&lang=" + lang + "&firstName=" + + URLEncoder.encode(courseId, "utf8") + "&country=" + country + "&lang=" + locale + "&firstName=" + URLEncoder.encode(firstName, "UTF-8") + "&lastName=" + URLEncoder.encode(lastName, "UTF-8") + "&email=" + URLEncoder.encode(email, "UTF-8") + "&lsId=" + new Long(lsId).toString(); @@ -1105,34 +1096,25 @@ throw new RuntimeException(e); } } - + /** - * - * @param localeStr - * the full balckboard locale string - * @return the language + * Returns country code based on country name. If it can't find according code - returns "XX". */ - public static String getLanguage(String localeStr) { - if (localeStr == null) - return "xx"; - String[] split = localeStr.split("_"); - return split[0]; - } + public static String getCountryCode(String countryName) { + + if (StringUtils.isNotBlank(countryName)) { + Locale[] locales = Locale.getAvailableLocales(); + for (Locale locale : locales) { + String code = locale.getCountry(); + String name = locale.getDisplayCountry(); - /** - * - * @param localeStr - * the full balckboard locale string - * @return the country - */ - public static String getCountry(String localeStr) { - if (localeStr == null) - return "XX"; - String[] split = localeStr.split("_"); + if (countryName.equals(name)) { + return code; + } + } + } - //default country set to AU - String country = split.length > 1 ? split[1] : "AU"; - return country; + return "XX"; } }