Search in sources :

Example 1 with StudyPublishedEvent

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

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

the class AbstractStudyService method removeRoles.

protected void removeRoles(@NotNull T study, Iterable<String> roles) {
    saveInternal(study, String.format("Removed roles: %s", Joiner.on(", ").join(roles)), false);
    S state = findStateById(study.getId());
    if (state.isPublished()) {
        publishState(study.getId());
        eventBus.post(new StudyPublishedEvent(study, getCurrentUsername(), PublishCascadingScope.NONE));
    }
}
Also used : StudyPublishedEvent(org.obiba.mica.study.event.StudyPublishedEvent)

Example 3 with StudyPublishedEvent

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

the class AbstractStudyService method publish.

@Caching(evict = { @CacheEvict(value = "aggregations-metadata", allEntries = true), @CacheEvict(value = { "studies-draft", "studies-published" }, key = "#id") })
public void publish(@NotNull String id, boolean publish, PublishCascadingScope cascadingScope) throws NoSuchEntityException {
    log.info("Publish study: {}", id);
    T study = getRepository().findOne(id);
    if (publish) {
        publishState(id);
        eventBus.post(new StudyPublishedEvent(study, getCurrentUsername(), cascadingScope));
    } else {
        unPublishState(id);
        eventBus.post(new StudyUnpublishedEvent(study));
    }
}
Also used : StudyPublishedEvent(org.obiba.mica.study.event.StudyPublishedEvent) StudyUnpublishedEvent(org.obiba.mica.study.event.StudyUnpublishedEvent) Caching(org.springframework.cache.annotation.Caching)

Aggregations

StudyPublishedEvent (org.obiba.mica.study.event.StudyPublishedEvent)3 PersonUpdatedEvent (org.obiba.mica.contact.event.PersonUpdatedEvent)1 StudyState (org.obiba.mica.study.domain.StudyState)1 DraftStudyUpdatedEvent (org.obiba.mica.study.event.DraftStudyUpdatedEvent)1 StudyUnpublishedEvent (org.obiba.mica.study.event.StudyUnpublishedEvent)1 Caching (org.springframework.cache.annotation.Caching)1