Index: lams_build/lib/lams/lams-central.jar =================================================================== diff -u -r8482164570cc9e8db87a1419dc6944c58553b327 -rab2e2241e9bfa93bad93f8908850405d124daaa5 Binary files differ Index: lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupAction.java =================================================================== diff -u -rd0a703641dee45b84a2cd9a011376a8f0d72c9fb -rab2e2241e9bfa93bad93f8908850405d124daaa5 --- lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupAction.java (.../OrganisationGroupAction.java) (revision d0a703641dee45b84a2cd9a011376a8f0d72c9fb) +++ lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupAction.java (.../OrganisationGroupAction.java) (revision ab2e2241e9bfa93bad93f8908850405d124daaa5) @@ -52,6 +52,7 @@ 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.Activity; import org.lamsfoundation.lams.learningdesign.Group; import org.lamsfoundation.lams.learningdesign.GroupComparator; import org.lamsfoundation.lams.learningdesign.Grouping; @@ -154,19 +155,12 @@ /** * Shows course grouping list or redirects to groups if a grouping was already chosen. - * @throws Exception + * + * @throws Exception */ @SuppressWarnings("unchecked") public ActionForward viewGroupings(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { - Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID, true); - boolean lessonGroupsExist = getLessonGrouping(request, activityID, false) != null; - if (lessonGroupsExist) { - // this is lesson mode and user have already chosen a grouping before, so show it - return viewGroups(mapping, form, request, response); - } - - 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) { @@ -175,37 +169,44 @@ .getOrganisationId(); } - // check if user is allowed to view and edit groups + Integer userId = getUserDTO().getUserID(); + // check if user is allowed to view and edit groupings if (!getSecurityService().hasOrgRole(organisationId, userId, new String[] { Role.GROUP_ADMIN, Role.GROUP_MANAGER, Role.MONITOR, Role.AUTHOR }, "view organisation groupings", false)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a participant in the organisation"); return null; } + Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID, true); + + boolean lessonGroupsExist = getLessonGrouping(request, activityID, false) != null; + if (lessonGroupsExist) { + // this is lesson mode and user have already chosen a grouping before, so show it + return viewGroups(mapping, form, request, response); + } + if (OrganisationGroupAction.log.isDebugEnabled()) { - OrganisationGroupAction.log.debug("Displaying course groupings for user " + userId + " and organisation " - + organisationId); + OrganisationGroupAction.log + .debug("Displaying course groupings for user " + userId + " and organisation " + organisationId); } request.setAttribute(AttributeNames.PARAM_ORGANISATION_ID, organisationId); // 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)) { + 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) + boolean canEdit = getUserManagementService().isUserInRole(userId, organisationId, Role.GROUP_ADMIN) || getUserManagementService().isUserInRole(userId, organisationId, Role.GROUP_MANAGER); - request.setAttribute("canEdit", isGroupSuperuser || (activityID != null)); + canEdit |= activityID != null; + request.setAttribute("canEdit", canEdit); + List orgGroupings = getUserManagementService() + .findByProperty(OrganisationGrouping.class, "organisationId", organisationId); Set orgGroupingDTOs = new TreeSet(); - List orgGroupings = getUserManagementService().findByProperty( - OrganisationGrouping.class, "organisationId", organisationId); for (OrganisationGrouping orgGrouping : orgGroupings) { orgGroupingDTOs.add(new OrganisationGroupingDTO(orgGrouping)); } @@ -218,7 +219,8 @@ /** * View groups of the given grouping. - * @throws Exception + * + * @throws Exception */ @SuppressWarnings("unchecked") public ActionForward viewGroups(ActionMapping mapping, ActionForm form, HttpServletRequest request, @@ -245,8 +247,8 @@ || getUserManagementService().isUserInRole(userId, organisationId, Role.GROUP_MANAGER); if (OrganisationGroupAction.log.isDebugEnabled()) { - OrganisationGroupAction.log.debug("Displaying course groups for user " + userId + " and organisation " - + organisationId); + OrganisationGroupAction.log + .debug("Displaying course groups for user " + userId + " and organisation " + organisationId); } Long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID, true); request.setAttribute("canEdit", isGroupSuperuser || (activityId != null)); @@ -265,10 +267,10 @@ orgGroupingJSON.put("name", orgGrouping.getName()); } } - + //selected groups from integrated server String[] extGroupIds = request.getParameterValues("extGroupIds"); - boolean isExternalGroupsSelected = extGroupIds != null && extGroupIds.length > 0; + boolean isExternalGroupsSelected = (extGroupIds != null) && (extGroupIds.length > 0); // check if any groups already exist in this grouping Grouping lessonGrouping = getLessonGrouping(request, activityId, true); @@ -295,38 +297,38 @@ // 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) { @@ -345,18 +347,18 @@ orgGroupsJSON.put(groupJSON); } } - - // if groups haven't been selected yet - show all available groups in organisation + + // 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 + + // show already selected groups } else { - + if (lesson == null) { lesson = (Lesson) getUserManagementService().findById(Lesson.class, lessonId); } @@ -398,8 +400,8 @@ } if (OrganisationGroupAction.log.isDebugEnabled()) { - OrganisationGroupAction.log.debug("Saving course groups for user " + userId + " and organisation " - + organisationId); + OrganisationGroupAction.log + .debug("Saving course groups for user " + userId + " and organisation " + organisationId); } // deserialize grouping @@ -458,8 +460,8 @@ duplicateCheckProperties.put("organisationId", organisationId); duplicateCheckProperties.put("name", orgGroupingName); - List duplicateOrgGrouping = getUserManagementService().findByProperties( - OrganisationGrouping.class, duplicateCheckProperties); + List duplicateOrgGrouping = getUserManagementService() + .findByProperties(OrganisationGrouping.class, duplicateCheckProperties); if (duplicateOrgGrouping.isEmpty()) { orgGrouping.setName(orgGroupingName); } else { @@ -473,7 +475,8 @@ /** * Deletes course grouping with the given ID. - * @throws Exception + * + * @throws Exception */ public ActionForward removeGrouping(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { @@ -488,8 +491,8 @@ Long groupingId = WebUtil.readLongParam(request, "groupingId"); if (OrganisationGroupAction.log.isDebugEnabled()) { - OrganisationGroupAction.log.debug("Removing grouping " + groupingId + " for user " + userId - + " and organisation " + organisationId); + OrganisationGroupAction.log.debug( + "Removing grouping " + groupingId + " for user " + userId + " and organisation " + organisationId); } getUserManagementService().deleteById(OrganisationGrouping.class, groupingId); @@ -499,7 +502,6 @@ /** * Build JSON objects based on existing lesson-level groups. */ - @SuppressWarnings("unchecked") private JSONArray getLessonGroupsDetails(Set groups, Collection learners) throws JSONException { // serialize database group objects into JSON JSONArray groupsJSON = new JSONArray(); @@ -513,7 +515,7 @@ groupJSON.put("groupId", group.getGroupId()); groupJSON.put("locked", !group.mayBeDeleted()); if (group.getUsers() != null) { - for (User groupUser : (Set) group.getUsers()) { + for (User groupUser : group.getUsers()) { JSONObject groupUserJSON = WebUtil.userToJSON(groupUser); groupJSON.append("users", groupUserJSON); @@ -565,9 +567,11 @@ @SuppressWarnings("unchecked") private Grouping getLessonGrouping(HttpServletRequest request, Long activityID, boolean allowDefault) { if (activityID != null) { - GroupingActivity groupingActivity = (GroupingActivity) getUserManagementService().findById( - GroupingActivity.class, activityID); - Grouping grouping = groupingActivity.getCreateGrouping(); + // we need to fetch real objects instead of stubs/proxies + Activity activity = (Activity) getUserManagementService().findById(Activity.class, activityID); + Grouping grouping = activity.isChosenBranchingActivity() ? activity.getGrouping() + : ((GroupingActivity) getUserManagementService().findById(GroupingActivity.class, activityID)) + .getCreateGrouping(); if ((grouping != null) && (grouping.getGroups() != null)) { Set groups = grouping.getGroups(); @@ -576,8 +580,8 @@ request.setAttribute(GroupingAJAXAction.PARAM_USED_FOR_BRANCHING, isUsedForBranching); // check if it is immutable (for branching) or default groups are allowed - return !groups.isEmpty() && (isUsedForBranching || allowDefault || !isDefaultChosenGrouping(grouping)) ? grouping - : null; + return !groups.isEmpty() && (isUsedForBranching || allowDefault || !isDefaultChosenGrouping(grouping)) + ? grouping : null; } } @@ -610,8 +614,8 @@ private IUserManagementService getUserManagementService() { if (OrganisationGroupAction.userManagementService == null) { - WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() - .getServletContext()); + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); OrganisationGroupAction.userManagementService = (IUserManagementService) ctx .getBean("userManagementService"); } @@ -620,26 +624,26 @@ private ILessonService getLessonService() { if (OrganisationGroupAction.lessonService == null) { - WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() - .getServletContext()); + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); OrganisationGroupAction.lessonService = (ILessonService) ctx.getBean("lessonService"); } return OrganisationGroupAction.lessonService; } private ISecurityService getSecurityService() { if (OrganisationGroupAction.securityService == null) { - WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() - .getServletContext()); + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); OrganisationGroupAction.securityService = (ISecurityService) ctx.getBean("securityService"); } return OrganisationGroupAction.securityService; } - + private IIntegrationService getIntegrationService() { if (OrganisationGroupAction.integrationService == null) { - WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet() - .getServletContext()); + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); OrganisationGroupAction.integrationService = (IIntegrationService) ctx.getBean("integrationService"); } return OrganisationGroupAction.integrationService; Index: lams_central/web/includes/javascript/orgGroup.js =================================================================== diff -u -rb5919685d81c48894cb5db96116d7238f49da22b -rab2e2241e9bfa93bad93f8908850405d124daaa5 --- lams_central/web/includes/javascript/orgGroup.js (.../orgGroup.js) (revision b5919685d81c48894cb5db96116d7238f49da22b) +++ lams_central/web/includes/javascript/orgGroup.js (.../orgGroup.js) (revision ab2e2241e9bfa93bad93f8908850405d124daaa5) @@ -324,7 +324,7 @@ dataType : 'json', url : LAMS_URL + 'monitoring/grouping.do', data : { - 'method' : 'removeGroupJSON', + 'method' : 'removeGroup', 'activityID' : groupingActivityId, 'groupID' : groupId }, @@ -357,7 +357,7 @@ cache : false, url : LAMS_URL + 'monitoring/grouping.do', data : { - 'method' : 'changeGroupNameJSON', + 'method' : 'changeGroupName', 'groupID' : groupId, 'name' : groupName }, @@ -458,7 +458,7 @@ dataType : 'json', url : LAMS_URL + 'monitoring/grouping.do', data : { - 'method' : 'addMembersJSON', + 'method' : 'addMembers', 'activityID' : groupingActivityId, 'groupID' : groupId, 'name' : groupName, Index: lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch2040056.sql =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch2040056.sql (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch2040056.sql (revision ab2e2241e9bfa93bad93f8908850405d124daaa5) @@ -0,0 +1,8 @@ +-- Turn off autocommit, so nothing is committed if there is an error +SET AUTOCOMMIT = 0; + +-- LDEV-3707 Use Flashless chosen grouping Monitoring interface +UPDATE lams_system_tool SET contribute_url = 'monitoring/grouping.do?method=startGrouping' WHERE tool_display_name = 'Monitor Chosen Branching'; + +COMMIT; +SET AUTOCOMMIT = 1; \ No newline at end of file Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/monitoringApplicationContext.xml =================================================================== diff -u -r5e63656a12c02f7476564e278b43ff4ce86ac930 -rab2e2241e9bfa93bad93f8908850405d124daaa5 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/monitoringApplicationContext.xml (.../monitoringApplicationContext.xml) (revision 5e63656a12c02f7476564e278b43ff4ce86ac930) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/monitoringApplicationContext.xml (.../monitoringApplicationContext.xml) (revision ab2e2241e9bfa93bad93f8908850405d124daaa5) @@ -75,6 +75,7 @@ PROPAGATION_REQUIRED PROPAGATION_REQUIRED PROPAGATION_REQUIRED,readOnly + PROPAGATION_REQUIRED Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java =================================================================== diff -u -r5e63656a12c02f7476564e278b43ff4ce86ac930 -rab2e2241e9bfa93bad93f8908850405d124daaa5 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision 5e63656a12c02f7476564e278b43ff4ce86ac930) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringService.java (.../IMonitoringService.java) (revision ab2e2241e9bfa93bad93f8908850405d124daaa5) @@ -603,16 +603,9 @@ throws LessonServiceException; /** - * Add learners to a branch. Doesn't necessarily check if the user is already in another branch. Assumes there - * should only be one group for this branch. Use for Teacher Chosen Branching. Don't use for Group Based Branching - * as there could be more than one group for the branch. - * - * @param sequenceActivityID - * Activity id of the sequenceActivity representing this branch - * @param learnerIDs - * the IDS of the learners to be added. + * Creates groups for branches, if they do not already exist. */ - void addUsersToBranch(Long sequenceActivityID, String learnerIDs[]) throws LessonServiceException; + void createChosenBranchingGroups(Long branchingActivityID); /** * Remove learners from a branch. Assumes there should only be one group for this branch. Use for Teacher Chosen Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java =================================================================== diff -u -r90845b9a3eb85240233e6f57923dd0e3fa40e93c -rab2e2241e9bfa93bad93f8908850405d124daaa5 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 90845b9a3eb85240233e6f57923dd0e3fa40e93c) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision ab2e2241e9bfa93bad93f8908850405d124daaa5) @@ -2128,7 +2128,7 @@ @Override public void addUsersToGroup(Long activityID, Long groupId, String learnerIDs[]) throws LessonServiceException { Activity activity = getActivityById(activityID); - Grouping grouping = getGroupingForActivity(activity, true, "addUsersToGroup"); + Grouping grouping = getGroupingForActivity(activity, !activity.isChosenBranchingActivity(), "addUsersToGroup"); ArrayList learners = createUserList(activityID, learnerIDs, "add"); lessonService.performGrouping(grouping, groupId, learners); } @@ -2156,59 +2156,33 @@ return learners; } + @SuppressWarnings("unchecked") @Override - public void addUsersToBranch(Long sequenceActivityID, String learnerIDs[]) throws LessonServiceException { - - SequenceActivity branch = (SequenceActivity) getActivityById(sequenceActivityID); - if (branch == null) { - String error = "addUsersToBranch: Branch missing. ActivityID was " + sequenceActivityID; - MonitoringService.log.error(error); - throw new MonitoringServiceException(error); - } - - Group group = branch.getSoleGroupForBranch(); - Grouping grouping = null; - if (group == null) { - // create a new group and a matching mapping entry - Activity parentActivity = branch.getParentActivity(); - if ((parentActivity == null) || !parentActivity.isBranchingActivity()) { - String error = "addUsersToBranch: Branching activity missing or not a branching activity. Branch was " - + branch + " parent activity was " + parentActivity; - MonitoringService.log.error(error); - throw new MonitoringServiceException(error); - } - BranchingActivity branchingActivity = (BranchingActivity) getActivityById(parentActivity.getActivityId()); - grouping = branchingActivity.getGrouping(); - - // Need the learning design to get the next uiid - which is needed - // if - // Live Edit is done, or Flash can't match the branch to the groups - // properly. + public void createChosenBranchingGroups(Long branchingActivityID) { + BranchingActivity branchingActivity = (BranchingActivity) getActivityById(branchingActivityID); + Grouping grouping = branchingActivity.getGrouping(); + if (grouping.getGroups().isEmpty()) { LearningDesign design = branchingActivity.getLearningDesign(); - - group = lessonService.createGroup(grouping, branch.getTitle()); - groupingDAO.insert(group); - Integer nextUIID = new Integer(design.getMaxID().intValue() + 1); - group.setGroupUIID(nextUIID); - nextUIID = new Integer(nextUIID.intValue() + 1); - group.allocateBranchToGroup(nextUIID, branch, branchingActivity); - groupingDAO.update(group); - - design.setMaxID(new Integer(nextUIID.intValue() + 1)); + for (Activity childActivity : (Set) branchingActivity.getActivities()) { + SequenceActivity branch = (SequenceActivity) getActivityById(childActivity.getActivityId()); + Group group = lessonService.createGroup(grouping, branch.getTitle()); + groupingDAO.insert(group); + Integer nextUIID = design.getMaxID() + 1; + group.setGroupUIID(nextUIID); + nextUIID++; + group.allocateBranchToGroup(nextUIID, branch, branchingActivity); + groupingDAO.update(group); + design.setMaxID(nextUIID); + } learningDesignDAO.update(design); - - } else { - grouping = group.getGrouping(); } - - ArrayList learners = createUserList(sequenceActivityID, learnerIDs, "add"); - lessonService.performGrouping(grouping, group.getGroupId(), learners); } @Override public void removeUsersFromGroup(Long activityID, Long groupId, String learnerIDs[]) throws LessonServiceException { Activity activity = getActivityById(activityID); - Grouping grouping = getGroupingForActivity(activity, true, "removeUsersFromGroup"); + Grouping grouping = getGroupingForActivity(activity, !activity.isChosenBranchingActivity(), + "removeUsersFromGroup"); ArrayList learners = createUserList(activityID, learnerIDs, "remove"); lessonService.removeLearnersFromGroup(grouping, groupId, learners); } Fisheye: Tag ab2e2241e9bfa93bad93f8908850405d124daaa5 refers to a dead (removed) revision in file `lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/ChosenBranchingAJAXAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GroupingAJAXAction.java =================================================================== diff -u -r0b087f6386e7e8cfd72dd34e3eec37533cb97d5f -rab2e2241e9bfa93bad93f8908850405d124daaa5 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GroupingAJAXAction.java (.../GroupingAJAXAction.java) (revision 0b087f6386e7e8cfd72dd34e3eec37533cb97d5f) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GroupingAJAXAction.java (.../GroupingAJAXAction.java) (revision ab2e2241e9bfa93bad93f8908850405d124daaa5) @@ -25,38 +25,29 @@ package org.lamsfoundation.lams.monitoring.web; import java.io.IOException; -import java.util.ArrayList; import java.util.Iterator; import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; import org.apache.commons.lang.StringUtils; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.tomcat.util.json.JSONException; import org.apache.tomcat.util.json.JSONObject; +import org.lamsfoundation.lams.learningdesign.Activity; import org.lamsfoundation.lams.learningdesign.Group; -import org.lamsfoundation.lams.learningdesign.GroupComparator; import org.lamsfoundation.lams.learningdesign.Grouping; import org.lamsfoundation.lams.learningdesign.GroupingActivity; import org.lamsfoundation.lams.lesson.service.LessonServiceException; import org.lamsfoundation.lams.monitoring.service.IMonitoringService; -import org.lamsfoundation.lams.monitoring.service.MonitoringServiceException; import org.lamsfoundation.lams.monitoring.service.MonitoringServiceProxy; import org.lamsfoundation.lams.usermanagement.User; -import org.lamsfoundation.lams.usermanagement.dto.UserDTO; -import org.lamsfoundation.lams.usermanagement.util.LastNameAlphabeticComparator; -import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.action.LamsDispatchAction; -import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; /** @@ -86,62 +77,46 @@ private static final String PARAM_ACTIVITY_DESCRIPTION = "description"; public static final String PARAM_MAX_NUM_GROUPS = "maxNumberOfGroups"; public static final String PARAM_NAME = "name"; - public static final String PARAM_GROUPS = "groups"; public static final String PARAM_MEMBERS = "members"; public static final String PARAM_MAY_DELETE = "mayDelete"; public static final String PARAM_USED_FOR_BRANCHING = "usedForBranching"; - public static final String PARAM_MODULE_LANGUAGE_XML = "languageXML"; public static final String PARAM_VIEW_MODE = "viewMode"; - private Integer getUserId(HttpServletRequest request) { - HttpSession ss = SessionManager.getSession(); - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - return user != null ? user.getUserID() : null; - } - - private Grouping getGrouping(GroupingActivity activity) { - Grouping grouping = activity.getCreateGrouping(); - if (grouping == null) { - String error = "Grouping activity missing grouping. Activity was " + activity + " Grouping was " + grouping; - LamsDispatchAction.log.error(error); - throw new MonitoringServiceException(error); - } - return grouping; - } - /** * Start the process of doing the chosen grouping * * Input parameters: activityID */ + @SuppressWarnings("unchecked") public ActionForward startGrouping(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); - IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet() - .getServletContext()); - GroupingActivity activity = monitoringService.getGroupingActivityById(activityID); - Grouping grouping = activity.getCreateGrouping(); - if (grouping == null) { - String error = "Grouping activity missing grouping. Activity was " + activity; - LamsDispatchAction.log.error(error); - throw new MonitoringServiceException(error); + IMonitoringService monitoringService = MonitoringServiceProxy + .getMonitoringService(getServlet().getServletContext()); + Activity activity = monitoringService.getActivityById(activityID); + + Grouping grouping = null; + if (activity.isChosenBranchingActivity()) { + grouping = activity.getGrouping(); + monitoringService.createChosenBranchingGroups(activityID); + } else { + grouping = ((GroupingActivity) activity).getCreateGrouping(); } request.setAttribute(AttributeNames.PARAM_ACTIVITY_ID, activityID); request.setAttribute(AttributeNames.PARAM_LESSON_ID, lessonId); request.setAttribute(GroupingAJAXAction.PARAM_ACTIVITY_TITLE, activity.getTitle()); request.setAttribute(GroupingAJAXAction.PARAM_ACTIVITY_DESCRIPTION, activity.getDescription()); - request.setAttribute(GroupingAJAXAction.PARAM_MODULE_LANGUAGE_XML, getLanguageXML()); if (grouping.isChosenGrouping()) { // can I remove groups/users - can't if tool sessions have been created - Set groups = grouping.getGroups(); - Iterator iter = groups.iterator(); + Set groups = grouping.getGroups(); + Iterator iter = groups.iterator(); boolean mayDelete = true; while (mayDelete && iter.hasNext()) { - Group group = (Group) iter.next(); + Group group = iter.next(); mayDelete = group.mayBeDeleted(); } @@ -169,350 +144,6 @@ } /** - * Get a list of group names and the number of users in each group. Designed to respond to an AJAX call. - * - * Input parameters: activityID - * - * Output format: "groupid,name,num users;groupid,name,num users" - */ - public ActionForward getGroups(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - - // get the grouping data and sort it. - Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); - IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet() - .getServletContext()); - GroupingActivity activity = monitoringService.getGroupingActivityById(activityID); - Grouping grouping = getGrouping(activity); - Set sortedGroups = new TreeSet(new GroupComparator()); - sortedGroups.addAll(grouping.getGroups()); - - String groupOutput = buildGroupsStringXML(sortedGroups); - writeAJAXResponse(response, groupOutput); - return null; - } - - /** - * Get a list of all the class members who aren't grouped yet. Designed to respond to an AJAX call. - * - * Input parameters: activityID - * - * Output format: "groupid,name,num users;groupid,name,num users" - */ - public ActionForward getClassMembersNotGrouped(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - - // get the grouping data and sort it. - Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); - Long lessonID = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); - IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet() - .getServletContext()); - SortedSet users = monitoringService.getClassMembersNotGrouped(lessonID, activityID, true); - String groupOutput = buildUserStringXML(-1, users); - writeAJAXResponse(response, groupOutput); - return null; - - } - - /** - * Get a list of group names and the number of users in each group. Designed to respond to an AJAX call. - * - * Input parameters: activityID, groupID - * - * Output format: "userid,lastname,firstname;" - */ - public ActionForward getGroupMembers(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { - - // TODO optimise this call - we don't really need the activity and the grouping - go straight to the group in - // the db - // get the group, and from there the user data and sort the user data. - Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); - Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID); - IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet() - .getServletContext()); - GroupingActivity activity = monitoringService.getGroupingActivityById(activityID); - Grouping grouping = getGrouping(activity); - Set groups = grouping.getGroups(); - Iterator iter = groups.iterator(); - Group group = null; - while ((group == null) && iter.hasNext()) { - Group candidateGroup = (Group) iter.next(); - if (groupID.equals(candidateGroup.getGroupId())) { - group = candidateGroup; - } - } - if (group == null) { - String error = "Group cannot be found. Activity was " + activity + " Grouping was " + grouping - + " Grouping ID was " + groupID; - LamsDispatchAction.log.error(error); - throw new MonitoringServiceException(error); - } - - Set users = group.getUsers(); - SortedSet sortedUsers = new TreeSet(new LastNameAlphabeticComparator()); - sortedUsers.addAll(users); - String userOutput = buildUserStringXML(groupID, sortedUsers); - writeAJAXResponse(response, userOutput); - return null; - } - - /** - * Output format: "userid,lastname,firstname;" - * - * @param sortedUsers - * @return String of users - */ - private String buildUserString(SortedSet sortedUsers) { - String userOutput = ""; - boolean first = true; - for (User user : sortedUsers) { - Integer userID = user.getUserId(); - String lastName = user.getLastName(); - String firstName = user.getFirstName(); - if (!first) { - userOutput = userOutput + ";"; - } else { - first = false; - } - userOutput = userOutput + userID + "," + lastName + "," + firstName; - } - return userOutput; - } - - /** - * @param sortedUsers - * @return String of users - */ - private String buildUserStringXML(long groupId, SortedSet sortedUsers) { - String userOutput = ""; - userOutput += "" + groupId + ""; - userOutput += ""; - for (User user : sortedUsers) { - Integer userID = user.getUserId(); - String lastName = user.getLastName(); - String firstName = user.getFirstName(); - - userOutput += ""; - userOutput += "" + userID + ""; - userOutput += "" + firstName + ""; - userOutput += "" + lastName + ""; - userOutput += "" + firstName + " " + lastName + ""; - userOutput += ""; - } - userOutput += ""; - return userOutput; - } - - /** - * @param sortedGroups - * @return String of groups - */ - private String buildGroupsString(Set sortedGroups) { - String groupOutput = ""; - - boolean first = true; - for (Group group : sortedGroups) { - Long groupId = group.getGroupId(); - String name = group.getGroupName(); - Integer numberOfMembers = group.getUsers().size(); - if (!first) { - groupOutput = groupOutput + ";"; - } else { - first = false; - } - groupOutput = groupOutput + groupId + "," + name + "," + numberOfMembers; - } - - return groupOutput; - } - - /** - * @param sortedGroups - * @return String of groups - */ - private String buildGroupsStringXML(Set sortedGroups) { - String groupOutput = ""; - for (Group group : sortedGroups) { - Long groupId = group.getGroupId(); - String name = group.getGroupName(); - Integer numberOfMembers = group.getUsers().size(); - - groupOutput += ""; - groupOutput += "" + groupId + ""; - groupOutput += "" + name + ""; - groupOutput += "" + numberOfMembers + ""; - groupOutput += ""; - } - groupOutput += ""; - - return groupOutput; - } - - /** - * @param group - * @return String of xml with group added - */ - private String buildAddGroupStringXML(Group group) { - String groupOutput = ""; - groupOutput += "" + group.getGroupId() + ""; - groupOutput += "" + group.getGroupName() + ""; - groupOutput += ""; - return groupOutput; - } - - /** - * @param group - * @return String of xml with group added - */ - private String buildRemoveGroupStringXML(Long groupID) { - String groupOutput = ""; - groupOutput += "" + groupID + ""; - groupOutput += ""; - return groupOutput; - } - - /** - * @param group - * @return String of xml with group added - */ - private String buildChangeGroupNameStringXML(Long groupID, String name) { - String groupOutput = ""; - groupOutput += "" + groupID + ""; - groupOutput += "" + name + ""; - groupOutput += ""; - return groupOutput; - } - - /** - * @return String of xml with all needed language elements - */ - private String getLanguageXML() { - IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet() - .getServletContext()); - MessageService messageService = monitoringService.getMessageService(); - ArrayList languageCollection = new ArrayList(); - languageCollection.add(new String("button.finished")); - languageCollection.add(new String("label.grouping.non.grouped.users.heading")); - languageCollection.add(new String("label.grouping.status")); - languageCollection.add(new String("label.grouping.functions")); - languageCollection.add(new String("label.grouping.popup.change.group.name")); - languageCollection.add(new String("label.grouping.popup.change.group.name.field")); - languageCollection.add(new String("label.grouping.learners")); - languageCollection.add(new String("label.grouping.popup.delete.group")); - languageCollection.add(new String("label.grouping.popup.delete.group.message")); - languageCollection.add(new String("button.ok")); - languageCollection.add(new String("button.cancel")); - languageCollection.add(new String("button.yes")); - languageCollection.add(new String("button.no")); - languageCollection.add(new String("error.title")); - languageCollection.add(new String("label.grouping.max.num.in.group.heading")); - languageCollection.add(new String("label.grouping.popup.drag.selection.message")); - languageCollection.add(new String("label.grouping.general.instructions.branching")); - languageCollection.add(new String("label.grouping.popup.viewmode.message")); - - String languageOutput = ""; - - for (int i = 0; i < languageCollection.size(); i++) { - languageOutput += "" - + messageService.getMessage(languageCollection.get(i)) + ""; - } - - languageOutput += ""; - - return languageOutput; - } - - /** - * Add a new group. Designed to respond to an AJAX call. If the teacher wants to add more groups than the number of - * groups set in authoring, and this grouping isn't used for branching then reset the max number of groups to avoid - * that validation. - * - * Input parameters: activityID, name (group name) - * - * Output format: no data returned - just the header - */ - public ActionForward addGroup(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException, LessonServiceException { - - Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); - String name = WebUtil.readStrParam(request, GroupingAJAXAction.PARAM_NAME); - IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet() - .getServletContext()); - Group group = monitoringService.addGroup(activityID, name, true); - String groupResponse = buildAddGroupStringXML(group); - writeAJAXResponse(response, groupResponse); - return null; - } - - /** - * Remove a group. Cannot remove the group if it is in use (tool session ids exist). Designed to respond to an AJAX - * call. - * - * Input parameters: activityID, name: group name - * - * Output format: no data returned - just the header - */ - public ActionForward removeGroup(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException, LessonServiceException { - - Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); - Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID); - - IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet() - .getServletContext()); - monitoringService.removeGroup(activityID, groupID); - String responseString = buildRemoveGroupStringXML(groupID); - writeAJAXResponse(response, responseString); - return null; - } - - /** - * Add learners to a group. Designed to respond to an AJAX call. - * - * Input parameters: activityID, name: group name, members: comma separated list of users - * - * Output format: no data returned - just the header - */ - public ActionForward addMembers(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException, LessonServiceException { - - Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); - Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID); - String members = WebUtil.readStrParam(request, GroupingAJAXAction.PARAM_MEMBERS, true); - if (members != null) { - String[] membersSplit = members.split(","); - IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet() - .getServletContext()); - monitoringService.addUsersToGroup(activityID, groupID, membersSplit); - } - writeAJAXOKResponse(response); - return null; - } - - /** - * Add learners to a group. Designed to respond to an AJAX call. - * - * Input parameters: activityID, name: group name, members: comma separated list of users - * - * Output format: no data returned - just the header - */ - public ActionForward changeGroupName(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException, LessonServiceException { - - Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID); - String name = WebUtil.readStrParam(request, GroupingAJAXAction.PARAM_NAME, true); - if (name != null) { - IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet() - .getServletContext()); - monitoringService.setGroupName(groupID, name); - } - String reponseSting = buildChangeGroupNameStringXML(groupID, name); - writeAJAXResponse(response, reponseSting); - return null; - } - - /** * Remove a list of users from a group. Designed to respond to an AJAX call. * * Input parameters: activityID, name: group name, members: comma separated list of users @@ -527,8 +158,8 @@ String members = WebUtil.readStrParam(request, GroupingAJAXAction.PARAM_MEMBERS, true); if (members != null) { String[] membersSplit = members.split(","); - IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet() - .getServletContext()); + IMonitoringService monitoringService = MonitoringServiceProxy + .getMonitoringService(getServlet().getServletContext()); monitoringService.removeUsersFromGroup(activityID, groupID, membersSplit); } writeAJAXOKResponse(response); @@ -538,7 +169,7 @@ /** * Moves users between groups, removing them from previous group and creating a new one, if needed. */ - public ActionForward addMembersJSON(ActionMapping mapping, ActionForm form, HttpServletRequest request, + public ActionForward addMembers(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws JSONException, IOException { response.setContentType("application/json;charset=utf-8"); JSONObject responseJSON = new JSONObject(); @@ -549,11 +180,12 @@ String[] members = StringUtils.isBlank(membersParam) ? null : membersParam.split(","); // remove users from current group - IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet() - .getServletContext()); + IMonitoringService monitoringService = MonitoringServiceProxy + .getMonitoringService(getServlet().getServletContext()); if (members != null) { - GroupingActivity groupingActivity = monitoringService.getGroupingActivityById(activityID); - Grouping grouping = groupingActivity.getCreateGrouping(); + Activity activity = monitoringService.getActivityById(activityID); + Grouping grouping = activity.isChosenBranchingActivity() ? activity.getGrouping() + : ((GroupingActivity) activity).getCreateGrouping(); User exampleUser = (User) MonitoringServiceProxy.getUserManagementService(getServlet().getServletContext()) .findById(User.class, Integer.valueOf(members[0])); Group group = grouping.getGroupBy(exampleUser); @@ -582,7 +214,7 @@ } } } - + Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID, true); // no group ID means that it has to be created // group ID = -1 means that user is not being assigned to any new group, i.e. becomse unassigned @@ -603,7 +235,7 @@ } } - if (result && members != null) { + if (result && (members != null)) { if (LamsDispatchAction.log.isDebugEnabled()) { LamsDispatchAction.log.debug("Adding users " + membersParam.toString() + " to group " + groupID + " in activity " + activityID); @@ -627,16 +259,16 @@ /** * Renames the group. */ - public ActionForward changeGroupNameJSON(ActionMapping mapping, ActionForm form, HttpServletRequest request, + public ActionForward changeGroupName(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID); String name = WebUtil.readStrParam(request, GroupingAJAXAction.PARAM_NAME); if (name != null) { if (LamsDispatchAction.log.isDebugEnabled()) { LamsDispatchAction.log.debug("Renaming group " + groupID + " to \"" + name + "\""); } - IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet() - .getServletContext()); + IMonitoringService monitoringService = MonitoringServiceProxy + .getMonitoringService(getServlet().getServletContext()); monitoringService.setGroupName(groupID, name); } return null; @@ -645,13 +277,13 @@ /** * Checks if a group can be removed and performs it. */ - public ActionForward removeGroupJSON(ActionMapping mapping, ActionForm form, HttpServletRequest request, + public ActionForward removeGroup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws JSONException, IOException { response.setContentType("application/json;charset=utf-8"); Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); Long groupID = WebUtil.readLongParam(request, AttributeNames.PARAM_GROUP_ID); - IMonitoringService monitoringService = MonitoringServiceProxy.getMonitoringService(getServlet() - .getServletContext()); + IMonitoringService monitoringService = MonitoringServiceProxy + .getMonitoringService(getServlet().getServletContext()); boolean result = true; // check if the group can be removed Fisheye: Tag ab2e2241e9bfa93bad93f8908850405d124daaa5 refers to a dead (removed) revision in file `lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/PerformChosenGroupingServlet.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_monitoring/web/WEB-INF/web.xml =================================================================== diff -u -r5e63656a12c02f7476564e278b43ff4ce86ac930 -rab2e2241e9bfa93bad93f8908850405d124daaa5 --- lams_monitoring/web/WEB-INF/web.xml (.../web.xml) (revision 5e63656a12c02f7476564e278b43ff4ce86ac930) +++ lams_monitoring/web/WEB-INF/web.xml (.../web.xml) (revision ab2e2241e9bfa93bad93f8908850405d124daaa5) @@ -75,11 +75,6 @@ - performChosenGrouping - org.lamsfoundation.lams.monitoring.web.PerformChosenGroupingServlet - - - initializeLesson org.lamsfoundation.lams.monitoring.web.InitializeLessonServlet @@ -113,10 +108,6 @@ - performChosenGrouping - /monitoring/performChosenGrouping - - initializeLesson /initializeLesson Index: lams_monitoring/web/branching/BranchManager.swf =================================================================== diff -u -r12450cbea53946ad074ec52d10f5e94ae207e1f9 -rab2e2241e9bfa93bad93f8908850405d124daaa5 Binary files differ Fisheye: Tag ab2e2241e9bfa93bad93f8908850405d124daaa5 refers to a dead (removed) revision in file `lams_monitoring/web/branching/chosenSelection.jsp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag ab2e2241e9bfa93bad93f8908850405d124daaa5 refers to a dead (removed) revision in file `lams_monitoring/web/branching/groupedSelection.jsp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag ab2e2241e9bfa93bad93f8908850405d124daaa5 refers to a dead (removed) revision in file `lams_monitoring/web/branching/viewBranches.jsp'. Fisheye: No comparison available. Pass `N' to diff?