public MongoDBVariantMergeLoader(MongoDBCollection variantsCollection, MongoDBCollection stageCollection, MongoDBCollection studiesCollection, StudyConfiguration studyConfiguration, List<Integer> fileIds, boolean resume, boolean cleanWhileLoading, ProgressLogger progressLogger) { this.progressLogger = progressLogger; this.variantsCollection = variantsCollection; this.stageCollection = stageCollection; this.studiesCollection = studiesCollection; this.resume = resume; this.studyId = studyConfiguration.getStudyId(); this.fileIds = fileIds; this.result = new MongoDBVariantWriteResult(); result.getGenotypes().addAll(studyConfiguration.getAttributes().getAsStringList(LOADED_GENOTYPES.key())); this.cleanWhileLoading = cleanWhileLoading; List<String> studyFileToPull = new ArrayList<>(fileIds.size()); for (Integer fileId : fileIds) { studyFileToPull.add(studyId + "_" + fileId); } List<Bson> cleanStageDuplicatedList = new ArrayList<>(fileIds.size() + 1); for (Integer fileId : fileIds) { // Can not unset value! cleanStageDuplicatedList.add(set(studyId + "." + fileId, null)); } cleanStageDuplicatedList.add(pullAll(StageDocumentToVariantConverter.STUDY_FILE_FIELD, studyFileToPull)); List<Bson> cleanStageList = new ArrayList<>(cleanStageDuplicatedList.size() + 1); cleanStageList.addAll(cleanStageDuplicatedList); cleanStageList.add(set(studyId.toString() + '.' + NEW_STUDY_FIELD, false)); cleanStageDuplicated = combine(cleanStageDuplicatedList); cleanStage = combine(cleanStageList); }
@Override public void removeUsersFromAllGroups(long studyId, List<String> users) throws CatalogDBException { if (users == null || users.size() == 0) { throw new CatalogDBException("Unable to remove users from groups. List of users is empty"); } Document query = new Document() .append(PRIVATE_UID, studyId) .append(QueryParams.GROUP_USER_IDS.key(), new Document("$in", users)) .append("$isolated", 1); Bson pull = Updates.pullAll("groups.$.userIds", users); // Pull those users while they are still there QueryResult<UpdateResult> update; do { update = studyCollection.update(query, pull, null); } while (update.first().getModifiedCount() > 0); }
@Override public void removeUsersFromGroup(long studyId, String groupId, List<String> members) throws CatalogDBException { if (members == null || members.size() == 0) { throw new CatalogDBException("Unable to remove members from group. List of members is empty"); } Document query = new Document() .append(PRIVATE_UID, studyId) .append(QueryParams.GROUP_NAME.key(), groupId) .append("$isolated", 1); Bson pull = Updates.pullAll("groups.$.userIds", members); QueryResult<UpdateResult> update = studyCollection.update(query, pull, null); if (update.first().getMatchedCount() != 1) { throw new CatalogDBException("Unable to remove members from group " + groupId + ". The group does not exist."); } }
updates.add(pullAll(StageDocumentToVariantConverter.STUDY_FILE_FIELD, studyFiles)); Bson filter = and(in(StageDocumentToVariantConverter.STUDY_FILE_FIELD, studyFiles), chrFilter, and(filters)); LOGGER.info("Clean studies from stage where all the files where duplicated"); updates.add(pullAll(StageDocumentToVariantConverter.STUDY_FILE_FIELD, studyFiles)); LOGGER.info("Cleaning files {} from stage collection", fileIds); modifiedCount += stageCollection.update(and(filters), combine(updates),