@Override public Document convertToStorageType(Study object) { Document document = super.convertToStorageType(object); document.put("uid", document.getInteger("uid").longValue()); return document; } }
@Override public E next() { Document next = this.previousDocument; getNextStudy(); if (converter != null) { return converter.convertToDataModelType(next); } else { return (E) next; } }
/** * Restore all the dots in the keys where {@link #TO_REPLACE_DOTS} is found. * @param document Document to modify * @return Restored document */ public static Document restoreDots(Document document) { return modifyKeys(document, key -> key.replace(TO_REPLACE_DOTS, "."), TO_REPLACE_DOTS); }
@Override public QueryResult updateProjectMetadata(ProjectMetadata projectMetadata, boolean updateCounters) { Document mongo = new GenericDocumentComplexConverter<>(ProjectMetadata.class).convertToStorageType(projectMetadata); // Update field by field, instead of replacing the whole object to preserve existing fields like "_lock" List<Bson> updates = new ArrayList<>(mongo.size()); mongo.forEach((s, o) -> { // Do not update counters if (updateCounters || !s.equals(COUNTERS_FIELD)) { updates.add(new Document("$set", new Document(s, o))); } }); return collection.update(QUERY, Updates.combine(updates), new QueryOptions(UPSERT, true)); }
@Override public T convertToDataModelType(Document document) { try { restoreDots(document); String json = objectMapper.writeValueAsString(document); return objectMapper.readValue(json, clazz); } catch (IOException e) { throw new UncheckedIOException(e); } }
@Override public Document convertToStorageType(T object) { try { String json = objectMapper.writeValueAsString(object); Document document = Document.parse(json); replaceDots(document); return document; } catch (JsonProcessingException e) { throw new UncheckedIOException(e); } }
public MongoDBProjectMetadataDBAdaptor(MongoDataStore db, String collectionName) { converter = new GenericDocumentComplexConverter<>(ProjectMetadata.class); this.collection = db.getCollection(collectionName) .withReadPreference(ReadPreference.primary()) .withWriteConcern(WriteConcern.ACKNOWLEDGED); mongoLock = new MongoLock(collection, "_lock"); }
@Override public Document convertToStorageType(Dataset object) { Document document = super.convertToStorageType(object); document.put("id", document.getInteger("id").longValue()); return document; }
@Override public E next() { Document next = (Document) mongoCursor.next(); if (filter != null) { next = filter.apply(next); } if (converter != null) { return converter.convertToDataModelType(next); } else { return (E) next; } }
/** * Replace all the dots in the keys with {@link #TO_REPLACE_DOTS}. * * MongoDB is not able to store dots in key fields. * * @param document Document to modify * @return Document modified */ public static Document replaceDots(Document document) { return modifyKeys(document, key -> key.replace(".", TO_REPLACE_DOTS), "."); }
@Override public Document convertToStorageType(VariableSet object) { Document document = super.convertToStorageType(object); document.put("id", document.getInteger("id").longValue()); return document; } }
@Override public Project convertToDataModelType(Document object) { Document projects = (Document) object.get("projects"); return super.convertToDataModelType(projects); }
keysWithDots.add(entry.getKey()); modifyKeys(entry.getValue(), keyMapper, toReplace); Collection collection = (Collection) object; for (Object o : collection) { modifyKeys(o, keyMapper, toReplace);
@Override public Document convertToStorageType(Project object) { Document document = super.convertToStorageType(object); document.put("uid", document.getInteger("uid").longValue()); return document; } }
@Override public E next() { Document next = clinicalAnalysisListBuffer.remove(); if (filter != null) { next = filter.apply(next); } addAclInformation(next, options); if (converter != null) { return (E) converter.convertToDataModelType(next); } else { return (E) next; } }
public Document convertToStorageType(String studyId, VariantFileMetadata object) { Document document = super.convertToStorageType(object); document.append("_id", buildId(studyId, object.getId())); return document; }
public T convertToDataModelType(Document document, QueryOptions queryOptions) { List<AnnotationSet> annotationSets = annotationConverter.fromDBToAnnotation((List<Document>) document.get(ANNOTATION_SETS), (Document) document.get(AnnotationMongoDBAdaptor.AnnotationSetParams.PRIVATE_VARIABLE_SET_MAP.key()), queryOptions); T t = super.convertToDataModelType(document); t.setAnnotationSets(annotationSets); return t; } }
@Override public Document convertToStorageType(Panel object) { Document document = super.convertToStorageType(object); document.put("uid", object.getUid()); document.put("studyUid", object.getStudyUid()); return document; }
public Document convertToStorageType(T object, List<VariableSet> variableSetList) { List<Document> documentList = new ArrayList<>(); Document privateVariableSetMap = new Document(); if (variableSetList != null && !variableSetList.isEmpty() && object.getAnnotationSets() != null && !object.getAnnotationSets().isEmpty()) { Map<String, VariableSet> variableSetMap = new HashMap<>(); for (VariableSet variableSet : variableSetList) { variableSetMap.put(variableSet.getId(), variableSet); } for (AnnotationSet annotationSet : object.getAnnotationSets()) { VariableSet variableSet = variableSetMap.get(annotationSet.getVariableSetId()); if (variableSet != null) { documentList.addAll(annotationConverter.annotationToDB(variableSet, annotationSet)); privateVariableSetMap.put(String.valueOf(variableSet.getUid()), variableSet.getId()); } } } object.setAnnotationSets(null); Document document = super.convertToStorageType(object); document.put(ANNOTATION_SETS, documentList); document.put(PRIVATE_VS_MAP, privateVariableSetMap); return document; }
@Override public Document convertToStorageType(ClinicalAnalysis clinicalAnalysis) { Document document = super.convertToStorageType(clinicalAnalysis); document.put("uid", clinicalAnalysis.getUid()); document.put("studyUid", clinicalAnalysis.getStudyUid()); document.put("interpretations", convertInterpretations(clinicalAnalysis.getInterpretations())); validateDocumentToUpdate(document); return document; }