List of usage examples for com.mongodb QueryBuilder start
public static QueryBuilder start(final String key)
From source file:net.atos.entng.wiki.service.WikiServiceMongoImpl.java
License:Open Source License
@Override public void listAllPages(UserInfos user, Handler<Either<String, JsonArray>> handler) { // Query : return pages visible by current user only (i.e. owner or // shared)/* w ww . j a va 2 s . c o m*/ List<DBObject> groups = new ArrayList<>(); groups.add(QueryBuilder.start("userId").is(user.getUserId()).get()); for (String gpId : user.getGroupsIds()) { groups.add(QueryBuilder.start("groupId").is(gpId).get()); } QueryBuilder query = new QueryBuilder().or(QueryBuilder.start("owner.userId").is(user.getUserId()).get(), QueryBuilder.start("shared") .elemMatch(new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get()).get()); // Projection JsonObject projection = new JsonObject(); projection.putNumber("pages.content", 0).putNumber("created", 0); JsonObject sort = new JsonObject().putNumber("pages.title", 1); mongo.find(collection, MongoQueryBuilder.build(query), sort, projection, MongoDbResult.validResultsHandler(handler)); }
From source file:net.atos.entng.wiki.service.WikiServiceMongoImpl.java
License:Open Source License
@Override public void getPage(String idWiki, String idPage, Handler<Either<String, JsonObject>> handler) { QueryBuilder query = QueryBuilder.start("_id").is(idWiki).put("pages._id").is(idPage); // Projection JsonObject matchId = new JsonObject(); matchId.putString("_id", idPage); JsonObject elemMatch = new JsonObject(); elemMatch.putObject("$elemMatch", matchId); JsonObject projection = new JsonObject(); projection.putObject("pages", elemMatch).putNumber("title", 1).putNumber("owner", 1).putNumber("shared", 1); // Send query to event bus mongo.findOne(collection, MongoQueryBuilder.build(query), projection, MongoDbResult.validResultHandler(handler)); }
From source file:net.atos.entng.wiki.service.WikiServiceMongoImpl.java
License:Open Source License
@Override public void createPage(UserInfos user, String idWiki, String newPageId, String pageTitle, String pageContent, boolean isIndex, Handler<Either<String, JsonObject>> handler) { QueryBuilder query = QueryBuilder.start("_id").is(idWiki); // Add new page to array "pages" JsonObject newPage = new JsonObject(); newPage.putString("_id", newPageId).putString("title", pageTitle).putString("content", pageContent) .putString("contentPlain", StringUtils.stripHtmlTag(pageContent)) .putString("author", user.getUserId()).putString("authorName", user.getUsername()) .putObject("modified", MongoDb.now()); MongoUpdateBuilder modifier = new MongoUpdateBuilder(); modifier.push("pages", newPage); // Set new page as index if (isIndex) { modifier.set("index", newPageId); }//from ww w . j a v a2 s .co m mongo.update(collection, MongoQueryBuilder.build(query), modifier.build(), MongoDbResult.validActionResultHandler(handler)); }
From source file:net.atos.entng.wiki.service.WikiServiceMongoImpl.java
License:Open Source License
@Override public void updatePage(UserInfos user, String idWiki, String idPage, String pageTitle, String pageContent, boolean isIndex, boolean wasIndex, Handler<Either<String, JsonObject>> handler) { // Query//from w w w . ja va 2 s . c o m BasicDBObject idPageDBO = new BasicDBObject("_id", idPage); QueryBuilder query = QueryBuilder.start("_id").is(idWiki).put("pages").elemMatch(idPageDBO); // Update MongoUpdateBuilder modifier = new MongoUpdateBuilder(); JsonObject now = MongoDb.now(); modifier.set("pages.$.title", pageTitle).set("pages.$.content", pageContent) .set("pages.$.contentPlain", StringUtils.stripHtmlTag(pageContent)) .set("pages.$.author", user.getUserId()).set("pages.$.authorName", user.getUsername()) .set("pages.$.modified", now).set("modified", now); if (isIndex) { // Set updated page as index modifier.set("index", idPage); } else if (wasIndex) { // Unset index when the value of isIndex has changed from true to false modifier.unset("index"); } mongo.update(collection, MongoQueryBuilder.build(query), modifier.build(), MongoDbResult.validActionResultHandler(handler)); }
From source file:net.atos.entng.wiki.service.WikiServiceMongoImpl.java
License:Open Source License
@Override public void deletePage(String idWiki, String idPage, Handler<Either<String, JsonObject>> handler) { // Query//from w ww. j a v a 2s .c o m BasicDBObject idPageDBO = new BasicDBObject("_id", idPage); QueryBuilder query = QueryBuilder.start("_id").is(idWiki).put("pages").elemMatch(idPageDBO); // Update JsonObject idPageJO = new JsonObject(); idPageJO.putString("_id", idPage); MongoUpdateBuilder modifier = new MongoUpdateBuilder(); modifier.pull("pages", idPageJO); modifier.set("modified", MongoDb.now()); mongo.update(collection, MongoQueryBuilder.build(query), modifier.build(), MongoDbResult.validActionResultHandler(handler)); }
From source file:net.atos.entng.wiki.service.WikiServiceMongoImpl.java
License:Open Source License
/** * {@inheritDoc}//from w ww. j av a 2s .c om */ @Override public void unsetIndex(String idWiki, String idPage, Handler<Either<String, JsonObject>> handler) { QueryBuilder query = QueryBuilder.start("_id").is(idWiki).put("index").is(idPage); MongoUpdateBuilder modifier = new MongoUpdateBuilder(); modifier.unset("index"); mongo.update(collection, MongoQueryBuilder.build(query), modifier.build(), MongoDbResult.validActionResultHandler(handler)); }
From source file:net.atos.entng.wiki.service.WikiServiceMongoImpl.java
License:Open Source License
/** * {@inheritDoc}//from w w w.jav a2s . c o m */ @Override public void getDataForNotification(String idWiki, String idPage, Handler<Either<String, JsonObject>> handler) { QueryBuilder query = QueryBuilder.start("_id").is(idWiki); // Projection JsonObject projection = new JsonObject(); projection.putNumber("owner", 1).putNumber("shared.userId", 1).putNumber("shared.groupId", 1) .putNumber("title", 1); if (idPage != null && !idPage.trim().isEmpty()) { query.put("pages._id").is(idPage); JsonObject matchId = new JsonObject().putString("_id", idPage); JsonObject elemMatch = new JsonObject().putObject("$elemMatch", matchId); projection.putObject("pages", elemMatch); // returns the whole page. Projection on a field (e.g. "title") of a subdocument of an array is not supported by mongo } // Send query to event bus mongo.findOne(collection, MongoQueryBuilder.build(query), projection, MongoDbResult.validResultHandler(handler)); }
From source file:net.atos.entng.wiki.service.WikiServiceMongoImpl.java
License:Open Source License
@Override public void comment(UserInfos user, String idWiki, String idPage, String newCommentId, String comment, Handler<Either<String, JsonObject>> handler) { // Query/*from w ww .j a v a2 s .c o m*/ BasicDBObject idPageDBO = new BasicDBObject("_id", idPage); QueryBuilder query = QueryBuilder.start("_id").is(idWiki).put("pages").elemMatch(idPageDBO); // Add new comment to array "comments" JsonObject newComment = new JsonObject(); newComment.putString("_id", newCommentId).putString("comment", comment) .putString("author", user.getUserId()).putString("authorName", user.getUsername()) .putObject("created", MongoDb.now()); MongoUpdateBuilder modifier = new MongoUpdateBuilder(); modifier.push("pages.$.comments", newComment); mongo.update(collection, MongoQueryBuilder.build(query), modifier.build(), MongoDbResult.validActionResultHandler(handler)); }
From source file:net.atos.entng.wiki.service.WikiServiceMongoImpl.java
License:Open Source License
@Override public void deleteComment(String idWiki, String idPage, String idComment, Handler<Either<String, JsonObject>> handler) { // Query//from w ww .ja v a 2 s . c o m BasicDBObject idPageDBO = new BasicDBObject("_id", idPage); QueryBuilder query = QueryBuilder.start("_id").is(idWiki).put("pages").elemMatch(idPageDBO); // Delete comment from array "comments" JsonObject commentToDelete = new JsonObject(); commentToDelete.putString("_id", idComment); MongoUpdateBuilder modifier = new MongoUpdateBuilder(); modifier.pull("pages.$.comments", commentToDelete); mongo.update(collection, MongoQueryBuilder.build(query), modifier.build(), MongoDbResult.validActionResultHandler(handler)); }
From source file:net.atos.entng.wiki.service.WikiServiceMongoImpl.java
License:Open Source License
@Override public void listRevisions(String wikiId, String pageId, Handler<Either<String, JsonArray>> handler) { QueryBuilder query = QueryBuilder.start("wikiId").is(wikiId).put("pageId").is(pageId); JsonObject sort = new JsonObject().putNumber("date", -1); mongo.find(REVISIONS_COLLECTION, MongoQueryBuilder.build(query), sort, null, MongoDbResult.validResultsHandler(handler)); }