use of org.obiba.mica.study.domain.StudyState in project mica2 by obiba.
the class ContactsRefactorUpgrade method execute.
@Override
public void execute(Version version) {
log.info("Executing contacts upgrade");
studyRepository.findAll().forEach(study -> {
study.getAllPersons().forEach(p -> p.setEmail(Strings.emptyToNull(p.getEmail())));
StudyState studyState = individualStudyService.findStateById(study.getId());
studyRepository.saveWithReferences(study);
eventBus.post(new DraftStudyUpdatedEvent(study));
study.getAllPersons().forEach(c -> eventBus.post(new PersonUpdatedEvent(c)));
if (studyState.isPublished()) {
eventBus.post(new StudyPublishedEvent(study, studyState.getPublishedBy(), PublishCascadingScope.ALL));
}
});
networkRepository.findAll().forEach(network -> {
network.getAllPersons().forEach(p -> p.setEmail(Strings.emptyToNull(p.getEmail())));
networkService.save(network, "System upgrade.");
if (network.isPublished()) {
networkService.publish(network.getId(), true);
}
});
}
use of org.obiba.mica.study.domain.StudyState in project mica2 by obiba.
the class IndividualStudyServiceTest method test_create_and_load_new_study.
@Test
public void test_create_and_load_new_study() throws Exception {
Study study = new Study();
study.setName(en("name en").forFr("name fr"));
individualStudyService.save(study);
List<StudyState> studyStates = studyStateRepository.findAll();
assertThat(studyStates).hasSize(1);
StudyState studyState = studyStates.get(0);
//
assertThat(studyState.getId()).isNotEmpty().isEqualTo(study.getId());
verify(eventBus).post(any(DraftStudyUpdatedEvent.class));
Study retrievedStudy = individualStudyService.findDraft(study.getId());
assertThat(retrievedStudy).areFieldsEqualToEachOther(study);
}
use of org.obiba.mica.study.domain.StudyState in project mica2 by obiba.
the class IndividualStudyServiceTest method test_loosing_git_clone_repo.
@Test
public void test_loosing_git_clone_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_CLONE);
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.StudyState in project mica2 by obiba.
the class IndividualStudyServiceTest method test_update_study.
@Test
public void test_update_study() throws Exception {
Study study = new Study();
study.setName(en("name en to update").forFr("name fr to update"));
individualStudyService.save(study);
study.setName(en("new name en").forFr("new name fr"));
individualStudyService.save(study);
List<StudyState> studyStates = studyStateRepository.findAll();
assertThat(studyStates).hasSize(1);
StudyState studyState = studyStates.get(0);
//
assertThat(studyState.getId()).isNotEmpty().isEqualTo(study.getId());
verify(eventBus, times(2)).post(any(DraftStudyUpdatedEvent.class));
Study retrievedStudy = individualStudyService.findDraft(study.getId());
assertThat(retrievedStudy).areFieldsEqualToEachOther(study);
}
use of org.obiba.mica.study.domain.StudyState in project mica2 by obiba.
the class IndividualStudyServiceTest method test_loosing_git_base_and_clone_repos.
@Test
public void test_loosing_git_base_and_clone_repos() 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);
FileUtil.delete(Config.BASE_CLONE);
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("1");
}
Aggregations