List of usage examples for com.mongodb BasicDBObject toString
@SuppressWarnings("deprecation") public String toString()
Returns a JSON serialization of this object
The output will look like: {"a":1, "b":["x","y","z"]} }
From source file:fr.gouv.vitam.cases.ElasticSearchAccess.java
License:Open Source License
/** * Should be called only once saved (last time), but for the moment let the object as it is, next should remove not indexable * entries//w ww . j a va 2 s . c o m * * @param dbvitam * @param model * @param indexes * @param bson * @return the number of DAip incorporated (0 if none) */ public static final int addEsIndex(final CassandraAccess dbvitam, final String model, final Map<String, String> indexes, final BSONObject bson) { BasicDBObject maip = getFiltered(bson); final String id = maip.getString(VitamType.ID); maip.removeField(VitamType.ID); // System.err.println(maip); // System.err.println(this); indexes.put(id, maip.toString()); int nb = 0; if (indexes.size() > GlobalDatas.LIMIT_ES_NEW_INDEX) { nb = indexes.size(); dbvitam.addEsEntryIndex(indexes, model); // dbvitam.flushOnDisk(); indexes.clear(); System.out.print("o"); } maip.clear(); maip = null; return nb; }
From source file:fr.gouv.vitam.mdbes.ElasticSearchAccess.java
License:Open Source License
/** * // w w w . java2 s .c o m * @param dbvitam * @param model * @param bson * @return True if inserted in ES */ public static final boolean addEsIndex(final MongoDbAccess dbvitam, final String model, final BSONObject bson) { BasicDBObject maip = getFiltered(bson); final String id = maip.getString(VitamType.ID); maip.removeField(VitamType.ID); return dbvitam.addEsEntryIndex(model, id, maip.toString()); }
From source file:fr.gouv.vitam.mdbes.ElasticSearchAccess.java
License:Open Source License
/** * Should be called only once saved (last time), but for the moment let the object as it is, next should remove not indexable * entries/*from w w w.ja v a 2s .com*/ * * @param dbvitam * @param model * @param indexes * @param bson * @return the number of DAip incorporated (0 if none) */ public static final int addEsIndex(final MongoDbAccess dbvitam, final String model, final Map<String, String> indexes, final BSONObject bson) { BasicDBObject maip = getFiltered(bson); final String id = maip.getString(VitamType.ID); maip.removeField(VitamType.ID); // System.err.println(maip); // System.err.println(this); indexes.put(id, maip.toString()); int nb = 0; if (indexes.size() > GlobalDatas.LIMIT_ES_NEW_INDEX) { nb = indexes.size(); dbvitam.addEsEntryIndex(indexes, model); // dbvitam.flushOnDisk(); indexes.clear(); System.out.print("o"); } maip.clear(); maip = null; return nb; }
From source file:hulop.hokoukukan.utils.MongoAdapter.java
License:Open Source License
@Override public JSONArray getLogs(String clientId, String start, String end, String skip, String limit, String event) { BasicDBObject query = new BasicDBObject(); if (clientId != null) { query.append("client", clientId); }/*from ww w.j av a 2s. co m*/ new BasicDBObject("Date", new BasicDBObject("$gt", start).append("$lte", end)); BasicDBObject timeRange = new BasicDBObject(); if (start != null) { timeRange.append("$gte", Long.parseLong(start)); } if (end != null) { timeRange.append("$lt", Long.parseLong(end)); } if (timeRange.size() > 0) { query.append("timestamp", timeRange); } if (event != null) { query.append("event", event); } System.out.println(query.toString()); DBCursor cursor = logCol.find(query); if (skip != null) { cursor = cursor.skip(Integer.parseInt(skip)); } if (limit != null) { cursor = cursor.limit(Integer.parseInt(limit)); } JSONArray result = new JSONArray(); try { while (cursor.hasNext()) { result.add(new JSONObject(cursor.next().toString())); } } catch (JSONException e) { e.printStackTrace(); } return result; }
From source file:kiaanfx.Kiaanfx.java
private static void getBuy() { try {/*w w w .j a v a 2 s .co m*/ MongoClient mongoClient = new MongoClient("localhost", 27017); DB db = mongoClient.getDB("kiaan"); DBCollection coll = db.getCollection("buy"); //aggregate DBObject unwind = new BasicDBObject("$unwind", "$items"); //$group DBObject group_id = new BasicDBObject("_id", "$_id"); group_id.put("num", "$num"); group_id.put("person_id", "$person_id"); group_id.put("discount", "$discount"); group_id.put("increase", "$increase"); //$group -> $multiply BasicDBList args = new BasicDBList(); args.add("$items.value"); args.add("$items.price"); DBObject multiply = new BasicDBObject("$multiply", args); //$group -> $sum // DBObject group_sum = new BasicDBObject("$sum", multiply); DBObject group_field = new BasicDBObject(); group_field.put("_id", group_id); group_field.put("total", new BasicDBObject("$sum", multiply)); DBObject group = new BasicDBObject("$group", group_field); //$project DBObject project_field = new BasicDBObject("_id", "$_id._id"); project_field.put("person_id", "$_id.person_id"); project_field.put("num", "$_id.num"); BasicDBList arr = new BasicDBList(); arr.add("$total"); arr.add("$_id.discount"); arr.add("$_id.increase"); DBObject field_add = new BasicDBObject("$add", arr); project_field.put("sum", field_add); DBObject project = new BasicDBObject("$project", project_field); DBObject sort = new BasicDBObject("$sort", new BasicDBObject("_id", 1)); List<DBObject> pipeline = Arrays.asList(unwind, group, project, sort); // AggregationOutput output = coll.aggregate(pipeline); // for (DBObject result : output.results()) { // System.out.println(result); // } AggregationOptions aggregationOptions = AggregationOptions.builder().batchSize(100) .outputMode(AggregationOptions.OutputMode.CURSOR).allowDiskUse(true).build(); BasicDBObject dbo = new BasicDBObject(); BasicDBList dbl = new BasicDBList(); Cursor cursor = coll.aggregate(pipeline, aggregationOptions); // DBCollection person_col = db.getCollection("persons"); // BasicDBObject query = new BasicDBObject("items.personId",1); BasicDBObject fields = new BasicDBObject("items.$", 1).append("_id", false); // BasicDBList l_per = (BasicDBList) person_col.findOne(query, fields).get("items"); // BasicDBObject[] lightArr = l_per.toArray(new BasicDBObject[0]); // System.out.println(lightArr[0].get("_id")); // System.out.println(lightArr[0].get("first_name")); // BasicDBList result = new BasicDBList(); while (cursor.hasNext()) { dbo = (BasicDBObject) cursor.next(); // System.out.println(dbo.toString()); DBObject query = new BasicDBObject("items._id", (ObjectId) dbo.get("person_id")); BasicDBList lst_person = (BasicDBList) person_col.findOne(query, fields).get("items"); BasicDBObject[] lightArr = lst_person.toArray(new BasicDBObject[0]); // System.out.println(lightArr[0].get("first_name")); Date date = ((ObjectId) lightArr[0].get("_id")).getDate(); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); persianCalendar persianCalendar = new persianCalendar(calendar); dbo.put("date", persianCalendar.getNumericDateFormatWithTime()); dbo.put("personId", lightArr[0].get("personId").toString()); dbo.put("first_name", lightArr[0].get("first_name").toString()); dbo.put("last_name", lightArr[0].get("last_name").toString()); data.add(new Person(dbo.get("num").toString(), dbo.get("date").toString(), dbo.get("personId").toString(), dbo.get("first_name").toString(), dbo.get("last_name").toString())); // buy_data.add(new buys(dbo.get("num").toString(), // dbo.get("date").toString(), // dbo.get("personId").toString(), // dbo.get("first_name").toString(), // dbo.get("last_name").toString(), // dbo.get("sum").toString() // )); dbo.remove("person_id"); // result.add(dbo); // System.out.println(dbo.get("first_name")); } System.out.println(dbo.toString()); } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); } }
From source file:MDBInt.DBMongo.java
License:Apache License
/** * * @param dbName/* w w w .jav a2 s .co m*/ * @param userName * @param password * @param cloudID * @return jsonObject that contains credential for a specified cloud or null */ public String getFederatedCredential(String dbName, String userName, String password, String cloudID) { DB dataBase = this.getDB(dbName); DBCollection collezione = this.getCollection(dataBase, "credentials"); DBObject federationUser = null; BasicDBObject query = new BasicDBObject("federationUser", userName); BasicDBList credList; Iterator it; BasicDBObject obj; query.append("federationPassword", this.toMd5(password)); // System.out.println("password: "+this.toMd5(password)); federationUser = collezione.findOne(query); if (federationUser == null) { return null; } credList = (BasicDBList) federationUser.get("crediantialList"); it = credList.iterator(); while (it.hasNext()) { obj = (BasicDBObject) it.next(); if (obj.containsValue(cloudID)) { return obj.toString(); } } return null; }
From source file:MDBInt.DBMongo.java
License:Apache License
/** * This use only token. It will be/* w ww .ja v a 2s. co m*/ * * @param dbName * @param, this is an UUID generated from simple_IDM when a new * Federation user is added. * @param cloudID * @return * @author gtricomi */ public String getFederatedCredential(String dbName, String token, String cloudID) { DB dataBase = this.getDB(dbName); DBCollection collezione = this.getCollection(dataBase, "credentials"); DBObject federationUser = null; BasicDBObject query = new BasicDBObject("token", token); BasicDBList credList; Iterator it; BasicDBObject obj; federationUser = collezione.findOne(query); if (federationUser == null) { return null; } credList = (BasicDBList) federationUser.get("crediantialList"); it = credList.iterator(); while (it.hasNext()) { obj = (BasicDBObject) it.next(); if (obj.containsValue(cloudID)) { return obj.toString(); } } return null; }
From source file:MDBInt.DBMongo.java
License:Apache License
/** * Returns generic federation infoes./*from ww w.ja v a 2s . c om*/ * * @param dbName * @param token, this is an internal token? * @return * @author gtricomi */ public String getFederationCredential(String dbName, String token) { DB dataBase = this.getDB(dbName); DBCollection collezione = this.getCollection(dataBase, "credentials"); DBObject federationUser = null; BasicDBObject query = new BasicDBObject("token", token); federationUser = collezione.findOne(query); if (federationUser == null) { return null; } BasicDBObject bo = new BasicDBObject(); bo.append("federationUser", (String) federationUser.get("federationUser")); bo.append("federationPassword", (String) federationUser.get("federationPassword")); return bo.toString(); }
From source file:MDBInt.DBMongo.java
License:Apache License
public void insertTemplateInfo(String db, String id, String templateName, Float version, String user, String templateRef) {/*ww w. j av a 2s .c o m*/ BasicDBObject obj; obj = new BasicDBObject(); obj.append("id", id); obj.append("templateName", templateName); obj.append("version", version); obj.append("user", user); obj.append("templateRef", templateRef); this.insert(db, "templateInfo", obj.toString()); }
From source file:MDBInt.DBMongo.java
License:Apache License
/** * Returns generic federation infoes.//from w w w. j a va 2s . c o m * @param dbName * @param value * @param type * @return */ public String getFederationCredential(String dbName, String value, String type) { DB dataBase = this.getDB(dbName); DBCollection collezione = this.getCollection(dataBase, "credentials"); DBObject federationUser = null; BasicDBObject query = new BasicDBObject(type, value); BasicDBList credList; Iterator it; BasicDBObject obj; String result = "{"; federationUser = collezione.findOne(query); if (federationUser == null) { return null; } BasicDBObject bo = new BasicDBObject(); bo.append("federationUser", (String) federationUser.get("federationUser")); bo.append("federationPassword", (String) federationUser.get("federationPassword")); return bo.toString();//result; }