List of usage examples for com.mongodb QueryBuilder start
public static QueryBuilder start(final String key)
From source file:net.atos.entng.calendar.event.CalendarRepositoryEvents.java
License:Open Source License
@Override public void deleteGroups(JsonArray groups) { if (groups == null || groups.size() == 0) { log.warn("[CalendarRepositoryEvents][deleteGroups] JsonArray groups is null or empty"); return;//from ww w . jav a 2 s. c o m } 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(Calendar.CALENDAR_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("[CalendarRepositoryEvents][deleteGroups] All groups shares are removed"); } else { log.error( "[CalendarRepositoryEvents][deleteGroups] Error removing groups shares. Message : " + event.left().getValue()); } } })); }
From source file:net.atos.entng.calendar.event.CalendarRepositoryEvents.java
License:Open Source License
/** * Remove the shares of categories with a list of users if OK, Call prepareCleanCategories() * @param usersIds users identifiers// w w w.j a v a 2 s. c o m */ private void removeSharesCalendars(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(Calendar.CALENDAR_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( "[CalendarRepositoryEvents][removeSharesCalendars] All calendars shares with users are removed"); prepareCleanCalendars(usersIds); } else { log.error( "[CalendarRepositoryEvents][removeSharesCalendars] Error removing calendars shares with users. Message : " + event.left().getValue()); } } })); }
From source file:net.atos.entng.calendar.event.CalendarRepositoryEvents.java
License:Open Source License
/** * Prepare a list of categories identifiers if OK, Call cleanCategories() * @param usersIds users identifiers// ww w. ja v a 2 s . c o m */ private void prepareCleanCalendars(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." + Calendar.MANAGE_RIGHT_ACTION) .notEquals(true).or(deletedUsers, ownerIsDeleted)); // return only calendar identifiers JsonObject projection = new JsonObject().putNumber("_id", 1); mongo.find(Calendar.CALENDAR_COLLECTION, matcher, null, projection, MongoDbResult.validResultsHandler(new Handler<Either<String, JsonArray>>() { @Override public void handle(Either<String, JsonArray> event) { if (event.isRight()) { JsonArray calendars = event.right().getValue(); if (calendars == null || calendars.size() == 0) { log.info( "[CalendarRepositoryEvents][prepareCleanCalendars] No calendars to delete"); return; } final String[] calendarIds = new String[calendars.size()]; for (int i = 0; i < calendars.size(); i++) { JsonObject j = calendars.get(i); calendarIds[i] = j.getString("_id"); } cleanCalendars(usersIds, calendarIds); } else { log.error( "[CalendarRepositoryEvents][prepareCleanCalendars] Error retreving the calendars created by users. Message : " + event.left().getValue()); } } })); }
From source file:net.atos.entng.calendar.event.CalendarRepositoryEvents.java
License:Open Source License
/** * Delete calendars by identifier if OK, call cleanEvents() and tagUsersAsDeleted() * @param usersIds users identifiers, used for tagUsersAsDeleted() * @param calendarIds calendars identifiers *///from ww w . ja va 2s. c o m private void cleanCalendars(final String[] usersIds, final String[] calendarIds) { JsonObject matcher = MongoQueryBuilder.build(QueryBuilder.start("_id").in(calendarIds)); mongo.delete(Calendar.CALENDAR_COLLECTION, matcher, MongoDbResult.validActionResultHandler(new Handler<Either<String, JsonObject>>() { @Override public void handle(Either<String, JsonObject> event) { if (event.isRight()) { log.info( "[CalendarRepositoryEvents][cleanCalendars] The calendars created by users are deleted"); cleanEvents(calendarIds); tagUsersAsDeleted(usersIds); } else { log.error( "[CalendarRepositoryEvents][cleanCalendars] Error deleting the calendars created by users. Message : " + event.left().getValue()); } } })); }
From source file:net.atos.entng.calendar.event.CalendarRepositoryEvents.java
License:Open Source License
/** * Delete events by calendar identifier/*from w w w .ja va 2 s. c om*/ * @param calendarIds calendars identifiers */ private void cleanEvents(final String[] calendarIds) { JsonObject matcher = MongoQueryBuilder.build(QueryBuilder.start("calendar").in(calendarIds)); mongo.delete(Calendar.CALENDAR_EVENT_COLLECTION, matcher, MongoDbResult.validActionResultHandler(new Handler<Either<String, JsonObject>>() { @Override public void handle(Either<String, JsonObject> event) { if (event.isRight()) { log.info( "[CalendarRepositoryEvents][cleanEvents] The events created by users are deleted"); } else { log.error( "[CalendarRepositoryEvents][cleanEvents] Error deleting the events created by users. Message : " + event.left().getValue()); } } })); }
From source file:net.atos.entng.calendar.event.CalendarRepositoryEvents.java
License:Open Source License
/** * Tag as deleted a list of users in their own calendars * @param usersIds users identifiers/*from w w w . ja v a2 s. c o 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(Calendar.CALENDAR_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( "[CalendarRepositoryEvents][tagUsersAsDeleted] users are tagged as deleted in their own calendars"); } else { log.error( "[CalendarRepositoryEvents][tagUsersAsDeleted] Error tagging as deleted users. Message : " + event.left().getValue()); } } })); }
From source file:net.atos.entng.calendar.event.CalendarSearchingEvents.java
License:Open Source License
@Override public void searchResource(List<String> appFilters, String userId, JsonArray groupIds, final JsonArray searchWords, final Integer page, final Integer limit, final JsonArray columnsHeader, final String locale, final Handler<Either<String, JsonArray>> handler) { if (appFilters.contains(CalendarSearchingEvents.class.getSimpleName())) { final List<String> groupIdsLst = groupIds.toList(); final List<DBObject> groups = new ArrayList<DBObject>(); groups.add(QueryBuilder.start("userId").is(userId).get()); for (String gpId : groupIdsLst) { groups.add(QueryBuilder.start("groupId").is(gpId).get()); }// w w w.ja va 2 s . com final QueryBuilder rightsQuery = new QueryBuilder().or( QueryBuilder.start("visibility").is(VisibilityFilter.PUBLIC.name()).get(), QueryBuilder.start("visibility").is(VisibilityFilter.PROTECTED.name()).get(), QueryBuilder.start("owner.userId").is(userId).get(), QueryBuilder.start("shared") .elemMatch(new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get()) .get()); JsonObject sort = new JsonObject().putNumber("modified", -1); final JsonObject projection = new JsonObject(); projection.putNumber("title", 1); //search all calendar of user mongo.find(Calendar.CALENDAR_COLLECTION, MongoQueryBuilder.build(rightsQuery), sort, projection, new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { final Either<String, JsonArray> ei = validResults(event); if (ei.isRight()) { final JsonArray calendarResult = ei.right().getValue(); final Map<String, String> mapIdTitle = new HashMap<String, String>(); for (int i = 0; i < calendarResult.size(); i++) { final JsonObject j = calendarResult.get(i); mapIdTitle.put(j.getString("_id"), j.getString("title")); } //search event for the calendars found searchEvent(page, limit, searchWords.toList(), mapIdTitle, new Handler<Either<String, JsonArray>>() { @Override public void handle(Either<String, JsonArray> event) { if (event.isRight()) { if (log.isDebugEnabled()) { log.debug( "[CalendarSearchingEvents][searchResource] The resources searched by user are finded"); } final JsonArray res = formatSearchResult( event.right().getValue(), columnsHeader, mapIdTitle, locale); handler.handle(new Right<String, JsonArray>(res)); } else { handler.handle(new Either.Left<String, JsonArray>( event.left().getValue())); } } }); } else { handler.handle(new Either.Left<String, JsonArray>(ei.left().getValue())); } } }); } else { handler.handle(new Right<String, JsonArray>(new JsonArray())); } }
From source file:net.atos.entng.calendar.helpers.EventHelper.java
License:Open Source License
/** * * @param request/*from ww w. j a va 2 s . c o m*/ * @param user * @param calendarId * @param calendarEvent */ public void notifyUsersSharing(final HttpServerRequest request, final UserInfos user, final String calendarId, final JsonObject calendarEvent, final boolean isCreated) { QueryBuilder query = QueryBuilder.start("_id").is(calendarId); JsonObject keys = new JsonObject().putNumber("calendar", 1); JsonArray fetch = new JsonArray().addString("shared"); findRecipiants("calendar", query, keys, fetch, user, new Handler<Map<String, Object>>() { @Override public void handle(Map<String, Object> event) { if (event != null) { List<String> recipients = (List<String>) event.get("recipients"); String calendarTitle = (String) event.get("calendarTitle"); if (recipients != null) { String template = isCreated ? "calendar.create" : "calendar.update"; Date startDate = null; Date endDate = null; try { startDate = DateUtils .parseTimestampWithoutTimezone(calendarEvent.getString("startMoment")); endDate = DateUtils.parseTimestampWithoutTimezone(calendarEvent.getString("endMoment")); } catch (ParseException e) { e.printStackTrace(); } JsonObject p = new JsonObject() .putString("uri", Config.getInstance().getConfig().getString("host", "http://localhost:8090") + "/userbook/annuaire#" + user.getUserId() + "#" + user.getType()) .putString("username", user.getUsername()).putString("CalendarTitle", calendarTitle) .putString("postTitle", calendarEvent.getString("title")) .putString("profilUri", Config.getInstance().getConfig().getString("host", "http://localhost:8090") + "/userbook/annuaire#" + user.getUserId() + "#" + user.getType()) .putString("calendarUri", Config.getInstance().getConfig().getString("host", "http://localhost:8090") + "/calendar#/view/" + calendarId) .putString("startMoment", DateUtils.format(startDate, "dd/MM/yyyy HH:mm")) .putString("endMoment", DateUtils.format(endDate, "dd/MM/yyyy HH:mm")) .putString("eventTitle", calendarEvent.getString("title")); notification.notifyTimeline(request, template, user, recipients, calendarId, calendarEvent.getString("id"), p); } } } }); }
From source file:net.atos.entng.calendar.services.impl.EventServiceMongoImpl.java
License:Open Source License
@Override public void list(String calendarId, UserInfos user, final Handler<Either<String, JsonArray>> handler) { // Query//from w w w .j av a2s . co m QueryBuilder query = QueryBuilder.start("calendar").is(calendarId); JsonObject sort = new JsonObject().putNumber("modified", -1); // Projection JsonObject projection = new JsonObject(); mongo.find(this.collection, MongoQueryBuilder.build(query), sort, projection, validResultsHandler(handler)); }
From source file:net.atos.entng.calendar.services.impl.EventServiceMongoImpl.java
License:Open Source License
@Override public void retrieve(String calendarId, String eventId, UserInfos user, Handler<Either<String, JsonObject>> handler) { // Query// w w w . jav a2 s . c o m QueryBuilder query = QueryBuilder.start("_id").is(eventId); query.put("calendar").is(calendarId); // Projection JsonObject projection = new JsonObject(); mongo.findOne(this.collection, MongoQueryBuilder.build(query), projection, validResultHandler(handler)); }