Search in sources :

Example 1 with StepInternalException

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);
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with StepInternalException

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.");
}
Also used : BibleBook(org.crosswire.jsword.versification.BibleBook) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) AbstractPassageBook(org.crosswire.jsword.book.basic.AbstractPassageBook) AbstractPassageBook(org.crosswire.jsword.book.basic.AbstractPassageBook)

Example 3 with StepInternalException

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);
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) PassageStat(com.tyndalehouse.step.core.models.stats.PassageStat) Book(org.crosswire.jsword.book.Book) Versification(org.crosswire.jsword.versification.Versification) BookException(org.crosswire.jsword.book.BookException) BookData(org.crosswire.jsword.book.BookData)

Example 4 with StepInternalException

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;
}
Also used : KeyWrapper(com.tyndalehouse.step.core.models.KeyWrapper) CombinedPassageStats(com.tyndalehouse.step.core.models.stats.CombinedPassageStats) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) PassageStat(com.tyndalehouse.step.core.models.stats.PassageStat)

Example 5 with StepInternalException

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);
    }
}
Also used : IndexSearcher(org.apache.lucene.search.IndexSearcher) NoSuchKeyException(org.crosswire.jsword.passage.NoSuchKeyException) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) Book(org.crosswire.jsword.book.Book) BookData(org.crosswire.jsword.book.BookData) Key(org.crosswire.jsword.passage.Key)

Aggregations

StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)62 IOException (java.io.IOException)25 Book (org.crosswire.jsword.book.Book)9 Key (org.crosswire.jsword.passage.Key)7 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)5 OsisWrapper (com.tyndalehouse.step.core.models.OsisWrapper)4 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 ParseException (org.apache.lucene.queryParser.ParseException)4 BookException (org.crosswire.jsword.book.BookException)4 Versification (org.crosswire.jsword.versification.Versification)4 LocalisedException (com.tyndalehouse.step.core.exceptions.LocalisedException)3 TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)3 KeyWrapper (com.tyndalehouse.step.core.models.KeyWrapper)3 FileInputStream (java.io.FileInputStream)3 TransformingSAXEventProvider (org.crosswire.common.xml.TransformingSAXEventProvider)3 XMLUtil.writeToString (org.crosswire.common.xml.XMLUtil.writeToString)3 NoSuchKeyException (org.crosswire.jsword.passage.NoSuchKeyException)3 BibleBook (org.crosswire.jsword.versification.BibleBook)3 AllResultsCollector (com.tyndalehouse.step.core.data.AllResultsCollector)2