Index: lams_central/src/java/org/lamsfoundation/lams/web/controller/LtiController.java =================================================================== diff -u -r4de0555990d486e499b8b829e4998f003987379f -r5926b5cb145649a9f978ab4c14146169684a849c --- lams_central/src/java/org/lamsfoundation/lams/web/controller/LtiController.java (.../LtiController.java) (revision 4de0555990d486e499b8b829e4998f003987379f) +++ lams_central/src/java/org/lamsfoundation/lams/web/controller/LtiController.java (.../LtiController.java) (revision 5926b5cb145649a9f978ab4c14146169684a849c) @@ -131,6 +131,10 @@ boolean isLessonCopyRequired = lesson.getOrganisation() != null && !lesson.getOrganisation().getOrganisationId().equals(currentOrganisationId); if (isLessonCopyRequired) { + + //add users to the course + integrationService.addUsersUsingMembershipService(extServer, null, extCourseId, resourceLinkId); + // clone lesson Integer creatorId = lesson.getUser().getUserId(); Long newLessonId = monitoringService.cloneLesson(lesson.getLessonId(), creatorId, true, true, null, null, @@ -258,7 +262,7 @@ String title = request.getParameter(CentralConstants.PARAM_TITLE); String desc = request.getParameter(CentralConstants.PARAM_DESC); String ldIdStr = request.getParameter(CentralConstants.PARAM_LEARNING_DESIGN_ID); - String contextId = request.getParameter(BasicLTIConstants.CONTEXT_ID); + String extCourseId = request.getParameter(BasicLTIConstants.CONTEXT_ID); Integer organisationId = WebUtil.readIntParam(request, CentralConstants.ATTR_COURSE_ID); boolean enableLessonIntro = WebUtil.readBooleanParam(request, "enableLessonIntro", false); @@ -294,7 +298,7 @@ // store information which extServer has started the lesson integrationService.createExtServerLessonMap(lessonId, resourceLinkId, extServer); - integrationService.addExtUsersToLesson(extServer, lessonId, contextId, resourceLinkId); + integrationService.addUsersUsingMembershipService(extServer, lessonId, extCourseId, resourceLinkId); //support for ContentItemSelectionRequest String ltiMessageType = request.getParameter(BasicLTIConstants.LTI_MESSAGE_TYPE); @@ -330,7 +334,7 @@ String redirectURL = "redirect:/lti/learnerMonitor.do"; redirectURL = WebUtil.appendParameterToURL(redirectURL, LtiUtils.OAUTH_CONSUMER_KEY, consumerKey); redirectURL = WebUtil.appendParameterToURL(redirectURL, BasicLTIConstants.RESOURCE_LINK_ID, resourceLinkId); - redirectURL = WebUtil.appendParameterToURL(redirectURL, BasicLTIConstants.CONTEXT_ID, contextId); + redirectURL = WebUtil.appendParameterToURL(redirectURL, BasicLTIConstants.CONTEXT_ID, extCourseId); return redirectURL; } } Index: lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java =================================================================== diff -u -r2921dcd0bdb3c896b149d7a398ee3f5104cdcf4a -r5926b5cb145649a9f978ab4c14146169684a849c --- lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java (.../LessonManagerServlet.java) (revision 2921dcd0bdb3c896b149d7a398ee3f5104cdcf4a) +++ lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LessonManagerServlet.java (.../LessonManagerServlet.java) (revision 5926b5cb145649a9f978ab4c14146169684a849c) @@ -928,7 +928,7 @@ if (StringUtils.isNotBlank(userName)) { // integrationService.addExtUserToLesson(extServer, LoginRequestDispatcher.METHOD_LEARNER, lessonId, // userName, firstName, lastName, email, courseId, countryIsoCode, langIsoCode); - integrationService.addExtUserToLesson(extServer, LoginRequestDispatcher.METHOD_LEARNER, lessonId, + integrationService.addExtUserToCourseAndLesson(extServer, LoginRequestDispatcher.METHOD_LEARNER, lessonId, userName, firstName, lastName, email, courseId, country, locale); } i++; @@ -946,7 +946,7 @@ } if (StringUtils.isNotBlank(userName)) { - integrationService.addExtUserToLesson(extServer, LoginRequestDispatcher.METHOD_MONITOR, lessonId, + integrationService.addExtUserToCourseAndLesson(extServer, LoginRequestDispatcher.METHOD_MONITOR, lessonId, userName, firstName, lastName, email, courseId, country, locale); } i++; Index: lams_common/src/java/org/lamsfoundation/lams/integration/service/IIntegrationService.java =================================================================== diff -u -r2921dcd0bdb3c896b149d7a398ee3f5104cdcf4a -r5926b5cb145649a9f978ab4c14146169684a849c --- lams_common/src/java/org/lamsfoundation/lams/integration/service/IIntegrationService.java (.../IIntegrationService.java) (revision 2921dcd0bdb3c896b149d7a398ee3f5104cdcf4a) +++ lams_common/src/java/org/lamsfoundation/lams/integration/service/IIntegrationService.java (.../IIntegrationService.java) (revision 5926b5cb145649a9f978ab4c14146169684a849c) @@ -120,12 +120,6 @@ * @return */ ExtServerLessonMap getLtiConsumerLesson(String serverId, String resourceLinkId); - - /** - * Try to get users from ext server using membership service. - */ - void addExtUsersToLesson(ExtServer extServer, Long lessonId, String courseId, String resourceLinkId) - throws IOException, UserInfoFetchException, UserInfoValidationException; ExtServerLessonMap getExtServerLessonMap(Long lessonId); @@ -232,9 +226,28 @@ List getExtGroups(Long lessonId, String[] extGroupIds) throws Exception; ExtCourseClassMap getExtCourseClassMap(Integer sid, Long lessonId); + + /** + * Try to get users from ext server using membership service. + * + * @param lessonId if supplied, user will be added to the according lesson; and only to the course otherwise + */ + void addUsersUsingMembershipService(ExtServer extServer, Long lessonId, String extCourseId, String resourceLinkId) + throws IOException, UserInfoFetchException, UserInfoValidationException; + + /** + * Adds an external user to the course with specified courseId. + */ + ExtUserUseridMap addExtUserToCourse(ExtServer extServer, String method, String username, String firstName, String lastName, + String email, String extCourseId, String countryIsoCode, String langIsoCode) + throws UserInfoFetchException, UserInfoValidationException; - ExtUserUseridMap addExtUserToLesson(ExtServer extServer, String method, Long lessonId, String username, String firstName, - String lastName, String email, String courseId, String countryIsoCode, String langIsoCode) + /** + * Add an external user to the course with specified courseId and then adds it the the lesson with specified + * lessonId. (This method makes internal call to addExtUserToCourse()). + */ + ExtUserUseridMap addExtUserToCourseAndLesson(ExtServer extServer, String method, Long lessonId, String username, String firstName, + String lastName, String email, String extCourseId, String countryIsoCode, String langIsoCode) throws UserInfoFetchException, UserInfoValidationException; /** Index: lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java =================================================================== diff -u -r2921dcd0bdb3c896b149d7a398ee3f5104cdcf4a -r5926b5cb145649a9f978ab4c14146169684a849c --- lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java (.../IntegrationService.java) (revision 2921dcd0bdb3c896b149d7a398ee3f5104cdcf4a) +++ lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java (.../IntegrationService.java) (revision 5926b5cb145649a9f978ab4c14146169684a849c) @@ -871,12 +871,12 @@ } @Override - public ExtUserUseridMap addExtUserToLesson(ExtServer extServer, String method, Long lesssonId, String username, - String firstName, String lastName, String email, String courseId, String countryIsoCode, String langIsoCode) + public ExtUserUseridMap addExtUserToCourse(ExtServer extServer, String method, String username, String firstName, String lastName, + String email, String extCourseId, String countryIsoCode, String langIsoCode) throws UserInfoFetchException, UserInfoValidationException { if (log.isDebugEnabled()) { - log.debug("Adding user '" + username + "' as " + method + " to lesson with id '" + lesssonId + "'."); + log.debug("Adding user '" + username + "' as " + method + " to course with extCourseId '" + extCourseId + "'."); } ExtUserUseridMap userMap = null; @@ -890,11 +890,26 @@ } // adds user to group - ExtCourseClassMap orgMap = getExtCourseClassMap(extServer, userMap, courseId, null, method); + ExtCourseClassMap orgMap = getExtCourseClassMap(extServer, userMap, extCourseId, null, method); //TODO when merging to newer branch, check and maybe change to the following // getExtCourseClassMap(extServer, userMap, courseId, countryIsoCode, langIsoCode, null, // method); + return userMap; + } + + @Override + public ExtUserUseridMap addExtUserToCourseAndLesson(ExtServer extServer, String method, Long lesssonId, String username, + String firstName, String lastName, String email, String extCourseId, String countryIsoCode, String langIsoCode) + throws UserInfoFetchException, UserInfoValidationException { + + if (log.isDebugEnabled()) { + log.debug("Adding user '" + username + "' as " + method + " to lesson with id '" + lesssonId + "'."); + } + + ExtUserUseridMap userMap = addExtUserToCourse(extServer, method, username, firstName, lastName, email, extCourseId, + countryIsoCode, langIsoCode); + User user = userMap.getUser(); if (user == null) { String error = "Unable to add user to lesson class as user is missing from the user map"; @@ -953,7 +968,7 @@ } @Override - public void addExtUsersToLesson(ExtServer extServer, Long lessonId, String courseId, String resourceLinkId) + public void addUsersUsingMembershipService(ExtServer extServer, Long lessonId, String courseId, String resourceLinkId) throws IOException, UserInfoFetchException, UserInfoValidationException { String membershipUrl = extServer.getMembershipUrl(); @@ -968,16 +983,6 @@ log.debug("Make a call to remote membershipUrl:" + membershipUrl); HttpGet ltiServiceGetRequest = new HttpGet(membershipUrl); ltiServiceGetRequest.setHeader("Accept", "application/vnd.ims.lis.v2.membershipcontainer+json"); -// request.setEntity(new StringEntity(xml, "UTF-8")); -// ltiServiceGetRequest.setAdditionalParameters(parameters); -// if (empty($data)) { -// if (!empty($type)) { -// $header .= "\nAccept: {$type}"; -// } -// } else if (isset($type)) { -// $header .= "\nContent-Type: {$type}"; -// $header .= "\nContent-Length: " . strlen($data); -// } LtiSigner ltiSigner = new LtiOauthSigner(); try { @@ -1033,8 +1038,13 @@ String method = LtiUtils.isStaff(roles, extServer) || LtiUtils.isAdmin(roles) ? LoginRequestDispatcher.METHOD_MONITOR : LoginRequestDispatcher.METHOD_LEARNER; - ExtUserUseridMap extUser = addExtUserToLesson(extServer, method, lessonId, extUserId, firstName, lastName, - email, courseId, countryIsoCode, langIsoCode); + + //empty lessonId means we need to only add users to the course. Otherwise we add them to course AND lesson + ExtUserUseridMap extUser = lessonId == null + ? addExtUserToCourse(extServer, method, extUserId, firstName, lastName, email, courseId, + countryIsoCode, langIsoCode) + : addExtUserToCourseAndLesson(extServer, method, lessonId, extUserId, firstName, lastName, email, + courseId, countryIsoCode, langIsoCode); // If a result sourcedid is provided, save it to the user object JsonNode messages = membership.get("message");