Search in sources :

Example 21 with Study

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

the class StudyDtos method fromDto.

@NotNull
BaseStudy fromDto(@NotNull Mica.StudyDtoOrBuilder dto) {
    Assert.isTrue(dto.hasExtension(Mica.CollectionStudyDto.type) || dto.hasExtension(Mica.HarmonizationStudyDto.type), "StudyDto must of a type extension.");
    BaseStudy study = dto.hasExtension(Mica.CollectionStudyDto.type) ? new Study() : new HarmonizationStudy();
    if (dto.hasId())
        study.setId(dto.getId());
    if (dto.getNameCount() > 0)
        study.setName(localizedStringDtos.fromDto(dto.getNameList()));
    if (dto.getAcronymCount() > 0)
        study.setAcronym(localizedStringDtos.fromDto(dto.getAcronymList()));
    if (dto.hasLogo())
        study.setLogo(attachmentDtos.fromDto(dto.getLogo()));
    if (dto.hasTimestamps())
        TimestampsDtos.fromDto(dto.getTimestamps(), study);
    if (dto.getObjectivesCount() > 0)
        study.setObjectives(localizedStringDtos.fromDto(dto.getObjectivesList()));
    if (dto.hasOpal())
        study.setOpal(dto.getOpal());
    if (dto.getMembershipsCount() > 0) {
        Map<String, List<Membership>> memberships = Maps.newHashMap();
        dto.getMembershipsList().forEach(e -> memberships.put(e.getRole(), e.getMembersList().stream().map(p -> new Membership(personDtos.fromDto(p), e.getRole())).collect(toList())));
        study.setMemberships(memberships);
    }
    if (dto.getPopulationsCount() > 0) {
        study.setPopulations(dto.getPopulationsList().stream().map(populationDtos::fromDto).collect(Collectors.toCollection(TreeSet<org.obiba.mica.study.domain.Population>::new)));
    }
    if (dto.hasContent() && !Strings.isNullOrEmpty(dto.getContent()))
        study.setModel(JSONUtils.toMap(dto.getContent()));
    else
        study.setModel(new HashMap<>());
    return study;
}
Also used : HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) HarmonizationStudyService(org.obiba.mica.study.service.HarmonizationStudyService) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Membership(org.obiba.mica.core.domain.Membership) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) NotNull(javax.validation.constraints.NotNull) Assert(io.jsonwebtoken.lang.Assert) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) TreeSet(java.util.TreeSet) Inject(javax.inject.Inject) IndividualStudyService(org.obiba.mica.study.service.IndividualStudyService) Strings(com.google.common.base.Strings) List(java.util.List) Component(org.springframework.stereotype.Component) Collectors.toList(java.util.stream.Collectors.toList) Study(org.obiba.mica.study.domain.Study) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) Map(java.util.Map) JSONUtils(org.obiba.mica.JSONUtils) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) HarmonizedDatasetHelper(org.obiba.mica.dataset.support.HarmonizedDatasetHelper) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Study(org.obiba.mica.study.domain.Study) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) Membership(org.obiba.mica.core.domain.Membership) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) BaseStudy(org.obiba.mica.study.domain.BaseStudy) NotNull(javax.validation.constraints.NotNull)

Example 22 with Study

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

the class CollectedDatasetServiceTest method buildStudy.

private Study buildStudy() {
    Study s = new Study();
    s.setOpal("opal");
    return s;
}
Also used : Study(org.obiba.mica.study.domain.Study)

Example 23 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 24 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 25 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)33 Test (org.junit.Test)16 StudyState (org.obiba.mica.study.domain.StudyState)8 BaseStudy (org.obiba.mica.study.domain.BaseStudy)6 List (java.util.List)5 Population (org.obiba.mica.study.domain.Population)5 Timed (com.codahale.metrics.annotation.Timed)4 HashMap (java.util.HashMap)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 NotNull (javax.validation.constraints.NotNull)4 Component (org.springframework.stereotype.Component)4 Strings (com.google.common.base.Strings)3 Maps (com.google.common.collect.Maps)3 Map (java.util.Map)3 Collectors.toList (java.util.stream.Collectors.toList)3 NoSuchEntityException (org.obiba.mica.NoSuchEntityException)3 Membership (org.obiba.mica.core.domain.Membership)3 DataCollectionEvent (org.obiba.mica.study.domain.DataCollectionEvent)3 HarmonizationStudy (org.obiba.mica.study.domain.HarmonizationStudy)3