use of org.obiba.mica.core.domain.Membership 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.Membership in project mica2 by obiba.
the class NetworkDtos method fromDto.
@NotNull
Network fromDto(@NotNull Mica.NetworkDtoOrBuilder dto) {
Network network = new Network();
if (dto.hasId()) {
network.setId(dto.getId());
}
network.setName(localizedStringDtos.fromDto(dto.getNameList()));
network.setDescription(localizedStringDtos.fromDto(dto.getDescriptionList()));
network.setAcronym(localizedStringDtos.fromDto(dto.getAcronymList()));
if (dto.getMembershipsCount() > 0) {
Map<String, List<Membership>> memberships = Maps.newHashMap();
dto.getMembershipsList().forEach(e -> memberships.put(e.getRole(), e.getMembersList().stream().map(p -> new Membership(personDtos.fromDto(p), e.getRole())).collect(toList())));
network.setMemberships(memberships);
}
if (dto.getStudyIdsCount() > 0) {
dto.getStudyIdsList().forEach(network::addStudyId);
}
if (dto.getAttachmentsCount() > 0) {
dto.getAttachmentsList().stream().filter(Mica.AttachmentDto::getJustUploaded).findFirst().ifPresent(a -> network.setLogo(attachmentDtos.fromDto(a)));
}
if (dto.hasLogo()) {
network.setLogo(attachmentDtos.fromDto(dto.getLogo()));
}
if (dto.getNetworkIdsCount() > 0) {
network.setNetworkIds(Lists.newArrayList(Sets.newHashSet(dto.getNetworkIdsList())));
}
if (dto.hasContent() && !Strings.isNullOrEmpty(dto.getContent()))
network.setModel(JSONUtils.toMap(dto.getContent()));
else
network.setModel(new HashMap<>());
return network;
}
use of org.obiba.mica.core.domain.Membership in project mica2 by obiba.
the class StudyDtos method fromDto.
@NotNull
BaseStudy fromDto(@NotNull Mica.StudyDtoOrBuilder dto) {
Assert.isTrue(dto.hasExtension(Mica.CollectionStudyDto.type) || dto.hasExtension(Mica.HarmonizationStudyDto.type), "StudyDto must of a type extension.");
BaseStudy study = dto.hasExtension(Mica.CollectionStudyDto.type) ? new Study() : new HarmonizationStudy();
if (dto.hasId())
study.setId(dto.getId());
if (dto.getNameCount() > 0)
study.setName(localizedStringDtos.fromDto(dto.getNameList()));
if (dto.getAcronymCount() > 0)
study.setAcronym(localizedStringDtos.fromDto(dto.getAcronymList()));
if (dto.hasLogo())
study.setLogo(attachmentDtos.fromDto(dto.getLogo()));
if (dto.hasTimestamps())
TimestampsDtos.fromDto(dto.getTimestamps(), study);
if (dto.getObjectivesCount() > 0)
study.setObjectives(localizedStringDtos.fromDto(dto.getObjectivesList()));
if (dto.hasOpal())
study.setOpal(dto.getOpal());
if (dto.getMembershipsCount() > 0) {
Map<String, List<Membership>> memberships = Maps.newHashMap();
dto.getMembershipsList().forEach(e -> memberships.put(e.getRole(), e.getMembersList().stream().map(p -> new Membership(personDtos.fromDto(p), e.getRole())).collect(toList())));
study.setMemberships(memberships);
}
if (dto.getPopulationsCount() > 0) {
study.setPopulations(dto.getPopulationsList().stream().map(populationDtos::fromDto).collect(Collectors.toCollection(TreeSet<org.obiba.mica.study.domain.Population>::new)));
}
if (dto.hasContent() && !Strings.isNullOrEmpty(dto.getContent()))
study.setModel(JSONUtils.toMap(dto.getContent()));
else
study.setModel(new HashMap<>());
return study;
}
Aggregations