@Deprecated public QueryResult<Sample> create(String studyStr, String name, String source, String description, String type, boolean somatic, Individual individual, Map<String, Object> stats, Map<String, Object> attributes, QueryOptions options, String sessionId) throws CatalogException { Sample sample = new Sample(name, source, individual, null, null, -1, 1, description, type, somatic, Collections.emptyList(), Collections.emptyList(), attributes).setStats(stats); return create(studyStr, sample, options, sessionId); }
@Deprecated public QueryResult<Sample> get(Long sampleId, QueryOptions options, String sessionId) throws CatalogException { return get(null, String.valueOf(sampleId), options, sessionId); }
@Deprecated public QueryResult<Sample> update(Long sampleId, ObjectMap parameters, QueryOptions options, String sessionId) throws CatalogException { return update(null, String.valueOf(sampleId), parameters, options, sessionId); }
@Test public void readSampleForbiddenForExternalUser() throws CatalogException { catalogManager.getSampleManager().updateAcl(String.valueOf(studyFqn), Arrays.asList(smp2.getId()), externalUser, new Sample.SampleAclParams("", AclParams.Action.SET, null, null, null), ownerSessionId); thrown.expect(CatalogAuthorizationException.class); catalogManager.getSampleManager().get(studyFqn, smp2.getId(), null, externalSessionId); }
MyResources<Sample> resource = getUids(sampleList, studyStr, sessionId); authorizationManager.checkCanAssignOrSeePermissions(resource.getStudy().getUid(), resource.getUser()); checkMembers(resource.getStudy().getUid(), members);
@Test public void testUpdateAnnotationFail() throws CatalogException { Sample sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, sessionIdUser).first(); AnnotationSet annotationSet = sample.getAnnotationSets().get(0); thrown.expect(CatalogException.class); //Can not delete required fields thrown.expectMessage("required variable"); catalogManager.getSampleManager().removeAnnotations(studyFqn, s_1, annotationSet.getId(), Collections.singletonList("NAME"), QueryOptions.empty(), sessionIdUser); }
for (Sample sample : catalogManager.getSampleManager().get(study.getFqn(), samplesQuery, null, sessionId).getResult()) { loadedSamples.put(sample.getId(), sample); logger.info("Sample " + individual.getId() + " already loaded with id : " + sample.getId()); } else { QueryResult<Sample> sampleQueryResult = catalogManager.getSampleManager().create(study.getFqn(), new Sample() .setId(individual.getId()) Map<String, Object> annotations = getAnnotation(ped.getIndividuals().get(entry.getKey()), sampleMap, variableSet, ped .getFields()); catalogManager.getSampleManager().update(study.getFqn(), entry.getValue().getId(), new ObjectMap() .append(SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Collections.singletonList(new ObjectMap() .append(AnnotationSetManager.ID, "pedigreeAnnotation") QueryResult<Sample> sampleQueryResult = catalogManager.getSampleManager().get(study.getFqn(), new Query(SampleDBAdaptor.QueryParams.ANNOTATION.key(), Constants.VARIABLE_SET + "=" + variableSetId), null, sessionId); return new QueryResult<>("loadPedigree", (int) (System.currentTimeMillis() - startTime),
@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 testModifySampleBadIndividual() throws CatalogException { String sampleId1 = catalogManager.getSampleManager().create(studyFqn, "SAMPLE_1", "", "", null, false, null, new HashMap<>(), null, new QueryOptions(), sessionIdUser).first().getId(); thrown.expect(CatalogException.class); thrown.expectMessage("not found"); catalogManager.getSampleManager() .update(studyFqn, sampleId1, new ObjectMap(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), "ind"), null, sessionIdUser); }
@Test public void testDeleteSample() throws CatalogException { long sampleUid = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), new QueryOptions(), sessionIdUser).first().getUid(); Query query = new Query(SampleDBAdaptor.QueryParams.ID.key(), "SAMPLE_1"); WriteResult delete = catalogManager.getSampleManager().delete("1000G:phase1", query, null, sessionIdUser); assertEquals(1, delete.getNumModified()); query = new Query() .append(SampleDBAdaptor.QueryParams.UID.key(), sampleUid) .append(SampleDBAdaptor.QueryParams.STATUS_NAME.key(), Status.DELETED); QueryResult<Sample> sampleQueryResult = catalogManager.getSampleManager().get("1000G:phase1", query, new QueryOptions(), sessionIdUser); // QueryResult<Sample> sample = catalogManager.getSample(sampleId, new QueryOptions(), sessionIdUser); assertEquals(1, sampleQueryResult.getNumResults()); assertTrue(sampleQueryResult.first().getId().contains("DELETED")); }
sampleList = catalogManager.getSampleManager().get(study.getFqn(), sampleQuery, sampleQueryOptions, sessionId).getResult(); } else { try { sampleList.add(catalogManager.getSampleManager().create(study.getFqn(), new Sample().setId(sampleName) .setSource(file.getName()), null, sessionId).first()); } catch (CatalogException e) { Query query = new Query(SampleDBAdaptor.QueryParams.ID.key(), sampleName); QueryOptions queryOptions = new QueryOptions(QueryOptions.INCLUDE, includeSampleNameId); if (catalogManager.getSampleManager().get(study.getFqn(), query, queryOptions, sessionId).getResult() .isEmpty()) { throw e; //Throw exception if sample does not exist. sampleList = catalogManager.getSampleManager().get(study.getFqn(), query, new QueryOptions(), sessionId).getResult();
@Test public void testAssignPermissionsWithPropagationAndNoIndividual() throws CatalogException { Sample sample = new Sample().setId("sample"); catalogManager.getSampleManager().create(studyFqn, sample, QueryOptions.empty(), sessionIdUser); List<QueryResult<SampleAclEntry>> queryResults = catalogManager.getSampleManager().updateAcl(studyFqn, Arrays.asList("sample"), "user2", new Sample.SampleAclParams("VIEW", AclParams.Action.SET, null, null, null, true), sessionIdUser); assertEquals(1, 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)); }
new File.FileAclParams(ALL_FILE_PERMISSIONS, AclParams.Action.SET, null), ownerSessionId); smp1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("smp1"), QueryOptions.empty(), ownerSessionId).first(); smp2 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("smp2"), QueryOptions.empty(), ownerSessionId).first(); smp3 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("smp3"), QueryOptions.empty(), ownerSessionId).first(); smp4 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("smp4"), QueryOptions.empty(), ownerSessionId).first(); smp5 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("smp5"), QueryOptions.empty(), ownerSessionId).first(); smp6 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("smp6"), QueryOptions.empty(), ownerSessionId).first(); catalogManager.getIndividualManager().create(studyFqn, new Individual().setId(ind2), QueryOptions.empty(), ownerSessionId); catalogManager.getSampleManager().update(studyFqn, smp1.getId(), new ObjectMap(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), ind1), QueryOptions.empty(), ownerSessionId); catalogManager.getSampleManager().update(studyFqn, smp2.getId(), new ObjectMap(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), ind2), QueryOptions.empty(), ownerSessionId); catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList(smp1.getId()), externalUser, allSamplePermissions, ownerSessionId); catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList(smp3.getId()), externalUser, noSamplePermissions, ownerSessionId); catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList(smp2.getId()), "*", noSamplePermissions, ownerSessionId); catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList(smp5.getId()), externalUser, noSamplePermissions, ownerSessionId); catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList(smp6.getId()), "@members", allSamplePermissions, ownerSessionId);
@Test public void testDeleteAnnotation() throws CatalogException { // We add one of the non mandatory annotations // First update catalogManager.getSampleManager().updateAnnotations(studyFqn, s_1, "annot1", new ObjectMap("EXTRA", "extra"), ParamUtils.CompleteUpdateAction.ADD, QueryOptions.empty(), sessionIdUser); Sample sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, sessionIdUser).first(); AnnotationSet annotationSet = sample.getAnnotationSets().get(0); assertEquals("extra", annotationSet.getAnnotations().get("EXTRA")); // Now we remove that non mandatory annotation catalogManager.getSampleManager().removeAnnotations(studyFqn, s_1, annotationSet.getId(), Collections.singletonList("EXTRA"), QueryOptions.empty(), sessionIdUser); sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, sessionIdUser).first(); annotationSet = sample.getAnnotationSets().get(0); assertTrue(!annotationSet.getAnnotations().containsKey("EXTRA")); // Now we attempt to remove one mandatory annotation thrown.expect(CatalogException.class); //Can not delete required fields thrown.expectMessage("required variable"); catalogManager.getSampleManager().removeAnnotations(studyFqn, s_1, annotationSet.getId(), Collections.singletonList("AGE"), QueryOptions.empty(), sessionIdUser); }
annotations.put("HEIGHT", 180); catalogManager.getSampleManager().update(studyFqn, s_1, new ObjectMap() .append(IndividualDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Collections.singletonList(new ObjectMap() .append(AnnotationSetManager.ID, "annotation1") QueryOptions.empty(), sessionIdUser); QueryResult<Sample> sampleQueryResult = catalogManager.getSampleManager().get(studyFqn, s_1, new QueryOptions(QueryOptions.INCLUDE, Constants.ANNOTATION_SET_NAME + ".annotation1"), sessionIdUser); assertEquals(1, sampleQueryResult.getNumResults());
for (Sample sample : individual.getSamples()) { try { MyResource<Sample> resource = catalogManager.getSampleManager().getUid(sample.getId(), studyStr, sessionId); existingSampleIds.add(resource.getResource().getUid()); } catch (CatalogException e) { QueryResult<Sample> sampleQueryResult = catalogManager.getSampleManager().create(studyStr, sample, QueryOptions.empty(), sessionId); if (sampleQueryResult.getNumResults() == 0) {
@Test public void testUpdateAnnotation() throws CatalogException { Sample sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, sessionIdUser).first(); AnnotationSet annotationSet = sample.getAnnotationSets().get(0); annotationSet.getAnnotations(), ParamUtils.CompleteUpdateAction.SET, new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser); catalogManager.getSampleManager().updateAnnotations(studyFqn, s_1, annotationSet.getId(), annotationSet.getAnnotations(), ParamUtils.CompleteUpdateAction.SET, new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser); sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, sessionIdUser).first(); ind = catalogManager.getIndividualManager().get(studyFqn, ind.getId(), null, sessionIdUser).first(); check.accept(sample.getAnnotationSets().get(0)); annotationSet.getAnnotations(), ParamUtils.CompleteUpdateAction.SET, new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser); catalogManager.getSampleManager().updateAnnotations(studyFqn, s_1, annotationSet.getId(), annotationSet.getAnnotations(), ParamUtils.CompleteUpdateAction.SET, new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser); sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, sessionIdUser).first(); ind = catalogManager.getIndividualManager().get(studyFqn, ind.getId(), null, sessionIdUser).first(); check.accept(sample.getAnnotationSets().get(0)); annotationSet.getAnnotations(), ParamUtils.CompleteUpdateAction.SET, new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser); catalogManager.getSampleManager().updateAnnotations(studyFqn, s_1, annotationSet.getId(), annotationSet.getAnnotations(), ParamUtils.CompleteUpdateAction.SET, new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser); sample = catalogManager.getSampleManager().get(studyFqn, s_1, null, sessionIdUser).first(); ind = catalogManager.getIndividualManager().get(studyFqn, ind.getId(), null, sessionIdUser).first();
@Test public void testDeleteAnnotationSet() throws CatalogException { catalogManager.getSampleManager().removeAnnotationSet(studyFqn, s_1, "annot1", QueryOptions.empty(), sessionIdUser); QueryResult<Sample> sampleQueryResult = catalogManager.getSampleManager().get(studyFqn, s_1, new QueryOptions(QueryOptions.INCLUDE, SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key()), sessionIdUser); assertEquals(0, sampleQueryResult.first().getAnnotationSets().size()); }
@Override protected List<String> validate(String defaultStudyStr, List<String> values, Integer release, VariantQueryParam param, String sessionId) throws CatalogException { if (release == null) { AbstractManager.MyResources<Sample> uids = catalogManager.getSampleManager().getUids(values, defaultStudyStr, sessionId); return uids.getResourceList().stream().map(Sample::getId).collect(Collectors.toList()); } else { return validate(defaultStudyStr, values, release, param, catalogManager.getSampleManager(), Sample::getId, Sample::getRelease, null, sessionId); } } }
new ObjectMap(jsonObjectMapper.writeValueAsString(annotationSet1)) )); QueryResult<Sample> update = catalogManager.getSampleManager().update(studyFqn, s_1, updateAnnotation, QueryOptions.empty(), sessionIdUser); assertEquals(3, update.first().getAnnotationSets().size()); catalogManager.getSampleManager().removeAnnotationSet(studyFqn, s_1, "annotation1", QueryOptions.empty(), sessionIdUser); QueryResult<Sample> sampleQueryResult = catalogManager.getSampleManager() .removeAnnotationSet(studyFqn, s_1, "annotation2", QueryOptions.empty(), sessionIdUser); assertEquals(1, sampleQueryResult.first().getAnnotationSets().size()); catalogManager.getSampleManager().removeAnnotationSet(studyFqn, s_1, "non_existing", QueryOptions.empty(), sessionIdUser);