QueryResult<Sample> insert(long studyId, Sample sample, List<VariableSet> variableSetList, QueryOptions options) throws CatalogDBException;
@Before public void before() throws IOException, CatalogException { MongoDBAdaptorTest dbAdaptorTest = new MongoDBAdaptorTest(); dbAdaptorTest.before(); user1 = MongoDBAdaptorTest.user1; user2 = MongoDBAdaptorTest.user2; user3 = MongoDBAdaptorTest.user3; user4 = MongoDBAdaptorTest.user4; dbAdaptorFactory = MongoDBAdaptorTest.catalogDBAdaptor; catalogSampleDBAdaptor = dbAdaptorFactory.getCatalogSampleDBAdaptor(); studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); s1 = catalogSampleDBAdaptor.insert(studyId, new Sample("s1", "", new Individual(), null, null, 1, 1, "", "", false, Collections.emptyList(), new ArrayList<>(), Collections.emptyMap()), null).first(); s2 = catalogSampleDBAdaptor.insert(studyId, new Sample("s2", "", new Individual(), null, null, 1, 1, "", "", false, Collections.emptyList(), new ArrayList<>(), Collections.emptyMap()), null).first(); }
@Before public void before() throws IOException, CatalogException { MongoDBAdaptorTest dbAdaptorTest = new MongoDBAdaptorTest(); dbAdaptorTest.before(); Configuration configuration = Configuration.load(getClass().getResource("/configuration-test.yml").openStream()); user1 = MongoDBAdaptorTest.user1; user2 = MongoDBAdaptorTest.user2; user3 = MongoDBAdaptorTest.user3; dbAdaptorFactory = MongoDBAdaptorTest.catalogDBAdaptor; aclDBAdaptor = new AuthorizationMongoDBAdaptor(configuration); studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); s1 = dbAdaptorFactory.getCatalogSampleDBAdaptor().insert(studyId, new Sample("s1", "", new Individual(), null, null, 1, 1, "", "", false, Collections.emptyList(), new ArrayList<>(), Collections.emptyMap()), QueryOptions.empty()).first(); acl_s1_user1 = new SampleAclEntry(user1.getId(), Arrays.asList()); acl_s1_user2 = new SampleAclEntry(user2.getId(), Arrays.asList( SampleAclEntry.SamplePermissions.VIEW.name(), SampleAclEntry.SamplePermissions.VIEW_ANNOTATIONS.name(), SampleAclEntry.SamplePermissions.UPDATE.name() )); aclDBAdaptor.setAcls(Arrays.asList(s1.getUid()), Arrays.asList(acl_s1_user1, acl_s1_user2), Entity.SAMPLE); }
@Test public void testPermissionRulesPlusManualPermissions() throws CatalogException { // We create a new sample s2 Sample s2 = dbAdaptorFactory.getCatalogSampleDBAdaptor().insert(studyId, new Sample("s2", "", new Individual(), null, null, 1, 1, "", "", false, Collections.emptyList(), new ArrayList<>(), Collections.emptyMap()), QueryOptions.empty()).first(); // We create a new permission rule PermissionRule pr = new PermissionRule("myPermissionRule", new Query(), Arrays.asList(user3.getId()), Arrays.asList(SampleAclEntry.SamplePermissions.VIEW.name())); dbAdaptorFactory.getCatalogStudyDBAdaptor().createPermissionRule(studyId, Study.Entity.SAMPLES, pr); // Apply the permission rule aclDBAdaptor.applyPermissionRules(studyId, pr, Study.Entity.SAMPLES); // All the samples should have view permissions for user user2 List<QueryResult<AbstractAclEntry>> queryResults = aclDBAdaptor.get(Arrays.asList(s1.getUid(), s2.getUid()), Arrays.asList(user3.getId()), Entity.SAMPLE); for (QueryResult<AbstractAclEntry> queryResult : queryResults) { assertEquals(1, queryResult.first().getPermissions().size()); assertTrue(queryResult.first().getPermissions().contains(SampleAclEntry.SamplePermissions.VIEW)); } // Assign a manual permission to s2 aclDBAdaptor.addToMembers(Arrays.asList(s2.getUid()), Arrays.asList(user3.getId()), Arrays.asList(SampleAclEntry.SamplePermissions.DELETE.name()), Entity.SAMPLE); }
@Test @Ignore // TODO: This should be tested in the sample manager, not here !!! public void deleteSampleFail3Test() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); Sample hg0097 = new Sample("HG0097", "1000g", new Individual(), "A description", 1); QueryResult<Sample> createResult = dbAdaptorFactory.getCatalogSampleDBAdaptor().insert(studyId, hg0097, null); dbAdaptorFactory.getCatalogCohortDBAdaptor().insert(studyId, new Cohort("Cohort", Study.Type.COLLECTION, "", "", Collections.singletonList(createResult.first()), 1, null), null); thrown.expect(CatalogDBException.class); dbAdaptorFactory.getCatalogSampleDBAdaptor().delete(createResult.first().getUid()); }
@Test @Ignore public void deleteSampleFail2Test() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); long fileId = dbAdaptorFactory.getCatalogFileDBAdaptor().getId(user3.getProjects().get(0).getStudies().get(0).getUid(), "data/file.vcf"); Sample hg0097 = new Sample("HG0097", "1000g", new Individual(), "A description", 1); QueryResult<Sample> createResult = dbAdaptorFactory.getCatalogSampleDBAdaptor().insert(studyId, hg0097, null); dbAdaptorFactory.getCatalogFileDBAdaptor().update(fileId, new ObjectMap(FileDBAdaptor.QueryParams.SAMPLES.key(), createResult.first().getUid()), QueryOptions.empty()); dbAdaptorFactory.getCatalogSampleDBAdaptor().delete(createResult.first().getUid()); }
@Test public void deleteSampleTest() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); Sample hg0097 = new Sample("HG0097", "1000g", new Individual(), "A description", 1); QueryResult<Sample> createResult = dbAdaptorFactory.getCatalogSampleDBAdaptor().insert(studyId, hg0097, null); dbAdaptorFactory.getCatalogSampleDBAdaptor().delete(createResult.first().getUid()); thrown.expect(CatalogDBException.class); thrown.expectMessage("does not exist"); catalogSampleDBAdaptor.get(createResult.first().getUid(), QueryOptions.empty()); }
@Test public void createSampleTest() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); Sample hg0097 = new Sample("HG0097", "1000g", new Individual(), "A description", 1); QueryResult<Sample> result = dbAdaptorFactory.getCatalogSampleDBAdaptor().insert(studyId, hg0097, null); assertEquals(hg0097.getId(), result.first().getId()); assertEquals(hg0097.getDescription(), result.first().getDescription()); assertTrue(result.first().getUid() > 0); }
QueryResult<Sample> queryResult = sampleDBAdaptor.insert(study.getUid(), sample, variableSetList, options); auditManager.recordCreation(AuditRecord.Resource.sample, queryResult.first().getUid(), userId, queryResult.first(), null, null);
@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()); }