@Override public List<Policy> findByResourceServer( Map<String, String[]> attributes, String resourceServerId, int firstResult, int maxResult) { QueryBuilder queryBuilder = new QueryBuilder().and("resourceServerId").is(resourceServerId); attributes.forEach( (name, value) -> { if ("permission".equals(name)) { if (Boolean.valueOf(value[0])) { queryBuilder.and("type").in(new String[] {"resource", "scope"}); } else { queryBuilder.and("type").notIn(new String[] {"resource", "scope"}); } } else if ("id".equals(name)) { queryBuilder.and("_id").in(value); } else { queryBuilder .and(name) .regex(Pattern.compile(".*" + value[0] + ".*", Pattern.CASE_INSENSITIVE)); } }); DBObject sort = new BasicDBObject("name", 1); return getMongoStore() .loadEntities( PolicyEntity.class, queryBuilder.get(), sort, firstResult, maxResult, invocationContext) .stream() .map(policy -> findById(policy.getId(), resourceServerId)) .collect(toList()); }
@Override public QueryResponse getAllByPositionList(List<Position> positionList, QueryOptions options) { // db.regulatory_region.find({"chunkIds": {$in:["1_200", "1_300"]}, "start": 601156}) String featureType = options.getString("featureType", null); String featureClass = options.getString("featureClass", null); List<DBObject> queries = new ArrayList<>(); for (Position position : positionList) { String chunkId = position.getChromosome() + "_" + getChunkId(position.getPosition(), CHUNKSIZE); BasicDBList chunksId = new BasicDBList(); chunksId.add(chunkId); QueryBuilder builder = QueryBuilder.start("chunkIds").in(chunksId).and("start").is(position.getPosition()); if (featureType != null) { builder.and("featureType").is(featureType); } if (featureClass != null) { builder.and("featureClass").is(featureClass); } // System.out.println("Query: " + builder.get()); queries.add(builder.get()); } System.out.println("Query: " + queries); options = addExcludeReturnFields("chunkIds", options); return executeQueryList(positionList, queries, options); }
@Override public QueryResult next(String chromosome, int position, QueryOptions options) { String featureType = options.getString("featureType", null); String featureClass = options.getString("featureClass", null); BasicDBList chunksId = new BasicDBList(); String chunkId = chromosome + "_" + getChunkId(position, regulatoryRegionChunkSize) + "_" + regulatoryRegionChunkSize / 1000 + "k"; chunksId.add(chunkId); // TODO: Add query to find next item considering next chunk // db.regulatory_region.find({ "chromosome" : "19" , "start" : { "$gt" : 62005} , "featureType" // : "TF_binding_site_motif"}).sort({start:1}).limit(1) QueryBuilder builder; if (options.getString("strand") == null || (options.getString("strand").equals("1") || options.getString("strand").equals("+"))) { // db.core.find({chromosome: "1", start: {$gt: 1000000}}).sort({start: 1}).limit(1) builder = QueryBuilder.start("_chunkIds") .in(chunksId) .and("chromosome") .is(chromosome) .and("start") .greaterThan(position); options.put("sort", new BasicDBObject("start", 1)); options.put("limit", 1); } else { builder = QueryBuilder.start("_chunkIds") .in(chunksId) .and("chromosome") .is(chromosome) .and("end") .lessThan(position); options.put("sort", new BasicDBObject("end", -1)); options.put("limit", 1); } if (featureType != null) { builder.and("featureType").is(featureType); } if (featureClass != null) { builder.and("featureClass").is(featureClass); } System.out.println(builder.get()); return executeQuery("result", builder.get(), options); }
@Override public List<QueryResult> getAllByRegionList(List<Region> regionList, QueryOptions options) { // db.regulatory_region.find({"chunkIds": {$in:["1_200", "1_300"]}, "start": 601156}) QueryBuilder builder = new QueryBuilder(); List<Object> featureType = options.getList("featureType", null); List<Object> featureClass = options.getList("featureClass", null); // options = addExcludeReturnFields("chunkIds", options); List<DBObject> queries = new ArrayList<>(); for (Region region : regionList) { int firstChunkId = getChunkId(region.getStart(), regulatoryRegionChunkSize); int lastChunkId = getChunkId(region.getEnd(), regulatoryRegionChunkSize); BasicDBList chunksId = new BasicDBList(); for (int j = firstChunkId; j <= lastChunkId; j++) { String chunkId = region.getChromosome() + "_" + j + "_" + regulatoryRegionChunkSize / 1000 + "k"; chunksId.add(chunkId); } // logger.info(chunksId.toString()); builder = builder .start("_chunkIds") .in(chunksId) .and("start") .lessThanEquals(region.getEnd()) .and("end") .greaterThanEquals(region.getStart()); if (featureType != null && featureType.size() > 0) { BasicDBList featureTypeDBList = new BasicDBList(); featureTypeDBList.addAll(featureType); builder = builder.and("featureType").in(featureTypeDBList); } if (featureClass != null && featureClass.size() > 0) { BasicDBList featureClassDBList = new BasicDBList(); featureClassDBList.addAll(featureClass); builder = builder.and("featureClass").in(featureClassDBList); } queries.add(builder.get()); } // System.out.println(">>"+regionList); // System.out.println(">>"+builder.get().toString()); return executeQueryList2(regionList, queries, options); }
@Override public void addQuery(AdRequest request, QueryBuilder builder) { if (request.date() != null) { List<DBObject> condition_queries = new ArrayList<DBObject>(); /* * Prefix der Indizieren beachten. */ for (int i = 0; i < DateConditionDefinition.MAX_PERIOD_COUNT; i++) { QueryBuilder condition = QueryBuilder.start(); // from part of the query BasicDBObject query_from_1 = new BasicDBObject( AdDBConstants.ADDB_AD_DATE_FROM + i, new BasicDBObject("$lte", request.date())); BasicDBObject query_from_2 = new BasicDBObject(AdDBConstants.ADDB_AD_DATE_FROM + i, AdDBConstants.ADDB_AD_DATE_ALL); List<BasicDBObject> queries = new ArrayList<BasicDBObject>(); queries.add(query_from_1); queries.add(query_from_2); BasicDBObject query_from = new BasicDBObject("$or", queries); condition.and(query_from); // to part of the query BasicDBObject query_to_1 = new BasicDBObject( AdDBConstants.ADDB_AD_DATE_TO + i, new BasicDBObject("$gte", request.date())); BasicDBObject query_to_2 = new BasicDBObject(AdDBConstants.ADDB_AD_DATE_TO + i, AdDBConstants.ADDB_AD_DATE_ALL); queries = new ArrayList<BasicDBObject>(); queries.add(query_to_1); queries.add(query_to_2); BasicDBObject query_to = new BasicDBObject("$or", queries); condition.and(query_to); condition_queries.add(condition.get()); } builder.and(new BasicDBObject("$or", condition_queries)); } }
public List<T> findByAttributes(Map<String, String> attributes) { QueryBuilder qb = QueryBuilder.start(); for (String k : attributes.keySet()) { qb.and("attributes." + k).is(attributes.get(k)); } return makeList(null, getDbCollection().find(qb.get())); }
@Override public QueryResponse getAllByRegionList(List<Region> regionList, QueryOptions options) { // db.regulatory_region.find({"chunkIds": {$in:["1_200", "1_300"]}, "start": 601156}) String featureType = options.getString("featureType", null); String featureClass = options.getString("featureClass", null); List<DBObject> queries = new ArrayList<>(); List<String> ids = new ArrayList<>(regionList.size()); for (Region region : regionList) { int firstChunkId = getChunkId(region.getStart(), CHUNKSIZE); int lastChunkId = getChunkId(region.getEnd(), CHUNKSIZE); BasicDBList chunksId = new BasicDBList(); for (int j = firstChunkId; j <= lastChunkId; j++) { String chunkId = region.getChromosome() + "_" + j; chunksId.add(chunkId); } QueryBuilder builder = QueryBuilder.start("chunkIds") .in(chunksId) .and("start") .lessThanEquals(region.getEnd()) .and("end") .greaterThanEquals(region.getStart()); if (featureType != null) { builder.and("featureType").is(featureType); } if (featureClass != null) { builder.and("featureClass").is(featureClass); } System.out.println("Query: " + builder.get()); queries.add(builder.get()); ids.add(region.toString()); } options = addExcludeReturnFields("chunkIds", options); return executeQueryList(ids, queries, options); }
@Override public void addQuery(AdRequest request, QueryBuilder builder) { if (request.day() == null) { return; } int day = request.day().getDay(); if (day == Day.ALL.getDay()) { return; } List<String> days = new ArrayList<String>(); days.add(String.valueOf(day)); days.add(String.valueOf(Day.ALL.getDay())); BasicDBObject dq = new BasicDBObject(AdDBConstants.ADDB_AD_DAY, new BasicDBObject("$in", days)); builder.and(dq); }