public QueryResult removeAnnotation(String annotationId, Query query, QueryOptions queryOptions) { Document mongoQuery = queryParser.parseQuery(query); logger.debug("deleteAnnotation: query = {}", mongoQuery); Document update = new Document("$set", new Document(DocumentToVariantConverter.ANNOTATION_FIELD + ".0", null)); logger.debug("deleteAnnotation: update = {}", update); return variantsCollection.update(mongoQuery, update, new QueryOptions(MULTI, true)); }
@Override public QueryResult<Long> extractSampleFromFiles(Query query, List<Long> sampleIds) throws CatalogDBException { long startTime = startQuery(); Bson bsonQuery = parseQuery(query, true); Bson update = new Document("$pull", new Document(QueryParams.SAMPLES.key(), new Document(PRIVATE_UID, new Document("$in", sampleIds)))); QueryOptions multi = new QueryOptions(MongoDBCollection.MULTI, true); QueryResult<UpdateResult> updateQueryResult = fileCollection.update(bsonQuery, update, multi); return endQuery("Extract samples from files", startTime, Collections.singletonList(updateQueryResult.first().getModifiedCount())); }
@Override public QueryResult<Long> insertFilesIntoDatasets(Query query, List<Long> fileIds) throws CatalogDBException { long startTime = startQuery(); Bson bsonQuery = parseQuery(query, false); Bson update = new Document("$push", new Document(QueryParams.FILES.key(), new Document("$each", fileIds))); QueryOptions multi = new QueryOptions(MongoDBCollection.MULTI, true); QueryResult<UpdateResult> updateQueryResult = datasetCollection.update(bsonQuery, update, multi); return endQuery("Insert files into datasets", startTime, Collections.singletonList(updateQueryResult.first().getModifiedCount())); }
@Override public void deleteGroup(long studyId, String groupId) throws CatalogDBException { Bson queryBson = new Document() .append(PRIVATE_UID, studyId) .append(QueryParams.GROUP_NAME.key(), groupId) .append("$isolated", 1); Document pull = new Document("$pull", new Document("groups", new Document("name", groupId))); QueryResult<UpdateResult> update = studyCollection.update(queryBson, pull, null); if (update.first().getModifiedCount() != 1) { throw new CatalogDBException("Could not remove the group " + groupId); } }
@Override public QueryResult<Long> extractFilesFromDatasets(Query query, List<Long> fileIds) throws CatalogDBException { long startTime = startQuery(); Bson bsonQuery = parseQuery(query, false); Bson update = new Document("$pull", new Document(QueryParams.FILES.key(), new Document("$in", fileIds))); QueryOptions multi = new QueryOptions(MongoDBCollection.MULTI, true); QueryResult<UpdateResult> updateQueryResult = datasetCollection.update(bsonQuery, update, multi); return endQuery("Extract files from datasets", startTime, Collections.singletonList(updateQueryResult.first().getModifiedCount())); }
@Override public void syncGroup(long studyId, String groupId, Group.Sync syncedFrom) throws CatalogDBException { Document mongoDBDocument = getMongoDBDocument(syncedFrom, "Group.Sync"); Document query = new Document() .append(PRIVATE_UID, studyId) .append(QueryParams.GROUP_NAME.key(), groupId) .append("$isolated", 1); Document updates = new Document("$set", new Document("groups.$.syncedFrom", mongoDBDocument)); studyCollection.update(query, updates, null); }
@Override public QueryResult updateStudyConfiguration(StudyConfiguration studyConfiguration, QueryOptions options) { Document studyMongo = new DocumentToStudyConfigurationConverter().convertToStorageType(studyConfiguration); // Update field by field, instead of replacing the whole object to preserve existing fields like "_lock" Document query = new Document("_id", studyConfiguration.getStudyId()); List<Bson> updates = new ArrayList<>(studyMongo.size()); studyMongo.forEach((s, o) -> updates.add(new Document("$set", new Document(s, o)))); QueryResult<UpdateResult> queryResult = collection.update(query, Updates.combine(updates), new QueryOptions(UPSERT, true)); // studyConfigurationMap.put(studyConfiguration.getStudyId(), studyConfiguration); return queryResult; }
public void delete(long id) throws CatalogDBException { Query query = new Query(QueryParams.UID.key(), id); Document pull = new Document("$pull", new Document("projects", new Document(QueryParams.UID.key(), id))); QueryResult<UpdateResult> update = userCollection.update(parseQuery(query), pull, null); if (update.first().getModifiedCount() != 1) { throw CatalogDBException.deleteError("Project " + id); } }
protected void unmarkPermissionRule(MongoDBCollection collection, long studyId, String permissionRuleId) { Bson query = new Document() .append(PRIVATE_STUDY_ID, studyId) .append(PERMISSION_RULES_APPLIED, permissionRuleId); Bson update = Updates.pull(PERMISSION_RULES_APPLIED, permissionRuleId); collection.update(query, update, new QueryOptions("multi", true)); }
@Override public QueryResult<Long> update(Query query, ObjectMap parameters, QueryOptions queryOptions) throws CatalogDBException { long startTime = startQuery(); Map<String, Object> jobParameters = getValidatedUpdateParams(parameters); if (!jobParameters.isEmpty()) { QueryResult<UpdateResult> update = jobCollection.update(parseQuery(query, false), new Document("$set", jobParameters), null); return endQuery("Update job", startTime, Arrays.asList(update.getNumTotalResults())); } return endQuery("Update job", startTime, new QueryResult<Long>()); }
@Override public void addSamplesToFile(long fileId, List<Sample> samples) throws CatalogDBException { if (samples == null || samples.size() == 0) { return; } List<Document> sampleList = fileConverter.convertSamples(samples); Bson update = Updates.addEachToSet(QueryParams.SAMPLES.key(), sampleList); fileCollection.update(Filters.eq(PRIVATE_UID, fileId), update, QueryOptions.empty()); }
@Override public void updateVariantFileMetadata(String studyId, VariantFileMetadata metadata) { MongoDBCollection coll = db.getCollection(collectionName); if (Integer.valueOf(metadata.getId()) <= 0) { throw new IllegalArgumentException("FileIds must be integer positive"); } Document document = variantFileMetadataConverter.convertToStorageType(studyId, metadata); String id = document.getString("_id"); document.append("_id", id); QueryOptions options = new QueryOptions(MongoDBCollection.REPLACE, true).append(MongoDBCollection.UPSERT, true); coll.update(Filters.eq("_id", id), document, options); }
public void insertDocument(Object id) { collection.update(new Document("_id", id), Updates.set("_id", id), new QueryOptions(MongoDBCollection.UPSERT, true)); } }
@Override public void updateProjectRelease(long studyId, int release) throws CatalogDBException { Query query = new Query() .append(QueryParams.STUDY_UID.key(), studyId) .append(QueryParams.SNAPSHOT.key(), release - 1); Bson bson = parseQuery(query, false); Document update = new Document() .append("$addToSet", new Document(RELEASE_FROM_VERSION, release)); QueryOptions queryOptions = new QueryOptions("multi", true); individualCollection.update(bson, update, queryOptions); }
@Override public void updateProjectRelease(long studyId, int release) throws CatalogDBException { Query query = new Query() .append(QueryParams.STUDY_UID.key(), studyId) .append(QueryParams.SNAPSHOT.key(), release - 1); Bson bson = parseQuery(query, false); Document update = new Document() .append("$addToSet", new Document(RELEASE_FROM_VERSION, release)); QueryOptions queryOptions = new QueryOptions("multi", true); sampleCollection.update(bson, update, queryOptions); }
@Override public void updateProjectRelease(long studyId, int release) throws CatalogDBException { Query query = new Query() .append(QueryParams.STUDY_UID.key(), studyId) .append(QueryParams.SNAPSHOT.key(), release - 1); Bson bson = parseQuery(query, false); Document update = new Document() .append("$addToSet", new Document(RELEASE_FROM_VERSION, release)); QueryOptions queryOptions = new QueryOptions("multi", true); familyCollection.update(bson, update, queryOptions); }
@Override public void updateProjectRelease(long studyId, int release) throws CatalogDBException { Query query = new Query() .append(QueryParams.STUDY_UID.key(), studyId) .append(QueryParams.SNAPSHOT.key(), release - 1); Bson bson = parseQuery(query, false); Document update = new Document() .append("$addToSet", new Document(RELEASE_FROM_VERSION, release)); QueryOptions queryOptions = new QueryOptions("multi", true); panelCollection.update(bson, update, queryOptions); }
@Override public void nativeInsert(Map<String, Object> project, String userId) throws CatalogDBException { Bson query = Filters.and(Filters.eq(UserDBAdaptor.QueryParams.ID.key(), userId), Filters.ne(UserDBAdaptor.QueryParams.PROJECTS_ID.key(), project.get(QueryParams.ID.key()))); Bson update = Updates.push("projects", getMongoDBDocument(project, "project")); //Update object QueryResult<UpdateResult> queryResult = userCollection.update(query, update, null); if (queryResult.getResult().get(0).getModifiedCount() == 0) { // Check if the project has been inserted throw new CatalogDBException("Project {" + project.get(QueryParams.ID.key()) + "\"} already exists for this user"); } }
private void addNewAnnotations(long entryId, List<Document> annotationDocumentList, boolean isVersioned) throws CatalogDBException { Document queryDocument = new Document(PRIVATE_UID, entryId); if (isVersioned) { queryDocument.append(LAST_OF_VERSION, true); } Bson push = Updates.addEachToSet(AnnotationSetParams.ANNOTATION_SETS.key(), annotationDocumentList); QueryResult<UpdateResult> update = getCollection().update(queryDocument, push, new QueryOptions("multi", true)); if (update.first().getModifiedCount() < 1) { throw new CatalogDBException("Could not add new annotations"); } }
@Override public QueryResult updateCustomAnnotations(Query query, String name, AdditionalAttribute attribute, long timeStamp, QueryOptions options) { Document queryDocument = queryParser.parseQuery(query); Document updateDocument = DocumentToVariantAnnotationConverter.convertToStorageType(attribute); return variantsCollection.update(queryDocument, combine(set(DocumentToVariantConverter.CUSTOM_ANNOTATION_FIELD + '.' + name, updateDocument), getSetIndexNotSynchronized(timeStamp)), new QueryOptions(MULTI, true)); }