Index: lams_build/3rdParty.userlibraries =================================================================== RCS file: /usr/local/cvsroot/lams_build/3rdParty.userlibraries,v diff -u -r1.32 -r1.33 --- lams_build/3rdParty.userlibraries 8 Feb 2008 00:44:37 -0000 1.32 +++ lams_build/3rdParty.userlibraries 19 Sep 2008 06:26:47 -0000 1.33 @@ -1,6 +1,8 @@ + + Index: lams_build/build.xml =================================================================== RCS file: /usr/local/cvsroot/lams_build/build.xml,v diff -u -r1.62 -r1.63 --- lams_build/build.xml 12 Aug 2008 04:45:08 -0000 1.62 +++ lams_build/build.xml 19 Sep 2008 06:26:47 -0000 1.63 @@ -118,6 +118,7 @@ + Index: lams_build/conf/j2ee/lams.application.xml =================================================================== RCS file: /usr/local/cvsroot/lams_build/conf/j2ee/lams.application.xml,v diff -u -r1.3 -r1.4 --- lams_build/conf/j2ee/lams.application.xml 8 Feb 2008 00:44:37 -0000 1.3 +++ lams_build/conf/j2ee/lams.application.xml 19 Sep 2008 06:26:44 -0000 1.4 @@ -76,6 +76,12 @@ + tk-autopatch-1.2.0-b2-cvs.jar + + + tk-discovery-1.0.0.jar + + axis.jar Index: lams_build/lib/autopatch/tk-autopatch-1.2.0-b2-cvs.jar =================================================================== RCS file: /usr/local/cvsroot/lams_build/lib/autopatch/Attic/tk-autopatch-1.2.0-b2-cvs.jar,v diff -u Binary files differ Index: lams_build/lib/autopatch/tk-discovery-1.0.0.jar =================================================================== RCS file: /usr/local/cvsroot/lams_build/lib/autopatch/tk-discovery-1.0.0.jar,v diff -u Binary files differ Index: lams_central/build.xml =================================================================== RCS file: /usr/local/cvsroot/lams_central/build.xml,v diff -u -r1.40 -r1.41 --- lams_central/build.xml 9 May 2007 01:05:24 -0000 1.40 +++ lams_central/build.xml 19 Sep 2008 06:26:42 -0000 1.41 @@ -89,6 +89,12 @@ + + + + + + @@ -275,8 +281,11 @@ - + + + + + @@ -296,39 +305,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Index: lams_central/conf/xdoclet/web-settings.xml =================================================================== RCS file: /usr/local/cvsroot/lams_central/conf/xdoclet/web-settings.xml,v diff -u -r1.15 -r1.16 --- lams_central/conf/xdoclet/web-settings.xml 31 Aug 2007 07:41:33 -0000 1.15 +++ lams_central/conf/xdoclet/web-settings.xml 19 Sep 2008 06:26:42 -0000 1.16 @@ -15,6 +15,7 @@ classpath:/org/lamsfoundation/lams/web/webApplicationContext.xml classpath:/org/lamsfoundation/lams/integrationContext.xml classpath:/org/lamsfoundation/lams/usermanagement/ldapContext.xml + classpath:/org/lamsfoundation/lams/dbupdates/autopatchContext.xml classpath:/org/lamsfoundation/lams/lesson/lessonApplicationContext.xml classpath:/org/lamsfoundation/lams/learning/learningApplicationContext.xml Index: lams_central/src/java/migration.properties =================================================================== RCS file: /usr/local/cvsroot/lams_central/src/java/migration.properties,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_central/src/java/migration.properties 19 Sep 2008 06:26:42 -0000 1.1 @@ -0,0 +1 @@ \ No newline at end of file Index: lams_common/build.xml =================================================================== RCS file: /usr/local/cvsroot/lams_common/build.xml,v diff -u -r1.61 -r1.62 --- lams_common/build.xml 25 Aug 2008 08:15:43 -0000 1.61 +++ lams_common/build.xml 19 Sep 2008 06:26:43 -0000 1.62 @@ -181,6 +181,8 @@ + + Index: lams_common/src/java/org/lamsfoundation/lams/dbupdates/Patch0011Alter21Integration.java =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/dbupdates/Attic/Patch0011Alter21Integration.java,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_common/src/java/org/lamsfoundation/lams/dbupdates/Patch0011Alter21Integration.java 19 Sep 2008 06:26:43 -0000 1.1 @@ -0,0 +1,202 @@ +/**************************************************************** + * 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: Patch0011Alter21Integration.java,v 1.1 2008/09/19 06:26:43 jliew Exp $ */ +package org.lamsfoundation.lams.dbupdates; + +import java.sql.Connection; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.Statement; +import java.util.ArrayList; + +import org.apache.log4j.Logger; + +import com.tacitknowledge.util.migration.MigrationContext; +import com.tacitknowledge.util.migration.MigrationException; +import com.tacitknowledge.util.migration.MigrationTaskSupport; +import com.tacitknowledge.util.migration.jdbc.DataSourceMigrationContext; + +/** + * @author jliew + * + * Update 3rd party integration courses to classes, LDEV-1284. + */ +public class Patch0011Alter21Integration extends MigrationTaskSupport { + + private static Logger log = Logger.getLogger(Patch0011Alter21Integration.class); + + private static final Integer LEVEL = new Integer(11); + private static final String NAME = "Alter21Integration"; + + // change integration orgs from classes to courses, with root org as parent. + private String updateToCourseType = "UPDATE lams_organisation " + + "SET organisation_type_id=2, " + + "parent_organisation_id=1 " + + "WHERE organisation_id IN ( " + + "SELECT classid " + + "FROM lams_ext_course_class_map " + + ")"; + + // we want to give these newly converted courses their own workspaces; + private String getCoursesWithoutWorkspaces = "SELECT organisation_id, name " + + "FROM lams_organisation " + + "WHERE organisation_type_id=2 " + + "AND workspace_id IS NULL"; + + // normal folder; + private String insertNormalFolder = "INSERT INTO lams_workspace_folder (name, user_id, create_date_time, " + + "last_modified_date_time, lams_workspace_folder_type_id) " + + "VALUES (?, ?, ?, ?, ?)"; + + // and run sequence folder + private String insertRunSequencesFolder = "INSERT INTO lams_workspace_folder (name, user_id, create_date_time, " + + "last_modified_date_time, lams_workspace_folder_type_id, parent_folder_id) " + + "VALUES (?, ?, ?, ?, ?, ?)"; + + // insert workspace, links to its folders, and link to its org + private String insertWorkspace = "INSERT INTO lams_workspace (name, default_fld_id, def_run_seq_fld_id) " + + "VALUES (?, ?, ?)"; + + private String insertLinks = "INSERT INTO lams_wkspc_wkspc_folder (workspace_id, workspace_folder_id) " + + "VALUES (?, ?)"; + + private String updateOrg = "UPDATE lams_organisation " + + "SET workspace_id=? " + + "WHERE organisation_id=?"; + + public Patch0011Alter21Integration () { + setLevel(LEVEL); + setName(NAME); + } + + public void migrate(MigrationContext context) throws MigrationException { + + // assuming we're using data source defined in application container + DataSourceMigrationContext ctx = (DataSourceMigrationContext) context; + + Connection conn = null; + + try { + conn = ctx.getConnection(); + log.debug("Connection.autoCommit=" + conn.getAutoCommit()); + conn.setAutoCommit(false); + + // update classes to courses + PreparedStatement query = conn.prepareStatement(updateToCourseType); + int numUpdatedCourses = query.executeUpdate(); + log.debug("Set " + numUpdatedCourses + " integration organisations to courses."); + + // get courses without workspaces + ArrayList orgs = new ArrayList(); + query = conn.prepareStatement(getCoursesWithoutWorkspaces); + ResultSet results = query.executeQuery(); + while (results.next()) { + orgs.add(new OrgDTO(results.getLong("organisation_id"), results.getString("name"))); + } + + // create workspace and folders for each org + for (OrgDTO org : orgs) { + // insert normal folder + query = conn.prepareStatement(insertNormalFolder, Statement.RETURN_GENERATED_KEYS); + query.setString(1, org.getOrgName()); + query.setLong(2, new Long(1)); + query.setDate(3, new Date(System.currentTimeMillis())); + query.setDate(4, new Date(System.currentTimeMillis())); + query.setInt(5, new Integer(1)); + int numInsert = query.executeUpdate(); + results = query.getGeneratedKeys(); + long wkspcFolderId = -1; + if (results.next()) wkspcFolderId = results.getLong(1); + log.debug("Inserted " + numInsert + " workspace folders, with id " + wkspcFolderId + "."); + + // insert run sequences folder + query = conn.prepareStatement(insertRunSequencesFolder, Statement.RETURN_GENERATED_KEYS); + query.setString(1, org.getOrgName()+" Run Sequences"); + query.setLong(2, new Long(1)); + query.setDate(3, new Date(System.currentTimeMillis())); + query.setDate(4, new Date(System.currentTimeMillis())); + query.setInt(5, new Integer(2)); + query.setLong(6, wkspcFolderId); + numInsert = query.executeUpdate(); + results = query.getGeneratedKeys(); + long wkspcRunFolderId = -1; + if (results.next()) wkspcRunFolderId = results.getLong(1); + log.debug("Inserted " + numInsert + " workspace folders, with id " + wkspcRunFolderId + "."); + + // insert workspace + query = conn.prepareStatement(insertWorkspace, Statement.RETURN_GENERATED_KEYS); + query.setString(1, org.getOrgName()); + query.setLong(2, wkspcFolderId); + query.setLong(3, wkspcRunFolderId); + numInsert = query.executeUpdate(); + results = query.getGeneratedKeys(); + long wkspcId = -1; + if (results.next()) wkspcId = results.getLong(1); + log.debug("Inserted " + numInsert + " workspaces, with id " + wkspcId + "."); + + // insert wkspc_wkspc_folder links + query = conn.prepareStatement(insertLinks); + query.setLong(1, wkspcId); + query.setLong(2, wkspcFolderId); + numInsert = query.executeUpdate(); + log.debug("Inserted " + numInsert + " wkspc_wkspc_folder links."); + query.setLong(1, wkspcId); + query.setLong(2, wkspcRunFolderId); + numInsert = query.executeUpdate(); + log.debug("Inserted " + numInsert + " wkspc_wkspc_folder links."); + + // update organisation with this workspace + query = conn.prepareStatement(updateOrg); + query.setLong(1, wkspcId); + query.setLong(2, org.getOrgId()); + numInsert = query.executeUpdate(); + log.debug("Updated " + org.getOrgName() + " with workspace_id " + wkspcId + "."); + } + + ctx.commit(); + + //conn.close(); // container managed data source + } catch (Exception e) { + ctx.rollback(); + throw new MigrationException("Problem running update; "); + } + } + + public class OrgDTO { + private Long orgId; + private String orgName; + public OrgDTO(Long orgId, String orgName) { + this.orgId = orgId; + this.orgName = orgName; + } + public Long getOrgId() { + return orgId; + } + public String getOrgName() { + return orgName; + } + } + +} + \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/dbupdates/autopatchContext.xml =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/dbupdates/Attic/autopatchContext.xml,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_common/src/java/org/lamsfoundation/lams/dbupdates/autopatchContext.xml 19 Sep 2008 06:26:43 -0000 1.1 @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch0013_updateFrom21.sql =================================================================== RCS file: /usr/local/cvsroot/lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch0013_updateFrom21.sql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch0013_updateFrom21.sql 19 Sep 2008 06:26:43 -0000 1.1 @@ -0,0 +1 @@ +-- SQL statements to update from LAMS 2.1/2.1.1 \ No newline at end of file