Search in sources :

Example 1 with DraftStudyUpdatedEvent

use of org.obiba.mica.study.event.DraftStudyUpdatedEvent in project mica2 by obiba.

the class ContactsRefactorUpgrade method execute.

@Override
public void execute(Version version) {
    log.info("Executing contacts upgrade");
    studyRepository.findAll().forEach(study -> {
        study.getAllPersons().forEach(p -> p.setEmail(Strings.emptyToNull(p.getEmail())));
        StudyState studyState = individualStudyService.findStateById(study.getId());
        studyRepository.saveWithReferences(study);
        eventBus.post(new DraftStudyUpdatedEvent(study));
        study.getAllPersons().forEach(c -> eventBus.post(new PersonUpdatedEvent(c)));
        if (studyState.isPublished()) {
            eventBus.post(new StudyPublishedEvent(study, studyState.getPublishedBy(), PublishCascadingScope.ALL));
        }
    });
    networkRepository.findAll().forEach(network -> {
        network.getAllPersons().forEach(p -> p.setEmail(Strings.emptyToNull(p.getEmail())));
        networkService.save(network, "System upgrade.");
        if (network.isPublished()) {
            networkService.publish(network.getId(), true);
        }
    });
}
Also used : PersonUpdatedEvent(org.obiba.mica.contact.event.PersonUpdatedEvent) DraftStudyUpdatedEvent(org.obiba.mica.study.event.DraftStudyUpdatedEvent) StudyState(org.obiba.mica.study.domain.StudyState) StudyPublishedEvent(org.obiba.mica.study.event.StudyPublishedEvent)

Example 2 with DraftStudyUpdatedEvent

use of org.obiba.mica.study.event.DraftStudyUpdatedEvent 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 3 with DraftStudyUpdatedEvent

use of org.obiba.mica.study.event.DraftStudyUpdatedEvent 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)

Aggregations

DraftStudyUpdatedEvent (org.obiba.mica.study.event.DraftStudyUpdatedEvent)3 MissingCommentException (org.obiba.mica.core.service.MissingCommentException)2 StudyState (org.obiba.mica.study.domain.StudyState)2 PersonUpdatedEvent (org.obiba.mica.contact.event.PersonUpdatedEvent)1 HarmonizationStudyState (org.obiba.mica.study.domain.HarmonizationStudyState)1 StudyPublishedEvent (org.obiba.mica.study.event.StudyPublishedEvent)1