List of usage examples for org.springframework.data.mongodb.core.query Query addCriteria
public Query addCriteria(CriteriaDefinition criteriaDefinition)
From source file:com.github.camellabs.iot.cloudlet.geofencing.service.DefaultRouteService.java
@Override public int analyzeRoutes(String client) { RouteGpsCoordinates lastRouteCoordinates = findLastRouteCoordinates(client); GpsCoordinates lastCoordinates = null; if (lastRouteCoordinates == null) { LOG.info("No GPS coordinates assigned to routes for client {}", client); } else {/* w ww . j av a2 s .com*/ lastCoordinates = mongoTemplate.findById(lastRouteCoordinates.getCoordinatesId(), GpsCoordinates.class, GpsCoordinates.class.getSimpleName()); } Query query = new Query(); query.addCriteria(where("client").is(client)); if (lastRouteCoordinates != null) { query.addCriteria(where("_id").gt(new ObjectId(lastRouteCoordinates.getCoordinatesId()))); } query.limit(routeAnalysisBatchSize); query.with(new Sort(ASC, "_id")); List<GpsCoordinates> coordinatesToAnalyze = mongoTemplate.find(query, GpsCoordinates.class, GpsCoordinates.class.getSimpleName()); for (GpsCoordinates coordinates : coordinatesToAnalyze) { String routeId; if (lastCoordinates == null || (TimeUnit.MILLISECONDS.toMinutes( coordinates.getTimestamp().getTime() - lastCoordinates.getTimestamp().getTime()) > 5)) { Route newRoute = createNewRoute(client); routeId = documentDriver.save(collectionName(newRoute.getClass()), pojoToMap(newRoute)); } else { routeId = lastRouteCoordinates.getRouteId(); } lastRouteCoordinates = new RouteGpsCoordinates(null, routeId, coordinates.getId(), client); mongoTemplate.save(lastRouteCoordinates, collectionName(RouteGpsCoordinates.class)); lastCoordinates = coordinates; } return coordinatesToAnalyze.size(); }
From source file:com.epam.ta.reportportal.database.dao.ShareableRepositoryImpl.java
@SuppressWarnings("unchecked") @Override//from ww w . j a v a 2s.co m public List<T> findOnlyOwnedEntities(Set<String> ids, String owner) { if (owner == null) { return new ArrayList<>(); } Query query = ShareableRepositoryUtils.createOwnedEntityQuery(owner); if (Preconditions.NOT_EMPTY_COLLECTION.test(ids)) { query.addCriteria(Criteria.where(Shareable.ID).in(ids)); } Class<T> entityType = getEntityInformation().getJavaType(); return getMongoOperations().find(query, entityType); }
From source file:edu.upf.nets.mercury.dao.GeoIpDatabase.java
public boolean load() { //Go to mongo to find the last maxmind file. Calendar cal = Calendar.getInstance(); cal.add(Calendar.MONTH, -1);//from www. j a v a 2 s .com Query query = new Query(); query.with(new Sort(Sort.Direction.DESC, "timestamp")); query.addCriteria(Criteria.where("timestamp").gt(cal.getTime())); GeoIpData geoIpData = mongoTemplate.findOne(query, GeoIpData.class); // If there is no data, return false. if (null == geoIpData) return false; // Save data to temporary file and load the new service. try { this.process(geoIpData.getData()); return true; } catch (IOException e) { return false; } }
From source file:com.card.loop.xyz.dao.LearningObjectDAO.java
public List<LearningObject> searchLO(String title, String subject, Date fromDate, Date toDate, String orderBy) throws UnknownHostException { Query query = new Query(); if (title != null || !"".equals(title)) query.addCriteria(Criteria.where("title").regex(title)); else if (subject != null || !"".equals(subject)) query.addCriteria(Criteria.where("subject").regex(subject)); else if (fromDate != null && toDate != null) query.addCriteria(Criteria.where("uploadDate").gte(fromDate).lte(toDate)); else if (orderBy != null || !"".equals(orderBy)) { switch (orderBy) { case "uploadDate": query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "uploadedDate"))); break; case "downloads": query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "downloads"))); break; case "title": query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "title"))); break; }/*from w w w . j a va2 s .c om*/ } return mongoOps.find(query, LearningObject.class); }
From source file:things.mongo.MongoConnector.java
@Override public Observable<? extends Thing<?>> getChildrenForId(String id) { Query q = new Query(); q.addCriteria(Criteria.where("parents").is(id)); List<Thing> result = mongoTemplate.find(q, Thing.class); return Observable.from(result).map(t -> (Thing<?>) t); }
From source file:com.epam.ta.reportportal.database.dao.UserFilterRepositoryCustomImpl.java
@Override public List<UserFilter> findFilters(String userName, String projectName, Sort sort, boolean isShared) { Query query; if (isShared) { query = ShareableRepositoryUtils.createSharedEntityQuery(userName, projectName); } else {//from www.j a va 2 s. co m query = ShareableRepositoryUtils.createOwnedEntityQuery(userName); } query.addCriteria(where("isLink").is(false)).addCriteria(where(UserFilter.PROJECT_NAME).is(projectName)) .with(sort); query.with(sort); query.fields().include(ID); query.fields().include(NAME); query.fields().include(TARGET); query.fields().include(CONDITIONS); query.fields().include(OPTIONS); query.fields().include(Shareable.OWNER); query.fields().include(ENTRIES); query.fields().include(PROJECT); return mongoTemplate.find(query, UserFilter.class); }
From source file:com.card.loop.xyz.dao.LearningElementDAO.java
public boolean nameAvailability(String title, String subject) throws UnknownHostException { mongoOps.find(query(where("rating").is(5)), LearningElement.class); Query query = new Query(); query.addCriteria(where("title").is(title).andOperator(where("subject").is(subject))); return DatabaseManager.getMongoOpsInstance(AppConfig.DATABASE_LOOP).exists(query, LearningElement.class); }
From source file:things.mongo.MongoConnector.java
@Override public Observable<? extends Thing<?>> findThingsForTypeAndKey(String type, String key) { final Timer.Context context = find_exact_type_and_key_timer.time(); try {/*from w ww . j a v a 2 s . c o m*/ Query q = new Query(); q.addCriteria(Criteria.where("thingType").is(type).and("key").is(key)); List<Thing> things = mongoTemplate.find(q, Thing.class); return Observable.from(things).map(t -> (Thing<?>) t); } finally { context.stop(); } }
From source file:com.card.loop.xyz.dao.LearningElementDAO.java
public boolean exists(String id) throws UnknownHostException { boolean ok = false; Query query = new Query(); query.addCriteria(where("_id").is(id)); ok = mongoOps.exists(query, LearningElement.class); return ok;/* www . j av a 2s . com*/ }
From source file:com.card.loop.xyz.dao.LearningElementDAO.java
public boolean acceptLE(LearningElement le) throws UnknownHostException { boolean ok = false; Query query = new Query(); query.addCriteria(where("_id").is(le.getId())); LearningElement obj = this.mongoOps.findOne(query, LearningElement.class); obj.setId(le.getId());/*from w ww. j a va 2 s . com*/ obj.setStatus(2); this.mongoOps.save(obj); return ok; }