Search in sources :

Example 1 with TranslatedException

use of com.tyndalehouse.step.core.exceptions.TranslatedException in project step by STEPBible.

the class AbstractAjaxController method getExceptionMessageAndLog.

/**
 * Gets the exception message.
 *
 * @param e the e
 * @return the exception message
 */
private String getExceptionMessageAndLog(final Throwable e) {
    LOGGER.trace("Tracing exception: ", e);
    final Locale locale = this.clientSessionProvider.get().getLocale();
    final ResourceBundle bundle = ResourceBundle.getBundle("ErrorBundle", locale);
    if (!(e instanceof StepInternalException)) {
        return returnInternalError(e, bundle);
    }
    // else we're looking at a STEP caught exception
    if (e instanceof LocalisedException) {
        return e.getMessage();
    }
    if (e instanceof TranslatedException) {
        final TranslatedException translatedException = (TranslatedException) e;
        LOGGER.warn(e.getMessage());
        LOGGER.debug(e.getMessage(), e);
        return format(bundle.getString(translatedException.getMessage()), translatedException.getArgs());
    }
    if (e instanceof ValidationException) {
        final ValidationException validationException = (ValidationException) e;
        switch(validationException.getExceptionType()) {
            case LOGIN_REQUIRED:
                return bundle.getString("error_login");
            case USER_MISSING_FIELD:
                return bundle.getString("error_missing_field");
            case USER_VALIDATION_ERROR:
                return bundle.getString("error_validation");
            case APP_MISSING_FIELD:
            case CONTROLLER_INITIALISATION_ERROR:
            case SERVICE_VALIDATION_ERROR:
            default:
                return returnInternalError(e, bundle);
        }
    }
    return returnInternalError(e, bundle);
}
Also used : Locale(java.util.Locale) LocalisedException(com.tyndalehouse.step.core.exceptions.LocalisedException) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) ValidationException(com.tyndalehouse.step.core.exceptions.ValidationException) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) ResourceBundle(java.util.ResourceBundle)

Example 2 with TranslatedException

use of com.tyndalehouse.step.core.exceptions.TranslatedException in project step by STEPBible.

the class JSwordModuleServiceImpl method installFromInstallers.

private void installFromInstallers(final String initials, List<Installer> installers) {
    LOGGER.debug("Installing module [{}]", initials);
    notBlank(initials, "No version was found", SERVICE_VALIDATION_ERROR);
    // check if already installed?
    if (!isInstalled(initials)) {
        LOGGER.debug("Book was not already installed, so kicking off installation process for [{}]", initials);
        for (final Installer i : installers) {
            // long initials
            String longInitials = this.versionResolver.getLongName(initials);
            final Book bookToBeInstalled = i.getBook(longInitials);
            if (bookToBeInstalled != null) {
                // then we can kick off installation and return
                try {
                    i.install(bookToBeInstalled);
                    return;
                } catch (final InstallException e) {
                    // we log error here,
                    LOGGER.error("An error occurred error, and we unable to use this installer for module" + initials, e);
                    // but go round the loop to see if more options are available
                    continue;
                }
            }
        }
        // if we get here, then we were unable to install the book
        // since we couldn't find it.
        LOGGER.error("Unable to install: [{}]", initials);
        throw new TranslatedException("book_not_found", initials);
    }
    // if we get here then we had already installed the book - how come we're asking for this again?
    LOGGER.warn("A request to install an already installed book was made for initials " + initials);
}
Also used : DirectoryListingInstaller(com.tyndalehouse.step.core.data.DirectoryListingInstaller) Installer(org.crosswire.jsword.book.install.Installer) BibleInstaller(com.tyndalehouse.step.core.models.BibleInstaller) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) Book(org.crosswire.jsword.book.Book) InstallException(org.crosswire.jsword.book.install.InstallException)

Example 3 with TranslatedException

use of com.tyndalehouse.step.core.exceptions.TranslatedException in project step by STEPBible.

the class JSwordPassageServiceImpl method getSiblingChapter.

@Override
public KeyWrapper getSiblingChapter(final String reference, final String version, final boolean previousChapter) {
    // getting the next chapter
    // FIXME find a way of getting the next chapter from the current key, in the current book, rather than
    // relying on versification systems which may contain verses that the Book does not support
    final Book currentBook = this.versificationService.getBookFromVersion(version);
    final Versification v11n = this.versificationService.getVersificationForVersion(currentBook);
    try {
        final Key key = currentBook.getKey(reference);
        return getSiblingChapter(previousChapter, currentBook, v11n, key);
    } catch (final NoSuchKeyException e) {
        throw new TranslatedException(e, "invalid_reference_in_book", reference, version);
    }
}
Also used : NoSuchKeyException(org.crosswire.jsword.passage.NoSuchKeyException) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) Versification(org.crosswire.jsword.versification.Versification) Key(org.crosswire.jsword.passage.Key)

Example 4 with TranslatedException

use of com.tyndalehouse.step.core.exceptions.TranslatedException in project step by STEPBible.

the class JSwordPassageServiceImpl method getTextForBookData.

/**
 * Gets the osis text
 *
 * @param options            the list of lookup options
 * @param interlinearVersion the interlinear version if applicable
 * @param bookData           the bookdata to use to look up the required version/reference combo
 * @param displayMode        the mode to display the text with
 * @return the html text
 */
private OsisWrapper getTextForBookData(final List<LookupOption> options, final String interlinearVersion, final BookData bookData, final InterlinearMode displayMode) {
    // check we have a book in mind and a reference
    notNull(bookData, "An internal error occurred", UserExceptionType.SERVICE_VALIDATION_ERROR);
    notNull(bookData.getFirstBook(), "An internal error occurred", UserExceptionType.SERVICE_VALIDATION_ERROR);
    Key key = bookData.getKey();
    notNull(key, "An internal error occurred", UserExceptionType.SERVICE_VALIDATION_ERROR);
    // the original book
    final Book book = bookData.getFirstBook();
    final Versification versification = this.versificationService.getVersificationForVersion(book);
    try {
        // first check whether the key is contained in the book
        key = normalize(key, versification);
        final SAXEventProvider osissep = bookData.getSAXEventProvider();
        final TransformingSAXEventProvider htmlsep = executeStyleSheet(versification, options, interlinearVersion, bookData, osissep, displayMode, "en");
        final OsisWrapper osisWrapper = new OsisWrapper(writeToString(htmlsep), key, getLanguages(book, displayMode, htmlsep, options), versification, resolver.getShortName(bookData.getFirstBook().getInitials()), displayMode, interlinearVersion);
        if (key instanceof Passage) {
            final Passage p = (Passage) key;
            final boolean hasMultipleRanges = p.hasRanges(RestrictionType.NONE);
            osisWrapper.setMultipleRanges(hasMultipleRanges);
            if (hasMultipleRanges) {
                // get the first "range" and set up the start and ends
                final VerseRange r = p.rangeIterator(RestrictionType.NONE).next();
                osisWrapper.setStartRange(versification.getOrdinal(r.getStart()));
                osisWrapper.setEndRange(versification.getOrdinal(r.getEnd()));
            } else {
                Iterator<Key> keys = p.iterator();
                Verse start = null;
                Verse end = null;
                while (keys.hasNext()) {
                    if (start == null) {
                        start = (Verse) keys.next();
                    } else {
                        end = (Verse) keys.next();
                    }
                }
                if (start != null) {
                    osisWrapper.setStartRange(start.getOrdinal());
                }
                if (end != null) {
                    osisWrapper.setEndRange(end.getOrdinal());
                } else if (start != null) {
                    osisWrapper.setEndRange(start.getOrdinal());
                }
            }
        } else if (key instanceof VerseRange) {
            final VerseRange vr = (VerseRange) key;
            osisWrapper.setStartRange(versification.getOrdinal(vr.getStart()));
            osisWrapper.setEndRange(versification.getOrdinal(vr.getEnd()));
            osisWrapper.setMultipleRanges(false);
        }
        return osisWrapper;
    } catch (final BookException e) {
        throw new LocalisedException(e, e.getMessage());
    } catch (final SAXException e) {
        throw new StepInternalException(e.getMessage(), e);
    } catch (final TransformerException e) {
        throw new StepInternalException(e.getMessage(), e);
    } catch (final NoSuchKeyException e) {
        throw new TranslatedException(e, "invalid_reference_in_book", bookData.getKey().getName(), book.getInitials());
    }
}
Also used : VerseRange(org.crosswire.jsword.passage.VerseRange) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) Versification(org.crosswire.jsword.versification.Versification) BookException(org.crosswire.jsword.book.BookException) RocketPassage(org.crosswire.jsword.passage.RocketPassage) Passage(org.crosswire.jsword.passage.Passage) SAXException(org.xml.sax.SAXException) LocalisedException(com.tyndalehouse.step.core.exceptions.LocalisedException) TransformingSAXEventProvider(org.crosswire.common.xml.TransformingSAXEventProvider) NoSuchKeyException(org.crosswire.jsword.passage.NoSuchKeyException) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) TransformingSAXEventProvider(org.crosswire.common.xml.TransformingSAXEventProvider) JDOMSAXEventProvider(org.crosswire.common.xml.JDOMSAXEventProvider) SAXEventProvider(org.crosswire.common.xml.SAXEventProvider) Key(org.crosswire.jsword.passage.Key) OsisWrapper(com.tyndalehouse.step.core.models.OsisWrapper) Verse(org.crosswire.jsword.passage.Verse) TransformerException(javax.xml.transform.TransformerException)

Example 5 with TranslatedException

use of com.tyndalehouse.step.core.exceptions.TranslatedException in project step by STEPBible.

the class AbstractSubjectSearchServiceImpl method getLuceneInputReferenceRestriction.

/**
 * This is part 1 of 2 that gives us a retriction on a book reference, as input by the user.
 * @param version the master version
 * @param mainRange the main range input by the user
 * @return the shortest viable prefix
 */
StringAndCount getLuceneInputReferenceRestriction(String version, String mainRange) {
    if (StringUtils.isBlank(mainRange)) {
        return new StringAndCount("", 0);
    }
    // strip out any + and square brackets
    Matcher matcher = IndividualSearch.MAIN_RANGE.matcher(mainRange);
    final boolean hasReference = matcher.find();
    String key;
    if (!hasReference || matcher.groupCount() < 2) {
        // assume un-wrapped reference
        key = mainRange;
    } else {
        key = matcher.group(2);
    }
    final Book master = this.jSwordVersificationService.getBookFromVersion(version);
    final Key k;
    try {
        k = master.getKey(key);
    } catch (NoSuchKeyException e) {
        throw new TranslatedException(e, "invalid_reference_in_book", key, version);
    }
    // now work out what we're looking at
    String keyOsisID = k.getOsisID();
    boolean hasSpaces = keyOsisID.indexOf(' ') != -1;
    int firstDot = keyOsisID.indexOf('.');
    boolean hasDots = firstDot != -1;
    if (!hasSpaces && !hasDots) {
        // no spaces and no ., so has to be a whole book
        return wrapRefForLucene(keyOsisID, true);
    }
    if (hasSpaces) {
        // then we're looking at a list of things, so, let's make one last attempt, in case we're looking at whole books...
        String osisRef = k.getOsisRef();
        if (osisRef.indexOf('.') == -1) {
            // (Gen Lev Mar)
            return getBooksFromRefs(this.jSwordVersificationService.getVersificationForVersion(version), osisRef);
        }
        return prefixWithNaveRefTerm(keyOsisID);
    }
    // so no spaces, but does have dots
    // then we're looking at a single chapter - has to be. Because OSIS IDs for ranges gets expanded.
    // Or at a single verse
    int numDots = StringUtils.countMatches(keyOsisID, ".");
    if (numDots > 1) {
        // then definitely a verse, so return the exact osis id with no *
        return wrapRefForLucene(keyOsisID, false);
    }
    // only 1 dot, so we're either looking at a chapter (Matt.1, or a verse Obad.1)
    // otherwise, either looking at a chapter or a short book
    String bookName = keyOsisID.substring(0, firstDot);
    BibleBook bibleBook = BibleBook.fromExactOSIS(bookName);
    if (bibleBook.isShortBook()) {
        // then we're definitely looking at a verse
        return wrapRefForLucene(keyOsisID, false);
    }
    // long book, so chapter ref
    return wrapRefForLucene(keyOsisID, true);
}
Also used : BibleBook(org.crosswire.jsword.versification.BibleBook) NoSuchKeyException(org.crosswire.jsword.passage.NoSuchKeyException) StringAndCount(com.tyndalehouse.step.core.models.StringAndCount) Matcher(java.util.regex.Matcher) TranslatedException(com.tyndalehouse.step.core.exceptions.TranslatedException) BibleBook(org.crosswire.jsword.versification.BibleBook) Book(org.crosswire.jsword.book.Book) AbstractPassageBook(org.crosswire.jsword.book.basic.AbstractPassageBook) Key(org.crosswire.jsword.passage.Key)

Aggregations

TranslatedException (com.tyndalehouse.step.core.exceptions.TranslatedException)15 Book (org.crosswire.jsword.book.Book)8 Key (org.crosswire.jsword.passage.Key)6 NoSuchKeyException (org.crosswire.jsword.passage.NoSuchKeyException)6 BibleBook (org.crosswire.jsword.versification.BibleBook)5 EntityDoc (com.tyndalehouse.step.core.data.EntityDoc)4 SearchQuery (com.tyndalehouse.step.core.service.impl.SearchQuery)4 ParseException (org.apache.lucene.queryParser.ParseException)4 Query (org.apache.lucene.search.Query)4 LocalisedException (com.tyndalehouse.step.core.exceptions.LocalisedException)3 StringAndCount (com.tyndalehouse.step.core.models.StringAndCount)3 HashSet (java.util.HashSet)3 MultiFieldQueryParser (org.apache.lucene.queryParser.MultiFieldQueryParser)3 Versification (org.crosswire.jsword.versification.Versification)3 StepInternalException (com.tyndalehouse.step.core.exceptions.StepInternalException)2 QueryParser (org.apache.lucene.queryParser.QueryParser)2 BookException (org.crosswire.jsword.book.BookException)2 Passage (org.crosswire.jsword.passage.Passage)2 DirectoryListingInstaller (com.tyndalehouse.step.core.data.DirectoryListingInstaller)1 ValidationException (com.tyndalehouse.step.core.exceptions.ValidationException)1