use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class JSwordRelatedVersesServiceImpl method getRelatedVerseReference.
/**
* Gets the list of all references as a string to be passed to JSword
*
* @param strongs the list of all strongs
* @param is the index searcher
* @return the related verses
*/
private String getRelatedVerseReference(final List<String> strongs, final IndexSearcher is) {
try {
final BooleanQuery bq = getRelatedLuceneQuery(strongs);
final TopScoreDocCollector collector = TopScoreDocCollector.create(50, true);
is.search(bq, collector);
final TopDocs topDocs = collector.topDocs();
final ScoreDoc[] scoreDocs = topDocs.scoreDocs;
final StringBuilder refs = new StringBuilder(128);
for (final ScoreDoc scoreDoc : scoreDocs) {
final String potentialVerse = is.doc(scoreDoc.doc).get(LuceneIndex.FIELD_KEY);
if (refs.length() > 0) {
refs.append(' ');
}
refs.append(potentialVerse);
}
return refs.toString();
} catch (final IOException ex) {
throw new StepInternalException(ex.getMessage(), ex);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class AnalysisServiceImpl method getReferenceSyntax.
/**
* Creates a lucene query to allow search for multiple chapters/entire books, without generating
* thousands of boolean queries, because we're expanding a book into all its verses!
*
* @param version the version in which look up the key
* @param scopeType the scope type
*/
private String getReferenceSyntax(final String reference, final String version, final ScopeType scopeType) {
final KeyWrapper key = this.jSwordPassageService.getKeyInfo(reference, version, version);
final Key total = key.getKey();
StringBuilder sb = new StringBuilder(32);
switch(scopeType) {
case PASSAGE:
case CHAPTER:
case NEAR_BY_CHAPTER:
// expand all the chapters....
int minChapter = -1;
int maxChapter = -1;
Verse firstVerse = null;
Verse lastVerse;
// need to expand between chapters....
final Iterator<Key> iterator = total.iterator();
Verse v = null;
while (iterator.hasNext()) {
final Key next = iterator.next();
if (next instanceof Verse) {
v = (Verse) next;
if (minChapter == -1) {
minChapter = v.getChapter();
firstVerse = v;
}
int currentChapter = v.getChapter();
if (currentChapter != maxChapter) {
sb.append(v.getBook().getOSIS());
sb.append('.');
sb.append(v.getChapter());
sb.append(".* ");
}
maxChapter = v.getChapter();
}
}
lastVerse = v;
// need to add +1 and -1
if (scopeType == ScopeType.NEAR_BY_CHAPTER) {
sb.append(firstVerse.getBook().getOSIS());
sb.append('.');
sb.append(minChapter - 1);
sb.append(".* ");
sb.append(lastVerse.getBook().getOSIS());
sb.append('.');
sb.append(minChapter - 1);
sb.append(".* ");
}
break;
case BOOK:
Key k = key.getKey().get(0);
if (k instanceof Verse) {
sb.append(((Verse) k).getBook().getOSIS());
sb.append(OSIS_CHAPTER_STARTS_WITH);
}
break;
default:
throw new StepInternalException("Unsupported option.");
}
return sb.toString();
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class MultiMap method putElement.
/**
* Put element.
*
* @param key the key
* @param value the value
*/
@SuppressWarnings("unchecked")
public void putElement(final K key, final V value) {
C collection = get(key);
if (collection == null) {
try {
collection = (C) this.collectionClass.newInstance();
} catch (final InstantiationException e) {
throw new StepInternalException("Unable to create collection of type" + this.collectionClass, e);
} catch (final IllegalAccessException e) {
throw new StepInternalException("Unable to create collection of type" + this.collectionClass, e);
}
put(key, collection);
}
collection.add(value);
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class DirectoryListingInstaller method extraConfFile.
/**
* Extracts a single conf file to read its details
*
* @param zipFile the zip file in question
*/
private void extraConfFile(BookDriver fakeDriver, File zipFile) {
InputStream in = null;
ZipInputStream zin = null;
try {
ConfigEntry.resetStatistics();
in = NetUtil.getInputStream(zipFile.toURI());
zin = new ZipInputStream(in);
while (true) {
ZipEntry entry = zin.getNextEntry();
if (entry == null) {
break;
}
String internal = entry.getName();
if (internal.endsWith(SwordConstants.EXTENSION_CONF)) {
LOGGER.trace("Reading a conf file [{}]", entry.getName());
try {
int size = (int) entry.getSize();
ByteArrayOutputStream os = new ByteArrayOutputStream();
byte[] bytes = new byte[1024];
int read;
while ((read = zin.read(bytes)) > 0) {
os.write(bytes, 0, read);
}
internal = internal.substring(0, internal.length() - 5);
if (internal.startsWith(SwordConstants.DIR_CONF + '/')) {
internal = internal.substring(7);
}
SwordBookMetaData sbmd = new SwordBookMetaData(os.toByteArray(), internal);
sbmd.setDriver(fakeDriver);
Book book = new SwordBook(sbmd, new NullBackend());
entries.put(book.getName(), book);
// assume 1 conf file per zip file
return;
} catch (Exception ex) {
LOGGER.error("Failed to load config for entry: {}", internal, ex);
}
}
}
ConfigEntry.dumpStatistics();
} catch (IOException ex) {
LOGGER.error("Failed to configuration from [{}]", zipFile.getName());
throw new StepInternalException("Error reading directory of zip files.", ex);
} finally {
IOUtil.close(zin);
IOUtil.close(in);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class EntityConfiguration method parseProperties.
/**
* parses the properties related to an entity configuration
*
* @param properties the set of properties
*/
@SuppressWarnings("unchecked")
private void parseProperties(final Properties properties) {
try {
final String analyzerProperty = properties.getProperty("entity.analyzer");
if (isNotBlank(analyzerProperty)) {
// try the default constructor
final Class<Analyzer> analyzerClass = (Class<Analyzer>) Class.forName(analyzerProperty);
try {
this.analyzerInstance = analyzerClass.newInstance();
} catch (final InstantiationException exception) {
this.analyzerInstance = analyzerClass.getConstructor(Version.class).newInstance(Version.LUCENE_30);
}
} else {
this.analyzerInstance = new StandardAnalyzer(LUCENE_30);
}
final String processor = properties.getProperty("entity.postProcessor");
if (isNotBlank(processor)) {
this.postProcessorInstance = (PostProcessor) this.injector.getInstance(Class.forName(processor));
}
} catch (final IllegalAccessException e) {
throw new StepInternalException(UNABLE_TO_PARSE_CONFIGURATION_FILE, e);
} catch (final ClassNotFoundException e) {
throw new StepInternalException(UNABLE_TO_PARSE_CONFIGURATION_FILE, e);
} catch (final InvocationTargetException e) {
throw new StepInternalException(UNABLE_TO_PARSE_CONFIGURATION_FILE, e);
} catch (final InstantiationException e) {
throw new StepInternalException(UNABLE_TO_PARSE_CONFIGURATION_FILE, e);
} catch (final NoSuchMethodException e) {
throw new StepInternalException(UNABLE_TO_PARSE_CONFIGURATION_FILE, e);
}
parseFieldConfigs(properties);
}
Aggregations