List of usage examples for com.mongodb BasicDBObject append
@Override public BasicDBObject append(final String key, final Object val)
From source file:ezbake.services.centralPurge.helpers.EzCentralPurgeServiceHelpers.java
License:Apache License
public static BasicDBList encodeApplicationStateMap(Map<String, ApplicationPurgeState> appMap) { BasicDBList basicDBList = new BasicDBList(); for (String key : appMap.keySet()) { ApplicationPurgeState applicationPurgeState = appMap.get(key); BasicDBObject dbApplicationPurgeState = new BasicDBObject(); dbApplicationPurgeState.append(ApplicationName, key); dbApplicationPurgeState.append(ApplicationPurgeStateString, encodeApplicationPurgeState(applicationPurgeState)); basicDBList.add(dbApplicationPurgeState); }// w w w .jav a 2 s. c o m return basicDBList; }
From source file:ezbake.services.centralPurge.helpers.EzCentralPurgeServiceHelpers.java
License:Apache License
public static DBObject encodePurgeInfo(PurgeInfo purgeInfo) { BasicDBList basicDBListUris = new BasicDBList(); for (String uri : purgeInfo.getDocumentUris()) { BasicDBObject dbURI = new BasicDBObject(); dbURI.append(URI, uri); basicDBListUris.add(dbURI);/* w w w . j a v a2s.co m*/ } BasicDBList basicDBListUrisNotFound = new BasicDBList(); for (String uriNotFound : purgeInfo.getDocumentUrisNotFound()) { BasicDBObject dbURINotFound = new BasicDBObject(); dbURINotFound.append(URI, uriNotFound); basicDBListUris.add(dbURINotFound); } BasicDBObjectBuilder purgeInfoBuilder = BasicDBObjectBuilder.start().add(PurgeId, purgeInfo.getId()) .add(PurgeBitVector, encodeURISet(purgeInfo.getPurgeDocumentIds())) .add(Description, purgeInfo.getDescription()).add(PurgeName, purgeInfo.getName()) .add(User, purgeInfo.getUser()) .add(CompletelyPurged, encodeURISet(purgeInfo.getCompletelyPurgedDocumentIds())) .add(Resolved, purgeInfo.isResolved()).add(URIsFoundSet, basicDBListUris) .add(URIsNotFoundSet, basicDBListUrisNotFound) .add(TimeStampString, encodeDateTime(purgeInfo.getTimeStamp())); return purgeInfoBuilder.get(); }
From source file:facebook.metrics.FacebookMetricsGroup.java
public static void main(String[] args) { try {/* w w w .j a v a 2 s. c o m*/ // Se crea el libro HSSFWorkbook libro = new HSSFWorkbook(); // Se crea una hoja dentro del libro HSSFSheet hoja = libro.createSheet(); // Se crea una fila dentro de la hoja HSSFRow fila = hoja.createRow(0); // Se crea una celda dentro de la fila HSSFCell celda = fila.createCell(1); // Se crea el contenido de la celda y se mete en ella. HSSFRichTextString texto = new HSSFRichTextString("Metricas de Grupo Cinepolitos"); celda.setCellValue(texto); /************************************/ /*Mongo DB Conection*/ MongoClient mongoClient = new MongoClient("localhost", 27017); DB db = mongoClient.getDB("JavaMongoFacebookGroup"); DBCollection datos = db.getCollection("Datos"); /********************/ Facebook facebook = new FacebookFactory().getInstance(); facebook.setOAuthAppId("603320016402931", "202694064e7a4e77f0c0042b1a16ebd4"); System.out.println(facebook.getOAuthAppAccessToken().getToken()); ResponseList<Post> feedX = facebook.getGroupFeed("17761155026", new Reading().limit(1135)); List<ResponseList<Post>> X = new ArrayList<ResponseList<Post>>(); do { X.add(feedX); Paging<Post> pag1 = feedX.getPaging(); feedX = facebook.fetchNext(pag1); } while (feedX.getPaging() != null); fila = hoja.createRow(2); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString("Id Post:")); celda = fila.createCell(2); celda.setCellValue(new HSSFRichTextString("Fecha del Post:")); celda = fila.createCell(3); celda.setCellValue(new HSSFRichTextString("Usuario que posteo:")); celda = fila.createCell(4); celda.setCellValue(new HSSFRichTextString("Post:")); celda = fila.createCell(5); celda.setCellValue(new HSSFRichTextString("# de Likes del Post:")); celda = fila.createCell(6); celda.setCellValue(new HSSFRichTextString("# de Comentarios del Post:")); celda = fila.createCell(7); celda.setCellValue(new HSSFRichTextString("Comentarios del Post:")); int filasX = 3; for (int j = 0; j < X.size(); j++) { ResponseList<Post> feed = X.get(j); System.out.println(feed.size()); for (int i = 0; i < feed.size(); i++) { System.out.println("Feed: " + i); BasicDBObject obj = new BasicDBObject(); ResponseList<Like> likes = facebook.getPostLikes(feed.get(i).getId(), new Reading().limit(1135)); ResponseList<Comment> comments = facebook.getPostComments(feed.get(i).getId(), new Reading().limit(1135)); obj.append("idPost", feed.get(i).getId() + ""); if (feed.get(i).getMessage() == null) { obj.append("Post", " "); //System.out.println("Null"); } else { obj.append("Post", feed.get(i).getMessage()); } obj.append("Likes", likes.size() + ""); obj.append("Comments", comments.size() + ""); datos.insert(obj); fila = hoja.createRow(filasX); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(feed.get(i).getId() + "")); celda = fila.createCell(2); celda.setCellValue(new HSSFRichTextString(feed.get(i).getCreatedTime() + "")); celda = fila.createCell(3); celda.setCellValue(new HSSFRichTextString(feed.get(i).getFrom().getName())); celda = fila.createCell(4); celda.setCellValue(new HSSFRichTextString(feed.get(i).getMessage())); celda = fila.createCell(5); celda.setCellValue(new HSSFRichTextString(likes.size() + "")); celda = fila.createCell(6); celda.setCellValue(new HSSFRichTextString(comments.size() + "")); filasX++; for (int y = 0; y < comments.size(); y++) { fila = hoja.createRow(filasX); celda = fila.createCell(7); celda.setCellValue(new HSSFRichTextString(comments.get(y).getMessage() + "")); filasX++; } } System.out.println(); } FileOutputStream elFichero = new FileOutputStream("Metricas_Cinepolitos.xls"); libro.write(elFichero); elFichero.close(); } catch (Exception e) { System.err.println("Fatal Error: " + e); } }
From source file:facebook.metrics.FacebookMetricsPage.java
public static void main(String[] args) throws IOException { int varFeed = 0; int filasX = 0; HSSFRow fila = null;/*from w w w.j a v a2s . co m*/ HSSFRow filam = null; HSSFCell celda = null; List<ResponseList<Post>> X = null; int j = 0; int i = 0; HSSFSheet hoja = null; Facebook facebook = null; HSSFWorkbook libro = null; try { // Se crea el libro libro = new HSSFWorkbook(); hoja = libro.createSheet(); fila = hoja.createRow(0); celda = fila.createCell(1); HSSFRichTextString texto = new HSSFRichTextString("Metricas de Infinitum"); celda.setCellValue(texto); /************************************/ /*Mongo DB Conection*/ MongoClient mongoClient = new MongoClient("localhost", 27017); DB db = mongoClient.getDB("JavaMongoFacebookGroup"); DBCollection datos = db.getCollection("Datos"); /********************/ facebook = new FacebookFactory().getInstance(); facebook.setOAuthAppId("603320016402931", "202694064e7a4e77f0c0042b1a16ebd4"); System.out.println(facebook.getOAuthAppAccessToken().getToken()); ResponseList<Post> feedX = facebook.getFeed("216786388331757", new Reading().limit(1000)); X = new ArrayList<ResponseList<Post>>(); int ui = 0; do { X.add(feedX); Paging<Post> pag1 = feedX.getPaging(); feedX = facebook.fetchNext(pag1); System.out.println("" + ui); ui++; } while (feedX.getPaging() != null && ui < 25); fila = hoja.createRow(2); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString("Id Post:")); celda = fila.createCell(2); celda.setCellValue(new HSSFRichTextString("Fecha del Post:")); celda = fila.createCell(3); celda.setCellValue(new HSSFRichTextString("Usuario que posteo:")); celda = fila.createCell(4); celda.setCellValue(new HSSFRichTextString("Post:")); celda = fila.createCell(5); celda.setCellValue(new HSSFRichTextString("# de Likes del Post:")); celda = fila.createCell(6); celda.setCellValue(new HSSFRichTextString("# de Comentarios del Post:")); celda = fila.createCell(7); celda.setCellValue(new HSSFRichTextString("Comentarios del Post:")); celda = fila.createCell(8); celda.setCellValue(new HSSFRichTextString("Tipo de Post:")); filasX = 4; for (j = 0; j < X.size(); j++) { ResponseList<Post> feed = X.get(j); System.out.println(feed.size()); for (i = 0; i < feed.size(); i++) { System.out.println("Feed: " + i); BasicDBObject obj = new BasicDBObject(); ResponseList<Like> likes = facebook.getPostLikes(feed.get(i).getId(), new Reading().limit(1135)); ResponseList<Comment> comments = facebook.getPostComments(feed.get(i).getId(), new Reading().limit(1135)); obj.append("idPost", feed.get(i).getId() + ""); if (feed.get(i).getMessage() == null) { obj.append("Post", " "); //System.out.println("Null"); } else { obj.append("Post", feed.get(i).getMessage()); } obj.append("Likes", likes.size() + ""); obj.append("Comments", comments.size() + ""); datos.insert(obj); filam = hoja.createRow(filasX); celda = filam.createCell(1); celda.setCellValue(new HSSFRichTextString(feed.get(i).getId() + "")); celda = filam.createCell(2); celda.setCellValue(new HSSFRichTextString(feed.get(i).getCreatedTime() + "")); celda = filam.createCell(3); celda.setCellValue(new HSSFRichTextString(feed.get(i).getFrom().getName())); celda = filam.createCell(4); celda.setCellValue(new HSSFRichTextString(feed.get(i).getMessage())); celda = filam.createCell(5); celda.setCellValue(new HSSFRichTextString(likes.size() + "")); celda = filam.createCell(6); celda.setCellValue(new HSSFRichTextString(comments.size() + "")); celda = filam.createCell(8); celda.setCellValue(new HSSFRichTextString(feed.get(i).getType() + "")); filasX++; for (int y = 0; y < comments.size(); y++) { filam = hoja.createRow(filasX); celda = filam.createCell(7); celda.setCellValue(new HSSFRichTextString(comments.get(y).getMessage() + "")); filasX++; } } } FileOutputStream elFichero = new FileOutputStream("Metricas_Infinitum.xls"); libro.write(elFichero); elFichero.close(); } catch (Exception e) { System.err.println("Fatal Error: " + e); FacebookMetricsPage s = new FacebookMetricsPage(); s.porsi(i, j, filasX + 1, filam, celda, facebook, X, hoja, libro); } }
From source file:facebook.metrics.FacebookMetricsPage2.java
public static void main(String[] args) throws IOException { int varFeed = 0; int filasX = 0; HSSFRow fila = null;// w w w. j a v a 2 s. c o m HSSFCell celda = null; List<ResponseList<Post>> X = null; int j = 0; int i = 0; HSSFSheet hoja = null; Facebook facebook = null; HSSFWorkbook libro = null; try { // Se crea el libro libro = new HSSFWorkbook(); // Se crea una hoja dentro del libro hoja = libro.createSheet(); // Se crea una fila dentro de la hoja fila = hoja.createRow(0); // Se crea una celda dentro de la fila celda = fila.createCell(1); // Se crea el contenido de la celda y se mete en ella. HSSFRichTextString texto = new HSSFRichTextString("Metricas de Sony Futbol"); celda.setCellValue(texto); /************************************/ /*Mongo DB Conection*/ MongoClient mongoClient = new MongoClient("localhost", 27017); DB db = mongoClient.getDB("JavaMongoFacebookGroup"); DBCollection datos = db.getCollection("Datos"); /********************/ facebook = new FacebookFactory().getInstance(); facebook.setOAuthAppId("603320016402931", "202694064e7a4e77f0c0042b1a16ebd4"); System.out.println(facebook.getOAuthAppAccessToken().getToken()); ResponseList<Post> feedX = facebook.getFeed("120472297979101", new Reading().limit(1000)); X = new ArrayList<ResponseList<Post>>(); int ui = 0; do { X.add(feedX); Paging<Post> pag1 = feedX.getPaging(); feedX = facebook.fetchNext(pag1); System.out.println("" + ui); ui++; } while (feedX.getPaging() != null && ui < 5); fila = hoja.createRow(2); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString("Id Post:")); celda = fila.createCell(2); celda.setCellValue(new HSSFRichTextString("Fecha del Post:")); celda = fila.createCell(3); celda.setCellValue(new HSSFRichTextString("Usuario que posteo:")); celda = fila.createCell(4); celda.setCellValue(new HSSFRichTextString("Post:")); celda = fila.createCell(5); celda.setCellValue(new HSSFRichTextString("# de Likes del Post:")); celda = fila.createCell(6); celda.setCellValue(new HSSFRichTextString("# de Comentarios del Post:")); celda = fila.createCell(7); celda.setCellValue(new HSSFRichTextString("Comentarios del Post:")); celda = fila.createCell(8); celda.setCellValue(new HSSFRichTextString("Tipo de Post:")); filasX = 3; for (j = 0; j < X.size(); j++) { ResponseList<Post> feed = X.get(j); System.out.println(feed.size()); for (i = 0; i < feed.size(); i++) { System.out.println("Feed: " + i); BasicDBObject obj = new BasicDBObject(); ResponseList<Like> likes = facebook.getPostLikes(feed.get(i).getId(), new Reading().limit(1135)); ResponseList<Comment> comments = facebook.getPostComments(feed.get(i).getId(), new Reading().limit(1135)); obj.append("idPost", feed.get(i).getId() + ""); if (feed.get(i).getMessage() == null) { obj.append("Post", " "); //System.out.println("Null"); } else { obj.append("Post", feed.get(i).getMessage()); } obj.append("Likes", likes.size() + ""); obj.append("Comments", comments.size() + ""); datos.insert(obj); fila = hoja.createRow(filasX); celda = fila.createCell(1); celda.setCellValue(new HSSFRichTextString(feed.get(i).getId() + "")); celda = fila.createCell(2); celda.setCellValue(new HSSFRichTextString(feed.get(i).getCreatedTime() + "")); celda = fila.createCell(3); celda.setCellValue(new HSSFRichTextString(feed.get(i).getFrom().getName())); celda = fila.createCell(4); celda.setCellValue(new HSSFRichTextString(feed.get(i).getMessage())); celda = fila.createCell(5); celda.setCellValue(new HSSFRichTextString(likes.size() + "")); celda = fila.createCell(6); celda.setCellValue(new HSSFRichTextString(comments.size() + "")); celda = fila.createCell(8); celda.setCellValue(new HSSFRichTextString(feed.get(i).getType() + "")); filasX++; for (int y = 0; y < comments.size(); y++) { fila = hoja.createRow(filasX); celda = fila.createCell(7); celda.setCellValue(new HSSFRichTextString(comments.get(y).getMessage() + "")); filasX++; } } } FileOutputStream elFichero = new FileOutputStream("Metricas_SonyFutbol.xls"); libro.write(elFichero); elFichero.close(); } catch (Exception e) { System.err.println("Fatal Error: " + e); FacebookMetricsPage s = new FacebookMetricsPage(); s.porsi(i, j, filasX, fila, celda, facebook, X, hoja, libro); } }
From source file:firesystem.ConfigPopup.java
public void updateMobile(String mobile) { BasicDBObject newDocument = new BasicDBObject(); newDocument.append("$set", new BasicDBObject().append("mobile", mobile)); users.update(FireSensor.findDocumentById(sensor.getJsonId(), users), newDocument); }
From source file:firesystem.ConfigPopup.java
public void updateEmail(String email) { BasicDBObject newDocument = new BasicDBObject(); newDocument.append("$set", new BasicDBObject().append("email", email)); users.update(FireSensor.findDocumentById(sensor.getJsonId(), users), newDocument); }
From source file:FloodPrototype.FloodAdapter.java
License:Apache License
private int startFlood2D(FloodTask task) throws IOException { BufferedReader reader = sshCon[0].in(); sshCon[0].out().println("flood2d"); sshCon[0].out().println("echo '\004'"); sshCon[0].out().flush();//www .j ava 2 s. co m String line = reader.readLine(); while (line != null && !line.equals("\004")) { /* check if output line contains progress report */ /* TODO */ Matcher matcher = Pattern.compile("Elapsed:\\s*(\\d*.\\d*)s\\s*(\\d*.\\d*)%").matcher(line); if (matcher.find()) { float progress = Float.valueOf(matcher.group(2)); float calcTime = Float.valueOf(matcher.group(1)); if (progress == 100.0f) { /* TODO: create water height kml + insert into DB */ System.out.println("Finished"); } System.out.println(matcher.group(1) + " - " + matcher.group(2)); /* DB object to find current earthquake ID */ BasicDBObject obj = new BasicDBObject("_id", task.id); /* create sub-object that is used to update the current progress */ BasicDBObject process = new BasicDBObject(); process.put("progress", progress); process.put("calcTime", calcTime); process.put("resources", this.hardware); BasicDBObject setter = new BasicDBObject("process", process); /* build update query */ BasicDBObject update = new BasicDBObject("$set", setter); /* update the DB entry with the given ID*/ System.out.println(obj); System.out.println(update); db.getCollection("floodsims").update(obj, update); /* create DB object that holds all event data */ BasicDBObject event = new BasicDBObject(); event.append("id", task.id); event.append("user", task.user.objId); event.append("timestamp", new Date()); event.append("event", "progress"); event.append("class", "flood"); event.append("process", process); /* create reference event that should be updated */ BasicDBObject refEvent = new BasicDBObject("id", task.id); refEvent.put("event", "progress"); refEvent.put("class", "flood"); /* update the reference event with the new data */ db.getCollection("events").update(refEvent, event, true, false); } line = reader.readLine(); } return 0; }
From source file:FloodPrototype.FloodProvider.java
License:Apache License
@Override public List<DBObject> fetch(User user, Date maxTimestamp, int limit) { List<DBObject> list = new ArrayList<DBObject>(); BasicDBObject query = new BasicDBObject("user", user.objId); query.append("timestamp", new BasicDBObject("$lte", maxTimestamp)); DBCursor cursor = db.getCollection("floodsims").find(query).sort(new BasicDBObject("timestamp", -1)) .limit(limit);//from ww w . j a v a 2 s .c o m list = cursor.toArray(); return list; }
From source file:FloodPrototype.FloodProvider.java
License:Apache License
@Override public List<DBObject> update(User user, Date minTimestamp, Date maxTimestamp) { List<DBObject> list = new ArrayList<DBObject>(); BasicDBList timestamp = new BasicDBList(); timestamp.add(new BasicDBObject("timestamp", new BasicDBObject("$gt", minTimestamp))); timestamp.add(new BasicDBObject("timestamp", new BasicDBObject("$lte", maxTimestamp))); BasicDBObject query = new BasicDBObject("$and", timestamp); query.append("class", "flood"); DBCursor cursor = db.getCollection("events").find(query).sort(new BasicDBObject("timestamp", -1)); for (DBObject obj : cursor) { //if( obj.get("event").equals("new") ) { BasicDBObject objQuery = new BasicDBObject("_id", obj.get("id")); obj.put("data", db.getCollection("floodsims").findOne(objQuery)); list.add(obj);/*w w w .j a v a 2 s . c o m*/ //} } return list; }