List of usage examples for com.mongodb QueryBuilder start
public static QueryBuilder start(final String key)
From source file:org.entcore.workspace.service.WorkspaceService.java
License:Open Source License
@Put("/rename/document/:id") @SecuredAction(value = "", type = ActionType.RESOURCE) public void renameDocument(final HttpServerRequest request) { RequestUtils.bodyToJson(request, pathPrefix + "rename", new Handler<JsonObject>() { public void handle(final JsonObject body) { UserUtils.getUserInfos(eb, request, new Handler<UserInfos>() { public void handle(UserInfos userInfos) { if (userInfos != null) { String id = request.params().get("id"); final QueryBuilder matcher = QueryBuilder.start("_id").is(id).put("owner") .is(userInfos.getUserId()).and("file").exists(true); MongoUpdateBuilder modifier = new MongoUpdateBuilder(); if (body.getString("name") != null) modifier.set("name", body.getString("name")); if (body.getString("alt") != null) modifier.set("alt", body.getString("alt")); if (body.getString("legend") != null) modifier.set("legend", body.getString("legend")); mongo.update(DOCUMENTS_COLLECTION, MongoQueryBuilder.build(matcher), modifier.build(), MongoDbResult.validResultHandler(defaultResponseHandler(request))); } else { unauthorized(request); }// w ww . j av a2 s. c o m } }); } }); }
From source file:org.entcore.workspace.service.WorkspaceService.java
License:Open Source License
@Get("/document/:id/revisions") @SecuredAction(value = "workspace.read", type = ActionType.RESOURCE) public void listRevisions(HttpServerRequest request) { String id = request.params().get("id"); final QueryBuilder builder = QueryBuilder.start("documentId").is(id); mongo.find(DOCUMENT_REVISION_COLLECTION, MongoQueryBuilder.build(builder), MongoDbResult.validResultsHandler(arrayResponseHandler(request))); }
From source file:org.entcore.workspace.service.WorkspaceService.java
License:Open Source License
private void getRevisionFile(final HttpServerRequest request, final String documentId, final String revisionId) { final QueryBuilder builder = QueryBuilder.start("_id").is(revisionId).and("documentId").is(documentId); //Find revision mongo.findOne(DOCUMENT_REVISION_COLLECTION, MongoQueryBuilder.build(builder), MongoDbResult.validResultHandler(new Handler<Either<String, JsonObject>>() { @Override/* www.ja va2 s .c o m*/ public void handle(Either<String, JsonObject> event) { if (event.isLeft()) { notFound(request); return; } JsonObject result = event.right().getValue(); String file = result.getString("file"); if (file != null && !file.trim().isEmpty()) { if (ETag.check(request, file)) { notModified(request, file); } else { storage.sendFile(file, result.getString("name"), request, false, result.getJsonObject("metadata")); } eventStore.createAndStoreEvent(WokspaceEvent.GET_RESOURCE.name(), request, new JsonObject().put("resource", documentId)); } else { notFound(request); } } })); }
From source file:org.entcore.workspace.service.WorkspaceService.java
License:Open Source License
@Delete("/document/:id/revision/:revisionId") @SecuredAction(value = "workspace.manager", type = ActionType.RESOURCE) public void deleteRevision(final HttpServerRequest request) { final String id = request.params().get("id"); final String revisionId = request.params().get("revisionId"); final QueryBuilder builder = QueryBuilder.start("_id").is(revisionId).and("documentId").is(id); //Find revision mongo.findOne(DOCUMENT_REVISION_COLLECTION, MongoQueryBuilder.build(builder), MongoDbResult.validResultHandler(new Handler<Either<String, JsonObject>>() { @Override/* ww w .ja v a 2 s . c o m*/ public void handle(Either<String, JsonObject> event) { if (event.isRight()) { final JsonObject result = event.right().getValue(); final String file = result.getString("file"); //Delete file in storage storage.removeFile(file, new Handler<JsonObject>() { public void handle(JsonObject event) { if (event != null && "ok".equals(event.getString("status"))) { //Delete revision mongo.delete(DOCUMENT_REVISION_COLLECTION, MongoQueryBuilder.build(builder), MongoDbResult.validResultHandler( new Handler<Either<String, JsonObject>>() { public void handle(Either<String, JsonObject> event) { if (event.isLeft()) { log.error("[Workspace] Error deleting revision " + revisionId + " - " + event.left().getValue()); badRequest(request, event.left().getValue()); } else { decrementStorage(result); renderJson(request, event.right().getValue()); } } })); } else { log.error("[Workspace] Error deleting revision storage file " + revisionId + " [" + file + "] - " + event.getString("message")); badRequest(request, event.getString("message")); } } }); } else { log.error("[Workspace] Error finding revision storage file " + revisionId + " - " + event.left().getValue()); notFound(request, event.left().getValue()); } } })); }
From source file:org.entcore.workspace.service.WorkspaceService.java
License:Open Source License
private void deleteAllRevisions(final String documentId, final JsonArray alreadyDeleted) { final QueryBuilder builder = QueryBuilder.start("documentId").is(documentId); JsonObject keys = new JsonObject(); mongo.find(DOCUMENT_REVISION_COLLECTION, MongoQueryBuilder.build(builder), new JsonObject(), keys, MongoDbResult.validResultsHandler(new Handler<Either<String, JsonArray>>() { public void handle(Either<String, JsonArray> event) { if (event.isRight()) { final JsonArray results = event.right().getValue(); final JsonArray ids = new fr.wseduc.webutils.collections.JsonArray(); for (Object obj : results) { JsonObject json = (JsonObject) obj; String id = json.getString("file"); if (id != null && !alreadyDeleted.contains(id)) { ids.add(id); }//from w w w .ja va 2s . c o m } storage.removeFiles(ids, new Handler<JsonObject>() { public void handle(JsonObject event) { if (event != null && "ok".equals(event.getString("status"))) { //Delete revisions mongo.delete(DOCUMENT_REVISION_COLLECTION, MongoQueryBuilder.build(builder), MongoDbResult.validResultHandler( new Handler<Either<String, JsonObject>>() { public void handle(Either<String, JsonObject> event) { if (event.isLeft()) { log.error( "[Workspace] Error deleting revisions for document " + documentId + " - " + event.left().getValue()); } else { for (Object obj : results) { JsonObject result = (JsonObject) obj; if (!alreadyDeleted .contains(result.getString("file"))) decrementStorage(result); } } } })); } else { log.error("[Workspace] Error deleting revision storage files for document " + documentId + " " + ids + " - " + event.getString("message")); } } }); } else { log.error("[Workspace] Error finding revision for document " + documentId + " - " + event.left().getValue()); } } })); }
From source file:org.graylog2.alerts.AlertServiceImpl.java
License:Open Source License
@Override public List<Alert> loadRecentOfStream(String streamId, DateTime since) { QueryBuilder qb = QueryBuilder.start("stream_id").is(streamId); if (since != null) { qb.and("triggered_at").greaterThanEquals(since.toDate()); }//from ww w . j a v a 2s .co m BasicDBObject sort = new BasicDBObject("triggered_at", -1); final List<DBObject> alertObjects = query(AlertImpl.class, qb.get(), sort, AlertImpl.MAX_LIST_COUNT, 0); List<Alert> alerts = Lists.newArrayList(); for (DBObject alertObj : alertObjects) { alerts.add(new AlertImpl(new ObjectId(alertObj.get("_id").toString()), alertObj.toMap())); } return alerts; }
From source file:org.graylog2.alerts.AlertServiceImpl.java
License:Open Source License
@Override public int triggeredSecondsAgo(String streamId, String conditionId) { DBObject query = QueryBuilder.start("stream_id").is(streamId).and("condition_id").is(conditionId).get(); BasicDBObject sort = new BasicDBObject("triggered_at", -1); DBObject alert = findOne(AlertImpl.class, query, sort); if (alert == null) { return -1; }//from ww w. ja va 2 s .c o m DateTime triggeredAt = new DateTime(alert.get("triggered_at"), DateTimeZone.UTC); return Seconds.secondsBetween(triggeredAt, Tools.iso8601()).getSeconds(); }
From source file:org.graylog2.inputs.InputServiceImpl.java
License:Open Source License
@Override public Input findForThisRadio(String radioId, String id) throws NotFoundException { final List<Object> list = new ArrayList<Object>() { {/*from w w w .j ava 2 s. co m*/ add(false); add(null); } }; final List<DBObject> query = ImmutableList.of(new BasicDBObject("_id", new ObjectId(id)), new BasicDBObject(MessageInput.FIELD_RADIO_ID, radioId), QueryBuilder.start(MessageInput.FIELD_GLOBAL).in(list).get()); final DBObject o = findOne(InputImpl.class, new BasicDBObject("$and", query)); if (o == null) { throw new NotFoundException(); } else { return new InputImpl((ObjectId) o.get("_id"), o.toMap()); } }
From source file:org.graylog2.periodical.AlarmCallbacksMigrationPeriodical.java
License:Open Source License
@Override public void doRun() { LOG.debug("Starting alarm callbacks migration"); final DBObject selection = QueryBuilder.start("id").exists(true).get(); final DBObject modifications = new BasicDBObject("$unset", new BasicDBObject("id", "")); this.dbCollection.updateMulti(selection, modifications); LOG.debug("Done with alarm callbacks migration"); }
From source file:org.knowrob.cram.LogdataPublisher.java
License:Open Source License
public boolean publishDesignator(String designatorId) { try {//from w w w .ja v a 2 s . c o m final StringTokenizer s1 = new StringTokenizer(designatorId, "#"); s1.nextToken(); designatorId = s1.nextToken(); QueryBuilder query = QueryBuilder.start("designator._id").is(designatorId); org.knowrob.interfaces.mongo.types.Designator d1 = mdb .designator(mdb.one(mdb.query(MongoDBInterface.COLLECTION_LOGGED_DESIGNATORS, query))); publishDesignator(d1); return true; } catch (Exception e) { System.err.println("Failed to publish designator: " + e.getMessage()); e.printStackTrace(); } return false; }