use of org.obiba.mica.study.NoSuchStudyException in project mica2 by obiba.
the class VariableQuery method processHit.
/**
* Fill the variable resolver dto with user-friendly labels about the variable, the dataset and the study.
*
* @param resolver
* @param variable
* @param studyMap study cache
* @return
*/
private Mica.DatasetVariableResolverDto processHit(DatasetVariable.IdResolver resolver, DatasetVariable variable, Map<String, BaseStudy> studyMap, Map<String, Network> networkMap) {
Mica.DatasetVariableResolverDto.Builder builder = dtos.asDto(resolver, variable);
String studyId = resolver.hasStudyId() ? resolver.getStudyId() : null;
if (resolver.getType() == DatasetVariable.Type.Collected || resolver.getType() == DatasetVariable.Type.Dataschema || resolver.getType() == DatasetVariable.Type.Harmonized) {
studyId = variable.getStudyId();
}
if (studyId != null) {
builder.setStudyId(studyId);
try {
BaseStudy study;
if (studyMap.containsKey(studyId)) {
study = studyMap.get(studyId);
} else {
study = publishedStudyService.findById(studyId);
studyMap.put(studyId, study);
}
if (study != null) {
builder.addAllStudyName(dtos.asDto(study.getName()));
builder.addAllStudyAcronym(dtos.asDto(study.getAcronym()));
String dceId = variable.getDceId();
if (!Strings.isNullOrEmpty(dceId)) {
String[] parts = dceId.split(":");
if (parts.length > 1) {
Optional<Population> optionalPopulation = study.getPopulations().stream().filter(population -> population.getId().equals(parts[1])).findFirst();
if (optionalPopulation.isPresent()) {
Population population = optionalPopulation.get();
builder.addAllPopulationName(dtos.asDto(population.getName()));
if (parts.length > 2) {
population.getDataCollectionEvents().stream().filter(dce -> dce.getId().equals(parts[2])).findFirst().ifPresent(dataCollectionEvent -> builder.addAllDceName(dtos.asDto(dataCollectionEvent.getName())));
}
}
}
}
}
} catch (NoSuchStudyException e) {
}
}
return builder.build();
}
Aggregations