use of org.obiba.mica.core.service.MissingCommentException in project mica2 by obiba.
the class HarmonizedDatasetService method saveInternal.
//
// Private methods
//
@SuppressWarnings("OverlyLongMethod")
private void saveInternal(HarmonizationDataset dataset, String comment) {
if (!Strings.isNullOrEmpty(dataset.getId()) && micaConfigService.getConfig().isCommentsRequiredOnDocumentSave() && Strings.isNullOrEmpty(comment)) {
throw new MissingCommentException("Due to the server configuration, comments are required when saving this document.");
}
HarmonizationDataset saved = prepareSave(dataset);
HarmonizationDatasetState harmonizationDatasetState = findEntityState(dataset, HarmonizationDatasetState::new);
if (!dataset.isNew())
ensureGitRepository(harmonizationDatasetState);
harmonizationDatasetState.incrementRevisionsAhead();
harmonizationDatasetStateRepository.save(harmonizationDatasetState);
saved.setLastModifiedDate(DateTime.now());
harmonizationDatasetRepository.save(saved);
gitService.save(saved, comment);
helper.getPublishedVariables(saved);
}
use of org.obiba.mica.core.service.MissingCommentException in project mica2 by obiba.
the class NetworkService method saveInternal.
@SuppressWarnings("OverlyLongMethod")
private void saveInternal(@NotNull Network network, String comment, boolean cascade) {
if (!Strings.isNullOrEmpty(network.getId()) && micaConfigService.getConfig().isCommentsRequiredOnDocumentSave() && Strings.isNullOrEmpty(comment)) {
throw new MissingCommentException("Due to the server configuration, comments are required when saving this document.");
}
Network saved = network;
if (network.isNew()) {
generateId(saved);
} else {
saved = networkRepository.findOne(network.getId());
if (saved != null) {
BeanUtils.copyProperties(network, saved, "id", "version", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate");
} else {
saved = network;
}
}
if (saved.getLogo() != null && saved.getLogo().isJustUploaded()) {
fileStoreService.save(saved.getLogo().getId());
saved.getLogo().setJustUploaded(false);
}
ImmutableSet<String> invalidRoles = ImmutableSet.copyOf(Sets.difference(saved.membershipRoles(), Sets.newHashSet(micaConfigService.getConfig().getRoles())));
for (String r : invalidRoles) {
saved.removeRole(r);
}
NetworkState networkState = findEntityState(network, () -> {
NetworkState defaultState = new NetworkState();
defaultState.setName(network.getName());
return defaultState;
});
if (!network.isNew())
ensureGitRepository(networkState);
networkState.incrementRevisionsAhead();
networkStateRepository.save(networkState);
saved.setLastModifiedDate(DateTime.now());
networkRepository.save(saved);
eventBus.post(new NetworkUpdatedEvent(saved));
gitService.save(saved, comment);
}
use of org.obiba.mica.core.service.MissingCommentException in project mica2 by obiba.
the class IndividualStudyService method saveInternal.
public void saveInternal(final Study study, String comment, boolean cascade, boolean weightChanged) {
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 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);
}
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());
studyRepository.save(study);
gitService.save(study, comment);
eventBus.post(new DraftStudyUpdatedEvent(study));
}
use of org.obiba.mica.core.service.MissingCommentException 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.core.service.MissingCommentException in project mica2 by obiba.
the class CollectedDatasetService method saveInternal.
private void saveInternal(StudyDataset dataset, String comment) {
if (!Strings.isNullOrEmpty(dataset.getId()) && micaConfigService.getConfig().isCommentsRequiredOnDocumentSave() && Strings.isNullOrEmpty(comment)) {
throw new MissingCommentException("Due to the server configuration, comments are required when saving this document.");
}
StudyDataset saved = prepareSave(dataset);
StudyDatasetState studyDatasetState = findEntityState(dataset, StudyDatasetState::new);
if (!dataset.isNew())
ensureGitRepository(studyDatasetState);
studyDatasetState.incrementRevisionsAhead();
studyDatasetStateRepository.save(studyDatasetState);
saved.setLastModifiedDate(DateTime.now());
studyDatasetRepository.save(saved);
gitService.save(saved, comment);
eventBus.post(new DatasetUpdatedEvent(saved));
}
Aggregations