Index: lams_central/src/java/org/lamsfoundation/lams/util/CentralConstants.java =================================================================== diff -u -re3cc96afe1761e30057a7cc1edacf7c6bbf6e14b -r49c83fb1fa62a2ed7c4de6c2bb2698106d2b3efa --- lams_central/src/java/org/lamsfoundation/lams/util/CentralConstants.java (.../CentralConstants.java) (revision e3cc96afe1761e30057a7cc1edacf7c6bbf6e14b) +++ lams_central/src/java/org/lamsfoundation/lams/util/CentralConstants.java (.../CentralConstants.java) (revision 49c83fb1fa62a2ed7c4de6c2bb2698106d2b3efa) @@ -74,6 +74,8 @@ public static final String PARAM_CUSTOM_CSV = "customCSV"; public static final String PARAM_USER_ID = "userId"; + + public static final String PARAM_USER_IDS = "userIds"; public static final String METHOD_START = "start"; @@ -82,8 +84,18 @@ public static final String METHOD_IMPORT = "import"; public static final String METHOD_SCHEDULE = "schedule"; + + public static final String METHOD_CLONE = "clone"; public static final String METHOD_DELETE = "delete"; + + public static final String METHOD_REMOVE_LESSON = "removeLesson"; + + public static final String METHOD_REMOVE_ALL_LESSONS = "removeAllLessons"; + + public static final String METHOD_REMOVE_USER = "removeUser"; + + public static final String METHOD_REMOVE_ALL_USERS = "removeAllUsers"; public static final String METHOD_STUDENT_PROGRESS = "studentProgress"; Index: lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java =================================================================== diff -u -r66ec2cacd545c973ae91f2dd4fc3850c49d84e5b -r49c83fb1fa62a2ed7c4de6c2bb2698106d2b3efa --- lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java (.../LessonManagerServlet.java) (revision 66ec2cacd545c973ae91f2dd4fc3850c49d84e5b) +++ lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java (.../LessonManagerServlet.java) (revision 49c83fb1fa62a2ed7c4de6c2bb2698106d2b3efa) @@ -6,6 +6,7 @@ import java.rmi.RemoteException; import java.util.ArrayList; import java.util.Date; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -50,6 +51,8 @@ import org.lamsfoundation.lams.lesson.dto.LearnerProgressDTO; import org.lamsfoundation.lams.lesson.service.ILessonService; import org.lamsfoundation.lams.monitoring.service.IMonitoringService; +import org.lamsfoundation.lams.monitoring.web.GroupingAJAXAction; +import org.lamsfoundation.lams.security.SecurityService; import org.lamsfoundation.lams.tool.OutputType; import org.lamsfoundation.lams.tool.ToolOutput; import org.lamsfoundation.lams.tool.ToolOutputDefinition; @@ -125,6 +128,7 @@ String method = request.getParameter(CentralConstants.PARAM_METHOD); String filePath = request.getParameter(CentralConstants.PARAM_FILEPATH); String outputsUser = request.getParameter("outputsUser"); + String userIds = request.getParameter(CentralConstants.PARAM_USER_IDS); String learnerIds = request.getParameter(CentralConstants.PARAM_LEARNER_IDS); String monitorIds = request.getParameter(CentralConstants.PARAM_MONITOR_IDS); @@ -183,14 +187,23 @@ element = document.createElement(CentralConstants.ELEM_LESSON); element.setAttribute(CentralConstants.ATTR_LESSON_ID, lessonId.toString()); - } else if (method.equals(CentralConstants.METHOD_DELETE)) { + } else if (method.equals(CentralConstants.METHOD_DELETE) + || method.equals(CentralConstants.METHOD_REMOVE_LESSON)) { + verifyPostRequestMethod(request); + lsId = new Long(lsIdStr); - Boolean deleted = deleteLesson(serverId, datetime, hashValue, username, lsId); + Boolean deleted = removeLesson(serverId, datetime, hashValue, username, lsId); element = document.createElement(CentralConstants.ELEM_LESSON); element.setAttribute(CentralConstants.ATTR_LESSON_ID, lsId.toString()); element.setAttribute(CentralConstants.ATTR_DELETED, deleted.toString()); + } else if (method.equals(CentralConstants.METHOD_REMOVE_ALL_LESSONS)) { + verifyPostRequestMethod(request); + + element = removeAllLessons(document, serverId, datetime, hashValue, username, courseId); + + } else if (method.equals(CentralConstants.METHOD_STUDENT_PROGRESS)) { lsId = new Long(lsIdStr); element = getAllStudentProgress(document, serverId, datetime, hashValue, username, lsId, courseId); @@ -323,7 +336,7 @@ doGet(request, response); } - public Long startLesson(String serverId, String datetime, String hashValue, String username, long ldId, + private Long startLesson(String serverId, String datetime, String hashValue, String username, long ldId, String courseId, String title, String desc, String countryIsoCode, String langIsoCode, String customCSV, boolean exportPortfolioEnable, boolean presenceEnable, boolean imEnable) throws RemoteException { try { @@ -352,7 +365,7 @@ } } - public Long scheduleLesson(String serverId, String datetime, String hashValue, String username, long ldId, + private Long scheduleLesson(String serverId, String datetime, String hashValue, String username, long ldId, String courseId, String title, String desc, String startDate, String countryIsoCode, String langIsoCode, String customCSV, boolean exportPortfolioEnable, boolean presenceEnable, boolean imEnable) throws RemoteException { @@ -379,7 +392,7 @@ } @SuppressWarnings("unchecked") - public Element getAllStudentProgress(Document document, String serverId, String datetime, String hashValue, + private Element getAllStudentProgress(Document document, String serverId, String datetime, String hashValue, String username, long lsId, String courseID) throws RemoteException { try { ExtServerOrgMap serverMap = LessonManagerServlet.integrationService.getExtServerOrgMap(serverId); @@ -437,7 +450,7 @@ } - public Element getSingleStudentProgress(Document document, String serverId, String datetime, String hashValue, + private Element getSingleStudentProgress(Document document, String serverId, String datetime, String hashValue, String username, String firstName, String lastName, String language, String country, String email, long lsId, String courseID) throws RemoteException { try { @@ -511,7 +524,7 @@ } - public boolean deleteLesson(String serverId, String datetime, String hashValue, String username, long lsId) + private boolean removeLesson(String serverId, String datetime, String hashValue, String username, long lsId) throws RemoteException { try { ExtServerOrgMap serverMap = LessonManagerServlet.integrationService.getExtServerOrgMap(serverId); @@ -523,8 +536,50 @@ throw new RemoteException(e.getMessage(), e); } } + + /** + * Deletes all users from the specified course. + */ + private Element removeAllLessons(Document document, String serverId, String datetime, String hashValue, + String username, String courseId) throws Exception { + // Create the root node of the xml document + Element lessonsElement = document.createElement("Lessons"); - public Long startPreview(String serverId, String datetime, String hashValue, String username, Long ldId, + ExtServerOrgMap serverMap = LessonManagerServlet.integrationService.getExtServerOrgMap(serverId); + Authenticator.authenticate(serverMap, datetime, username, hashValue); + + ExtUserUseridMap userMap = LessonManagerServlet.integrationService.getExtUserUseridMap(serverMap, username); + + // find all lesons in organisation + ExtCourseClassMap orgMap = LessonManagerServlet.integrationService.getExtCourseClassMap(serverMap.getSid(), + courseId); + if (orgMap == null) { + LessonManagerServlet.log.debug("No course exists for: " + courseId + ". Can't delete any lessons."); + throw new Exception("Course with courseId: " + courseId + " could not be found"); + } + Integer organisationId = orgMap.getOrganisation().getOrganisationId(); + List lessons = lessonService.getLessonsByGroup(organisationId); + + if (lessons != null) { + for (Lesson lesson : lessons) { + + Long lessonId = lesson.getLessonId(); + + // remove lesson + LessonManagerServlet.monitoringService.removeLesson(lessonId, userMap.getUser().getUserId()); + + // add lessonId to output xml document + Element lessonElement = document.createElement(CentralConstants.ELEM_LESSON); + lessonElement.setAttribute(CentralConstants.ATTR_LESSON_ID, "" + lessonId); + lessonElement.setAttribute(CentralConstants.ATTR_DELETED, "true"); + lessonsElement.appendChild(lessonElement); + } + } + + return lessonsElement; + } + + 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 { @@ -553,7 +608,7 @@ } @SuppressWarnings("unchecked") - public Long importLearningDesign(HttpServletRequest request, HttpServletResponse response, String filePath, + private Long importLearningDesign(HttpServletRequest request, HttpServletResponse response, String filePath, String username, String serverId, String customCSV) throws RemoteException { List ldErrorMsgs = new ArrayList(); @@ -834,7 +889,7 @@ * @throws Exception */ @SuppressWarnings("unchecked") - public Element getGradebookMarks(Document document, String serverId, String datetime, String hashValue, + private Element getGradebookMarks(Document document, String serverId, String datetime, String hashValue, String username, Long lessonIdParam, String courseId, String outputsUser) throws Exception { @@ -1240,4 +1295,21 @@ } return null; } + + /** + * Checks whether request method is POST, throws SecurityException if not. + * + * @param request + * @return + * @throws SecurityException + */ + private boolean verifyPostRequestMethod(HttpServletRequest request) throws SecurityException { + boolean isPost = "POST".equals(request.getMethod()); + + if (!isPost) { + throw new SecurityException("This API call allows only POST request method."); + } + + return isPost; + } }