Search in sources :

Example 41 with Study

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

the class StudyDtosTest method test_full_dto.

@Test
public void test_full_dto() throws Exception {
    when(attachmentDtos.asDto(any(Attachment.class))).thenReturn(Mica.AttachmentDto.newBuilder().setId("123").setFileName("logo123").build());
    when(attachmentDtos.fromDto(any(Mica.AttachmentDtoOrBuilder.class))).thenReturn(createAttachment());
    Study study = createStudy();
    Mica.StudyDto dto = studyDtos.asDto(study, true);
    Study fromDto = (Study) studyDtos.fromDto(dto);
    assertTimestamps(study, dto);
    assertThat(fromDto).isEqualTo(study);
}
Also used : Study(org.obiba.mica.study.domain.Study) Attachment(org.obiba.mica.file.Attachment) Test(org.junit.Test)

Example 42 with Study

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

the class StudyDtosTest method test_required_only_dto.

@Test
public void test_required_only_dto() throws Exception {
    Study study = new Study();
    study.setId(new ObjectId().toString());
    study.setName(en("Canadian Longitudinal Study on Aging"));
    study.setObjectives(en("The Canadian Longitudinal Study on Aging (CLSA) is a large, national, long-term study"));
    Mica.StudyDto dto = studyDtos.asDto(study, true);
    Study fromDto = (Study) studyDtos.fromDto(dto);
    assertTimestamps(study, dto);
    assertThat(fromDto).areFieldsEqualToEachOther(study);
}
Also used : Study(org.obiba.mica.study.domain.Study) ObjectId(org.bson.types.ObjectId) Test(org.junit.Test)

Example 43 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 44 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.getPopulationsCount() > 0) {
        study.setPopulations(dto.getPopulationsList().stream().map(populationDtos::fromDto).collect(Collectors.toCollection(TreeSet<org.obiba.mica.study.domain.Population>::new)));
    }
    if (dto.getMembershipSortOrderCount() > 0) {
        Map<String, List<String>> membershipSortOrder = new HashMap<>();
        dto.getMembershipSortOrderList().forEach(membership -> {
            membershipSortOrder.put(membership.getRole(), membership.getPersonIdsList());
        });
        study.setMembershipSortOrder(membershipSortOrder);
    }
    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) 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) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) BaseStudy(org.obiba.mica.study.domain.BaseStudy) NotNull(javax.validation.constraints.NotNull)

Example 45 with Study

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

the class VariableController method getStudy.

private BaseStudy getStudy(String id, boolean published) {
    BaseStudy study = published ? publishedStudyService.findById(id) : studyService.findStudy(id);
    if (study == null)
        throw NoSuchStudyException.withId(id);
    checkAccess((study instanceof Study) ? "/individual-study" : "/harmonization-study", id);
    return study;
}
Also used : BaseStudy(org.obiba.mica.study.domain.BaseStudy) Study(org.obiba.mica.study.domain.Study) BaseStudy(org.obiba.mica.study.domain.BaseStudy)

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