Search in sources :

Example 1 with Term

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

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

the class AbstractIdAggregationMetaDataHelper method createTermFromMetaData.

protected Term createTermFromMetaData(String id, AggregationMetaDataProvider.LocalizedMetaData metaData) {
    Term term = new Term(id);
    term.setTitle(metaData.getTitle());
    term.setDescription(metaData.getDescription());
    term.addAttribute("className", metaData.getClassName());
    return term;
}
Also used : Term(org.obiba.opal.core.domain.taxonomy.Term)

Example 3 with Term

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

the class DatasetDtos method asDto.

private Mica.TermAttributesDto asDto(Taxonomy taxonomy, Attributes attributes, String locale) {
    Mica.TermAttributesDto.Builder builder = // 
    Mica.TermAttributesDto.newBuilder().setTaxonomy(taxonomyDtos.asDto(taxonomy, locale));
    Map<String, Mica.TermAttributeDto.Builder> terms = Maps.newHashMap();
    attributes.getAttributes(taxonomy.getName()).forEach(attr -> {
        if (taxonomy.hasVocabulary(attr.getName())) {
            Vocabulary vocabulary = taxonomy.getVocabulary(attr.getName());
            String termStr = attr.getValues().getUndetermined();
            if (!Strings.isNullOrEmpty(termStr) && vocabulary.hasTerm(termStr)) {
                Mica.TermAttributeDto.Builder termBuilder;
                if (terms.containsKey(vocabulary.getName())) {
                    termBuilder = terms.get(vocabulary.getName());
                } else {
                    termBuilder = Mica.TermAttributeDto.newBuilder();
                    terms.put(vocabulary.getName(), termBuilder);
                    termBuilder.setVocabulary(taxonomyDtos.asDto(vocabulary, locale));
                }
                Term term = vocabulary.getTerm(termStr);
                termBuilder.addTerms(taxonomyDtos.asDto(term, locale));
            }
        }
    });
    // keep vocabulary order
    taxonomy.getVocabularies().forEach(vocabulary -> {
        if (terms.containsKey(vocabulary.getName())) {
            builder.addVocabularyTerms(terms.get(vocabulary.getName()));
        }
    });
    return builder.build();
}
Also used : Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Term(org.obiba.opal.core.domain.taxonomy.Term)

Example 4 with Term

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

the class TaxonomyConfigServiceTest method createTerm.

private Term createTerm(String name, String title, String desc) {
    Term term = new Term(name);
    term.setTitle(LocalizedString.en(title));
    term.setDescription(LocalizedString.en(desc));
    return term;
}
Also used : Term(org.obiba.opal.core.domain.taxonomy.Term)

Example 5 with Term

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

the class MicaConfigService method addTerms.

private ObjectNode addTerms(ObjectNode parentNode, List<Term> terms, String locale) {
    if (!isEmpty(terms)) {
        ObjectNode termsArrayNode = new ObjectNode(JsonNodeFactory.instance);
        for (Term term : terms) {
            ObjectNode termNode = createObjectNode(term, locale);
            termNode = addTerms(termNode, term.getTerms(), locale);
            termsArrayNode.set(term.getName(), termNode);
        }
        parentNode.set("term", termsArrayNode);
    }
    return parentNode;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Term(org.obiba.opal.core.domain.taxonomy.Term)

Aggregations

Term (org.obiba.opal.core.domain.taxonomy.Term)6 Vocabulary (org.obiba.opal.core.domain.taxonomy.Vocabulary)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 LocalizedString (org.obiba.mica.core.domain.LocalizedString)1 Taxonomy (org.obiba.opal.core.domain.taxonomy.Taxonomy)1