Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java =================================================================== diff -u -rfd131067cd0d56f83e3f9675277248bca41e259e -r11403ed5085a73344f4cea2b7d3677115c6f2150 --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (.../ILessonService.java) (revision fd131067cd0d56f83e3f9675277248bca41e259e) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/ILessonService.java (.../ILessonService.java) (revision 11403ed5085a73344f4cea2b7d3677115c6f2150) @@ -23,11 +23,6 @@ package org.lamsfoundation.lams.lesson.service; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Set; - import org.lamsfoundation.lams.index.IndexLessonBean; import org.lamsfoundation.lams.learningdesign.Activity; import org.lamsfoundation.lams.learningdesign.Group; @@ -39,6 +34,11 @@ import org.lamsfoundation.lams.lesson.dto.LessonDetailsDTO; import org.lamsfoundation.lams.usermanagement.User; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + /** * Access the general lesson details and access to grouping. * @@ -163,7 +163,7 @@ * @param grouping * the object on which to perform the grouing. (mandatory) */ - void performGrouping(Grouping grouping, Long groupId, List learners) throws LessonServiceException; + void performGrouping(Grouping grouping, Long groupId, List learners, boolean forceChosenGrouping) throws LessonServiceException; /** * Perform grouping for the given learner. Index: lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java =================================================================== diff -u -rfd131067cd0d56f83e3f9675277248bca41e259e -r11403ed5085a73344f4cea2b7d3677115c6f2150 --- lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision fd131067cd0d56f83e3f9675277248bca41e259e) +++ lams_common/src/java/org/lamsfoundation/lams/lesson/service/LessonService.java (.../LessonService.java) (revision 11403ed5085a73344f4cea2b7d3677115c6f2150) @@ -23,19 +23,11 @@ package org.lamsfoundation.lams.lesson.service; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - import org.apache.log4j.Logger; import org.lamsfoundation.lams.dao.IBaseDAO; import org.lamsfoundation.lams.index.IndexLessonBean; import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.ChosenGrouper; import org.lamsfoundation.lams.learningdesign.Group; import org.lamsfoundation.lams.learningdesign.Grouper; import org.lamsfoundation.lams.learningdesign.Grouping; @@ -61,13 +53,24 @@ import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.util.MessageService; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + /** * Access the general lesson details. * * A lesson has three different "lists" of learners. *
    - *
  1. The learners who are in the learner group attached to the lesson. This is fixed when the lesson is started and is - * a list of all the learners who could ever participate in to the lesson. This is available via lesson.getAllLearners() + *
  2. The learners who are in the learner group attached to the lesson. This is fixed when the lesson is started and + * is + * a list of all the learners who could ever participate in to the lesson. This is available via + * lesson.getAllLearners() *
  3. The learners who have started the lesson. They may or may not be logged in currently, or if they are logged in * they may or may not be doing this lesson. This is available via getActiveLessonLearners(). *
@@ -76,7 +79,6 @@ * the functionality at present. If this is required later it should be combined with the user's shared session logic * and will need to purge users who haven't done anything for a while - otherwise a user whose PC has crashed and then * never returns to a lesson will staying in the cache forever. - * */ public class LessonService implements ILessonService { private static Logger log = Logger.getLogger(LessonService.class); @@ -191,8 +193,9 @@ } } else { - String error = "The method performGrouping supports only grouping methods where the grouper decides the groups (currently only RandomGrouping). Called with a groupingActivity with the wrong grouper " - + groupingActivity.getActivityId(); + String error = + "The method performGrouping supports only grouping methods where the grouper decides the groups (currently only RandomGrouping). Called with a groupingActivity with the wrong grouper " + + groupingActivity.getActivityId(); LessonService.log.error(error); throw new LessonServiceException(error); } @@ -246,9 +249,10 @@ } @Override - public void performGrouping(Grouping grouping, Long groupId, List learners) throws LessonServiceException { + public void performGrouping(Grouping grouping, Long groupId, List learners, boolean forceChosenGrouping) + throws LessonServiceException { if (grouping != null) { - Grouper grouper = grouping.getGrouper(); + Grouper grouper = forceChosenGrouping ? new ChosenGrouper() : grouping.getGrouper(); if (grouper != null) { grouper.setCommonMessageService(messageService); try { @@ -259,8 +263,9 @@ groupingDAO.update(grouping); } } else { - String error = "The method performChosenGrouping supports only grouping methods where the supplied list should be used as a single group (currently only ChosenGrouping). Called with a grouping with the wrong grouper " - + grouping; + String error = + "The method performChosenGrouping supports only grouping methods where the supplied list should be used as a single group (currently only ChosenGrouping). Called with a grouping with the wrong grouper " + + grouping; LessonService.log.error(error); throw new LessonServiceException(error); } @@ -466,8 +471,8 @@ int numberOfLearners = lessonClass.setLearners(users); lessonClassDAO.updateLessonClass(lessonClass); if (LessonService.log.isDebugEnabled()) { - LessonService.log - .debug("Set " + numberOfLearners + " learners in lessonClass " + lessonClass.getGroupingId()); + LessonService.log.debug( + "Set " + numberOfLearners + " learners in lessonClass " + lessonClass.getGroupingId()); } } @@ -546,8 +551,8 @@ lessonClassDAO.updateLessonClass(lessonClass); } if (LessonService.log.isDebugEnabled()) { - LessonService.log - .debug("Added " + numAdded + " staff members to lessonClass " + lessonClass.getGroupingId()); + LessonService.log.debug( + "Added " + numAdded + " staff members to lessonClass " + lessonClass.getGroupingId()); } } @@ -557,8 +562,8 @@ int numberOfStaff = lessonClass.setStaffMembers(users); lessonClassDAO.updateLessonClass(lessonClass); if (LessonService.log.isDebugEnabled()) { - LessonService.log - .debug("Set " + numberOfStaff + " staff members in lessonClass " + lessonClass.getGroupingId()); + LessonService.log.debug( + "Set " + numberOfStaff + " staff members in lessonClass " + lessonClass.getGroupingId()); } } @@ -605,8 +610,8 @@ if (progresses != null) { for (LearnerProgress progress : progresses) { if (LessonService.log.isDebugEnabled()) { - LessonService.log - .debug("Processing learner progress learner " + progress.getUser().getUserId()); + LessonService.log.debug( + "Processing learner progress learner " + progress.getUser().getUserId()); } boolean recordUpdated = false; @@ -724,8 +729,8 @@ Boolean lessonCompleted = (Boolean) tuple[4]; lessonCompleted = lessonCompleted == null ? false : lessonCompleted.booleanValue(); Boolean enableLessonNotifications = (Boolean) tuple[5]; - enableLessonNotifications = enableLessonNotifications == null ? false - : enableLessonNotifications.booleanValue(); + enableLessonNotifications = + enableLessonNotifications == null ? false : enableLessonNotifications.booleanValue(); Boolean dependent = (Boolean) tuple[6]; dependent = dependent == null ? false : dependent.booleanValue(); Boolean scheduledFinish = (Boolean) tuple[7]; @@ -805,8 +810,8 @@ Lesson lesson = getLesson(completedLessonId); if (lesson != null) { for (Lesson succeedingLesson : lesson.getSucceedingLessons()) { - if (succeedingLesson.isLessonAccessibleForLearner() - && checkLessonReleaseConditions(succeedingLesson.getLessonId(), learnerId)) { + if (succeedingLesson.isLessonAccessibleForLearner() && checkLessonReleaseConditions( + succeedingLesson.getLessonId(), learnerId)) { releasedSucceedingLessons.add(succeedingLesson); } } Fisheye: Tag 11403ed5085a73344f4cea2b7d3677115c6f2150 refers to a dead (removed) revision in file `lams_common/src/java/org/lamsfoundation/lams/usermanagement/util/ExcelUserImportFileParser.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 11403ed5085a73344f4cea2b7d3677115c6f2150 refers to a dead (removed) revision in file `lams_common/src/java/org/lamsfoundation/lams/usermanagement/util/IUserImportFileParser.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java =================================================================== diff -u -re9e7042e16de3421b8c0cd6b1cf6c59dede544b4 -r11403ed5085a73344f4cea2b7d3677115c6f2150 --- lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision e9e7042e16de3421b8c0cd6b1cf6c59dede544b4) +++ lams_learning/src/java/org/lamsfoundation/lams/learning/service/LearnerService.java (.../LearnerService.java) (revision 11403ed5085a73344f4cea2b7d3677115c6f2150) @@ -23,21 +23,6 @@ package org.lamsfoundation.lams.learning.service; -import java.io.UnsupportedEncodingException; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; - import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.lamsfoundation.lams.gradebook.service.IGradebookService; @@ -99,6 +84,21 @@ import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.MessageService; +import java.io.UnsupportedEncodingException; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + /** * This class is a facade over the Learning middle tier. * @@ -807,7 +807,7 @@ learnerList.add(learner); if (group != null) { if (group.getGroupId() != null) { - lessonService.performGrouping(grouping, group.getGroupId(), learnerList); + lessonService.performGrouping(grouping, group.getGroupId(), learnerList, false); } else { lessonService.performGrouping(grouping, group.getGroupName(), learnerList); } @@ -816,7 +816,7 @@ // if any group exists, put them in there. Group aGroup = grouping.getGroups().iterator().next(); if (aGroup.getGroupId() != null) { - lessonService.performGrouping(grouping, aGroup.getGroupId(), learnerList); + lessonService.performGrouping(grouping, aGroup.getGroupId(), learnerList, false); } else { lessonService.performGrouping(grouping, aGroup.getGroupName(), learnerList); } Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringFullService.java =================================================================== diff -u -r7116e79c883ad42375d9fa3278dec8a84733ea86 -r11403ed5085a73344f4cea2b7d3677115c6f2150 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringFullService.java (.../IMonitoringFullService.java) (revision 7116e79c883ad42375d9fa3278dec8a84733ea86) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/IMonitoringFullService.java (.../IMonitoringFullService.java) (revision 11403ed5085a73344f4cea2b7d3677115c6f2150) @@ -1,12 +1,5 @@ package org.lamsfoundation.lams.monitoring.service; -import java.io.IOException; -import java.util.Collection; -import java.util.Date; -import java.util.List; -import java.util.Set; -import java.util.SortedSet; - import org.lamsfoundation.lams.events.EmailNotificationArchive; import org.lamsfoundation.lams.learningdesign.Activity; import org.lamsfoundation.lams.learningdesign.GateActivity; @@ -21,6 +14,13 @@ import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.util.excel.ExcelSheet; +import java.io.IOException; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Set; +import java.util.SortedSet; + /** * Contains methods intended for internal usage by lams_monitoring. * @@ -39,7 +39,7 @@ * @param userId * @param learnerPresenceAvailable * @return new value for learnerPresenceAvailable. Normally will be same as input parameter, will only be different - * if the value cannot be updated for some reason. + * if the value cannot be updated for some reason. */ Boolean togglePresenceAvailable(long lessonId, Integer userId, Boolean learnerPresenceAvailable); @@ -51,7 +51,7 @@ * @param userId * @param learnerImPresenceAvailable * @return new value for learnerPresenceImAvailable. Normally will be same as input parameter, will only be - * different if the value cannot be updated for some reason. + * different if the value cannot be updated for some reason. */ Boolean togglePresenceImAvailable(long lessonId, Integer userId, Boolean learnerPresenceImAvailable); @@ -65,33 +65,31 @@ * Archive the specified lesson. When archived, the data is retained but the learners cannot access the details. * * @param lessonId - * the specified the lesson id. + * the specified the lesson id. * @param userId - * checks that the user is a staff member for this lesson + * checks that the user is a staff member for this lesson */ void archiveLesson(long lessonId, Integer userId) throws UserAccessDeniedException; /** * Unarchive the specified the lesson. Reverts back to its previous state. * * @param lessonId - * the specified the lesson id. + * the specified the lesson id. */ void unarchiveLesson(long lessonId, Integer userId); /** * Suspend lesson now! A lesson can only be suspended if it is started. The purpose of suspending is to hide the - * lesson from learners - * temporarily. + * lesson from learners temporarily. * * @param lessonId - * the lesson ID which will be suspended. + * the lesson ID which will be suspended. * @param userId - * checks that the user is a staff member for this lesson + * checks that the user is a staff member for this lesson * @param clearScheduleDetails - * should it remove any triggers set up to suspend the lesson and clear the schedule date field. true if - * user suspending right now, - * false if this is being called by the trigger + * should it remove any triggers set up to suspend the lesson and clear the schedule date field. true if user + * suspending right now, false if this is being called by the trigger */ void suspendLesson(long lessonId, Integer userId, boolean removeTriggers) throws UserAccessDeniedException; @@ -101,7 +99,7 @@ * * @param lessonId * @param userId - * checks that the user is a staff member for this lesson + * checks that the user is a staff member for this lesson */ void unsuspendLesson(long lessonId, Integer userId) throws UserAccessDeniedException; @@ -111,7 +109,7 @@ * that the class can be returned to the web layer for proper handling. * * @param gate - * the id of the gate we need to open. + * the id of the gate we need to open. */ GateActivity openGate(Long gateId, Integer openerId); @@ -133,7 +131,7 @@ * Set the gate to closed. * * @param gate - * the id of the gate we need to close. + * the id of the gate we need to close. */ GateActivity closeGate(Long gateId); @@ -144,7 +142,7 @@ * Returns users by search type criteria. It's sorted by first and last user names. * * @param searchType - * one of 11 constants from MonitoringConstants defining search type + * one of 11 constants from MonitoringConstants defining search type * @param lessonId * @param lessonIds * @param activityId @@ -163,13 +161,13 @@ * This is also known as the learner progress url. * * @param lessonID - * The lesson_id of the Lesson for which the information has to be fetched. + * The lesson_id of the Lesson for which the information has to be fetched. * @param activityID - * The activity_id of the activity for which the URL is required + * The activity_id of the activity for which the URL is required * @param learnerID - * The user_id of the Learner for whom the URL is being fetched + * The user_id of the Learner for whom the URL is being fetched * @param requesterID - * The user_id of the user who is requesting the url + * The user_id of the user who is requesting the url * @throws IOException * @throws LamsToolServiceException */ @@ -180,17 +178,18 @@ * This method returns the monitor url for the given activity * * @param lessonID - * The lesson_id of the Lesson for which the information has to be fetched. + * The lesson_id of the Lesson for which the information has to be fetched. * @param activityID - * The activity_id of the Activity whose URL will be returned + * The activity_id of the Activity whose URL will be returned * @param userID - * The user id of the user requesting the url. + * The user id of the user requesting the url. * @throws IOException */ String getActivityMonitorURL(Long lessonID, Long activityID, String contentFolderID, Integer userID) throws IOException, LamsToolServiceException; /* Supports the Chosen Groupings and Branching */ + /** * Get all the active learners in the lesson who are not in a group or in a branch. * @@ -201,7 +200,7 @@ * @param activityID * @param lessonID * @param useCreateGrouping - * true/false for GroupingActivities, always false for non-GroupingActivities + * true/false for GroupingActivities, always false for non-GroupingActivities * @return Sorted set of Users, sorted by surname */ SortedSet getClassMembersNotGrouped(Long lessonID, Long activityID, boolean useCreateGrouping); @@ -215,11 +214,11 @@ * If it is a teacher chosen branching activity and the grouping doesn't exist, it creates one. * * @param activityID - * id of the grouping activity + * id of the grouping activity * @param name - * group name + * group name * @throws LessonServiceException - * , MonitoringServiceException + * , MonitoringServiceException */ abstract Group addGroup(Long activityID, String name, boolean overrideMaxNumberOfGroups) throws LessonServiceException, MonitoringServiceException; @@ -235,9 +234,9 @@ * If it is a teacher chosen branching activity and the grouping doesn't exist, it creates one. * * @param activityID - * id of the grouping activity + * id of the grouping activity * @param name - * group name + * group name * @throws LessonServiceException **/ abstract void removeGroup(Long activityID, Long groupID) throws LessonServiceException; @@ -248,10 +247,11 @@ abstract void addUsersToGroup(Long activityID, Long groupID, String learnerIDs[]) throws LessonServiceException; /** - * Add learners to a group based on their logins. Doesn't necessarily check if the user is already in another group. + * Add learners to a group based on their logins. Doesn't necessarily check if the user is already in another + * group. */ - abstract int addUsersToGroupByLogins(Long activityID, String groupName, Set logins) - throws LessonServiceException; + abstract int addUsersToGroupByLogins(Long activityID, String groupName, Set logins, + boolean forceChosenGrouping) throws LessonServiceException; /** * Remove a user to a group. If the user is not in the group, then nothing is changed. @@ -277,9 +277,9 @@ * Group Based Branching. * * @param sequenceActivityID - * Activity id of the sequenceActivity representing this branch + * Activity id of the sequenceActivity representing this branch * @param learnerIDs - * the IDS of the learners to be added. + * the IDS of the learners to be added. */ void addGroupToBranch(Long sequenceActivityID, String groupIDs[]) throws LessonServiceException; @@ -288,17 +288,17 @@ * based branching in define later. * * @param sequenceActivityID - * Activity id of the sequenceActivity representing this branch + * Activity id of the sequenceActivity representing this branch * @param learnerIDs - * the IDS of the learners to be added. + * the IDS of the learners to be added. */ void removeGroupFromBranch(Long sequenceActivityID, String groupIDs[]) throws LessonServiceException; /** * Get all the groups that exist for the related grouping activity that have not been allocated to a branch. * * @param branchingActivityID - * Activity id of the branchingActivity + * Activity id of the branchingActivity */ SortedSet getGroupsNotAssignedToBranch(Long branchingActivityID) throws LessonServiceException; @@ -345,4 +345,4 @@ List getAllContributeActivityDTO(Long lessonID); -} +} \ No newline at end of file Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java =================================================================== diff -u -rdbbe9d80bcbeda8f746963fcde183242996fcc68 -r11403ed5085a73344f4cea2b7d3677115c6f2150 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision dbbe9d80bcbeda8f746963fcde183242996fcc68) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/service/MonitoringService.java (.../MonitoringService.java) (revision 11403ed5085a73344f4cea2b7d3677115c6f2150) @@ -23,29 +23,8 @@ package org.lamsfoundation.lams.monitoring.service; -import java.io.IOException; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Date; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.SortedSet; -import java.util.TimeZone; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.Vector; - -import javax.servlet.http.HttpSession; - +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -128,8 +107,27 @@ import org.quartz.TriggerBuilder; import org.quartz.TriggerKey; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; +import javax.servlet.http.HttpSession; +import java.io.IOException; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TimeZone; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.Vector; /** *

@@ -2265,6 +2263,9 @@ grouping = activity.getGrouping(); } + // get real object and not proxy + grouping = groupingDAO.getGroupingById(grouping.getGroupingId()); + if (grouping == null) { String error = methodName + ": Grouping activity missing grouping. Activity was " + activity; MonitoringService.log.error(error); @@ -2318,7 +2319,7 @@ Activity activity = getActivityById(activityID); Grouping grouping = getGroupingForActivity(activity, !activity.isChosenBranchingActivity(), "addUsersToGroup"); ArrayList learners = createUserList(activityID, learnerIDs, "add"); - lessonService.performGrouping(grouping, groupId, learners); + lessonService.performGrouping(grouping, groupId, learners, false); } private ArrayList createUserList(Long activityIDForErrorMessage, String[] learnerIDs, @@ -2345,7 +2346,7 @@ } @Override - public int addUsersToGroupByLogins(Long activityID, String groupName, Set logins) + public int addUsersToGroupByLogins(Long activityID, String groupName, Set logins, boolean forceChosenGrouping) throws LessonServiceException { ArrayList learners = new ArrayList<>(); @@ -2376,9 +2377,9 @@ if (group == null) { // Leave performGrouping to create any new groups as addGroup returns a group without an id, so it could not be - // used by performGrouping. Fix up name afterwards. Clumsy way to find to find the new group but how else? + // used by performGrouping. Fix up name afterwards. Clumsy way to find the new group but how else? // It may not be the only new group and hence not the only group with no id. - lessonService.performGrouping(grouping, (Long) null, learners); + lessonService.performGrouping(grouping, (Long) null, learners, forceChosenGrouping); for (Group checkGroup : grouping.getGroups()) { if (!otherGroupNames.contains(checkGroup.getGroupName())) { group = checkGroup; @@ -2389,7 +2390,7 @@ group.setGroupName(groupName); } } else { - lessonService.performGrouping(grouping, group.getGroupId(), learners); + lessonService.performGrouping(grouping, group.getGroupId(), learners, forceChosenGrouping); } return learners.size(); Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GroupingUploadController.java =================================================================== diff -u -rfd131067cd0d56f83e3f9675277248bca41e259e -r11403ed5085a73344f4cea2b7d3677115c6f2150 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GroupingUploadController.java (.../GroupingUploadController.java) (revision fd131067cd0d56f83e3f9675277248bca41e259e) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GroupingUploadController.java (.../GroupingUploadController.java) (revision 11403ed5085a73344f4cea2b7d3677115c6f2150) @@ -23,24 +23,8 @@ package org.lamsfoundation.lams.monitoring.web; -import java.io.IOException; -import java.security.InvalidParameterException; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import java.util.Vector; - -import javax.servlet.ServletOutputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.apache.poi.hssf.usermodel.HSSFCell; @@ -81,8 +65,22 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; -import com.fasterxml.jackson.databind.node.JsonNodeFactory; -import com.fasterxml.jackson.databind.node.ObjectNode; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import java.io.IOException; +import java.security.InvalidParameterException; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.Vector; /** * The action servlet that provides the support for the AJAX based Chosen Grouping upload from File @@ -145,8 +143,9 @@ return; } - String fileName = new StringBuilder(messageService.getMessage("filename.create.grouping.template").trim()) - .append(" ").append(lessonOrOrganisationName).append(".xls").toString().replaceAll(" ", "-"); + String fileName = new StringBuilder( + messageService.getMessage("filename.create.grouping.template").trim()).append(" ") + .append(lessonOrOrganisationName).append(".xls").toString().replaceAll(" ", "-"); fileName = FileUtil.encodeFilenameForDownload(request, fileName); List sheets; @@ -155,16 +154,17 @@ // check for any groups already exist in this grouping Long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); Activity activity = monitoringService.getActivityById(activityId); - Grouping grouping = activity.isChosenBranchingActivity() ? activity.getGrouping() + Grouping grouping = activity.isChosenBranchingActivity() + ? activity.getGrouping() : ((GroupingActivity) activity).getCreateGrouping(); sheets = exportLearnersForGrouping(learners, grouping.getGroups(), null); } else { Long groupingId = WebUtil.readLongParam(request, "groupingId", true); Set groups = null; if (groupingId != null) { - OrganisationGrouping orgGrouping = (OrganisationGrouping) userManagementService - .findById(OrganisationGrouping.class, groupingId); + OrganisationGrouping orgGrouping = (OrganisationGrouping) userManagementService.findById( + OrganisationGrouping.class, groupingId); if (orgGrouping != null) { groups = orgGrouping.getGroups(); } @@ -290,7 +290,8 @@ + " filename " + file); } - ObjectNode responseJSON = isLessonMode ? saveLessonGrouping(lessonId, activityId, file) + ObjectNode responseJSON = isLessonMode + ? saveLessonGrouping(lessonId, activityId, file) : saveCourseGrouping(organisation, groupingId, name, file); return responseJSON.toString(); @@ -371,7 +372,8 @@ // Lesson grouping case so clean out and reuse any existing groups Activity activity = monitoringService.getActivityById(activityId); - Grouping grouping = activity.isChosenBranchingActivity() ? activity.getGrouping() + Grouping grouping = activity.isChosenBranchingActivity() + ? activity.getGrouping() : ((GroupingActivity) activity).getCreateGrouping(); Set existingGroupNames = new HashSet<>(); @@ -440,7 +442,7 @@ // Now put in the new users groupings for (Map.Entry> groupEntry : groups.entrySet()) { int added = monitoringService.addUsersToGroupByLogins(activityId, groupEntry.getKey(), - groupEntry.getValue()); + groupEntry.getValue(), true); totalUsersAdded += added; totalUsersSkipped += groupEntry.getValue().size() - added; } @@ -506,8 +508,9 @@ String groupName = row.getLastCellNum() > 3 ? parseStringCell(row.getCell(3)) : null; if (groupName == null || groupName.length() == 0) { skipped++; - GroupingUploadController.log.warn("Unable to add learner " + login - + " for group in related to grouping " + groupingID + " as group name is missing."); + GroupingUploadController.log.warn( + "Unable to add learner " + login + " for group in related to grouping " + groupingID + + " as group name is missing."); continue; } Set users = groups.get(groupName); @@ -525,4 +528,4 @@ return (UserDTO) ss.getAttribute(AttributeNames.USER); } -} +} \ No newline at end of file