List of usage examples for com.mongodb DBObject containsField
boolean containsField(String s);
From source file:xbdd.webapp.resource.feature.Favourites.java
License:Apache License
@GET @Path("/") @Produces("application/json") public DBObject getSummaryOfAllReports(@Context final HttpServletRequest req) { final DB db = this.client.getDB("bdd"); final DBCollection collection = db.getCollection("summary"); final DBCollection usersCollection = db.getCollection("users"); final BasicDBObject user = new BasicDBObject(); user.put("user_id", req.getRemoteUser()); final DBObject blank = new BasicDBObject(); DBObject uDoc = usersCollection.findAndModify(user, blank, blank, false, new BasicDBObject("$setOnInsert", new BasicDBObject("favourites", new BasicDBObject())), true, true);//from w ww . j a va2 s. c o m DBObject userFavourites; if (uDoc.containsField("favourites")) { userFavourites = (DBObject) uDoc.get("favourites"); } else { userFavourites = new BasicDBObject(); } final DBCursor cursor = collection.find(); try { final BasicDBList returns = new BasicDBList(); DBObject doc; while (cursor.hasNext()) { doc = cursor.next(); String product = ((String) ((DBObject) doc.get("coordinates")).get("product")); if (userFavourites.containsField(product) && (boolean) userFavourites.get(product)) { doc.put("favourite", userFavourites.get(product)); returns.add(doc); } } return returns; } finally { cursor.close(); } }
From source file:xbdd.webapp.resource.feature.Recents.java
License:Apache License
/** * Uses the '.+' regexp on featureId to allow for symbols such as slashes in the id * /*from w w w . ja va 2 s . c o m*/ * @param String id The featureId to get the history for * @return Response Either a 200 response or a 500 */ @PUT @Path("/feature/{product}/{major}.{minor}.{servicePack}/{build}/{id:.+}") @Produces("application/json") public Response addFeatureToRecents(@QueryParam("name") final String featureName, @BeanParam Coordinates coordinates, @PathParam("id") final String featureID, @Context final HttpServletRequest req) { final BasicDBObject featureDetails = new BasicDBObject("name", featureName); featureDetails.put("product", coordinates.getProduct()); featureDetails.put("version", coordinates.getVersionString()); featureDetails.put("build", coordinates.getBuild()); featureDetails.put("id", featureID); final DB db = this.client.getDB("bdd"); final DBCollection collection = db.getCollection("users"); final BasicDBObject user = new BasicDBObject(); user.put("user_id", req.getRemoteUser()); final DBObject blank = new BasicDBObject(); DBObject doc = collection.findAndModify(user, blank, blank, false, new BasicDBObject("$set", user), true, true); if (doc.containsField("recentFeatures")) { BasicDBList featureArray = (BasicDBList) doc.get("recentFeatures"); if (featureArray.contains(featureDetails)) { featureArray.remove(featureDetails); featureArray.add(featureDetails); collection.update(user, new BasicDBObject("$set", new BasicDBObject("recentFeatures", featureArray))); } else { if (featureArray.size() >= 5) { collection.update(user, new BasicDBObject("$pop", new BasicDBObject("recentFeatures", "-1"))); } collection.update(user, new BasicDBObject("$addToSet", new BasicDBObject("recentFeatures", featureDetails))); } } else { collection.update(user, new BasicDBObject("$addToSet", new BasicDBObject("recentFeatures", featureDetails))); } return Response.ok().build(); }
From source file:xbdd.webapp.resource.feature.Recents.java
License:Apache License
@PUT @Path("/build/{product}/{major}.{minor}.{servicePack}/{build}") @Produces("application/json") public Response addBuildToRecents(@BeanParam Coordinates coordinates, @Context final HttpServletRequest req) { DBObject buildCoords = coordinates.getReportCoordinates(); final DB db = this.client.getDB("bdd"); final DBCollection collection = db.getCollection("users"); final BasicDBObject user = new BasicDBObject(); user.put("user_id", req.getRemoteUser()); final DBObject blank = new BasicDBObject(); DBObject doc = collection.findAndModify(user, blank, blank, false, new BasicDBObject("$set", user), true, true);/*from w ww . j av a 2s . c o m*/ if (doc.containsField("recentBuilds")) { BasicDBList buildArray = (BasicDBList) doc.get("recentBuilds"); if (buildArray.contains(buildCoords)) { //BasicDBObject toMove = (BasicDBObject) featureArray.get(featureArray.indexOf(featureDetails)); buildArray.remove(buildCoords); buildArray.add(buildCoords); collection.update(user, new BasicDBObject("$set", new BasicDBObject("recentBuilds", buildArray))); } else { if (buildArray.size() >= 5) { collection.update(user, new BasicDBObject("$pop", new BasicDBObject("recentBuilds", "-1"))); } collection.update(user, new BasicDBObject("$addToSet", new BasicDBObject("recentBuilds", buildCoords))); } } else { collection.update(user, new BasicDBObject("$addToSet", new BasicDBObject("recentBuilds", buildCoords))); } return Response.ok().build(); }
From source file:xbdd.webapp.resource.feature.Recents.java
License:Apache License
@GET @Path("/builds") @Produces("application/json") public DBObject getRecentBuilds(@Context final HttpServletRequest req) { final DB db = this.client.getDB("bdd"); final DBCollection collection = db.getCollection("users"); final BasicDBObject user = new BasicDBObject("user_id", req.getRemoteUser()); final DBCursor cursor = collection.find(user); DBObject doc; BasicDBList ret = new BasicDBList(); if (cursor.hasNext()) { doc = cursor.next();/*from w w w .ja v a 2 s.co m*/ if (doc.containsField("recentBuilds")) { ret = (BasicDBList) doc.get("recentBuilds"); } } return new BasicDBObject("recents", ret); }
From source file:xbdd.webapp.resource.feature.Recents.java
License:Apache License
@GET @Path("/features") @Produces("application/json") public DBObject getRecentFeatures(@Context final HttpServletRequest req) { final DB db = this.client.getDB("bdd"); final DBCollection collection = db.getCollection("users"); final BasicDBObject user = new BasicDBObject("user_id", req.getRemoteUser()); final DBCursor cursor = collection.find(user); DBObject doc; BasicDBList ret = new BasicDBList(); if (cursor.hasNext()) { doc = cursor.next();//w ww. j av a 2s . c om if (doc.containsField("recentFeatures")) { ret = (BasicDBList) doc.get("recentFeatures"); } } return new BasicDBObject("recents", ret); }
From source file:xbdd.webapp.resource.feature.Report.java
License:Apache License
@SuppressWarnings("unchecked") @GET/* ww w. j a v a 2s.co m*/ @Produces("application/json") public DBObject getSummaryOfAllReports(@Context final HttpServletRequest req) { final DB db = this.client.getDB("bdd"); final DBCollection collection = db.getCollection("summary"); final DBCollection usersCollection = db.getCollection("users"); final BasicDBObject user = new BasicDBObject(); user.put("user_id", req.getRemoteUser()); final DBCursor userCursor = usersCollection.find(user); DBObject userFavourites; if (userCursor.count() != 1) { userFavourites = new BasicDBObject(); } else { final DBObject uDoc = userCursor.next(); if (uDoc.containsField("favourites")) { userFavourites = (DBObject) uDoc.get("favourites"); } else { userFavourites = new BasicDBObject(); } } final DBCursor cursor = collection.find(); try { final BasicDBList returns = new BasicDBList(); DBObject doc; while (cursor.hasNext()) { doc = cursor.next(); final String product = ((String) ((DBObject) doc.get("coordinates")).get("product")); if (userFavourites.containsField(product)) { doc.put("favourite", userFavourites.get(product)); } else { doc.put("favourite", false); } returns.add(doc); } return returns; } finally { cursor.close(); } }
From source file:xbdd.webapp.resource.feature.UploadAttachment.java
License:Apache License
@SuppressWarnings("unchecked") @POST//from w w w . ja va 2s.com @Path("/{elementId}/{report}/{version}/{build}/{id}") @Consumes(MediaType.MULTIPART_FORM_DATA) public String setAttachment(@PathParam("report") final String report, @PathParam("version") final String version, @PathParam("build") final String build, @PathParam("id") final String id, @PathParam("elementId") final String elementId, @FormDataParam("attachmentfile") final File file, @FormDataParam("attachmentfile") final FormDataBodyPart body, @Context final HttpServletRequest req) throws IOException { try (final InputStream is = new FileInputStream(file.getAbsolutePath())) { final String elementIdMod = elementId.replace("&2F", "/"); final DB gridDB = this.client.getDB("grid"); final GridFS gridFS = new GridFS(gridDB); final GridFSInputFile gridFile = gridFS.createFile(is); gridFile.setFilename( body.getMediaType().toString().split("/")[0] + ".x1.mu." + UUID.randomUUID().toString()); gridFile.setContentType(body.getMediaType().toString()); gridFile.save(); final DB bddDB = this.client.getDB("bdd"); final DBCollection collection = bddDB.getCollection("features"); // // get object final String featureId = report + "/" + version + "/" + build + "/" + id; final DBObject feature = collection.findOne(new BasicDBObject("_id", featureId)); final BasicDBList elements = (BasicDBList) feature.get("elements"); String scenarioName = ""; if (elements != null) { for (int i = 0; i < elements.size(); i++) { final DBObject scenario = (DBObject) elements.get(i); if (scenario.get("id").equals(id + ";" + elementIdMod)) { scenarioName = (String) scenario.get("name"); // get steps final BasicDBList steps = (BasicDBList) scenario.get("steps"); final DBObject laststep = (DBObject) steps.get(steps.size() - 1); List<String> embeddings = new ArrayList<String>(); if (laststep.containsField("embeddings")) { embeddings = (ArrayList<String>) laststep.get("embeddings"); } embeddings.add(gridFile.getFilename()); // get existng then add to them laststep.put("embeddings", embeddings); steps.set(steps.size() - 1, laststep); scenario.put("steps", steps); elements.set(i, scenario); } } } feature.put("elements", elements); feature.put("statusLastEditedBy", req.getRemoteUser()); feature.put("lastEditOn", new Date()); // add edit update BasicDBList edits = (BasicDBList) feature.get("edits"); if (edits == null) { edits = new BasicDBList(); } final BasicDBList temp = new BasicDBList(); temp.add(new BasicDBObject().append("id", "embeddings").append("added", gridFile.getFilename()) .append("removed", null)); final BasicDBList masks = new BasicDBList(); masks.add(new BasicDBObject().append("scenario", scenarioName).append("changes", temp)); final BasicDBObject edit = new BasicDBObject().append("name", feature.get("statusLastEditedBy")) .append("date", feature.get("lastEditOn")).append("prev", feature.get("calculatedStatus")) .append("curr", feature.get("calculatedStatus")).append("stepChanges", masks); final BasicDBList newEdits = new BasicDBList(); newEdits.add(edit); newEdits.addAll(edits); feature.put("edits", newEdits); collection.save(feature); return gridFile.getFilename(); } }
From source file:xml.dom.DomBuilder.java
private Node generateMovieNode(DBObject DBmovie) { Element movie = doc.createElementNS("http://moviesRT", "movie"); if (DBmovie.containsField("_id")) textChild(DBmovie, movie, "_id"); if (DBmovie.containsField("title")) textChild(DBmovie, movie, "title"); if (DBmovie.containsField("genres")) genreChild(DBmovie, movie);/*from www . j a v a2 s . com*/ if (DBmovie.containsField("overview")) textChild(DBmovie, movie, "overview"); if (DBmovie.containsField("vote_average")) numberChild(DBmovie, movie, "vote_average"); if (DBmovie.containsField("vote_count")) numberChild(DBmovie, movie, "vote_count"); if (DBmovie.containsField("release_date")) textChild(DBmovie, movie, "release_date"); if (DBmovie.containsField("runtime")) numberChild(DBmovie, movie, "runtime"); if (DBmovie.containsField("spoken_languages")) languagesChild(DBmovie, movie); if (DBmovie.containsField("status")) textChild(DBmovie, movie, "status"); if (DBmovie.containsField("tagline")) textChild(DBmovie, movie, "tagline"); if (DBmovie.containsField("actors")) actorsChild(DBmovie, movie); if (DBmovie.containsField("directors")) directorsChild(DBmovie, movie); if (DBmovie.containsField("production_companies")) companiesChild(DBmovie, movie); if (DBmovie.containsField("original_title")) textChild(DBmovie, movie, "original_title"); if (DBmovie.containsField("budget")) numberChild(DBmovie, movie, "budget"); if (DBmovie.containsField("revenue")) numberChild(DBmovie, movie, "revenue"); if (DBmovie.containsField("production_countries")) countriesChild(DBmovie, movie); if (DBmovie.containsField("homepage")) textChild(DBmovie, movie, "homepage"); if (DBmovie.containsField("poster_path")) textChild(DBmovie, movie, "poster_path"); return movie; }