Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/CreateLibraryPackageTask.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/CreateLibraryPackageTask.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/CreateLibraryPackageTask.java (revision 7bcd6f90150d5c8f5eefaa00e989603de9f6ed19) @@ -0,0 +1,126 @@ +/* +Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +http://www.gnu.org/licenses/gpl.txt +*/ + +/* + * Created on 29/11/2005 + */ +package org.lamsfoundation.lams.tool.deploy.libraryActivity; + + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.net.URL; +import java.util.Iterator; +import java.util.Properties; + +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DynamicConfigurator; +import org.apache.tools.ant.Task; +import org.lamsfoundation.lams.tool.deploy.CreatePackageTask; +import org.lamsfoundation.lams.tool.deploy.DeployException; +import org.lamsfoundation.lams.tool.deploy.DeployToolConfig; +import org.xml.sax.SAXException; + +/** + * @author Mailing Truong + * + * Creates a library deployment package. Ant Task. + * Specifies the implementation for the Ant's Task execute() method. + * Other methods used are inherited from parent class CreatePackageTask + * + * Files created: deploy.xml + * + * A deploy.xml file is created. It is built from two sources - + * a configuration file supplied at runtime and ant task parameter. + * + * The configuration file supplied, should contain the list of learning libraries + * to deploy and all tool activities that are a part of the learning library. + * Settings these values via an Ant Task is not yet supported. However the ant task + * parameters can be used to set the database values. + * + * The DeployLibraryConfig object is created and the specified configuration file + * will set up values for the LearningLibrary, ToolActivity objects and if you want, + * the db settings. If the program is running as an ant task, then the task parameters + * (usually for the db settings) are checked and added to the DeployLibraryConfig + * object. + * + * Ant task parameters: + * + * + */ +public class CreateLibraryPackageTask extends CreatePackageTask { + + /* ************** ANT Task Methods *****************************/ + public void execute() { + log("Create Library Deployment Package."); + + // create the new configuration file, using the template + //deployConfig = new DeployToolConfig(getTemplateDeployName()); + deployConfig = new DeployLibraryConfig(); + // override with values from an optional config file + if ( configFile != null && configFile.length() > 0 ) { + log("Applying configuration file "+configFile.getAbsolutePath()); + //deployConfig.updateConfiguration(configFile.getAbsolutePath(), false); + try + { + deployConfig.updateConfigurationProperties(configFile.getAbsolutePath()); + } + catch(ParserConfigurationException e) + { + throw new DeployException("Could not parse the XML file" + e.getMessage(), e); + } + catch(IOException e) + { + throw new DeployException("Please check the file or file path. Error is:" + e.getMessage(), e); + } + catch(SAXException e) + { + throw new DeployException(e.getMessage()); + } + } + + applyParameters(); + deployConfig.validateProperties(); + try + { + writeConfigFile(); //change this to write out xml file instead + } + catch(IOException e) + { + throw new DeployException(e.getMessage()); + } + } + + /* ************** End Interface/Inherited Methods *****************************/ + + +} Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/DeployLibrary.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/DeployLibrary.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/DeployLibrary.java (revision 7bcd6f90150d5c8f5eefaa00e989603de9f6ed19) @@ -0,0 +1,75 @@ +/* +Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +http://www.gnu.org/licenses/gpl.txt +*/ + +/* + * Created on 17/11/2005 + */ +package org.lamsfoundation.lams.tool.deploy.libraryActivity; + +import java.io.IOException; + +import javax.xml.parsers.ParserConfigurationException; + +import org.xml.sax.SAXException; +/** + * @author mtruong + * + * Deployer for library activities that contain more than one tool activity. + * Currently, is only supported for the complex activity types: parallel, + * options, sequence + * + * The main logic is adopted from Deploy.java + * See org.lamsfoundation.lams.tool.deploy.Deploy + */ +public class DeployLibrary { + + public DeployLibrary() { + + } + + public static void main (String[] args) + { + if ((args.length < 1) || (args[0] == null)) + { + throw new IllegalArgumentException("Usage: Deployer ." ); + } + + System.out.println("Starting Library Deploy"); + + try + { + DeployLibraryConfig config= new DeployLibraryConfig(args[0]); + LibraryDBDeployTask deployTask = new LibraryDBDeployTask(config); + deployTask.execute(); + System.out.println("Library Deployed"); + + } + catch (Exception ex) + { + System.out.println("TOOL DEPLOY FAILED"); + ex.printStackTrace(); + } + + + + } + +} Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/DeployLibraryConfig.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/DeployLibraryConfig.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/DeployLibraryConfig.java (revision 7bcd6f90150d5c8f5eefaa00e989603de9f6ed19) @@ -0,0 +1,247 @@ +/* +Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +http://www.gnu.org/licenses/gpl.txt +*/ + +/* + * Created on 24/11/2005 + * + */ +package org.lamsfoundation.lams.tool.deploy.libraryActivity; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Iterator; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.lamsfoundation.lams.tool.deploy.DeployConfig; +import org.lamsfoundation.lams.tool.deploy.DeployException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + + +/** + * @author mtruong + * + * Encapsulates configuration data for the Library deployer + */ +public class DeployLibraryConfig extends DeployConfig { + + private static Log log = LogFactory.getLog(DeployLibraryConfig.class); + + private static final String LEARNING_LIBRARY = "learningLibrary"; + private static final String LIBRARY_INSERT_SCRIPT = "libraryInsertScriptPath"; + private static final String TEMPLATE_ACTIVITY_INSERT_SCRIPT = "templateActivityInsertScriptPath"; + private static final String TOOL_ACTIVITY = "toolActivity"; + private static final String LEARNING_LIBRARY_LIST = "learningLibraryList"; + private static final String TOOL_ACTIVITY_LIST = "toolActivityList"; + + private ArrayList learningLibraryList; + + public DeployLibraryConfig() + { + xstream.alias(ROOT_ELEMENT, DeployLibraryConfig.class); + xstream.alias(LEARNING_LIBRARY, LearningLibrary.class); + xstream.alias(TOOL_ACTIVITY, ToolActivity.class); + } + + public DeployLibraryConfig( String dbUsername, + String dbPassword, + String dbDriverClass, + String dbDriverUrl, + ArrayList learningLibraries) + { + setDbUsername(dbUsername); + setDbPassword(dbPassword); + setDbDriverClass(dbDriverClass); + setDbDriverUrl(dbDriverUrl); + this.learningLibraryList = learningLibraries; + + xstream.alias(ROOT_ELEMENT, DeployLibraryConfig.class); + xstream.alias(LEARNING_LIBRARY, LearningLibrary.class); + xstream.alias(TOOL_ACTIVITY, ToolActivity.class); + } + + public DeployLibraryConfig(String configurationFilePath) throws ParserConfigurationException, IOException, SAXException + { + super(); + xstream.alias(ROOT_ELEMENT, DeployLibraryConfig.class); + xstream.alias(LEARNING_LIBRARY, LearningLibrary.class); + xstream.alias(TOOL_ACTIVITY, ToolActivity.class); + updateConfigurationProperties(configurationFilePath); + } + + /** + * Takes in the file path location of the XML configuration file. + * Parses the configuration file and will create + * LearningLibrary object(s) and ToolActivity object(s). + * + * @param configFilePath the file path for the XML configuration file + * @throws ParserConfigurationException + * @throws IOException + * @throws SAXException + */ + public void updateConfigurationProperties(String configFilePath) throws ParserConfigurationException, IOException, SAXException + { + String xml = readFile(configFilePath); + DeployLibraryConfig config = (DeployLibraryConfig)deserialiseXML(xml); + copyProperties(config); + } + + /** + * Upon deserialisation of the xml string, a new object will be created. + * The properties of this object will be copied to the calling object. + * Only copy properties if the properties are not null + * @param config + */ + private void copyProperties(DeployLibraryConfig config) + { + if (config.getDbUsername() != null) + this.setDbUsername(config.getDbUsername()); + if (config.getDbPassword() != null) + this.setDbPassword(config.getDbPassword()); + if (config.getDbDriverUrl() != null) + this.setDbDriverUrl(config.getDbDriverUrl()); + if (config.getDbDriverClass() != null) + this.setDbDriverClass(config.getDbDriverClass()); + if (config.getLearningLibraryList() != null) + this.setLearningLibraryList(config.getLearningLibraryList()); + } + + public void printObjectProperties() + { + System.out.println("========Object Properties======="); + System.out.println("DbUsername: " + getDbUsername()); + System.out.println("DbPassword: " + getDbPassword()); + System.out.println("DbDriverClass: " + getDbDriverClass()); + System.out.println("DbDriverUrl: " + getDbDriverUrl()); + ArrayList learningLibraries = getLearningLibraryList(); + for (int j=0; j libraryInsertScriptPath: " + libraryActivity.getLibraryInsertScriptPath()); + System.out.println("\t Learning Library " + j + "-> templateActivityInsertScriptPath: " + libraryActivity.getTemplateActivityInsertScriptPath()); + + ArrayList list = libraryActivity.getToolActivityList(); + for (int i=0; i< list.size(); i++) + { + ToolActivity a = (ToolActivity)list.get(i); + System.out.println("\t\tToolActivity "+ i + "-> ToolSignature: " + a.getToolSignature()); + System.out.println("\t\tToolActivity "+ i + "-> ToolActivityScriptPath: " + a.getToolActivityInsertScriptPath()); + } + } + System.out.println("========End Object Properties======="); + } + + public void validateProperties() throws DeployException { + boolean valid; + validationError = ""; // object attribute - will be updated by validateProperty() if something is missing. + + valid = validateStringProperty(getDbUsername(), DB_USERNAME); + valid = valid && validateStringProperty(getDbPassword(), DB_PASSWORD); + valid = valid && validateStringProperty(getDbDriverClass(), DB_PASSWORD); + valid = valid && validateStringProperty(getDbDriverUrl(), DB_DRIVER_URL); + valid = valid && validateListProperty(getLearningLibraryList(),LEARNING_LIBRARY_LIST); + + //iterate through learning libraries + ArrayList learningLibraries = getLearningLibraryList(); + if (learningLibraries != null) + { + Iterator libraryIterator = learningLibraries.iterator(); + while (libraryIterator.hasNext()) + { + LearningLibrary learningLibrary = (LearningLibrary)libraryIterator.next(); + valid = valid && validateStringProperty(learningLibrary.getLibraryInsertScriptPath(), LIBRARY_INSERT_SCRIPT); + valid = valid && validateStringProperty(learningLibrary.getTemplateActivityInsertScriptPath(), TEMPLATE_ACTIVITY_INSERT_SCRIPT); + ArrayList toolActivities = learningLibrary.getToolActivityList(); + + valid = valid && validateListProperty(toolActivities, TOOL_ACTIVITY_LIST); + if (toolActivities != null) + { + Iterator toolActivityIterator = toolActivities.iterator(); + while (toolActivityIterator.hasNext()) + { + ToolActivity toolActivity = (ToolActivity)toolActivityIterator.next(); + valid = valid && validateStringProperty(toolActivity.getToolActivityInsertScriptPath(), TOOL_ACTIVITY_INSERT_SCRIPT_PATH); + valid = valid && validateStringProperty(toolActivity.getToolSignature(), TOOL_SIGNATURE); + } + } + + } + } + + + if ( ! valid ) + throw new DeployException("Invalid deployment properties: "+validationError); + } + + /* public void writePropertiesToFile(Writer writer) + { + xstream.toXML(this, writer); + } */ + + /*protected void setProperty(String key, String value) throws DeployException { + if ( key == null ) + throw new DeployException("Invalid parameter: Key is null. "); + + //super.setProperty(key, value); + + System.out.println("LibraryConfig " + key + " is: " + value); + + if ( key.equalsIgnoreCase(DB_USERNAME) ) { + setDbUsername(value); + } + + if ( key.equalsIgnoreCase(DB_PASSWORD) ) { + setDbPassword(value); + } + + if ( key.equalsIgnoreCase(DB_DRIVER_CLASS) ) { + setDbDriverClass(value); + } + + if ( key.equalsIgnoreCase(DB_DRIVER_URL) ) { + setDbDriverUrl(value); + } + } */ + + + /** + * @return Returns the learningLibraryList. + */ + public ArrayList getLearningLibraryList() { + return learningLibraryList; + } + /** + * @param learningLibraryList The learningLibraryList to set. + */ + public void setLearningLibraryList(ArrayList learningLibraryList) { + this.learningLibraryList = learningLibraryList; + } +} Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/LearningLibrary.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/LearningLibrary.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/LearningLibrary.java (revision 7bcd6f90150d5c8f5eefaa00e989603de9f6ed19) @@ -0,0 +1,90 @@ +/* +Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +http://www.gnu.org/licenses/gpl.txt +*/ + +/* + * Created on 17/11/2005 + * + */ +package org.lamsfoundation.lams.tool.deploy.libraryActivity; + +import java.util.ArrayList; + +/** + * @author mtruong + */ +public class LearningLibrary { + + private String libraryInsertScriptPath; + private String templateActivityInsertScriptPath; + private ArrayList toolActivityList; + + + public LearningLibrary() + { + } + + public LearningLibrary(String libraryInsertScript, String templateActivityInsertScript, ArrayList toolActivityList) + { + this.libraryInsertScriptPath = libraryInsertScript; + this.templateActivityInsertScriptPath = templateActivityInsertScript; + this.toolActivityList = toolActivityList; + } + + + /** + * @return Returns the libraryActivityInsertScriptPath. + */ + public String getTemplateActivityInsertScriptPath() { + return templateActivityInsertScriptPath; + } + /** + * @param libraryActivityInsertScriptPath The libraryActivityInsertScriptPath to set. + */ + public void setTemplateActivityInsertScriptPath( + String libraryActivityInsertScriptPath) { + this.templateActivityInsertScriptPath = libraryActivityInsertScriptPath; + } + /** + * @return Returns the toolActivities. + */ + public ArrayList getToolActivityList() { + return toolActivityList; + } + /** + * @param toolActivities The toolActivities to set. + */ + public void setToolActivityList(ArrayList toolActivities) { + this.toolActivityList = toolActivities; + } + + /** + * @return Returns the libraryInsertScriptPath. + */ + public String getLibraryInsertScriptPath() { + return libraryInsertScriptPath; + } + /** + * @param libraryInsertScriptPath The libraryInsertScriptPath to set. + */ + public void setLibraryInsertScriptPath(String libraryInsertScriptPath) { + this.libraryInsertScriptPath = libraryInsertScriptPath; + } +} Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/LibraryDBDeployTask.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/LibraryDBDeployTask.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/LibraryDBDeployTask.java (revision 7bcd6f90150d5c8f5eefaa00e989603de9f6ed19) @@ -0,0 +1,266 @@ +/* +Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +http://www.gnu.org/licenses/gpl.txt +*/ + +/* + * Created on 17/11/2005 + * + */ +package org.lamsfoundation.lams.tool.deploy.libraryActivity; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.apache.commons.dbutils.DbUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.lamsfoundation.lams.tool.deploy.DBTask; +import org.lamsfoundation.lams.tool.deploy.DeployException; +import org.lamsfoundation.lams.tool.deploy.FileTokenReplacer; +import org.lamsfoundation.lams.tool.deploy.ScriptRunner; + +/** + * @author mtruong + * + * Task to deploy a learning library that contains one or + * more tool activities. + * + */ +public class LibraryDBDeployTask extends DBTask { + + private static Log log = LogFactory.getLog(LibraryDBDeployTask.class); + + private ArrayList learningLibraries; + + public LibraryDBDeployTask() + {} + + public LibraryDBDeployTask(DeployLibraryConfig config) + { + this.setDbDriverClass(config.getDbDriverClass()); + this.setDbDriverUrl(config.getDbDriverUrl()); + this.setDbPassword(config.getDbPassword()); + this.setDbUsername(config.getDbUsername()); + this.learningLibraries = config.getLearningLibraryList(); + } + /** + * Loop through the library activities + * 1) insert library script -> returns the learning_library_id + * 2) update library activity script with learning_library_id + * 3) run library activity script -> returns the activity_id + * 4) Loop through tool activities + * a) Find the tool_id that matches the tool_signature + * b) Update tool activity script with tool_id and parent_activity_id equal to the activity_id from step 3 + * c) run the tool activity script + */ + + public void execute() throws DeployException + { + Connection conn = getConnection(); + try + { + conn.setAutoCommit(false); + + Iterator i = learningLibraries.iterator(); + //iterating through learning libraries + while (i.hasNext()) + { + LearningLibrary learningLibrary = (LearningLibrary)i.next(); + + String libraryInsertScriptPath = learningLibrary.getLibraryInsertScriptPath(); + File libraryInsertScript = new File(libraryInsertScriptPath); + long learningLibraryId = runLibraryScript(readFile(libraryInsertScript), conn, "lams_learning_library"); + + log.debug("The learning_library_id is learningLibraryId"); + + //put the library id into the library activity insert script + Map replacementMap = new HashMap(1); + replacementMap.put("learning_library_id", Long.toString(learningLibraryId)); + FileTokenReplacer activityScriptReplacer = new FileTokenReplacer(new File(learningLibrary.getTemplateActivityInsertScriptPath()), replacementMap); + String libraryActivityScriptSQL = activityScriptReplacer.replace(); + + + long parentActivityId = runLibraryScript(libraryActivityScriptSQL, conn, "lams_learning_activity"); + log.debug("Parent Learning Activity ID is: " + parentActivityId); + + ArrayList toolActivities = learningLibrary.getToolActivityList(); + + Iterator j = toolActivities.iterator(); + + //iterating through tool activities within a particular learning library + while (j.hasNext()) + { + ToolActivity toolActivity = (ToolActivity)j.next(); + //lookup tool_id from toolSignature + long toolId = getToolId(toolActivity.getToolSignature(), conn); + + //put the tool_id and parent_activity_id into the tool activity insert script + replacementMap = new HashMap(1); + replacementMap.put("tool_id", Long.toString(toolId)); + replacementMap.put("parent_activity_id", Long.toString(parentActivityId)); + FileTokenReplacer toolTablesScriptReplacer = new FileTokenReplacer(new File(toolActivity.getToolActivityInsertScriptPath()), replacementMap); + String toolTablesScriptSQL = toolTablesScriptReplacer.replace(); + + runScript(toolTablesScriptSQL, conn); + + } + } + // commit transaction + conn.commit(); + + } + catch (SQLException sqlex) + { + try + { + DbUtils.rollback(conn); + } + catch (SQLException sqlex2) + { + throw new DeployException("Attempted to rollback because of "+sqlex+" but failed - cleanup maybe required (see root cause)", sqlex2); + } + throw new DeployException("Execute failed", sqlex); + } + catch (DeployException dex) + { + try + { + DbUtils.rollback(conn); + } + catch (SQLException sqlex) + { + throw new DeployException("Attempted to rollback because of "+dex+" but failed - cleanup maybe required (see root cause)", sqlex); + } + throw dex; + } + finally + { + DbUtils.closeQuietly(conn); + } + + } + + /** + * Looks up current tool installations for the tool with toolSignature + * The tool_id for the tool with the matching tool signature will be returned. + * @param toolSignature + * @param conn + * @return + */ + public long getToolId(String toolSignature, Connection conn) + { + PreparedStatement stmt = null; + ResultSet results = null; + try + { + stmt = conn.prepareStatement("SELECT tool_id FROM lams_tool WHERE tool_signature=?"); + stmt.setString(1, toolSignature); + stmt.execute(); + + results = stmt.executeQuery(); + if (results.next()) + { + return results.getLong("tool_id"); + } + else + { + throw new DeployException("Tool id for tool signature " + toolSignature + " not found."); + } + + } + catch (SQLException sqlex) + { + throw new DeployException("Tool id for tool signature " + toolSignature + " not found.", sqlex); + } + finally + { + DbUtils.closeQuietly(stmt); + DbUtils.closeQuietly(results); + } + } + + + /** + * Runs the sql statements and will return the last inserted id from the particular + * table. + * @param scriptSQL The sql to run + * @param conn + * @param tablename The table which to query for the last inserted id. + * @return the last inserted id from tablename + * @throws DeployException + */ + private long runLibraryScript(final String scriptSQL, final Connection conn, String tablename) throws DeployException + { + runScript(scriptSQL, conn); + PreparedStatement stmt = null; + ResultSet results = null; + try + { + stmt = conn.prepareStatement("SELECT LAST_INSERT_ID() FROM " + tablename); + results = stmt.executeQuery(); + if (results.next()) + { + return results.getLong("LAST_INSERT_ID()"); + } + else + { + throw new DeployException("Could not get the last inserted id from table " + tablename); + } + } + catch (SQLException sqlex) + { + throw new DeployException("Failed to run learning library script",sqlex); + } + finally + { + DbUtils.closeQuietly(stmt); + DbUtils.closeQuietly(results); + } + + } + + private void runScript(final String scriptSQL, final Connection conn) throws DeployException + { + ScriptRunner runner = new ScriptRunner(scriptSQL, conn); + runner.run(); + } + + + /** + * @return Returns the learningLibraries. + */ + public ArrayList getLearningLibraries() { + return learningLibraries; + } + /** + * @param learningLibraries The learningLibraries to set. + */ + public void setLearningLibraries(ArrayList learningLibraries) { + this.learningLibraries = learningLibraries; + } +} Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/ToolActivity.java =================================================================== diff -u --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/ToolActivity.java (revision 0) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/libraryActivity/ToolActivity.java (revision 7bcd6f90150d5c8f5eefaa00e989603de9f6ed19) @@ -0,0 +1,72 @@ +/* +Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +http://www.gnu.org/licenses/gpl.txt +*/ + +/* + * Created on 17/11/2005 + */ +package org.lamsfoundation.lams.tool.deploy.libraryActivity; + +/** + * @author mtruong + * + */ +public class ToolActivity { + + private String toolSignature; + private String toolActivityInsertScriptPath; + + + public ToolActivity() + {} + + public ToolActivity(String toolSignature, String toolActivityInsertScriptPath) + { + this.toolSignature = toolSignature; + this.toolActivityInsertScriptPath = toolActivityInsertScriptPath; + } + + /** + * @return Returns the toolActivityInsertScriptPath. + */ + public String getToolActivityInsertScriptPath() { + return toolActivityInsertScriptPath; + } + /** + * @param toolActivityInsertScriptPath The toolActivityInsertScriptPath to set. + */ + public void setToolActivityInsertScriptPath( + String toolActivityInsertScriptPath) { + this.toolActivityInsertScriptPath = toolActivityInsertScriptPath; + } + + /** + * @return Returns the toolSignature. + */ + public String getToolSignature() { + return toolSignature; + } + /** + * @param toolSignature The toolSignature to set. + */ + public void setToolSignature(String toolSignature) { + this.toolSignature = toolSignature; + } +}