Index: lams_central/src/java/org/lamsfoundation/lams/web/controller/LtiController.java =================================================================== diff -u -rf2ad75cef0c507a64877942631fee13efbc6ed50 -r39c16d5d248419593b4012a0b9adb0adca43970d --- lams_central/src/java/org/lamsfoundation/lams/web/controller/LtiController.java (.../LtiController.java) (revision f2ad75cef0c507a64877942631fee13efbc6ed50) +++ lams_central/src/java/org/lamsfoundation/lams/web/controller/LtiController.java (.../LtiController.java) (revision 39c16d5d248419593b4012a0b9adb0adca43970d) @@ -6,8 +6,10 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; +import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.Vector; @@ -33,6 +35,7 @@ import org.lamsfoundation.lams.lesson.LearnerProgress; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.lesson.dto.LearnerProgressDTO; +import org.lamsfoundation.lams.lesson.dto.LessonDetailsDTO; import org.lamsfoundation.lams.lesson.service.ILessonService; import org.lamsfoundation.lams.monitoring.service.IMonitoringService; import org.lamsfoundation.lams.security.ISecurityService; @@ -91,28 +94,60 @@ String resourceLinkId = request.getParameter(BasicLTIConstants.RESOURCE_LINK_ID); String tcGradebookId = request.getParameter(BasicLTIConstants.LIS_RESULT_SOURCEDID); String extUserId = request.getParameter(BasicLTIConstants.USER_ID); + Long customLessonId = WebUtil.readLongParam(request, "custom_lessonid", true); + boolean isContentItemSelection = WebUtil.readBooleanParam(request, "custom_iscontentitemselection", false); - ExtServerLessonMap lesson = integrationService.getLtiConsumerLesson(consumerKey, resourceLinkId); - //support for ContentItemSelectionRequest. If lesson was created during such request, update its ExtServerLesson's resourceLinkId for the first time - boolean isContentItemSelection = WebUtil.readBooleanParam(request, "custom_isContentItemSelection", false); - if (lesson == null && isContentItemSelection) { - Long lessonId = WebUtil.readLongParam(request, "custom_lessonId"); - lesson = integrationService.getExtServerLessonMap(lessonId); - lesson.setResourceLinkId(resourceLinkId); - userManagementService.save(lesson); + ExtServerLessonMap extLessonMap = integrationService.getLtiConsumerLesson(consumerKey, resourceLinkId); + ExtServer extServer = integrationService.getExtServer(consumerKey); + +// log.info("" request.getParameter(name)); + Map params = request.getParameterMap(); + Iterator i = params.keySet().iterator(); + while (i.hasNext()) { + String key = (String) i.next(); + String value = ((String[]) params.get(key))[0]; + log.info("#### Parameter " + key + ": " + value); } + + //it's the case of ContentItemSelection request or course-copy. (Currently we support course-copy only for links created using ContentItemSelection) + if (extLessonMap == null && (customLessonId != null) && isContentItemSelection) { + Lesson lesson = lessonService.getLesson(customLessonId); + String extCourseId = request.getParameter(BasicLTIConstants.CONTEXT_ID); + ExtCourseClassMap orgMap = integrationService.getExtCourseClassMap(extServer.getSid(), extCourseId); + Integer organisationId = orgMap.getOrganisation().getOrganisationId(); + + //check if the new lesson should be created after course copy, that potentially has happened on LMS side. + //(we can detect it by comparing orgId of the custom_lessonid's organisation and CONTEXT_ID's one) + boolean isLessonCopyRequired = lesson.getOrganisation() != null + && !lesson.getOrganisation().getOrganisationId().equals(organisationId); + if (isLessonCopyRequired) { + // clone lesson + Integer creatorId = lesson.getUser().getUserId(); + Long newLessonId = monitoringService.cloneLesson(customLessonId, creatorId, true, true, null, null, + orgMap.getOrganisation()); + // store information which extServer has started the lesson + extLessonMap = integrationService.createExtServerLessonMap(newLessonId, extServer); + + } else { + //support for ContentItemSelectionRequest. If lesson was created during such request, update its ExtServerLesson's resourceLinkId for the first time + extLessonMap = integrationService.getExtServerLessonMap(customLessonId); + } + + extLessonMap.setResourceLinkId(resourceLinkId); + userManagementService.save(extLessonMap); + } + //update lessonFinishCallbackUrl. We store it one time during the very first call to LAMS and it stays the same all the time afterwards String lessonFinishCallbackUrl = request.getParameter(BasicLTIConstants.LIS_OUTCOME_SERVICE_URL); - ExtServer extServer = integrationService.getExtServer(consumerKey); if (StringUtils.isNotBlank(lessonFinishCallbackUrl) && StringUtils.isBlank(extServer.getLessonFinishUrl())) { extServer.setLessonFinishUrl(lessonFinishCallbackUrl); userManagementService.save(extServer); } //check if learner tries to access the link that hasn't been authored by teacher yet String method = request.getParameter("_" + LoginRequestDispatcher.PARAM_METHOD); - if (LoginRequestDispatcher.METHOD_LEARNER_STRICT_AUTHENTICATION.equals(method) && lesson == null) { + if (LoginRequestDispatcher.METHOD_LEARNER_STRICT_AUTHENTICATION.equals(method) && extLessonMap == null) { String errorMsg = "Learner tries to access the link that hasn't been authored by teacher yet. resource_link_id: " + tcGradebookId; log.debug(errorMsg); @@ -122,7 +157,7 @@ } //determine whether to show author or learnerMonitor pages - if (lesson == null) { + if (extLessonMap == null) { return addLesson(request, respnse); } else { @@ -152,8 +187,8 @@ String resourceLinkDescription = request.getParameter(BasicLTIConstants.RESOURCE_LINK_DESCRIPTION); ExtServer extServer = integrationService.getExtServer(consumerKey); - ExtCourseClassMap orgMap = integrationService.getExtCourseClassMap(extServer.getSid(), contextId); - Integer organisationId = orgMap.getOrganisation().getOrganisationId(); + ExtCourseClassMap extCourse = integrationService.getExtCourseClassMap(extServer.getSid(), contextId); + Integer organisationId = extCourse.getOrganisation().getOrganisationId(); //only monitors are allowed to create lesson if (!securityService.isGroupMonitor(organisationId, userId, "add lesson", false)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the organisation"); @@ -205,7 +240,7 @@ String desc = request.getParameter(CentralConstants.PARAM_DESC); String ldIdStr = request.getParameter(CentralConstants.PARAM_LEARNING_DESIGN_ID); String contextId = request.getParameter(BasicLTIConstants.CONTEXT_ID); - Integer organisationId = new Integer(WebUtil.readIntParam(request, CentralConstants.ATTR_COURSE_ID)); + Integer organisationId = WebUtil.readIntParam(request, CentralConstants.ATTR_COURSE_ID); boolean enableLessonIntro = WebUtil.readBooleanParam(request, "enableLessonIntro", false); //only monitors are allowed to create lesson @@ -368,12 +403,6 @@ String consumerKey = request.getParameter(LtiUtils.OAUTH_CONSUMER_KEY); String resourceLinkId = request.getParameter(BasicLTIConstants.RESOURCE_LINK_ID); - //get orgId -// String contextId = request.getParameter(BasicLTIConstants.CONTEXT_ID); -// ExtServer extServer = integrationService.getExtServer(consumerKey); -// ExtCourseClassMap orgMap = integrationService.getExtCourseClassMap(extServer.getSid(), contextId); -// Integer organisationId = orgMap.getOrganisation().getOrganisationId(); - //get lesson ExtServerLessonMap extLesson = integrationService.getLtiConsumerLesson(consumerKey, resourceLinkId); Long lessonId = extLesson.getLessonId(); Index: lams_common/src/java/org/lamsfoundation/lams/integration/service/IIntegrationService.java =================================================================== diff -u -ra5bb8ab1bbc5f6732acef6132286e89c80f2e8f3 -r39c16d5d248419593b4012a0b9adb0adca43970d --- lams_common/src/java/org/lamsfoundation/lams/integration/service/IIntegrationService.java (.../IIntegrationService.java) (revision a5bb8ab1bbc5f6732acef6132286e89c80f2e8f3) +++ lams_common/src/java/org/lamsfoundation/lams/integration/service/IIntegrationService.java (.../IIntegrationService.java) (revision 39c16d5d248419593b4012a0b9adb0adca43970d) @@ -187,7 +187,7 @@ * @param lessonId * @param extServer */ - void createExtServerLessonMap(Long lessonId, ExtServer extServer); + ExtServerLessonMap createExtServerLessonMap(Long lessonId, ExtServer extServer); /** * Creates new ExtServerLessonMap object. Method is suitable for creating lessons via LTI tool consumers as long as @@ -198,7 +198,7 @@ * resource_link_id parameter sent by LTI tool consumer * @param extServer */ - void createExtServerLessonMap(Long lessonId, String resourceLinkId, ExtServer extServer); + ExtServerLessonMap createExtServerLessonMap(Long lessonId, String resourceLinkId, ExtServer extServer); /** * Checks whether the lesson was created from extServer and returns lessonFinishCallbackUrl if it's not blank. Index: lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java =================================================================== diff -u -ra5bb8ab1bbc5f6732acef6132286e89c80f2e8f3 -r39c16d5d248419593b4012a0b9adb0adca43970d --- lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java (.../IntegrationService.java) (revision a5bb8ab1bbc5f6732acef6132286e89c80f2e8f3) +++ lams_common/src/java/org/lamsfoundation/lams/integration/service/IntegrationService.java (.../IntegrationService.java) (revision 39c16d5d248419593b4012a0b9adb0adca43970d) @@ -606,18 +606,18 @@ } @Override - public void createExtServerLessonMap(Long lessonId, ExtServer extServer) { - createExtServerLessonMap(lessonId, null, extServer); - ; + public ExtServerLessonMap createExtServerLessonMap(Long lessonId, ExtServer extServer) { + return createExtServerLessonMap(lessonId, null, extServer); } @Override - public void createExtServerLessonMap(Long lessonId, String resourceLinkId, ExtServer extServer) { + public ExtServerLessonMap createExtServerLessonMap(Long lessonId, String resourceLinkId, ExtServer extServer) { ExtServerLessonMap map = new ExtServerLessonMap(); map.setLessonId(lessonId); map.setResourceLinkId(resourceLinkId); map.setExtServer(extServer); service.save(map); + return map; } @Override