Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/ImportLessonsServlet.java =================================================================== diff -u -radc0d80ed42274e4f08b4dbd588f50eb1715cd39 -r4cbb8f0a143a5ceed24a3de664315b501a8cbbdf --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/ImportLessonsServlet.java (.../ImportLessonsServlet.java) (revision adc0d80ed42274e4f08b4dbd588f50eb1715cd39) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/ImportLessonsServlet.java (.../ImportLessonsServlet.java) (revision 4cbb8f0a143a5ceed24a3de664315b501a8cbbdf) @@ -106,13 +106,12 @@ logger.debug("Lesson (lessonId=" + urlLessonId + ") was successfully imported to the one (learningDesignId=" + newLdId + ")."); - // Start the Lesson in LAMS (via Webservices) and capture the lesson ID - String teacherUsername = teacher.getUserName(); + // Start the Lesson in LAMS (via Webservices) and get back the lesson ID String title = content.getTitle(); FormattedText descriptionFormatted = content.getBody(); String description = URLEncoder.encode(descriptionFormatted.getText(), "UTF-8"); - final long newLessonId = LamsSecurityUtil.startLesson(ctx, teacherUsername, courseIdParam, newLdId, - title, description, false); + final long newLessonId = LamsSecurityUtil.startLesson(teacher, courseIdParam, newLdId, title, + description, false); // update lesson id content.setLinkRef(Long.toString(newLessonId)); Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/StartLessonServlet.java =================================================================== diff -u -r67bf7cc2eed9d841593d383cf139d63a65e1a8a6 -r4cbb8f0a143a5ceed24a3de664315b501a8cbbdf --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/StartLessonServlet.java (.../StartLessonServlet.java) (revision 67bf7cc2eed9d841593d383cf139d63a65e1a8a6) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/StartLessonServlet.java (.../StartLessonServlet.java) (revision 4cbb8f0a143a5ceed24a3de664315b501a8cbbdf) @@ -22,42 +22,22 @@ */ import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.Calendar; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; -import org.lamsfoundation.ld.integration.util.LamsPluginUtil; -import org.lamsfoundation.ld.integration.util.LamsSecurityUtil; -import org.lamsfoundation.ld.integration.util.LineitemUtil; +import org.lamsfoundation.ld.integration.util.BlackboardUtil; -import blackboard.base.FormattedText; -import blackboard.data.content.Content; -import blackboard.data.content.CourseDocument; -import blackboard.data.course.Course; -import blackboard.persist.BbPersistenceManager; -import blackboard.persist.Id; -import blackboard.persist.PkId; -import blackboard.persist.content.ContentDbPersister; +import blackboard.data.user.User; import blackboard.platform.BbServiceManager; -import blackboard.platform.context.Context; import blackboard.platform.context.ContextManager; -import blackboard.platform.persistence.PersistenceServiceFactory; -import blackboard.platform.plugin.PlugInException; -import blackboard.platform.plugin.PlugInUtil; -import blackboard.portal.data.ExtraInfo; -import blackboard.portal.data.PortalExtraInfo; -import blackboard.portal.servlet.PortalUtil; /** * Starts a lesson, returning the BB Content Id in JSON. Based on start_lesson_proc but uses the username * parameter as a basis for identifying the user. * Return a server error rather than throw an exception as this will be consumed by AJAX call or the like. - * - * TODO create a common methods util class with start_lesson_proc.jsp */ public class StartLessonServlet extends HttpServlet { @@ -75,150 +55,27 @@ protected void process(HttpServletRequest request, HttpServletResponse response) throws IOException { ContextManager ctxMgr = null; - Context ctx = null; try { // get Blackboard context ctxMgr = (ContextManager) BbServiceManager.lookupService(ContextManager.class); - ctx = ctxMgr.setContext(request); - // Set the new LAMS Lesson Content Object - CourseDocument bbContent = new blackboard.data.content.CourseDocument(); - - // Retrieve the Db persistence manager from the persistence service - BbPersistenceManager bbPm = PersistenceServiceFactory.getInstance().getDbPersistenceManager(); - String courseIdStr = request.getParameter("course_id"); String contentIdStr = request.getParameter("content_id"); - String strTitle = getTrimmedString(request,"title"); - String strSequenceID = getTrimmedString(request,"sequence_id"); - String username = request.getParameter("username"); + String strTitle = BlackboardUtil.getTrimmedString(request, "title"); + String strSequenceID = BlackboardUtil.getTrimmedString(request, "sequence_id"); if ( courseIdStr == null || contentIdStr == null || strSequenceID.length()==0 || strTitle.length() == 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unable to create error - parameter missing. course_id, content_id, sequence_id and title required"); - } else { - - // Internal Blackboard IDs for the course and parent content item - Id courseId = bbPm.generateId(Course.DATA_TYPE, courseIdStr); - Id folderId = bbPm.generateId(CourseDocument.DATA_TYPE, contentIdStr); - - // Get the form parameters and convert into correct data types - // TODO: Use bb text area instead - String strDescription = getTrimmedString(request,"descriptiontext"); - FormattedText description = new FormattedText(strDescription, FormattedText.Type.HTML); - - long ldId = Long.parseLong(strSequenceID); - - String strIsAvailable = request.getParameter("isAvailable"); - String strIsGradecenter = request.getParameter("isGradecenter"); - String strIsTracked = request.getParameter("isTracked"); - boolean isAvailable = (strIsAvailable == null || strIsAvailable.equals("true")) ? true : false; // default true - boolean isGradecenter = (strIsGradecenter != null && strIsGradecenter.equals("true")) ? true : false; // default - // false - boolean isTracked = (strIsTracked != null && strIsTracked.equals("true")) ? true : false; // default false - - String isDisplayDesignImage = request.getParameter("isDisplayDesignImage"); - - // Set Availability Dates - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - // Start Date - String strStartDate = request.getParameter("lessonAvailability_start_datetime"); - if (strStartDate != null) { - Calendar startDate = Calendar.getInstance(); - startDate.setTime(formatter.parse(strStartDate)); - String strStartDateCheckbox = request.getParameter("lessonAvailability_start_checkbox"); - if (strStartDateCheckbox != null) { - if (strStartDateCheckbox.equals("1")) { - bbContent.setStartDate(startDate); - } - } - } - - // End Date - String strEndDate = request.getParameter("lessonAvailability_end_datetime"); - if (strEndDate != null) { - Calendar endDate = Calendar.getInstance(); - endDate.setTime(formatter.parse(strEndDate)); - String strEndDateCheckbox = request.getParameter("lessonAvailability_end_checkbox"); - if (strEndDateCheckbox != null) { - if (strEndDateCheckbox.equals("1")) { - bbContent.setEndDate(endDate); - } - } - } - - // Set the New LAMS Lesson content data (in Blackboard) - bbContent.setTitle(strTitle); - bbContent.setIsAvailable(isAvailable); - bbContent.setIsDescribed(isGradecenter);// isDescribed field is used for storing isGradecenter parameter - bbContent.setIsTracked(isTracked); - bbContent.setAllowGuests(false); - bbContent.setContentHandler(LamsPluginUtil.CONTENT_HANDLE); - - bbContent.setCourseId(courseId); - bbContent.setParentId(folderId); - - bbContent.setRenderType(Content.RenderType.URL); - bbContent.setBody(description); - - // LDEV-3510 LAMS Lessons were always at the top and could not be moved. - bbContent.setPosition(0); - - // Start the Lesson in LAMS (via Webservices) and capture the lesson ID - final long LamsLessonIdLong = LamsSecurityUtil.startLesson(ctx, username, courseIdStr, ldId, strTitle, strDescription, false); - // error checking - if (LamsLessonIdLong == -1) { - response.sendRedirect("lamsServerDown.jsp"); - System.exit(1); - } - String lamsLessonId = Long.toString(LamsLessonIdLong); - bbContent.setLinkRef(lamsLessonId); - - // Persist the New Lesson Object in Blackboard - ContentDbPersister persister = (ContentDbPersister) bbPm.getPersister(ContentDbPersister.TYPE); - persister.persist(bbContent); - PkId bbContentPkId = (PkId) bbContent.getId(); - String bbContentId = "_" + bbContentPkId.getPk1() + "_" + bbContentPkId.getPk2(); - - // Build and set the content URL. Include new lesson id parameter - int bbport = request.getServerPort();// Add port to the url if the port is in the blackboard url. - String bbportstr = bbport != 0 ? ":" + bbport : ""; - String contentUrl = request.getScheme() + "://" + request.getServerName() + bbportstr - + request.getContextPath() + "/modules/learnermonitor.jsp?lsid=" + lamsLessonId + "&course_id=" - + request.getParameter("course_id") + "&content_id=" + bbContentId + "&ldid=" + ldId - + "&isDisplayDesignImage=" + isDisplayDesignImage; - bbContent.setUrl(contentUrl); - persister.persist(bbContent); - - // store internalContentId -> externalContentId. It's used for GradebookServlet - PortalExtraInfo pei = PortalUtil.loadPortalExtraInfo(null, null, "LamsStorage"); - ExtraInfo ei = pei.getExtraInfo(); - ei.setValue(bbContentId, lamsLessonId); - PortalUtil.savePortalExtraInfo(pei); - - // Create new Gradebook column for current lesson - if (isGradecenter) { - String userName = ctx.getUser().getUserName(); - LineitemUtil.createLineitem(bbContent, ctx, userName); - } - - String strReturnUrl = PlugInUtil.getEditableContentReturnURL(bbContent.getParentId(), courseId); - - // create a new thread to pre-add students and monitors to a lesson (in order to do this task in parallel not to - // slow down later work) - final Context ctxFinal = ctx; - Thread preaddLearnersMonitorsThread = new Thread(new Runnable() { - @Override - public void run() { - LamsSecurityUtil.preaddLearnersMonitorsToLesson(ctxFinal, LamsLessonIdLong); - } - }, "LAMS_preaddLearnersMonitors_thread"); - preaddLearnersMonitorsThread.start(); - - response.setContentType("application/json;charset=UTF-8"); - response.getWriter().print("{\"content_id\":"+bbContentId+"}"); + + String username = request.getParameter("username"); + User user = BlackboardUtil.loadUserFromDB(username); + + String bbContentId = BlackboardUtil.storeBlackboardContent(request, response, user); + + response.setContentType("application/json;charset=UTF-8"); + response.getWriter().print("{\"content_id\":" + bbContentId + "}"); } } catch (Exception e) { @@ -233,10 +90,5 @@ } - private String getTrimmedString(HttpServletRequest request, String paramName) { - String value = request.getParameter(paramName); - return value != null ? value.trim() : ""; - } - } Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/util/BlackboardUtil.java =================================================================== diff -u -radc0d80ed42274e4f08b4dbd588f50eb1715cd39 -r4cbb8f0a143a5ceed24a3de664315b501a8cbbdf --- lams_bb_integration/src/org/lamsfoundation/ld/integration/util/BlackboardUtil.java (.../BlackboardUtil.java) (revision adc0d80ed42274e4f08b4dbd588f50eb1715cd39) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/util/BlackboardUtil.java (.../BlackboardUtil.java) (revision 4cbb8f0a143a5ceed24a3de664315b501a8cbbdf) @@ -1,19 +1,38 @@ package org.lamsfoundation.ld.integration.util; +import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; import java.util.List; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + import blackboard.base.BbList; +import blackboard.base.FormattedText; +import blackboard.data.ValidationException; import blackboard.data.content.Content; +import blackboard.data.content.CourseDocument; +import blackboard.data.course.Course; import blackboard.data.course.CourseMembership; import blackboard.data.navigation.CourseToc; import blackboard.data.user.User; +import blackboard.persist.BbPersistenceManager; import blackboard.persist.Id; +import blackboard.persist.KeyNotFoundException; import blackboard.persist.PersistenceException; import blackboard.persist.PkId; import blackboard.persist.content.ContentDbLoader; +import blackboard.persist.content.ContentDbPersister; import blackboard.persist.course.CourseMembershipDbLoader; import blackboard.persist.navigation.CourseTocDbLoader; +import blackboard.persist.user.UserDbLoader; +import blackboard.platform.persistence.PersistenceServiceFactory; +import blackboard.portal.data.ExtraInfo; +import blackboard.portal.data.PortalExtraInfo; +import blackboard.portal.servlet.PortalUtil; /** * Set of utilities dealing with Blackboard data. @@ -91,8 +110,167 @@ } } } - + return lamsContents; } + /** + * @throws ParseException + * @throws IOException + * @throws ValidationException + */ + public static String storeBlackboardContent(HttpServletRequest request, HttpServletResponse response, User user) + throws PersistenceException, ParseException, IOException, ValidationException { + + // Set the new LAMS Lesson Content Object + CourseDocument bbContent = new blackboard.data.content.CourseDocument(); + // Retrieve the Db persistence manager from the persistence service + BbPersistenceManager bbPm = PersistenceServiceFactory.getInstance().getDbPersistenceManager(); + + String courseIdStr = request.getParameter("course_id"); + String contentIdStr = request.getParameter("content_id"); + String strTitle = getTrimmedString(request, "title"); + String strSequenceID = getTrimmedString(request, "sequence_id"); + // TODO: Use bb text area instead + String strDescription = getTrimmedString(request, "descriptiontext"); + String strIsAvailable = request.getParameter("isAvailable"); + String strIsGradecenter = request.getParameter("isGradecenter"); + String strIsTracked = request.getParameter("isTracked"); + String isDisplayDesignImage = request.getParameter("isDisplayDesignImage"); + + // Internal Blackboard IDs for the course and parent content item + Id courseId = bbPm.generateId(Course.DATA_TYPE, courseIdStr); + Id folderId = bbPm.generateId(CourseDocument.DATA_TYPE, contentIdStr); + + FormattedText description = new FormattedText(strDescription, FormattedText.Type.HTML); + long ldId = Long.parseLong(strSequenceID); + + boolean isAvailable = (strIsAvailable == null || strIsAvailable.equals("true")) ? true : false; // default true + boolean isGradecenter = (strIsGradecenter != null && strIsGradecenter.equals("true")) ? true : false; // default false + boolean isTracked = (strIsTracked != null && strIsTracked.equals("true")) ? true : false; // default false + + // Set Availability Dates + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + // Start Date + String strStartDate = request.getParameter("lessonAvailability_start_datetime"); + if (strStartDate != null) { + Calendar startDate = Calendar.getInstance(); + startDate.setTime(formatter.parse(strStartDate)); + String strStartDateCheckbox = request.getParameter("lessonAvailability_start_checkbox"); + if (strStartDateCheckbox != null) { + if (strStartDateCheckbox.equals("1")) { + bbContent.setStartDate(startDate); + } + } + } + + // End Date + String strEndDate = request.getParameter("lessonAvailability_end_datetime"); + if (strEndDate != null) { + Calendar endDate = Calendar.getInstance(); + endDate.setTime(formatter.parse(strEndDate)); + String strEndDateCheckbox = request.getParameter("lessonAvailability_end_checkbox"); + if (strEndDateCheckbox != null) { + if (strEndDateCheckbox.equals("1")) { + bbContent.setEndDate(endDate); + } + } + } + + // Set the New LAMS Lesson content data (in Blackboard) + bbContent.setTitle(strTitle); + bbContent.setIsAvailable(isAvailable); + bbContent.setIsDescribed(isGradecenter);// isDescribed field is used for storing isGradecenter parameter + bbContent.setIsTracked(isTracked); + bbContent.setAllowGuests(false); + bbContent.setContentHandler(LamsPluginUtil.CONTENT_HANDLE); + + bbContent.setCourseId(courseId); + bbContent.setParentId(folderId); + + bbContent.setRenderType(Content.RenderType.URL); + bbContent.setBody(description); + + // LDEV-3510 LAMS Lessons were always at the top and could not be moved. + //bbContent.setPosition(0); + + // Start the Lesson in LAMS (via Webservices) and capture the lesson ID + final long LamsLessonIdLong = LamsSecurityUtil.startLesson(user, courseIdStr, ldId, strTitle, strDescription, + false); + // error checking + if (LamsLessonIdLong == -1) { + response.sendRedirect("lamsServerDown.jsp"); + System.exit(1); + } + String lamsLessonId = Long.toString(LamsLessonIdLong); + bbContent.setLinkRef(lamsLessonId); + + // Persist the New Lesson Object in Blackboard + ContentDbPersister persister = (ContentDbPersister) bbPm.getPersister(ContentDbPersister.TYPE); + persister.persist(bbContent); + PkId bbContentPkId = (PkId) bbContent.getId(); + String bbContentId = "_" + bbContentPkId.getPk1() + "_" + bbContentPkId.getPk2(); + + // Build and set the content URL. Include new lesson id parameter + int bbport = request.getServerPort();// Add port to the url if the port is in the blackboard url. + String bbportstr = bbport != 0 ? ":" + bbport : ""; + String contentUrl = request.getScheme() + "://" + + request.getServerName() + bbportstr + request.getContextPath() + "/modules/learnermonitor.jsp" + + "?lsid=" + lamsLessonId + + "&course_id=" + request.getParameter("course_id") + + "&content_id=" + bbContentId + + "&ldid=" + ldId + + "&isDisplayDesignImage=" + isDisplayDesignImage; + bbContent.setUrl(contentUrl); + persister.persist(bbContent); + + // store internalContentId -> externalContentId. It's used for GradebookServlet + PortalExtraInfo pei = PortalUtil.loadPortalExtraInfo(null, null, "LamsStorage"); + ExtraInfo ei = pei.getExtraInfo(); + ei.setValue(bbContentId, lamsLessonId); + PortalUtil.savePortalExtraInfo(pei); + + // Create new Gradebook column for current lesson + if (isGradecenter) { + String userName = user.getUserName(); + LineitemUtil.createLineitem(bbContent, strSequenceID, userName); + } + + // create a new thread to pre-add students and monitors to a lesson (in order to do this task in parallel not to + // slow down later work) + final User userFinal = user; + final String courseIdStrFinal = courseIdStr; + Thread preaddLearnersMonitorsThread = new Thread(new Runnable() { + @Override + public void run() { + LamsSecurityUtil.preaddLearnersMonitorsToLesson(userFinal, courseIdStrFinal, LamsLessonIdLong); + } + }, "LAMS_preaddLearnersMonitors_thread"); + preaddLearnersMonitorsThread.start(); + + return bbContentId; + } + + public static String getTrimmedString(HttpServletRequest request, String paramName) { + String value = request.getParameter(paramName); + return value != null ? value.trim() : ""; + } + + public static User loadUserFromDB(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,e); + } catch (PersistenceException e) { + throw new RuntimeException("No user details found in context or via username parameter. Unable access LAMS. "+e.getMessage()+" Username "+username,e); + } + if ( user == null ) { + throw new RuntimeException("No user details found in context or via username parameter. Unable access LAMS. Username "+username); + } + return user; + } + } Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LamsSecurityUtil.java =================================================================== diff -u -r15727fba2560b07c19aa85591b35791515be1a8e -r4cbb8f0a143a5ceed24a3de664315b501a8cbbdf --- lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LamsSecurityUtil.java (.../LamsSecurityUtil.java) (revision 15727fba2560b07c19aa85591b35791515be1a8e) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LamsSecurityUtil.java (.../LamsSecurityUtil.java) (revision 4cbb8f0a143a5ceed24a3de664315b501a8cbbdf) @@ -50,6 +50,7 @@ import org.xml.sax.SAXException; import blackboard.base.BbList; +import blackboard.data.course.Course; import blackboard.data.course.CourseMembership; import blackboard.data.user.User; import blackboard.persist.BbPersistenceManager; @@ -243,7 +244,7 @@ User user = ctx.getUser(); if ( user == null ) - user = loadUserFromDB(usernameFromParam); + user = BlackboardUtil.loadUserFromDB(usernameFromParam); String username = user.getUserName(); String firstName = user.getGivenName(); @@ -327,22 +328,6 @@ return learningDesigns; } - private static User loadUserFromDB(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,e); - } catch (PersistenceException e) { - throw new RuntimeException("No user details found in context or via username parameter. Unable access LAMS. "+e.getMessage()+" Username "+username,e); - } - if ( user == null ) { - throw new RuntimeException("No user details found in context or via username parameter. Unable access LAMS. Username "+username); - } - return user; - } - /** * Gets a list of learning designs & workspace folders for the current user from LAMS. * @@ -425,34 +410,16 @@ } return courseId; } - /** - * Starts lessons in lams through a LAMS webservice - * - * @param ctx - * the blackboard contect, contains session data - * @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, 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. + * Starts lessons in lams through a LAMS webservice. * * @param ctx * the blackboard contect, contains session data * @param usernameFromParam - * current user's username as a request parameter + * current user's username * @param courseIdStr - * courseId as a request parameter + * courseId * @param ldId * the learning design id for which you wish to start a lesson * @param title @@ -462,25 +429,17 @@ * * @return the learning session id */ - public static Long startLesson(Context ctx, String usernameFromParam, String courseIdStr, long ldId, String title, String desc, boolean isPreview) { + public static Long startLesson(User user, String courseId, long ldId, String title, String desc, boolean isPreview) { String serverId = getServerID(); String serverAddr = getServerAddress(); String serverKey = getServerKey(); - - User user = ctx.getUser(); - if ( user == null ) - user = loadUserFromDB(usernameFromParam); String username = user.getUserName(); String locale = user.getLocale(); String country = getCountry(locale); String lang = getLanguage(locale); String method = (isPreview) ? "preview" : "start"; - - // courseId always needed to check roles - // if it is preview, then can use the DUMMY_COURSE - 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"); @@ -705,13 +664,12 @@ * @param lessonId * the lesoon id that was just started */ - public static void preaddLearnersMonitorsToLesson(Context ctx, long lessonId) { + public static void preaddLearnersMonitorsToLesson(User user, String courseIdStr, long lessonId) { String serverId = getServerID(); String serverAddr = getServerAddress(); String serverKey = getServerKey(); - String courseIdStr = ctx.getCourse().getCourseId(); - String username = ctx.getUser().getUserName(); - String locale = ctx.getUser().getLocale(); + String username = user.getUserName(); + String locale = user.getLocale(); String country = getCountry(locale); String lang = getLanguage(locale); @@ -733,10 +691,9 @@ final String DUMMY_VALUE = "-"; BbPersistenceManager bbPm = PersistenceServiceFactory.getInstance().getDbPersistenceManager(); - Id courseId = ctx.getCourse().getId(); + CourseMembershipDbLoader courseMemLoader = CourseMembershipDbLoader.Default.getInstance(); - CourseMembershipDbLoader courseMemLoader = (CourseMembershipDbLoader) bbPm - .getLoader(CourseMembershipDbLoader.TYPE); + Id courseId = bbPm.generateId(Course.DATA_TYPE, courseIdStr); BbList studentCourseMemberships = courseMemLoader.loadByCourseIdAndRole(courseId, CourseMembership.Role.STUDENT, null, true); for (CourseMembership courseMembership : studentCourseMemberships) { Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LineitemUtil.java =================================================================== diff -u -r67bf7cc2eed9d841593d383cf139d63a65e1a8a6 -r4cbb8f0a143a5ceed24a3de664315b501a8cbbdf --- lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LineitemUtil.java (.../LineitemUtil.java) (revision 67bf7cc2eed9d841593d383cf139d63a65e1a8a6) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LineitemUtil.java (.../LineitemUtil.java) (revision 4cbb8f0a143a5ceed24a3de664315b501a8cbbdf) @@ -72,7 +72,7 @@ private static Logger logger = Logger.getLogger(LineitemUtil.class); - public static void createLineitem(Content bbContent, Context ctx, String userName) + public static void createLineitem(Content bbContent, String ldId, String userName) throws ValidationException, PersistenceException, IOException { LineitemDbPersister linePersister = LineitemDbPersister.Default.getInstance(); OutcomeDefinitionDbPersister outcomeDefinitionPersister = OutcomeDefinitionDbPersister.Default.getInstance(); @@ -102,7 +102,7 @@ outcomeDefinition.setCourseId(courseId); outcomeDefinition.setPosition(1); - boolean hasLessonScoreOutputs = LineitemUtil.hasLessonScoreOutputs(bbContent, ctx, userName); + boolean hasLessonScoreOutputs = LineitemUtil.hasLessonScoreOutputs(bbContent, ldId, userName); OutcomeDefinitionScale outcomeDefinitionScale; if (hasLessonScoreOutputs) { outcomeDefinitionScale = outcomeDefinitionScaleLoader.loadByCourseIdAndTitle(courseId, @@ -133,8 +133,7 @@ * * @throws IOException */ - private static boolean hasLessonScoreOutputs(Content bbContent, Context ctx, String username) throws IOException { - String ldId = ctx.getRequestParameter("sequence_id"); + private static boolean hasLessonScoreOutputs(Content bbContent, String ldId, String username) throws IOException { //sequence_id parameter is null in case we come from modify_proc if (ldId == null) { @@ -251,7 +250,8 @@ Id lineitemId = getLineitem(_content_id, courseIdStr, false); //in case admin forgot to check "Grade Center Columns and Settings" option on doing course copy/import if (lineitemId == null) { - createLineitem(bbContent, ctx, userName); + String ldId = ctx.getRequestParameter("sequence_id"); + createLineitem(bbContent, ldId, userName); //in case he checked it and BB created Lineitem object, then just need to update it } else { Index: lams_bb_integration/web/modules/modify_proc.jsp =================================================================== diff -u -r60e3807f78aa28e63cf1da381fc37cf621549beb -r4cbb8f0a143a5ceed24a3de664315b501a8cbbdf --- lams_bb_integration/web/modules/modify_proc.jsp (.../modify_proc.jsp) (revision 60e3807f78aa28e63cf1da381fc37cf621549beb) +++ lams_bb_integration/web/modules/modify_proc.jsp (.../modify_proc.jsp) (revision 4cbb8f0a143a5ceed24a3de664315b501a8cbbdf) @@ -86,7 +86,7 @@ if (!bbContent.getIsDescribed() && isGradecenter) { String username = ctx.getUser().getUserName(); - LineitemUtil.createLineitem(bbContent, ctx, username); + LineitemUtil.createLineitem(bbContent, null, username); //if teacher turned Gradecenter option OFF (and it was ON previously) - remove lineitem } else if (bbContent.getIsDescribed() && !isGradecenter) { Index: lams_bb_integration/web/modules/preview.jsp =================================================================== diff -u -r60e3807f78aa28e63cf1da381fc37cf621549beb -r4cbb8f0a143a5ceed24a3de664315b501a8cbbdf --- lams_bb_integration/web/modules/preview.jsp (.../preview.jsp) (revision 60e3807f78aa28e63cf1da381fc37cf621549beb) +++ lams_bb_integration/web/modules/preview.jsp (.../preview.jsp) (revision 4cbb8f0a143a5ceed24a3de664315b501a8cbbdf) @@ -21,6 +21,7 @@ <%@ page import="blackboard.data.content.ContentFile"%> <%@ page import="blackboard.data.content.ContentFolder"%> <%@ page import="blackboard.data.content.CourseDocument"%> +<%@ page import="blackboard.data.user.User"%> <%@ page import="blackboard.persist.Id"%> <%@ page import="blackboard.persist.BbPersistenceManager"%> <%@ page import="blackboard.persist.content.ContentDbPersister"%> @@ -53,11 +54,12 @@ String strTitle = request.getParameter("title").trim(); String strLdId = request.getParameter("ldId").trim(); - long ldId = Long.parseLong(strLdId); + long ldId = Long.parseLong(strLdId); - // Start the Lesson for preview in LAMS (via Webservices) - // Capture the lesson ID - Long lsId = LamsSecurityUtil.startLesson(ctx, ldId, strTitle, "", true); + User user = ctx.getUser(); + + // Start the Lesson for preview in LAMS (via Webservices) and get back the lesson ID + Long lsId = LamsSecurityUtil.startLesson(user, "Previews", ldId, strTitle, "", true); //error checking if (lsId == -1) { response.sendRedirect("lamsServerDown.jsp"); Index: lams_bb_integration/web/modules/start_lesson_proc.jsp =================================================================== diff -u -ra9dbee1cb6d28872008dbe22130e2281a059b1ce -r4cbb8f0a143a5ceed24a3de664315b501a8cbbdf --- lams_bb_integration/web/modules/start_lesson_proc.jsp (.../start_lesson_proc.jsp) (revision a9dbee1cb6d28872008dbe22130e2281a059b1ce) +++ lams_bb_integration/web/modules/start_lesson_proc.jsp (.../start_lesson_proc.jsp) (revision 4cbb8f0a143a5ceed24a3de664315b501a8cbbdf) @@ -21,6 +21,7 @@ <%@ page import="blackboard.data.content.ContentFile"%> <%@ page import="blackboard.data.content.ContentFolder"%> <%@ page import="blackboard.data.content.CourseDocument"%> +<%@ page import="blackboard.data.user.User"%> <%@ page import="blackboard.persist.*"%> <%@ page import="blackboard.persist.content.*"%> <%@ page import="blackboard.data.gradebook.impl.*"%> @@ -46,6 +47,8 @@ <% + BbPersistenceManager bbPm = PersistenceServiceFactory.getInstance().getDbPersistenceManager(); + //Set the new LAMS Lesson Content Object CourseDocument bbContent = new blackboard.data.content.CourseDocument(); @@ -56,143 +59,17 @@ } catch(PlugInException e) { throw new RuntimeException(e); } - - // Retrieve the Db persistence manager from the persistence service - BbPersistenceManager bbPm = BbServiceManager.getPersistenceService().getDbPersistenceManager(); - ContentDbPersister contentPersister = (ContentDbPersister) bbPm.getPersister( ContentDbPersister.TYPE ); - - // Internal Blackboard IDs for the course and parent content item - Id courseId = bbPm.generateId(Course.DATA_TYPE,request.getParameter("course_id")); - Id folderId = bbPm.generateId(CourseDocument.DATA_TYPE,request.getParameter("content_id")); - - // Load parent content item - ContentDbLoader courseDocumentLoader = (ContentDbLoader) bbPm.getLoader( ContentDbLoader.TYPE ); - ContentFolder courseDocParent = (ContentFolder)courseDocumentLoader.loadById( folderId ); - - // Get the session object to obtain the user and course object - BbSessionManagerService sessionService = BbServiceManager.getSessionManagerService(); - BbSession bbSession = sessionService.getSession( request ); - - // Get the form parameters and convert into correct data types - // TODO: Use bb text area instead - String strTitle = request.getParameter("title").trim(); - String strDescription = request.getParameter("descriptiontext").trim(); - FormattedText description = new FormattedText(strDescription, FormattedText.Type.HTML); - - String strSequenceID = request.getParameter("sequence_id").trim(); - long ldId = Long.parseLong(strSequenceID); - - String strIsAvailable = request.getParameter("isAvailable"); - String strIsGradecenter = request.getParameter("isGradecenter"); - String strIsTracked = request.getParameter("isTracked"); - boolean isAvailable = (strIsAvailable==null || strIsAvailable.equals("true"))?true:false; // default true - boolean isGradecenter = (strIsGradecenter!=null && strIsGradecenter.equals("true"))?true:false; // default false - boolean isTracked = (strIsTracked!=null && strIsTracked.equals("true"))?true:false; // default false - - String isDisplayDesignImage = request.getParameter("isDisplayDesignImage"); - - // Set Availability Dates - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - - // Start Date - String strStartDate = request.getParameter("lessonAvailability_start_datetime"); - if ( strStartDate != null ) { - Calendar startDate = Calendar.getInstance(); - startDate.setTime(formatter.parse(strStartDate)); - String strStartDateCheckbox = request.getParameter("lessonAvailability_start_checkbox"); - if (strStartDateCheckbox != null){ - if (strStartDateCheckbox.equals("1")){ - bbContent.setStartDate(startDate); - } - } - } - - // End Date - String strEndDate = request.getParameter("lessonAvailability_end_datetime"); - if ( strEndDate != null ) { - Calendar endDate = Calendar.getInstance(); - endDate.setTime(formatter.parse(strEndDate)); - String strEndDateCheckbox = request.getParameter("lessonAvailability_end_checkbox"); - if (strEndDateCheckbox != null){ - if (strEndDateCheckbox.equals("1")){ - bbContent.setEndDate(endDate); - } - } - } - - // Set the New LAMS Lesson content data (in Blackboard) - bbContent.setTitle(strTitle); - bbContent.setIsAvailable(isAvailable); - bbContent.setIsDescribed(isGradecenter);//isDescribed field is used for storing isGradecenter parameter - bbContent.setIsTracked(isTracked); - bbContent.setAllowGuests(false); - bbContent.setContentHandler(LamsPluginUtil.CONTENT_HANDLE); - - bbContent.setCourseId(courseId); - bbContent.setParentId(folderId); - - bbContent.setRenderType(Content.RenderType.URL); - bbContent.setBody(description); - // LDEV-3510 LAMS Lessons were always at the top and could not be moved. - //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); - //error checking - if (LamsLessonIdLong == -1) { - response.sendRedirect("lamsServerDown.jsp"); - System.exit(1); - } - String lamsLessonId = Long.toString(LamsLessonIdLong); - bbContent.setLinkRef(lamsLessonId); - - //Persist the New Lesson Object in Blackboard - ContentDbPersister persister= (ContentDbPersister) bbPm.getPersister( ContentDbPersister.TYPE ); - persister.persist( bbContent ); - PkId bbContentPkId = (PkId) bbContent.getId(); - String bbContentId = "_" + bbContentPkId.getPk1() + "_" + bbContentPkId.getPk2(); - - //Build and set the content URL. Include new lesson id parameter - int bbport = request.getServerPort();// Add port to the url if the port is in the blackboard url. - String bbportstr = bbport != 0 ? ":" + bbport : ""; - String contentUrl = request.getScheme() - + "://" + - request.getServerName() + - bbportstr + - request.getContextPath() + - "/modules/learnermonitor.jsp?lsid=" + lamsLessonId + - "&course_id=" + request.getParameter("course_id") + - "&content_id=" + bbContentId + - "&ldid=" + ldId + - "&isDisplayDesignImage=" + isDisplayDesignImage; - bbContent.setUrl(contentUrl); - persister.persist(bbContent); - - //store internalContentId -> externalContentId. It's used for GradebookServlet - PortalExtraInfo pei = PortalUtil.loadPortalExtraInfo(null, null, "LamsStorage"); - ExtraInfo ei = pei.getExtraInfo(); - ei.setValue(bbContentId, lamsLessonId); - PortalUtil.savePortalExtraInfo(pei); + User user = ctx.getUser(); + BlackboardUtil.storeBlackboardContent(request, response, user); - //Create new Gradebook column for current lesson - if (isGradecenter) { - String userName = ctx.getUser().getUserName(); - LineitemUtil.createLineitem(bbContent, ctx, userName); - } + String courseIdStr = request.getParameter("course_id"); + String contentIdStr = request.getParameter("content_id"); + // Internal Blackboard IDs for the course and parent content item + Id courseId = bbPm.generateId(Course.DATA_TYPE, courseIdStr); + Id folderId = bbPm.generateId(CourseDocument.DATA_TYPE, contentIdStr); - String strReturnUrl = PlugInUtil.getEditableContentReturnURL(bbContent.getParentId(), courseId); - - // create a new thread to pre-add students and monitors to a lesson (in order to do this task in parallel not to slow down later work) - final Context ctxFinal = ctx; - Thread preaddLearnersMonitorsThread = new Thread(new Runnable() { - @Override - public void run() { - LamsSecurityUtil.preaddLearnersMonitorsToLesson(ctxFinal, LamsLessonIdLong); - } - }, "LAMS_preaddLearnersMonitors_thread"); - preaddLearnersMonitorsThread.start(); - + String strReturnUrl = PlugInUtil.getEditableContentReturnURL(folderId, courseId); %> <%-- Breadcrumbs --%>