Index: lams_central/src/java/org/lamsfoundation/lams/web/LoginRequestLtiServlet.java =================================================================== diff -u -rdcb3b94d9880535cd0c166204280928a8741faaf -r290f69ec4bba91e9bc91247e7633f44bd8dc0e5c --- lams_central/src/java/org/lamsfoundation/lams/web/LoginRequestLtiServlet.java (.../LoginRequestLtiServlet.java) (revision dcb3b94d9880535cd0c166204280928a8741faaf) +++ lams_central/src/java/org/lamsfoundation/lams/web/LoginRequestLtiServlet.java (.../LoginRequestLtiServlet.java) (revision 290f69ec4bba91e9bc91247e7633f44bd8dc0e5c) @@ -43,6 +43,9 @@ import org.lamsfoundation.lams.integration.service.IntegrationService; import org.lamsfoundation.lams.integration.util.IntegrationConstants; import org.lamsfoundation.lams.integration.util.LtiUtils; +import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.lesson.service.ILessonService; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; import org.lamsfoundation.lams.util.CentralConstants; import org.lamsfoundation.lams.util.HashUtil; import org.lamsfoundation.lams.util.WebUtil; @@ -62,6 +65,10 @@ @Autowired private IntegrationService integrationService = null; + @Autowired + private ILessonService lessonService; + @Autowired + private IUserManagementService userManagementService; private final String DEFAULT_FIRST_NAME = "John"; private final String DEFAULT_LAST_NAME = "Doe"; @@ -167,8 +174,6 @@ } else if (StringUtils.isBlank(lastName)) { lastName = " "; } - - ExtServerLessonMap lesson = integrationService.getLtiConsumerLesson(consumerKey, resourceLinkId); //Determine method based on the "role" parameter. Author roles can be either LTI standard ones or tool consumer's custom ones set //In case of ContentItemSelectionRequest user must still be a stuff member in order to create a lesson. @@ -178,8 +183,20 @@ ? IntegrationConstants.METHOD_AUTHOR : IntegrationConstants.METHOD_LEARNER_STRICT_AUTHENTICATION; - //provide empty lessonId in case of learner accesses LTI link before teacher authored it - String lessonId = lesson == null ? "" : lesson.getLessonId().toString(); + ExtServerLessonMap extLessonMap = integrationService.getLtiConsumerLesson(consumerKey, resourceLinkId); + if (extLessonMap == null) { + //if deep linking was used to create the lesson and it's accessed for the first time, try to get lessonId as "custom_lessonid" parameter + Long customLessonId = WebUtil.readLongParam(request, "custom_lessonid", true); + boolean isContentItemSelection = WebUtil.readBooleanParam(request, "custom_iscontentitemselection", false); + if (isContentItemSelection && customLessonId != null) { + //update its ExtServerLesson's resourceLinkId for the first time + extLessonMap = integrationService.getExtServerLessonMap(customLessonId); + extLessonMap.setResourceLinkId(resourceLinkId); + userManagementService.save(extLessonMap); + } + } + //lessonId would be empty in case learner accesses LTI link before teacher authored it + String lessonId = extLessonMap == null ? "" : extLessonMap.getLessonId().toString(); String timestamp = String.valueOf(System.currentTimeMillis()); Index: lams_central/src/java/org/lamsfoundation/lams/web/controller/LtiController.java =================================================================== diff -u -ra95da9a25304bdc449188c818764e1a40a982042 -r290f69ec4bba91e9bc91247e7633f44bd8dc0e5c --- lams_central/src/java/org/lamsfoundation/lams/web/controller/LtiController.java (.../LtiController.java) (revision a95da9a25304bdc449188c818764e1a40a982042) +++ lams_central/src/java/org/lamsfoundation/lams/web/controller/LtiController.java (.../LtiController.java) (revision 290f69ec4bba91e9bc91247e7633f44bd8dc0e5c) @@ -132,8 +132,7 @@ Integer currentOrganisationId = currentOrgMap.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). - //Otherwise this is the case of a first call after deep linking was used, and thus we need to update resourceLinkId, which was empty previously. + //(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(currentOrganisationId); if (isLessonCopyRequired) { @@ -146,15 +145,11 @@ Long newLessonId = monitoringService.cloneLesson(lesson.getLessonId(), creatorId, true, true, null, null, currentOrgMap.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 = integrationService.createExtServerLessonMap(newLessonId, extServer); - extLessonMap.setResourceLinkId(resourceLinkId); - userManagementService.save(extLessonMap); + 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