use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class SubjectSearchServiceImpl method naveDocsToReference.
/**
* Converts a set of nave documents to their reference equivalent
*
* @param extendedDocs
* @return
*/
private Key naveDocsToReference(SearchQuery sq, EntityDoc[] extendedDocs) {
String mainVersion = sq.getCurrentSearch().getVersions()[0];
Book naveVersion = this.jSwordVersificationService.getBookFromVersion(JSwordPassageService.BEST_VERSIFICATION);
Book bookFromVersion = this.jSwordVersificationService.getBookFromVersion(mainVersion);
Key passageKey = null;
for (EntityDoc d : extendedDocs) {
String storedReferences = d.get(NAVE_STORED_REFERENCES);
final Key key;
try {
// NEEDS TO BE KJV
// NEEDS TO BE KJV
// NEEDS TO BE KJV
// NEEDS TO BE KJV
// NEEDS TO BE KJV
// NEEDS TO BE KJV
// NEEDS TO BE KJV
// NEEDS TO BE KJV
key = naveVersion.getKey(storedReferences);
} catch (Exception ex) {
throw new StepInternalException("Stored references are unparseable in nave module: " + storedReferences);
}
if (passageKey == null) {
passageKey = key;
} else {
passageKey.addAll(key);
}
}
return passageKey;
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class SubjectSearchServiceImpl method getKeys.
@Override
public Key getKeys(SearchQuery sq) {
switch(sq.getCurrentSearch().getType()) {
case SUBJECT_SIMPLE:
final String[] originalVersions = sq.getCurrentSearch().getVersions();
prepareSearchForHeadings(sq);
final Key allTopics = this.jswordSearch.searchKeys(sq);
cleanUpSearchFromHeadingsSearch(sq, originalVersions);
return allTopics;
case SUBJECT_EXTENDED:
return naveDocsToReference(sq, this.getNaveDocs(sq));
case SUBJECT_FULL:
return naveDocsToReference(sq, this.getExtendedNaveDocs(sq));
case SUBJECT_RELATED:
return naveDocsToReference(sq, getDocsByExpandedReferences(this.getInputReferenceForNaveSearch(sq.getCurrentSearch().getVersions(), sq.getCurrentSearch().getQuery()).getValue()));
default:
throw new StepInternalException("Unrecognized subject search");
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class JSwordModuleServiceImpl method getProgressOnIndexing.
@Override
public double getProgressOnIndexing(final String bookName) {
notBlank(bookName, "The book name to be indexed was blank", SERVICE_VALIDATION_ERROR);
if (isIndexed(bookName)) {
return 1;
}
// not yet installed (or at least wasn't on the lines above, so check job list
String longVersionName = this.versionResolver.getLongName(bookName);
final Iterator<Progress> iterator = JobManager.iterator();
while (iterator.hasNext()) {
final Progress p = iterator.next();
final String expectedJobName = format(CURRENT_BIBLE_INDEX_JOB, longVersionName);
if (expectedJobName.equals(p.getJobName())) {
if (p.isFinished()) {
return 1;
}
return (double) p.getWork() / p.getTotalWork();
}
}
// the job may have completed by now, while we did the search, so do a final check
if (isIndexed(bookName)) {
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 mergeSearches.
/**
* merges all search results together
*
* @param resultsPerVersion the results per version
* @return the list of results
*/
private Key mergeSearches(final Map<String, Key> resultsPerVersion) {
Key all = null;
Versification allVersification = null;
for (final Entry<String, Key> entry : resultsPerVersion.entrySet()) {
final Key value = entry.getValue();
LOGGER.debug("Sub-result-set [{}] has [{}] entries", entry.getKey(), value.getCardinality());
if (all == null) {
all = value;
if (all instanceof VerseKey) {
allVersification = ((VerseKey) all).getVersification();
}
} else {
boolean valueIsVerseKey = value instanceof VerseKey;
if (valueIsVerseKey && allVersification == null) {
throw new StepInternalException("Trying to combine versified key with non-versified key.");
}
// i.e. and allVersification != null
Key convertedKey = value;
if (valueIsVerseKey) {
final VerseKey versifiedResults = (VerseKey) value;
final Passage versifiedPassageResults = KeyUtil.getPassage(versifiedResults);
convertedKey = VersificationsMapper.instance().map(versifiedPassageResults, allVersification);
}
all.addAll(convertedKey);
}
LOGGER.debug("Combined result-set has [{}] entries", all.getCardinality());
}
return all;
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class TestEntityIndexWriterImpl method close.
@Override
public synchronized int close() {
try {
final IndexWriter ramWriter = getRamWriter();
ramWriter.maybeMerge();
ramWriter.optimize(true);
ramWriter.close();
} catch (final IOException e) {
throw new StepInternalException("Unable to write to ram index", e);
}
return super.getNumEntriesInIndex();
}
Aggregations