Search in sources :

Example 1 with Taxonomy

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

the class MicaConfigService method getTaxonomyNode.

private JsonNode getTaxonomyNode(TaxonomyTarget taxonomyTarget, String locale) {
    Taxonomy taxonomy = taxonomyConfigService.findByTarget(taxonomyTarget);
    ObjectNode vocabularies = new ObjectNode(JsonNodeFactory.instance);
    for (Vocabulary vocabulary : taxonomy.getVocabularies()) {
        ObjectNode vocabularyNode = createObjectNode(vocabulary, locale);
        vocabularyNode = addTerms(vocabularyNode, vocabulary.getTerms(), locale);
        vocabularies.set(vocabulary.getName(), vocabularyNode);
    }
    ObjectNode taxonomyNode = createObjectNode(taxonomy, locale);
    taxonomyNode.set("vocabulary", vocabularies);
    return taxonomyNode;
}
Also used : Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy)

Example 2 with Taxonomy

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

the class TaxonomyService method copy.

private Taxonomy copy(Taxonomy source) {
    Taxonomy target = new Taxonomy();
    BeanUtils.copyProperties(source, target, "vocabularies");
    if (source.hasVocabularies()) {
        source.getVocabularies().forEach(sourceVoc -> {
            Vocabulary targetVoc = new Vocabulary();
            BeanUtils.copyProperties(sourceVoc, targetVoc, "terms");
            if (sourceVoc.hasTerms()) {
                sourceVoc.getTerms().forEach(sourceTerm -> {
                    Term targetTerm = new Term();
                    BeanUtils.copyProperties(sourceTerm, targetTerm);
                    targetVoc.addTerm(targetTerm);
                });
            }
            target.addVocabulary(targetVoc);
        });
    }
    return target;
}
Also used : Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) Term(org.obiba.opal.core.domain.taxonomy.Term)

Example 3 with Taxonomy

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

the class OpalServiceHelper method fromDto.

/**
 * Decorate the variable taxonomies with some Mica specific attributes.
 *
 * @param dto
 * @return
 */
private Taxonomy fromDto(Opal.TaxonomyDto dto) {
    Taxonomy taxonomy = Dtos.fromDto(dto);
    taxonomy.getVocabularies().forEach(vocabulary -> {
        String field = vocabulary.getAttributeValue("field");
        if (Strings.isNullOrEmpty(field)) {
            vocabulary.addAttribute("field", "attributes." + AttributeKey.getMapKey(vocabulary.getName(), taxonomy.getName()) + ".und");
        }
        String alias = vocabulary.getAttributeValue("alias");
        if (Strings.isNullOrEmpty(alias)) {
            vocabulary.addAttribute("alias", "attributes-" + AttributeKey.getMapKey(vocabulary.getName(), taxonomy.getName()) + "-und");
        }
    });
    return taxonomy;
}
Also used : Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy)

Example 4 with Taxonomy

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

the class ConfigurationTaxonomyMetaDataProvider method getAllLocalizedMetadata.

private Map<String, LocalizedMetaData> getAllLocalizedMetadata(String aggregation) {
    Taxonomy taxonomy = getTaxonomy();
    Vocabulary v = taxonomyVocabularyWithAlias(taxonomy, aggregation);
    if (v == null && taxonomy.hasVocabulary(aggregation)) {
        log.debug("Found in taxonomy {} a vocabulary with name: {}", taxonomy.getName(), aggregation);
        v = taxonomy.getVocabulary(aggregation);
    }
    return populateMetadataMap(v);
}
Also used : Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy)

Example 5 with Taxonomy

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

the class TaxonomyConfigServiceTest method validateTaxonomyDuplicateAliasRange.

@Test(expected = VocabularyDuplicateAliasException.class)
public void validateTaxonomyDuplicateAliasRange() {
    Taxonomy taxonomy = new Taxonomy("tax001");
    taxonomy.addVocabulary(createVocabulary("voc001", createTerms("term001", "term002"), AttributeBuilder.newBuilder().field("tax.voc").alias("tax-voc-range").range("true").build()));
    taxonomy.addVocabulary(createVocabulary("voc002", createTerms("term001", "term002"), AttributeBuilder.newBuilder().field("tax.voc").alias("tax-voc-range").range("true").build()));
    new TaxonomyConfigService().validateTaxonomy(taxonomy);
}
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