List of usage examples for com.mongodb.util JSON parse
public static Object parse(final String jsonString)
Parses a JSON string and returns a corresponding Java object.
From source file:edu.sjsu.carbonated.mongodbaccessors.MongoDBAlbum.java
License:Apache License
public String getPhoto(String album_id, String photo_id) { String toReturn = ""; BasicDBObject query = new BasicDBObject("$and", JSON.parse("[{\"album_id\":\"" + album_id + "\"},{\"photo_id\":\"" + photo_id + "\"}]")); DBCursor cur = photoColl.find(query, new BasicDBObject("_id", 0)); while (cur.hasNext()) { toReturn += cur.next();/*from w ww. ja v a 2 s . c om*/ } return toReturn; }
From source file:edu.sjsu.carbonated.mongodbaccessors.MongoDBAlbum.java
License:Apache License
/** * Will update the name and description of an album. All Resources must have * a getMap method returning all those that need to be updated only. * <p>//from w ww .j a va 2s . c o m * No null values should be present in the map. * * @param album_id * @param albumRes */ public void updateAlbum(String album_id, AlbumResource albumRes) { BasicDBObject query = new BasicDBObject("$and", JSON .parse("[{\"album_id\":\"" + album_id + "\"},{\"user_id\":\"" + albumRes.getUser_id() + "\"}]")); BasicDBObject update = new BasicDBObject("$set", new BasicDBObject(albumRes.getUpdateAlbumMap())); WriteResult wr = albumColl.update(query, update); // mongodb way of saying there was no record updated... if (wr.getLastError().getString("updatedExisting") == "false") { throw new WebApplicationException(Response.status(404).entity("Album not found").build()); } }
From source file:edu.sjsu.carbonated.mongodbaccessors.MongoDBAlbum.java
License:Apache License
public void updatePhoto(String album_id, String photo_id, AlbumResource albumRes) { // BasicDBObject query = new BasicDBObject("$and", new // BasicDBObject("album_id",album_id).append("photo_id", photo_id)); BasicDBObject query = new BasicDBObject("$and", JSON.parse("[{\"album_id\":\"" + album_id + "\"},{\"photo_id\":\"" + photo_id + "\"}]")); BasicDBObject update = new BasicDBObject("$set", new BasicDBObject(albumRes.getMap())); WriteResult wr = photoColl.update(query, update); if (wr.getLastError().getString("updatedExisting") == "false") { throw new WebApplicationException(Response.status(404).entity("Album/Photo not found").build()); }//from www. java 2 s . co m }
From source file:edu.sjsu.carbonated.mongodbaccessors.MongoDBAlbum.java
License:Apache License
/** * Currently only requires album_id to be passed since Authentication system * is not up. Removes the metadata from the data store. * // w w w. j a va2 s . c om * @param album_id * @param user_id */ public void removeAlbum(String album_id, String user_id) { BasicDBObject removeQuery = new BasicDBObject("$and", JSON.parse("[{\"album_id\":\"" + album_id + "\"},{\"user_id\":\"" + user_id + "\"}]")); WriteResult wr = albumColl.remove(removeQuery); photoColl.remove(new BasicDBObject("album_id", album_id)); if (wr.getLastError().getInt("n") == 0) { throw new WebApplicationException(Response.status(404).build()); } }
From source file:edu.sjsu.carbonated.mongodbaccessors.MongoDBAlbum.java
License:Apache License
public void removePhoto(String user_id, String photo_id) { BasicDBObject removeQuery = new BasicDBObject("$and", JSON.parse("[{\"photo_id\":\"" + photo_id + "\"},{\"user_id\":\"" + user_id + "\"}]")); WriteResult wr = photoColl.remove(removeQuery); if (wr.getLastError().getInt("n") == 0) { throw new WebApplicationException(Response.status(404).build()); }/*from w ww . j ava 2 s . c om*/ }
From source file:edu.sjsu.cohort6.esp.dao.mongodb.CourseDAO.java
License:Open Source License
@Override public synchronized List<Course> fetch(String query) { List<Course> courses = new ArrayList<>(); DBObject dbObjQuery;/* w w w. j a v a2 s . c om*/ DBCursor cursor; if (!(query == null)) { dbObjQuery = (DBObject) JSON.parse(query); cursor = this.getCollection().find(dbObjQuery); } else { cursor = this.getCollection().find(); } List<DBObject> dbObjects = cursor.toArray(); for (DBObject dbObject : dbObjects) { Course course = morphia.fromDBObject(Course.class, dbObject); courses.add(course); } return courses; }
From source file:edu.sjsu.cohort6.esp.dao.mongodb.StudentDAO.java
License:Open Source License
@Override public synchronized List<Student> fetch(String query) { List<Student> students = new ArrayList<>(); DBObject dbObjQuery;/* w w w . jav a 2 s.co m*/ DBCursor cursor; if (!(query == null)) { dbObjQuery = (DBObject) JSON.parse(query); cursor = this.getCollection().find(dbObjQuery); } else { cursor = this.getCollection().find(); } List<DBObject> dbObjects = cursor.toArray(); for (DBObject dbObject : dbObjects) { Student student = morphia.fromDBObject(Student.class, dbObject); students.add(student); } return students; }
From source file:edu.sjsu.cohort6.esp.dao.mongodb.UserDAO.java
License:Open Source License
@Override public List<User> fetch(String query) { List<User> users = new ArrayList<>(); DBObject dbObjQuery;/*from ww w. j a v a 2 s . c o m*/ DBCursor cursor; if (!(query == null)) { dbObjQuery = (DBObject) JSON.parse(query); cursor = this.getCollection().find(dbObjQuery); } else { cursor = this.getCollection().find(); } List<DBObject> dbObjects = cursor.toArray(); for (DBObject dbObject : dbObjects) { User user = morphia.fromDBObject(User.class, dbObject); users.add(user); } return users; }
From source file:edu.sjsu.cohort6.openstack.db.mongodb.QuotaDAO.java
License:Open Source License
@Override public List<Quota> fetch(String query) throws DBException { List<Quota> quotas = new ArrayList<>(); DBObject dbObjQuery;//from w w w. j av a2 s. co m DBCursor cursor; if (!(query == null)) { dbObjQuery = (DBObject) JSON.parse(query); cursor = this.getCollection().find(dbObjQuery); } else { cursor = this.getCollection().find(); } List<DBObject> dbObjects = cursor.toArray(); for (DBObject dbObject : dbObjects) { Quota quota = morphia.fromDBObject(Quota.class, dbObject); quotas.add(quota); } return quotas; }
From source file:edu.sjsu.cohort6.openstack.db.mongodb.ServiceDAO.java
License:Open Source License
@Override public List<Service> fetch(String query) throws DBException { List<Service> services = new ArrayList<>(); DBObject dbObjQuery;/*from w ww. j a v a2 s .co m*/ DBCursor cursor; if (!(query == null)) { dbObjQuery = (DBObject) JSON.parse(query); cursor = this.getCollection().find(dbObjQuery); } else { cursor = this.getCollection().find(); } List<DBObject> dbObjects = cursor.toArray(); for (DBObject dbObject : dbObjects) { Service service = morphia.fromDBObject(Service.class, dbObject); services.add(service); } return services; }