Search in sources :

Example 11 with StepInternalException

use of com.tyndalehouse.step.core.exceptions.StepInternalException 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 12 with StepInternalException

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

the class JSwordModuleServiceImpl method reloadInstallers.

@Override
public void reloadInstallers() {
    boolean errors = false;
    LOGGER.trace("About to reload installers");
    final List<Installer> installers = getInstallers();
    for (final Installer i : installers) {
        try {
            LOGGER.trace("Reloading installer [{}]", i.getInstallerDefinition());
            i.reloadBookList();
        } catch (final InstallException e) {
            errors = true;
            LOGGER.error(e.getMessage(), e);
        }
    }
    if (errors) {
        throw new StepInternalException("Errors occurred while trying to retrieve the latest installer information");
    }
}
Also used : StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) DirectoryListingInstaller(com.tyndalehouse.step.core.data.DirectoryListingInstaller) Installer(org.crosswire.jsword.book.install.Installer) BibleInstaller(com.tyndalehouse.step.core.models.BibleInstaller) InstallException(org.crosswire.jsword.book.install.InstallException)

Example 13 with StepInternalException

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

the class JSwordModuleServiceImpl method getProgressOnInstallation.

@Override
public double getProgressOnInstallation(final String version) {
    notBlank(version, "The book name provided was blank", SERVICE_VALIDATION_ERROR);
    if (isInstalled(version)) {
        return 1;
    }
    // not yet installed (or at least wasn't on the lines above, so check job list
    String longVersionName = this.versionResolver.getLongName(version);
    final Iterator<Progress> iterator = JobManager.iterator();
    while (iterator.hasNext()) {
        final Progress p = iterator.next();
        final String expectedJobName = format(Progress.INSTALL_BOOK, longVersionName);
        if (expectedJobName.equals(p.getJobID())) {
            if (p.isFinished()) {
                return 1;
            }
            return (double) p.getWorkDone() / p.getTotalWork();
        }
    }
    // the job may have completed by now, while we did the search, so do a final check
    if (isInstalled(version)) {
        return 1;
    }
    throw new StepInternalException("An unknown error has occurred: the job has disappeared of the job list, " + "but the module is not installed");
}
Also used : Progress(org.crosswire.common.progress.Progress) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException)

Example 14 with StepInternalException

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

the class JSwordSearchServiceImpl method getIndexSearcher.

/**
 * Retrieves the index from JSword
 * @param bookName the book name
 * @return the index searcher responsible for carrying out operations on JSword data.
 */
public IndexSearcher getIndexSearcher(String bookName) {
    final IndexManager indexManager = IndexManagerFactory.getIndexManager();
    Index index;
    try {
        index = indexManager.getIndex(this.av11nService.getBookFromVersion(bookName));
    } catch (BookException e) {
        throw new StepInternalException(e.getMessage(), e);
    }
    if (!(index instanceof LuceneIndex)) {
        LOGGER.warn("Unsupported Lucene Index type [{}]", index.getClass());
        throw new StepInternalException("Unable to obtain index");
    }
    @SuppressWarnings("resource") final LuceneIndex li = (LuceneIndex) index;
    return (IndexSearcher) li.getSearcher();
}
Also used : IndexManager(org.crosswire.jsword.index.IndexManager) IndexSearcher(org.apache.lucene.search.IndexSearcher) LuceneIndex(org.crosswire.jsword.index.lucene.LuceneIndex) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) Index(org.crosswire.jsword.index.Index) LuceneIndex(org.crosswire.jsword.index.lucene.LuceneIndex) BookException(org.crosswire.jsword.book.BookException)

Example 15 with StepInternalException

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

the class JSwordPassageServiceImpl method executeStyleSheet.

/**
 * Executes the stylesheet
 *
 * @param masterVersification the versification of the top line
 * @param options             the list of options to pass in
 * @param interlinearVersion  the interlinear version(s)
 * @param bookData            the book data, containing book and reference
 * @param osissep             the XML SAX provider
 * @param displayMode         the display mode
 * @return a Transforming SAX event provider, from which can be transformed into HTML
 * @throws TransformerException an exception in the stylesheet that is being executed
 */
private TransformingSAXEventProvider executeStyleSheet(final Versification masterVersification, final List<LookupOption> options, final String interlinearVersion, final BookData bookData, final SAXEventProvider osissep, final InterlinearMode displayMode, final String userLanguage) throws TransformerException {
    final XslConversionType requiredTransformation = identifyStyleSheet(options, displayMode);
    return (TransformingSAXEventProvider) new Converter() {

        @Override
        public SAXEventProvider convert(final SAXEventProvider provider) throws TransformerException {
            try {
                final String file = requiredTransformation.getFile();
                final URI resourceURI = getClass().getResource(file).toURI();
                final TransformingSAXEventProvider tsep = new TransformingSAXEventProvider(resourceURI, osissep);
                // set parameters here
                String changeVersion = "";
                if (userLanguage.toLowerCase().startsWith("es"))
                    changeVersion = "SpaRV1909";
                else if (userLanguage.equalsIgnoreCase("zh"))
                    changeVersion = "CUns";
                else if (userLanguage.equalsIgnoreCase("zh_tw"))
                    changeVersion = "CUn";
                else if (userLanguage.toLowerCase().startsWith("bg"))
                    changeVersion = "BulProtRev";
                else if (userLanguage.toLowerCase().startsWith("hi"))
                    changeVersion = "HinULB";
                if (changeVersion.length() > 0) {
                    tsep.setParameter("defaultVersion", changeVersion);
                }
                setOptions(tsep, options, bookData.getBooks());
                setInterlinearOptions(tsep, bookData.getBooks()[0].getInitials(), masterVersification, getInterlinearVersion(interlinearVersion), bookData.getKey().getOsisID(), displayMode, bookData.getKey(), options);
                setInterleavingOptions(tsep, displayMode, bookData);
                return tsep;
            } catch (final URISyntaxException e) {
                throw new StepInternalException("Failed to load resource correctly", e);
            }
        }
    }.convert(osissep);
}
Also used : TransformingSAXEventProvider(org.crosswire.common.xml.TransformingSAXEventProvider) StepInternalException(com.tyndalehouse.step.core.exceptions.StepInternalException) Converter(org.crosswire.common.xml.Converter) TransformingSAXEventProvider(org.crosswire.common.xml.TransformingSAXEventProvider) JDOMSAXEventProvider(org.crosswire.common.xml.JDOMSAXEventProvider) SAXEventProvider(org.crosswire.common.xml.SAXEventProvider) XMLUtil.writeToString(org.crosswire.common.xml.XMLUtil.writeToString) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) XslConversionType(com.tyndalehouse.step.core.xsl.XslConversionType)

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