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);
}
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");
}
}
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");
}
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();
}
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);
}
Aggregations