Index: lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java =================================================================== diff -u -r42d1e3fc39b9b5421eb2b65620f6856dd5afebc4 -r209169e5b23bcde0a00dc86cd250e83c9ac76492 --- lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java (.../LessonManagerServlet.java) (revision 42d1e3fc39b9b5421eb2b65620f6856dd5afebc4) +++ lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java (.../LessonManagerServlet.java) (revision 209169e5b23bcde0a00dc86cd250e83c9ac76492) @@ -212,6 +212,18 @@ element = removeAllLessons(document, serverId, datetime, hashValue, username, courseId); + } else if (method.equals(CentralConstants.METHOD_REMOVE_USER)) { + verifyPostRequestMethod(request); + + lsId = new Long(lsIdStr); + element = removeUser(document, serverId, datetime, hashValue, username, lsId, userIds); + + } else if (method.equals(CentralConstants.METHOD_REMOVE_ALL_USERS)) { + verifyPostRequestMethod(request); + + lsId = new Long(lsIdStr); + element = removeAllUsers(document, serverId, datetime, hashValue, username, lsId); + } else if (method.equals(CentralConstants.METHOD_STUDENT_PROGRESS)) { lsId = new Long(lsIdStr); element = getAllStudentProgress(document, serverId, datetime, hashValue, username, lsId, courseId); @@ -620,6 +632,79 @@ return lessonsElement; } + /** + * Deletes all lessons from the specified course. + */ + private Element removeUser(Document document, String serverId, String datetime, String hashValue, String username, + long lsId, String userIds) throws Exception { + // Create the root node of the xml document + Element usersElement = document.createElement("Users"); + + ExtServerOrgMap serverMap = LessonManagerServlet.integrationService.getExtServerOrgMap(serverId); + Authenticator.authenticate(serverMap, datetime, username, hashValue); + + // check is user monitor + ExtUserUseridMap monitorMap = LessonManagerServlet.integrationService.getExtUserUseridMap(serverMap, username); + LessonManagerServlet.securityService.isLessonMonitor(lsId, monitorMap.getUser().getUserId(), "remove user", + true); + + // remove requested user + String[] extUsernames = (userIds != null) ? userIds.split(",") : new String[0]; + for (String extUsername : extUsernames) { + + ExtUserUseridMap userMap = LessonManagerServlet.integrationService.getExtUserUseridMap(serverMap, + extUsername); + Integer userId = userMap.getUser().getUserId(); + // remove user + LessonManagerServlet.lessonService.removeLearner(lsId, userId); + + // add userId to output xml document + Element lessonElement = document.createElement("User"); + lessonElement.setAttribute(CentralConstants.PARAM_USER_ID, "" + userId); + lessonElement.setAttribute(CentralConstants.ATTR_DELETED, "true"); + usersElement.appendChild(lessonElement); + } + + return usersElement; + } + + /** + * Deletes all lessons from the specified course. + */ + private Element removeAllUsers(Document document, String serverId, String datetime, String hashValue, + String username, long lsId) throws Exception { + // Create the root node of the xml document + Element usersElement = document.createElement("Users"); + + ExtServerOrgMap serverMap = LessonManagerServlet.integrationService.getExtServerOrgMap(serverId); + Authenticator.authenticate(serverMap, datetime, username, hashValue); + + // check is user monitor + ExtUserUseridMap monitorMap = LessonManagerServlet.integrationService.getExtUserUseridMap(serverMap, username); + LessonManagerServlet.securityService.isLessonMonitor(lsId, monitorMap.getUser().getUserId(), "remove all users", + true); + + // remove all users from the specified lesson + Lesson lesson = LessonManagerServlet.lessonService.getLesson(lsId); + Set users = lesson.getAllLearners(); + if (users != null) { + for (User user : users) { + + Integer userId = user.getUserId(); + // remove user + LessonManagerServlet.lessonService.removeLearner(lsId, userId); + + // add userId to output xml document + Element lessonElement = document.createElement("User"); + lessonElement.setAttribute(CentralConstants.PARAM_USER_ID, "" + userId); + lessonElement.setAttribute(CentralConstants.ATTR_DELETED, "true"); + usersElement.appendChild(lessonElement); + } + } + + return usersElement; + } + private Long startPreview(String serverId, String datetime, String hashValue, String username, Long ldId, String courseId, String title, String desc, String countryIsoCode, String langIsoCode, String customCSV, boolean presenceEnable, boolean imEnable) throws RemoteException {