public static void mergeNewAnnotations(AnnotationSet annotationSet, Map<String, Object> newAnnotations) { annotationSet.getAnnotations().putAll(newAnnotations); // Map<String, Object> annotations = annotationSet.getAnnotations(); // // for (Map.Entry<String, Object> entry : newAnnotations.entrySet()) { // if (entry.getValue() != null) { // // Replace the annotation // annotations.put(entry.getKey(), entry.getValue()); // } else { // //Remove the old value (if present) // annotations.remove(entry.getKey()); // } // } }
public static Map<String, Object> populateAnnotations(Map<String, Map<String, QueryParam.Type>> variableTypeMap, List<AnnotationSet> annotationSets) { Map<String, Object> result = new HashedMap(); if (annotationSets != null) { for (AnnotationSet annotationSet : annotationSets) { for (String annotationKey : annotationSet.getAnnotations().keySet()) { Object value = annotationSet.getAnnotations().get(annotationKey); result.put("annotations" + type(variableTypeMap.get(annotationSet.getVariableSetId()).get(annotationKey)) + annotationSet.getVariableSetId() + "." + annotationKey, value); } } } return result; }
public List<Document> annotationToDB(VariableSet variableSet, AnnotationSet annotationSet) { return annotationToDB(variableSet, annotationSet.getId(), annotationSet.getAnnotations()); }
replaceAnnotations(targetAnnotationSet.getAnnotations(), sourceAnnotationSet.getAnnotations()); } else { targetAnnotationSet.getAnnotations().putAll(sourceAnnotationSet.getAnnotations()); String resetFields = (String) sourceAnnotationSet.getAnnotations().get("reset"); resetAnnotation(targetAnnotationSet.getAnnotations(), variable, variableSet.getVariables()); } catch (CatalogException e) { throw new CatalogException(variable + ": " + e.getMessage(), e); String removeFields = (String) sourceAnnotationSet.getAnnotations().get("remove"); removeAnnotation(targetAnnotationSet.getAnnotations(), variable, variableSet.getVariables()); } catch (CatalogException e) { throw new CatalogException(variable + ": " + e.getMessage(), e);
for (AnnotationSet annotationSet : annotationSets) { String prefix = annotationSets.size() > 1 ? annotationSet.getName() + '.' : ""; Map<String, Object> annotations = annotationSet.getAnnotations(); for (Map.Entry<String, Object> annotationEntry : annotations.entrySet()) { Object value = annotationEntry.getValue();
Set<String> annotatedVariables = annotationSet.getAnnotations().entrySet() .stream() .map(annotation -> annotation.getKey()) annotationSet.getAnnotations().putAll(defaultAnnotations); checkAnnotations(variableMap, annotationSet.getAnnotations());
annotationSetMap.get(compoundKey).getAnnotations().put(annotationDocument.getString(ID), annotationDocument.get(VALUE)); } else { annotationSetMap.get(compoundKey).getAnnotations()));
@Test public void mergeAnnotationsTest() { Map<String, Object> annotations = new HashMap<>(); annotations.put("K", "V"); annotations.put("K2", "V2"); annotations.put("K4", false); AnnotationSet annotationSet = new AnnotationSet("", "", annotations, "", 1, Collections.emptyMap()); Map<String, Object> newAnnotations = new ObjectMap() .append("K", "newValue") //Modify .append("K2", null) //Delete .append("K3", "newAnnotation"); //Add AnnotationUtils.mergeNewAnnotations(annotationSet, newAnnotations); Map<String, Object> newAnnotation = annotationSet.getAnnotations(); Assert.assertEquals(4, newAnnotation.size()); Assert.assertEquals("newValue", newAnnotation.get("K")); Assert.assertEquals(null, newAnnotation.get("K2")); Assert.assertEquals("newAnnotation", newAnnotation.get("K3")); Assert.assertEquals(false, newAnnotation.get("K4")); }
if (action == ParamUtils.CompleteUpdateAction.RESET && (annotationSet.getAnnotations() == null || annotationSet.getAnnotations().size() != 1 || !annotationSet.getAnnotations().containsKey("reset"))) { throw new CatalogException("Expected annotation key 'reset' not found"); if (action == ParamUtils.CompleteUpdateAction.REMOVE && (annotationSet.getAnnotations() == null || annotationSet.getAnnotations().size() != 1 || !annotationSet.getAnnotations().containsKey("remove"))) { throw new CatalogException("Expected annotation key 'remove' not found"); if (action == ParamUtils.CompleteUpdateAction.ADD && (annotationSet.getAnnotations() == null || annotationSet.getAnnotations().isEmpty())) { throw new CatalogException("Missing annotations to add to the annotationSet"); if (action == ParamUtils.CompleteUpdateAction.REPLACE && (annotationSet.getAnnotations() == null || annotationSet.getAnnotations().isEmpty())) { throw new CatalogException("Missing annotations to replace");
annotationSet.getAnnotations());
Map<String, Object> map = sampleQueryResult.first().getAnnotationSets().get(0).getAnnotations(); assertEquals(3, map.size()); assertEquals("Joe", map.get("NAME"));
@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); }
annotationSet.getAnnotations().put("NAME", "SAMPLE1"); annotationSet.getAnnotations().put("AGE", 38); annotationSet.getAnnotations().put("EXTRA", "extra"); annotationSet.getAnnotations().remove("HEIGHT"); 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); Map<String, Object> auxAnnotations = as.getAnnotations(); annotationSet.getAnnotations(), ParamUtils.CompleteUpdateAction.SET, new QueryOptions(Constants.INCREMENT_VERSION, true), sessionIdUser); check.accept(ind.getAnnotationSets().get(0)); annotationSet.getAnnotations().put("NAME", "SAMPLE 1"); annotationSet.getAnnotations().remove("EXTRA"); 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); Map<String, Object> auxAnnotations = as.getAnnotations(); annotationSet.getAnnotations().put("EXTRA", "extra"); catalogManager.getIndividualManager().updateAnnotations(studyFqn, ind.getId(), annotationSet.getId(), annotationSet.getAnnotations(), ParamUtils.CompleteUpdateAction.SET, new QueryOptions(Constants.INCREMENT_VERSION, true),
List<Document> documentList2 = annotableConverter.annotationToDB(vs, "annotName", annotationSets.get(0).getAnnotations());