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