@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 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()); }
public QueryResult<Sample> updateAnnotations(String studyStr, String sampleStr, String annotationSetId, Map<String, Object> annotations, ParamUtils.CompleteUpdateAction action, QueryOptions options, String token) throws CatalogException { if (annotations == null || annotations.isEmpty()) { return new QueryResult<>(sampleStr, -1, -1, -1, "Nothing to do: The map of annotations is empty", "", Collections.emptyList()); } ObjectMap params = new ObjectMap(AnnotationSetManager.ANNOTATIONS, new AnnotationSet(annotationSetId, "", annotations)); options = ParamUtils.defaultObject(options, QueryOptions::new); options.put(Constants.ACTIONS, new ObjectMap(AnnotationSetManager.ANNOTATIONS, action)); return update(studyStr, sampleStr, params, options, token); }
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);
public QueryResult<Sample> updateAnnotationSet(String studyStr, String sampleStr, List<AnnotationSet> annotationSetList, ParamUtils.UpdateAction action, QueryOptions options, String token) throws CatalogException { ObjectMap params = new ObjectMap(AnnotationSetManager.ANNOTATION_SETS, annotationSetList); options = ParamUtils.defaultObject(options, QueryOptions::new); options.put(Constants.ACTIONS, new ObjectMap(AnnotationSetManager.ANNOTATION_SETS, action)); return update(studyStr, sampleStr, params, options, token); }
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")
@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); }
annotations.put("NAME", "Luke"); catalogManager.getSampleManager().update(studyFqn, sampleId, new ObjectMap() .append(IndividualDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Collections.singletonList(new ObjectMap() .append(AnnotationSetManager.ID, "annotation1") catalogManager.getSampleManager().update(studyFqn, sampleId, new ObjectMap() .append(IndividualDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Collections.singletonList(new ObjectMap() .append(AnnotationSetManager.ID, "annotation2")
@Test public void testUpdateSampleStats() throws CatalogException { catalogManager.getSampleManager().create(studyFqn, new Sample().setId("HG007"), null, sessionIdUser); QueryResult<Sample> update = catalogManager.getSampleManager().update(studyFqn, "HG007", new ObjectMap (SampleDBAdaptor.QueryParams.STATS.key(), new ObjectMap("one", "two")), new QueryOptions(), sessionIdUser); assertEquals(1, update.first().getStats().size()); assertTrue(update.first().getStats().containsKey("one")); assertEquals("two", update.first().getStats().get("one")); update = catalogManager.getSampleManager().update(studyFqn, "HG007", new ObjectMap(SampleDBAdaptor.QueryParams.STATS.key(), new ObjectMap("two", "three")), new QueryOptions(), sessionIdUser); assertEquals(2, update.first().getStats().size()); }
new ObjectMap(jsonObjectMapper.writeValueAsString(annotationSet1)) )); QueryResult<Sample> update = catalogManager.getSampleManager().update(studyFqn, s_1, updateAnnotation, QueryOptions.empty(), sessionIdUser); assertEquals(3, update.first().getAnnotationSets().size());
annotations.put("NAME", "Luke"); catalogManager.getSampleManager().update(studyFqn, sampleId, new ObjectMap() .append(IndividualDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Collections.singletonList(new ObjectMap() .append(AnnotationSetManager.ID, "annotation1") thrown.expect(CatalogException.class); thrown.expectMessage("unique"); catalogManager.getSampleManager().update(studyFqn, sampleId, new ObjectMap() .append(IndividualDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Collections.singletonList(new ObjectMap() .append(AnnotationSetManager.ID, "annotation2")
@Test public void testDeleteVariableSetInUse() throws CatalogException { String sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), new QueryOptions(), sessionIdUser).first().getId(); List<Variable> variables = Arrays.asList( new Variable("NAME", "", "", Variable.VariableType.TEXT, "", true, false, Collections.emptyList(), 0, "", "", null, Collections.emptyMap()), new Variable("AGE", "", "", Variable.VariableType.DOUBLE, null, false, false, Collections.singletonList("0:99"), 1, "", "", null, Collections.emptyMap()) ); VariableSet vs1 = catalogManager.getStudyManager().createVariableSet(studyFqn, "vs1", "vs1", true, false, "", null, variables, sessionIdUser).first(); Map<String, Object> annotations = new HashMap<>(); annotations.put("NAME", "LINUS"); catalogManager.getSampleManager().update(studyFqn, sampleId1, new ObjectMap() .append(SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Collections.singletonList(new ObjectMap() .append(AnnotationSetManager.ID, "annotationId") .append(AnnotationSetManager.VARIABLE_SET_ID, vs1.getId()) .append(AnnotationSetManager.ANNOTATIONS, annotations)) ), QueryOptions.empty(), sessionIdUser); try { catalogManager.getStudyManager().deleteVariableSet(studyFqn, Long.toString(vs1.getUid()), sessionIdUser).first(); } finally { VariableSet variableSet = catalogManager.getStudyManager().getVariableSet(studyFqn, vs1.getId(), null, sessionIdUser).first(); assertEquals(vs1.getUid(), variableSet.getUid()); thrown.expect(CatalogDBException.class); //Expect the exception from the try } }
catalogManager.getSampleManager().update(studyFqn, sampleId, new ObjectMap() .append(IndividualDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Collections.singletonList(new ObjectMap() .append(AnnotationSetManager.ID, "annotation1") catalogManager.getSampleManager().update(studyFqn, sampleId, new ObjectMap() .append(IndividualDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Collections.singletonList(new ObjectMap() .append(AnnotationSetManager.ID, "annotation2") catalogManager.getSampleManager().update(studyFqn, sampleId, new ObjectMap() .append(IndividualDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Collections.singletonList(new ObjectMap() .append(AnnotationSetManager.ID, "annotation3")
new Variable("other", "", "", Variable.VariableType.TEXT, "unknown", false, false, null, 0, null, null, null, null)), sessionId); catalogManager.getSampleManager().update(studyId, "NA19600", new ObjectMap() .append(SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Collections.singletonList(new ObjectMap() .append(AnnotationSetManager.ID, "as1") ), QueryOptions.empty(), sessionId); catalogManager.getSampleManager().update(studyId, "NA19660", new ObjectMap() .append(SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Collections.singletonList(new ObjectMap() .append(AnnotationSetManager.ID, "as1") ), QueryOptions.empty(), sessionId); catalogManager.getSampleManager().update(studyId, "NA19660", new ObjectMap() .append(SampleDBAdaptor.QueryParams.ANNOTATION_SETS.key(), Collections.singletonList(new ObjectMap() .append(AnnotationSetManager.ID, "as2")
@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()); }
catalogManager.getSampleManager().update(studyFqn, "sample1", new ObjectMap(), new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser); catalogManager.getSampleManager().update(studyFqn, "sample1", new ObjectMap(), new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser); catalogManager.getSampleManager().update(studyFqn, "sample1", new ObjectMap(), new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser); catalogManager.getSampleManager().update(studyFqn, "sample2", new ObjectMap(), new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser); catalogManager.getSampleManager().update(studyFqn, "sample2", new ObjectMap(), new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser); catalogManager.getSampleManager().update(studyFqn, "sample3", new ObjectMap(), new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser);
new ObjectMap(jsonObjectMapper.writeValueAsString(annotationSet)) )); catalogManager.getSampleManager().update(studyFqn, s_1, updateAnnotation, QueryOptions.empty(), sessionIdUser);
@Test public void updateCollectionField() throws CatalogException { catalogManager.getSampleManager().create(studyFqn, new Sample().setId("testSample").setDescription("description"), null, sessionIdUser); SampleCollection collection = new SampleCollection("tissue", "organ", "quantity", "method", "date", Collections.emptyMap()); ObjectMap params = new ObjectMap(SampleDBAdaptor.UpdateParams.COLLECTION.key(), collection); catalogManager.getSampleManager().update(studyFqn, "testSample", params, new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser); QueryResult<Sample> testSample = catalogManager.getSampleManager().get(studyFqn, "testSample", new QueryOptions(), sessionIdUser); assertEquals("tissue", testSample.first().getCollection().getTissue()); assertEquals("organ", testSample.first().getCollection().getOrgan()); assertEquals("quantity", testSample.first().getCollection().getQuantity()); assertEquals("method", testSample.first().getCollection().getMethod()); assertEquals("date", testSample.first().getCollection().getDate()); assertTrue(testSample.first().getCollection().getAttributes().isEmpty()); }
catalogManager.getSampleManager().update(studyFqn, sample1.getId(), new ObjectMap(), new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser);
@Test public void updateProcessingField() throws CatalogException { catalogManager.getSampleManager().create(studyFqn, new Sample().setId("testSample").setDescription("description"), null, sessionIdUser); SampleProcessing processing = new SampleProcessing("product", "preparationMethod", "extractionMethod", "labSampleId", "quantity", "date", Collections.emptyMap()); ObjectMap params = new ObjectMap(SampleDBAdaptor.UpdateParams.PROCESSING.key(), processing); catalogManager.getSampleManager().update(studyFqn, "testSample", params, new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser); QueryResult<Sample> testSample = catalogManager.getSampleManager().get(studyFqn, "testSample", new QueryOptions(), sessionIdUser); assertEquals("product", testSample.first().getProcessing().getProduct()); assertEquals("preparationMethod", testSample.first().getProcessing().getPreparationMethod()); assertEquals("extractionMethod", testSample.first().getProcessing().getExtractionMethod()); assertEquals("labSampleId", testSample.first().getProcessing().getLabSampleId()); assertEquals("quantity", testSample.first().getProcessing().getQuantity()); assertEquals("date", testSample.first().getProcessing().getDate()); assertTrue(testSample.first().getProcessing().getAttributes().isEmpty()); }