List of usage examples for com.mongodb QueryBuilder get
public DBObject get()
From source file:it.sayservice.platform.smartplanner.otp.OTPManager.java
License:Apache License
private List<AlertDelay> getAlertDelay(String router, String tripId, boolean now) { QueryBuilder qb = new QueryBuilder(); qb = qb.start("transport.tripId").is(tripId); if (now) {//ww w . j a v a2 s. c o m long time = System.currentTimeMillis(); qb = qb.and("from").lessThanEquals(time); qb = qb.and("to").greaterThanEquals(time); } List<AlertDelay> delays = (List) storage.getObjectsByQuery( mongoRouterMapper.getMongoTemplateMap().get(router), qb.get(), Constants.ALERT_DELAYS, AlertDelay.class, "delay"); return delays; }
From source file:it.sayservice.platform.smartplanner.otp.OTPManager.java
License:Apache License
private List<TripSchedule> getSchedule(String router, String agencyId, String routeId, int day, String date, String collectionName, boolean symbolic) { QueryBuilder qb = QueryBuilder.start(); if (symbolic) { qb.and("symbolicRouteIds").is(routeId); } else {/*from ww w . ja v a2s. c o m*/ qb = qb.and("routeId").is(routeId); } qb = qb.and("agencyId").is(agencyId); qb = qb.and("days").is(day); qb = qb.and("daysRemoved").notEquals(date); qb = qb.and("fromDate").lessThanEquals(date); qb = qb.and("toDate").greaterThanEquals(date); List<TripSchedule> schedules = (List) storage.getObjectsByQuery( mongoRouterMapper.getMongoTemplateMap().get(router), qb.get(), collectionName, TripSchedule.class, "routeId"); qb = QueryBuilder.start(); if (symbolic) { qb.and("symbolicRouteIds").is(routeId); } else { qb = qb.and("routeId").is(routeId); } qb = qb.and("agencyId").is(agencyId); qb = qb.and("daysAdded").is(date); qb = qb.and("fromDate").lessThanEquals(date); qb = qb.and("toDate").greaterThanEquals(date); List<TripSchedule> addedSchedules = (List) storage.getObjectsByQuery( mongoRouterMapper.getMongoTemplateMap().get(router), qb.get(), collectionName, TripSchedule.class, "routeId"); for (TripSchedule toCheck : addedSchedules) { if (!schedules.contains(toCheck)) { schedules.add(toCheck); } } qb = QueryBuilder.start(); if (symbolic) { qb.and("symbolicRouteIds").is(routeId); qb = qb.and("agencyId").is(agencyId); qb = qb.and("daysAdded").is(date); qb = qb.and("fromDate").lessThanEquals(date); qb = qb.and("toDate").greaterThanEquals(date); QueryBuilder fb = QueryBuilder.start(); fb = fb.and("times").is("1"); fb = fb.and("order").is("1"); List<TripSchedule> toRemove = Lists.newArrayList(); for (TripSchedule ts : schedules) { qb = QueryBuilder.start(); qb = qb.and("agencyId").is(agencyId); qb = qb.and("tripId").is(ts.getTripId()); List<AnnotatedTrip> annotatedTrips = (List) storage.getObjectsByQuery( mongoRouterMapper.getMongoTemplateMap().get(router), qb.get(), Constants.ANNOTATED_TRIPS, AnnotatedTrip.class, null, fb.get()); if (!annotatedTrips.isEmpty()) { try { List<String> times = (List) annotatedTrips.get(0).getTimes(); ts.setTimes(times.toArray(new String[times.size()])); ts.setOrder(annotatedTrips.get(0).getOrder()); } catch (Exception e) { e.printStackTrace(); } } else { System.err.println("Annotated trip not found for " + ts.getTripId()); toRemove.add(ts); } } schedules.removeAll(toRemove); } Collections.sort(schedules); return schedules; }
From source file:it.sayservice.platform.smartplanner.otp.OTPStorage.java
License:Apache License
public Object getObjectByField(MongoTemplate template, String key, String value, String collectionName, Class destinationClass) { Object result = null;//from w w w.j a va 2s .c o m DBCollection collection = template.getCollection(collectionName); QueryBuilder qb = QueryBuilder.start(key).is(value); BasicDBObject dbObject = (BasicDBObject) collection.findOne(qb.get()); if (dbObject != null) { dbObject.remove("_id"); ObjectMapper mapper = new ObjectMapper(); result = mapper.convertValue(dbObject, destinationClass); } return result; }
From source file:it.sayservice.platform.smartplanner.otp.OTPStorage.java
License:Apache License
public Object getObjectByField(MongoTemplate template, String key, String value, String collectionName, Class destinationClass, List<String> fieldsToRemove) { Object result = null;/* w w w . j a va2 s. c om*/ DBCollection collection = template.getCollection(collectionName); QueryBuilder qb = QueryBuilder.start(key).is(value); BasicDBObject dbObject = (BasicDBObject) collection.findOne(qb.get()); if (dbObject != null) { dbObject.remove("_id"); for (String toRemove : fieldsToRemove) { dbObject.remove(toRemove); } ObjectMapper mapper = new ObjectMapper(); result = mapper.convertValue(dbObject, destinationClass); } return result; }
From source file:it.sayservice.platform.smartplanner.otp.OTPStorage.java
License:Apache License
public Object getObjectByFields(MongoTemplate template, Map<String, Object> map, String collectionName, Class destinationClass) { DBCollection collection = template.getCollection(collectionName); QueryBuilder qb = QueryBuilder.start(); for (String key : map.keySet()) { qb = qb.and(key).is(map.get(key)); }/*from w w w . java 2 s . c om*/ BasicDBObject dbObject = (BasicDBObject) collection.findOne(qb.get()); if (dbObject != null) { dbObject.remove("_id"); ObjectMapper mapper = new ObjectMapper(); Object result = mapper.convertValue(dbObject, destinationClass); return result; } else { return null; } }
From source file:it.sayservice.platform.smartplanner.otp.OTPStorage.java
License:Apache License
public List<Object> getObjectsByField(MongoTemplate template, String key, String value, String collectionName, Class destinationClass, String orderBy) { DBCollection collection = template.getCollection(collectionName); List<Object> result = new ArrayList<Object>(); QueryBuilder qb = QueryBuilder.start(key).is(value); DBCursor cursor = collection.find(qb.get()); if (orderBy != null) { BasicDBObject sb = new BasicDBObject(); sb.put(orderBy, 1);/* ww w. j a v a 2 s . c om*/ cursor = cursor.sort(sb); } while (cursor.hasNext()) { BasicDBObject dbObject = (BasicDBObject) cursor.next(); dbObject.remove("_id"); ObjectMapper mapper = new ObjectMapper(); Object res = mapper.convertValue(dbObject, destinationClass); result.add(res); } return result; }
From source file:it.sayservice.platform.smartplanner.otp.OTPStorage.java
License:Apache License
public List<Object> getObjectsByFields(MongoTemplate template, Map<String, Object> map, String collectionName, Class destinationClass, String orderBy) { DBCollection collection = template.getCollection(collectionName); List<Object> result = new ArrayList<Object>(); QueryBuilder qb = QueryBuilder.start(); for (String key : map.keySet()) { qb = qb.and(key).is(map.get(key)); }//ww w. j a v a 2 s.c o m DBCursor cursor = collection.find(qb.get()); if (orderBy != null) { BasicDBObject sb = new BasicDBObject(); sb.put(orderBy, 1); cursor = cursor.sort(sb); } while (cursor.hasNext()) { BasicDBObject dbObject = (BasicDBObject) cursor.next(); dbObject.remove("_id"); ObjectMapper mapper = new ObjectMapper(); mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false); Object res = mapper.convertValue(dbObject, destinationClass); result.add(res); } return result; }
From source file:it.sayservice.platform.smartplanner.otp.OTPStorage.java
License:Apache License
public void bulkDelete(MongoTemplate template, String key, Collection<Object> values, String collectionName) { DBCollection collection = template.getCollection(collectionName); QueryBuilder qb = QueryBuilder.start(key).notIn(values); collection.remove(qb.get()); }
From source file:it.sayservice.platform.smartplanner.utils.LegGenerator.java
License:Apache License
public static Object getObjectByField(DB db, String key, String value, DBCollection collection, Class destinationClass) { Object result = null;/*from w ww .j a v a 2 s . co m*/ QueryBuilder qb = QueryBuilder.start(key).is(value); BasicDBObject dbObject = (BasicDBObject) collection.findOne(qb.get()); if (dbObject != null) { dbObject.remove("_id"); ObjectMapper mapper = new ObjectMapper(); result = mapper.convertValue(dbObject, destinationClass); } return result; }
From source file:javasensei.db.managments.RankingManager.java
public boolean colocarRankingDefault() { boolean result = false; try {/*from w w w. j a va2 s . c o m*/ QueryBuilder query = QueryBuilder.start("id").notIn(rankingEjercicios.distinct("idEjercicio", QueryBuilder.start("idAlumno").is(estudiante.getId()).get())); //Obtenemos los id de ejercicios que no estan rankeados por el alumno //Se colocara un valor 2 de default para dicho ranking, de acuerdo a la escala de LIKERT List<DBObject> objects = ejercicios.find(query.get()).toArray(); if (!objects.isEmpty()) { List<DBObject> listObjects = new ArrayList<>(); for (DBObject object : objects) { listObjects.add(BasicDBObjectBuilder.start().add("idEjercicio", object.get("id")) .add("idAlumno", estudiante.getId()).add("ranking", 2) //2 De acuerdo a la escala .get()); } rankingEjercicios.insert(listObjects); updateDataModelEjercicios(); } //Mismo proceso para ranking de recursos QueryBuilder queryRecursos = QueryBuilder.start("id").notIn(rankingRecursos.distinct("idRecurso", QueryBuilder.start("idAlumno").is(estudiante.getId()).get())); List<DBObject> idRecursos = recursos.find(queryRecursos.get()).toArray(); if (!idRecursos.isEmpty()) { List<DBObject> listRankingRecursosSave = new ArrayList<>(); for (DBObject object : idRecursos) { listRankingRecursosSave.add(BasicDBObjectBuilder.start().add("idRecurso", object.get("id")) .add("idAlumno", estudiante.getId()).add("ranking", 2) //2 De acuerdo a la escala .get()); } rankingRecursos.insert(listRankingRecursosSave); updateDataModelRecursos(); } result = true; } catch (Exception ex) { System.err.println(ex); } return result; }