Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/CloneLessonsServlet.java =================================================================== diff -u -rf2a3c4096484b9fe80c78c5dde83c093ab40cec9 -ra9ef5fba9560f8028fc73bbda99f7456f1a7ebf0 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/CloneLessonsServlet.java (.../CloneLessonsServlet.java) (revision f2a3c4096484b9fe80c78c5dde83c093ab40cec9) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/CloneLessonsServlet.java (.../CloneLessonsServlet.java) (revision a9ef5fba9560f8028fc73bbda99f7456f1a7ebf0) @@ -30,11 +30,13 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.xml.parsers.ParserConfigurationException; 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 org.xml.sax.SAXException; import blackboard.data.ValidationException; import blackboard.data.content.Content; @@ -104,9 +106,11 @@ * @throws ValidationException * @throws IOException * @throws ServletException + * @throws SAXException + * @throws ParserConfigurationException */ public static String recreateLessonsAfterCourseCopy(String courseIdParam) - throws PersistenceException, ValidationException, ServletException, IOException { + throws PersistenceException, ValidationException, ServletException, IOException, ParserConfigurationException, SAXException { String newLessonIds = ""; ContentDbPersister persister = ContentDbPersister.Default.getInstance(); Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/util/BlackboardUtil.java =================================================================== diff -u -rd1354049e2ed70185d219183eb5c38c8434cd73b -ra9ef5fba9560f8028fc73bbda99f7456f1a7ebf0 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/util/BlackboardUtil.java (.../BlackboardUtil.java) (revision d1354049e2ed70185d219183eb5c38c8434cd73b) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/util/BlackboardUtil.java (.../BlackboardUtil.java) (revision a9ef5fba9560f8028fc73bbda99f7456f1a7ebf0) @@ -10,8 +10,10 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.xml.parsers.ParserConfigurationException; import org.apache.log4j.Logger; +import org.xml.sax.SAXException; import blackboard.base.BbList; import blackboard.base.FormattedText; @@ -122,9 +124,11 @@ * @throws ParseException * @throws IOException * @throws ValidationException + * @throws SAXException + * @throws ParserConfigurationException */ public static String storeBlackboardContent(HttpServletRequest request, HttpServletResponse response, User user) - throws PersistenceException, ParseException, IOException, ValidationException { + throws PersistenceException, ParseException, IOException, ValidationException, ParserConfigurationException, SAXException { // Set the new LAMS Lesson Content Object CourseDocument bbContent = new blackboard.data.content.CourseDocument(); @@ -205,14 +209,14 @@ String courseIdStr = course.getCourseId(); // Start the Lesson in LAMS (via Webservices) and capture the lesson ID - final long LamsLessonIdLong = LamsSecurityUtil.startLesson(user, courseIdStr, ldId, strTitle, strDescription, + final long lamsLessonIdLong = LamsSecurityUtil.startLesson(user, courseIdStr, ldId, strTitle, strDescription, false); // error checking - if (LamsLessonIdLong == -1) { + if (lamsLessonIdLong == -1) { response.sendRedirect("lamsServerDown.jsp"); System.exit(1); } - String lamsLessonId = Long.toString(LamsLessonIdLong); + String lamsLessonId = Long.toString(lamsLessonIdLong); bbContent.setLinkRef(lamsLessonId); // Persist the New Lesson Object in Blackboard @@ -243,7 +247,7 @@ // Create new Gradebook column for current lesson if (isGradecenter) { String userName = user.getUserName(); - LineitemUtil.createLineitem(bbContent, strSequenceID, userName); + LineitemUtil.createLineitem(bbContent, userName); } // create a new thread to pre-add students and monitors to a lesson (in order to do this task in parallel not to @@ -253,7 +257,7 @@ Thread preaddLearnersMonitorsThread = new Thread(new Runnable() { @Override public void run() { - LamsSecurityUtil.preaddLearnersMonitorsToLesson(userFinal, courseFinal, LamsLessonIdLong); + LamsSecurityUtil.preaddLearnersMonitorsToLesson(userFinal, courseFinal, lamsLessonIdLong); } }, "LAMS_preaddLearnersMonitors_thread"); preaddLearnersMonitorsThread.start(); Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LineitemUtil.java =================================================================== diff -u -rf2a3c4096484b9fe80c78c5dde83c093ab40cec9 -ra9ef5fba9560f8028fc73bbda99f7456f1a7ebf0 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LineitemUtil.java (.../LineitemUtil.java) (revision f2a3c4096484b9fe80c78c5dde83c093ab40cec9) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LineitemUtil.java (.../LineitemUtil.java) (revision a9ef5fba9560f8028fc73bbda99f7456f1a7ebf0) @@ -24,20 +24,22 @@ import java.io.IOException; import java.io.InputStream; -import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; -import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.List; import java.util.Set; import javax.servlet.ServletException; -import javax.servlet.http.HttpServletResponse; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; -import org.apache.commons.io.IOUtils; import org.apache.log4j.Logger; import org.lamsfoundation.ld.integration.Constants; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.xml.sax.SAXException; import blackboard.data.ValidationException; import blackboard.data.content.Content; @@ -49,7 +51,6 @@ import blackboard.persist.BbPersistenceManager; import blackboard.persist.Container; import blackboard.persist.Id; -import blackboard.persist.KeyNotFoundException; import blackboard.persist.PersistenceException; import blackboard.persist.PkId; import blackboard.persist.content.ContentDbLoader; @@ -59,8 +60,6 @@ import blackboard.persist.gradebook.ext.OutcomeDefinitionScaleDbLoader; import blackboard.persist.gradebook.ext.OutcomeDefinitionScaleDbPersister; import blackboard.persist.gradebook.impl.OutcomeDefinitionDbPersister; -import blackboard.platform.BbServiceManager; -import blackboard.platform.context.Context; import blackboard.platform.persistence.PersistenceServiceFactory; import blackboard.portal.data.ExtraInfo; import blackboard.portal.data.PortalExtraInfo; @@ -72,8 +71,8 @@ private static Logger logger = Logger.getLogger(LineitemUtil.class); - public static void createLineitem(Content bbContent, String ldId, String userName) - throws ValidationException, PersistenceException, IOException { + public static void createLineitem(Content bbContent, String userName) + throws ValidationException, PersistenceException, IOException, ParserConfigurationException, SAXException { LineitemDbPersister linePersister = LineitemDbPersister.Default.getInstance(); OutcomeDefinitionDbPersister outcomeDefinitionPersister = OutcomeDefinitionDbPersister.Default.getInstance(); OutcomeDefinitionScaleDbLoader outcomeDefinitionScaleLoader = OutcomeDefinitionScaleDbLoader.Default @@ -102,7 +101,7 @@ outcomeDefinition.setCourseId(courseId); outcomeDefinition.setPosition(1); - boolean hasLessonScoreOutputs = LineitemUtil.hasLessonScoreOutputs(bbContent, ldId, userName); + boolean hasLessonScoreOutputs = LineitemUtil.hasLessonScoreOutputs(bbContent, userName); OutcomeDefinitionScale outcomeDefinitionScale; if (hasLessonScoreOutputs) { outcomeDefinitionScale = outcomeDefinitionScaleLoader.loadByCourseIdAndTitle(courseId, @@ -133,31 +132,19 @@ * * @throws IOException */ - private static boolean hasLessonScoreOutputs(Content bbContent, String ldId, String username) throws IOException { + private static boolean hasLessonScoreOutputs(Content bbContent, String username) throws IOException, ParserConfigurationException, SAXException { - //sequence_id parameter is null in case we come from modify_proc or CorrectLineItemServlet/CloneLessonsServlet/ImportLessonsServlet - if (ldId == null) { - //get sequence_id from bbcontent URL, set in start_lesson_proc - String bbContentUrl = bbContent.getUrl(); - String[] params = bbContentUrl.split("&"); - for (String param : params) { - String paramName = param.split("=")[0]; - String paramValue = param.split("=")[1]; + //at this moment bbContent contains already updated lessonId + String lessonId = bbContent.getLinkRef(); - if ("ldid".equals(paramName)) { - ldId = paramValue; - break; - } - } - } + String serviceURL = LamsSecurityUtil.getServerAddress() + "/services/xml/LessonManager?" + + LamsSecurityUtil.generateAuthenticateParameters(username) + + "&method=checkLessonForNumericToolOutputs&lsId=" + lessonId; - String learningDesignSvgUrl = LamsSecurityUtil.generateRequestLearningDesignImage(username, true) + "&ldId=" - + ldId.trim(); - - URL url = new URL(learningDesignSvgUrl); + URL url = new URL(serviceURL); URLConnection conn = url.openConnection(); if (!(conn instanceof HttpURLConnection)) { - throw new RuntimeException("Unable to open connection to: " + learningDesignSvgUrl); + throw new RuntimeException("Unable to open connection to: " + serviceURL); } HttpURLConnection httpConn = (HttpURLConnection) conn; @@ -167,15 +154,17 @@ + httpConn.getResponseMessage()); } - // InputStream is = url.openConnection().getInputStream(); InputStream is = conn.getInputStream(); // parse xml response - String learningDesignSvg = IOUtils.toString(is, "UTF-8"); - boolean hasLessonScoreOutputs = (learningDesignSvg.indexOf("icon_mcq.png") != -1) - || (learningDesignSvg.indexOf("icon_assessment.png") != -1); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(is); + Node lesson = document.getDocumentElement().getFirstChild(); + boolean hasNumericToolOutput = Boolean + .parseBoolean(lesson.getAttributes().getNamedItem("hasNumericToolOutput").getNodeValue()); - return hasLessonScoreOutputs; + return hasNumericToolOutput; } /** @@ -235,9 +224,11 @@ * @throws ServletException * @throws ValidationException * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException */ public static void updateLineitemLessonId(Content bbContent, String courseIdStr, Long newLamsLessonId, String userName) - throws PersistenceException, ServletException, ValidationException, IOException { + throws PersistenceException, ServletException, ValidationException, IOException, ParserConfigurationException, SAXException { LineitemDbLoader lineitemLoader = LineitemDbLoader.Default.getInstance(); LineitemDbPersister linePersister = LineitemDbPersister.Default.getInstance(); @@ -250,7 +241,7 @@ 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, null, userName); + createLineitem(bbContent, 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 -rdd7bd917e8d153853ee947c0853a4e3f536f93f3 -ra9ef5fba9560f8028fc73bbda99f7456f1a7ebf0 --- lams_bb_integration/web/modules/modify_proc.jsp (.../modify_proc.jsp) (revision dd7bd917e8d153853ee947c0853a4e3f536f93f3) +++ lams_bb_integration/web/modules/modify_proc.jsp (.../modify_proc.jsp) (revision a9ef5fba9560f8028fc73bbda99f7456f1a7ebf0) @@ -86,7 +86,7 @@ if (!bbContent.getIsDescribed() && isGradecenter) { String username = ctx.getUser().getUserName(); - LineitemUtil.createLineitem(bbContent, null, username); + LineitemUtil.createLineitem(bbContent, username); //if teacher turned Gradecenter option OFF (and it was ON previously) - remove lineitem } else if (bbContent.getIsDescribed() && !isGradecenter) {