Search in sources :

Example 36 with Study

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

the class StudySummaryDtos method asDtoFromDceUid.

Mica.StudySummaryDto asDtoFromDceUid(String dceUid) {
    String[] splitId = dceUid.split(":");
    String studyId = splitId[0];
    String populationId = splitId[1];
    String dceId = splitId[2];
    EntityState studyState = studyService.getEntityState(studyId);
    BaseStudy study = null;
    Mica.StudySummaryDto.Builder builder = Mica.StudySummaryDto.newBuilder();
    if (studyState.isPublished()) {
        study = publishedStudyService.findById(studyId);
    } else {
        study = studyService.findStudy(studyId);
    }
    builder.setPublished(studyState.isPublished()).setId(study.getId()).setTimestamps(TimestampsDtos.asDto(study)).addAllName(localizedStringDtos.asDto(study.getName())).addAllAcronym(localizedStringDtos.asDto(study.getAcronym())).addAllObjectives(localizedStringDtos.asDto(study.getObjectives())).setStudyResourcePath(study.getResourcePath());
    Optional<Population> optionalPopulation = study.getPopulations().stream().filter(population -> population.getId().equals(populationId)).findFirst();
    if (optionalPopulation.isPresent()) {
        Population population = optionalPopulation.get();
        Mica.PopulationSummaryDto.Builder populationBuilder = Mica.PopulationSummaryDto.newBuilder().setId(population.getId()).addAllName(localizedStringDtos.asDto(population.getName()));
        if (population.getDescription() != null)
            populationBuilder.addAllDescription(localizedStringDtos.asDto(population.getDescription()));
        Optional<DataCollectionEvent> optionalDce = population.getDataCollectionEvents().stream().filter(dce -> dce.getId().equals(dceId)).findFirst();
        if (optionalDce.isPresent()) {
            DataCollectionEvent dce = optionalDce.get();
            Mica.DataCollectionEventSummaryDto.Builder dceBuilder = Mica.DataCollectionEventSummaryDto.newBuilder().setId(dceUid).addAllName(localizedStringDtos.asDto(dce.getName()));
            if (dce.getDescription() != null)
                dceBuilder.addAllDescription(localizedStringDtos.asDto(dce.getDescription()));
            if (dce.hasStart())
                dceBuilder.setStart(dce.getStart().getYearMonth());
            if (dce.hasEnd())
                dceBuilder.setEnd(dce.getEnd().getYearMonth());
            populationBuilder.addDataCollectionEventSummaries(dceBuilder.build());
        }
        builder.addPopulationSummaries(populationBuilder.build());
    }
    return builder.build();
}
Also used : SortedSet(java.util.SortedSet) LoggerFactory(org.slf4j.LoggerFactory) HashSet(java.util.HashSet) Inject(javax.inject.Inject) PersistableYearMonth(org.obiba.mica.study.date.PersistableYearMonth) EntityState(org.obiba.mica.core.domain.EntityState) Map(java.util.Map) JSONUtils(org.obiba.mica.JSONUtils) NoSuchElementException(java.util.NoSuchElementException) Collectors.toSet(java.util.stream.Collectors.toSet) PublishedDatasetVariableService(org.obiba.mica.study.service.PublishedDatasetVariableService) Logger(org.slf4j.Logger) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) Collection(java.util.Collection) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Population(org.obiba.mica.study.domain.Population) Set(java.util.Set) StudyService(org.obiba.mica.study.service.StudyService) NotNull(javax.validation.constraints.NotNull) DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) Collectors(java.util.stream.Collectors) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) Objects(java.util.Objects) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) Study(org.obiba.mica.study.domain.Study) DateTimeFormatter(java.time.format.DateTimeFormatter) Optional(java.util.Optional) EntityState(org.obiba.mica.core.domain.EntityState) DataCollectionEvent(org.obiba.mica.study.domain.DataCollectionEvent) Population(org.obiba.mica.study.domain.Population) BaseStudy(org.obiba.mica.study.domain.BaseStudy)

Example 37 with Study

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

the class TestDataCollectionEventSort method test_study_populations_sort_with_duplicate_events.

@Test
public void test_study_populations_sort_with_duplicate_events() {
    Study study = new Study();
    study.setId("01234567889");
    study.addPopulation(createPopulation("Population001", createEvent("A", "A", 2010, 1, 2020, 12)));
    study.addPopulation(createPopulation("Population002", createEvent("A", "A", 2010, 1, 2020, 12)));
    study.addPopulation(createPopulation("Population003", createEvent("A", "A", 2010, 1, 2020, 12)));
    SortedSet<Population> populations = study.getPopulations();
    assertThat(populations.size()).isEqualTo(3);
    assertThat(Iterables.get(Iterables.get(populations, 0).getDataCollectionEvents(), 0).getStart()).isEqualTo(of(2010, 1));
    assertThat(Iterables.get(Iterables.get(populations, 1).getDataCollectionEvents(), 0).getStart()).isEqualTo(of(2010, 1));
    assertThat(Iterables.get(Iterables.get(populations, 2).getDataCollectionEvents(), 0).getStart()).isEqualTo(of(2010, 1));
}
Also used : Study(org.obiba.mica.study.domain.Study) Population(org.obiba.mica.study.domain.Population) Test(org.junit.Test)

Example 38 with Study

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

the class IndividualStudyServiceTest method test_loosing_git_base_repo.

@Test
public void test_loosing_git_base_repo() throws IOException {
    Study study = new Study();
    Stream.of("a", "b", "c").forEach(name -> {
        study.setName(en(name + " en").forFr(name + " fr"));
        individualStudyService.save(study);
        individualStudyService.publish(study.getId(), true);
    });
    FileUtil.delete(Config.BASE_REPO);
    Study draft = individualStudyService.findDraft(study.getId());
    draft.setName(en("d en").forFr("d fr"));
    individualStudyService.save(draft);
    individualStudyService.publish(draft.getId(), true);
    StudyState studyState = individualStudyService.findStateById(draft.getId());
    assertThat(studyState.isPublished()).isTrue();
    assertThat(studyState.getPublishedTag()).isEqualTo("4");
}
Also used : Study(org.obiba.mica.study.domain.Study) StudyState(org.obiba.mica.study.domain.StudyState) Test(org.junit.Test)

Example 39 with Study

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

the class IndividualStudyServiceTest method test_publish_current.

@Test
public void test_publish_current() throws Exception {
    Study study = new Study();
    study.setName(en("name en").forFr("name fr"));
    individualStudyService.save(study);
    assertThat(individualStudyService.findAllStates()).hasSize(1);
    assertThat(individualStudyService.findPublishedStates()).isEmpty();
    individualStudyService.publish(study.getId(), true);
    List<StudyState> publishedStates = individualStudyService.findPublishedStates();
    assertThat(publishedStates).hasSize(1);
    StudyState publishedState = publishedStates.get(0);
    assertThat(publishedState.getId()).isEqualTo(study.getId());
    assertThat(publishedState.getPublishedTag()).isEqualTo("1");
    Study draft = individualStudyService.findDraft(study.getId());
    draft.setName(en("new name en").forFr("new name fr"));
    individualStudyService.save(draft);
    assertThat(individualStudyService.findDraft(study.getId())).areFieldsEqualToEachOther(draft);
}
Also used : Study(org.obiba.mica.study.domain.Study) StudyState(org.obiba.mica.study.domain.StudyState) Test(org.junit.Test)

Example 40 with Study

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

the class IndividualStudyServiceTest method test_delete_study.

@Test
public void test_delete_study() {
    Study study = new Study();
    study.setName(en("name en").forFr("name fr"));
    individualStudyService.save(study);
    assertThat(studyStateRepository.findAll()).hasSize(1);
    individualStudyService.delete(study.getId());
    assertThat(studyRepository.findAll()).hasSize(0);
    assertThat(studyStateRepository.findAll()).hasSize(0);
}
Also used : Study(org.obiba.mica.study.domain.Study) Test(org.junit.Test)

Aggregations

Study (org.obiba.mica.study.domain.Study)46 BaseStudy (org.obiba.mica.study.domain.BaseStudy)17 Test (org.junit.Test)16 Collectors (java.util.stream.Collectors)10 Inject (javax.inject.Inject)10 List (java.util.List)9 HarmonizationStudy (org.obiba.mica.study.domain.HarmonizationStudy)9 Strings (com.google.common.base.Strings)8 Population (org.obiba.mica.study.domain.Population)8 NotNull (javax.validation.constraints.NotNull)7 DataCollectionEvent (org.obiba.mica.study.domain.DataCollectionEvent)7 Timed (com.codahale.metrics.annotation.Timed)6 Lists (com.google.common.collect.Lists)6 Map (java.util.Map)6 Collectors.toList (java.util.stream.Collectors.toList)6 PublishedStudyService (org.obiba.mica.study.service.PublishedStudyService)6 Sets (com.google.common.collect.Sets)5 HashMap (java.util.HashMap)5 NoSuchEntityException (org.obiba.mica.NoSuchEntityException)5 StudyService (org.obiba.mica.study.service.StudyService)5