use of org.obiba.opal.core.domain.taxonomy.Vocabulary 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();
}
use of org.obiba.opal.core.domain.taxonomy.Vocabulary in project mica2 by obiba.
the class Mica220Upgrade method updateFixWrongKeysInStudyTaxonomy.
private void updateFixWrongKeysInStudyTaxonomy() {
TaxonomyEntityWrapper studyTaxonomy = taxonomyConfigRepository.findOne("study");
if (studyTaxonomy == null)
return;
List<Vocabulary> vocabularies = studyTaxonomy.getTaxonomy().getVocabularies();
vocabularies.stream().filter(vocabulary -> vocabulary.getName().equals("numberOfParticipants-sample-number") || vocabulary.getName().equals("numberOfParticipants-sample-range")).map(TaxonomyEntity::getAttributes).forEach(attributes -> {
attributes.put("field", "model." + attributes.get("field"));
attributes.put("alias", "model-" + attributes.get("alias"));
});
taxonomyConfigRepository.save(studyTaxonomy);
}
use of org.obiba.opal.core.domain.taxonomy.Vocabulary 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);
}
use of org.obiba.opal.core.domain.taxonomy.Vocabulary in project mica2 by obiba.
the class TaxonomyConfigService method mergeVocabulariesTerms.
void mergeVocabulariesTerms(Taxonomy taxonomy, Taxonomy defaultTaxonomy) {
defaultTaxonomy.getVocabularies().forEach(v -> {
if (!taxonomy.hasVocabulary(v.getName())) {
taxonomy.addVocabulary(v);
} else {
Vocabulary defaultTaxonomyVocabulary = defaultTaxonomy.getVocabulary(v.getName());
Vocabulary taxonomyVocabulary = taxonomy.getVocabulary(v.getName());
if (defaultTaxonomyVocabulary.hasTerms()) {
defaultTaxonomyVocabulary.getTerms().forEach(t -> {
if (!taxonomyVocabulary.hasTerm(t.getName()))
taxonomyVocabulary.addTerm(t);
});
}
}
});
}
use of org.obiba.opal.core.domain.taxonomy.Vocabulary in project mica2 by obiba.
the class VocabularyDuplicateAliasExceptionMapper method getErrorDto.
@Override
protected GeneratedMessage.ExtendableMessage<?> getErrorDto(VocabularyDuplicateAliasException e) {
Vocabulary vocabulary = e.getVocabulary();
ErrorDtos.ClientErrorDto.Builder builder = ErrorDtos.ClientErrorDto.newBuilder().setCode(getStatus().getStatusCode());
if (vocabulary != null) {
builder.setMessageTemplate("server.error.taxonomy.duplicate-criterion-alias");
String field = vocabulary.getAttributeValue("field");
builder.addArguments(Strings.isNullOrEmpty(field) ? vocabulary.getName() : field);
}
return builder.build();
}
Aggregations