use of org.obiba.mica.study.domain.HarmonizationStudyState in project mica2 by obiba.
the class HarmonizationStudyService method saveInternal.
@Override
protected void saveInternal(final HarmonizationStudy study, String comment, boolean cascade) {
if (!Strings.isNullOrEmpty(study.getId()) && micaConfigService.getConfig().isCommentsRequiredOnDocumentSave() && Strings.isNullOrEmpty(comment)) {
throw new MissingCommentException("Due to the server configuration, comments are required when saving this document.");
}
log.info("Saving harmonization study: {}", study.getId());
// checks if population and dce are still the same
String studyId = study.getId();
if (studyId != null) {
List<String> list = populationsAffected(study, harmonizationStudyRepository.findOne(study.getId()));
if (list != null && list.size() > 0) {
checkPopulationMissingConstraints(studyId, 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);
HarmonizationStudyState studyState = findEntityState(study, HarmonizationStudyState::new);
if (!study.isNew())
ensureGitRepository(studyState);
studyState.incrementRevisionsAhead();
harmonizationStudyStateRepository.save(studyState);
study.setLastModifiedDate(DateTime.now());
harmonizationStudyRepository.save(study);
gitService.save(study, comment);
eventBus.post(new DraftStudyUpdatedEvent(study));
}
use of org.obiba.mica.study.domain.HarmonizationStudyState 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;
}
Aggregations