Search in sources :

Example 1 with NoSuchStudyException

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();
}
Also used : java.util(java.util) Query(org.obiba.mica.spi.search.support.Query) Taxonomy(org.obiba.opal.core.domain.taxonomy.Taxonomy) OpalService(org.obiba.mica.micaConfig.service.OpalService) AggregationMetaDataProvider(org.obiba.mica.micaConfig.service.helper.AggregationMetaDataProvider) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) MicaSearch(org.obiba.mica.web.model.MicaSearch) Lists(com.google.common.collect.Lists) DocumentQueryHelper(org.obiba.mica.search.DocumentQueryHelper) LanguageTag(sun.util.locale.LanguageTag) org.obiba.mica.spi.search(org.obiba.mica.spi.search) Mica(org.obiba.mica.web.model.Mica) Network(org.obiba.mica.network.domain.Network) Dtos(org.obiba.mica.web.model.Dtos) Nullable(javax.annotation.Nullable) DocumentQueryIdProvider(org.obiba.mica.search.DocumentQueryIdProvider) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Population(org.obiba.mica.study.domain.Population) CollectedDatasetService(org.obiba.mica.dataset.service.CollectedDatasetService) IOException(java.io.IOException) AttributeKey(org.obiba.mica.spi.search.support.AttributeKey) NotNull(javax.validation.constraints.NotNull) Maps(com.google.common.collect.Maps) org.obiba.mica.search.aggregations(org.obiba.mica.search.aggregations) Collectors(java.util.stream.Collectors) HarmonizedDatasetService(org.obiba.mica.dataset.service.HarmonizedDatasetService) NoSuchStudyException(org.obiba.mica.study.NoSuchStudyException) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) NONE(org.obiba.mica.spi.search.QueryScope.NONE) Component(org.springframework.stereotype.Component) DETAIL(org.obiba.mica.spi.search.QueryScope.DETAIL) Vocabulary(org.obiba.opal.core.domain.taxonomy.Vocabulary) Pattern(java.util.regex.Pattern) Joiner(com.google.common.base.Joiner) Population(org.obiba.mica.study.domain.Population) BaseStudy(org.obiba.mica.study.domain.BaseStudy) NoSuchStudyException(org.obiba.mica.study.NoSuchStudyException)

Aggregations

Joiner (com.google.common.base.Joiner)1 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 IOException (java.io.IOException)1 java.util (java.util)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1 NotNull (javax.validation.constraints.NotNull)1 DatasetVariable (org.obiba.mica.dataset.domain.DatasetVariable)1 CollectedDatasetService (org.obiba.mica.dataset.service.CollectedDatasetService)1 HarmonizedDatasetService (org.obiba.mica.dataset.service.HarmonizedDatasetService)1 OpalService (org.obiba.mica.micaConfig.service.OpalService)1 AggregationMetaDataProvider (org.obiba.mica.micaConfig.service.helper.AggregationMetaDataProvider)1 Network (org.obiba.mica.network.domain.Network)1 DocumentQueryHelper (org.obiba.mica.search.DocumentQueryHelper)1 DocumentQueryIdProvider (org.obiba.mica.search.DocumentQueryIdProvider)1 org.obiba.mica.search.aggregations (org.obiba.mica.search.aggregations)1