Search in sources :

Example 11 with Taxonomy

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

the class TaxonomyConfigServiceTest method validateRangeTaxonomyWithoutTerms.

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

Example 12 with Taxonomy

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

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

the class Mica220UpgradeTest method getWrapper.

private TaxonomyEntityWrapper getWrapper(String name) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    Taxonomy taxonomy = mapper.readValue(new File("src/test/resources/config/mica-" + name + ".json"), Taxonomy.class);
    TaxonomyEntityWrapper wrapper = new TaxonomyEntityWrapper();
    wrapper.setTarget(name);
    wrapper.setTaxonomy(taxonomy);
    return wrapper;
}
Also used : Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) TaxonomyEntityWrapper(org.obiba.mica.core.domain.TaxonomyEntityWrapper) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 14 with Taxonomy

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

the class TaxonomyConfigServiceTest method merge_taxonomy_with_one_having_same_vocabulary_but_extra_term.

@Test
public void merge_taxonomy_with_one_having_same_vocabulary_but_extra_term() {
    Taxonomy tax001 = new Taxonomy("tax001");
    tax001.addVocabulary(createVocabulary("voc001", null, null));
    Taxonomy tax002 = new Taxonomy("tax002");
    tax002.addVocabulary(createVocabulary("voc001", createTerms("term001"), null));
    new TaxonomyConfigService().mergeVocabulariesTerms(tax001, tax002);
    assert tax001.getVocabulary("voc001").hasTerm("term001");
}
Also used : Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) Test(org.junit.Test)

Example 15 with Taxonomy

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

the class TaxonomyConfigServiceTest method merge_taxonomy_with_vocabulary_having_one_term_with_one_having_same_vocabulary_without_term.

@Test
public void merge_taxonomy_with_vocabulary_having_one_term_with_one_having_same_vocabulary_without_term() {
    Taxonomy tax001 = new Taxonomy("tax001");
    tax001.addVocabulary(createVocabulary("voc001", createTerms("term001"), null));
    Taxonomy tax002 = new Taxonomy("tax002");
    tax002.addVocabulary(createVocabulary("voc001", null, null));
    new TaxonomyConfigService().mergeVocabulariesTerms(tax001, tax002);
    assert tax001.getVocabulary("voc001").hasTerm("term001");
}
Also used : Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) Test(org.junit.Test)

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