Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/GradebookServlet.java =================================================================== diff -u -re27f01d34eea709e255d542039faac9c4e46ac4d -rdc03f6c07b7eec19f6ab1c0ebd7b1826fbea5560 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/GradebookServlet.java (.../GradebookServlet.java) (revision e27f01d34eea709e255d542039faac9c4e46ac4d) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/GradebookServlet.java (.../GradebookServlet.java) (revision dc03f6c07b7eec19f6ab1c0ebd7b1826fbea5560) @@ -93,7 +93,6 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ContextManager ctxMgr = null; - String errorMsg = "error"; try { // get Blackboard context @@ -108,17 +107,18 @@ // check parameters if (userName == null || timeStamp == null || hash == null || lamsLessonIdParam == null) { - response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "missing expected parameters"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "missing expected parameters"); return; } //check user rights String secretKey = LamsPluginUtil.getSecretKey(); String serverId = LamsPluginUtil.getServerId(); - if (!sha1( + if (!LamsSecurityUtil.sha1( timeStamp.toLowerCase() + userName.toLowerCase() + serverId.toLowerCase() + secretKey.toLowerCase()).equals(hash)) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "authentication failed"); + return; } //check if isGradebookcenter @@ -155,7 +155,7 @@ User user = userLoader.loadByUserName(userName); if (user == null) { - throw new ServletException("user not found"); + throw new ServletException("User not found with userName:" + userName); } String serverAddr = LamsSecurityUtil.getServerAddress(); @@ -169,13 +169,13 @@ URL url = new URL(serviceURL); URLConnection conn = url.openConnection(); if (!(conn instanceof HttpURLConnection)) { - logger.error("Unable to open connection to: " + serviceURL); + throw new RuntimeException("Unable to open connection to: " + serviceURL); } HttpURLConnection httpConn = (HttpURLConnection) conn; if (httpConn.getResponseCode() != HttpURLConnection.HTTP_OK) { - errorMsg = "HTTP Response Code: " + httpConn.getResponseCode() + ", HTTP Response Message: " + String errorMsg = "HTTP Response Code: " + httpConn.getResponseCode() + ", HTTP Response Message: " + httpConn.getResponseMessage(); logger.error(errorMsg); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, errorMsg); @@ -277,59 +277,36 @@ scorePersister.persist(current_score); } catch (MalformedURLException e) { - errorMsg = "Unable to get LAMS learning designs, bad URL: " + ", please check lams.properties"; - logger.error(errorMsg, e); - e.printStackTrace(); - response.sendError(HttpServletResponse.SC_BAD_REQUEST, errorMsg); + throw new ServletException("Unable to get LAMS learning designs, bad URL: " + + ", please check lams.properties", e); } catch (IllegalStateException e) { - errorMsg = "LAMS Server timeout, did not get a response from the LAMS server. Please contact your systems administrator"; - logger.error(errorMsg, e); - e.printStackTrace(); - response.sendError(HttpServletResponse.SC_BAD_REQUEST, errorMsg); + throw new ServletException( + "LAMS Server timeout, did not get a response from the LAMS server. Please contact your systems administrator", + e); } catch (ConnectException e) { - errorMsg = "LAMS Server timeout, did not get a response from the LAMS server. Please contact your systems administrator"; - logger.error(errorMsg, e); - e.printStackTrace(); - response.sendError(HttpServletResponse.SC_BAD_REQUEST, errorMsg); + throw new ServletException( + "LAMS Server timeout, did not get a response from the LAMS server. Please contact your systems administrator", + e); } catch (UnsupportedEncodingException e) { - logger.error(e); - e.printStackTrace(); - response.sendError(HttpServletResponse.SC_BAD_REQUEST, errorMsg); + throw new ServletException(e); } catch (IOException e) { - logger.error(e); - e.printStackTrace(); - response.sendError(HttpServletResponse.SC_BAD_REQUEST, errorMsg); + throw new ServletException(e); } catch (ParserConfigurationException e) { - logger.error(e); - e.printStackTrace(); - response.sendError(HttpServletResponse.SC_BAD_REQUEST, errorMsg); + throw new ServletException(e); } catch (SAXException e) { - logger.error(e); - e.printStackTrace(); - response.sendError(HttpServletResponse.SC_BAD_REQUEST, errorMsg); + throw new ServletException(e); } catch (Exception e) { - e.printStackTrace(); - logger.error("Problem with gradebook servlet: " + e.getMessage(), e); - logger.error(e.getStackTrace().toString()); throw new ServletException(e); } finally { // make sure context is released - if (ctxMgr != null) + if (ctxMgr != null) { ctxMgr.releaseContext(); + } } response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.write("OK"); } - private String sha1(String str) { - try { - MessageDigest md = MessageDigest.getInstance("SHA1"); - return new String(Hex.encodeHex(md.digest(str.getBytes()))); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - } - } Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsActionRequestServlet.java =================================================================== diff -u -r8af1746d179f41095b074fef269722c6689b39eb -rdc03f6c07b7eec19f6ab1c0ebd7b1826fbea5560 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsActionRequestServlet.java (.../LamsActionRequestServlet.java) (revision 8af1746d179f41095b074fef269722c6689b39eb) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsActionRequestServlet.java (.../LamsActionRequestServlet.java) (revision dc03f6c07b7eec19f6ab1c0ebd7b1826fbea5560) @@ -35,76 +35,69 @@ import blackboard.platform.session.BbSession; import blackboard.platform.session.BbSessionManagerService; - /** - * Handles requests to the LAMS server - * - * @author Luke Foxton + * Handles requests to the LAMS server + * + * @author Luke Foxton */ public class LamsActionRequestServlet extends HttpServlet { - - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** + /** * The doGet method of the servlet.
- * - * This method is called by a when a GET request is performed - * There are three types of requests for LAMS AUTHOR, MONITOR and LEARNER - * Basically it creates the redirect URL strings and sends the redirect * - * @param request the request sent by the client to the server - * @param response the response sent by the server to the client + * This method is called by a when a GET request is performed There are three types of requests for LAMS AUTHOR, + * MONITOR and LEARNER Basically it creates the redirect URL strings and sends the redirect + * + * @param request + * the request sent by the client to the server + * @param response + * the response sent by the server to the client */ - public void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException{ - - //get request parameters - String p_method = request.getParameter(Constants.PARAM_METHOD); - - //String p_learningSessionId = request.getParameter(Constants.PARAM_LEARNING_SESSION_ID); - //String p_learningDesignId = request.getParameter(Constants.PARAM_LEARNING_DESIGN_ID); - String p_courseId = request.getParameter(Constants.PARAM_COURSE_ID); - - //validate method parameter and associated parameters - if(p_method == null) - { - throw new ServletException("requred parameters missing"); - } - + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - ContextManager ctxMgr = null; - Context ctx = null; - - try{ - // get Blackboard context - ctxMgr = (ContextManager) BbServiceManager.lookupService(ContextManager.class); - ctx = ctxMgr.setContext(request); - - - // get the session object to obtain the current user and course object - BbSessionManagerService sessionService = BbServiceManager.getSessionManagerService(); - BbSession bbSession = sessionService.getSession( request ); + // get request parameters + String p_method = request.getParameter(Constants.PARAM_METHOD); - String redirect = LamsSecurityUtil.generateRequestURL(ctx, p_method); + // String p_learningSessionId = request.getParameter(Constants.PARAM_LEARNING_SESSION_ID); + // String p_learningDesignId = request.getParameter(Constants.PARAM_LEARNING_DESIGN_ID); + String p_courseId = request.getParameter(Constants.PARAM_COURSE_ID); - if(p_courseId!=null) - { - redirect += '&' + Constants.PARAM_COURSE_ID + '=' + p_courseId; - //redirect1 += '&' + Constants.PARAM_LEARNING_SESSION_ID + '=' + p_learningSessionId; - } - - response.sendRedirect(response.encodeRedirectURL(redirect)); - - - } catch (Exception e){ - - throw new ServletException(e.getMessage(), e); - } - finally{ - //make sure context is released - if (ctxMgr != null) - ctxMgr.releaseContext(); - } + // validate method parameter and associated parameters + if (p_method == null) { + throw new ServletException("requred parameters missing"); + } + + ContextManager ctxMgr = null; + Context ctx = null; + + try { + // get Blackboard context + ctxMgr = (ContextManager) BbServiceManager.lookupService(ContextManager.class); + ctx = ctxMgr.setContext(request); + + // get the session object to obtain the current user and course object + BbSessionManagerService sessionService = BbServiceManager.getSessionManagerService(); + BbSession bbSession = sessionService.getSession(request); + + String redirect = LamsSecurityUtil.generateRequestURL(ctx, p_method); + + if (p_courseId != null) { + redirect += '&' + Constants.PARAM_COURSE_ID + '=' + p_courseId; + // redirect1 += '&' + Constants.PARAM_LEARNING_SESSION_ID + '=' + p_learningSessionId; + } + + response.sendRedirect(response.encodeRedirectURL(redirect)); + + } catch (Exception e) { + + throw new ServletException(e); + } finally { + // make sure context is released + if (ctxMgr != null) { + ctxMgr.releaseContext(); + } + } } } Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsSecurityUtil.java =================================================================== diff -u -re27f01d34eea709e255d542039faac9c4e46ac4d -rdc03f6c07b7eec19f6ab1c0ebd7b1826fbea5560 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsSecurityUtil.java (.../LamsSecurityUtil.java) (revision e27f01d34eea709e255d542039faac9c4e46ac4d) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsSecurityUtil.java (.../LamsSecurityUtil.java) (revision dc03f6c07b7eec19f6ab1c0ebd7b1826fbea5560) @@ -35,6 +35,7 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import javax.servlet.ServletException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -69,15 +70,15 @@ * @return a url pointing to the LAMS lesson, monitor, author session * @throws Exception */ - public static String generateRequestURL(Context ctx, String method) throws Exception { + public static String generateRequestURL(Context ctx, String method) { String serverAddr = getServerAddress(); String serverId = getServerID(); String reqSrc = getReqSrc(); // If lams.properties could not be read, throw exception if (serverAddr == null || serverId == null || reqSrc == null) { - throw new Exception("Configuration Exception " + serverAddr + ", " + serverId); + throw new RuntimeException("Configuration Exception " + serverAddr + ", " + serverId); } String timestamp = new Long(System.currentTimeMillis()).toString(); @@ -102,7 +103,7 @@ + "&email=" + email; } catch (UnsupportedEncodingException e) { - throw new RuntimeException(); + throw new RuntimeException(e); } logger.info("LAMS Req: " + url); @@ -113,15 +114,16 @@ /** * Generates default + * @throws UnsupportedEncodingException */ - public static String generateAuthenticateParameters(Context ctx) throws Exception { + public static String generateAuthenticateParameters(Context ctx) throws UnsupportedEncodingException { String serverAddr = getServerAddress(); String serverId = getServerID(); String reqSrc = getReqSrc(); // If lams.properties could not be read, throw exception if (serverAddr == null || serverId == null || reqSrc == null) { - throw new Exception("Configuration Exception " + serverAddr + ", " + serverId); + throw new RuntimeException("Configuration Exception " + serverAddr + ", " + serverId); } String timestamp = new Long(System.currentTimeMillis()).toString(); @@ -140,9 +142,9 @@ * @param ctx * the blackboard contect, contains session data * @return a url pointing to the LAMS lesson, monitor, author session - * @throws Exception + * @throws UnsupportedEncodingException */ - public static String generateRequestLearningDesignImage(Context ctx, boolean isSvgImage) throws Exception { + public static String generateRequestLearningDesignImage(Context ctx, boolean isSvgImage) throws UnsupportedEncodingException { String serverAddr = getServerAddress(); int svgFormat = (isSvgImage) ? 1 : 2; @@ -266,7 +268,6 @@ * @return the learning session id */ public static Long startLesson(Context ctx, long ldId, String title, String desc, boolean isPreview) { - Long error = new Long(-1); String serverId = getServerID(); String serverAddr = getServerAddress(); String serverKey = getServerKey(); @@ -442,7 +443,6 @@ } // generate authentication hash code to validate parameters - public static String generateAuthenticationHash(String datetime, String login, String serverId) { String secretkey = getServerKey(); @@ -472,7 +472,7 @@ * The string to be hashed * @return The hased string */ - private static String sha1(String str) { + public static String sha1(String str) { try { MessageDigest md = MessageDigest.getInstance("SHA1"); return new String(Hex.encodeHex(md.digest(str.getBytes()))); Index: lams_bb_integration/src/org/lamsfoundation/ld/util/LineitemUtil.java =================================================================== diff -u -re27f01d34eea709e255d542039faac9c4e46ac4d -rdc03f6c07b7eec19f6ab1c0ebd7b1826fbea5560 --- lams_bb_integration/src/org/lamsfoundation/ld/util/LineitemUtil.java (.../LineitemUtil.java) (revision e27f01d34eea709e255d542039faac9c4e46ac4d) +++ lams_bb_integration/src/org/lamsfoundation/ld/util/LineitemUtil.java (.../LineitemUtil.java) (revision dc03f6c07b7eec19f6ab1c0ebd7b1826fbea5560) @@ -23,8 +23,11 @@ /* $Id$ */ package org.lamsfoundation.ld.util; +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; @@ -36,6 +39,7 @@ import org.lamsfoundation.ld.integration.Constants; import org.lamsfoundation.ld.integration.blackboard.LamsSecurityUtil; +import blackboard.data.ValidationException; import blackboard.data.content.Content; import blackboard.data.content.CourseDocument; import blackboard.data.course.Course; @@ -63,7 +67,7 @@ private static Logger logger = Logger.getLogger(LineitemUtil.class); - public static void createLineitem(Context ctx, Content bbContent) throws Exception { + public static void createLineitem(Context ctx, Content bbContent) throws ValidationException, PersistenceException, IOException { BbPersistenceManager bbPm = BbServiceManager.getPersistenceService().getDbPersistenceManager(); @@ -132,9 +136,9 @@ * @param ctx * the blackboard contect, contains session data * @return a url pointing to the LAMS lesson, monitor, author session - * @throws Exception + * @throws IOException */ - private static boolean hasLessonScoreOutputs(Context ctx, Content bbContent) throws Exception { + private static boolean hasLessonScoreOutputs(Context ctx, Content bbContent) throws IOException { String ldId = ctx.getRequestParameter("sequence_id"); //sequence_id parameter is null in case we come from modify_proc if (ldId == null) { @@ -157,16 +161,14 @@ URL url = new URL(learningDesignSvgUrl); URLConnection conn = url.openConnection(); if (!(conn instanceof HttpURLConnection)) { - logger.error("Unable to open connection to: " + learningDesignSvgUrl); + throw new RuntimeException("Unable to open connection to: " + learningDesignSvgUrl); } HttpURLConnection httpConn = (HttpURLConnection) conn; if (httpConn.getResponseCode() != HttpURLConnection.HTTP_OK) { - String errorMsg = "HTTP Response Code: " + httpConn.getResponseCode() + ", HTTP Response Message: " - + httpConn.getResponseMessage(); - logger.error(errorMsg); - throw new RuntimeException(errorMsg); + throw new RuntimeException("HTTP Response Code: " + httpConn.getResponseCode() + + ", HTTP Response Message: " + httpConn.getResponseMessage()); } // InputStream is = url.openConnection().getInputStream(); @@ -190,6 +192,34 @@ if (!bbContent.getIsDescribed()) {//(isDescribed field is used for storing isGradecenter parameter) return; } + + Id lineitemId = getLineitem(bbContentId, courseIdStr); + LineitemDbPersister linePersister = (LineitemDbPersister) bbPm.getPersister(LineitemDbPersister.TYPE); + linePersister.deleteById(lineitemId); + + } + + public static void changeLineitemName(String bbContentId, String courseIdStr, String newLineitemName) + throws PersistenceException, ServletException, ValidationException { + BbPersistenceManager bbPm = BbServiceManager.getPersistenceService().getDbPersistenceManager(); + + Id lineitemId = getLineitem(bbContentId, courseIdStr); + + LineitemDbLoader lineitemLoader = (LineitemDbLoader) bbPm.getLoader(LineitemDbLoader.TYPE); + Lineitem lineitem = (Lineitem) lineitemLoader.loadById(lineitemId); + lineitem.setName(newLineitemName); + + LineitemDbPersister linePersister = (LineitemDbPersister) bbPm.getPersister(LineitemDbPersister.TYPE); + linePersister.persist(lineitem); + } + + /** + * Gets existing lineitem object. + * @throws ServletException + * @throws PersistenceException + */ + private static Id getLineitem(String bbContentId, String courseIdStr) throws ServletException, PersistenceException { + BbPersistenceManager bbPm = BbServiceManager.getPersistenceService().getDbPersistenceManager(); //get lineitemid from the storage (bbContentId -> lineitemid) PortalExtraInfo pei = PortalUtil.loadPortalExtraInfo(null, null, "LamsLineitemStorage"); @@ -223,7 +253,7 @@ } if (lineitem == null) { - throw new ServletException("Lineitem that corresponds to bbContentId: " + bbContentId + "was not found"); + throw new ServletException("Lineitem that corresponds to bbContentId: " + bbContentId + " was not found"); } // delete lineitem (can't delete it simply doing linePersister.deleteById(lineitem.getId()) due to BB9 bug) @@ -237,8 +267,6 @@ } Id lineitemId = bbPm.generateId(Lineitem.LINEITEM_DATA_TYPE, lineitemIdStr.trim()); - LineitemDbPersister linePersister = (LineitemDbPersister) bbPm.getPersister(LineitemDbPersister.TYPE); - linePersister.deleteById(lineitemId); - + return lineitemId; } } Index: lams_bb_integration/web/modules/create.jsp =================================================================== diff -u -re27f01d34eea709e255d542039faac9c4e46ac4d -rdc03f6c07b7eec19f6ab1c0ebd7b1826fbea5560 --- lams_bb_integration/web/modules/create.jsp (.../create.jsp) (revision e27f01d34eea709e255d542039faac9c4e46ac4d) +++ lams_bb_integration/web/modules/create.jsp (.../create.jsp) (revision dc03f6c07b7eec19f6ab1c0ebd7b1826fbea5560) @@ -129,8 +129,8 @@ - Yes - No + Yes + No Index: lams_bb_integration/web/modules/modify_proc.jsp =================================================================== diff -u -re27f01d34eea709e255d542039faac9c4e46ac4d -rdc03f6c07b7eec19f6ab1c0ebd7b1826fbea5560 --- lams_bb_integration/web/modules/modify_proc.jsp (.../modify_proc.jsp) (revision e27f01d34eea709e255d542039faac9c4e46ac4d) +++ lams_bb_integration/web/modules/modify_proc.jsp (.../modify_proc.jsp) (revision dc03f6c07b7eec19f6ab1c0ebd7b1826fbea5560) @@ -55,7 +55,7 @@ // Load the content item ContentDbLoader courseDocumentLoader = (ContentDbLoader) bbPm.getLoader( ContentDbLoader.TYPE ); - Content modifiedBbContent = (Content)courseDocumentLoader.loadById( contentId ); + Content bbContent = (Content)courseDocumentLoader.loadById( contentId ); // Get the form parameters and convert into correct data types // TODO: Use bb text area instead @@ -82,49 +82,53 @@ String strEndDateCheckbox = request.getParameter("lessonAvailability_end_checkbox"); //if teacher turned Gradecenter option ON (and it was OFF previously) - create lineitem - if (!modifiedBbContent.getIsDescribed() && isGradecenter) { - LineitemUtil.createLineitem(ctx, modifiedBbContent); + if (!bbContent.getIsDescribed() && isGradecenter) { + LineitemUtil.createLineitem(ctx, bbContent); //if teacher turned Gradecenter option OFF (and it was ON previously) - remove lineitem - } else if (modifiedBbContent.getIsDescribed() && !isGradecenter) { + } else if (bbContent.getIsDescribed() && !isGradecenter) { LineitemUtil.removeLineitem(contentIdStr, courseIdStr); + + //change existing lineitem's name if lesson name has been changed + } else if (isGradecenter && !strTitle.equals(bbContent.getTitle())) { + LineitemUtil.changeLineitemName(contentIdStr, courseIdStr, strTitle); } // Set LAMS content data in Blackboard - modifiedBbContent.setTitle(strTitle); - modifiedBbContent.setIsAvailable(isAvailable); - modifiedBbContent.setIsDescribed(isGradecenter);//isDescribed field is used for storing isGradecenter parameter - modifiedBbContent.setIsTracked(isTracked); - modifiedBbContent.setBody(description); + bbContent.setTitle(strTitle); + bbContent.setIsAvailable(isAvailable); + bbContent.setIsDescribed(isGradecenter);//isDescribed field is used for storing isGradecenter parameter + bbContent.setIsTracked(isTracked); + bbContent.setBody(description); // Set Availability Dates // Clear the date (set to null) if the checkbox is unchecked // Start Date if (strStartDateCheckbox != null){ if (strStartDateCheckbox.equals("1")){ - modifiedBbContent.setStartDate(startDate); + bbContent.setStartDate(startDate); } else { - modifiedBbContent.setStartDate(null); + bbContent.setStartDate(null); } } else { - modifiedBbContent.setStartDate(null); + bbContent.setStartDate(null); } // End Date if (strEndDateCheckbox != null){ if (strEndDateCheckbox.equals("1")){ - modifiedBbContent.setEndDate(endDate); + bbContent.setEndDate(endDate); } else { - modifiedBbContent.setEndDate(null); + bbContent.setEndDate(null); } } else { - modifiedBbContent.setEndDate(null); + bbContent.setEndDate(null); } //Persist the Modified Lesson Object in Blackboard ContentDbPersister persister= (ContentDbPersister) bbPm.getPersister( ContentDbPersister.TYPE ); - persister.persist( modifiedBbContent ); + persister.persist( bbContent ); - String strReturnUrl = PlugInUtil.getEditableContentReturnURL(modifiedBbContent.getParentId(), courseId); + String strReturnUrl = PlugInUtil.getEditableContentReturnURL(bbContent.getParentId(), courseId); %> <%-- Breadcrumbs --%>