Index: lams_bb_integration/RELEASE_NOTES.TXT =================================================================== RCS file: /usr/local/cvsroot/lams_bb_integration/RELEASE_NOTES.TXT,v diff -u -r1.17 -r1.18 --- lams_bb_integration/RELEASE_NOTES.TXT 3 Jul 2015 00:23:41 -0000 1.17 +++ lams_bb_integration/RELEASE_NOTES.TXT 20 Jul 2015 01:14:26 -0000 1.18 @@ -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/build.xml =================================================================== RCS file: /usr/local/cvsroot/lams_bb_integration/build.xml,v diff -u -r1.18 -r1.19 --- lams_bb_integration/build.xml 14 May 2015 11:33:48 -0000 1.18 +++ lams_bb_integration/build.xml 20 Jul 2015 01:14:26 -0000 1.19 @@ -2,7 +2,7 @@ - + Index: lams_bb_integration/WEB-INF/bb-manifest.xml =================================================================== RCS file: /usr/local/cvsroot/lams_bb_integration/WEB-INF/bb-manifest.xml,v diff -u -r1.23 -r1.24 --- lams_bb_integration/WEB-INF/bb-manifest.xml 14 May 2015 11:33:48 -0000 1.23 +++ lams_bb_integration/WEB-INF/bb-manifest.xml 20 Jul 2015 01:14:26 -0000 1.24 @@ -5,7 +5,7 @@ - + Index: lams_bb_integration/WEB-INF/web.xml =================================================================== RCS file: /usr/local/cvsroot/lams_bb_integration/WEB-INF/web.xml,v diff -u -r1.8 -r1.9 --- lams_bb_integration/WEB-INF/web.xml 11 Jun 2015 23:44:29 -0000 1.8 +++ lams_bb_integration/WEB-INF/web.xml 20 Jul 2015 01:14:26 -0000 1.9 @@ -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/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignDeleteServlet.java =================================================================== RCS file: /usr/local/cvsroot/lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignDeleteServlet.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignDeleteServlet.java 20 Jul 2015 01:10:20 -0000 1.1 @@ -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: LamsLearningDesignDeleteServlet.java,v 1.1 2015/07/20 01:10:20 fionam Exp $ */ +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 =================================================================== RCS file: /usr/local/cvsroot/lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignServlet.java,v diff -u -r1.2 -r1.3 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignServlet.java 16 Jul 2015 23:23:42 -0000 1.2 +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsLearningDesignServlet.java 20 Jul 2015 01:10:20 -0000 1.3 @@ -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 =================================================================== RCS file: /usr/local/cvsroot/lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/Attic/LamsSecurityUtil.java,v diff -u -r1.32 -r1.33 --- lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsSecurityUtil.java 16 Jul 2015 23:23:42 -0000 1.32 +++ lams_bb_integration/src/org/lamsfoundation/ld/integration/blackboard/LamsSecurityUtil.java 20 Jul 2015 01:10:20 -0000 1.33 @@ -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