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