Search in sources :

Example 11 with Vocabulary

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

the class VocabularyMissingRangeTermsExceptionMapper method getErrorDto.

@Override
protected GeneratedMessage.ExtendableMessage<?> getErrorDto(VocabularyMissingRangeTermsException e) {
    Vocabulary vocabulary = e.getVocabulary();
    ErrorDtos.ClientErrorDto.Builder builder = ErrorDtos.ClientErrorDto.newBuilder().setCode(getStatus().getStatusCode());
    if (vocabulary != null) {
        builder.setMessageTemplate("server.error.taxonomy.range-criterion-missing-terms");
        builder.addArguments(vocabulary.getName());
    }
    return builder.build();
}
Also used : Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary)

Example 12 with Vocabulary

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

the class TaxonomyAggregationMetaDataProvider method getVocabulary.

private Optional<Vocabulary> getVocabulary(String aggregation) {
    String key = aggregation.replaceAll("^attributes-", "").replaceAll("-und$", "");
    AttributeKey attrKey = AttributeKey.from(key);
    String targetTaxonomy = attrKey.hasNamespace(null) ? "Default" : attrKey.getNamespace();
    String targetVocabulary = attrKey.getName();
    return // 
    getTaxonomies().stream().filter(// 
    taxonomy -> !Strings.isNullOrEmpty(targetTaxonomy) && taxonomy.getName().equals(targetTaxonomy)).map(// 
    Taxonomy::getVocabularies).flatMap(// 
    Collection::stream).filter(// 
    vocabulary -> vocabulary.getName().equals(targetVocabulary)).findFirst();
}
Also used : AttributeKey(org.obiba.mica.spi.search.support.AttributeKey) LocalizedString(org.obiba.mica.core.domain.LocalizedString) Collection(java.util.Collection) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) AttributeKey(org.obiba.mica.spi.search.support.AttributeKey) OpalService(org.obiba.mica.micaConfig.service.OpalService) AggregationMetaDataProvider(org.obiba.mica.micaConfig.service.helper.AggregationMetaDataProvider) Maps(com.google.common.collect.Maps) Inject(javax.inject.Inject) Term(org.obiba.opal.core.domain.taxonomy.Term) Strings(com.google.common.base.Strings) List(java.util.List) Component(org.springframework.stereotype.Component) Map(java.util.Map) Optional(java.util.Optional) Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Collections(java.util.Collections) Collection(java.util.Collection) LocalizedString(org.obiba.mica.core.domain.LocalizedString)

Example 13 with Vocabulary

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

the class TaxonomyAggregationMetaDataProvider method getAllLocalizedMetadata.

private Map<String, LocalizedMetaData> getAllLocalizedMetadata(String aggregation) {
    Optional<Vocabulary> vocabulary = getVocabulary(aggregation);
    if (vocabulary.isPresent()) {
        Map<String, LocalizedMetaData> r = Maps.newHashMap();
        for (Term t : vocabulary.get().getTerms()) {
            LocalizedString title = new LocalizedString();
            title.putAll(t.getTitle());
            LocalizedString description = new LocalizedString();
            description.putAll(t.getDescription());
            String className = t.getAttributeValue("className");
            if (Strings.isNullOrEmpty(className)) {
                className = t.getClass().getSimpleName();
            }
            if (!r.containsKey(t.getName())) {
                r.put(t.getName(), new LocalizedMetaData(title, description, className));
            }
        }
        return r;
    }
    return null;
}
Also used : Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) LocalizedString(org.obiba.mica.core.domain.LocalizedString) Term(org.obiba.opal.core.domain.taxonomy.Term) LocalizedString(org.obiba.mica.core.domain.LocalizedString)

Example 14 with Vocabulary

use of org.obiba.opal.core.domain.taxonomy.Vocabulary 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)

Aggregations

Vocabulary (org.obiba.opal.core.domain.taxonomy.Vocabulary)14 Taxonomy (org.obiba.opal.core.domain.taxonomy.Taxonomy)6 Term (org.obiba.opal.core.domain.taxonomy.Term)4 Map (java.util.Map)2 LocalizedString (org.obiba.mica.core.domain.LocalizedString)2 Timed (com.codahale.metrics.annotation.Timed)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Strings (com.google.common.base.Strings)1 Maps (com.google.common.collect.Maps)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Inject (javax.inject.Inject)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 TaxonomyEntityWrapper (org.obiba.mica.core.domain.TaxonomyEntityWrapper)1 OpalService (org.obiba.mica.micaConfig.service.OpalService)1 AggregationMetaDataProvider (org.obiba.mica.micaConfig.service.helper.AggregationMetaDataProvider)1 TaxonomyTarget (org.obiba.mica.spi.search.TaxonomyTarget)1