List of usage examples for com.mongodb QueryBuilder start
public static QueryBuilder start(final String key)
From source file:net.atos.entng.calendar.services.impl.EventServiceMongoImpl.java
License:Open Source License
@Override public void retrieveByIcsUid(String calendarId, String icsUid, UserInfos user, Handler<Either<String, JsonObject>> handler) { // Query/*from ww w .j av a 2 s . co m*/ QueryBuilder query = QueryBuilder.start("icsUid").is(icsUid); query.put("calendar").is(calendarId); // Projection JsonObject projection = new JsonObject(); mongo.findOne(this.collection, MongoQueryBuilder.build(query), projection, validResultHandler(handler)); }
From source file:net.atos.entng.calendar.services.impl.EventServiceMongoImpl.java
License:Open Source License
@Override public void update(String calendarId, String eventId, JsonObject body, UserInfos user, Handler<Either<String, JsonObject>> handler) { // Query/*from w ww. j a v a2 s.co m*/ QueryBuilder query = QueryBuilder.start("_id").is(eventId); query.put("calendar").is(calendarId); // Clean data body.removeField("_id"); body.removeField("calendar"); // Modifier MongoUpdateBuilder modifier = new MongoUpdateBuilder(); for (String attr : body.getFieldNames()) { modifier.set(attr, body.getValue(attr)); } modifier.set("modified", MongoDb.now()); mongo.update(this.collection, MongoQueryBuilder.build(query), modifier.build(), validActionResultHandler(handler)); }
From source file:net.atos.entng.calendar.services.impl.EventServiceMongoImpl.java
License:Open Source License
@Override public void delete(String calendarId, String eventId, UserInfos user, Handler<Either<String, JsonObject>> handler) { QueryBuilder query = QueryBuilder.start("_id").is(eventId); query.put("calendar").is(calendarId); mongo.delete(this.collection, MongoQueryBuilder.build(query), validActionResultHandler(handler)); }
From source file:net.atos.entng.calendar.services.impl.EventServiceMongoImpl.java
License:Open Source License
@Override public void getCalendarEventById(String eventId, Handler<Either<String, JsonObject>> handler) { JsonObject projection = new JsonObject(); QueryBuilder query = QueryBuilder.start("_id").is(eventId); mongo.findOne("calendarevent", MongoQueryBuilder.build(query), validResultHandler(handler)); }
From source file:net.atos.entng.forum.events.ForumRepositoryEvents.java
License:Open Source License
@Override public void deleteGroups(JsonArray groups) { if (groups == null || groups.size() == 0) { log.warn("[ForumRepositoryEvents][deleteGroups] JsonArray groups is null or empty"); return;/*from w w w . j a v a 2 s .c om*/ } final String[] groupIds = new String[groups.size()]; for (int i = 0; i < groups.size(); i++) { JsonObject j = groups.get(i); groupIds[i] = j.getString("group"); } final JsonObject matcher = MongoQueryBuilder.build(QueryBuilder.start("shared.groupId").in(groupIds)); MongoUpdateBuilder modifier = new MongoUpdateBuilder(); modifier.pull("shared", MongoQueryBuilder.build(QueryBuilder.start("groupId").in(groupIds))); // remove all the shares with groups mongo.update(CATEGORY_COLLECTION, matcher, modifier.build(), false, true, MongoDbResult.validActionResultHandler(new Handler<Either<String, JsonObject>>() { @Override public void handle(Either<String, JsonObject> event) { if (event.isRight()) { log.info("[ForumRepositoryEvents][deleteGroups] All groups shares are removed"); } else { log.error( "[ForumRepositoryEvents][deleteGroups] Error removing groups shares. Message : " + event.left().getValue()); } } })); }
From source file:net.atos.entng.forum.events.ForumRepositoryEvents.java
License:Open Source License
/** * Remove the shares of categories with a list of users * if OK, Call prepareCleanCategories()//from w w w . ja v a 2 s .co m * @param usersIds users identifiers */ private void removeSharesCategories(final String[] usersIds) { final JsonObject criteria = MongoQueryBuilder.build(QueryBuilder.start("shared.userId").in(usersIds)); MongoUpdateBuilder modifier = new MongoUpdateBuilder(); modifier.pull("shared", MongoQueryBuilder.build(QueryBuilder.start("userId").in(usersIds))); // Remove Categories shares with these users mongo.update(CATEGORY_COLLECTION, criteria, modifier.build(), false, true, MongoDbResult.validActionResultHandler(new Handler<Either<String, JsonObject>>() { @Override public void handle(Either<String, JsonObject> event) { if (event.isRight()) { log.info( "[ForumRepositoryEvents][removeSharesCategories] All categories shares with users are removed"); ForumRepositoryEvents.this.prepareCleanCategories(usersIds); } else { log.error( "[ForumRepositoryEvents][removeSharesCategories] Error removing categories shares with users. Message : " + event.left().getValue()); } } })); }
From source file:net.atos.entng.forum.events.ForumRepositoryEvents.java
License:Open Source License
/** * Prepare a list of categories identifiers * if OK, Call cleanCategories()/*from w w w. jav a 2 s .c o m*/ * @param usersIds users identifiers */ private void prepareCleanCategories(final String[] usersIds) { DBObject deletedUsers = new BasicDBObject(); // users currently deleted deletedUsers.put("owner.userId", new BasicDBObject("$in", usersIds)); // users who have already been deleted DBObject ownerIsDeleted = new BasicDBObject("owner.deleted", true); // no manager found JsonObject matcher = MongoQueryBuilder.build(QueryBuilder.start("shared." + MANAGE_RIGHT_ACTION) .notEquals(true).or(deletedUsers, ownerIsDeleted)); // return only categories identifiers JsonObject projection = new JsonObject().putNumber("_id", 1); mongo.find(CATEGORY_COLLECTION, matcher, null, projection, MongoDbResult.validResultsHandler(new Handler<Either<String, JsonArray>>() { @Override public void handle(Either<String, JsonArray> event) { if (event.isRight()) { JsonArray categories = event.right().getValue(); if (categories == null || categories.size() == 0) { log.info("[ForumRepositoryEvents][prepareCleanCategories] No categorie to delete"); return; } final String[] categoriesIds = new String[categories.size()]; for (int i = 0; i < categories.size(); i++) { JsonObject j = categories.get(i); categoriesIds[i] = j.getString("_id"); } ForumRepositoryEvents.this.cleanCategories(usersIds, categoriesIds); } else { log.error( "[ForumRepositoryEvents][prepareCleanCategories] Error retreving the categories created by users. Message : " + event.left().getValue()); } } })); }
From source file:net.atos.entng.forum.events.ForumRepositoryEvents.java
License:Open Source License
/** * Delete categories by identifier/*from w w w.j a v a2 s .co m*/ * if OK, call cleanSubjects() and tagUsersAsDeleted() * @param usersIds users identifiers, used for tagUsersAsDeleted() * @param categoriesIds categories identifiers */ private void cleanCategories(final String[] usersIds, final String[] categoriesIds) { JsonObject matcher = MongoQueryBuilder.build(QueryBuilder.start("_id").in(categoriesIds)); mongo.delete(CATEGORY_COLLECTION, matcher, MongoDbResult.validActionResultHandler(new Handler<Either<String, JsonObject>>() { @Override public void handle(Either<String, JsonObject> event) { if (event.isRight()) { log.info( "[ForumRepositoryEvents][cleanCategories] The categories created by users are deleted"); ForumRepositoryEvents.this.cleanSubjects(categoriesIds); ForumRepositoryEvents.this.tagUsersAsDeleted(usersIds); } else { log.error( "[ForumRepositoryEvents][cleanCategories] Error deleting the categories created by users. Message : " + event.left().getValue()); } } })); }
From source file:net.atos.entng.forum.events.ForumRepositoryEvents.java
License:Open Source License
/** * Delete subjects by category identifier * @param categoriesIds categories identifiers *//*from w w w . j a v a 2s .c o m*/ private void cleanSubjects(final String[] categoriesIds) { JsonObject matcher = MongoQueryBuilder.build(QueryBuilder.start("category").in(categoriesIds)); mongo.delete(SUBJECT_COLLECTION, matcher, MongoDbResult.validActionResultHandler(new Handler<Either<String, JsonObject>>() { @Override public void handle(Either<String, JsonObject> event) { if (event.isRight()) { log.info( "[ForumRepositoryEvents][cleanSubjects] The subjects created by users are deleted"); } else { log.error( "[ForumRepositoryEvents][cleanSubjects] Error deleting the subjects created by users. Message : " + event.left().getValue()); } } })); }
From source file:net.atos.entng.forum.events.ForumRepositoryEvents.java
License:Open Source License
/** * Tag as deleted a list of users in their own categories * @param usersIds users identifiers/*from w w w . j a v a 2 s.co m*/ */ private void tagUsersAsDeleted(final String[] usersIds) { final JsonObject criteria = MongoQueryBuilder.build(QueryBuilder.start("owner.userId").in(usersIds)); MongoUpdateBuilder modifier = new MongoUpdateBuilder(); modifier.set("owner.deleted", true); mongo.update(CATEGORY_COLLECTION, criteria, modifier.build(), false, true, MongoDbResult.validActionResultHandler(new Handler<Either<String, JsonObject>>() { @Override public void handle(Either<String, JsonObject> event) { if (event.isRight()) { log.info( "[ForumRepositoryEvents][deleteCategoriesUser] users are tagged as deleted in their own categories"); } else { log.error( "[ForumRepositoryEvents][deleteCategoriesUser] Error tagging as deleted users. Message : " + event.left().getValue()); } } })); }