Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/CloneLessonsServlet.java =================================================================== diff -u -r2df41e4250f5329a8be4e9e2642d17b091a11f64 -r6c816ed5cfaacf7a92c46e7ddb649148b73fbfb3 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/CloneLessonsServlet.java (.../CloneLessonsServlet.java) (revision 2df41e4250f5329a8be4e9e2642d17b091a11f64) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/CloneLessonsServlet.java (.../CloneLessonsServlet.java) (revision 6c816ed5cfaacf7a92c46e7ddb649148b73fbfb3) @@ -25,6 +25,7 @@ import java.io.IOException; import java.io.PrintWriter; +import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -36,17 +37,12 @@ import org.lamsfoundation.ld.integration.util.LamsSecurityUtil; import org.lamsfoundation.ld.integration.util.LineitemUtil; -import blackboard.base.BbList; import blackboard.data.content.Content; import blackboard.data.course.Course; -import blackboard.data.navigation.CourseToc; import blackboard.data.user.User; -import blackboard.persist.Id; import blackboard.persist.PkId; -import blackboard.persist.content.ContentDbLoader; import blackboard.persist.content.ContentDbPersister; import blackboard.persist.course.CourseDbLoader; -import blackboard.persist.navigation.CourseTocDbLoader; import blackboard.platform.BbServiceManager; import blackboard.platform.context.Context; import blackboard.platform.context.ContextManager; @@ -72,79 +68,55 @@ // get Blackboard context ContextManager ctxMgr = (ContextManager) BbServiceManager.lookupService(ContextManager.class); Context ctx = ctxMgr.setContext(request); + ContentDbPersister persister =ContentDbPersister.Default.getInstance(); CourseDbLoader courseLoader = CourseDbLoader.Default.getInstance(); Course course = courseLoader.loadByCourseId(courseIdParam); PkId courseId = (PkId) course.getId(); String _course_id = "_" + courseId.getPk1() + "_" + courseId.getPk2(); + logger.debug("Starting clonning course lessons (courseId=" + courseId + ")."); // find a teacher that will be assigned as lesson's author on LAMS side User teacher = BlackboardUtil.getCourseTeacher(courseId); - logger.debug("Starting clonning course lessons (courseId=" + courseId + ")."); + //find all lessons that should be updated + List lamsContents = BlackboardUtil.getLamsLessonsByCourse(courseId); + for (Content content : lamsContents) { - ContentDbLoader contentLoader = ContentDbLoader.Default.getInstance(); - CourseTocDbLoader cTocDbLoader = CourseTocDbLoader.Default.getInstance(); - ContentDbPersister persister =ContentDbPersister.Default.getInstance(); + PkId contentId = (PkId) content.getId(); + String _content_id = "_" + contentId.getPk1() + "_" + contentId.getPk2(); - //find all lessons that should be updated + String url = content.getUrl(); + String urlLessonId = getParameterValue(url, "lsid"); + String urlCourseId = getParameterValue(url, "course_id"); + String urlContentId = getParameterValue(url, "content_id"); - // get a CourseTOC (Table of Contents) loader. We will need this to iterate through all of the "areas" - // within the course - BbList courseTocs = cTocDbLoader.loadByCourseId(courseId); + //in case when both courseId and contentId don't coincide with the ones from URL - means lesson needs to be cloned + if (!urlCourseId.equals(_course_id) && !urlContentId.equals(_content_id)) { - // iterate through the course TOC items - for (CourseToc courseToc : courseTocs) { + final Long newLessonId = LamsSecurityUtil.cloneLesson(teacher, courseIdParam, urlLessonId); - // determine if the TOC item is of type "CONTENT" rather than applicaton, or something else - if ((courseToc.getTargetType() == CourseToc.Target.CONTENT) - && (courseToc.getContentId() != Id.UNSET_ID)) { - // we have determined that the TOC item is content, next we need to load the content object and - // iterate through it - // load the content tree into an object "content" and iterate through it - BbList contents = contentLoader.loadListById(courseToc.getContentId()); - // iterate through the content items in this content object - for (Content content : contents) { - // only LAMS content - if ("resource/x-lams-lamscontent".equals(content.getContentHandler())) { - - PkId contentId = (PkId) content.getId(); - String _content_id = "_" + contentId.getPk1() + "_" + contentId.getPk2(); - - String url = content.getUrl(); - String urlLessonId = getParameterValue(url, "lsid"); - String urlCourseId = getParameterValue(url, "course_id"); - String urlContentId = getParameterValue(url, "content_id"); + // update lesson id + content.setLinkRef(Long.toString(newLessonId)); - //in case when both courseId and contentId don't coincide with the ones from URL - means lesson needs to be cloned - if (!urlCourseId.equals(_course_id) && !urlContentId.equals(_content_id)) { - - final Long newLessonId = LamsSecurityUtil.cloneLesson(teacher, courseIdParam, urlLessonId); - - // update lesson id - content.setLinkRef(Long.toString(newLessonId)); + // update URL + url = replaceParameterValue(url, "lsid", Long.toString(newLessonId)); + url = replaceParameterValue(url, "course_id", _course_id); + url = replaceParameterValue(url, "content_id", _content_id); + content.setUrl(url); - // update URL - url = replaceParameterValue(url, "lsid", Long.toString(newLessonId)); - url = replaceParameterValue(url, "course_id", _course_id); - url = replaceParameterValue(url, "content_id", _content_id); - content.setUrl(url); + // persist updated content + persister.persist(content); - // persist updated content - persister.persist(content); - - //update lineitem details - LineitemUtil.updateLineitemLessonId(content, _course_id, newLessonId, ctx, teacher.getUserName()); + //update lineitem details + LineitemUtil.updateLineitemLessonId(content, _course_id, newLessonId, ctx, teacher.getUserName()); - logger.debug("Lesson (lessonId=" + urlLessonId - + ") was successfully cloned to the one (lessonId=" + newLessonId + ")."); - - newLessonIds += newLessonId + ", "; - } - } + logger.debug("Lesson (lessonId=" + urlLessonId + ") was successfully cloned to the one (lessonId=" + + newLessonId + ")."); - } + newLessonIds += newLessonId + ", "; } + } } catch (IllegalStateException e) { Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/CorrectLineitemsServlet.java =================================================================== diff -u -r2df41e4250f5329a8be4e9e2642d17b091a11f64 -r6c816ed5cfaacf7a92c46e7ddb649148b73fbfb3 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/CorrectLineitemsServlet.java (.../CorrectLineitemsServlet.java) (revision 2df41e4250f5329a8be4e9e2642d17b091a11f64) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/CorrectLineitemsServlet.java (.../CorrectLineitemsServlet.java) (revision 6c816ed5cfaacf7a92c46e7ddb649148b73fbfb3) @@ -25,6 +25,7 @@ import java.io.IOException; import java.io.PrintWriter; +import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -33,22 +34,13 @@ import org.apache.log4j.Logger; import org.lamsfoundation.ld.integration.util.BlackboardUtil; -import org.lamsfoundation.ld.integration.util.LamsSecurityUtil; import org.lamsfoundation.ld.integration.util.LineitemUtil; -import blackboard.base.BbList; import blackboard.data.content.Content; import blackboard.data.course.Course; -import blackboard.data.course.CourseMembership; -import blackboard.data.navigation.CourseToc; import blackboard.data.user.User; -import blackboard.persist.Id; import blackboard.persist.PkId; -import blackboard.persist.content.ContentDbLoader; -import blackboard.persist.content.ContentDbPersister; import blackboard.persist.course.CourseDbLoader; -import blackboard.persist.course.CourseMembershipDbLoader; -import blackboard.persist.navigation.CourseTocDbLoader; import blackboard.platform.BbServiceManager; import blackboard.platform.context.Context; import blackboard.platform.context.ContextManager; @@ -78,46 +70,21 @@ Course course = courseLoader.loadByCourseId(courseIdParam); PkId courseId = (PkId) course.getId(); String _course_id = "_" + courseId.getPk1() + "_" + courseId.getPk2(); + logger.debug("Starting clonning course lessons (courseId=" + courseId + ")."); // find a teacher that will be assigned as lesson's author on LAMS side User teacher = BlackboardUtil.getCourseTeacher(courseId); - logger.debug("Starting clonning course lessons (courseId=" + courseId + ")."); - - ContentDbLoader contentLoader = ContentDbLoader.Default.getInstance(); - CourseTocDbLoader cTocDbLoader = CourseTocDbLoader.Default.getInstance(); - //find all lessons that should be updated + List lamsContents = BlackboardUtil.getLamsLessonsByCourse(courseId); + for (Content content : lamsContents) { - // get a CourseTOC (Table of Contents) loader. We will need this to iterate through all of the "areas" - // within the course - BbList courseTocs = cTocDbLoader.loadByCourseId(courseId); + // update lesson id + String lessonId = content.getLinkRef(); - // iterate through the course TOC items - for (CourseToc courseToc : courseTocs) { - - // determine if the TOC item is of type "CONTENT" rather than applicaton, or something else - if ((courseToc.getTargetType() == CourseToc.Target.CONTENT) - && (courseToc.getContentId() != Id.UNSET_ID)) { - // we have determined that the TOC item is content, next we need to load the content object and - // iterate through it - // load the content tree into an object "content" and iterate through it - BbList contents = contentLoader.loadListById(courseToc.getContentId()); - // iterate through the content items in this content object - for (Content content : contents) { - // only LAMS content - if ("resource/x-lams-lamscontent".equals(content.getContentHandler())) { - - // update lesson id - String lessonId = content.getLinkRef(); - - //update lineitem details - LineitemUtil.updateLineitemLessonId(content, _course_id, Long.parseLong(lessonId), ctx, - teacher.getUserName()); - } - - } - } + //update lineitem details + LineitemUtil.updateLineitemLessonId(content, _course_id, Long.parseLong(lessonId), ctx, + teacher.getUserName()); } } catch (IllegalStateException e) { @@ -143,47 +110,5 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doGet(req, resp); } - - /* - * Returns param value, and empty string in case of there is no such param available - * - * @param url - * @param paramName - * @return - */ - private static String getParameterValue(String url, String paramName) { - String paramValue = ""; - int quotationMarkIndex = url.indexOf("?"); - String queryPart = quotationMarkIndex > -1 ? url.substring(quotationMarkIndex + 1) : url; - String[] paramEntries = queryPart.split("&"); - for (String paramEntry : paramEntries) { - String[] paramEntrySplitted = paramEntry.split("="); - if ((paramEntrySplitted.length > 1) && paramName.equalsIgnoreCase(paramEntrySplitted[0])) { - paramValue = paramEntrySplitted[1]; - break; - } - } - - return paramValue; - } - - private static String replaceParameterValue(String url, String paramName, String newParamValue) { - String oldParamValue = ""; - - int quotationMarkIndex = url.indexOf("?"); - String queryPart = quotationMarkIndex > -1 ? url.substring(quotationMarkIndex + 1) : url; - String[] paramEntries = queryPart.split("&"); - for (String paramEntry : paramEntries) { - String[] paramEntrySplitted = paramEntry.split("="); - if ((paramEntrySplitted.length > 1) && paramName.equalsIgnoreCase(paramEntrySplitted[0])) { - oldParamValue = paramEntrySplitted[1]; - - return url.replaceFirst(paramName + "=" + oldParamValue, paramName + "=" + newParamValue); - } - } - - return url; - } - } \ No newline at end of file Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/ImportLessonsServlet.java =================================================================== diff -u -r2df41e4250f5329a8be4e9e2642d17b091a11f64 -r6c816ed5cfaacf7a92c46e7ddb649148b73fbfb3 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/ImportLessonsServlet.java (.../ImportLessonsServlet.java) (revision 2df41e4250f5329a8be4e9e2642d17b091a11f64) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/ImportLessonsServlet.java (.../ImportLessonsServlet.java) (revision 6c816ed5cfaacf7a92c46e7ddb649148b73fbfb3) @@ -26,6 +26,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.net.URLEncoder; +import java.util.List; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; @@ -38,28 +39,18 @@ import org.lamsfoundation.ld.integration.util.LamsServerException; import org.lamsfoundation.ld.integration.util.LineitemUtil; -import blackboard.base.BbList; import blackboard.base.FormattedText; import blackboard.base.InitializationException; import blackboard.data.content.Content; import blackboard.data.course.Course; -import blackboard.data.course.CourseMembership; -import blackboard.data.navigation.CourseToc; import blackboard.data.user.User; -import blackboard.persist.Id; import blackboard.persist.PkId; -import blackboard.persist.content.ContentDbLoader; import blackboard.persist.content.ContentDbPersister; import blackboard.persist.course.CourseDbLoader; -import blackboard.persist.course.CourseMembershipDbLoader; -import blackboard.persist.navigation.CourseTocDbLoader; import blackboard.platform.BbServiceException; import blackboard.platform.BbServiceManager; import blackboard.platform.context.Context; import blackboard.platform.context.ContextManager; -import blackboard.portal.data.ExtraInfo; -import blackboard.portal.data.PortalExtraInfo; -import blackboard.portal.servlet.PortalUtil; import blackboard.util.StringUtil; /** @@ -82,91 +73,66 @@ // get Blackboard context ContextManager ctxMgr = (ContextManager) BbServiceManager.lookupService(ContextManager.class); Context ctx = ctxMgr.setContext(request); + ContentDbPersister persister =ContentDbPersister.Default.getInstance(); CourseDbLoader courseLoader = CourseDbLoader.Default.getInstance(); Course course = courseLoader.loadByCourseId(courseIdParam); PkId courseId = (PkId) course.getId(); String _course_id = "_" + courseId.getPk1() + "_" + courseId.getPk2(); + logger.debug("Starting importing course lessons (courseId=" + courseId + ")."); // find a teacher that will be assigned as lesson's author on LAMS side User teacher = BlackboardUtil.getCourseTeacher(courseId); - logger.debug("Starting importing course lessons (courseId=" + courseId + ")."); + //find all lessons that should be updated + List lamsContents = BlackboardUtil.getLamsLessonsByCourse(courseId); + for (Content content : lamsContents) { - ContentDbLoader contentLoader = ContentDbLoader.Default.getInstance(); - CourseTocDbLoader cTocDbLoader = CourseTocDbLoader.Default.getInstance(); - ContentDbPersister persister =ContentDbPersister.Default.getInstance(); + PkId contentId = (PkId) content.getId(); + String _content_id = "_" + contentId.getPk1() + "_" + contentId.getPk2(); - //find all lessons that should be updated + String url = content.getUrl(); + String urlLessonId = getParameterValue(url, "lsid"); + String urlCourseId = getParameterValue(url, "course_id"); + String urlContentId = getParameterValue(url, "content_id"); + String urlLdId = getParameterValue(url, "ldid"); - // get a CourseTOC (Table of Contents) loader. We will need this to iterate through all of the "areas" - // within the course - BbList courseTocs = cTocDbLoader.loadByCourseId(courseId); + //in case when both courseId and contentId don't coincide with the ones from URL - means lesson needs to be imported + if (!urlCourseId.equals(_course_id) && !urlContentId.equals(_content_id)) { - // iterate through the course TOC items - for (CourseToc courseToc : courseTocs) { + final Long newLdId = LamsSecurityUtil.importLearningDesign(teacher, courseIdParam, urlLessonId, + urlLdId); - // determine if the TOC item is of type "CONTENT" rather than applicaton, or something else - if ((courseToc.getTargetType() == CourseToc.Target.CONTENT) - && (courseToc.getContentId() != Id.UNSET_ID)) { - // we have determined that the TOC item is content, next we need to load the content object and - // iterate through it - // load the content tree into an object "content" and iterate through it - BbList contents = contentLoader.loadListById(courseToc.getContentId()); - // iterate through the content items in this content object - for (Content content : contents) { - // only LAMS content - if ("resource/x-lams-lamscontent".equals(content.getContentHandler())) { - - PkId contentId = (PkId) content.getId(); - String _content_id = "_" + contentId.getPk1() + "_" + contentId.getPk2(); - - String url = content.getUrl(); - String urlLessonId = getParameterValue(url, "lsid"); - String urlCourseId = getParameterValue(url, "course_id"); - String urlContentId = getParameterValue(url, "content_id"); - String urlLdId = getParameterValue(url, "ldid"); + logger.debug("Lesson (lessonId=" + urlLessonId + + ") was successfully imported to the one (learningDesignId=" + newLdId + ")."); - //in case when both courseId and contentId don't coincide with the ones from URL - means lesson needs to be imported - if (!urlCourseId.equals(_course_id) && !urlContentId.equals(_content_id)) { - - final Long newLdId = LamsSecurityUtil.importLearningDesign(teacher, courseIdParam, urlLessonId, - urlLdId); - - 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(); + 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); - // Start the Lesson in LAMS (via Webservices) and capture the lesson ID - String teacherUsername = teacher.getUserName(); - 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); - - // update lesson id - content.setLinkRef(Long.toString(newLessonId)); + // update lesson id + content.setLinkRef(Long.toString(newLessonId)); - // update URL - url = replaceParameterValue(url, "lsid", Long.toString(newLessonId)); - url = replaceParameterValue(url, "course_id", _course_id); - url = replaceParameterValue(url, "content_id", _content_id); - content.setUrl(url); + // update URL + url = replaceParameterValue(url, "lsid", Long.toString(newLessonId)); + url = replaceParameterValue(url, "course_id", _course_id); + url = replaceParameterValue(url, "content_id", _content_id); + content.setUrl(url); - // persist updated content - persister.persist(content); + // persist updated content + persister.persist(content); - //update lineitem details - LineitemUtil.updateLineitemLessonId(content, _course_id, newLessonId, ctx, teacher.getUserName()); + //update lineitem details + LineitemUtil.updateLineitemLessonId(content, _course_id, newLessonId, ctx, teacher.getUserName()); - logger.debug("Lesson (lessonId=" + urlLessonId - + ") was successfully imported to the one (lessonId=" + newLessonId + ")."); - - newLessonIds += newLessonId + ", "; - } - } + logger.debug("Lesson (lessonId=" + urlLessonId + ") was successfully imported to the one (lessonId=" + + newLessonId + ")."); - } + newLessonIds += newLessonId + ", "; } } Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/UpdateServerUrlServlet.java =================================================================== diff -u -r90551510089141ff0f625b92c00ab97ba4e98a26 -r6c816ed5cfaacf7a92c46e7ddb649148b73fbfb3 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/UpdateServerUrlServlet.java (.../UpdateServerUrlServlet.java) (revision 90551510089141ff0f625b92c00ab97ba4e98a26) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/UpdateServerUrlServlet.java (.../UpdateServerUrlServlet.java) (revision 6c816ed5cfaacf7a92c46e7ddb649148b73fbfb3) @@ -33,17 +33,14 @@ import org.apache.log4j.Logger; import org.lamsfoundation.ld.integration.Constants; +import org.lamsfoundation.ld.integration.util.BlackboardUtil; import blackboard.data.content.Content; import blackboard.data.course.Course; -import blackboard.data.navigation.CourseToc; import blackboard.persist.BbPersistenceManager; import blackboard.persist.Container; -import blackboard.persist.Id; import blackboard.persist.PkId; -import blackboard.persist.content.ContentDbLoader; import blackboard.persist.content.ContentDbPersister; -import blackboard.persist.navigation.CourseTocDbLoader; import blackboard.platform.BbServiceManager; import blackboard.platform.context.ContextManager; import blackboard.platform.persistence.PersistenceServiceFactory; @@ -83,38 +80,20 @@ ctxMgr = (ContextManager) BbServiceManager.lookupService(ContextManager.class); BbPersistenceManager bbPm = PersistenceServiceFactory.getInstance().getDbPersistenceManager(); Container bbContainer = bbPm.getContainer(); + ContentDbPersister persister = ContentDbPersister.Default.getInstance(); - ContentDbLoader contentDbLoader = ContentDbLoader.Default.getInstance(); - CourseTocDbLoader courseTocDbLoader = CourseTocDbLoader.Default.getInstance(); - ContentDbPersister persister = (ContentDbPersister) bbPm.getPersister(ContentDbPersister.TYPE); - - Id courseId = new PkId(bbContainer, Course.DATA_TYPE, courseIdParam); + PkId courseId = new PkId(bbContainer, Course.DATA_TYPE, courseIdParam); - List listCourseToc = courseTocDbLoader.loadByCourseId(courseId); - for (CourseToc cToc : listCourseToc) { + //find all lessons that should be updated + List lamsContents = BlackboardUtil.getLamsLessonsByCourse(courseId); + for (Content content : lamsContents) { + String oldUrl = content.getUrl(); + String newUrl = oldUrl.replaceFirst(oldUrlHost, newUrlHost); + content.setUrl(newUrl); + persister.persist(content); - // determine if the TOC item is of type "CONTENT" rather than application, or something else - if ((cToc.getTargetType() == CourseToc.Target.CONTENT) && (cToc.getContentId() != Id.UNSET_ID)) { - - // load the content object and iterate through it - List listContent = contentDbLoader.loadListById(cToc.getContentId()); - for (Content content : listContent) { - - if (content.getUrlHost().contains(oldUrlHost) - && (content.getContentHandler().equals("resource/x-lams-lamscontent") - || content.getContentHandler().equals("resource/x-ntu-hdllams"))) { - String oldUrl = content.getUrl(); - String newUrl = oldUrl.replaceFirst(oldUrlHost, newUrlHost); - content.setUrl(newUrl); - persister.persist(content); - - out.write("Old Url" + oldUrl + ". New url:" + newUrl + "\n\r"); - } - - } - } + out.write("Old Url" + oldUrl + ". New url:" + newUrl + "\n\r"); } - } catch (Exception e) { throw new ServletException(e); @@ -130,19 +109,4 @@ out.write("OK"); } - private static String extractParameterValue(String url, String param) { - if (url != null && param != null) { - int quotationMarkIndex = url.indexOf("?"); - String queryPart = quotationMarkIndex > -1 ? url.substring(quotationMarkIndex + 1) : url; - String[] paramEntries = queryPart.split("&"); - for (String paramEntry : paramEntries) { - String[] paramEntrySplitted = paramEntry.split("="); - if ((paramEntrySplitted.length > 1) && param.equalsIgnoreCase(paramEntrySplitted[0])) { - return paramEntrySplitted[1]; - } - } - } - return null; - } - } Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/util/BlackboardUtil.java =================================================================== diff -u -r2df41e4250f5329a8be4e9e2642d17b091a11f64 -r6c816ed5cfaacf7a92c46e7ddb649148b73fbfb3 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/util/BlackboardUtil.java (.../BlackboardUtil.java) (revision 2df41e4250f5329a8be4e9e2642d17b091a11f64) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/util/BlackboardUtil.java (.../BlackboardUtil.java) (revision 6c816ed5cfaacf7a92c46e7ddb649148b73fbfb3) @@ -1,26 +1,34 @@ package org.lamsfoundation.ld.integration.util; +import java.util.ArrayList; +import java.util.List; + import blackboard.base.BbList; +import blackboard.data.content.Content; import blackboard.data.course.CourseMembership; +import blackboard.data.navigation.CourseToc; import blackboard.data.user.User; +import blackboard.persist.Id; import blackboard.persist.PersistenceException; import blackboard.persist.PkId; +import blackboard.persist.content.ContentDbLoader; import blackboard.persist.course.CourseMembershipDbLoader; +import blackboard.persist.navigation.CourseTocDbLoader; /** * Set of utilities dealing with Blackboard data. * * @author Andrey Balan */ public class BlackboardUtil { - + /** - * Returns some random teacher from the specified course. + * Returns one random teacher from the specified course. * * @param courseId * BB course id * @return teacher - * @throws PersistenceException + * @throws PersistenceException */ public static User getCourseTeacher(PkId courseId) throws PersistenceException { // find the main teacher @@ -46,4 +54,45 @@ return teacher; } + /** + * Returns all LAMS lessons from the specified course. + * + * @param courseId + * BB course id + * @return list of LAMS lessons + * @throws PersistenceException + */ + public static List getLamsLessonsByCourse(PkId courseId) throws PersistenceException { + + ContentDbLoader contentLoader = ContentDbLoader.Default.getInstance(); + CourseTocDbLoader cTocDbLoader = CourseTocDbLoader.Default.getInstance(); + + // get a CourseTOC (Table of Contents) loader. We will need this to iterate through all of the "areas" + // within the course + BbList courseTocs = cTocDbLoader.loadByCourseId(courseId); + + // iterate through the course TOC items + List lamsContents = new ArrayList(); + for (CourseToc courseToc : courseTocs) { + + // determine if the TOC item is of type "CONTENT" rather than applicaton, or something else + if ((courseToc.getTargetType() == CourseToc.Target.CONTENT) && (courseToc.getContentId() != Id.UNSET_ID)) { + // we have determined that the TOC item is content, next we need to load the content object and + // iterate through it + // load the content tree into an object "content" and iterate through it + BbList contents = contentLoader.loadListById(courseToc.getContentId()); + // iterate through the content items in this content object + for (Content content : contents) { + // only LAMS content + if ("resource/x-lams-lamscontent".equals(content.getContentHandler()) + || content.getContentHandler().equals("resource/x-ntu-hdllams")) { + lamsContents.add(content); + } + } + } + } + + return lamsContents; + } + }