Search in sources :

Example 6 with StudyState

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

the class StudyIdGeneratorService method getNextId.

private String getNextId(String prefix, int count) {
    String id = prefix + (count > 0 ? "-" + count : "");
    StudyState studyState = studyStateRepository.findOne(id);
    HarmonizationStudyState harmonizationStudyState = harmonizationStudyStateRepository.findOne(id);
    if (studyState == null && harmonizationStudyState == null) {
        return id;
    }
    return count < 1000 ? getNextId(prefix, ++count) : null;
}
Also used : HarmonizationStudyState(org.obiba.mica.study.domain.HarmonizationStudyState) StudyState(org.obiba.mica.study.domain.StudyState) HarmonizationStudyState(org.obiba.mica.study.domain.HarmonizationStudyState) LocalizedString(org.obiba.mica.core.domain.LocalizedString)

Example 7 with StudyState

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

the class IndividualStudyService method saveInternal.

public void saveInternal(final Study study, String comment, boolean cascade, boolean weightChanged) {
    log.info("Saving study: {}", study.getId());
    // checks if population and dce are still the same
    if (study.getId() != null) {
        List<String> list = populationsOrDceAffected(study, studyRepository.findOne(study.getId()), false);
        if (list != null && list.size() > 0) {
            checkPopulationOrDceMissingConstraints(list);
        }
    }
    if (study.getLogo() != null && study.getLogo().isJustUploaded()) {
        fileStoreService.save(study.getLogo().getId());
        study.getLogo().setJustUploaded(false);
    }
    ImmutableSet<String> invalidRoles = ImmutableSet.copyOf(Sets.difference(study.membershipRoles(), Sets.newHashSet(micaConfigService.getConfig().getRoles())));
    invalidRoles.forEach(study::removeRole);
    StudyState studyState = findEntityState(study, StudyState::new);
    if (!study.isNew())
        ensureGitRepository(studyState);
    studyState.incrementRevisionsAhead();
    if (weightChanged) {
        studyState.setPopulationOrDceWeightChange(true);
    }
    studyStateRepository.save(studyState);
    study.setLastModifiedDate(DateTime.now());
    if (cascade)
        studyRepository.saveWithReferences(study);
    else
        studyRepository.save(study);
    gitService.save(study, comment);
    eventBus.post(new DraftStudyUpdatedEvent(study));
}
Also used : DraftStudyUpdatedEvent(org.obiba.mica.study.event.DraftStudyUpdatedEvent) StudyState(org.obiba.mica.study.domain.StudyState)

Example 8 with StudyState

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

Example 9 with StudyState

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

Example 10 with StudyState

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

the class CollectedDatasetService method resetCollectionStudyStatePopulationDceWeightChangeStatus.

private void resetCollectionStudyStatePopulationDceWeightChangeStatus(String studyId) {
    StudyState studyState = individualStudyService.getEntityState(studyId);
    if (!studyState.hasRevisionsAhead()) {
        studyState.setPopulationOrDceWeightChange(false);
        individualStudyService.saveState(studyState);
    }
}
Also used : StudyState(org.obiba.mica.study.domain.StudyState)

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