[Tynstep-svn] r124 - in trunk: . step-dataloader step-dataloader/src/main/java/com/tyndalehouse/step/dataloader step-dataloader/src/main/java/com/tyndalehouse/step/dataloader/loaders step-dataloader/src/main/resources step-web-app

ChrisBurrell at crosswire.org ChrisBurrell at crosswire.org
Sun Apr 18 14:41:35 MST 2010


Author: ChrisBurrell
Date: 2010-04-18 14:41:35 -0700 (Sun, 18 Apr 2010)
New Revision: 124

Added:
   trunk/step-dataloader/src/main/java/com/tyndalehouse/step/dataloader/loaders/JSwordModuleInstaller.java
   trunk/step-dataloader/src/main/resources/log4j.properties
Modified:
   trunk/pom.xml
   trunk/step-dataloader/pom.xml
   trunk/step-dataloader/src/main/java/com/tyndalehouse/step/dataloader/Dataloader.java
   trunk/step-web-app/pom.xml
Log:
committing dataloader changes

Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml	2010-04-17 14:32:41 UTC (rev 123)
+++ trunk/pom.xml	2010-04-18 21:41:35 UTC (rev 124)
@@ -4,7 +4,7 @@
 	<groupId>com.tyndalehouse</groupId>
 	<artifactId>step-parent</artifactId>
 	<packaging>pom</packaging>
-	<version>1.0-SNAPSHOT</version>
+	<version>0.1-SNAPSHOT</version>
 	<name>step-parent</name>
 	
 	<properties>
@@ -28,8 +28,8 @@
 
 
 	<modules>
+		<module>step-dataloader</module>
 		<module>step-web-app</module>
-		<module>step-dataloader</module>
 		<module>step-server</module>
 		<module>step-tools</module>
 	</modules>
@@ -41,6 +41,11 @@
 				<artifactId>jsword</artifactId>
 				<version>1.6.1-SNAPSHOT</version>
 			</dependency>
+			<dependency>
+				<groupId>org.crosswire</groupId>
+				<artifactId>jsword-common</artifactId>
+				<version>1.6.1-SNAPSHOT</version>
+			</dependency>
 
 			<dependency>
 				<groupId>com.google.gwt</groupId>
@@ -193,6 +198,11 @@
 					<artifactId>maven-eclipse-plugin</artifactId>
 					<version>2.5</version>
 				</plugin>
+				<plugin>
+					<groupId>org.codehaus.mojo</groupId>
+					<artifactId>exec-maven-plugin</artifactId>
+					<version>1.1.1</version>
+				</plugin>
 			</plugins>
 		</pluginManagement>
 	</build>

Modified: trunk/step-dataloader/pom.xml
===================================================================
--- trunk/step-dataloader/pom.xml	2010-04-17 14:32:41 UTC (rev 123)
+++ trunk/step-dataloader/pom.xml	2010-04-18 21:41:35 UTC (rev 124)
@@ -3,7 +3,7 @@
 	<parent>
 		<groupId>com.tyndalehouse</groupId>
 		<artifactId>step-parent</artifactId>
-		<version>1.0-SNAPSHOT</version>
+		<version>0.1-SNAPSHOT</version>
 		<relativePath>..</relativePath>
 	</parent>
 
@@ -18,6 +18,14 @@
 			<plugin>
 				<groupId>org.codehaus.mojo</groupId>
 				<artifactId>exec-maven-plugin</artifactId>
+				<executions>
+					<execution>
+						<phase>install</phase>
+						<goals>
+							<goal>java</goal>
+						</goals>
+					</execution>
+				</executions>
 				<configuration>
 					<mainClass>com.tyndalehouse.step.dataloader.Dataloader</mainClass>
 					<systemProperties>
@@ -25,6 +33,14 @@
 							<key>db.location</key>
 							<value>${db.directory}</value>
 						</systemProperty>
+						<systemProperty>
+							<key>step.http.proxy</key>
+							<value>${step.http.proxy}</value>
+						</systemProperty>
+						<systemProperty>
+							<key>step.http.port</key>
+							<value>${step.http.port}</value>
+						</systemProperty>
 					</systemProperties>
 					<classpathScope>runtime</classpathScope>
 				</configuration>
@@ -33,18 +49,19 @@
 	</build>
 
 	<dependencies>
-
 		<dependency>
 			<groupId>org.crosswire</groupId>
 			<artifactId>jsword</artifactId>
 		</dependency>
-
 		<dependency>
+			<groupId>org.crosswire</groupId>
+			<artifactId>jsword-common</artifactId>
+		</dependency>
+		<dependency>
 			<groupId>commons-dbutils</groupId>
 			<artifactId>commons-dbutils</artifactId>
 			<version>1.3</version>
 		</dependency>
-
 		<dependency>
 			<groupId>commons-io</groupId>
 			<artifactId>commons-io</artifactId>
@@ -56,6 +73,11 @@
 		</dependency>
 
 		<dependency>
+			<groupId>commons-logging</groupId>
+			<artifactId>commons-logging</artifactId>
+		</dependency>
+
+		<dependency>
 			<groupId>net.sf.opencsv</groupId>
 			<artifactId>opencsv</artifactId>
 		</dependency>

Modified: trunk/step-dataloader/src/main/java/com/tyndalehouse/step/dataloader/Dataloader.java
===================================================================
--- trunk/step-dataloader/src/main/java/com/tyndalehouse/step/dataloader/Dataloader.java	2010-04-17 14:32:41 UTC (rev 123)
+++ trunk/step-dataloader/src/main/java/com/tyndalehouse/step/dataloader/Dataloader.java	2010-04-18 21:41:35 UTC (rev 124)
@@ -1,41 +1,55 @@
 package com.tyndalehouse.step.dataloader;
 
+import org.apache.commons.logging.Log;
+import org.apache.log4j.Logger;
+
 import java.io.IOException;
 import java.sql.SQLException;
 import java.util.Calendar;
 
 import org.apache.commons.dbutils.DbUtils;
+import org.crosswire.jsword.book.install.InstallException;
 import org.crosswire.jsword.passage.NoSuchKeyException;
 
 import com.tyndalehouse.step.dataloader.common.DateParsingException;
+import com.tyndalehouse.step.dataloader.loaders.JSwordModuleInstaller;
 import com.tyndalehouse.step.dataloader.loaders.SchemaLoader;
 import com.tyndalehouse.step.dataloader.loaders.TimelineLoader;
 
 public class Dataloader {
-	public static void main(String args[]) throws SQLException, ClassNotFoundException, IOException, DateParsingException, NoSuchKeyException {
-		if(System.getProperty("driver") != null) {
-			DbUtils.loadDriver(System.getProperty("org.apache.derby.jdbc.ClientDriver"));
-		} else {
-			DbUtils.loadDriver("org.apache.derby.jdbc.EmbeddedDriver");	
+	private static Logger log = Logger.getLogger(Dataloader.class);
+
+	public static void main(String args[]) throws SQLException, ClassNotFoundException, IOException, DateParsingException, NoSuchKeyException, InstallException {
+		try {
+			if(System.getProperty("driver") != null) {
+				DbUtils.loadDriver(System.getProperty("org.apache.derby.jdbc.ClientDriver"));
+			} else {
+				DbUtils.loadDriver("org.apache.derby.jdbc.EmbeddedDriver");
+			}
+
+			SchemaLoader sl = new SchemaLoader();
+			TimelineLoader tl = new TimelineLoader();
+			JSwordModuleInstaller jmi = new JSwordModuleInstaller();
+			jmi.installDefaultModules();
+
+//			long startTime= Calendar.getInstance().getTimeInMillis();
+//
+//			sl.recreateAll();
+//			long currentTime = Calendar.getInstance().getTimeInMillis();
+//			System.out.println("Took " + (currentTime-startTime ) + "ms to create schema");
+//			startTime = currentTime;
+//			tl.loadData();
+//
+//			currentTime = Calendar.getInstance().getTimeInMillis();
+//			System.out.println("Took " + (currentTime-startTime ) + "ms to load data");
+//
+//			startTime = currentTime;
+//			currentTime = Calendar.getInstance().getTimeInMillis();
+//			System.out.println("Took " + (currentTime-startTime ) + "ms to install bibles");
+//
+		} catch(Exception ex) {
+			log.error(ex);
 		}
-	
-		SchemaLoader sl = new SchemaLoader();
-		TimelineLoader tl = new TimelineLoader();
-	
-		
-		
-		
-		long startTime= Calendar.getInstance().getTimeInMillis();
-
-		sl.recreateAll();
-		long currentTime = Calendar.getInstance().getTimeInMillis();
-		System.out.println("Took " + (currentTime-startTime ) + "ms to create schema");
-		startTime = currentTime;
-		tl.loadData();
-		
-		currentTime = Calendar.getInstance().getTimeInMillis();
-		System.out.println("Took " + (currentTime-startTime ) + "ms to load data");
-			
 	}
 
 }

Added: trunk/step-dataloader/src/main/java/com/tyndalehouse/step/dataloader/loaders/JSwordModuleInstaller.java
===================================================================
--- trunk/step-dataloader/src/main/java/com/tyndalehouse/step/dataloader/loaders/JSwordModuleInstaller.java	                        (rev 0)
+++ trunk/step-dataloader/src/main/java/com/tyndalehouse/step/dataloader/loaders/JSwordModuleInstaller.java	2010-04-18 21:41:35 UTC (rev 124)
@@ -0,0 +1,93 @@
+package com.tyndalehouse.step.dataloader.loaders;
+
+import org.apache.commons.logging.Log;
+import org.apache.log4j.Logger;
+import org.crosswire.jsword.book.Book;
+import org.crosswire.jsword.book.Books;
+import org.crosswire.jsword.book.install.InstallException;
+import org.crosswire.jsword.book.install.sword.HttpSwordInstaller;
+
+public class JSwordModuleInstaller {
+	private final static String proxyHostProperty = "step.http.proxy";
+	private final static String proxyPortProperty = "step.http.port";
+
+	private Logger log = Logger.getLogger(getClass());
+
+	/** default set of bibles */
+	String[] defaultModules = new String[] { "ESV", "KJV", "ASV",
+			"StrongsHebrew", "StrongsGreek", "LXX", "BYZ" };
+
+	/**
+	 * a default set of modules need to be installed since unit tests rely on
+	 * them to be present TODO: the whole project should probably be cleaned
+	 * up/rewritten in a neater fashion
+	 * 
+	 * @throws InstallException
+	 *             failed to install bible modules
+	 */
+	public void installDefaultModules() {
+		try {
+			log.info("about to create installer");
+			HttpSwordInstaller installer = getInstaller();
+			log.info("got installer, going to reload books");
+			installer.reloadBookList();
+			log.info("reloaded books");
+			for (String s : defaultModules) {
+				installBible(installer, s);
+			}
+		} catch (Exception ex) {
+			log.error(ex.getMessage(), ex);
+		}
+	}
+
+	private void installBible(HttpSwordInstaller installer, String initials)
+			throws InstallException {
+		log.info("installing " + initials);
+
+		Book b = null;
+		try {
+			Books books = Books.installed();
+			if (books != null) {
+				b = books.getBook(initials);
+
+				if (b == null) {
+					installer.install(installer.getBook(initials));
+				} else {
+					log.warn("Skipping " + initials);
+				}
+			}
+		} catch (Exception ex) {
+			log
+					.info(
+							"An exception occurred while reading the list of installed books (first time?)",
+							ex);
+		}
+	}
+
+	private HttpSwordInstaller getInstaller() {
+		log.warn("Creating new installer for JSword");
+		HttpSwordInstaller resourceInstaller = new HttpSwordInstaller();
+		System.out.println("Currently hardcoded installer host to:"
+				+ "www.crosswire.org");
+		System.out.println("Currently hardcoded property names for step");
+		String host = "www.crosswire.org";
+		String proxyHost = System.getProperty(proxyHostProperty);
+		String proxyPort = System.getProperty(proxyPortProperty);
+		System.out.println(String.format("Setting to (%1$s via %2$s:%3$s)",
+				"www.crosswire.org", proxyHost, proxyPort));
+
+		resourceInstaller.setHost(host);
+		if (proxyHost != null && proxyHost.length() != 0) {
+			resourceInstaller.setProxyHost(proxyHost);
+		}
+		if (proxyPort != null && proxyHost.length() != 0) {
+			resourceInstaller.setProxyPort(Integer.parseInt(proxyPort));
+		}
+
+		System.out.println("Setting package and catalog directories");
+		resourceInstaller
+				.setPackageDirectory("/ftpmirror/pub/sword/packages/rawzip");
+		resourceInstaller.setCatalogDirectory("/ftpmirror/pub/sword/raw");
+		return resourceInstaller;
+	}
+}

Added: trunk/step-dataloader/src/main/resources/log4j.properties
===================================================================
--- trunk/step-dataloader/src/main/resources/log4j.properties	                        (rev 0)
+++ trunk/step-dataloader/src/main/resources/log4j.properties	2010-04-18 21:41:35 UTC (rev 124)
@@ -0,0 +1,8 @@
+# Set root logger level to DEBUG and its only appender to A1.
+log4j.rootLogger=INFO, A1
+
+# A1 is set to be a ConsoleAppender.
+# A1 uses PatternLayout.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

Modified: trunk/step-web-app/pom.xml
===================================================================
--- trunk/step-web-app/pom.xml	2010-04-17 14:32:41 UTC (rev 123)
+++ trunk/step-web-app/pom.xml	2010-04-18 21:41:35 UTC (rev 124)
@@ -3,7 +3,7 @@
 	<parent>
 		<groupId>com.tyndalehouse</groupId>
 		<artifactId>step-parent</artifactId>
-		<version>1.0-SNAPSHOT</version>
+		<version>0.1-SNAPSHOT</version>
 		<relativePath>..</relativePath>
 	</parent>
 




More information about the Tynstep-svn mailing list