Search in sources :

Example 1 with TaxonomyTarget

use of org.obiba.mica.spi.search.TaxonomyTarget in project mica2 by obiba.

the class AbstractTaxonomySearchResource method filterTerms.

protected List<String> filterTerms(TaxonomyTarget target, String query, String locale, List<String> vocabularies) {
    try {
        if (vocabularies != null && vocabularies.size() > 0) {
            // filter on vocabulary names; remove taxonomy prefixes ('Mica_study:')
            String vocabulariesQuery = vocabularies.stream().map(v -> String.format("vocabularyName:%s", v.replaceAll("^([^\\:]+):", ""))).collect(Collectors.joining(" AND "));
            query = Strings.isNullOrEmpty(query) ? vocabulariesQuery : query + " " + vocabulariesQuery;
        }
        return esTaxonomyTermService.find(0, MAX_SIZE, DEFAULT_SORT, "asc", null, getTargettedQuery(target, query), getFields(locale, TERM_FIELDS)).getList();
    } catch (Exception e) {
        initTaxonomies();
        // for a 404 response
        throw new NoSuchElementException();
    }
}
Also used : EsTaxonomyTermService(org.obiba.mica.taxonomy.EsTaxonomyTermService) Arrays(java.util.Arrays) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) Dtos(org.obiba.opal.web.taxonomy.Dtos) TaxonomyNotFoundException(org.obiba.mica.micaConfig.service.TaxonomyNotFoundException) Opal(org.obiba.opal.web.model.Opal) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) List(java.util.List) Lists(com.google.common.collect.Lists) LanguageTag(sun.util.locale.LanguageTag) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) Map(java.util.Map) TaxonomyService(org.obiba.mica.micaConfig.service.TaxonomyService) TaxonomyTarget(org.obiba.mica.spi.search.TaxonomyTarget) NoSuchElementException(java.util.NoSuchElementException) EsTaxonomyVocabularyService(org.obiba.mica.taxonomy.EsTaxonomyVocabularyService) TaxonomyNotFoundException(org.obiba.mica.micaConfig.service.TaxonomyNotFoundException) NoSuchElementException(java.util.NoSuchElementException) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with TaxonomyTarget

use of org.obiba.mica.spi.search.TaxonomyTarget in project mica2 by obiba.

the class TaxonomiesSearchResource method filter.

@GET
@Path("/_filter")
@Timed
public List<Opal.TaxonomyDto> filter(@QueryParam("target") @DefaultValue("variable") String target, @QueryParam("query") String query, @QueryParam("locale") String locale) {
    TaxonomyTarget taxonomyTarget = getTaxonomyTarget(target);
    List<String> filteredVocabularies = filterVocabularies(taxonomyTarget, query, locale);
    Map<String, Map<String, List<String>>> taxoNamesMap = TaxonomyResolver.asMap(filteredVocabularies, filterTerms(taxonomyTarget, query, locale, filteredVocabularies));
    List<Opal.TaxonomyDto> results = Lists.newArrayList();
    getTaxonomies(taxonomyTarget).stream().filter(t -> taxoNamesMap.containsKey(t.getName())).forEach(taxo -> {
        Opal.TaxonomyDto.Builder tBuilder = Dtos.asDto(taxo, false).toBuilder();
        populate(tBuilder, taxo, taxoNamesMap);
        results.add(tBuilder.build());
    });
    return results;
}
Also used : Logger(org.slf4j.Logger) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) Dtos(org.obiba.opal.web.taxonomy.Dtos) LoggerFactory(org.slf4j.LoggerFactory) Opal(org.obiba.opal.web.model.Opal) Collectors(java.util.stream.Collectors) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Component(org.springframework.stereotype.Component) QueryParam(javax.ws.rs.QueryParam) Lists(com.google.common.collect.Lists) Map(java.util.Map) TaxonomyResolver(org.obiba.mica.taxonomy.TaxonomyResolver) DefaultValue(javax.ws.rs.DefaultValue) TaxonomyService(org.obiba.mica.micaConfig.service.TaxonomyService) TaxonomyTarget(org.obiba.mica.spi.search.TaxonomyTarget) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) Nullable(javax.annotation.Nullable) TaxonomyTarget(org.obiba.mica.spi.search.TaxonomyTarget) Map(java.util.Map) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 3 with TaxonomyTarget

use of org.obiba.mica.spi.search.TaxonomyTarget 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 4 with TaxonomyTarget

use of org.obiba.mica.spi.search.TaxonomyTarget 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

Map (java.util.Map)4 TaxonomyTarget (org.obiba.mica.spi.search.TaxonomyTarget)4 Timed (com.codahale.metrics.annotation.Timed)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Taxonomy (org.obiba.opal.core.domain.taxonomy.Taxonomy)3 Lists (com.google.common.collect.Lists)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 TaxonomyService (org.obiba.mica.micaConfig.service.TaxonomyService)2 TaxonomyResolver.asMap (org.obiba.mica.taxonomy.TaxonomyResolver.asMap)2 Opal (org.obiba.opal.web.model.Opal)2 Dtos (org.obiba.opal.web.taxonomy.Dtos)2 Strings (com.google.common.base.Strings)1 Arrays (java.util.Arrays)1 NoSuchElementException (java.util.NoSuchElementException)1 Nullable (javax.annotation.Nullable)1 DefaultValue (javax.ws.rs.DefaultValue)1 QueryParam (javax.ws.rs.QueryParam)1