Index: lams_central/src/java/org/lamsfoundation/lams/web/GradebookServlet.java =================================================================== diff -u -r935066ab304c8de82b2d511422f26996c87cb60c -r192e8bed06df5a995b34c4e94023cbc699b341e5 --- lams_central/src/java/org/lamsfoundation/lams/web/GradebookServlet.java (.../GradebookServlet.java) (revision 935066ab304c8de82b2d511422f26996c87cb60c) +++ lams_central/src/java/org/lamsfoundation/lams/web/GradebookServlet.java (.../GradebookServlet.java) (revision 192e8bed06df5a995b34c4e94023cbc699b341e5) @@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.lamsfoundation.lams.integration.ExtCourseClassMap; import org.lamsfoundation.lams.integration.ExtServerOrgMap; @@ -38,6 +39,7 @@ import org.lamsfoundation.lams.integration.service.IntegrationService; import org.lamsfoundation.lams.integration.util.LoginRequestDispatcher; import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.CentralConstants; import org.lamsfoundation.lams.util.Configuration; import org.lamsfoundation.lams.util.ConfigurationKeys; @@ -53,9 +55,11 @@ private static Logger log = Logger.getLogger(GradebookServlet.class); private static IntegrationService integrationService = null; + private static IUserManagementService userManagementService; - private static final String GRADEBOOK_LESSON_URL = "gradebook/gradebookMonitoring.do?lessonID="; - private static final String GRADEBOOK_ORGANISATION_URL = "gradebook/gradebookMonitoring.do?dispatch=courseMonitor&organisationID="; + private static final String GRADEBOOK_MONITOR_LESSON_URL = "gradebook/gradebookMonitoring.do?lessonID="; + private static final String GRADEBOOK_MONITOR_ORGANISATION_URL = "gradebook/gradebookMonitoring.do?dispatch=courseMonitor&organisationID="; + private static final String GRADEBOOK_LEARNER_ORGANISATION_URL = "gradebook/gradebookLearning.do?dispatch=courseLearner&organisationID="; /** * The doGet method of the servlet.
@@ -85,35 +89,44 @@ String lessonId = request.getParameter(LoginRequestDispatcher.PARAM_LESSON_ID); String courseName = request.getParameter(CentralConstants.PARAM_COURSE_NAME); String method = request.getParameter(LoginRequestDispatcher.PARAM_METHOD); - + // either lesson ID or course ID is required; if both provided, only lesson ID is used if ((username == null) || (serverId == null) || (timestamp == null) || (hash == null) || ((lessonId == null) && (extCourseId == null))) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Gradebook request failed - invalid parameters"); } else { - ExtServerOrgMap serverMap = getService().getExtServerOrgMap(serverId); + ExtServerOrgMap serverMap = getIntegrationService().getExtServerOrgMap(serverId); try { // if request comes from LoginRequest, method parameter was meaningful there // if it's a direct call, it can be anything Authenticator.authenticate(serverMap, timestamp, username, method, hash); - String redirect = null; + boolean isTeacher = StringUtils.equals(method, LoginRequestDispatcher.METHOD_AUTHOR) + || StringUtils.equals(method, LoginRequestDispatcher.METHOD_MONITOR); if (lessonId == null) { + String gradebookServletURL = isTeacher ? GradebookServlet.GRADEBOOK_MONITOR_ORGANISATION_URL + : GradebookServlet.GRADEBOOK_LEARNER_ORGANISATION_URL; + // translate external course ID to internal organisation ID and then get the gradebook for it - ExtUserUseridMap userMap = GradebookServlet.integrationService.getExtUserUseridMap(serverMap, - username); - ExtCourseClassMap orgMap = GradebookServlet.integrationService.getExtCourseClassMap(serverMap, - userMap, extCourseId, countryIsoCode, langIsoCode, courseName, method); + ExtUserUseridMap userMap = getIntegrationService().getExtUserUseridMap(serverMap, username); + ExtCourseClassMap orgMap = getIntegrationService().getExtCourseClassMap(serverMap, userMap, + extCourseId, courseName, countryIsoCode, langIsoCode, + getUserManagementService().getRootOrganisation().getOrganisationId().toString(), isTeacher, + false); Organisation org = orgMap.getOrganisation(); - redirect = Configuration.get(ConfigurationKeys.SERVER_URL) - + GradebookServlet.GRADEBOOK_ORGANISATION_URL + org.getOrganisationId(); + + response.sendRedirect(Configuration.get(ConfigurationKeys.SERVER_URL) + gradebookServletURL + + org.getOrganisationId()); } else { - // get gradebook for particular lesson - redirect = Configuration.get(ConfigurationKeys.SERVER_URL) + GradebookServlet.GRADEBOOK_LESSON_URL - + lessonId; + if (isTeacher) { + // get gradebook for particular lesson + response.sendRedirect(Configuration.get(ConfigurationKeys.SERVER_URL) + + GradebookServlet.GRADEBOOK_MONITOR_LESSON_URL + lessonId); + } else { + response.sendError(HttpServletResponse.SC_BAD_REQUEST, + "There is no lesson level gradebook for learner"); + } } - - response.sendRedirect(redirect); } catch (AuthenticationException e) { GradebookServlet.log.error(e); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Login failed - authentication error"); @@ -125,11 +138,21 @@ } } - private IntegrationService getService() { + private IntegrationService getIntegrationService() { if (GradebookServlet.integrationService == null) { GradebookServlet.integrationService = (IntegrationService) WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()).getBean("integrationService"); } return GradebookServlet.integrationService; } + + protected IUserManagementService getUserManagementService() { + if (GradebookServlet.userManagementService == null) { + GradebookServlet.userManagementService = (IUserManagementService) WebApplicationContextUtils + .getRequiredWebApplicationContext(getServletContext()).getBean( + CentralConstants.USER_MANAGEMENT_SERVICE_BEAN_NAME); + + } + return GradebookServlet.userManagementService; + } } \ No newline at end of file Index: lams_central/src/java/org/lamsfoundation/lams/webservice/LearningDesignSVGServlet.java =================================================================== diff -u -r83299df260ee318896700f2dc17a3f38c04c58f6 -r192e8bed06df5a995b34c4e94023cbc699b341e5 --- lams_central/src/java/org/lamsfoundation/lams/webservice/LearningDesignSVGServlet.java (.../LearningDesignSVGServlet.java) (revision 83299df260ee318896700f2dc17a3f38c04c58f6) +++ lams_central/src/java/org/lamsfoundation/lams/webservice/LearningDesignSVGServlet.java (.../LearningDesignSVGServlet.java) (revision 192e8bed06df5a995b34c4e94023cbc699b341e5) @@ -73,15 +73,11 @@ String datetime = request.getParameter(CentralConstants.PARAM_DATE_TIME); String hashValue = request.getParameter(CentralConstants.PARAM_HASH_VALUE); String username = request.getParameter(CentralConstants.PARAM_USERNAME); - String courseId = request.getParameter(CentralConstants.PARAM_COURSE_ID); - String courseName = request.getParameter(CentralConstants.PARAM_COURSE_NAME); - String country = request.getParameter(CentralConstants.PARAM_COUNTRY); - String lang = request.getParameter(CentralConstants.PARAM_LANG); + Long learningDesignId = WebUtil.readLongParam(request, CentralConstants.PARAM_LEARNING_DESIGN_ID); int imageFormat = WebUtil.readIntParam(request, CentralConstants.PARAM_SVG_FORMAT); - if (serverId == null || datetime == null || hashValue == null || username == null || courseId == null - || country == null || lang == null) { + if (serverId == null || datetime == null || hashValue == null || username == null) { String msg = "Parameters missing"; log.error(msg); response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Parameters missing"); Index: lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java =================================================================== diff -u -r109a77d78a087aeb8b9418b2a49f943597097f06 -r192e8bed06df5a995b34c4e94023cbc699b341e5 --- lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java (.../IntegrationService.java) (revision 109a77d78a087aeb8b9418b2a49f943597097f06) +++ lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java (.../IntegrationService.java) (revision 192e8bed06df5a995b34c4e94023cbc699b341e5) @@ -135,8 +135,9 @@ Organisation org = map.getOrganisation(); // update external course name if if has changed - if (extCourseName != null && !org.getName().equals(buildName(serverMap.getPrefix(), extCourseName))) { - org.setName(buildName(serverMap.getPrefix(), extCourseName)); + String requestedCourseName = prefix ? buildName(serverMap.getPrefix(), extCourseName) : extCourseName; + if (extCourseName != null && !org.getName().equals(requestedCourseName)) { + org.setName(requestedCourseName); service.updateOrganisationandWorkspaceNames(org); } if (service.getUserOrganisation(user.getUserId(), org.getOrganisationId()) == null) { Index: lams_common/src/java/org/lamsfoundation/lams/integration/util/LoginRequestDispatcher.java =================================================================== diff -u -r935066ab304c8de82b2d511422f26996c87cb60c -r192e8bed06df5a995b34c4e94023cbc699b341e5 --- lams_common/src/java/org/lamsfoundation/lams/integration/util/LoginRequestDispatcher.java (.../LoginRequestDispatcher.java) (revision 935066ab304c8de82b2d511422f26996c87cb60c) +++ lams_common/src/java/org/lamsfoundation/lams/integration/util/LoginRequestDispatcher.java (.../LoginRequestDispatcher.java) (revision 192e8bed06df5a995b34c4e94023cbc699b341e5) @@ -113,12 +113,14 @@ String lessonId = request.getParameter(PARAM_LESSON_ID); String mode = request.getParameter(PARAM_MODE); - try { - addUserToLessonClass(request, lessonId, method); - } catch (UserInfoFetchException e) { - throw new ServletException(e); + if (lessonId != null) { + try { + addUserToLessonClass(request, lessonId, method); + } catch (UserInfoFetchException e) { + throw new ServletException(e); + } } - + if (MODE_GRADEBOOK.equals(mode)) { return request.getContextPath() + URL_GRADEBOOK + request.getQueryString(); }