Search in sources :

Example 1 with Membership

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);
}
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 2 with Membership

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;
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) Membership(org.obiba.mica.core.domain.Membership) HashMap(java.util.HashMap) AbstractGitPersistable(org.obiba.mica.core.domain.AbstractGitPersistable) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) Map(java.util.Map) JSONUtils(org.obiba.mica.JSONUtils) Network(org.obiba.mica.network.domain.Network) Lists(jersey.repackaged.com.google.common.collect.Lists) PublishedDatasetVariableService(org.obiba.mica.study.service.PublishedDatasetVariableService) ImmutableSet(com.google.common.collect.ImmutableSet) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Logger(org.slf4j.Logger) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) NoSuchEntityException(org.obiba.mica.NoSuchEntityException) PublishedStudyService(org.obiba.mica.study.service.PublishedStudyService) List(java.util.List) Component(org.springframework.stereotype.Component) Collectors.toList(java.util.stream.Collectors.toList) Study(org.obiba.mica.study.domain.Study) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) NetworkState(org.obiba.mica.network.domain.NetworkState) NetworkService(org.obiba.mica.network.service.NetworkService) HashMap(java.util.HashMap) Network(org.obiba.mica.network.domain.Network) Membership(org.obiba.mica.core.domain.Membership) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) NotNull(javax.validation.constraints.NotNull)

Example 3 with Membership

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;
}
Also used : HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) HarmonizationStudyService(org.obiba.mica.study.service.HarmonizationStudyService) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Membership(org.obiba.mica.core.domain.Membership) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) HashMap(java.util.HashMap) NotNull(javax.validation.constraints.NotNull) Assert(io.jsonwebtoken.lang.Assert) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) TreeSet(java.util.TreeSet) Inject(javax.inject.Inject) IndividualStudyService(org.obiba.mica.study.service.IndividualStudyService) Strings(com.google.common.base.Strings) List(java.util.List) Component(org.springframework.stereotype.Component) Collectors.toList(java.util.stream.Collectors.toList) Study(org.obiba.mica.study.domain.Study) MicaConfigService(org.obiba.mica.micaConfig.service.MicaConfigService) Map(java.util.Map) JSONUtils(org.obiba.mica.JSONUtils) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) HarmonizedDatasetHelper(org.obiba.mica.dataset.support.HarmonizedDatasetHelper) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Study(org.obiba.mica.study.domain.Study) HarmonizationStudy(org.obiba.mica.study.domain.HarmonizationStudy) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) Membership(org.obiba.mica.core.domain.Membership) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) BaseStudy(org.obiba.mica.study.domain.BaseStudy) NotNull(javax.validation.constraints.NotNull)

Aggregations

Membership (org.obiba.mica.core.domain.Membership)3 Study (org.obiba.mica.study.domain.Study)3 Strings (com.google.common.base.Strings)2 Maps (com.google.common.collect.Maps)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Collectors.toList (java.util.stream.Collectors.toList)2 Inject (javax.inject.Inject)2 NotNull (javax.validation.constraints.NotNull)2 JSONUtils (org.obiba.mica.JSONUtils)2 MicaConfigService (org.obiba.mica.micaConfig.service.MicaConfigService)2 BaseStudy (org.obiba.mica.study.domain.BaseStudy)2 HarmonizationStudy (org.obiba.mica.study.domain.HarmonizationStudy)2 Component (org.springframework.stereotype.Component)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Sets (com.google.common.collect.Sets)1 Assert (io.jsonwebtoken.lang.Assert)1