Search in sources :

Example 1 with StudyState

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);
        }
    });
}
Also used : PersonUpdatedEvent(org.obiba.mica.contact.event.PersonUpdatedEvent) DraftStudyUpdatedEvent(org.obiba.mica.study.event.DraftStudyUpdatedEvent) StudyState(org.obiba.mica.study.domain.StudyState) StudyPublishedEvent(org.obiba.mica.study.event.StudyPublishedEvent)

Example 2 with StudyState

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);
}
Also used : Study(org.obiba.mica.study.domain.Study) DraftStudyUpdatedEvent(org.obiba.mica.study.event.DraftStudyUpdatedEvent) StudyState(org.obiba.mica.study.domain.StudyState) Test(org.junit.Test)

Example 3 with StudyState

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");
}
Also used : Study(org.obiba.mica.study.domain.Study) StudyState(org.obiba.mica.study.domain.StudyState) Test(org.junit.Test)

Example 4 with StudyState

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);
}
Also used : Study(org.obiba.mica.study.domain.Study) DraftStudyUpdatedEvent(org.obiba.mica.study.event.DraftStudyUpdatedEvent) StudyState(org.obiba.mica.study.domain.StudyState) Test(org.junit.Test)

Example 5 with StudyState

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");
}
Also used : Study(org.obiba.mica.study.domain.Study) StudyState(org.obiba.mica.study.domain.StudyState) Test(org.junit.Test)

Aggregations

StudyState (org.obiba.mica.study.domain.StudyState)10 Test (org.junit.Test)6 Study (org.obiba.mica.study.domain.Study)6 DraftStudyUpdatedEvent (org.obiba.mica.study.event.DraftStudyUpdatedEvent)4 PersonUpdatedEvent (org.obiba.mica.contact.event.PersonUpdatedEvent)1 LocalizedString (org.obiba.mica.core.domain.LocalizedString)1 HarmonizationStudyState (org.obiba.mica.study.domain.HarmonizationStudyState)1 StudyPublishedEvent (org.obiba.mica.study.event.StudyPublishedEvent)1