Search in sources :

Example 1 with TaxonomyEntity

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

the class VariableController method variable.

@GetMapping("/variable/{id:.+}")
public ModelAndView variable(@PathVariable String id) {
    Map<String, Object> params = newParameters();
    DatasetVariable.IdResolver resolver = DatasetVariable.IdResolver.from(id);
    String datasetId = resolver.getDatasetId();
    String variableName = resolver.getName();
    switch(resolver.getType()) {
        case Collected:
            if (!collectedDatasetService.isPublished(datasetId))
                throw NoSuchDatasetException.withId(datasetId);
            break;
        case Dataschema:
        case Harmonized:
            if (!harmonizedDatasetService.isPublished(datasetId))
                throw NoSuchDatasetException.withId(datasetId);
            break;
    }
    DatasetVariable variable = resolver.getType().equals(DatasetVariable.Type.Harmonized) ? getHarmonizedDatasetVariable(resolver.getDatasetId(), id, variableName) : getDatasetVariable(id, variableName);
    params.put("variable", variable);
    params.put("type", resolver.getType().toString());
    addStudyTableParameters(params, variable);
    Map<String, Taxonomy> taxonomies = taxonomyService.getVariableTaxonomies().stream().collect(Collectors.toMap(TaxonomyEntity::getName, e -> e));
    // annotations are attributes described by some taxonomies
    List<Annotation> annotations = variable.hasAttributes() ? variable.getAttributes().asAttributeList().stream().filter(attr -> attr.hasNamespace() && taxonomies.containsKey(attr.getNamespace()) && taxonomies.get(attr.getNamespace()).hasVocabulary(attr.getName())).map(attr -> new Annotation(attr, taxonomies.get(attr.getNamespace()))).collect(Collectors.toList()) : Lists.newArrayList();
    List<Annotation> harmoAnnotations = annotations.stream().filter(annot -> annot.getTaxonomyName().equals("Mlstr_harmo")).collect(Collectors.toList());
    annotations = annotations.stream().filter(annot -> !annot.getTaxonomyName().equals("Mlstr_harmo")).collect(Collectors.toList());
    StringBuilder query = new StringBuilder();
    for (Annotation annot : annotations) {
        String expr = "in(" + annot.getTaxonomyName() + "." + annot.getVocabularyName() + "," + annot.getTermName() + ")";
        if (query.length() == 0)
            query = new StringBuilder(expr);
        else
            query = new StringBuilder("and(" + query + "," + expr + ")");
    }
    params.put("annotations", annotations);
    params.put("harmoAnnotations", new HarmonizationAnnotations(harmoAnnotations));
    params.put("query", "variable(" + query.toString() + ")");
    params.put("showDatasetContingencyLink", showDatasetContingencyLink());
    return new ModelAndView("variable", params);
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) LoggerFactory(org.slf4j.LoggerFactory) HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable) Controller(org.springframework.stereotype.Controller) NoSuchVariableException(org.obiba.magma.NoSuchVariableException) Indexer(org.obiba.mica.spi.search.Indexer) Inject(javax.inject.Inject) Lists(com.google.common.collect.Lists) Map(java.util.Map) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) GetMapping(org.springframework.web.bind.annotation.GetMapping) NoSuchDatasetException(org.obiba.mica.dataset.NoSuchDatasetException) TaxonomyEntity(org.obiba.opal.core.domain.taxonomy.TaxonomyEntity) NoSuchElementException(java.util.NoSuchElementException) Logger(org.slf4j.Logger) Searcher(org.obiba.mica.spi.search.Searcher) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) BaseStudy(org.obiba.mica.study.domain.BaseStudy) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Population(org.obiba.mica.study.domain.Population) CollectedDatasetService(org.obiba.mica.dataset.service.CollectedDatasetService) StudyService(org.obiba.mica.study.service.StudyService) IOException(java.io.IOException) DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) Collectors(java.util.stream.Collectors) HarmonizedDatasetService(org.obiba.mica.dataset.service.HarmonizedDatasetService) NoSuchStudyException(org.obiba.mica.study.NoSuchStudyException) HarmonizationAnnotations(org.obiba.mica.web.controller.domain.HarmonizationAnnotations) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) ModelAndView(org.springframework.web.servlet.ModelAndView) List(java.util.List) Study(org.obiba.mica.study.domain.Study) Annotation(org.obiba.mica.web.controller.domain.Annotation) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) TaxonomyService(org.obiba.mica.micaConfig.service.TaxonomyService) Optional(java.util.Optional) StudyTable(org.obiba.mica.core.domain.StudyTable) InputStream(java.io.InputStream) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) ModelAndView(org.springframework.web.servlet.ModelAndView) HarmonizationAnnotations(org.obiba.mica.web.controller.domain.HarmonizationAnnotations) Annotation(org.obiba.mica.web.controller.domain.Annotation) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with TaxonomyEntity

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

the class OpalServiceHelper method getTaxonomies.

// opal root url as key
@Cacheable(value = "opal-taxonomies", key = "#opalJavaClient.newUri().build()")
public Map<String, Taxonomy> getTaxonomies(OpalJavaClient opalJavaClient) {
    log.info("Fetching opal taxonomies");
    URI uri = opalJavaClient.newUri().segment("system", "conf", "taxonomies").build();
    List<Opal.TaxonomyDto> taxonomies = opalJavaClient.getResources(Opal.TaxonomyDto.class, uri, Opal.TaxonomyDto.newBuilder());
    ConcurrentMap<String, Taxonomy> taxonomiesList = taxonomies.stream().map(taxonomyDto -> {
        Taxonomy taxonomy = fromDto(taxonomyDto);
        String defaultTermsSortOrder = opalTaxonomiesProperties.getProperty("defaultTermsSortOrder");
        if (!Strings.isNullOrEmpty(defaultTermsSortOrder)) {
            taxonomy.getVocabularies().forEach(vocabulary -> vocabulary.addAttribute("termsSortKey", defaultTermsSortOrder));
        }
        return taxonomy;
    }).collect(Collectors.toConcurrentMap(TaxonomyEntity::getName, taxonomy -> taxonomy));
    eventBus.post(new OpalTaxonomiesUpdatedEvent(taxonomiesList));
    return taxonomiesList;
}
Also used : Search(org.obiba.opal.web.model.Search) Logger(org.slf4j.Logger) OpalTaxonomiesUpdatedEvent(org.obiba.mica.micaConfig.event.OpalTaxonomiesUpdatedEvent) Cacheable(org.springframework.cache.annotation.Cacheable) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) Dtos(org.obiba.opal.web.taxonomy.Dtos) LoggerFactory(org.slf4j.LoggerFactory) AttributeKey(org.obiba.mica.spi.search.support.AttributeKey) Opal(org.obiba.opal.web.model.Opal) Collectors(java.util.stream.Collectors) ConcurrentMap(java.util.concurrent.ConcurrentMap) Inject(javax.inject.Inject) EventBus(com.google.common.eventbus.EventBus) Strings(com.google.common.base.Strings) List(java.util.List) RelaxedPropertyResolver(org.springframework.boot.bind.RelaxedPropertyResolver) Component(org.springframework.stereotype.Component) EnvironmentAware(org.springframework.context.EnvironmentAware) Environment(org.springframework.core.env.Environment) Map(java.util.Map) URI(java.net.URI) TaxonomyEntity(org.obiba.opal.core.domain.taxonomy.TaxonomyEntity) OpalJavaClient(org.obiba.opal.rest.client.magma.OpalJavaClient) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) Opal(org.obiba.opal.web.model.Opal) URI(java.net.URI) OpalTaxonomiesUpdatedEvent(org.obiba.mica.micaConfig.event.OpalTaxonomiesUpdatedEvent) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Taxonomy (org.obiba.opal.core.domain.taxonomy.Taxonomy)2 TaxonomyEntity (org.obiba.opal.core.domain.taxonomy.TaxonomyEntity)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 EventBus (com.google.common.eventbus.EventBus)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 NoSuchElementException (java.util.NoSuchElementException)1 Optional (java.util.Optional)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 NoSuchVariableException (org.obiba.magma.NoSuchVariableException)1 HarmonizationStudyTable (org.obiba.mica.core.domain.HarmonizationStudyTable)1