use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class UserServiceImpl method createUser.
/**
* @param email the email address of the user
* @param name the name of the user
*/
private synchronized void createUser(final String email, final String name) {
ensureFileIsOpenForWrite();
try {
this.userWriter.write(email);
this.userWriter.write(',');
this.userWriter.write(name);
this.userWriter.write(',');
this.userWriter.write(new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss", Locale.ENGLISH).format(new Date()));
this.userWriter.write('\n');
this.userWriter.flush();
this.users.add(email);
} catch (final IOException e) {
IOUtils.closeQuietly(this.userWriter);
throw new StepInternalException("Unable to write user", e);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class JSwordMetadataServiceImpl method getFirstChapterReference.
@Override
public String getFirstChapterReference(final String version) {
final Book bookFromVersion = versificationService.getBookFromVersion(version);
if (bookFromVersion instanceof AbstractPassageBook) {
final Iterator<BibleBook> bookIterator = ((AbstractPassageBook) bookFromVersion).getBibleBooks().iterator();
BibleBook bibleBook = bookIterator.next();
if (BibleBook.INTRO_BIBLE.equals(bibleBook) || BibleBook.INTRO_OT.equals(bibleBook) || BibleBook.INTRO_NT.equals(bibleBook)) {
bibleBook = bookIterator.next();
if (BibleBook.INTRO_OT.equals(bibleBook) || BibleBook.INTRO_NT.equals(bibleBook)) {
bibleBook = bookIterator.next();
}
}
return String.format("%s.%d", bibleBook.getOSIS(), 1);
}
throw new StepInternalException("Unable to ascertain first chapter of book.");
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class JSwordAnalysisServiceImpl method getTextStats.
@Override
public PassageStat getTextStats(final String version, final Key reference, final ScopeType scopeType) {
try {
final Book book = this.versification.getBookFromVersion(version);
final Versification av11n = this.versification.getVersificationForVersion(book);
final BookData bookData = getExpandedBookData(reference, scopeType, av11n, book);
final String canonicalText = OSISUtil.getCanonicalText(bookData.getOsisFragment());
final String[] words = split(canonicalText, WORD_SPLIT);
Set<String> languageStopWords = getLanguageStopList(book);
final PassageStat stat = new PassageStat();
for (final String word : words) {
// only add word if not in STOP list
if (!languageStopWords.contains(StringConversionUtils.unAccent(word.toUpperCase(), true))) {
stat.addWord(word);
}
}
return stat;
} catch (final BookException e) {
throw new StepInternalException("Unable to read passage text", e);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class AnalysisServiceImpl method getStatsForPassage.
@Override
public CombinedPassageStats getStatsForPassage(final String version, final String reference, final StatType statType, final ScopeType scopeType, boolean nextChapter, final String userLanguage, final boolean mostOccurrences) {
final String keyResolutionVersion = statType == StatType.TEXT ? version : JSwordPassageService.REFERENCE_BOOK;
final KeyWrapper centralReference = nextChapter ? jSwordPassageService.getSiblingChapter(reference, keyResolutionVersion, false) : jSwordPassageService.getKeyInfo(reference, keyResolutionVersion, keyResolutionVersion);
final CombinedPassageStats statsForPassage = new CombinedPassageStats();
PassageStat stat = null;
String curBookName = "";
switch(statType) {
case WORD:
if (scopeType == ScopeType.BOOK) {
curBookName = getBookName(centralReference.getKey().getOsisID());
if (!curBookName.equals("")) {
CombinedPassageStats cachedStatsForPassage = getPutBookAnalysisCache(curBookName, mostOccurrences, null);
if (cachedStatsForPassage != null) {
if ((!userLanguage.toLowerCase().startsWith("es")) && (!userLanguage.toLowerCase().startsWith("zh")))
return cachedStatsForPassage;
stat = cachedStatsForPassage.getPassageStat();
}
}
}
if (stat == null) {
stat = this.jswordAnalysis.getWordStats(centralReference.getKey(), scopeType, userLanguage);
stat.trim(maxWords, mostOccurrences);
}
statsForPassage.setLexiconWords(convertWordStatsToDefinitions(stat, userLanguage));
stat = this.bibleInformation.getArrayOfStrongNumbers(version, reference, stat, userLanguage);
break;
case TEXT:
stat = this.jswordAnalysis.getTextStats(version, centralReference.getKey(), scopeType);
stat.trim(maxWords, mostOccurrences);
break;
case SUBJECT:
stat = getSubjectStats(version, centralReference.getName(), scopeType);
stat.trim(maxWords, mostOccurrences);
break;
default:
throw new StepInternalException("Unsupported type of stat asked for.");
}
stat.setReference(centralReference);
statsForPassage.setPassageStat(stat);
if ((scopeType == ScopeType.BOOK) && (!curBookName.equals("")) && (!userLanguage.toLowerCase().startsWith("es")) && (!userLanguage.toLowerCase().startsWith("zh")))
getPutBookAnalysisCache(curBookName, mostOccurrences, statsForPassage);
return statsForPassage;
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class JSwordRelatedVersesServiceImpl method getRelatedVerses.
@Override
public Key getRelatedVerses(final String version, final String key) {
try {
// target book, and intermediary strong book
final Book targetBook = jSwordVersificationService.getBookFromVersion(version);
final Book strongBook = jSwordMetadataService.supportsStrongs(targetBook) ? targetBook : jSwordVersificationService.getBookFromVersion(JSwordPassageService.REFERENCE_BOOK);
// target and strong key
final Key targetKey = targetBook.getKey(key);
final Key strongKey = VersificationsMapper.instance().map(KeyUtil.getPassage(targetKey), jSwordVersificationService.getVersificationForVersion(strongBook));
// get list of strong numbers
final String[] strongs = this.getStrongsFromKey(new BookData(strongBook, strongKey));
final IndexSearcher is = jSwordSearchService.getIndexSearcher(strongBook.getInitials());
final List<String> filteredStrongs = keepInfrequentStrongs(strongs, is);
return targetBook.getKey(getRelatedVerseReference(filteredStrongs, is));
} catch (final NoSuchKeyException ex) {
throw new StepInternalException(ex.getMessage(), ex);
}
}
Aggregations