use of com.tyndalehouse.step.core.models.TrimmedLookupOption in project step by STEPBible.
the class PassageOptionsValidationServiceImpl method getUserOptionsForVersion.
/**
* Given a set of options selected by the user and a verson, retrieves the options that are actually available
*
* @param errors the error messages
* @param options the options given by the user
* @param version the version of interest
* @param extraVersions the secondary versions that affect feature resolution
* @param trimmingExplanations the explanations of why options are being removed
* @return a potentially smaller set of options that are actually possible
*/
private Set<LookupOption> getUserOptionsForVersion(final ResourceBundle errors, final List<LookupOption> options, final String version, final List<String> extraVersions, final List<TrimmedLookupOption> trimmingExplanations) {
final Set<LookupOption> available = this.jswordMetadata.getFeatures(version, extraVersions);
final Set<LookupOption> result = new HashSet<>(options.size());
// do a crazy bubble intersect, but it's tiny so that's fine
for (final LookupOption loOption : options) {
boolean added = false;
for (final LookupOption avOption : available) {
if (loOption.equals(avOption)) {
result.add(loOption);
added = true;
break;
}
}
// option not available in that particular version
if (trimmingExplanations != null && !added) {
trimmingExplanations.add(new TrimmedLookupOption(errors.getString("option_not_supported_by_version"), loOption));
}
}
return result;
}
use of com.tyndalehouse.step.core.models.TrimmedLookupOption in project step by STEPBible.
the class BibleInformationServiceImpl method getPassageText.
/**
* Gets the passage text.
*
* @param version the version
* @param reference the reference
* @param options the options
* @param interlinearVersion the interlinear version
* @param interlinearMode the interlinear mode
* @return the passage text
*/
// TODO: this could be optimized. last call to get options is very similar to 'getLookupOptions'
// as they share some of the same stuff.
@Override
@Timed(name = "passage-lookup", group = "service", rateUnit = TimeUnit.SECONDS, durationUnit = TimeUnit.MILLISECONDS)
public OsisWrapper getPassageText(final String version, final String reference, final String options, final String interlinearVersion, final String interlinearMode, final String userLanguage) {
final List<String> extraVersions = getExtraVersionsFromString(interlinearVersion);
final InterlinearMode desiredModeOfDisplay = this.optionsValidationService.getDisplayMode(interlinearMode, version, extraVersions);
OsisWrapper passageText;
final List<TrimmedLookupOption> removedOptions = new ArrayList<TrimmedLookupOption>(4);
final List<LookupOption> inputLookupOptions = this.optionsValidationService.getLookupOptions(options);
final InterlinearMode realModeOfDisplay = this.optionsValidationService.determineDisplayMode(inputLookupOptions, desiredModeOfDisplay, true);
final Set<LookupOption> lookupOptions = this.optionsValidationService.trim(inputLookupOptions, version, extraVersions, desiredModeOfDisplay, realModeOfDisplay, removedOptions);
if (INTERLINEAR != desiredModeOfDisplay && NONE != desiredModeOfDisplay) {
// split the versions
lookupOptions.add(LookupOption.VERSE_NUMBERS);
final String[] versions = getInterleavedVersions(version, interlinearVersion);
passageText = this.jswordPassage.getInterleavedVersions(versions, reference, new ArrayList<>(lookupOptions), desiredModeOfDisplay, userLanguage);
} else {
passageText = this.jswordPassage.getOsisText(version, reference, new ArrayList(lookupOptions), interlinearVersion, desiredModeOfDisplay);
}
passageText.setRemovedOptions(removedOptions);
passageText.setPreviousChapter(this.jswordPassage.getSiblingChapter(passageText.getOsisId(), version, true));
passageText.setNextChapter(this.jswordPassage.getSiblingChapter(passageText.getOsisId(), version, false));
passageText.setOptions(this.optionsValidationService.optionsToString(this.optionsValidationService.getAvailableFeaturesForVersion(version, extraVersions, interlinearMode, realModeOfDisplay).getOptions()));
// the passage lookup wasn't made with the removed options, however, the client needs to think these were selected.
passageText.setSelectedOptions(this.optionsValidationService.optionsToString(lookupOptions) + getRemovedOptions(removedOptions));
return passageText;
}
use of com.tyndalehouse.step.core.models.TrimmedLookupOption in project step by STEPBible.
the class PassageOptionsValidationServiceImpl method trim.
@Override
public Set<LookupOption> trim(final List<LookupOption> options, final String version, List<String> extraVersions, final InterlinearMode mode, final InterlinearMode displayMode, final List<TrimmedLookupOption> trimmingExplanations) {
// obtain error messages
final ResourceBundle errors = ResourceBundle.getBundle("ErrorBundle", this.clientSessionProvider.get().getLocale());
if (options.isEmpty()) {
return new HashSet<>();
}
final Set<LookupOption> result = getUserOptionsForVersion(errors, options, version, extraVersions, trimmingExplanations);
// now trim further depending on modes required:
switch(displayMode) {
case COLUMN:
case COLUMN_COMPARE:
case INTERLEAVED:
case INTERLEAVED_COMPARE:
removeInterleavingOptions(errors, trimmingExplanations, result, !mode.equals(displayMode));
break;
case INTERLINEAR:
explainRemove(errors, NOTES, result, trimmingExplanations, !mode.equals(displayMode), errors.getString("option_not_available_interlinear"));
result.add(LookupOption.VERSE_NEW_LINE);
break;
case NONE:
break;
default:
break;
}
return result;
}
use of com.tyndalehouse.step.core.models.TrimmedLookupOption in project step by STEPBible.
the class PassageOptionsValidationServiceImpl method explainRemove.
/**
* explains why an option has been removed.
*
* @param errors the errors
* @param option the option we want to remove
* @param result the resulting options
* @param trimmingOptions the list of options
* @param originalModeChanged tru if the original mode has changed
* @param explanation the explanation
*/
private void explainRemove(final ResourceBundle errors, final LookupOption option, final Set<LookupOption> result, final List<TrimmedLookupOption> trimmingOptions, final boolean originalModeChanged, final String explanation) {
if (result.remove(option) && trimmingOptions != null) {
final TrimmedLookupOption trimmedOption;
if (originalModeChanged) {
final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(explanation);
stringBuilder.append(" ");
stringBuilder.append(errors.getString("option_not_available_other"));
trimmedOption = new TrimmedLookupOption(stringBuilder.toString(), option);
} else {
trimmedOption = new TrimmedLookupOption(explanation, option);
}
trimmingOptions.add(trimmedOption);
}
}
Aggregations