Search in sources :

Example 1 with PersonUpdatedEvent

use of org.obiba.mica.contact.event.PersonUpdatedEvent 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 PersonUpdatedEvent

use of org.obiba.mica.contact.event.PersonUpdatedEvent in project mica2 by obiba.

the class PersonService method micaConfigUpdated.

@Async
@Subscribe
public void micaConfigUpdated(MicaConfigUpdatedEvent event) {
    event.getRemovedRoles().forEach(r -> {
        log.info("Removing role {} from Persons.", r);
        Set<Person> persons = Sets.newHashSet(personRepository.findByStudyMembershipsRole(r));
        persons.addAll(personRepository.findByNetworkMembershipsRole(r));
        persons.forEach(p -> {
            p.removeAllMemberships(r);
            personRepository.save(p);
            eventBus.post(new PersonUpdatedEvent(p));
        });
    });
}
Also used : PersonUpdatedEvent(org.obiba.mica.contact.event.PersonUpdatedEvent) Person(org.obiba.mica.core.domain.Person) Async(org.springframework.scheduling.annotation.Async) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

PersonUpdatedEvent (org.obiba.mica.contact.event.PersonUpdatedEvent)2 Subscribe (com.google.common.eventbus.Subscribe)1 Person (org.obiba.mica.core.domain.Person)1 StudyState (org.obiba.mica.study.domain.StudyState)1 DraftStudyUpdatedEvent (org.obiba.mica.study.event.DraftStudyUpdatedEvent)1 StudyPublishedEvent (org.obiba.mica.study.event.StudyPublishedEvent)1 Async (org.springframework.scheduling.annotation.Async)1