Search in sources :

Example 6 with Vocabulary

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();
}
Also used : Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Term(org.obiba.opal.core.domain.taxonomy.Term)

Example 7 with Vocabulary

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);
}
Also used : Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) TaxonomyEntityWrapper(org.obiba.mica.core.domain.TaxonomyEntityWrapper)

Example 8 with Vocabulary

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);
}
Also used : Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy)

Example 9 with Vocabulary

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);
                });
            }
        }
    });
}
Also used : Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary)

Example 10 with Vocabulary

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();
}
Also used : Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary)

Aggregations

Vocabulary (org.obiba.opal.core.domain.taxonomy.Vocabulary)14 Taxonomy (org.obiba.opal.core.domain.taxonomy.Taxonomy)6 Term (org.obiba.opal.core.domain.taxonomy.Term)4 Map (java.util.Map)2 LocalizedString (org.obiba.mica.core.domain.LocalizedString)2 Timed (com.codahale.metrics.annotation.Timed)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Strings (com.google.common.base.Strings)1 Maps (com.google.common.collect.Maps)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Inject (javax.inject.Inject)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 TaxonomyEntityWrapper (org.obiba.mica.core.domain.TaxonomyEntityWrapper)1 OpalService (org.obiba.mica.micaConfig.service.OpalService)1 AggregationMetaDataProvider (org.obiba.mica.micaConfig.service.helper.AggregationMetaDataProvider)1 TaxonomyTarget (org.obiba.mica.spi.search.TaxonomyTarget)1