use of org.obiba.mica.core.service.MissingCommentException in project mica2 by obiba.
the class ProjectService method save.
@Override
public void save(@NotNull @Valid Project project, String comments) {
if (!Strings.isNullOrEmpty(project.getId()) && micaConfigService.getConfig().isCommentsRequiredOnDocumentSave() && Strings.isNullOrEmpty(comments)) {
throw new MissingCommentException("Due to the server configuration, comments are required when saving this document.");
}
Project saved = project;
if (project.isNew()) {
generateId(saved);
} else {
saved = projectRepository.findOne(project.getId());
if (saved != null) {
BeanUtils.copyProperties(project, saved, "id", "version", "createdBy", "createdDate", "lastModifiedBy", "lastModifiedDate", "dataAccessRequestId");
} else {
saved = project;
}
}
ProjectState projectState = findEntityState(project, () -> {
ProjectState defaultState = new ProjectState();
defaultState.setTitle(project.getTitle());
return defaultState;
});
if (!project.isNew())
ensureGitRepository(projectState);
projectState.incrementRevisionsAhead();
projectStateRepository.save(projectState);
saved.setLastModifiedDate(DateTime.now());
projectRepository.save(saved);
eventBus.post(new ProjectUpdatedEvent(saved));
gitService.save(saved);
}
Aggregations