Index: lams_build/deploy-tool/lib/lams-tool-deploy.jar =================================================================== diff -u -r6bfe987420fb2770e06815edcd57c0f95c51c90b -r1e0112c787e72a7240ef2aea57fabd73babda639 Binary files differ Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/Deploy.java =================================================================== diff -u -r08950e1090443c3423a3d1c587416a2fccd8bbdf -r1e0112c787e72a7240ef2aea57fabd73babda639 --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/Deploy.java (.../Deploy.java) (revision 08950e1090443c3423a3d1c587416a2fccd8bbdf) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/Deploy.java (.../Deploy.java) (revision 1e0112c787e72a7240ef2aea57fabd73babda639) @@ -71,6 +71,48 @@ System.out.println("Reading Configuration File"+args[0]); DeployToolConfig config = new DeployToolConfig(args[0]); + String toolSignature = config.getToolSignature(); + String toolVersionStr = config.getToolVersion(); + + /** + * Checking if the tool is installed, if not continue to install the new tool + * If it is, check if the tool to be installed is newer than the current + * If it is newer, update the db, jar and war files, otherwise + * put up a message that the tool is already up to date and do nothing + */ + ToolDBUpdater dbUpdater = new ToolDBUpdater(); + dbUpdater.setDbUsername(config.getDbUsername()); + dbUpdater.setDbPassword(config.getDbPassword()); + dbUpdater.setDbDriverClass(config.getDbDriverClass()); + dbUpdater.setDbDriverUrl(config.getDbDriverUrl()); + dbUpdater.setToolSignature(config.getToolSignature()); + dbUpdater.setToolVersion(config.getToolVersion()); + dbUpdater.checkInstalledVersion(); + if (dbUpdater.getToolExists()) + { + if (dbUpdater.getToolNewer()) + { + System.out.println("Updating tool: " +toolSignature+ " with version " +toolVersionStr); + // TODO copy the .jar and .war from build/deploy + // TODO update scripts + dbUpdater.execute(); + System.exit(0); + } + else + { + System.out.println("The tool to be installed: " +toolSignature+ " " +toolVersionStr+ " is already up to date."); + System.exit(0); + } + } + else + { + System.out.println("The tool to be installed: " +toolSignature+ " does not exist in database"); + System.out.println("Continuing with full install"); + // Do nothing, continue with full install + } + + + Boolean forceDB = Boolean.FALSE; if ( args.length == 2 && args[1] != null) { forceDB = new Boolean(args[1]); Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployConfig.java =================================================================== diff -u -r3a8216a0f97d66b941870386f80f9288f2a4c4dc -r1e0112c787e72a7240ef2aea57fabd73babda639 --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployConfig.java (.../DeployConfig.java) (revision 3a8216a0f97d66b941870386f80f9288f2a4c4dc) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployConfig.java (.../DeployConfig.java) (revision 1e0112c787e72a7240ef2aea57fabd73babda639) @@ -73,7 +73,12 @@ protected transient String validationError = ""; protected transient XStream xstream; + /** + * Holds value of property toolVersion. + */ + protected String toolVersion; + /** * Holds value of property dbDriverClass. */ @@ -129,6 +134,8 @@ public abstract void validateProperties() throws DeployException; + + /** * Validates the value of a property. If the property does not exist, or * the property doesn't have a value, it will return false. @@ -327,6 +334,15 @@ public void setLamsEarPath(String lamsEarPath) { this.lamsEarPath = lamsEarPath; } + + /** + * @return Returns the toolVersion. + */ + public String getToolVersion() + { + return toolVersion; + } + /** Used for testing purposes only */ public void printObjectProperties() Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployToolConfig.java =================================================================== diff -u -r3a8216a0f97d66b941870386f80f9288f2a4c4dc -r1e0112c787e72a7240ef2aea57fabd73babda639 --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployToolConfig.java (.../DeployToolConfig.java) (revision 3a8216a0f97d66b941870386f80f9288f2a4c4dc) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/DeployToolConfig.java (.../DeployToolConfig.java) (revision 1e0112c787e72a7240ef2aea57fabd73babda639) @@ -67,7 +67,7 @@ /** * Holds value of property toolVersion. */ - private String toolVersion; + //private String toolVersion; /** * Holds value of property toolWebUri. @@ -417,9 +417,9 @@ /** * @return Returns the toolVersion. */ - public String getToolVersion() { - return toolVersion; - } + //public String getToolVersion() { + // return toolVersion; + //} /** * @param toolSignature The toolSignature to set. */ @@ -432,6 +432,7 @@ public void setToolVersion(String toolVersion) { this.toolVersion = toolVersion; } + /** * @return Returns the toolTablesDeleteScriptPath. */ Index: lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/ToolDBUpdater.java =================================================================== diff -u -r6014f4098fc4242d6a61d40db676a204eab436b8 -r1e0112c787e72a7240ef2aea57fabd73babda639 --- lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/ToolDBUpdater.java (.../ToolDBUpdater.java) (revision 6014f4098fc4242d6a61d40db676a204eab436b8) +++ lams_tool_deploy/src/java/org/lamsfoundation/lams/tool/deploy/ToolDBUpdater.java (.../ToolDBUpdater.java) (revision 1e0112c787e72a7240ef2aea57fabd73babda639) @@ -25,8 +25,11 @@ import java.sql.Connection; import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; +import org.apache.commons.dbutils.DbUtils; + /** * Checks if the tool version to be installed exists and is a newer version * Updates the database with the new tool version @@ -46,48 +49,115 @@ // Holds value of property toolVersion private String toolVersion; - // Creates instance of ToolDBUpdater - public ToolDBUpdater () {} + // Holds the value of property toolExists + private boolean toolExists; + // Holds the value of property toolNewer + private boolean toolNewer; + /** - * Updates the lams_tool table and the learning library - */ - public void execute() + * Creates instance of ToolDBUpdater + */ + public ToolDBUpdater () { } /** - * Checks if the tool is installed by checking the db - * @param toolSig The tool signature of the tool to be installed - * @return True if the tool signature is present in the db + * Updates the lams_tool table and the learning library */ - public boolean checkInstalled(String toolSig) + public void execute() { - return false; + } /** - * Checks if the currently installed version is equal or newer than the - * version to be installed - * @param toolVer String of the version to be installed - * @return True if the current version is older than the version to be installed + * Checks the tool is installed in the db, sets property toolExists + * Checks the tool version in the db, sets the property toolNewer */ - public boolean checkVersion(String toolVer) + public void checkInstalledVersion() { - return false; + Connection conn = getConnection(); + PreparedStatement stmt = null; + ResultSet results = null; + try + { + stmt = conn.prepareStatement("SELECT tool_version FROM lams_tool WHERE tool_signature=\""+toolSignature+"\""); + results = stmt.executeQuery(); + System.out.println("SELECT tool_version FROM lams_tool WHERE tool_signature=\""+toolSignature+"\""); + if (results.first()) + { + toolExists = true; + double dbVersion = java.lang.Double.parseDouble(results.getString("tool_version")); + double instVersion = java.lang.Double.parseDouble(toolVersion); + + System.out.println("TEST: dbVersion = " + dbVersion); + System.out.println("TEST: instVersion = " + instVersion); + + if (instVersion > dbVersion) + { + toolNewer = true; + } + else + { + toolNewer = false; + } + } + else + { + toolExists = false; + } + + conn.close(); + } + catch (SQLException sqlex) + { + throw new DeployException("Could not get tool version", sqlex); + } + finally + { + DbUtils.closeQuietly(stmt); + DbUtils.closeQuietly(results); + } } + - // set method for toolId + + + /** + * set method for toolId + * @param toolId The toolId to be set + */ public void setToolId(long toolId) {this.toolId = toolId;} - // set method for learningLibraryId + /** + * set method for learningLibraryId + * @param id The LearningLibrayId to be set + */ public void setLearningLibraryId(long id) {this.learningLibraryId = id;} - // set method for toolSignature + /** + * set method for toolSignature + * @param sig The toolSignature to be set + */ public void setToolSignature(String sig) {this.toolSignature = sig;} - // set method for toolVersion + /** + * set method for toolVersion + * @param ver the toolVersion to be set + */ public void setToolVersion(String ver) {this.toolVersion = ver;} + + /** + * get method for toolExists + * @return True if the tool signature exists in the database + */ + public boolean getToolExists() {return this.toolExists;} + + /** + * get method for toolNewer + * @return True if the tool to be installed is a newer version than the version in the datbase + */ + public boolean getToolNewer() {return this.toolNewer;} }