Index: lams_admin/.classpath =================================================================== RCS file: /usr/local/cvsroot/lams_admin/.classpath,v diff -u -r1.10.2.9 -r1.10.2.10 --- lams_admin/.classpath 25 Nov 2014 10:47:34 -0000 1.10.2.9 +++ lams_admin/.classpath 15 Dec 2015 18:13:14 -0000 1.10.2.10 @@ -13,7 +13,8 @@ - + + Index: lams_admin/conf/xdoclet/struts-forms.xml =================================================================== RCS file: /usr/local/cvsroot/lams_admin/conf/xdoclet/struts-forms.xml,v diff -u -r1.43.2.4 -r1.43.2.5 --- lams_admin/conf/xdoclet/struts-forms.xml 23 Oct 2015 16:07:49 -0000 1.43.2.4 +++ lams_admin/conf/xdoclet/struts-forms.xml 15 Dec 2015 18:13:14 -0000 1.43.2.5 @@ -84,6 +84,7 @@ + Index: lams_admin/web/servermaintain.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_admin/web/servermaintain.jsp,v diff -u -r1.11.2.3 -r1.11.2.4 --- lams_admin/web/servermaintain.jsp 8 Dec 2014 14:45:54 -0000 1.11.2.3 +++ lams_admin/web/servermaintain.jsp 15 Dec 2015 18:13:14 -0000 1.11.2.4 @@ -88,6 +88,10 @@ : + + : + +
@@ -130,7 +134,6 @@ prefix: "${namev}", userinfoUrl: "${namev}", timeoutUrl: "${namev}", - timeoutUrl: "${namev}", timeToLiveLoginRequest: { required: "${namev}", min: "" Index: lams_central/.classpath =================================================================== RCS file: /usr/local/cvsroot/lams_central/.classpath,v diff -u -r1.20.2.20 -r1.20.2.21 --- lams_central/.classpath 23 Oct 2015 16:13:46 -0000 1.20.2.20 +++ lams_central/.classpath 15 Dec 2015 18:12:07 -0000 1.20.2.21 @@ -39,5 +39,6 @@ + Index: lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupAction.java,v diff -u -r1.9.2.1 -r1.9.2.2 --- lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupAction.java 3 Nov 2014 14:12:05 -0000 1.9.2.1 +++ lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupAction.java 15 Dec 2015 18:12:07 -0000 1.9.2.2 @@ -24,6 +24,7 @@ package org.lamsfoundation.lams.web; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -39,6 +40,7 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.apache.commons.collections.CollectionUtils; import org.apache.log4j.Logger; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; @@ -48,6 +50,8 @@ import org.apache.tomcat.util.json.JSONException; import org.apache.tomcat.util.json.JSONObject; import org.lamsfoundation.lams.contentrepository.InvalidParameterException; +import org.lamsfoundation.lams.integration.dto.ExtGroupDTO; +import org.lamsfoundation.lams.integration.service.IIntegrationService; import org.lamsfoundation.lams.learningdesign.Group; import org.lamsfoundation.lams.learningdesign.GroupComparator; import org.lamsfoundation.lams.learningdesign.Grouping; @@ -73,6 +77,7 @@ * @struts.action path = "/OrganisationGroup" parameter = "method" validate = "false" * @struts.action-forward name = "viewGroupings" path = "/orgGrouping.jsp" * @struts.action-forward name = "viewGroups" path = "/orgGroup.jsp" + * @struts.action-forward name = "viewExtGroups" path = "/extGroups.jsp" */ public class OrganisationGroupAction extends DispatchAction { /** @@ -141,18 +146,19 @@ private static IUserManagementService userManagementService; private static ILessonService lessonService; private static ISecurityService securityService; + private static IIntegrationService integrationService; private static final String MAPPING_VIEW_GROUPINGS = "viewGroupings"; private static final String MAPPING_VIEW_GROUPS = "viewGroups"; + private static final String MAPPING_VIEW_EXT_GROUPS = "viewExtGroups"; /** * Shows course grouping list or redirects to groups if a grouping was already chosen. - * - * @throws IOException + * @throws Exception */ @SuppressWarnings("unchecked") public ActionForward viewGroupings(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws JSONException, IOException { + HttpServletResponse response) throws Exception { Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID, true); boolean lessonGroupsExist = getLessonGrouping(request, activityID, false) != null; if (lessonGroupsExist) { @@ -162,9 +168,9 @@ Integer userId = getUserDTO().getUserID(); Integer organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true); + Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID, true); if (organisationId == null) { // read organisation ID from lesson - Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); organisationId = ((Lesson) getUserManagementService().findById(Lesson.class, lessonId)).getOrganisation() .getOrganisationId(); } @@ -177,35 +183,46 @@ return null; } - boolean isGroupSuperuser = getUserManagementService().isUserInRole(userId, organisationId, Role.GROUP_ADMIN) - || getUserManagementService().isUserInRole(userId, organisationId, Role.GROUP_MANAGER); - if (OrganisationGroupAction.log.isDebugEnabled()) { OrganisationGroupAction.log.debug("Displaying course groupings for user " + userId + " and organisation " + organisationId); } request.setAttribute(AttributeNames.PARAM_ORGANISATION_ID, organisationId); - request.setAttribute("canEdit", isGroupSuperuser || (activityID != null)); - Set orgGroupingDTOs = new TreeSet(); - List orgGroupings = getUserManagementService().findByProperty(OrganisationGrouping.class, - "organisationId", organisationId); - for (OrganisationGrouping orgGrouping : orgGroupings) { - orgGroupingDTOs.add(new OrganisationGroupingDTO(orgGrouping)); + // if this is a chosen group and lesson is created using integrations - show groups received from LMS instead of actual LAMS ones + if (lessonId != null && getIntegrationService().isIntegratedServerGroupFetchingAvailable(lessonId)) { + List extGroups = getIntegrationService().getExtGroups(lessonId, null); + request.setAttribute("extGroups", extGroups); + // TODO ? show only with user number >0 + return mapping.findForward(OrganisationGroupAction.MAPPING_VIEW_EXT_GROUPS); + + } else { + + boolean isGroupSuperuser = getUserManagementService() + .isUserInRole(userId, organisationId, Role.GROUP_ADMIN) + || getUserManagementService().isUserInRole(userId, organisationId, Role.GROUP_MANAGER); + request.setAttribute("canEdit", isGroupSuperuser || (activityID != null)); + + Set orgGroupingDTOs = new TreeSet(); + List orgGroupings = getUserManagementService().findByProperty( + OrganisationGrouping.class, "organisationId", organisationId); + for (OrganisationGrouping orgGrouping : orgGroupings) { + orgGroupingDTOs.add(new OrganisationGroupingDTO(orgGrouping)); + } + request.setAttribute("groupings", orgGroupingDTOs); + + return mapping.findForward(OrganisationGroupAction.MAPPING_VIEW_GROUPINGS); } - request.setAttribute("groupings", orgGroupingDTOs); - return mapping.findForward(OrganisationGroupAction.MAPPING_VIEW_GROUPINGS); } /** * View groups of the given grouping. - * - * @throws IOException + * @throws Exception */ @SuppressWarnings("unchecked") public ActionForward viewGroups(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws JSONException, IOException { + HttpServletResponse response) throws Exception { Integer userId = getUserDTO().getUserID(); Integer organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true); Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID, true); @@ -248,11 +265,16 @@ orgGroupingJSON.put("name", orgGrouping.getName()); } } + + //selected groups from integrated server + String[] extGroupIds = request.getParameterValues("extGroupIds"); + boolean isExternalGroupsSelected = extGroupIds != null && extGroupIds.length > 0; // check if any groups already exist in this grouping Grouping lessonGrouping = getLessonGrouping(request, activityId, true); Set lessonGroups = lessonGrouping == null ? null : lessonGrouping.getGroups(); - if ((activityId != null) && (orgGroupingId != null) && isDefaultChosenGrouping(lessonGrouping)) { + if ((activityId != null) && (lessonGrouping != null) && (isExternalGroupsSelected || (orgGroupingId != null)) + && isDefaultChosenGrouping(lessonGrouping)) { if (OrganisationGroupAction.log.isDebugEnabled()) { OrganisationGroupAction.log.debug("Removing default groups for grouping " + orgGroupingId); } @@ -268,16 +290,73 @@ lessonGroups = null; } - JSONArray orgGroupsJSON = null; + JSONArray orgGroupsJSON = new JSONArray(); Collection learners = null; - // select source for groups (course or lesson) - if ((lessonGroups == null) || lessonGroups.isEmpty()) { + // if teacher selected groups from integrated server - show them + if (isExternalGroupsSelected) { + + if (lesson == null) { + lesson = (Lesson) getUserManagementService().findById(Lesson.class, lessonId); + } + learners = lesson.getLessonClass().getLearners(); + + //request all users from selected groups from integrated server + List extGroups = getIntegrationService().getExtGroups(lessonId, extGroupIds); + + // serialize database group objects into JSON + if (extGroups != null) { + + //if there are duplicate users - put them into unassigned column + List allDuplicates = new ArrayList(); + for (ExtGroupDTO groupA : extGroups) { + for (ExtGroupDTO groupB : extGroups) { + List usersA = groupA.getUsers(); + List usersB = groupB.getUsers(); + + //proceed for non empty and different groups + if ((usersA != null) && (usersB != null) && !groupA.getGroupId().equals(groupB.getGroupId())) { + + Collection duplicates = CollectionUtils.intersection(usersA, usersB); + allDuplicates.addAll(duplicates); + + usersA.removeAll(duplicates); + usersB.removeAll(duplicates); + } + + } + } + + // sort groups by their name + Collections.sort(extGroups); + for (ExtGroupDTO extGroup : extGroups) { + JSONObject groupJSON = new JSONObject(); + groupJSON.put("name", extGroup.getGroupName()); + groupJSON.put("groupId", extGroup.getGroupId()); + if (extGroup.getUsers() != null) { + for (User groupUser : (List) extGroup.getUsers()) { + JSONObject groupUserJSON = WebUtil.userToJSON(groupUser); + groupJSON.append("users", groupUserJSON); + + // remove the user who is already assigned to a group + learners.remove(groupUser); + } + } + orgGroupsJSON.put(groupJSON); + } + } + + // if groups haven't been selected yet - show all available groups in organisation + } else if ((lessonGroups == null) || lessonGroups.isEmpty()) { + learners = getUserManagementService().getUsersFromOrganisationByRole(organisationId, Role.LEARNER, false, true); Set orgGroups = orgGrouping == null ? null : orgGrouping.getGroups(); orgGroupsJSON = getOrgGroupsDetails(orgGroups, learners); + + // show already selected groups } else { + if (lesson == null) { lesson = (Lesson) getUserManagementService().findById(Lesson.class, lessonId); } @@ -394,11 +473,10 @@ /** * Deletes course grouping with the given ID. - * - * @throws IOException + * @throws Exception */ public ActionForward removeGrouping(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws JSONException, IOException { + HttpServletResponse response) throws Exception { // check if user is allowed to edit groups Integer userId = getUserDTO().getUserID(); int organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID); @@ -557,4 +635,13 @@ } return OrganisationGroupAction.securityService; } + + private IIntegrationService getIntegrationService() { + if (OrganisationGroupAction.integrationService == null) { + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() + .getServletContext()); + OrganisationGroupAction.integrationService = (IIntegrationService) ctx.getBean("integrationService"); + } + return OrganisationGroupAction.integrationService; + } } \ No newline at end of file Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `lams_central/web/extGroups.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_common/.classpath =================================================================== RCS file: /usr/local/cvsroot/lams_common/.classpath,v diff -u -r1.25.2.25 -r1.25.2.26 --- lams_common/.classpath 25 Aug 2015 11:00:40 -0000 1.25.2.25 +++ lams_common/.classpath 15 Dec 2015 18:12:05 -0000 1.25.2.26 @@ -26,7 +26,7 @@ - + Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/integration/ExtServerOrgMap.hbm.xml =================================================================== RCS file: /usr/local/cvsroot/lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/integration/Attic/ExtServerOrgMap.hbm.xml,v diff -u -r1.6.2.4 -r1.6.2.5 --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/integration/ExtServerOrgMap.hbm.xml 8 Dec 2014 14:45:57 -0000 1.6.2.4 +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/integration/ExtServerOrgMap.hbm.xml 15 Dec 2015 18:12:05 -0000 1.6.2.5 @@ -115,6 +115,16 @@ length="65535" not-null="false" /> + + + Fisheye: Tag 1.1.2.3 refers to a dead (removed) revision in file `lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch2040050.sql'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_common/src/java/org/lamsfoundation/lams/integration/ExtServerOrgMap.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/integration/Attic/ExtServerOrgMap.java,v diff -u -r1.6.2.2 -r1.6.2.3 --- lams_common/src/java/org/lamsfoundation/lams/integration/ExtServerOrgMap.java 8 Dec 2014 14:45:57 -0000 1.6.2.2 +++ lams_common/src/java/org/lamsfoundation/lams/integration/ExtServerOrgMap.java 15 Dec 2015 18:12:05 -0000 1.6.2.3 @@ -38,6 +38,8 @@ /** persistent field */ private String lessonFinishUrl; + + private String extGroupsUrl; /** persistent field */ private Boolean disabled; @@ -140,7 +142,15 @@ public void setLessonFinishUrl(String lessonFinishUrl) { this.lessonFinishUrl = lessonFinishUrl; } + + public String getExtGroupsUrl() { + return this.extGroupsUrl; + } + public void setExtGroupsUrl(String extGroupsUrl) { + this.extGroupsUrl = extGroupsUrl; + } + public Boolean getDisabled() { return this.disabled; } Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `lams_common/src/java/org/lamsfoundation/lams/integration/dto/ExtGroupDTO.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_common/src/java/org/lamsfoundation/lams/integration/service/IIntegrationService.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/integration/service/IIntegrationService.java,v diff -u -r1.15.2.3 -r1.15.2.4 --- lams_common/src/java/org/lamsfoundation/lams/integration/service/IIntegrationService.java 21 Oct 2015 11:44:55 -0000 1.15.2.3 +++ lams_common/src/java/org/lamsfoundation/lams/integration/service/IIntegrationService.java 15 Dec 2015 18:12:05 -0000 1.15.2.4 @@ -32,6 +32,7 @@ import org.lamsfoundation.lams.integration.ExtUserUseridMap; import org.lamsfoundation.lams.integration.UserInfoFetchException; import org.lamsfoundation.lams.integration.UserInfoValidationException; +import org.lamsfoundation.lams.integration.dto.ExtGroupDTO; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.usermanagement.User; @@ -151,4 +152,16 @@ * @throws UnsupportedEncodingException */ String getLessonFinishCallbackUrl(User user, Lesson lesson) throws UnsupportedEncodingException; + + /** + * Checks whether lesson was created using integrations and whether according integrated server has ExtGroupsUrl + * property set up. + * + * @param lessonId + * @return true in case lesson was created using integrations and according integrated server has ExtGroupsUrl + * property set up, false otherwise + */ + boolean isIntegratedServerGroupFetchingAvailable(Long lessonId); + + List getExtGroups(Long lessonId, String[] extGroupIds) throws Exception; } Index: lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java,v diff -u -r1.33.2.3 -r1.33.2.4 --- lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java 21 Oct 2015 11:44:55 -0000 1.33.2.3 +++ lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java 15 Dec 2015 18:12:05 -0000 1.33.2.4 @@ -34,23 +34,29 @@ import java.net.URLConnection; import java.net.URLEncoder; import java.text.ParseException; +import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; +import org.apache.tomcat.util.json.JSONArray; +import org.apache.tomcat.util.json.JSONObject; import org.lamsfoundation.lams.integration.ExtCourseClassMap; import org.lamsfoundation.lams.integration.ExtServerLessonMap; import org.lamsfoundation.lams.integration.ExtServerOrgMap; import org.lamsfoundation.lams.integration.ExtServerToolAdapterMap; import org.lamsfoundation.lams.integration.ExtUserUseridMap; import org.lamsfoundation.lams.integration.UserInfoFetchException; import org.lamsfoundation.lams.integration.UserInfoValidationException; +import org.lamsfoundation.lams.integration.dto.ExtGroupDTO; import org.lamsfoundation.lams.integration.security.RandomPasswordGenerator; +import org.lamsfoundation.lams.integration.util.GroupInfoFetchException; import org.lamsfoundation.lams.integration.util.LoginRequestDispatcher; import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.lesson.service.ILessonService; import org.lamsfoundation.lams.usermanagement.AuthenticationMethod; import org.lamsfoundation.lams.usermanagement.Organisation; import org.lamsfoundation.lams.usermanagement.OrganisationState; @@ -64,6 +70,7 @@ import org.lamsfoundation.lams.util.HashUtil; import org.lamsfoundation.lams.util.LanguageUtil; import org.lamsfoundation.lams.util.ValidationUtil; +import org.lamsfoundation.lams.util.WebUtil; /** *

@@ -77,15 +84,8 @@ private static Logger log = Logger.getLogger(IntegrationService.class); private IUserManagementService service; + private ILessonService lessonService; - public IUserManagementService getService() { - return service; - } - - public void setService(IUserManagementService service) { - this.service = service; - } - @Override public ExtServerOrgMap getExtServerOrgMap(String serverId) { List list = service.findByProperty(ExtServerOrgMap.class, "serverid", serverId); @@ -561,7 +561,7 @@ @Override public String getLessonFinishCallbackUrl(User user, Lesson lesson) throws UnsupportedEncodingException { // the callback url must contain %username%, %lessonid%, %timestamp% and %hash% eg: - // "http://test100.ics.mq.edu.au/webapps/lams-plglamscontent-bb_bb60/UserData?uid=%username%&lessonid=%lessonid%&ts=%timestamp%&hash=%hash%"; + // "http://server.com/lams--bb/UserData?uid=%username%&lessonid=%lessonid%&ts=%timestamp%&hash=%hash%"; // where %username%, %lessonid%, %timestamp% and %hash% will be replaced with their real values String lessonFinishCallbackUrl = null; @@ -594,7 +594,151 @@ return lessonFinishCallbackUrl; } + + @Override + public boolean isIntegratedServerGroupFetchingAvailable(Long lessonId) { + boolean isIntegratedServerGroupFetchingAvailable = false; + if (lessonId != null) { + ExtServerLessonMap extServerLesson = getExtServerLessonMap(lessonId); + isIntegratedServerGroupFetchingAvailable = (extServerLesson != null) + && StringUtils.isNotBlank(extServerLesson.getExtServer().getExtGroupsUrl()); + } + + return isIntegratedServerGroupFetchingAvailable; + } + + @Override + public List getExtGroups(Long lessonId, String[] extGroupIds) throws Exception { + // the callback url must contain %username%, %lessonid%, %timestamp% and %hash% eg: + // "http://server.org/lams-bb/UserData?uid=%username%&lessonid=%lessonid%&ts=%timestamp%&hash=%hash%"; + // where %username%, %lessonid%, %timestamp% and %hash% will be replaced with their real values + + if (lessonId == null) { + throw new GroupInfoFetchException("Fail to fetch group data from external server:" + + " specified lessonId is null"); + } + + Lesson lesson = (Lesson) service.findById(Lesson.class, lessonId); + if (lesson == null) { + throw new GroupInfoFetchException("Fail to fetch group data from external server:" + + " specified lesson is null"); + } + Organisation organisation = lesson.getOrganisation(); + Integer organisationId = lesson.getOrganisation().getOrganisationId(); + + ExtServerLessonMap extServerLesson = getExtServerLessonMap(lessonId); + ExtCourseClassMap extCourse = getExtCourseClassMap(organisationId); + + // checks whether the lesson was created from extServer and whether it has lessonFinishCallbackUrl setting + if (extServerLesson == null) { + throw new GroupInfoFetchException("Fail to fetch group data from external server:" + + " there is no corresponding ExtServerLessonMap for lessonId " + lessonId); + } + + if (StringUtils.isBlank(extServerLesson.getExtServer().getExtGroupsUrl())) { + throw new GroupInfoFetchException("Fail to fetch group data from external server:" + + " corresponding ExtCourseClassMap doesn't have extGroupsUrl specified."); + } + + if (extCourse == null) { + throw new GroupInfoFetchException("Fail to fetch group data from external server:" + + " there is no corresponding ExtCourseClassMap for lessonId " + lessonId); + } + + ExtServerOrgMap serverMap = extServerLesson.getExtServer(); + + // construct real lessonFinishCallbackUrl + String lmsGroupsUrl = serverMap.getExtGroupsUrl(); + + //in case group info is also requested - provide selected groups' ids + if (extGroupIds != null && extGroupIds.length > 0) { + + if (!lmsGroupsUrl.contains("?")) { + lmsGroupsUrl += "?"; + } + String extGroupIdsParam = ""; + for (String extGroupId : extGroupIds) { + extGroupIdsParam += "&extGroupIds=" + extGroupId; + } + lmsGroupsUrl += extGroupIdsParam; + } + + String timestamp = Long.toString(new Date().getTime()); + String hashUsername = "username"; + String hash = hash(serverMap, hashUsername, timestamp); + + // set values for the parameters + HashMap params = new HashMap(); + params.put("uid", hashUsername); + params.put("ts", timestamp); + params.put("hash", hash); + params.put("course_id", extCourse.getCourseid()); + + // send the request to the external server + InputStream is = WebUtil.getResponseInputStreamFromExternalServer(lmsGroupsUrl, params); + BufferedReader isReader = new BufferedReader(new InputStreamReader(is)); + String str = isReader.readLine(); + + JSONArray jsonGroups = new JSONArray(str); + List extGroups = new ArrayList(); + for (int i = 0; i < jsonGroups.length(); i++) { + JSONObject jsonGroup = jsonGroups.getJSONObject(i); + ExtGroupDTO group = new ExtGroupDTO(); + group.setGroupName(jsonGroup.getString("groupName")); + group.setGroupId(jsonGroup.getString("groupId")); + extGroups.add(group); + + // in case group info is also requested - provide selected groups' ids + if (extGroupIds != null && extGroupIds.length > 0) { + ArrayList users = new ArrayList(); + + JSONArray jsonUsers = jsonGroup.getJSONArray("users"); + for (int j = 0; j < jsonUsers.length(); j++) { + JSONObject jsonUser = jsonUsers.getJSONObject(j); + + String extUsername = jsonUser.getString("userName"); + + ExtUserUseridMap extUserUseridMap = getExistingExtUserUseridMap(serverMap, extUsername); + + //create extUserUseridMap if it's not available + if (extUserUseridMap == null) { + // User properties list format: ,<First name>,<Last name>,<Address>,<City>,<State>, + // <Postcode>,<Country>,<Day time number>,<Mobile number>,<Fax number>,<Email>,<Locale + // language>,<Locale country> + String[] userData = new String[14]; + for (int k=1; k <= 14; k++) { + String userProperty = jsonUser.getString("" + k); + userData[k-1] = userProperty; + } + String salt = HashUtil.salt(); + String password = HashUtil.sha1(RandomPasswordGenerator.nextPassword(10)); + extUserUseridMap = createExtUserUseridMap(serverMap, extUsername, password, salt, userData, true); + } + User user = extUserUseridMap.getUser(); + Integer userId = extUserUseridMap.getUser().getUserId(); + + //add user to organisation if it's not there + updateUserRoles(user, organisation, false); + + //check if user belong to the lesson. and if not - add it + if (!lesson.getLessonClass().getLearnersGroup().hasLearner(user)) { + lessonService.addLearner(lessonId, userId); + } + + users.add(user); + } + + group.setUsers(users); + } else { + group.setNumberUsers(jsonGroup.getInt("groupSize")); + } + + } + + return extGroups; + } + private ExtServerLessonMap getExtServerLessonMap(Long lessonId) { List list = service.findByProperty(ExtServerLessonMap.class, "lessonId", lessonId); if ((list == null) || (list.size() == 0)) { @@ -615,4 +759,21 @@ return (ExtUserUseridMap) list.get(0); } } + + private ExtCourseClassMap getExtCourseClassMap(Integer organisationId) { + List list = service.findByProperty(ExtCourseClassMap.class, "organisation.organisationId", organisationId); + if (list == null || list.size() == 0) { + return null; + } else { + return (ExtCourseClassMap) list.get(0); + } + } + + public void setService(IUserManagementService service) { + this.service = service; + } + + public void setLessonService(ILessonService lessonService) { + this.lessonService = lessonService; + } } \ No newline at end of file Fisheye: Tag 1.1.2.1 refers to a dead (removed) revision in file `lams_common/src/java/org/lamsfoundation/lams/integration/util/GroupInfoFetchException.java'. Fisheye: No comparison available. Pass `N' to diff?