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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations