Index: lams_bb_integration/RELEASE_NOTES.TXT =================================================================== diff -u -r0ec3b20689e8ff67770a028165ef4ec45e8e2fde -ra992ac61e8e1ba2366392c77d1783147f48dbc5c --- lams_bb_integration/RELEASE_NOTES.TXT (.../RELEASE_NOTES.TXT) (revision 0ec3b20689e8ff67770a028165ef4ec45e8e2fde) +++ lams_bb_integration/RELEASE_NOTES.TXT (.../RELEASE_NOTES.TXT) (revision a992ac61e8e1ba2366392c77d1783147f48dbc5c) @@ -88,3 +88,7 @@ This module has new calls to list the sequences in the root of a user's account and to render a learning design image, which allows other deployment options on the Blackboard side. Also supports calls to the LAMS server to use a dummy course to suit the templates. + +1.2.12 Release Fixes +=================== +* LDEV-3456: Supports deleting learning designs. \ No newline at end of file Index: lams_bb_integration/WEB-INF/bb-manifest.xml =================================================================== diff -u -rb53690e16703a7a2fe1ff25384ac862373f75536 -ra992ac61e8e1ba2366392c77d1783147f48dbc5c --- lams_bb_integration/WEB-INF/bb-manifest.xml (.../bb-manifest.xml) (revision b53690e16703a7a2fe1ff25384ac862373f75536) +++ lams_bb_integration/WEB-INF/bb-manifest.xml (.../bb-manifest.xml) (revision a992ac61e8e1ba2366392c77d1783147f48dbc5c) @@ -5,7 +5,7 @@ - + Index: lams_bb_integration/WEB-INF/web.xml =================================================================== diff -u -r068e4100028edf75e5f748dd330c8996b13b7d46 -ra992ac61e8e1ba2366392c77d1783147f48dbc5c --- lams_bb_integration/WEB-INF/web.xml (.../web.xml) (revision 068e4100028edf75e5f748dd330c8996b13b7d46) +++ lams_bb_integration/WEB-INF/web.xml (.../web.xml) (revision a992ac61e8e1ba2366392c77d1783147f48dbc5c) @@ -14,6 +14,10 @@ org.lamsfoundation.ld.integration.blackboard.LamsLearningDesignServlet + LamsLearningDesignDeleteServlet + org.lamsfoundation.ld.integration.blackboard.LamsLearningDesignDeleteServlet + + GradebookServlet org.lamsfoundation.ld.integration.blackboard.GradebookServlet @@ -31,6 +35,10 @@ /LamsLearningDesign + LamsLearningDesignDeleteServlet + /LamsLearningDesignDelete + + UserDataServlet /UserData Index: lams_bb_integration/build.xml =================================================================== diff -u -rb53690e16703a7a2fe1ff25384ac862373f75536 -ra992ac61e8e1ba2366392c77d1783147f48dbc5c --- lams_bb_integration/build.xml (.../build.xml) (revision b53690e16703a7a2fe1ff25384ac862373f75536) +++ lams_bb_integration/build.xml (.../build.xml) (revision a992ac61e8e1ba2366392c77d1783147f48dbc5c) @@ -2,7 +2,7 @@ - + Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignDeleteServlet.java =================================================================== diff -u --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignDeleteServlet.java (revision 0) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignDeleteServlet.java (revision a992ac61e8e1ba2366392c77d1783147f48dbc5c) @@ -0,0 +1,103 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +/* $Id$ */ +package org.lamsfoundation.ld.integration.blackboard; + +import java.io.IOException; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.lamsfoundation.ld.integration.Constants; + +import blackboard.base.InitializationException; +import blackboard.platform.BbServiceException; +import blackboard.platform.BbServiceManager; +import blackboard.platform.context.Context; +import blackboard.platform.context.ContextManager; + +/** + * Makes a call to LAMS server to delete a learning design. + */ +public class LamsLearningDesignDeleteServlet extends HttpServlet { + + private static final long serialVersionUID = -351131323404991332L; + + public void doGet(HttpServletRequest request, HttpServletResponse response) { + + String serverAddr = LamsSecurityUtil.getServerAddress(); + String serverId = LamsSecurityUtil.getServerID(); + + // If lams.properties could not be read, throw exception + if (serverAddr == null || serverId == null) { + throw new RuntimeException("lams.properties file could not be read. serverAddr:" + serverAddr + ", serverId:" + serverId); + } + + // get request parameters + String courseId = request.getParameter("course_id"); + + String strLearningDesignId = request.getParameter("sequence_id"); + if ( strLearningDesignId != null ) { + strLearningDesignId.trim(); + } + + // validate method parameter and associated parameters + if ( strLearningDesignId == null || strLearningDesignId.length() == 0 ) { + throw new RuntimeException("Required parameters missing. Add sequence_id for the id of the learning design to be deleted"); + } + + long learningDesignId = 0; + try { + learningDesignId = Long.parseLong(strLearningDesignId); + } catch ( Exception e ) { + throw new RuntimeException("Required parameters missing. Add sequence_id for the id of the learning design to be deleted",e); + } + + ContextManager ctxMgr = null; + Context ctx = null; + try { + // get Blackboard context + ctxMgr = (ContextManager) BbServiceManager.lookupService(ContextManager.class); + ctx = ctxMgr.setContext(request); + + String serverResponse = LamsSecurityUtil.deleteLearningDesigns(ctx, courseId, learningDesignId); + + response.setContentType("application/json;charset=UTF-8"); + response.getWriter().print(serverResponse); + + } catch (InitializationException e) { + throw new RuntimeException(e); + } catch (BbServiceException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + // make sure context is released + if (ctxMgr != null) { + ctxMgr.releaseContext(); + } + } + } +} + Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignServlet.java =================================================================== diff -u -re7a6669f01c68c5071b0ae1f2074aa2398f01c70 -ra992ac61e8e1ba2366392c77d1783147f48dbc5c --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignServlet.java (.../LamsLearningDesignServlet.java) (revision e7a6669f01c68c5071b0ae1f2074aa2398f01c70) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignServlet.java (.../LamsLearningDesignServlet.java) (revision a992ac61e8e1ba2366392c77d1783147f48dbc5c) @@ -58,11 +58,6 @@ String folderId = request.getParameter(Constants.PARAM_FOLDER_ID); String courseId = request.getParameter("courseId"); - // validate method parameter and associated parameters - if (courseId == null) { - throw new RuntimeException("Required parameter missing. courseId=" + courseId); - } - //paging parameters of tablesorter - used in the LAMS Template Wizard boolean usePaging = false; String page = request.getParameter("page"); Index: lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsSecurityUtil.java =================================================================== diff -u -re7a6669f01c68c5071b0ae1f2074aa2398f01c70 -ra992ac61e8e1ba2366392c77d1783147f48dbc5c --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsSecurityUtil.java (.../LamsSecurityUtil.java) (revision e7a6669f01c68c5071b0ae1f2074aa2398f01c70) +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsSecurityUtil.java (.../LamsSecurityUtil.java) (revision a992ac61e8e1ba2366392c77d1783147f48dbc5c) @@ -107,7 +107,7 @@ // Even for authoring calls we still need a 'course' the user, role & organisation are all bound up together // do to be authorised to use authoring you must be in an organisation. - String courseId = ctx.getCourse()!=null ? ctx.getCourse().getCourseId() : DUMMY_COURSE; + String courseId = setupCourseId(ctx, null); String secretkey = LamsPluginUtil.getSecretKey(); @@ -213,7 +213,7 @@ * Gets a list of learning designs & workspace folders for the current user from LAMS. * * @param ctx the blackboard context, contains session data - * @param courseId blackboard courseid. We pass it as a parameter as ctx.getCourse().getCourseId() is null when called + * @param courseId blackboard course id. We pass it as a parameter as ctx.getCourse().getCourseId() is null when called * from LamsLearningDesignServlet. * @param folderId folderID in LAMS. It can be null and then LAMS returns default workspace folders. * @param method which method to call on the LAMS end @@ -222,9 +222,11 @@ * @return a string containing the LAMS workspace tree in tigra format (method = getLearningDesignsJSON) or * a string containing the learning designs in JSON (method = getPagedHomeLearningDesignsJSON) */ - public static String getLearningDesigns(Context ctx, String courseId, String folderId, String method, + public static String getLearningDesigns(Context ctx, String urlCourseId, String folderId, String method, String search, String page, String size, String sortName, String sortDate) { String serverAddr = getServerAddress(); + + String courseId = setupCourseId(ctx, urlCourseId); String serverId = getServerID(); // If lams.properties could not be read, throw exception @@ -310,6 +312,84 @@ return learningDesigns; } + /** + * Gets a list of learning designs & workspace folders for the current user from LAMS. + * + * @param ctx the blackboard context, contains session data + * @param courseId blackboard courseid. We pass it as a parameter as ctx.getCourse().getCourseId() is null when called + * from LamsLearningDesignServlet. + * @param ldId learning design to delete + * @return JSON response from server + */ + public static String deleteLearningDesigns(Context ctx, String urlCourseId, Long ldId) { + + String courseId = setupCourseId(ctx, urlCourseId); + + String serverAddr = getServerAddress(); + String serverId = getServerID(); + + // If lams.properties could not be read, throw exception + if (serverAddr == null || serverId == null) { + throw new RuntimeException("lams.properties file could not be read. serverAddr:" + serverAddr + ", serverId:" + serverId); + } + + String timestamp = new Long(System.currentTimeMillis()).toString(); + String username = ctx.getUser().getUserName(); + String firstName = ctx.getUser().getGivenName(); + String lastName = ctx.getUser().getFamilyName(); + String email = ctx.getUser().getEmailAddress(); + String hash = generateAuthenticationHash(timestamp, username, serverId); + + String locale = ctx.getUser().getLocale(); + String country = getCountry(locale); + String lang = getLanguage(locale); + + try { + + String serviceURL = serverAddr + + "/services/xml/LearningDesignRepository?method=deleteLearningDesignJSON&datetime=" + + timestamp + "&username=" + URLEncoder.encode(username, "utf8") + "&serverId=" + + URLEncoder.encode(serverId, "utf8") + "&hashValue=" + hash + "&courseId=" + + URLEncoder.encode(courseId, "UTF8") + "&country=" + country + "&lang=" + lang + + "&firstName=" + URLEncoder.encode(firstName, "UTF-8") + "&lastName=" + + URLEncoder.encode(lastName, "UTF-8") + "&email=" + URLEncoder.encode(email, "UTF-8") + + "&learningDesignID="+ldId; + + InputStream is = LamsSecurityUtil.callLamsServer(serviceURL); + + // Read/convert response to a String + StringWriter writer = new StringWriter(); + IOUtils.copy(is, writer, "UTF-8"); + return writer.toString(); + + } catch (MalformedURLException e) { + throw new RuntimeException("Unable to get LAMS learning designs, 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 (ConnectException e) { + throw new RuntimeException( + "LAMS Server timeout, did not get a response from the LAMS server. Please contact your systems administrator", + e); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private static String setupCourseId(Context ctx, String urlCourseId) { + // can we pull the alphanumeric course id from the context, rather than the on passed in from the URL? If neither exist, use the dummy Preview course. + String courseId = null; + if ( ctx.getCourse()!=null ) + courseId = ctx.getCourse().getCourseId(); + if ( courseId == null ) + courseId = urlCourseId != null && urlCourseId.length() > 0 ? urlCourseId : DUMMY_COURSE; + return courseId; + } + /** * Starts lessons in lams through a LAMS webservice