Index: lams_central/web/includes/javascript/main.js =================================================================== diff -u -r6455f6e20efee02e4c447821693548724bb9cf8c -r33308a6a7d7b29a01697f0274baaccbf9dca6bb3 --- lams_central/web/includes/javascript/main.js (.../main.js) (revision 6455f6e20efee02e4c447821693548724bb9cf8c) +++ lams_central/web/includes/javascript/main.js (.../main.js) (revision 33308a6a7d7b29a01697f0274baaccbf9dca6bb3) @@ -363,8 +363,8 @@ function showOrgGroupDialog(url) { $('#dialogOrgGrouping').modal('hide'); showDialog("dialogOrgGroup", { - 'width' : Math.max(380, Math.min(850, $(window).width() - 60)), - 'height': Math.max(380, Math.min(470, $(window).height() - 30)), + 'width' : Math.max(380, Math.min(960, $(window).width() - 60)), + 'height': Math.max(380, Math.min(650, $(window).height() - 30)), 'title' : LABELS.COURSE_GROUPS_TITLE, 'open' : function() { // load contents after opening the dialog Index: lams_central/web/includes/javascript/orgGroup.js =================================================================== diff -u -r092ede3b8b3828ffa688c4db18c5d535e3364b98 -r33308a6a7d7b29a01697f0274baaccbf9dca6bb3 --- lams_central/web/includes/javascript/orgGroup.js (.../orgGroup.js) (revision 092ede3b8b3828ffa688c4db18c5d535e3364b98) +++ lams_central/web/includes/javascript/orgGroup.js (.../orgGroup.js) (revision 33308a6a7d7b29a01697f0274baaccbf9dca6bb3) @@ -1,4 +1,4 @@ -// for user selecting and sorting purposes +// for user selecting and sorting purposes var sortOrderAscending = {}; var lastSelectedUsers = {}; @@ -538,7 +538,7 @@ url += '&activityID='+groupingActivityId; if ( lessonId ) url += '&lessonID='+lessonId; - if ( grouping.groupingId ) + if ( grouping && grouping.groupingId ) url += '&groupingId='+grouping.groupingId; var height = Math.min(550, $(window).height()), width = Math.max(1093, $(window).width()); @@ -571,58 +571,126 @@ } function importGroupsFromSpreadsheet() { + if (!canEdit) { + return false; + } + disableButtons(); var file = getValidateSpreadsheetFile(); if ( file != null && ( ! warnBeforeUpload || confirm(LABELS.WARNING_REPLACE_GROUPS_LABEL) ) ) { var form = $("#uploadForm")[0]; var formDataUpload = new FormData(form); formDataUpload.append("organisationID", organisationId); - $.ajax({ - data: formDataUpload, - processData: false, // tell jQuery not to process the data - contentType: false, // tell jQuery not to set contentType - type: 'POST', - url: form.action, - enctype: "multipart/form-data", - dataType : 'json', - success: function (response) { - if ( response.result != 'OK') { - if ( response.error ) { - alert(response.error); - if ( response.reload ) { - window.location.reload(); // do not have another go, look at new data - } else { - enableButtons(); // let them have another go - } - } - else { - // unknown failure on back end. - alert(LABELS.GENERAL_ERROR_LABEL); - var div = document.getElementById("attachmentArea_Busy"); - if(div != null){ - div.style.display = 'none'; - } - } - } else { - var msg = LABELS.LABEL_IMPORT_SUCCESSFUL_LABEL.replace("%1", response.added).replace("%2", response.skipped); - alert(msg); - window.location.reload(); - } - }, - error: function() { - // unknown failure on back end. - alert(LABELS.GENERAL_ERROR_LABEL); - var div = document.getElementById("attachmentArea_Busy"); - if(div != null){ - div.style.display = 'none'; - } - } - }); + formDataUpload.append("lessonMode", lessonMode); + if ( lessonMode ) { + callImportURL(form, formDataUpload); + + } else if ( grouping && grouping.groupingId ) { + // course grouping - grouping already exists so just upload users + formDataUpload.append("groupingId", grouping.groupingId); + callImportURL(form, formDataUpload); + } else { + // New course grouping. Need to check name okay first. + + $('.errorMessage').hide(); + var groupingName = $('#groupingName').val(); + // course grouping name can not be blank + if (!groupingName) { + $('#grouping-name-blank-error').show(); + $('#groupingName').focus(); + enableButtons(); + return false; + } + + // course grouping name should be unique + var isGroupingNameUnique = false; + $.ajax({ + dataType : 'json', + url : LAMS_URL + 'monitoring/grouping.do', + cache : false, + async : false, + data : { + 'method' : 'checkGroupingNameUnique', + 'organisationID' : grouping.organisationId, + 'name' : groupingName + }, + success : function(response) { + if ( response.isGroupingNameUnique ) { + formDataUpload.append("name", groupingName) + callImportURL(form, formDataUpload); + } else { + $('#grouping-name-non-unique-error').show(); + $('#groupingName').focus(); + enableButtons(); + return false; + } + } + }); + } + } else { enableButtons(); } } + function reloadIframe(returnedGroupingId) { + if ( !lessonMode && returnedGroupingId ) { + var locationUrl = window.location.href; + if ( locationUrl.indexOf('groupingId') == -1 ) { + // if course grouping we need to add the new grouping id if this was a new grouping. + locationUrl += '&groupingId=' + returnedGroupingId; + window.location.assign(locationUrl); + return; + } + } + window.location.reload(); + } + function callImportURL(form, formDataUpload) { + $.ajax({ + data: formDataUpload, + processData: false, // tell jQuery not to process the data + contentType: false, // tell jQuery not to set contentType + type: 'POST', + url: form.action, + enctype: "multipart/form-data", + dataType : 'json', + success: function (response) { + var returnedGroupingId = response.groupingId; + if ( response.result != 'OK') { + if ( response.error ) { + alert(response.error); + if ( response.reload ) { + // do not have another go, look at new data + reloadIframe(returnedGroupingId); + } else { + enableButtons(); // let them have another go + } + } + else { + // unknown failure on back end. + alert(LABELS.GENERAL_ERROR_LABEL); + var div = document.getElementById("attachmentArea_Busy"); + if(div != null){ + div.style.display = 'none'; + } + } + } else { + var msg = LABELS.LABEL_IMPORT_SUCCESSFUL_LABEL.replace("%1", response.added).replace("%2", response.skipped); + alert(msg); + reloadIframe(returnedGroupingId); + } + }, + error: function() { + // unknown failure on back end. + alert(LABELS.GENERAL_ERROR_LABEL); + var div = document.getElementById("attachmentArea_Busy"); + if(div != null){ + div.style.display = 'none'; + } + } + }); + } + function getValidateSpreadsheetFile() { var file = null; // check file @@ -651,8 +719,12 @@ } }, 1000); - document.location.href = LAMS_URL + "groupingUpload.do?method=getGroupTemplateFile&activityID="+groupingActivityId - +"&organisationID="+organisationId+"&lessonID="+lessonId+"&downloadTokenValue=" + token; + var url = LAMS_URL + "groupingUpload.do?method=getGroupTemplateFile&activityID="+groupingActivityId + +"&organisationID="+organisationId+"&lessonID="+lessonId+"&downloadTokenValue=" + token; + if ( grouping && grouping.groupingId) { + url += "&groupingId=" + grouping.groupingId; + } + document.location.href = url; return false; } Index: lams_central/web/includes/javascript/orgGrouping.js =================================================================== diff -u -r092ede3b8b3828ffa688c4db18c5d535e3364b98 -r33308a6a7d7b29a01697f0274baaccbf9dca6bb3 --- lams_central/web/includes/javascript/orgGrouping.js (.../orgGrouping.js) (revision 092ede3b8b3828ffa688c4db18c5d535e3364b98) +++ lams_central/web/includes/javascript/orgGrouping.js (.../orgGrouping.js) (revision 33308a6a7d7b29a01697f0274baaccbf9dca6bb3) @@ -1,4 +1,4 @@ -var gtbDialog = null; +var gtbDialog = null; function removeGrouping(groupingId) { if (!lessonMode && confirm(LABELS.REMOVE_GROUPING_CONFIRM_LABEL)) { @@ -8,7 +8,6 @@ } function viewGroups(groupingId, force) { - debugger; var url = LAMS_URL + 'OrganisationGroup.do?method=viewGroups&organisationID=' + organisationId; if (lessonId) { url += '&lessonID=' + lessonId; Index: lams_central/web/orgGroup.jsp =================================================================== diff -u -r092ede3b8b3828ffa688c4db18c5d535e3364b98 -r33308a6a7d7b29a01697f0274baaccbf9dca6bb3 --- lams_central/web/orgGroup.jsp (.../orgGroup.jsp) (revision 092ede3b8b3828ffa688c4db18c5d535e3364b98) +++ lams_central/web/orgGroup.jsp (.../orgGroup.jsp) (revision 33308a6a7d7b29a01697f0274baaccbf9dca6bb3) @@ -183,46 +183,47 @@ + - -
-
-
- - - -
-
-
- -
- -
-
- - - - <%-- Value is set in Javascript as it comes in the JSON --%> - - - -
- -
+ +
+
+
+ + + +
+
+
+ +
+
+
+ + + + <%-- Value is set in Javascript as it comes in the JSON --%> + <%-- Value is set in Javascript as only used for some modes --%> + + + +
+ +
- - +
+
Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GroupingUploadAJAXAction.java =================================================================== diff -u -r1aff6aeac19473c0089c0f3ff578a183beb92555 -r33308a6a7d7b29a01697f0274baaccbf9dca6bb3 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GroupingUploadAJAXAction.java (.../GroupingUploadAJAXAction.java) (revision 1aff6aeac19473c0089c0f3ff578a183beb92555) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/GroupingUploadAJAXAction.java (.../GroupingUploadAJAXAction.java) (revision 33308a6a7d7b29a01697f0274baaccbf9dca6bb3) @@ -36,6 +36,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Vector; import javax.servlet.ServletOutputStream; import javax.servlet.http.Cookie; @@ -67,7 +68,9 @@ import org.lamsfoundation.lams.monitoring.service.IMonitoringService; import org.lamsfoundation.lams.monitoring.service.MonitoringServiceProxy; import org.lamsfoundation.lams.security.ISecurityService; +import org.lamsfoundation.lams.usermanagement.Organisation; import org.lamsfoundation.lams.usermanagement.OrganisationGroup; +import org.lamsfoundation.lams.usermanagement.OrganisationGrouping; import org.lamsfoundation.lams.usermanagement.Role; import org.lamsfoundation.lams.usermanagement.User; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; @@ -98,7 +101,8 @@ private static MessageService centralMessageService; /** - * Get the spreadsheet file containing list of the current users, ready for uploading with groups. + * Get the spreadsheet file containing list of the current users, ready for uploading with groups. If lesson supplied, + * list lesson users, otherwise list organisation users (course grouping screen has just the organisation). * * @throws Exception */ @@ -108,13 +112,23 @@ Integer userId = getUserDTO().getUserID(); Integer organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true); Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID, true); - Lesson lesson = (Lesson) getUserManagementService().findById(Lesson.class, lessonId); - ; - if (organisationId == null) { - // read organisation ID from lesson - organisationId = lesson.getOrganisation().getOrganisationId(); + + if ( lessonId == null && organisationId == null ) { + log.error("Cannot create group template file as lessonId and organisationId are both null."); + response.sendError(HttpServletResponse.SC_FORBIDDEN, "Invalid parameters"); } - Long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + + Lesson lesson = null; + String lessonOrOrganisationName = null; + + if ( lessonId != null ) { + lesson = (Lesson) getUserManagementService().findById(Lesson.class, lessonId); + lessonOrOrganisationName = lesson.getLessonName(); + organisationId = lesson.getOrganisation().getOrganisationId(); + } else { + Organisation organisation = (Organisation) getUserManagementService().findById(Organisation.class, organisationId); + lessonOrOrganisationName = organisation.getName(); + } // check if user is allowed to view and edit groups if (!getSecurityService().hasOrgRole(organisationId, userId, @@ -124,35 +138,51 @@ return null; } - // check for any groups already exist in this grouping - IMonitoringService monitoringService = MonitoringServiceProxy - .getMonitoringService(getServlet().getServletContext()); - Activity activity = monitoringService.getActivityById(activityId); - Grouping grouping = activity.isChosenBranchingActivity() ? activity.getGrouping() - : ((GroupingActivity) activity).getCreateGrouping(); - String fileName = new StringBuilder( getCentralMessageService().getMessage("filename.create.grouping.template").trim()).append(" ") - .append(lesson.getLessonName()).append(".xls").toString().replaceAll(" ", "-"); + .append(lessonOrOrganisationName).append(".xls").toString().replaceAll(" ", "-"); fileName = FileUtil.encodeFilenameForDownload(request, fileName); - response.setContentType("application/x-download"); - response.setHeader("Content-Disposition", "attachment;filename=" + fileName); - ServletOutputStream out = response.getOutputStream(); + LinkedHashMap dataToExport = null; - LinkedHashMap dataToExport = exportLearnersForGrouping(lesson, grouping.getGroups()); + if (lesson != null) { + Set learners = lesson.getLessonClass().getLearners(); + // check for any groups already exist in this grouping + Long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + IMonitoringService monitoringService = MonitoringServiceProxy + .getMonitoringService(getServlet().getServletContext()); + Activity activity = monitoringService.getActivityById(activityId); + Grouping grouping = activity.isChosenBranchingActivity() ? activity.getGrouping() + : ((GroupingActivity) activity).getCreateGrouping(); + dataToExport = exportLearnersForGrouping(learners, grouping.getGroups(), null); + } else { + @SuppressWarnings("unchecked") + Long groupingId = WebUtil.readLongParam(request, "groupingId", true); + Set groups = null; + if ( groupingId != null ) { + OrganisationGrouping orgGrouping = (OrganisationGrouping) getUserManagementService().findById(OrganisationGrouping.class, groupingId); + if ( orgGrouping != null ) + groups = orgGrouping.getGroups(); + } + Vector learners = (Vector) getUserManagementService().getUsersFromOrganisationByRole(organisationId, Role.LEARNER, true); + dataToExport = exportLearnersForGrouping(learners, null, groups); + } + // set cookie that will tell JS script that export has been finished String downloadTokenValue = WebUtil.readStrParam(request, "downloadTokenValue"); Cookie fileDownloadTokenCookie = new Cookie("fileDownloadToken", downloadTokenValue); fileDownloadTokenCookie.setPath("/"); response.addCookie(fileDownloadTokenCookie); + response.setContentType("application/x-download"); + response.setHeader("Content-Disposition", "attachment;filename=" + fileName); + ServletOutputStream out = response.getOutputStream(); ExcelUtil.createExcelXLS(out, dataToExport, null, false); return null; } - private LinkedHashMap exportLearnersForGrouping(Lesson lesson, Set groups) { + private LinkedHashMap exportLearnersForGrouping(Collection learners, Set groups, Set orgGroups) { List rowList = new LinkedList(); int numberOfColumns = 4; @@ -164,17 +194,28 @@ title[3] = new ExcelCell(getCentralMessageService().getMessage("spreadsheet.column.groupname"), false); rowList.add(title); - Collection learners = lesson.getLessonClass().getLearners(); - - List groupList = new LinkedList<>(groups); - Collections.sort(groupList, new GroupComparator()); - for (Group group : groupList) { - String groupName = group.getGroupName(); - for (User groupUser : group.getUsers()) { - rowList.add(generateUserRow(numberOfColumns, groupName, groupUser)); - learners.remove(groupUser); + if ( groups != null ) { + List groupList = new LinkedList<>(groups); + Collections.sort(groupList, new GroupComparator()); + for (Group group : groupList) { + String groupName = group.getGroupName(); + for (User groupUser : group.getUsers()) { + rowList.add(generateUserRow(numberOfColumns, groupName, groupUser)); + learners.remove(groupUser); + } } } + + if ( orgGroups != null ) { + List groupList = new LinkedList<>(orgGroups); + for (OrganisationGroup group : groupList) { + String groupName = group.getName(); + for (User groupUser : group.getUsers()) { + rowList.add(generateUserRow(numberOfColumns, groupName, groupUser)); + learners.remove(groupUser); + } + } + } // all the remaining users are unassigned to any group for (User unassignedUser : learners) { @@ -204,18 +245,39 @@ Integer userId = getUserDTO().getUserID(); Integer organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true); + boolean isLessonMode = WebUtil.readBooleanParam(request, "lessonMode", true); + + // used for lesson based grouping Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID, true); - Long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); - Lesson lesson = (Lesson) getUserManagementService().findById(Lesson.class, lessonId); + Long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID, true); + Lesson lesson = lessonId != null ? (Lesson) getUserManagementService().findById(Lesson.class, lessonId) : null; + // used for course grouping + Long groupingId = WebUtil.readLongParam(request, "groupingId", true); + String name = WebUtil.readStrParam(request, "name", true); + if ( isLessonMode && activityId == null ) { + log.error("Lesson grouping to be saved but activityId is missing"); + response.sendError(HttpServletResponse.SC_FORBIDDEN, "Invalid parameters"); + } else if ( !isLessonMode ) { + if ( ( groupingId == null && name == null ) || organisationId == null ) { + log.error("Course grouping to be saved but groupingId, grouping name or organisationId is missing"); + response.sendError(HttpServletResponse.SC_FORBIDDEN, "Invalid parameters"); + } + } + + Organisation organisation; if (organisationId == null) { // read organisation ID from lesson - organisationId = lesson.getOrganisation().getOrganisationId(); + organisation = lesson.getOrganisation(); + organisationId = organisation.getOrganisationId(); + } else { + organisation = (Organisation) getUserManagementService().findById(Organisation.class, organisationId); } // check if user is allowed to save grouping if (!getSecurityService().hasOrgRole(organisationId, userId, - new String[] { Role.GROUP_ADMIN, Role.GROUP_MANAGER }, "save organisation grouping from spreadsheet", + new String[] { Role.GROUP_ADMIN, Role.GROUP_MANAGER, Role.MONITOR, Role.AUTHOR }, + "save organisation grouping from spreadsheet", false)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a manager or admin in the organisation"); return null; @@ -231,10 +293,89 @@ + " and organisation " + organisationId + " filename " + fileElements); } - // remove users from current group + JSONObject responseJSON = null; + + if ( isLessonMode ) { + responseJSON = saveLessonGrouping(response, activityId, fileElements); + } else { + responseJSON = saveCourseGrouping(response, organisation, groupingId, name, fileElements); + } + + response.getWriter().write(responseJSON.toString()); + return null; + } + + + /** Create the new course grouping */ + private JSONObject saveCourseGrouping(HttpServletResponse response, Organisation organisation, Long orgGroupingId, String name, Hashtable fileElements) + throws JSONException, IOException { + + OrganisationGrouping orgGrouping = null; + if (orgGroupingId != null) { + orgGrouping = (OrganisationGrouping) getUserManagementService().findById(OrganisationGrouping.class, + orgGroupingId); + } + if (orgGrouping == null) { + orgGrouping = new OrganisationGrouping(); + orgGrouping.setOrganisationId(organisation.getOrganisationId()); + orgGrouping.setName(name); + } + + Map existingGroupNameToId = new HashMap(); + Map> groups = new HashMap>(); + if ( orgGrouping.getGroups() != null ) { + for (OrganisationGroup group : orgGrouping.getGroups()) { + existingGroupNameToId.put(group.getName(), group.getGroupId()); + } + } + + int totalUsersSkipped = parseGroupSpreadsheet((FormFile) fileElements.elements().nextElement(), orgGroupingId, groups); + int totalUsersAdded = 0; + + List orgGroups = new LinkedList<>(); + for ( Map.Entry> groupEntry : groups.entrySet()) { + String groupName = groupEntry.getKey(); + // just overwrite existing groups; they will be updated if already exist + Set learners = new HashSet<>(); + for ( String login : groupEntry.getValue() ) { + User learner = (User) getUserManagementService().getUserByLogin(login); + if (learner == null) { + log.warn("Unable to add learner " + login + " for group in related to grouping " + + orgGroupingId + " as learner cannot be found."); + totalUsersSkipped++; + } else { + totalUsersAdded++; + learners.add(learner); + } + } + OrganisationGroup orgGroup = new OrganisationGroup(); + Long orgGroupId = existingGroupNameToId.get(groupName); + if ( orgGroupId != null ) { + orgGroup.setGroupId(orgGroupId); + orgGroup.setGroupingId(orgGroupingId); + } + orgGroup.setName(groupName); + orgGroup.setUsers(learners); + orgGroups.add(orgGroup); + } + + getUserManagementService().saveOrganisationGrouping(orgGrouping, orgGroups); + return createResponseJSON(response, false, null, true, orgGrouping.getGroupingId(), totalUsersAdded, totalUsersSkipped); + + } + + /** Clean out and reuse any existing groups */ + private JSONObject saveLessonGrouping(HttpServletResponse response, Long activityId, Hashtable fileElements) + throws JSONException, IOException { + IMonitoringService monitoringService = MonitoringServiceProxy .getMonitoringService(getServlet().getServletContext()); + Map> groups = new HashMap>(); + int totalUsersSkipped = 0; + int totalUsersAdded = 0; + + // Lesson grouping case so clean out and reuse any existing groups Activity activity = monitoringService.getActivityById(activityId); Grouping grouping = activity.isChosenBranchingActivity() ? activity.getGrouping() : ((GroupingActivity) activity).getCreateGrouping(); @@ -245,14 +386,11 @@ existingGroupNames.add(group.getGroupName()); if (!group.mayBeDeleted()) { String error = getCentralMessageService().getMessage("error.groups.upload.locked"); - return returnImport(response, error, true); + return createResponseJSON(response, true, error, true, grouping.getGroupingId(),0, 0); } } - Map> groups = new HashMap>(); - int totalUserSkipped = parseGroupSpreadsheet((FormFile) fileElements.elements().nextElement(), activityId, - groups); - int totalUserAdded = 0; + totalUsersSkipped = parseGroupSpreadsheet((FormFile) fileElements.elements().nextElement(), grouping.getGroupingId(), groups); // if branching must use the already specified groups or cannot match to a branch! if (activity.isChosenBranchingActivity()) { @@ -262,9 +400,9 @@ for (String name : existingGroupNames) groupNamesStrBlder.append("'").append(name).append("' "); String error = getCentralMessageService().getMessage( - "error.branching.upload.must.use.existing.groups", - new String[] { groupNamesStrBlder.toString() }); - return returnImport(response, error.toString(), false); + "error.branching.upload.must.use.existing.groups", + new String[] { groupNamesStrBlder.toString() }); + return createResponseJSON(response, true, error.toString(), false, grouping.getGroupingId(), 0, 0); } } } @@ -276,30 +414,29 @@ for (Map.Entry> groupEntry : groups.entrySet()) { int added = monitoringService.addUsersToGroupByLogins(activityId, groupEntry.getKey(), groupEntry.getValue()); - totalUserAdded += added; - totalUserSkipped += groupEntry.getValue().size() - added; + totalUsersAdded += added; + totalUsersSkipped += groupEntry.getValue().size() - added; } - JSONObject responseJSON = new JSONObject(); - responseJSON.put("result", "OK"); - responseJSON.put("added", totalUserAdded); - responseJSON.put("skipped", totalUserSkipped); - response.getWriter().write(responseJSON.toString()); - return null; + return createResponseJSON(response, false, null, true, grouping.getGroupingId(), totalUsersAdded, totalUsersSkipped); } - private ActionForward returnImport(HttpServletResponse response, String errorMessage, boolean reload) - throws JSONException, IOException { + private JSONObject createResponseJSON(HttpServletResponse response, boolean isError, String errorMessage, + boolean reload, Long groupingId, int totalUsersAdded, int totalUsersSkipped) throws JSONException { JSONObject responseJSON = new JSONObject(); - responseJSON.put("result", "FAIL"); - responseJSON.put("reload", reload); - responseJSON.put("error", errorMessage); - response.getWriter().write(responseJSON.toString()); - return null; - + if (isError) { + responseJSON.put("result", "FAIL"); + responseJSON.put("reload", reload); + responseJSON.put("error", errorMessage); + } else { + responseJSON.put("result", "OK"); + responseJSON.put("added", totalUsersAdded); + responseJSON.put("skipped", totalUsersSkipped); + } + responseJSON.put("groupingId", groupingId); + return responseJSON; } - /* XLS Version Parse */ private String parseStringCell(HSSFCell cell) { if (cell != null) { @@ -311,7 +448,7 @@ return null; } - public int parseGroupSpreadsheet(FormFile fileItem, Long activityID, Map> groups) + public int parseGroupSpreadsheet(FormFile fileItem, Long groupingID, Map> groups) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(fileItem.getInputStream()); HSSFWorkbook wb = new HSSFWorkbook(fs); @@ -332,7 +469,7 @@ if (groupName == null || groupName.length() == 0) { skipped++; GroupingUploadAJAXAction.log.warn("Unable to add learner " + login - + " for group in related to activity " + activityID + " as group name is missing."); + + " for group in related to grouping " + groupingID + " as group name is missing."); } else { Set users = groups.get(groupName); if (users == null) {