Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/GradebookServlet.java =================================================================== diff -u -ra8aab0452b1fa93676367b8619c6e654e59dbb43 -r92a2cde4a59959ace402244f09cb68cc7269aa7a --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/GradebookServlet.java (.../GradebookServlet.java) (revision a8aab0452b1fa93676367b8619c6e654e59dbb43) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/GradebookServlet.java (.../GradebookServlet.java) (revision 92a2cde4a59959ace402244f09cb68cc7269aa7a) @@ -116,21 +116,38 @@ throw new ServletException("User not found with userName:" + userName); } Id userId = user.getId(); + + //allow lessonComplete.jsp on LAMS side to make an Ajax call to this servlet + String serverUrlWithLamsWord = LamsSecurityUtil.getServerAddress(); + URI uri = new URI(serverUrlWithLamsWord); + //strip out '/lams/' from the end of the URL + String serverUrl = serverUrlWithLamsWord.lastIndexOf(uri.getPath()) == -1 ? serverUrlWithLamsWord + : serverUrlWithLamsWord.substring(0, serverUrlWithLamsWord.lastIndexOf(uri.getPath())); + response.addHeader("Access-Control-Allow-Origin", serverUrl); - String serviceURL = LamsSecurityUtil.getServerAddress() + "/services/xml/LessonManager?" + Lineitem lineitem = LineitemUtil.getLineitem(userId, lamsLessonIdParam, false); + //notifying LAMS that servlet finished its work without exceptions but the score wasn't saved + if (lineitem == null) { + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.write("No Lineitem object found"); + return; + } + // do not remove the following line: it's required to instantiate the object + logger.info("Record score for " + lineitem.getName() + " lesson. It now has " + lineitem.getScores().size() + + " scores."); + + String getLamsMarkURL = LamsSecurityUtil.getServerAddress() + "/services/xml/LessonManager?" + LamsSecurityUtil.generateAuthenticateParameters(userName) + "&method=gradebookMarksUser" + "&lsId=" + lamsLessonIdParam + "&outputsUser=" + URLEncoder.encode(userName, "UTF8"); - - URL url = new URL(serviceURL); + URL url = new URL(getLamsMarkURL); URLConnection conn = url.openConnection(); if (!(conn instanceof HttpURLConnection)) { - throw new RuntimeException("Unable to open connection to: " + serviceURL); + throw new RuntimeException("Unable to open connection to: " + getLamsMarkURL); } - HttpURLConnection httpConn = (HttpURLConnection) conn; - if (httpConn.getResponseCode() != HttpURLConnection.HTTP_OK) { String errorMsg = "HTTP Response Code: " + httpConn.getResponseCode() + ", HTTP Response Message: " + httpConn.getResponseMessage(); @@ -141,7 +158,6 @@ // InputStream is = url.openConnection().getInputStream(); InputStream is = conn.getInputStream(); - // parse xml response DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); @@ -150,14 +166,6 @@ Node lesson = document.getDocumentElement().getFirstChild(); Node learnerResult = lesson.getFirstChild(); - Lineitem lineitem = LineitemUtil.getLineitem(userId, lamsLessonIdParam); - if (lineitem == null) { - throw new ServletException("Lineitem was not found for userId:" + userId + " and lamsLessonId:" + lamsLessonIdParam); - } - // do not remove the following line: it's required to instantiate the object - logger.info("Record score for " + lineitem.getName() + " lesson. It now has " + lineitem.getScores().size() - + " scores."); - // store new score CourseMembership courseMembership = courseMembershipLoader.loadByCourseAndUserId(lineitem.getCourseId(), userId); @@ -174,16 +182,6 @@ //updates and persists currentScore in the DB LineitemUtil.updateScoreBasedOnLamsResponse(lesson, learnerResult, currentScore); - // get LAMS server address - String serverUrlWithLamsWord = LamsSecurityUtil.getServerAddress(); - URI uri = new URI(serverUrlWithLamsWord); - //strip out '/lams/' from the end of the URL - String serverUrl = serverUrlWithLamsWord.lastIndexOf(uri.getPath()) == -1 ? serverUrlWithLamsWord - : serverUrlWithLamsWord.substring(0, serverUrlWithLamsWord.lastIndexOf(uri.getPath())); - - //allow lessonComplete.jsp on LAMS side to make an Ajax call to this servlet - response.addHeader("Access-Control-Allow-Origin", serverUrl); - //notifying LAMS that score has been stored successfully response.setContentType("text/html"); PrintWriter out = response.getWriter(); Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/GradebookSyncServlet.java =================================================================== diff -u -r718f1592143790b7e3cc8fd0d6bc2fc62717e7bf -r92a2cde4a59959ace402244f09cb68cc7269aa7a --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/GradebookSyncServlet.java (.../GradebookSyncServlet.java) (revision 718f1592143790b7e3cc8fd0d6bc2fc62717e7bf) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/GradebookSyncServlet.java (.../GradebookSyncServlet.java) (revision 92a2cde4a59959ace402244f09cb68cc7269aa7a) @@ -98,7 +98,7 @@ throw new RuntimeException("Requred parameters missing. lsid=" + lamsLessonIdParam); } - Lineitem lineitem = LineitemUtil.getLineitem(ctx.getUserId(), lamsLessonIdParam); + Lineitem lineitem = LineitemUtil.getLineitem(ctx.getUserId(), lamsLessonIdParam, true); if (lineitem == null) { throw new ServletException("Lineitem was not found for userId:" + ctx.getUserId() + " and lamsLessonId:" + lamsLessonIdParam); } @@ -224,7 +224,7 @@ response.setContentType("text/html"); PrintWriter out = response.getWriter(); - out.write("Complete! " + numberUpdatedScores + " marks have been updated/added to LMS Gradecenter."); + out.write("Complete! " + numberUpdatedScores + " marks have been updated/added to Blackboard Gradecenter."); } Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LineitemUtil.java =================================================================== diff -u -rea63a092873520f86f47c4204c513fbe0c62f5a8 -r92a2cde4a59959ace402244f09cb68cc7269aa7a --- lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LineitemUtil.java (.../LineitemUtil.java) (revision ea63a092873520f86f47c4204c513fbe0c62f5a8) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LineitemUtil.java (.../LineitemUtil.java) (revision 92a2cde4a59959ace402244f09cb68cc7269aa7a) @@ -401,10 +401,11 @@ * Finds lineitem by userId and lamsLessonId. The same as above method but first finds bbContentId and also checks * Grade center option is ON. * + * @param isThrowException whether exception should be thrown in case Gradecenter option is OFF or it should return simple null * @throws ServletException * @throws PersistenceException */ - public static Lineitem getLineitem(Id userId, String lamsLessonIdParam) + public static Lineitem getLineitem(Id userId, String lamsLessonIdParam, boolean isThrowException) throws ServletException, PersistenceException { BbPersistenceManager bbPm = PersistenceServiceFactory.getInstance().getDbPersistenceManager(); Container bbContainer = bbPm.getContainer(); @@ -429,8 +430,12 @@ Content bbContent = contentDbLoader.loadById(contentId); // check isGradecenter option is ON (bbContent.isDescribed field is used for storing isGradecenter parameter) if (!bbContent.getIsDescribed()) { - throw new LamsBuildingBlockException("Operation failed due to lesson (lessonId=" + lamsLessonIdParam - + ") has gradecenter option switched OFF."); + if (isThrowException) { + throw new LamsBuildingBlockException("Operation failed due to lesson (lessonId=" + lamsLessonIdParam + + ", bbContentId=" + bbContentId + ") has gradecenter option switched OFF."); + } else { + return null; + } } }