List of usage examples for com.mongodb QueryBuilder QueryBuilder
public QueryBuilder()
From source file:it.sayservice.platform.smartplanner.otp.OTPManager.java
License:Apache License
private List<AlertDelay> getAlertDelay(String router, String tripId, boolean now) { QueryBuilder qb = new QueryBuilder(); qb = qb.start("transport.tripId").is(tripId); if (now) {//from w ww . j av a 2 s.c o m long time = System.currentTimeMillis(); qb = qb.and("from").lessThanEquals(time); qb = qb.and("to").greaterThanEquals(time); } List<AlertDelay> delays = (List) storage.getObjectsByQuery( mongoRouterMapper.getMongoTemplateMap().get(router), qb.get(), Constants.ALERT_DELAYS, AlertDelay.class, "delay"); return delays; }
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()); }/*from w w w . j av a2 s.co m*/ 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.event.CalendarSearchingEvents.java
License:Open Source License
private void searchEvent(int page, int limit, List<String> searchWords, final Map<String, String> mapIdTitle, Handler<Either<String, JsonArray>> handler) { final int skip = (0 == page) ? -1 : page * limit; final List<String> returnFields = new ArrayList<String>(); returnFields.add("title"); returnFields.add("calendar"); returnFields.add("description"); returnFields.add("location"); returnFields.add("modified"); returnFields.add("startMoment"); returnFields.add("endMoment"); returnFields.add("owner.userId"); returnFields.add("owner.displayName"); final QueryBuilder worldsQuery = new QueryBuilder(); worldsQuery.text(MongoDbSearchService.textSearchedComposition(searchWords)); final QueryBuilder calendarQuery = new QueryBuilder().start("calendar").in(mapIdTitle.keySet()); final QueryBuilder query = new QueryBuilder().and(worldsQuery.get(), calendarQuery.get()); JsonObject sort = new JsonObject().putNumber("modified", -1); final JsonObject projection = new JsonObject(); for (String field : returnFields) { projection.putNumber(field, 1);// ww w . ja v a 2 s . c o m } mongo.find(Calendar.CALENDAR_EVENT_COLLECTION, MongoQueryBuilder.build(query), sort, projection, skip, limit, Integer.MAX_VALUE, validResultsHandler(handler)); }
From source file:net.atos.entng.forum.events.ForumSearchingEvents.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(ForumSearchingEvents.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 v a 2 s .c om 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("name", 1); //search all category of user mongo.find(Forum.CATEGORY_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 categoryResult = ei.right().getValue(); final Map<String, String> mapIdName = new HashMap<String, String>(); for (int i = 0; i < categoryResult.size(); i++) { final JsonObject j = categoryResult.get(i); mapIdName.put(j.getString("_id"), j.getString("name")); } //search subject for the catagories found searchSubject(page, limit, searchWords.toList(), mapIdName, new Handler<Either<String, JsonArray>>() { @Override public void handle(Either<String, JsonArray> event) { if (event.isRight()) { if (log.isDebugEnabled()) { log.debug( "[ForumSearchingEvents][searchResource] The resources searched by user are finded"); } final JsonArray res = formatSearchResult( event.right().getValue(), columnsHeader, searchWords.toList(), mapIdName, 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.forum.events.ForumSearchingEvents.java
License:Open Source License
private void searchSubject(int page, int limit, List<String> searchWords, final Map<String, String> mapIdName, Handler<Either<String, JsonArray>> handler) { final int skip = (0 == page) ? -1 : page * limit; final QueryBuilder worldsQuery = new QueryBuilder(); worldsQuery.text(MongoDbSearchService.textSearchedComposition(searchWords)); final QueryBuilder categoryQuery = new QueryBuilder().start("category").in(mapIdName.keySet()); final QueryBuilder query = new QueryBuilder().and(worldsQuery.get(), categoryQuery.get()); JsonObject sort = new JsonObject().putNumber("modified", -1); final JsonObject projection = new JsonObject(); projection.putNumber("title", 1); projection.putNumber("messages", 1); projection.putNumber("category", 1); projection.putNumber("modified", 1); projection.putNumber("owner.userId", 1); projection.putNumber("owner.displayName", 1); mongo.find(Forum.SUBJECT_COLLECTION, MongoQueryBuilder.build(query), sort, projection, skip, limit, Integer.MAX_VALUE, validResultsHandler(handler)); }
From source file:net.atos.entng.forum.services.impl.MongoDbCategoryService.java
License:Open Source License
@Override public void list(UserInfos user, Handler<Either<String, JsonArray>> handler) { // Start/* w w w. j ava 2 s . com*/ QueryBuilder query = QueryBuilder.start(); // Permissions Filter List<DBObject> groups = new ArrayList<>(); groups.add(QueryBuilder.start("userId").is(user.getUserId()).get()); for (String gpId : user.getProfilGroupsIds()) { groups.add(QueryBuilder.start("groupId").is(gpId).get()); } query.or(QueryBuilder.start("owner.userId").is(user.getUserId()).get(), QueryBuilder.start("shared") .elemMatch(new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get()).get()); JsonObject sort = new JsonObject().putNumber("modified", -1); mongo.find(categories_collection, MongoQueryBuilder.build(query), sort, null, validResultsHandler(handler)); }
From source file:net.atos.entng.forum.services.impl.MongoDbMessageService.java
License:Open Source License
protected void prepareIsSharedMethodQuery(final QueryBuilder query, final UserInfos user, final String threadId, final String sharedMethod) { // ThreadId//ww w .j av a2s . c o m query.put("_id").is(threadId); // Permissions List<DBObject> groups = new ArrayList<>(); groups.add(QueryBuilder.start("userId").is(user.getUserId()).put(sharedMethod).is(true).get()); for (String gpId : user.getProfilGroupsIds()) { groups.add(QueryBuilder.start("groupId").is(gpId).put(sharedMethod).is(true).get()); } query.or(QueryBuilder.start("owner.userId").is(user.getUserId()).get(), QueryBuilder.start("visibility").is(VisibilityFilter.PUBLIC.name()).get(), QueryBuilder.start("visibility").is(VisibilityFilter.PROTECTED.name()).get(), QueryBuilder.start("shared") .elemMatch(new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get()).get()); }
From source file:net.atos.entng.forum.services.impl.MongoDbMessageService.java
License:Open Source License
protected void prepareIsSharedAnyQuery(final QueryBuilder query, final UserInfos user, final String threadId) { // ThreadId/*from ww w . ja v a 2s. com*/ query.put("_id").is(threadId); // Permissions List<DBObject> groups = new ArrayList<>(); groups.add(QueryBuilder.start("userId").is(user.getUserId()).get()); for (String gpId : user.getProfilGroupsIds()) { groups.add(QueryBuilder.start("groupId").is(gpId).get()); } query.or(QueryBuilder.start("owner.userId").is(user.getUserId()).get(), QueryBuilder.start("visibility").is(VisibilityFilter.PUBLIC.name()).get(), QueryBuilder.start("visibility").is(VisibilityFilter.PROTECTED.name()).get(), QueryBuilder.start("shared") .elemMatch(new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get()).get()); }
From source file:net.atos.entng.wiki.filters.OwnerAuthorOrShared.java
License:Open Source License
@Override public void authorize(HttpServerRequest request, Binding binding, UserInfos user, Handler<Boolean> handler) { String wikiId = request.params().get(conf.getResourceIdLabel()); String pageId = request.params().get("idpage"); String commentId = request.params().get("idcomment"); if (isValidId(wikiId) && isValidId(pageId) && isValidId(commentId)) { List<DBObject> groups = new ArrayList<>(); String sharedMethod = binding.getServiceMethod().replaceAll("\\.", "-"); groups.add(QueryBuilder.start("userId").is(user.getUserId()).put(sharedMethod).is(true).get()); for (String gpId : user.getGroupsIds()) { groups.add(QueryBuilder.start("groupId").is(gpId).put(sharedMethod).is(true).get()); }/*from w w w . j av a 2 s. com*/ BasicDBObject commentMatch = new BasicDBObject("_id", commentId); commentMatch.put("author", user.getUserId()); DBObject pageMatch = QueryBuilder.start("_id").is(pageId).put("comments").elemMatch(commentMatch).get(); // Authorize if current user is the wiki's owner, the comment's author or if the serviceMethod has been shared QueryBuilder query = QueryBuilder.start("_id").is(wikiId).or( QueryBuilder.start("owner.userId").is(user.getUserId()).get(), QueryBuilder.start("pages").elemMatch(pageMatch).get(), QueryBuilder.start("shared") .elemMatch(new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get()) .get()); MongoAppFilter.executeCountQuery(request, conf.getCollection(), MongoQueryBuilder.build(query), 1, handler); } else { handler.handle(false); } }
From source file:net.atos.entng.wiki.service.WikiServiceMongoImpl.java
License:Open Source License
@Override public void listWikis(UserInfos user, Handler<Either<String, JsonArray>> handler) { // Query : return wikis visible by current user only (i.e. owner or // shared)//from w w w. j a v a2 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", 0).putNumber("created", 0); JsonObject sort = new JsonObject().putNumber("modified", -1); mongo.find(collection, MongoQueryBuilder.build(query), sort, projection, MongoDbResult.validResultsHandler(handler)); }