/** Loads the terms from the vocabulary when needed. */ private synchronized void loadTerms() { if (this.terms == null) { this.terms = this.vocabulary.getTerms(this.identifiers); } } }
/** * Builds a {@link JSONArray} with the data retrieved for the provided {@code termIds}. * * @param vocabulary the {@link Vocabulary} from which term data will be queried * @param termIds a {@link List} of term identifiers of interest * @return a {@link JSONArray} with data for {@code termIds} */ @Nonnull private JSONArray createRows(@Nonnull final Vocabulary vocabulary, @Nonnull final List<Object> termIds) { final JSONArray termsJson = new JSONArray(); // Try to retrieve the vocabulary terms vocabulary.getTerms((List<String>) (List<?>) termIds).stream() // Get the JSONObject representation of each term .map(this::getTermJsonWithLinks) // Insert the term into the JSONArray .forEach(termsJson::put); return termsJson; }
/** * Given the {@code vocabularyPrefix}, tries to retrieve data for provided {@code termIds}. * * @param vocabPrefix a vocabulary prefix (e.g. HP) * @param termIds a {@link Set} of term identifiers, as strings * @return a {@link Stream} of {@link JSONObject} for each specified term ID */ @Nullable private Stream<JSONObject> getTerms(@Nonnull final String vocabPrefix, @Nonnull final Set<String> termIds) { // Try to get the vocabulary by prefix. final Vocabulary vocabulary = this.vm.getVocabulary(vocabPrefix); if (vocabulary == null) { // If no matching vocabulary can be found, log a warning. this.slf4Jlogger.warn("Could not resolve terms [{}]. No matching vocabulary found.", termIds); return null; } // Return a stream of JSONObject for the retrieved terms return vocabulary.getTerms(termIds).stream().map(this::getTermJsonWithLinks); }