Index: lams_bb_integration/RELEASE_NOTES.TXT =================================================================== diff -u -r7b8276acaecb9871b6e169f3376c4ebcddeceb67 -r43d07bd0fe24199a988b13dae99c31e6b2dad6d8 --- lams_bb_integration/RELEASE_NOTES.TXT (.../RELEASE_NOTES.TXT) (revision 7b8276acaecb9871b6e169f3376c4ebcddeceb67) +++ lams_bb_integration/RELEASE_NOTES.TXT (.../RELEASE_NOTES.TXT) (revision 43d07bd0fe24199a988b13dae99c31e6b2dad6d8) @@ -103,4 +103,8 @@ 1.2.14 Release Fixes ==================== -* LDEV-3526: Adding further POST support. +* LDEV-3456: Adding further POST support. + +1.2.15 Release Fixes +==================== +* LDEV-3456: Adding new parameters to LAMSLearningDesign and StartLesson calls Index: lams_bb_integration/WEB-INF/bb-manifest.xml =================================================================== diff -u -r7b8276acaecb9871b6e169f3376c4ebcddeceb67 -r43d07bd0fe24199a988b13dae99c31e6b2dad6d8 --- lams_bb_integration/WEB-INF/bb-manifest.xml (.../bb-manifest.xml) (revision 7b8276acaecb9871b6e169f3376c4ebcddeceb67) +++ lams_bb_integration/WEB-INF/bb-manifest.xml (.../bb-manifest.xml) (revision 43d07bd0fe24199a988b13dae99c31e6b2dad6d8) @@ -5,7 +5,7 @@ - + Index: lams_bb_integration/build.xml =================================================================== diff -u -r7b8276acaecb9871b6e169f3376c4ebcddeceb67 -r43d07bd0fe24199a988b13dae99c31e6b2dad6d8 --- lams_bb_integration/build.xml (.../build.xml) (revision 7b8276acaecb9871b6e169f3376c4ebcddeceb67) +++ lams_bb_integration/build.xml (.../build.xml) (revision 43d07bd0fe24199a988b13dae99c31e6b2dad6d8) @@ -2,7 +2,7 @@ - + Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignServlet.java =================================================================== diff -u -r7b8276acaecb9871b6e169f3376c4ebcddeceb67 -r43d07bd0fe24199a988b13dae99c31e6b2dad6d8 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignServlet.java (.../LamsLearningDesignServlet.java) (revision 7b8276acaecb9871b6e169f3376c4ebcddeceb67) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignServlet.java (.../LamsLearningDesignServlet.java) (revision 43d07bd0fe24199a988b13dae99c31e6b2dad6d8) @@ -32,13 +32,10 @@ import org.lamsfoundation.ld.integration.Constants; import blackboard.base.InitializationException; -import blackboard.data.user.User; import blackboard.platform.BbServiceException; import blackboard.platform.BbServiceManager; import blackboard.platform.context.Context; import blackboard.platform.context.ContextManager; -import blackboard.platform.context.ContextManagerFactory; -import blackboard.platform.context.UserContext; /** * Makes a call to LAMS server to get learning designs and returns it. @@ -81,36 +78,17 @@ String sortDate = request.getParameter("sortDate"); String search = request.getParameter("search"); String type = request.getParameter("type"); + String username = request.getParameter("username"); // backup method to get user, when the Blackboard context does not have the user ContextManager ctxMgr = null; Context ctx = null; try { - // In some instances of calling this servlet, the user is missing from the context. Try a few different ways to ensure we have the user! - User user = null; - + // get Blackboard context ctxMgr = (ContextManager) BbServiceManager.lookupService(ContextManager.class); ctx = ctxMgr.setContext(request); - if ( ctx != null ) { - user = ctx.getUser(); - } - if ( user == null ) { - ctxMgr = ContextManagerFactory.getInstance(); - ctx=ctxMgr.setContext(request); - if ( ctx != null ) { - user = ctx.getUser(); - } - } - if ( user == null ) { - ctx = ContextManagerFactory.getInstance().getContext(); - if ( ctx !=null ) - user = ctx.getUser(); - } - if ( user == null ) - throw new RuntimeException("Unable to get user from context: cannot proceed to get Learning Designs"); - // we have a good context, now get on with the task. String method = usePaging ? "getPagedHomeLearningDesignsJSON" : "getLearningDesignsJSON"; - String learningDesigns = LamsSecurityUtil.getLearningDesigns(ctx, courseId, folderId, method, type, search, page, size, sortName, sortDate); + String learningDesigns = LamsSecurityUtil.getLearningDesigns(ctx, username, courseId, folderId, method, type, search, page, size, sortName, sortDate); response.setContentType("application/json;charset=UTF-8"); response.getWriter().print(learningDesigns); @@ -128,6 +106,5 @@ } } } - } Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsSecurityUtil.java =================================================================== diff -u -ra08111337692e8715b306e2a11218eb0b0b06e5b -r43d07bd0fe24199a988b13dae99c31e6b2dad6d8 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsSecurityUtil.java (.../LamsSecurityUtil.java) (revision a08111337692e8715b306e2a11218eb0b0b06e5b) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsSecurityUtil.java (.../LamsSecurityUtil.java) (revision 43d07bd0fe24199a988b13dae99c31e6b2dad6d8) @@ -33,7 +33,6 @@ import java.net.URL; import java.net.URLConnection; import java.net.URLEncoder; -import java.nio.charset.Charset; import java.rmi.RemoteException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -52,10 +51,13 @@ import blackboard.base.BbList; import blackboard.data.course.CourseMembership; +import blackboard.data.user.User; import blackboard.persist.BbPersistenceManager; import blackboard.persist.Id; +import blackboard.persist.KeyNotFoundException; import blackboard.persist.PersistenceException; import blackboard.persist.course.CourseMembershipDbLoader; +import blackboard.persist.user.UserDbLoader; import blackboard.platform.BbServiceManager; import blackboard.platform.context.Context; import blackboard.portal.data.ExtraInfo; @@ -128,7 +130,7 @@ // Even for authoring calls we still need a 'course' the user, role & organisation are all bound up together // do to be authorised to use authoring you must be in an organisation. - String courseId = setupCourseId(ctx, null); + String courseId = setupCourseId(ctx, null, true); String secretkey = LamsPluginUtil.getSecretKey(); @@ -227,13 +229,14 @@ * @return a string containing the LAMS workspace tree in tigra format */ public static String getLearningDesigns(Context ctx, String courseId, String folderId) { - return getLearningDesigns(ctx, courseId, folderId,"getLearningDesignsJSON",null,null,null,null,null,null); + return getLearningDesigns(ctx, null, courseId, folderId,"getLearningDesignsJSON",null,null,null,null,null,null); } /** - * Gets a list of learning designs & workspace folders for the current user from LAMS. + * Gets a list of learning designs & workspace folders for the current user from LAMS or the user "usernameFromParam" * * @param ctx the blackboard context, contains session data + * @param usernameFromParam only used if there isn't a user in the context, due to how the servlet is called * @param courseId blackboard course id. We pass it as a parameter as ctx.getCourse().getCourseId() is null when called * from LamsLearningDesignServlet. * @param folderId folderID in LAMS. It can be null and then LAMS returns default workspace folders. @@ -244,12 +247,12 @@ * @return a string containing the LAMS workspace tree in tigra format (method = getLearningDesignsJSON) or * a string containing the learning designs in JSON (method = getPagedHomeLearningDesignsJSON) */ - public static String getLearningDesigns(Context ctx, String urlCourseId, String folderId, String method, String type, + public static String getLearningDesigns(Context ctx, String usernameFromParam, String urlCourseId, String folderId, String method, String type, String search, String page, String size, String sortName, String sortDate) { String serverAddr = getServerAddress(); - String courseId = setupCourseId(ctx, urlCourseId); + String courseId = setupCourseId(ctx, urlCourseId, true); String serverId = getServerID(); // If lams.properties could not be read, throw exception @@ -258,13 +261,18 @@ } String timestamp = new Long(System.currentTimeMillis()).toString(); - String username = ctx.getUser().getUserName(); - String firstName = ctx.getUser().getGivenName(); - String lastName = ctx.getUser().getFamilyName(); - String email = ctx.getUser().getEmailAddress(); + + User user = ctx.getUser(); + if ( user == null ) + user = loadUserFromDB(ctx, usernameFromParam); + + String username = user.getUserName(); + String firstName = user.getGivenName(); + String lastName = user.getFamilyName(); + String email = user.getEmailAddress(); String hash = generateAuthenticationHash(timestamp, username, serverId); - String locale = ctx.getUser().getLocale(); + String locale = user.getLocale(); String country = getCountry(locale); String lang = getLanguage(locale); @@ -340,6 +348,22 @@ return learningDesigns; } + private static User loadUserFromDB(Context ctx, String username) { + User user = null; + try { + final UserDbLoader userDbLoader = UserDbLoader.Default.getInstance(); + user = userDbLoader.loadByUserName(username); + } catch (KeyNotFoundException e) { + throw new RuntimeException("No user details found in context or via username parameter. Unable access LAMS. "+e.getMessage()+" Username "+username+" Ctx "+ctx,e); + } catch (PersistenceException e) { + throw new RuntimeException("No user details found in context or via username parameter. Unable access LAMS. "+e.getMessage()+" Username "+username+" Ctx "+ctx,e); + } + if ( user == null ) { + throw new RuntimeException("No user details found in context or via username parameter. Unable access LAMS. Username "+username+" Ctx "+ctx); + } + return user; + } + /** * Gets a list of learning designs & workspace folders for the current user from LAMS. * @@ -351,7 +375,7 @@ */ public static String deleteLearningDesigns(Context ctx, String urlCourseId, Long ldId) { - String courseId = setupCourseId(ctx, urlCourseId); + String courseId = setupCourseId(ctx, urlCourseId, false); String serverAddr = getServerAddress(); String serverId = getServerID(); @@ -408,17 +432,17 @@ } } - private static String setupCourseId(Context ctx, String urlCourseId) { + private static String setupCourseId(Context ctx, String urlCourseId, boolean allowUserDummyCourse) { // can we pull the alphanumeric course id from the context, rather than the on passed in from the URL? If neither exist, use the dummy Preview course. String courseId = null; if ( ctx.getCourse()!=null ) courseId = ctx.getCourse().getCourseId(); - if ( courseId == null ) - courseId = urlCourseId != null && urlCourseId.length() > 0 ? urlCourseId : DUMMY_COURSE; + if ( courseId == null && urlCourseId != null && urlCourseId.length() > 0) + courseId = urlCourseId; + if ( courseId == null && allowUserDummyCourse ) + courseId = DUMMY_COURSE; return courseId; } - - /** * Starts lessons in lams through a LAMS webservice * @@ -434,27 +458,51 @@ * @return the learning session id */ public static Long startLesson(Context ctx, long ldId, String title, String desc, boolean isPreview) { + return startLesson(ctx, null, null, ldId, title, desc, isPreview); + } + /** + * Starts lessons in lams through a LAMS webservice using the username & courseId parameter, needed + * when there won't be a user / courseId in the context. + * + * @param ctx + * the blackboard contect, contains session data + * @param usernameFromParam + * current user's username as a request parameter + * @param courseIdStr + * courseId as a request parameter + * @param ldId + * the learning design id for which you wish to start a lesson + * @param title + * the title of the lesson + * @param desc + * the description of the lesson + * + * @return the learning session id + */ + public static Long startLesson(Context ctx, String usernameFromParam, String courseIdStr, long ldId, String title, String desc, boolean isPreview) { + String serverId = getServerID(); String serverAddr = getServerAddress(); String serverKey = getServerKey(); - String username = ctx.getUser().getUserName(); - String locale = ctx.getUser().getLocale(); + + User user = ctx.getUser(); + if ( user == null ) + user = loadUserFromDB(ctx, usernameFromParam); + + String username = user.getUserName(); + String locale = user.getLocale(); String country = getCountry(locale); String lang = getLanguage(locale); String method = (isPreview) ? "preview" : "start"; - // courseId aways needed to check roles + // courseId always needed to check roles // if it is preview, then can use the DUMMY_COURSE - String courseId = null; - if ( isPreview ) - courseId = ctx.getCourse()!=null ? ctx.getCourse().getCourseId() : DUMMY_COURSE; - else - courseId = ctx.getCourse().getCourseId(); + String courseId = setupCourseId(ctx, courseIdStr, isPreview); if (courseId == null || serverId == null || serverAddr == null || serverKey == null) { logger.info("Unable to start lesson, one or more lams configuration properties or the course id is null"); - throw new RuntimeException("Unable to start lesson, one or more lams configuration properties or the course id is null"); + throw new RuntimeException("Unable to start lesson, one or more lams configuration properties or the course id is null. courseId="+courseId); } try { Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/StartLessonServlet.java =================================================================== diff -u -r7b8276acaecb9871b6e169f3376c4ebcddeceb67 -r43d07bd0fe24199a988b13dae99c31e6b2dad6d8 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/StartLessonServlet.java (.../StartLessonServlet.java) (revision 7b8276acaecb9871b6e169f3376c4ebcddeceb67) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/StartLessonServlet.java (.../StartLessonServlet.java) (revision 43d07bd0fe24199a988b13dae99c31e6b2dad6d8) @@ -33,20 +33,16 @@ import org.lamsfoundation.ld.util.LineitemUtil; import blackboard.base.FormattedText; -import blackboard.base.InitializationException; import blackboard.data.content.Content; import blackboard.data.content.CourseDocument; import blackboard.data.course.Course; -import blackboard.data.user.User; import blackboard.persist.BbPersistenceManager; import blackboard.persist.Id; import blackboard.persist.PkId; import blackboard.persist.content.ContentDbPersister; -import blackboard.platform.BbServiceException; import blackboard.platform.BbServiceManager; import blackboard.platform.context.Context; import blackboard.platform.context.ContextManager; -import blackboard.platform.context.ContextManagerFactory; import blackboard.platform.plugin.PlugInException; import blackboard.platform.plugin.PlugInUtil; import blackboard.portal.data.ExtraInfo; @@ -76,30 +72,9 @@ ContextManager ctxMgr = null; Context ctx = null; try { - // In some instances of calling this servlet, the user is missing from the context. Try a few different ways to ensure we have the user! - User user = null; - + // get Blackboard context ctxMgr = (ContextManager) BbServiceManager.lookupService(ContextManager.class); ctx = ctxMgr.setContext(request); - if ( ctx != null ) { - user = ctx.getUser(); - } - if ( user == null ) { - ctxMgr = ContextManagerFactory.getInstance(); - ctx=ctxMgr.setContext(request); - if ( ctx != null ) { - user = ctx.getUser(); - } - } - if ( user == null ) { - ctx = ContextManagerFactory.getInstance().getContext(); - if ( ctx !=null ) - user = ctx.getUser(); - } - if ( user == null ) - throw new RuntimeException("Unable to get user from context: cannot proceed to get Learning Designs"); - - // we have a good context, now get on with the task. // Set the new LAMS Lesson Content Object CourseDocument bbContent = new blackboard.data.content.CourseDocument(); @@ -119,6 +94,7 @@ String contentIdStr = request.getParameter("content_id"); String strTitle = getTrimmedString(request,"title"); String strSequenceID = getTrimmedString(request,"sequence_id"); + String username = request.getParameter("username"); if ( courseIdStr == null || contentIdStr == null || strSequenceID.length()==0 || strTitle.length() == 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, @@ -196,7 +172,7 @@ bbContent.setPosition(0); // Start the Lesson in LAMS (via Webservices) and capture the lesson ID - final long LamsLessonIdLong = LamsSecurityUtil.startLesson(ctx, ldId, strTitle, strDescription, false); + final long LamsLessonIdLong = LamsSecurityUtil.startLesson(ctx, username, courseIdStr, ldId, strTitle, strDescription, false); // error checking if (LamsLessonIdLong == -1) { response.sendRedirect("lamsServerDown.jsp"); @@ -265,32 +241,5 @@ return value != null ? value.trim() : ""; } - // In some instances of calling this servlet, the user is missing from the context. Try a few different ways to ensure we have the user! - private Context getContext(HttpServletRequest request) throws InitializationException, BbServiceException { - - User user = null; - - ContextManager ctxMgr = (ContextManager) BbServiceManager.lookupService(ContextManager.class); - Context ctx = ctxMgr.setContext(request); - if ( ctx != null ) { - user = ctx.getUser(); - } - if ( user == null ) { - final ContextManager contextManagerViaFactory = ContextManagerFactory.getInstance(); - ctx=contextManagerViaFactory.setContext(request); - if ( ctx != null ) { - user = ctx.getUser(); - } - } - if ( user == null ) { - ctx = ContextManagerFactory.getInstance().getContext(); - if ( ctx !=null ) - user = ctx.getUser(); - } - if ( user != null ) - return ctx; - else - throw new RuntimeException("Unable to get user from context: cannot proceed to get Learning Designs"); - } }