@Test public void testCreateIndividualFatherNotFound() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); thrown.expect(CatalogDBException.class); catalogIndividualDBAdaptor.insert(studyId, new Individual("in1", "in1", new Individual().setId("father").setUid(10), null, null, null, null, null, "", null, null, null, "", Collections.emptyList(), false, 1, Collections.emptyList(), Collections.emptyList(), null), null); }
@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()); }
@Test public void createFamilyPhenotypeNotPassed() throws CatalogException { Phenotype phenotype1 = new Phenotype("dis1", "Phenotype 1", "HPO"); Phenotype phenotype2 = new Phenotype("dis2", "Phenotype 2", "HPO"); Individual father = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual mother = new Individual().setId("mother").setPhenotypes(Arrays.asList(new Phenotype("dis2", "dis2", "OT"))); // 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 relMother = new Individual().setId("mother").setPhenotypes(Arrays.asList(new Phenotype("dis2", "dis2", "OT"))); Individual relChild1 = new Individual().setId("child1") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"), new Phenotype("dis3", "dis3", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Individual relChild2 = new Individual().setId("child2") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Family family = new Family("Martinez-Martinez", "Martinez-Martinez", Arrays.asList(phenotype1, phenotype2), null, Arrays.asList(relFather, relMother, relChild1, relChild2), "", 4, Collections.emptyList(), Collections.emptyMap()); thrown.expect(CatalogException.class); thrown.expectMessage("not present in any member of the family"); familyManager.create(STUDY, family, QueryOptions.empty(), sessionIdUser); }
@Test public void createFamilyRepeatedMember() throws CatalogException { Phenotype phenotype1 = new Phenotype("dis1", "Phenotype 1", "HPO"); Phenotype phenotype2 = new Phenotype("dis2", "Phenotype 2", "HPO"); Individual father = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual mother = new Individual().setId("mother").setPhenotypes(Arrays.asList(new Phenotype("dis2", "dis2", "OT"))); // 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 relMother = new Individual().setId("mother").setPhenotypes(Arrays.asList(new Phenotype("dis2", "dis2", "OT"))); Individual relChild1 = new Individual().setId("child1") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"), new Phenotype("dis2", "dis2", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Individual relChild2 = new Individual().setId("child2") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Family family = new Family("Martinez-Martinez", "Martinez-Martinez", Arrays.asList(phenotype1, phenotype2), null, Arrays.asList(relFather, relMother, relChild1, relChild2, relChild1), "", -1, Collections.emptyList(), Collections.emptyMap ()); QueryResult<Family> familyQueryResult = familyManager.create(STUDY, family, QueryOptions.empty(), sessionIdUser); assertEquals(4, familyQueryResult.first().getMembers().size()); }
@Test public void createFamilyMissingMember() throws CatalogException { Phenotype phenotype1 = new Phenotype("dis1", "Phenotype 1", "HPO"); Phenotype phenotype2 = new Phenotype("dis2", "Phenotype 2", "HPO"); Individual father = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual mother = new Individual().setId("mother").setPhenotypes(Arrays.asList(new Phenotype("dis2", "dis2", "OT"))); // 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("child1") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"), new Phenotype("dis2", "dis2", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Individual relChild2 = new Individual().setId("child2") .setPhenotypes(Collections.singletonList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Family family = new Family("Martinez-Martinez", "Martinez-Martinez", Arrays.asList(phenotype1, phenotype2), null, Arrays.asList(relFather, relChild1, relChild2), "", 3, Collections.emptyList(), Collections.emptyMap()); thrown.expect(CatalogException.class); thrown.expectMessage("not present in the members list"); familyManager.create(STUDY, family, QueryOptions.empty(), sessionIdUser); }
Phenotype phenotype2 = new Phenotype("dis2", "Phenotype 2", "HPO"); Individual father = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual mother = new Individual().setId("mother").setPhenotypes(Arrays.asList(new Phenotype("dis2", "dis2", "OT"))); Individual relFather = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual relMother = new Individual().setId("mother").setPhenotypes(Arrays.asList(new Phenotype("dis2", "dis2", "OT"))); Individual relChild1 = new Individual().setId("child1") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"), new Phenotype("dis2", "dis2", "OT"))) .setFather(father) .setMultiples(new Multiples("multiples", Arrays.asList("child2", "child3"))) .setParentalConsanguinity(true); Individual relChild2 = new Individual().setId("child2") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMultiples(new Multiples("multiples", Arrays.asList("child1", "child3"))) .setParentalConsanguinity(true); Individual relChild3 = new Individual().setId("child3") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father)
Phenotype phenotype2 = new Phenotype("dis2", "Phenotype 2", "HPO"); Individual father = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual mother = new Individual().setId("mother").setPhenotypes(Arrays.asList(new Phenotype("dis2", "dis2", "OT"))); Individual relFather = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual relMother = new Individual().setId("mother").setPhenotypes(Arrays.asList(new Phenotype("dis2", "dis2", "OT"))); Individual relChild1 = new Individual().setId("child1") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"), new Phenotype("dis2", "dis2", "OT"))) .setFather(father) .setMultiples(new Multiples("multiples", Arrays.asList("child2", "child3"))) .setParentalConsanguinity(true); Individual relChild2 = new Individual().setId("child2") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMultiples(new Multiples("multiples", Arrays.asList("child1", "child3"))) .setParentalConsanguinity(true); Individual relChild3 = new Individual().setId("child3") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father)
@Test public void FamilyToSolrTest() { Study study = new Study().setFqn("user@project:study").setAttributes(new HashMap<>()); Family family = new Family("id", "family", null, null, Arrays.asList(new Individual().setId("I1"), new Individual().setId("I2")), "test", 1000, AnnotationHelper.createAnnotation(), null); family.setUid(100).setStatus(new Family.FamilyStatus("READY")).setRelease(1).setVersion(2); FamilySolrModel familySolrModel = new CatalogFamilyToSolrFamilyConverter(study).convertToStorageType(family); assertEquals(familySolrModel.getUid(), family.getUid()); assertEquals(familySolrModel.getStatus(), family.getStatus().getName()); assertEquals(familySolrModel.getNumMembers(), family.getMembers().size()); assertEquals(familySolrModel.getRelease(), family.getRelease()); assertEquals(familySolrModel.getVersion(), family.getVersion()); assertEquals(familySolrModel.getPhenotypes().size(), 0); assertEquals(familySolrModel.getAnnotations().get("annotations__o__annotName.vsId.a.ab2.ab2c1.ab2c1d1"), Arrays.asList(1, 2, 3, 4, 11, 12, 13, 14, 21)); assertEquals(familySolrModel.getAnnotations().get("annotations__o__annotName.vsId.a.ab1.ab1c1"), Arrays.asList(true, false, false)); assertEquals(familySolrModel.getAnnotations().get("annotations__s__annotName.vsId.a.ab1.ab1c2"), "hello world"); assertEquals(familySolrModel.getAnnotations().get("annotations__o__annotName.vsId.a.ab2.ab2c1.ab2c1d2"), Arrays.asList("hello ab2c1d2 1", "hello ab2c1d2 2")); assertEquals(familySolrModel.getAnnotations().get("annotations__o__annotName.vsId.a.ab3.ab3c1.ab3c1d1"), Arrays.asList(Arrays.asList("hello"), Arrays.asList("hello2", "bye2"), Arrays.asList("byeee2", "hellooo2"))); assertEquals(familySolrModel.getAnnotations().get("annotations__o__annotName.vsId.a.ab3.ab3c1.ab3c1d2"), Arrays.asList(2.0, 4.0, 24.0)); assertNull(familySolrModel.getAnnotations().get("nothing")); assertEquals(familySolrModel.getAnnotations().keySet().size(), 6); } }
@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); }
@Test public void testAssignPermissionsWithPropagationWithIndividualAndNoIndividual() throws CatalogException { Sample sample = new Sample().setId("sample").setIndividual(new Individual().setId("individual")); catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), sessionIdUser); Sample sample2 = new Sample().setId("sample2"); catalogManager.getSampleManager().create(studyFqn, sample2, QueryOptions.empty(), sessionIdUser); List<QueryResult<SampleAclEntry>> queryResults = catalogManager.getSampleManager().updateAcl(studyFqn, Arrays.asList("sample", "sample2"), "user2", new Sample.SampleAclParams("VIEW", AclParams.Action.SET, null, null, null, true), sessionIdUser); assertEquals(2, queryResults.size()); assertEquals(1, queryResults.get(0).getNumResults()); assertEquals(1, queryResults.get(0).first().getPermissions().size()); assertTrue(queryResults.get(0).first().getPermissions().contains(SampleAclEntry.SamplePermissions.VIEW)); assertTrue(queryResults.get(1).first().getPermissions().contains(SampleAclEntry.SamplePermissions.VIEW)); List<QueryResult<IndividualAclEntry>> individualAcl = catalogManager.getIndividualManager().getAcls(studyFqn, Collections.singletonList("individual"), "user2", false, sessionIdUser); assertEquals(1, individualAcl.size()); assertEquals(1, individualAcl.get(0).getNumResults()); assertEquals(1, individualAcl.get(0).first().getPermissions().size()); assertTrue(individualAcl.get(0).first().getPermissions().contains(IndividualAclEntry.IndividualPermissions.VIEW)); }
@Test public void testCreateSampleWithIndividual() throws CatalogException { String individualId = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1"), new QueryOptions(), sessionIdUser).first().getId(); String sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample() .setId("SAMPLE_1") .setIndividual(new Individual().setId(individualId)), new QueryOptions(), sessionIdUser).first().getId(); QueryResult<Individual> individualQueryResult = catalogManager.getIndividualManager().get(studyFqn, individualId, QueryOptions.empty(), sessionIdUser); assertEquals(sampleId1, individualQueryResult.first().getSamples().get(0).getId()); // Create sample linking to individual based on the individual name String sampleId2 = catalogManager.getSampleManager().create(studyFqn, new Sample() .setId("SAMPLE_2") .setIndividual(new Individual().setId("Individual1")), new QueryOptions(), sessionIdUser).first().getId(); individualQueryResult = catalogManager.getIndividualManager().get(studyFqn, individualId, QueryOptions.empty(), sessionIdUser); assertEquals(2, individualQueryResult.first().getSamples().size()); assertTrue(individualQueryResult.first().getSamples().stream().map(Sample::getId).collect(Collectors.toSet()).containsAll( Arrays.asList(sampleId1, sampleId2) )); }
private QueryResult<ClinicalAnalysis> createDummyEnvironment(boolean createFamily) throws CatalogException { createDummyFamily(); ClinicalAnalysis clinicalAnalysis = new ClinicalAnalysis() .setId("analysis").setDescription("My description").setType(ClinicalAnalysis.Type.FAMILY) .setDueDate("20180510100000") .setProband(new Individual().setId("child1").setSamples(Arrays.asList(new Sample().setId("sample2")))); if (createFamily) { clinicalAnalysis.setFamily(new Family().setId("family")); } return catalogManager.getClinicalAnalysisManager().create(STUDY, clinicalAnalysis, QueryOptions.empty(), sessionIdUser); }
@Test public void testUpdateIndividuaParents() throws CatalogException { IndividualManager individualManager = catalogManager.getIndividualManager(); individualManager.create(studyFqn, new Individual().setId("child"), QueryOptions.empty(), sessionIdUser); individualManager.create(studyFqn, new Individual().setId("father"), QueryOptions.empty(), sessionIdUser); individualManager.create(studyFqn, new Individual().setId("mother"), QueryOptions.empty(), sessionIdUser); QueryResult<Individual> individualQueryResult = individualManager.update(studyFqn, "child", new ObjectMap() .append(IndividualDBAdaptor.QueryParams.FATHER.key(), new ObjectMap(IndividualDBAdaptor.QueryParams.ID.key(), "father")) .append(IndividualDBAdaptor.QueryParams.MOTHER.key(), new ObjectMap(IndividualDBAdaptor.QueryParams.ID.key(), "mother")), QueryOptions.empty(), sessionIdUser); assertEquals("mother", individualQueryResult.first().getMother().getId()); assertEquals(1, individualQueryResult.first().getMother().getVersion()); assertEquals("father", individualQueryResult.first().getFather().getId()); assertEquals(1, individualQueryResult.first().getFather().getVersion()); }
@Test public void updateSubjectsNoFamilyTest() throws CatalogException { createDummyEnvironment(false); ObjectMap params = new ObjectMap(ClinicalAnalysisDBAdaptor.QueryParams.PROBAND.key(), new Individual().setId("child1").setSamples(Arrays.asList(new Sample().setId("sample2")))); QueryResult<ClinicalAnalysis> updateResult = catalogManager.getClinicalAnalysisManager().update(STUDY, "analysis", params, QueryOptions.empty(), sessionIdUser); assertEquals(1, updateResult.getNumResults()); assertEquals(0, updateResult.first().getInterpretations().size()); assertEquals(catalogManager.getIndividualManager().getUid("child1", STUDY, sessionIdUser).getResource().getUid(), updateResult.first().getProband().getUid()); assertEquals(1, updateResult.first().getProband().getSamples().size()); assertEquals(catalogManager.getSampleManager().getUid("sample2", STUDY, sessionIdUser).getResource().getUid(), updateResult.first().getProband().getSamples().get(0).getUid()); }
@Test public void testModifySample() throws CatalogException { String sampleId1 = catalogManager.getSampleManager() .create(studyFqn, new Sample().setId("SAMPLE_1"), new QueryOptions(), sessionIdUser).first().getId(); String individualId = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1"), new QueryOptions(), sessionIdUser).first().getId(); Sample sample = catalogManager.getSampleManager() .update(studyFqn, sampleId1, new ObjectMap(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), individualId), new QueryOptions("lazy", false), sessionIdUser).first(); assertEquals(individualId, ((Individual) sample.getAttributes().get("individual")).getId()); }
@Test public void searchSamplesByIndividual() throws CatalogException { catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1") .setSamples(Arrays.asList(new Sample().setId("sample1"), new Sample().setId("sample2"))), new QueryOptions(), sessionIdUser); QueryResult<Sample> sampleQueryResult = catalogManager.getSampleManager().search(studyFqn, new Query(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), "Individual1"), QueryOptions.empty(), sessionIdUser); assertEquals(2, sampleQueryResult.getNumResults()); sampleQueryResult = catalogManager.getSampleManager().search(studyFqn, new Query().append(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), "Individual1") .append(SampleDBAdaptor.QueryParams.ID.key(), "sample1"), QueryOptions.empty(), sessionIdUser); assertEquals(1, sampleQueryResult.getNumResults()); catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual2"), new QueryOptions(), sessionIdUser); sampleQueryResult = catalogManager.getSampleManager().search(studyFqn, new Query().append(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), "Individual2"), QueryOptions.empty(), sessionIdUser); assertEquals(0, sampleQueryResult.getNumResults()); }
@Test public void testUpdateIndividualInfo() throws CatalogException { IndividualManager individualManager = catalogManager.getIndividualManager(); QueryResult<Individual> individualQueryResult = individualManager.create(studyFqn, new Individual().setId("Test") .setDateOfBirth("19870214"), QueryOptions.empty(), sessionIdUser); assertEquals(1, individualQueryResult.getNumResults()); assertEquals("Test", individualQueryResult.first().getId()); assertEquals("19870214", individualQueryResult.first().getDateOfBirth()); QueryResult<Individual> update = individualManager.update(studyFqn, individualQueryResult.first().getId(), new ObjectMap(IndividualDBAdaptor.QueryParams.DATE_OF_BIRTH.key() , null), QueryOptions.empty(), sessionIdUser); assertEquals("", update.first().getDateOfBirth()); update = individualManager.update(studyFqn, individualQueryResult.first().getId(), new ObjectMap(IndividualDBAdaptor.QueryParams.DATE_OF_BIRTH.key(), "19870214"), QueryOptions.empty(), sessionIdUser); assertEquals("19870214", update.first().getDateOfBirth()); update = individualManager.update(studyFqn, String.valueOf(individualQueryResult.first().getId()), new ObjectMap(IndividualDBAdaptor.QueryParams.ATTRIBUTES.key(), Collections.singletonMap("key", "value")), QueryOptions.empty(), sessionIdUser); assertEquals("value", update.first().getAttributes().get("key")); update = individualManager.update(studyFqn, String.valueOf(individualQueryResult.first().getId()), new ObjectMap(IndividualDBAdaptor.QueryParams.ATTRIBUTES.key(), Collections.singletonMap("key2", "value2")), QueryOptions.empty(), sessionIdUser); assertEquals("value", update.first().getAttributes().get("key")); // Keep "key" assertEquals("value2", update.first().getAttributes().get("key2")); // add new "key2" // Wrong date of birth format thrown.expect(CatalogException.class); thrown.expectMessage("Invalid date of birth format"); individualManager.update(studyFqn, individualQueryResult.first().getId(), new ObjectMap(IndividualDBAdaptor.QueryParams.DATE_OF_BIRTH.key(), "198421"), QueryOptions.empty(), sessionIdUser); }
@Test public void updateSubjectsAndFamilyTest() throws CatalogException { createDummyEnvironment(false); ObjectMap params = new ObjectMap() .append(ClinicalAnalysisDBAdaptor.QueryParams.PROBAND.key(), new Individual().setId("child1").setSamples(Arrays.asList(new Sample().setId("sample2")))) .append(ClinicalAnalysisDBAdaptor.QueryParams.FAMILY.key(), new Family().setId("family")); QueryResult<ClinicalAnalysis> updateResult = catalogManager.getClinicalAnalysisManager().update(STUDY, "analysis", params, QueryOptions.empty(), sessionIdUser); assertEquals(1, updateResult.getNumResults()); assertEquals(0, updateResult.first().getInterpretations().size()); assertEquals(catalogManager.getFamilyManager().getUid("family", STUDY, sessionIdUser).getResource().getUid(), updateResult.first().getFamily().getUid()); assertEquals(catalogManager.getIndividualManager().getUid("child1", STUDY, sessionIdUser).getResource().getUid(), updateResult.first().getProband().getUid()); assertEquals(1, updateResult.first().getProband().getSamples().size()); assertEquals(catalogManager.getSampleManager().getUid("sample2", STUDY, sessionIdUser).getResource().getUid(), updateResult.first().getProband().getSamples().get(0).getUid()); }
@Test public void testGetSampleAndIndividualWithPermissionsChecked() throws CatalogException { String sampleId1 = catalogManager.getSampleManager() .create(studyFqn, new Sample().setId("SAMPLE_1"), new QueryOptions(), sessionIdUser).first().getId(); String individualId = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1"), new QueryOptions(), sessionIdUser).first().getId(); Sample sample = catalogManager.getSampleManager() .update(studyFqn, sampleId1, new ObjectMap(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), individualId), new QueryOptions("lazy", false), sessionIdUser).first(); assertEquals(individualId, ((Individual) sample.getAttributes().get("individual")).getId()); assertEquals(sampleId1, sample.getId()); catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList("SAMPLE_1"), "user2", new Sample.SampleAclParams(SampleAclEntry.SamplePermissions.VIEW.name(), AclParams.Action.SET, null, null, null), sessionIdUser); sample = catalogManager.getSampleManager().get(studyFqn, "SAMPLE_1", new QueryOptions("lazy", false), sessionIdUser2).first(); assertEquals(null, sample.getAttributes().get("individual")); assertEquals(sampleId1, sample.getId()); catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList("SAMPLE_1"), "user2", new Sample.SampleAclParams(SampleAclEntry.SamplePermissions.VIEW.name(), AclParams.Action.SET, null, null, null, true), sessionIdUser); sample = catalogManager.getSampleManager().get(studyFqn, "SAMPLE_1", new QueryOptions("lazy", false), sessionIdUser2).first(); assertEquals(individualId, ((Individual) sample.getAttributes().get("individual")).getId()); assertEquals(sampleId1, sample.getId()); sample = catalogManager.getSampleManager().get(studyFqn, new Query("individual", "Individual1"), new QueryOptions("lazy", false), sessionIdUser2).first(); assertEquals(individualId, ((Individual) sample.getAttributes().get("individual")).getId()); assertEquals(sampleId1, sample.getId()); }
@Test public void getSampleWithIndividual() throws CatalogDBException { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); QueryOptions queryOptions = new QueryOptions(); // We create a new sample with the individual Sample sample = new Sample().setId("sample1").setStatus(new Status()); QueryResult<Sample> sampleQR = catalogSampleDBAdaptor.insert(studyId, sample, queryOptions); long sampleId = sampleQR.first().getUid(); // We create an individual String individualName = "individualName"; Individual individual = new Individual() .setId(individualName) .setStatus(new Status()) .setSamples(Arrays.asList(new Sample().setUid(sampleId).setVersion(1).setStatus(new Status()))); dbAdaptorFactory.getCatalogIndividualDBAdaptor().insert(studyId, individual, queryOptions); // Get the sample Query query = new Query() .append(SampleDBAdaptor.QueryParams.STUDY_UID.key(), studyId) .append(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), "individualName"); QueryResult<Sample> individualQuery = catalogSampleDBAdaptor.get(query, queryOptions); assertEquals("sample1", individualQuery.first().getId()); query = new Query() .append(SampleDBAdaptor.QueryParams.STUDY_UID.key(), studyId) .append(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), "non-existing"); QueryResult<Sample> inexistentIndividualQuery = catalogSampleDBAdaptor.get(query, queryOptions); assertEquals(0, inexistentIndividualQuery.getNumResults()); }