Search in sources :

Example 21 with Taxonomy

use of org.obiba.opal.core.domain.taxonomy.Taxonomy 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();
}
Also used : Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) NoSuchVocabularyException(org.obiba.opal.core.cfg.NoSuchVocabularyException) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) TaxonomyTarget(org.obiba.mica.spi.search.TaxonomyTarget) Map(java.util.Map) TaxonomyResolver.asMap(org.obiba.mica.taxonomy.TaxonomyResolver.asMap) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 22 with Taxonomy

use of org.obiba.opal.core.domain.taxonomy.Taxonomy in project mica2 by obiba.

the class TaxonomySearchResource method filterTaxonomy.

@GET
@Path("/_filter")
@Timed
public Opal.TaxonomyDto filterTaxonomy(@PathParam("name") String name, @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));
    List<String> filteredVocabularies = filterVocabularies(taxonomyTarget, query, locale);
    Map<String, Map<String, List<String>>> taxoNamesMap = asMap(filteredVocabularies, filterTerms(taxonomyTarget, query, locale, filteredVocabularies));
    Taxonomy taxonomy = getTaxonomy(taxonomyTarget, name);
    Opal.TaxonomyDto.Builder tBuilder = Dtos.asDto(taxonomy, false).toBuilder();
    if (taxoNamesMap.isEmpty() || !taxoNamesMap.containsKey(name) || taxoNamesMap.get(name).isEmpty())
        return tBuilder.build();
    populate(tBuilder, taxonomy, taxoNamesMap);
    return tBuilder.build();
}
Also used : Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) TaxonomyTarget(org.obiba.mica.spi.search.TaxonomyTarget) Map(java.util.Map) TaxonomyResolver.asMap(org.obiba.mica.taxonomy.TaxonomyResolver.asMap) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

Taxonomy (org.obiba.opal.core.domain.taxonomy.Taxonomy)22 Test (org.junit.Test)10 Vocabulary (org.obiba.opal.core.domain.taxonomy.Vocabulary)6 Map (java.util.Map)4 TaxonomyTarget (org.obiba.mica.spi.search.TaxonomyTarget)3 Timed (com.codahale.metrics.annotation.Timed)2 Strings (com.google.common.base.Strings)2 List (java.util.List)2 Inject (javax.inject.Inject)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 TaxonomyResolver.asMap (org.obiba.mica.taxonomy.TaxonomyResolver.asMap)2 Term (org.obiba.opal.core.domain.taxonomy.Term)2 Opal (org.obiba.opal.web.model.Opal)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 File (java.io.File)1 URI (java.net.URI)1