Search in sources :

Example 6 with MissingCommentException

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);
}
Also used : Project(org.obiba.mica.project.domain.Project) MissingCommentException(org.obiba.mica.core.service.MissingCommentException) ProjectState(org.obiba.mica.project.domain.ProjectState)

Aggregations

MissingCommentException (org.obiba.mica.core.service.MissingCommentException)6 DraftStudyUpdatedEvent (org.obiba.mica.study.event.DraftStudyUpdatedEvent)2 LocalizedString (org.obiba.mica.core.domain.LocalizedString)1 HarmonizationDataset (org.obiba.mica.dataset.domain.HarmonizationDataset)1 HarmonizationDatasetState (org.obiba.mica.dataset.domain.HarmonizationDatasetState)1 StudyDataset (org.obiba.mica.dataset.domain.StudyDataset)1 StudyDatasetState (org.obiba.mica.dataset.domain.StudyDatasetState)1 DatasetUpdatedEvent (org.obiba.mica.dataset.event.DatasetUpdatedEvent)1 Network (org.obiba.mica.network.domain.Network)1 NetworkState (org.obiba.mica.network.domain.NetworkState)1 Project (org.obiba.mica.project.domain.Project)1 ProjectState (org.obiba.mica.project.domain.ProjectState)1 HarmonizationStudyState (org.obiba.mica.study.domain.HarmonizationStudyState)1 StudyState (org.obiba.mica.study.domain.StudyState)1