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