[Tynstep-svn] r239 - in trunk/step: step-core/src/main/java/com/tyndalehouse/step/core/service step-core/src/main/java/com/tyndalehouse/step/core/service/impl step-core/src/test/java/com/tyndalehouse/step/core/service/impl step-web/src/main/java/com/tyndalehouse/step/rest/controllers step-web/src/main/webapp/js

ChrisBurrell at crosswire.org ChrisBurrell at crosswire.org
Tue Apr 17 08:46:57 MST 2012


Author: ChrisBurrell
Date: 2012-04-17 08:46:56 -0700 (Tue, 17 Apr 2012)
New Revision: 239

Modified:
   trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/BibleInformationService.java
   trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/JSwordService.java
   trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/impl/BibleInformationServiceImpl.java
   trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/impl/JSwordServiceImpl.java
   trunk/step/step-core/src/test/java/com/tyndalehouse/step/core/service/impl/JSwordServiceImplTest.java
   trunk/step/step-web/src/main/java/com/tyndalehouse/step/rest/controllers/BibleController.java
   trunk/step/step-web/src/main/webapp/js/passage.js
   trunk/step/step-web/src/main/webapp/js/ui_hooks.js
Log:
Committing TYNSTEP-97

Modified: trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/BibleInformationService.java
===================================================================
--- trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/BibleInformationService.java	2012-04-17 13:06:17 UTC (rev 238)
+++ trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/BibleInformationService.java	2012-04-17 15:46:56 UTC (rev 239)
@@ -50,6 +50,16 @@
     List<EnrichedLookupOption> getAllFeatures();
 
     /**
+     * returns a list of matching names or references in a particular book
+     * 
+     * @param bookStart the name of the matching key to look across book names
+     * @param version the name of the version, defaults to KJV if not found
+     * 
+     * @return a list of matching bible book names
+     */
+    List<String> getBibleBookNames(String bookStart, String version);
+
+    /**
      * Checks a set of core versions to see if they have been installed
      * 
      * @return true if the core modules have been installed

Modified: trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/JSwordService.java
===================================================================
--- trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/JSwordService.java	2012-04-17 13:06:17 UTC (rev 238)
+++ trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/JSwordService.java	2012-04-17 15:46:56 UTC (rev 239)
@@ -85,8 +85,17 @@
     /**
      * 
      * @param references a list of references
-     * @param target id of the event
      * @return the list of references strongly-typed
      */
     List<ScriptureReference> getPassageReferences(final String references);
+
+    /**
+     * returns a list of matching names or references in a particular book
+     * 
+     * @param bookStart the name of the matching key to look across book names
+     * @param version the name of the version, defaults to KJV if not found
+     * 
+     * @return a list of matching bible book names
+     */
+    List<String> getBibleBookNames(String bookStart, String version);
 }

Modified: trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/impl/BibleInformationServiceImpl.java
===================================================================
--- trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/impl/BibleInformationServiceImpl.java	2012-04-17 13:06:17 UTC (rev 238)
+++ trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/impl/BibleInformationServiceImpl.java	2012-04-17 15:46:56 UTC (rev 239)
@@ -103,4 +103,10 @@
     public void installModules(final String reference) {
         this.jsword.installBook(reference);
     }
+
+    @Override
+    public List<String> getBibleBookNames(final String bookStart, final String version) {
+        return this.jsword.getBibleBookNames(bookStart, version);
+    }
+
 }

Modified: trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/impl/JSwordServiceImpl.java
===================================================================
--- trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/impl/JSwordServiceImpl.java	2012-04-17 13:06:17 UTC (rev 238)
+++ trunk/step/step-core/src/main/java/com/tyndalehouse/step/core/service/impl/JSwordServiceImpl.java	2012-04-17 15:46:56 UTC (rev 239)
@@ -37,6 +37,9 @@
 import org.crosswire.jsword.passage.RocketPassage;
 import org.crosswire.jsword.passage.Verse;
 import org.crosswire.jsword.passage.VerseRange;
+import org.crosswire.jsword.versification.BibleBook;
+import org.crosswire.jsword.versification.BibleBookList;
+import org.crosswire.jsword.versification.Versification;
 import org.crosswire.jsword.versification.system.Versifications;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -380,4 +383,44 @@
         }
         return refs;
     }
+
+    /**
+     * Looks through a versification for a particular type of book
+     * 
+     * @param bookStart the string to match
+     * @param versification the versification we are interested in
+     * @return the list of matching names
+     */
+    private List<String> getBooksFromVersification(final String bookStart, final Versification versification) {
+        final List<String> matchingNames = new ArrayList<String>();
+        final BibleBookList books = versification.getBooks();
+        for (final BibleBook book : books) {
+            if (book.getLongName().startsWith(bookStart) || book.getPreferredName().startsWith(bookStart)
+                    || book.getShortName().startsWith(bookStart)) {
+                matchingNames.add(book.getLongName());
+            }
+        }
+        return matchingNames;
+    }
+
+    @Override
+    public List<String> getBibleBookNames(final String bookStart, final String version) {
+        if (isBlank(bookStart)) {
+            return new ArrayList<String>();
+        }
+
+        Versification versification = Versifications.instance().getVersification(version);
+        if (versification == null) {
+            versification = Versifications.instance().getDefaultVersification();
+        }
+
+        final List<String> books = getBooksFromVersification(bookStart, versification);
+
+        if (books.isEmpty()) {
+            return getBooksFromVersification(bookStart, Versifications.instance().getDefaultVersification());
+        }
+
+        return books;
+    }
+
 }

Modified: trunk/step/step-core/src/test/java/com/tyndalehouse/step/core/service/impl/JSwordServiceImplTest.java
===================================================================
--- trunk/step/step-core/src/test/java/com/tyndalehouse/step/core/service/impl/JSwordServiceImplTest.java	2012-04-17 13:06:17 UTC (rev 238)
+++ trunk/step/step-core/src/test/java/com/tyndalehouse/step/core/service/impl/JSwordServiceImplTest.java	2012-04-17 15:46:56 UTC (rev 239)
@@ -2,6 +2,7 @@
 
 import static com.tyndalehouse.step.core.models.LookupOption.INTERLINEAR;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.io.IOException;
 import java.io.StringReader;
@@ -157,6 +158,21 @@
     }
 
     /**
+     * Tests that getting a bible book returns the correct set of names
+     */
+    @Test
+    public void testGetBibleBooks() {
+        final JSwordServiceImpl jsi = new JSwordServiceImpl(null);
+
+        final List<String> bibleBookNames = jsi.getBibleBookNames("Ma", "ESV");
+
+        assertTrue(bibleBookNames.contains("Malachi"));
+        assertTrue(bibleBookNames.contains("Matthew"));
+        assertTrue(bibleBookNames.contains("Mark"));
+
+    }
+
+    /**
      * tries to replicate the issue with bookdata not being able to be read in a concurrent fashion
      * 
      * @throws NoSuchKeyException a no such key exception

Modified: trunk/step/step-web/src/main/java/com/tyndalehouse/step/rest/controllers/BibleController.java
===================================================================
--- trunk/step/step-web/src/main/java/com/tyndalehouse/step/rest/controllers/BibleController.java	2012-04-17 13:06:17 UTC (rev 238)
+++ trunk/step/step-web/src/main/java/com/tyndalehouse/step/rest/controllers/BibleController.java	2012-04-17 15:46:56 UTC (rev 239)
@@ -128,4 +128,16 @@
     public List<EnrichedLookupOption> getAllFeatures() {
         return this.bibleInformation.getAllFeatures();
     }
+
+    /**
+     * 
+     * @param bookStart the phrase input so far in a textbox to use for the lookup
+     * @param version the version to lookup upon
+     * @return a list of items
+     */
+    @Cacheable(true)
+    public List<String> getBibleBookNames(final String bookStart, final String version) {
+        return this.bibleInformation.getBibleBookNames(bookStart, version);
+    }
+
 }

Modified: trunk/step/step-web/src/main/webapp/js/passage.js
===================================================================
--- trunk/step/step-web/src/main/webapp/js/passage.js	2012-04-17 13:06:17 UTC (rev 238)
+++ trunk/step/step-web/src/main/webapp/js/passage.js	2012-04-17 15:46:56 UTC (rev 239)
@@ -17,26 +17,11 @@
 	//read state from the cookie
 	this.setInitialPassage();
 	
-	// set up autocomplete
-	this.version.autocomplete({
-		source : versions,
-		minLength: 0,
-		delay: 0,
-		select : function(event, ui) {
-			$(this).val(ui.item.value);
-			$(this).change();
-		},
-	}).focus(function() {
-		self.version.autocomplete("search", "");
-	}).change(function() {
-		$.shout("version-changed-" + self.passageId, this.value);
-	});
+	this.initVersionsTextBox(versions);
+	this.initReferenceTextBox();
 	
-	//set up change for textbox
-	this.reference.change(function(){
-		self.changePassage();
-	});
 	
+	
 	//register to listen for events that click a word/phrase:
 	this.passage.hear("show-all-strong-morphs", function(selfElement, data) {
 		self.higlightStrongs(data);
@@ -67,6 +52,49 @@
 };
 
 /**
+ * Sets up the autocomplete for the versions dropdown
+ */
+Passage.prototype.initVersionsTextBox = function(versions) {
+	var self = this;
+	
+	// set up autocomplete
+	this.version.autocomplete({
+		source : versions,
+		minLength: 0,
+		delay: 0,
+		select : function(event, ui) {
+			$(this).val(ui.item.value);
+			$(this).change();
+		},
+	}).focus(function() {
+		self.version.autocomplete("search", "");
+	}).change(function() {
+		$.shout("version-changed-" + self.passageId, this.value);
+	});
+};
+
+Passage.prototype.initReferenceTextBox = function() {	
+	var self = this;
+	
+	//set up change for textbox
+	this.reference.autocomplete({
+		source : function(request, response) {
+			$.get(BIBLE_GET_BIBLE_BOOK_NAMES + request.term + "/" + self.version.val(), function(text) {
+				response(text);
+			});
+		},
+		minLength: 1,
+		delay: 0,
+		select : function(event, ui) {
+			$(this).val(ui.item.value);
+		}
+	}).change(function(){
+		self.changePassage();
+	});
+};
+
+
+/**
  * sets up the initial passages based on the cookie state
  */
 Passage.prototype.setInitialPassage = function() {

Modified: trunk/step/step-web/src/main/webapp/js/ui_hooks.js
===================================================================
--- trunk/step/step-web/src/main/webapp/js/ui_hooks.js	2012-04-17 13:06:17 UTC (rev 238)
+++ trunk/step/step-web/src/main/webapp/js/ui_hooks.js	2012-04-17 15:46:56 UTC (rev 239)
@@ -20,7 +20,9 @@
 BIBLE_GET_BIBLE_TEXT = STEP_SERVER_BASE_URL + "bible/getBibleText/";
 BIBLE_GET_FEATURES = STEP_SERVER_BASE_URL + "bible/getFeatures/";
 BIBLE_GET_ALL_FEATURES = STEP_SERVER_BASE_URL + "bible/getAllFeatures/";
+BIBLE_GET_BIBLE_BOOK_NAMES = STEP_SERVER_BASE_URL + "bible/getBibleBookNames/"
 
+
 MODULE_GET_ALL_MODULES = STEP_SERVER_BASE_URL + "module/getAllModules/";
 MODULE_GET_ALL_INSTALLABLE_MODULES = STEP_SERVER_BASE_URL + "module/getAllModules/";
 MODULE_GET_DEFINITION = STEP_SERVER_BASE_URL + "module/getDefinition/";




More information about the Tynstep-svn mailing list