use of org.obiba.opal.core.cfg.NoSuchVocabularyException in project mica2 by obiba.
the class TaxonomySearchResource method filterVocabulary.
@GET
@Path("/vocabulary/{vocabulary}/_filter")
@Timed
public Opal.VocabularyDto filterVocabulary(@PathParam("name") String name, @PathParam("vocabulary") String vocabularyName, @QueryParam("target") @DefaultValue("variable") String target, @QueryParam("query") String query, @QueryParam("locale") String locale) {
TaxonomyTarget taxonomyTarget = getTaxonomyTarget(target);
if (taxonomyTarget.equals(TaxonomyTarget.TAXONOMY))
return Dtos.asDto(getTaxonomy(taxonomyTarget, name).getVocabulary(vocabularyName));
List<String> foundVocabularies = filterVocabularies(taxonomyTarget, String.format("name:%s", vocabularyName), locale);
if (foundVocabularies.isEmpty()) {
throw new NoSuchVocabularyException(name, vocabularyName);
}
Taxonomy taxonomy = getTaxonomy(taxonomyTarget, name);
Vocabulary vocabulary = taxonomy.getVocabulary(vocabularyName);
Opal.VocabularyDto.Builder tBuilder = Dtos.asDto(vocabulary, false).toBuilder();
String filteredQuery = String.format(Strings.isNullOrEmpty(query) ? "taxonomyName:%s AND vocabularyName:%s" : "taxonomyName:%s AND vocabularyName:%s AND (%s)", name, vocabularyName, query);
Map<String, Map<String, List<String>>> taxoNamesMap = asMap(filterTerms(taxonomyTarget, filteredQuery, locale, null));
if (taxoNamesMap.isEmpty() || !taxoNamesMap.containsKey(name) || taxoNamesMap.get(name).isEmpty() || taxoNamesMap.get(name).get(vocabularyName).isEmpty())
return tBuilder.build();
taxoNamesMap.get(name).get(vocabularyName).forEach(term -> tBuilder.addTerms(Dtos.asDto(vocabulary.getTerm(term))));
return tBuilder.build();
}
Aggregations