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