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