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);
}
}
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);
}
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));
});
});
}
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;
}
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);
}
Aggregations