Search in sources :

Example 16 with Taxonomy

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

the class TaxonomyConfigServiceTest method validateRangeTaxonomyWithoutRangeAttribute.

@Test(expected = VocabularyMissingRangeAttributeException.class)
public void validateRangeTaxonomyWithoutRangeAttribute() {
    Taxonomy taxonomy = new Taxonomy("tax001");
    taxonomy.addVocabulary(createVocabulary("voc001", createTerms("term001", "term002"), AttributeBuilder.newBuilder().field("tax.voc").alias("tax-voc-range").type("integer").build()));
    new TaxonomyConfigService().validateTaxonomy(taxonomy);
}
Also used : Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) Test(org.junit.Test)

Example 17 with Taxonomy

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

the class Mica310Upgrade method addDefaultFacets.

private void addDefaultFacets() {
    logger.info("Add default facets in study taxonomy");
    ImmutableList<String> vocabulariesWithFacet = ImmutableList.<String>builder().add("methods-design").add("start").add("end").add("populations-selectionCriteria-countriesIso").add("populations-selectionCriteria-ageMin").add("populations-selectionCriteria-ageMax").add("populations-selectionCriteria-gender").add("populations-selectionCriteria-pregnantWomen").add("populations-selectionCriteria-newborn").add("populations-selectionCriteria-twins").add("numberOfParticipants-participant-number").add("numberOfParticipants-sample-number").add("methods-recruitments").add("populations-recruitment-dataSources").add("populations-dataCollectionEvents-dataSources").add("populations-dataCollectionEvents-bioSamples").add("access", "19").build();
    Taxonomy studyTaxonomy = taxonomyConfigService.findByTarget(TaxonomyTarget.STUDY);
    for (Vocabulary vocabulary : studyTaxonomy.getVocabularies()) {
        if (vocabulariesWithFacet.contains(vocabulary.getName())) {
            vocabulary.addAttribute("facet", "true");
            vocabulary.addAttribute("facetPosition", "0");
            vocabulary.addAttribute("facetExpanded", "false");
        }
    }
    taxonomyConfigService.update(TaxonomyTarget.STUDY, studyTaxonomy);
}
Also used : Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy)

Example 18 with Taxonomy

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

the class TaxonomyConfigService method mergeWithDefault.

public void mergeWithDefault(TaxonomyTarget target) {
    Taxonomy targetTaxonomy = findByTarget(target);
    mergeVocabulariesTerms(targetTaxonomy, getDefault(target));
    updateInternal(target, targetTaxonomy);
}
Also used : Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy)

Example 19 with Taxonomy

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

the class OpalServiceHelper method getTaxonomies.

// opal root url as key
@Cacheable(value = "opal-taxonomies", key = "#opalJavaClient.newUri().build()")
public Map<String, Taxonomy> getTaxonomies(OpalJavaClient opalJavaClient) {
    log.info("Fetching opal taxonomies");
    URI uri = opalJavaClient.newUri().segment("system", "conf", "taxonomies").build();
    List<Opal.TaxonomyDto> taxonomies = opalJavaClient.getResources(Opal.TaxonomyDto.class, uri, Opal.TaxonomyDto.newBuilder());
    ConcurrentMap<String, Taxonomy> taxonomiesList = taxonomies.stream().collect(Collectors.toConcurrentMap(Opal.TaxonomyDto::getName, this::fromDto));
    eventBus.post(new OpalTaxonomiesUpdatedEvent(taxonomiesList));
    return taxonomiesList;
}
Also used : Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) Opal(org.obiba.opal.web.model.Opal) URI(java.net.URI) OpalTaxonomiesUpdatedEvent(org.obiba.mica.micaConfig.event.OpalTaxonomiesUpdatedEvent) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 20 with Taxonomy

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

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