Search in sources :

Example 1 with HarmonizationAnnotations

use of org.obiba.mica.web.controller.domain.HarmonizationAnnotations 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)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 List (java.util.List)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1 NoSuchVariableException (org.obiba.magma.NoSuchVariableException)1 HarmonizationStudyTable (org.obiba.mica.core.domain.HarmonizationStudyTable)1 StudyTable (org.obiba.mica.core.domain.StudyTable)1 NoSuchDatasetException (org.obiba.mica.dataset.NoSuchDatasetException)1 DatasetVariable (org.obiba.mica.dataset.domain.DatasetVariable)1 HarmonizationDataset (org.obiba.mica.dataset.domain.HarmonizationDataset)1 CollectedDatasetService (org.obiba.mica.dataset.service.CollectedDatasetService)1 HarmonizedDatasetService (org.obiba.mica.dataset.service.HarmonizedDatasetService)1 TaxonomyService (org.obiba.mica.micaConfig.service.TaxonomyService)1 Indexer (org.obiba.mica.spi.search.Indexer)1