Search in sources :

Example 11 with BaseStudy

use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.

the class CollectedDatasetService method processVariablesForStudyDataset.

public List<DatasetVariable> processVariablesForStudyDataset(StudyDataset dataset, Iterable<DatasetVariable> variables) {
    if (!dataset.hasStudyTable()) {
        return Lists.newArrayList(variables);
    }
    StudyTable studyTable = dataset.getStudyTable();
    BaseStudy study = studyService.findStudy(dataset.getStudyTable().getStudyId());
    Population population = study.findPopulation(studyTable.getPopulationId());
    if (population == null) {
        return Lists.newArrayList(variables);
    }
    int populationWeight = population.getWeight();
    DataCollectionEvent dataCollectionEvent = population.findDataCollectionEvent(studyTable.getDataCollectionEventId());
    if (dataCollectionEvent == null) {
        return Lists.newArrayList(variables);
    }
    int dataCollectionEventWeight = dataCollectionEvent.getWeight();
    return StreamSupport.stream(variables.spliterator(), false).map(datasetVariable -> {
        datasetVariable.setPopulationWeight(populationWeight);
        datasetVariable.setDataCollectionEventWeight(dataCollectionEventWeight);
        return datasetVariable;
    }).collect(toList());
}
Also used : Search(org.obiba.opal.web.model.Search) DatasetDeletedEvent(org.obiba.mica.dataset.event.DatasetDeletedEvent) FileUtils(org.obiba.mica.file.FileUtils) Cacheable(org.springframework.cache.annotation.Cacheable) LoggerFactory(org.slf4j.LoggerFactory) CacheEvict(org.springframework.cache.annotation.CacheEvict) AbstractGitPersistable(org.obiba.mica.core.domain.AbstractGitPersistable) NoSuchVariableException(org.obiba.magma.NoSuchVariableException) DatasetUnpublishedEvent(org.obiba.mica.dataset.event.DatasetUnpublishedEvent) Valid(javax.validation.Valid) StudyDatasetIndexedEvent(org.obiba.mica.dataset.event.StudyDatasetIndexedEvent) PublishCascadingScope(org.obiba.mica.core.domain.PublishCascadingScope) EntityStateRepository(org.obiba.mica.core.repository.EntityStateRepository) NoSuchDatasetException(org.obiba.mica.dataset.NoSuchDatasetException) StudyState(org.obiba.mica.study.domain.StudyState) QueryTermsUtil(org.obiba.mica.dataset.service.support.QueryTermsUtil) Set(java.util.Set) StudyService(org.obiba.mica.study.service.StudyService) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) Sets(com.google.common.collect.Sets) List(java.util.List) NoSuchValueTableException(org.obiba.magma.NoSuchValueTableException) Stream(java.util.stream.Stream) Study(org.obiba.mica.study.domain.Study) StudyDatasetState(org.obiba.mica.dataset.domain.StudyDatasetState) StudyDatasetStateRepository(org.obiba.mica.dataset.StudyDatasetStateRepository) Lazy(org.springframework.context.annotation.Lazy) NetworkService(org.obiba.mica.network.service.NetworkService) BeanUtils(org.springframework.beans.BeanUtils) Async(org.springframework.scheduling.annotation.Async) DatasetPublishedEvent(org.obiba.mica.dataset.event.DatasetPublishedEvent) RestValueTable(org.obiba.opal.rest.client.magma.RestValueTable) OpalService(org.obiba.mica.micaConfig.service.OpalService) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Caching(org.springframework.cache.annotation.Caching) EventBus(com.google.common.eventbus.EventBus) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) Service(org.springframework.stereotype.Service) StreamSupport(java.util.stream.StreamSupport) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Validated(org.springframework.validation.annotation.Validated) DatasetUpdatedEvent(org.obiba.mica.dataset.event.DatasetUpdatedEvent) Logger(org.slf4j.Logger) DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) BaseStudy(org.obiba.mica.study.domain.BaseStudy) DateTime(org.joda.time.DateTime) Population(org.obiba.mica.study.domain.Population) FileSystemService(org.obiba.mica.file.service.FileSystemService) DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) NoSuchStudyException(org.obiba.mica.study.NoSuchStudyException) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) IndividualStudyService(org.obiba.mica.study.service.IndividualStudyService) Component(org.springframework.stereotype.Component) Collectors.toList(java.util.stream.Collectors.toList) StudyDatasetRepository(org.obiba.mica.dataset.StudyDatasetRepository) StudyTable(org.obiba.mica.core.domain.StudyTable) DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) StudyTable(org.obiba.mica.core.domain.StudyTable) Population(org.obiba.mica.study.domain.Population) BaseStudy(org.obiba.mica.study.domain.BaseStudy)

Example 12 with BaseStudy

use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.

the class CollectedDatasetService method prepareForIndex.

private void prepareForIndex(StudyDataset dataset) {
    if (dataset.hasStudyTable()) {
        StudyTable studyTable = dataset.getStudyTable();
        BaseStudy study = publishedStudyService.findById(dataset.getStudyTable().getStudyId());
        if (study != null) {
            Population population = study.findPopulation(studyTable.getPopulationId());
            if (population != null) {
                studyTable.setPopulationWeight(population.getWeight());
                DataCollectionEvent dataCollectionEvent = population.findDataCollectionEvent(studyTable.getDataCollectionEventId());
                if (dataCollectionEvent != null) {
                    studyTable.setDataCollectionEventWeight(dataCollectionEvent.getWeight());
                }
            }
        }
    }
}
Also used : DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) StudyTable(org.obiba.mica.core.domain.StudyTable) Population(org.obiba.mica.study.domain.Population) BaseStudy(org.obiba.mica.study.domain.BaseStudy)

Example 13 with BaseStudy

use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.

the class StudyQuery method processHits.

@Override
public void processHits(QueryResultDto.Builder builder, Searcher.DocumentResults results, QueryScope scope, CountStatsData counts) throws IOException {
    StudyResultDto.Builder resBuilder = StudyResultDto.newBuilder();
    StudyCountStatsBuilder studyCountStatsBuilder = counts == null ? null : StudyCountStatsBuilder.newBuilder(counts);
    Consumer<BaseStudy> addDto = getStudyConsumer(scope, resBuilder, studyCountStatsBuilder);
    List<BaseStudy> publishedStudies = getPublishedDocumentsFromHitsByClassName(results, BaseStudy.class);
    publishedStudies.forEach(addDto::accept);
    builder.setExtension(StudyResultDto.result, resBuilder.build());
}
Also used : StudyResultDto(org.obiba.mica.web.model.MicaSearch.StudyResultDto) StudyCountStatsBuilder(org.obiba.mica.search.CountStatsDtoBuilders.StudyCountStatsBuilder) BaseStudy(org.obiba.mica.study.domain.BaseStudy)

Example 14 with BaseStudy

use of org.obiba.mica.study.domain.BaseStudy 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);
    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()));
            }
        } catch (NoSuchStudyException e) {
        }
    }
    builder.addAllDatasetAcronym(dtos.asDto(variable.getDatasetAcronym()));
    builder.addAllDatasetName(dtos.asDto(variable.getDatasetName()));
    if (variable.hasAttribute("label", null)) {
        builder.addAllVariableLabel(dtos.asDto(variable.getAttributes().getAttribute("label", null).getValues()));
    }
    return builder.build();
}
Also used : BaseStudy(org.obiba.mica.study.domain.BaseStudy) NoSuchStudyException(org.obiba.mica.study.NoSuchStudyException)

Example 15 with BaseStudy

use of org.obiba.mica.study.domain.BaseStudy in project mica2 by obiba.

the class VariableQuery method processHits.

@Override
protected void processHits(MicaSearch.QueryResultDto.Builder builder, Searcher.DocumentResults results, QueryScope scope, CountStatsData counts) throws IOException {
    MicaSearch.DatasetVariableResultDto.Builder resBuilder = MicaSearch.DatasetVariableResultDto.newBuilder();
    Map<String, BaseStudy> studyMap = Maps.newHashMap();
    Map<String, Network> networkMap = Maps.newHashMap();
    for (Searcher.DocumentResult result : results.getDocuments()) {
        if (result.hasSource()) {
            DatasetVariable.IdResolver resolver = DatasetVariable.IdResolver.from(result.getId());
            DatasetVariable variable = objectMapper.readValue(result.getSourceInputStream(), DatasetVariable.class);
            resBuilder.addSummaries(processHit(resolver, variable, studyMap, networkMap));
        }
    }
    builder.setExtension(MicaSearch.DatasetVariableResultDto.result, resBuilder.build());
}
Also used : DatasetVariable(org.obiba.mica.dataset.domain.DatasetVariable) Network(org.obiba.mica.network.domain.Network) BaseStudy(org.obiba.mica.study.domain.BaseStudy)

Aggregations

BaseStudy (org.obiba.mica.study.domain.BaseStudy)15 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Inject (javax.inject.Inject)6 Study (org.obiba.mica.study.domain.Study)5 Component (org.springframework.stereotype.Component)5 Strings (com.google.common.base.Strings)4 HarmonizationStudy (org.obiba.mica.study.domain.HarmonizationStudy)4 StudyService (org.obiba.mica.study.service.StudyService)4 Map (java.util.Map)3 Collectors.toList (java.util.stream.Collectors.toList)3 NotNull (javax.validation.constraints.NotNull)3 NoSuchEntityException (org.obiba.mica.NoSuchEntityException)3 DatasetVariable (org.obiba.mica.dataset.domain.DatasetVariable)3 MicaConfigService (org.obiba.mica.micaConfig.service.MicaConfigService)3 NoSuchStudyException (org.obiba.mica.study.NoSuchStudyException)3 Population (org.obiba.mica.study.domain.Population)3 PublishedStudyService (org.obiba.mica.study.service.PublishedStudyService)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3