Search in sources :

Example 1 with MissingCommentException

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);
}
Also used : MissingCommentException(org.obiba.mica.core.service.MissingCommentException) HarmonizationDatasetState(org.obiba.mica.dataset.domain.HarmonizationDatasetState) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset)

Example 2 with MissingCommentException

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);
}
Also used : MissingCommentException(org.obiba.mica.core.service.MissingCommentException) Network(org.obiba.mica.network.domain.Network) LocalizedString(org.obiba.mica.core.domain.LocalizedString) NetworkState(org.obiba.mica.network.domain.NetworkState)

Example 3 with MissingCommentException

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));
}
Also used : MissingCommentException(org.obiba.mica.core.service.MissingCommentException) DraftStudyUpdatedEvent(org.obiba.mica.study.event.DraftStudyUpdatedEvent) StudyState(org.obiba.mica.study.domain.StudyState)

Example 4 with MissingCommentException

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));
}
Also used : MissingCommentException(org.obiba.mica.core.service.MissingCommentException) DraftStudyUpdatedEvent(org.obiba.mica.study.event.DraftStudyUpdatedEvent) HarmonizationStudyState(org.obiba.mica.study.domain.HarmonizationStudyState)

Example 5 with MissingCommentException

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));
}
Also used : MissingCommentException(org.obiba.mica.core.service.MissingCommentException) DatasetUpdatedEvent(org.obiba.mica.dataset.event.DatasetUpdatedEvent) StudyDatasetState(org.obiba.mica.dataset.domain.StudyDatasetState) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset)

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