Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LessonManagerServlet.java =================================================================== diff -u -r615a2ef7e23ebd72fd36a62324e12a82fe2e1ac1 -re6a8d68204cbc85c94ba7504185f5f0581abbe88 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LessonManagerServlet.java (.../LessonManagerServlet.java) (revision 615a2ef7e23ebd72fd36a62324e12a82fe2e1ac1) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LessonManagerServlet.java (.../LessonManagerServlet.java) (revision e6a8d68204cbc85c94ba7504185f5f0581abbe88) @@ -298,4 +298,31 @@ request.getRequestDispatcher("/modules/modifyLessonSuccess.jsp").forward(request, response); } + private void delete(HttpServletRequest request, HttpServletResponse response, Context ctx) + throws InitializationException, BbServiceException, PersistenceException, IOException, ServletException { + + //remove Lineitem object from Blackboard DB + String bbContentId = request.getParameter("content_id"); + String courseId = request.getParameter("course_id"); + LineitemUtil.removeLineitem(bbContentId, courseId); + + // remove internalContentId -> externalContentId key->value pair (it's used for GradebookServlet) + PortalExtraInfo pei = PortalUtil.loadPortalExtraInfo(null, null, "LamsStorage"); + ExtraInfo ei = pei.getExtraInfo(); + ei.clearEntry(bbContentId); + PortalUtil.savePortalExtraInfo(pei); + + //remove lesson from LAMS server + BbPersistenceManager bbPm = PersistenceServiceFactory.getInstance().getDbPersistenceManager(); + Container bbContainer = bbPm.getContainer(); + ContentDbLoader courseDocumentLoader = ContentDbLoader.Default.getInstance(); + Id contentId = new PkId(bbContainer, CourseDocument.DATA_TYPE, bbContentId); + Content bbContent = courseDocumentLoader.loadById(contentId); + String lsId = bbContent.getLinkRef(); + String userName = ctx.getUser().getUserName(); + Boolean isDeletedSuccessfully = LamsSecurityUtil.deleteLesson(userName, lsId); + + System.out.println("Lesson (bbContentId:" + bbContentId + ") successfully deleted by userName:" + userName); + } + } Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LamsSecurityUtil.java =================================================================== diff -u -rbedb398d185d135e7505f51352f0c1037031ed27 -re6a8d68204cbc85c94ba7504185f5f0581abbe88 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LamsSecurityUtil.java (.../LamsSecurityUtil.java) (revision bedb398d185d135e7505f51352f0c1037031ed27) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/util/LamsSecurityUtil.java (.../LamsSecurityUtil.java) (revision e6a8d68204cbc85c94ba7504185f5f0581abbe88) @@ -447,7 +447,6 @@ } try { - String timestamp = new Long(System.currentTimeMillis()).toString(); String hash = generateAuthenticationHash(timestamp, username, serverId); String course = courseId != null ? "&courseId=" + URLEncoder.encode(courseId, "UTF8") : ""; @@ -493,6 +492,71 @@ } } + + /** + * Deletes lesson on LAMS server through a LAMS webservice. + * + * @param ctx + * the blackboard contect, contains session data + * @param usernameFromParam + * current user's username + * @param lsId + * the lesson id to be deleted + * + * @return boolean whether lesson was successfully deleted + */ + public static Boolean deleteLesson(String userName, String lsId) { + + String serverId = getServerID(); + String serverAddr = getServerAddress(); + String serverKey = getServerKey(); + + if (serverId == null || serverAddr == null || serverKey == null) { + throw new RuntimeException("Unable to delete lesson. One or more LAMS configuration properties are null"); + } + + try { + String timestamp = new Long(System.currentTimeMillis()).toString(); + String hash = generateAuthenticationHash(timestamp, userName, serverId); + + String serviceURL = serverAddr + "/services/xml/LessonManager?" + "serverId=" + + URLEncoder.encode(serverId, "utf8") + "&datetime=" + timestamp + "&username=" + + URLEncoder.encode(userName, "utf8") + "&hashValue=" + hash + "&method=removeLesson" + "&lsId=" + + lsId; + + logger.info("LAMS DELETE LESSON Req: " + serviceURL); + + // parse xml response and get the lesson id + InputStream is = LamsSecurityUtil.callLamsServerPost(serviceURL); + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + Document document = db.parse(is); + return Boolean.parseBoolean(document.getElementsByTagName("Lesson").item(0).getAttributes() + .getNamedItem("deleted").getNodeValue()); + + } catch (MalformedURLException e) { + throw new RuntimeException("Unable to start LAMS lesson, bad URL: '" + serverAddr + + "', please check lams.properties", e); + } catch (IllegalStateException e) { + throw new RuntimeException( + "LAMS Server timeout, did not get a response from the LAMS server. Please contact your systems administrator", + e); + } catch (RemoteException e) { + throw new RuntimeException("Unable to start LAMS lesson, RMI Remote Exception", e); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("Unable to start LAMS lesson, Unsupported Encoding Exception", e); + } catch (ConnectException e) { + throw new RuntimeException( + "LAMS Server timeout, did not get a response from the LAMS server. Please contact your systems administrator", + e); + } catch (IOException e) { + throw new RuntimeException("Unable to start LAMS lesson. " + e.getMessage() + + " Please contact your system administrator.", e); + } catch (Exception e) { + throw new RuntimeException("Unable to start LAMS lesson. Please contact your system administrator.", e); + } + + } /** * Clones lessons in lams through a LAMS webservice using the lsID & courseId parameter.