List of usage examples for com.mongodb.client.model Filters in
public static <TItem> Bson in(final String fieldName, final Iterable<TItem> values)
From source file:org.opencb.opencga.catalog.db.mongodb.MetaMongoDBAdaptor.java
License:Apache License
@Override public QueryResult<StudyAclEntry> getDaemonAcl(List<String> members) throws CatalogDBException { long startTime = startQuery(); Bson match = Aggregates.match(Filters.eq(PRIVATE_ID, "METADATA")); Bson unwind = Aggregates.unwind("$" + CohortDBAdaptor.QueryParams.ACL.key()); Bson match2 = Aggregates.match(Filters.in(CohortDBAdaptor.QueryParams.ACL_MEMBER.key(), members)); Bson project = Aggregates.project(// w w w. jav a 2 s .c o m Projections.include(CohortDBAdaptor.QueryParams.ID.key(), CohortDBAdaptor.QueryParams.ACL.key())); QueryResult<Document> aggregate = metaCollection.aggregate(Arrays.asList(match, unwind, match2, project), null); StudyAclEntry result = null; if (aggregate.getNumResults() == 1) { result = parseObject(((Document) aggregate.getResult().get(0).get("acl")), StudyAclEntry.class); } return endQuery("get daemon Acl", startTime, Arrays.asList(result)); }
From source file:org.opencb.opencga.catalog.db.mongodb.MongoDBUtils.java
License:Apache License
static QueryResult<Document> getAcl(long id, List<String> members, MongoDBCollection collection, Logger logger) throws CatalogDBException { List<Bson> aggregation = new ArrayList<>(); aggregation.add(Aggregates.match(Filters.eq(PRIVATE_ID, id))); aggregation.add(Aggregates.project(//ww w .java2 s.c o m Projections.include(FileDBAdaptor.QueryParams.ID.key(), FileDBAdaptor.QueryParams.ACL.key()))); aggregation.add(Aggregates.unwind("$" + FileDBAdaptor.QueryParams.ACL.key())); List<Bson> filters = new ArrayList<>(); if (members != null && members.size() > 0) { filters.add(Filters.in(FileDBAdaptor.QueryParams.ACL_MEMBER.key(), members)); } if (filters.size() > 0) { Bson filter = filters.size() == 1 ? filters.get(0) : Filters.and(filters); aggregation.add(Aggregates.match(filter)); } for (Bson bson : aggregation) { logger.debug("Get Acl: {}", bson.toBsonDocument(Document.class, com.mongodb.MongoClient.getDefaultCodecRegistry())); } return collection.aggregate(aggregation, null); }
From source file:org.opencb.opencga.catalog.db.mongodb.StudyMongoDBAdaptor.java
License:Apache License
@Override public QueryResult<Group> getGroup(long studyId, @Nullable String groupId, List<String> userIds) throws CatalogDBException { long startTime = startQuery(); checkId(studyId);// w w w.j av a 2 s . com for (String userId : userIds) { dbAdaptorFactory.getCatalogUserDBAdaptor().checkId(userId); } if (groupId != null && groupId.length() > 0 && !groupExists(studyId, groupId)) { throw new CatalogDBException("Group \"" + groupId + "\" does not exist in study " + studyId); } /* * List<Bson> aggregation = new ArrayList<>(); aggregation.add(Aggregates.match(Filters.elemMatch(QueryParams.VARIABLE_SET.key(), Filters.eq(VariableSetParams.ID.key(), variableSetId)))); aggregation.add(Aggregates.project(Projections.include(QueryParams.VARIABLE_SET.key()))); aggregation.add(Aggregates.unwind("$" + QueryParams.VARIABLE_SET.key())); aggregation.add(Aggregates.match(Filters.eq(QueryParams.VARIABLE_SET_ID.key(), variableSetId))); QueryResult<VariableSet> queryResult = studyCollection.aggregate(aggregation, variableSetConverter, new QueryOptions()); * */ List<Bson> aggregation = new ArrayList<>(); aggregation.add(Aggregates.match(Filters.eq(PRIVATE_ID, studyId))); aggregation.add(Aggregates.project(Projections.include(QueryParams.GROUPS.key()))); aggregation.add(Aggregates.unwind("$" + QueryParams.GROUPS.key())); // Document query = new Document(PRIVATE_ID, studyId); // List<Bson> groupQuery = new ArrayList<>(); if (userIds.size() > 0) { aggregation.add(Aggregates.match(Filters.in(QueryParams.GROUP_USER_IDS.key(), userIds))); // groupQuery.add(Filters.in("userIds", userIds)); } if (groupId != null && groupId.length() > 0) { aggregation.add(Aggregates.match(Filters.eq(QueryParams.GROUP_NAME.key(), groupId))); // groupQuery.add(Filters.eq("id", groupId)); } // Bson projection = new Document(QueryParams.GROUPS.key(), new Document("$elemMatch", groupQuery)); QueryResult<Document> queryResult = studyCollection.aggregate(aggregation, null); // QueryResult<Document> queryResult = studyCollection.find(query, projection, null); List<Study> studies = MongoDBUtils.parseStudies(queryResult); List<Group> groups = new ArrayList<>(); studies.stream().filter(study -> study.getGroups() != null) .forEach(study -> groups.addAll(study.getGroups())); return endQuery("getGroup", startTime, groups); }
From source file:org.opencb.opencga.storage.mongodb.variant.adaptors.VariantSourceMongoDBAdaptor.java
License:Apache License
protected Bson parseQuery(Query query) { LinkedList<Bson> filters = new LinkedList<>(); if (query.containsKey(VariantSourceQueryParam.STUDY_ID.key())) { List<String> studyIds = query.getAsStringList(VariantSourceQueryParam.STUDY_ID.key()); filters.add(Filters.in(VariantSourceQueryParam.STUDY_ID.key(), studyIds)); }/*w w w. j a v a 2 s .c o m*/ if (query.containsKey(VariantSourceQueryParam.FILE_ID.key())) { List<String> studyIds = query.getAsStringList(VariantSourceQueryParam.FILE_ID.key()); filters.add(Filters.in(VariantSourceQueryParam.FILE_ID.key(), studyIds)); } return Filters.and(filters); }