family.setMembers(memberMap.entrySet().stream().map(Map.Entry::getValue).collect(Collectors.toList()));
finalFamily.setMembers(finalMembers); } else { finalFamily.setMembers(Collections.emptyList());
@Test public void createFamilyDuo() throws CatalogException { Family family = new Family() .setId("test") .setPhenotypes(Arrays.asList(new Phenotype("E00", "blabla", "blabla"))) .setMembers(Arrays.asList(new Individual().setId("proband").setSex(IndividualProperty.Sex.MALE), new Individual().setFather(new Individual().setId("proband")).setId("child") .setSex(IndividualProperty.Sex.FEMALE))); QueryResult<Family> familyQueryResult = familyManager.create(STUDY, family, QueryOptions.empty(), sessionIdUser); assertEquals(2, familyQueryResult.first().getMembers().size()); }
public QueryResult<Family> create(String studyStr, Family family, QueryOptions options, String sessionId) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(sessionId); Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); authorizationManager.checkStudyPermission(study.getUid(), userId, StudyAclEntry.StudyPermissions.WRITE_FAMILIES); ParamUtils.checkObj(family, "family"); ParamUtils.checkAlias(family.getId(), "id"); family.setName(ParamUtils.defaultObject(family.getName(), family.getId())); family.setMembers(ParamUtils.defaultObject(family.getMembers(), Collections.emptyList())); family.setPhenotypes(ParamUtils.defaultObject(family.getPhenotypes(), Collections.emptyList())); family.setDisorders(ParamUtils.defaultObject(family.getDisorders(), Collections.emptyList())); family.setCreationDate(TimeUtils.getTime()); family.setDescription(ParamUtils.defaultString(family.getDescription(), "")); family.setStatus(new Family.FamilyStatus()); family.setAnnotationSets(ParamUtils.defaultObject(family.getAnnotationSets(), Collections.emptyList())); family.setRelease(catalogManager.getStudyManager().getCurrentRelease(study, userId)); family.setVersion(1); family.setAttributes(ParamUtils.defaultObject(family.getAttributes(), Collections.emptyMap())); List<VariableSet> variableSetList = validateNewAnnotationSetsAndExtractVariableSets(study.getUid(), family.getAnnotationSets()); autoCompleteFamilyMembers(family, study, sessionId); validateFamily(family); validateMultiples(family); validatePhenotypes(family); validateDisorders(family); createMissingMembers(family, study, sessionId); options = ParamUtils.defaultObject(options, QueryOptions::new); family.setUuid(UUIDUtils.generateOpenCGAUUID(UUIDUtils.Entity.FAMILY)); QueryResult<Family> queryResult = familyDBAdaptor.insert(study.getUid(), family, variableSetList, options); auditManager.recordCreation(AuditRecord.Resource.family, queryResult.first().getId(), userId, queryResult.first(), null, null); return queryResult; }
@Test public void updateFamilyMissingMember() throws CatalogException, JsonProcessingException { QueryResult<Family> originalFamily = createDummyFamily("Martinez-Martinez"); Individual father = new Individual().setId("father"); Individual mother = new Individual().setId("mother2"); // We create a new father and mother with the same information to mimic the behaviour of the webservices. Otherwise, we would be // ingesting references to exactly the same object and this test would not work exactly the same way. Individual relFather = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual relChild1 = new Individual().setId("child3") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"), new Phenotype("dis2", "dis2", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Family family = new Family(); family.setMembers(Arrays.asList(relChild1, relFather)); ObjectMapper jsonObjectMapper = catalogManagerResource.generateNewObjectMapper(); ObjectMap params = new ObjectMap(jsonObjectMapper.writeValueAsString(family)); params = new ObjectMap(FamilyDBAdaptor.QueryParams.MEMBERS.key(), params.get(FamilyDBAdaptor.QueryParams.MEMBERS.key())); thrown.expect(CatalogException.class); thrown.expectMessage("not present in the members list"); familyManager.update(STUDY, originalFamily.first().getName(), params, QueryOptions.empty(), sessionIdUser); }
family.setMembers(familyQueryResult.first().getMembers()); } else {