public List<Document> annotationToDB(VariableSet variableSet, AnnotationSet annotationSet) { return annotationToDB(variableSet, annotationSet.getId(), annotationSet.getAnnotations()); }
public QueryResult<Individual> updateAnnotations(String studyStr, String individualStr, String annotationSetId, Map<String, Object> annotations, ParamUtils.CompleteUpdateAction action, QueryOptions options, String token) throws CatalogException { if (annotations == null || annotations.isEmpty()) { return new QueryResult<>(individualStr, -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, individualStr, params, options, token); }
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 QueryResult<Sample> removeAnnotationSets(String studyStr, String sampleStr, List<String> annotationSetIdList, QueryOptions options, String token) throws CatalogException { List<AnnotationSet> annotationSetList = annotationSetIdList .stream() .map(id -> new AnnotationSet().setId(id)) .collect(Collectors.toList()); return updateAnnotationSet(studyStr, sampleStr, annotationSetList, ParamUtils.UpdateAction.REMOVE, options, token); }
.append(AnnotationSetParams.ANNOTATION_SET_NAME.key(), annotationSet.getId()) .append("_id", id)); if (count.first() > 0) { throw CatalogDBException.alreadyExists("AnnotationSet", "name", annotationSet.getId()); .append(AnnotationSetParams.ANNOTATION_SETS_VARIABLE_SET_ID.key(), annotationSet.getVariableSetId()) .append("_id", id)); if (count.first() > 0) { List<Document> documentList = annotationConverter.annotationToDB(variableSet, annotationSet.getId(), annotationSet.getAnnotations()); Filters.eq(AnnotationSetParams.ANNOTATION_SET_NAME.key(), new Document("$ne", annotationSet.getId())) ); Bson update = new Document() throw CatalogDBException.alreadyExists("AnnotationSet", "name", annotationSet.getId());
annotationSetMap.put(compoundKey, new AnnotationSet(annSetName, variableSetId, new HashMap<>(), Collections.emptyMap())); annotationSetMap.get(compoundKey).getAnnotations().put(annotationDocument.getString(ID), annotationDocument.get(VALUE)); } else { annotationSetMap.put(compoundKey, new AnnotationSet(annSetName, variableSetId, new HashMap<>(), Collections.emptyMap())); annotationSetMap.get(compoundKey).getAnnotations()));
while (iterator.hasNext()) { AnnotationSet annotationSet = iterator.next(); String annotationSetName = annotationSet.getId(); ParamUtils.checkAlias(annotationSetName, "annotationSetName"); if (!variableSetMap.containsKey(annotationSet.getVariableSetId())) { throw new CatalogException("VariableSetId " + annotationSet.getVariableSetId() + " not found in study " + studyId); VariableSet variableSet = variableSetMap.get(annotationSet.getVariableSetId());
if (action == ParamUtils.CompleteUpdateAction.SET) { targetAnnotationSet.setAnnotations(new HashMap<>()); 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);
sample.setAnnotations(new LinkedHashMap<>(sample.getAnnotations())); 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();
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()); // } // } }
private List<Document> getNewAnnotationList(List<AnnotationSet> annotationSetList, List<VariableSet> variableSetList) { List<Document> annotationList = new ArrayList<>(); Map<String, VariableSet> variableSetMap = new HashMap<>(); for (VariableSet variableSet : variableSetList) { variableSetMap.put(variableSet.getId(), variableSet); } // Convert the annotations to the list of documents for (AnnotationSet annotationSet : annotationSetList) { VariableSet variableSet = variableSetMap.get(annotationSet.getVariableSetId()); annotationList.addAll(annotationConverter.annotationToDB(variableSet, annotationSet)); } return annotationList; }
if (!existingAnnotationSets.contains(annotationSet.getId())) { throw new CatalogDBException("Could not delete: AnnotationSet " + annotationSet.getId() + " not found"); removeAnnotationSet(entryId, annotationSet.getId(), isVersioned); String variableSetId = annotationSetIdVariableSetUidMap.get(annotationSet.getId()); variableSetAnnotationsets.get(variableSetId).remove(annotationSet.getId()); removeAnnotationSet(entryId, annotationSet.getId(), isVersioned);
annotationSetMap.put(annotationSet.getId(), annotationSet); if (annotationSetMap.containsKey(annotationSet.getId())) { throw new CatalogException("Cannot add AnnotationSet " + annotationSet.getId() + ". An AnnotationSet with " + "the same id was already found."); } else if (variableSetMap.containsKey(annotationSet.getVariableSetId())) { if (variableSetMap.get(annotationSet.getVariableSetId()).isConfidential()) { if (!confidentialPermissionsChecked) { authorizationManager.checkStudyPermission(resource.getStudy().getUid(), resource.getUser(), AnnotationUtils.checkAnnotationSet(variableSetMap.get(annotationSet.getVariableSetId()), annotationSet, annotationSetList, true); if (StringUtils.isEmpty(annotationSet.getId())) { throw new CatalogException("Cannot remove annotationSet. Mandatory annotationSet id field is empty"); ParamUtils.checkParameter(annotationSet.getId(), "annotationSet id"); 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
@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")); }
public QueryResult<Individual> removeAnnotationSets(String studyStr, String individualStr, List<String> annotationSetIdList, QueryOptions options, String token) throws CatalogException { List<AnnotationSet> annotationSetList = annotationSetIdList .stream() .map(id -> new AnnotationSet().setId(id)) .collect(Collectors.toList()); return updateAnnotationSet(studyStr, individualStr, annotationSetList, ParamUtils.UpdateAction.REMOVE, options, token); }
if (annotationSetIds.contains(annotationSet.getId())) { throw new CatalogDBException("Found more than one annotationSet with same id " + annotationSet.getId()); annotationSetIds.add(annotationSet.getId()); .append(AnnotationSetParams.ANNOTATION_SET_NAME.key(), annotationSet.getId()) .append(PRIVATE_UID, entryId); if (isVersioned) { throw CatalogDBException.alreadyExists("AnnotationSet", "id", annotationSet.getId()); VariableSet variableSet = variableSetMap.get(annotationSet.getVariableSetId()); if (variableSet.isUnique()) { query = new Document() .append(AnnotationSetParams.ANNOTATION_SETS_VARIABLE_SET_ID.key(), annotationSet.getVariableSetId()) .append(PRIVATE_UID, entryId); if (isVersioned) {
Map<String, Object> map = sampleQueryResult.first().getAnnotationSets().get(0).getAnnotations(); assertEquals(3, map.size()); assertEquals("Joe", map.get("NAME"));
private Map<String, String> getPrivateVariableMapToSet(List<AnnotationSet> annotationSetList, List<VariableSet> variableSetList) { Map<String, VariableSet> variableSetMap = new HashMap<>(); for (VariableSet variableSet : variableSetList) { variableSetMap.put(variableSet.getId(), variableSet); } Map<String, String> privateVariableMap = new HashMap<>(); for (AnnotationSet annotationSet : annotationSetList) { VariableSet variableSet = variableSetMap.get(annotationSet.getVariableSetId()); privateVariableMap.put(String.valueOf(variableSet.getUid()), variableSet.getId()); } return privateVariableMap; }
@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); }
.append(String.valueOf(vs.getUid()), vs.getId()), new QueryOptions()); assertEquals(1, annotationSets.size()); assertEquals("annotName", annotationSets.get(0).getId()); assertEquals(vs.getId(), annotationSets.get(0).getVariableSetId()); List<Document> documentList2 = annotableConverter.annotationToDB(vs, "annotName", annotationSets.get(0).getAnnotations());