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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations