Search in sources :

Example 1 with Person

use of org.obiba.mica.core.domain.Person in project mica2 by obiba.

the class Mica2Upgrade method migrateIso2ToIso3.

private void migrateIso2ToIso3() {
    for (Person person : personRepository.findAllWhenCountryIsoContainsTwoCharacters()) {
        String countryIso2 = person.getInstitution().getAddress().getCountryIso();
        countryIso2 = cleanIso2Standart(countryIso2);
        String countryIso3 = new Locale("", countryIso2).getISO3Country();
        person.getInstitution().getAddress().setCountryIso(countryIso3);
        personRepository.save(person);
    }
}
Also used : Locale(java.util.Locale) Person(org.obiba.mica.core.domain.Person)

Example 2 with Person

use of org.obiba.mica.core.domain.Person in project mica2 by obiba.

the class IndividualStudyServiceTest method testCreateStudyWithContacts.

@Test
public void testCreateStudyWithContacts() throws Exception {
    Study study = new Study();
    study.setId("test");
    Person person = new Person();
    person.setEmail("test@test.com");
    List<Person> persons = Lists.newArrayList();
    persons.add(person);
    study.getMemberships().get(Membership.CONTACT).addAll(persons.stream().map(e -> new Membership(e, "contact")).collect(Collectors.toList()));
    individualStudyService.save(study);
    Study retrievedStudy = individualStudyService.findDraft(study.getId());
    List<Person> retrievedPersons = retrievedStudy.getMemberships().get(Membership.CONTACT).stream().map(Membership::getPerson).collect(Collectors.toList());
    assertThat(retrievedPersons).contains(person);
}
Also used : Study(org.obiba.mica.study.domain.Study) Membership(org.obiba.mica.core.domain.Membership) Person(org.obiba.mica.core.domain.Person) Test(org.junit.Test)

Example 3 with Person

use of org.obiba.mica.core.domain.Person 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)

Example 4 with Person

use of org.obiba.mica.core.domain.Person in project mica2 by obiba.

the class PersonDtos method fromDto.

Person fromDto(Mica.PersonDtoOrBuilder dto) {
    Person person = new Person();
    if (dto.hasId())
        person.setId(dto.getId());
    if (dto.hasTitle())
        person.setTitle(dto.getTitle());
    if (dto.hasFirstName())
        person.setFirstName(dto.getFirstName());
    person.setLastName(dto.getLastName());
    if (dto.hasAcademicLevel())
        person.setAcademicLevel(dto.getAcademicLevel());
    if (dto.hasEmail())
        person.setEmail(dto.getEmail());
    if (dto.hasPhone())
        person.setPhone(dto.getPhone());
    if (dto.hasInstitution())
        person.setInstitution(fromDto(dto.getInstitution()));
    if (dto.getNetworkMembershipsCount() > 0) {
        person.setNetworkMemberships(dto.getNetworkMembershipsList().stream().map(this::fromDto).collect(toList()));
    }
    if (dto.getStudyMembershipsCount() > 0) {
        person.setStudyMemberships(dto.getStudyMembershipsList().stream().map(this::fromDto).collect(toList()));
    }
    return person;
}
Also used : Person(org.obiba.mica.core.domain.Person)

Example 5 with Person

use of org.obiba.mica.core.domain.Person in project mica2 by obiba.

the class PersonIndexer method reIndexContacts.

@Async
@Subscribe
public void reIndexContacts(IndexContactsEvent event) {
    log.info("Reindexing all persons");
    if (indexer.hasIndex(Indexer.PERSON_INDEX))
        indexer.dropIndex(Indexer.PERSON_INDEX);
    Pageable pageRequest = new PageRequest(0, 100);
    Page<Person> persons;
    do {
        persons = personRepository.findAll(pageRequest);
        indexer.indexAll(Indexer.PERSON_INDEX, persons);
    } while ((pageRequest = persons.nextPageable()) != null);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) Person(org.obiba.mica.core.domain.Person) Async(org.springframework.scheduling.annotation.Async) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

Person (org.obiba.mica.core.domain.Person)5 Subscribe (com.google.common.eventbus.Subscribe)2 Async (org.springframework.scheduling.annotation.Async)2 Locale (java.util.Locale)1 Test (org.junit.Test)1 PersonUpdatedEvent (org.obiba.mica.contact.event.PersonUpdatedEvent)1 Membership (org.obiba.mica.core.domain.Membership)1 Study (org.obiba.mica.study.domain.Study)1 PageRequest (org.springframework.data.domain.PageRequest)1 Pageable (org.springframework.data.domain.Pageable)1