Search in sources :

Example 1 with HarmonizationStudyState

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

Example 2 with HarmonizationStudyState

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;
}
Also used : HarmonizationStudyState(org.obiba.mica.study.domain.HarmonizationStudyState) StudyState(org.obiba.mica.study.domain.StudyState) HarmonizationStudyState(org.obiba.mica.study.domain.HarmonizationStudyState) LocalizedString(org.obiba.mica.core.domain.LocalizedString)

Aggregations

HarmonizationStudyState (org.obiba.mica.study.domain.HarmonizationStudyState)2 LocalizedString (org.obiba.mica.core.domain.LocalizedString)1 MissingCommentException (org.obiba.mica.core.service.MissingCommentException)1 StudyState (org.obiba.mica.study.domain.StudyState)1 DraftStudyUpdatedEvent (org.obiba.mica.study.event.DraftStudyUpdatedEvent)1