List of usage examples for io.vertx.core.json JsonObject getJsonObject
public JsonObject getJsonObject(String key, JsonObject def)
From source file:com.groupon.vertx.memcache.MemcacheClusterConfig.java
License:Apache License
public MemcacheClusterConfig(JsonObject jsonConfig) { if (jsonConfig == null) { log.error("initialize", "exception", "noConfigFound"); throw new MemcacheException("No Memcache cluster config found"); }//from ww w. ja v a 2s . co m this.eventBusAddressPrefix = jsonConfig.getString(EVENT_BUS_ADDRESS_PREFIX_KEY); this.retryInterval = jsonConfig.getLong(RETRY_INTERVAL, MemcacheConfig.DEFAULT_RETRY_INTERVAL); JsonObject clusters = jsonConfig.getJsonObject(CLUSTERS_KEY, new JsonObject()); if (eventBusAddressPrefix != null && !eventBusAddressPrefix.isEmpty() && clusters.size() > 0) { for (String clusterKey : clusters.fieldNames()) { JsonObject clusterConfig = clusters.getJsonObject(clusterKey, new JsonObject()).copy(); clusterConfig.put(EVENT_BUS_ADDRESS_KEY, eventBusAddressPrefix); clusterConfig.put(RETRY_INTERVAL, retryInterval); clusterMap.put(clusterKey, new MemcacheConfig(clusterConfig)); } } else { log.error("initialize", "exception", "invalidConfigFound", new String[] { "config" }, jsonConfig.encode()); throw new MemcacheException("Invalid Memcache config defined"); } log.info("initialize", "success", new String[] { "eventBusAddressPrefix", "clusters" }, eventBusAddressPrefix, clusterMap.size()); }
From source file:de.fraunhofer.fokus.redistest.Query.java
License:Creative Commons License
/** * Constructor for a Query object/*from www . j av a 2 s . c o m*/ * @param json - JosonObject, a JSON representation of a Query object * @param issuer */ public Query(JsonObject json, String issuer) { familyName = NameHelper.toStringArray(json.getJsonArray("familyName", null)); firstName = NameHelper.toStringArray(json.getJsonArray("firstName", null)); placeOfBirth = json.getString("placeOfBirth", null); yearOfBirth = DateQuery.toDateQuery(json.getJsonObject("yearOfBirth", null)); monthOfBirth = DateQuery.toDateQuery(json.getJsonObject("monthOfBirth", null)); dayOfBirth = DateQuery.toDateQuery(json.getJsonObject("dayOfBirth", null)); gender = json.getString("gender", null); JsonArray tmp = json.getJsonArray("familyNameFltr"); if (tmp != null) { familyNameFltr = NameHelper.toStringArray(tmp); } tmp = json.getJsonArray("firstNameFltr"); if (tmp != null) { firstNameFltr = NameHelper.toStringArray(tmp); } String stmp = json.getString("placeOfBirthFltr"); if (stmp != null) { placeOfBirthFltr = stmp; } this.issuer = issuer; pseudonymized = json.getBoolean("pseudonymized", false); }
From source file:de.neofonie.deployer.DeployerVerticle.java
License:Open Source License
/** * Start the deployer.//from w w w .j a va 2 s . c o m * * @param startFuture */ @Override public void start(final Future<Void> startFuture) { // load the deployer.json when available JsonObject configuration = this.loadConfiguration(); if (configuration != null) { deployed = new JsonArray(); // assign loopback to this handler vertx.eventBus().localConsumer(LOOPBACK, this::deployVerticle); // copy the current verticle configuration workingCopy = configuration.getJsonObject(VERTICLES, new JsonObject()).copy(); // set the global configuration globalConfig = configuration.getJsonObject(CONFIG, new JsonObject()); // start iterations vertx.eventBus().send(LOOPBACK, null, (AsyncResult<Message<Boolean>> event) -> { if (event.succeeded() && event.result().body()) { LOG.log(Level.INFO, "Deployed {0} Verticles: {1}", new Object[] { this.deployed.size(), deployed }); startFuture.complete(); } else { LOG.log(Level.SEVERE, "Deployment stopped: {0}", event.cause().getMessage()); startFuture.fail(event.cause()); } }); } else { LOG.info("No deployer.json found on the classpath."); } }
From source file:de.neofonie.deployer.DeployerVerticle.java
License:Open Source License
/** * Iterate and deploy verticles//w w w.j a v a 2s . c o m */ private void deployVerticle(final Message<JsonObject> event) { // iterate over all candidates to be deployed Set<String> candidates = this.workingCopy.fieldNames(); // detach from underlying json Map<String, JsonObject> initiants = new HashMap<>(); candidates.forEach(id -> { JsonObject info = this.workingCopy.getJsonObject(id); JsonArray dependsOn = info.getJsonArray("dependsOn"); if (dependsOn != null && deployed.getList().containsAll(dependsOn.getList()) || dependsOn == null || dependsOn.isEmpty()) { initiants.put(id, info); } }); // remove the initiants initiants.keySet().forEach(id -> this.workingCopy.remove(id)); // setup latch for the reply CountDownLatch latch = new CountDownLatch(initiants.size()); if (initiants.isEmpty()) { event.reply(Boolean.TRUE); return; } // run over all dependencies initiants.forEach((id, info) -> { // get the name of the verticle String name = info.getString("name"); final JsonObject localConfig = new JsonObject(); localConfig.mergeIn(globalConfig); localConfig.mergeIn(info.getJsonObject("config", new JsonObject())); Handler<AsyncResult<String>> handler = innerEvent -> { if (innerEvent.succeeded()) { // add service to deployed-list deployed.add(id); // re-emit vertx.eventBus().send(LOOPBACK, workingCopy, (AsyncResult<Message<Boolean>> recursiveReply) -> { // always decrease latch latch.countDown(); if (recursiveReply.succeeded() && recursiveReply.result().body()) { if (latch.getCount() == 0) { event.reply(recursiveReply.result().body() & Boolean.TRUE); } } else { event.fail(500, this.getFailure(id, recursiveReply)); } }); } else { event.fail(500, id + " >> " + innerEvent.cause().getMessage()); } }; LOG.log(Level.INFO, "Deploying: ''{0}''", new Object[] { id }); DeploymentOptions deploymentOptions = new DeploymentOptions(info); vertx.deployVerticle(name, deploymentOptions.setConfig(localConfig), handler); }); }
From source file:fr.wseduc.rack.controllers.RackController.java
License:Open Source License
/** * Returns a rack document./*w w w .j av a2 s . co m*/ * @param request Client request containing the id of the document. */ @Get("/get/:id") @SecuredAction(value = owner, type = ActionType.RESOURCE) public void getRack(final HttpServerRequest request) { final String thumbSize = request.params().get("thumbnail"); final String id = request.params().get("id"); rackService.getRack(id, new Handler<Either<String, JsonObject>>() { @Override public void handle(Either<String, JsonObject> event) { if (event.isRight()) { JsonObject result = event.right().getValue(); String file; if (thumbSize != null && !thumbSize.trim().isEmpty()) { file = result.getJsonObject("thumbnails", new JsonObject()).getString(thumbSize, result.getString("file")); } else { file = result.getString("file"); } if (file != null && !file.trim().isEmpty()) { boolean inline = inlineDocumentResponse(result, request.params().get("application")); if (inline && ETag.check(request, file)) { notModified(request, file); } else { storage.sendFile(file, result.getString("name"), request, inline, result.getJsonObject("metadata")); } } else { notFound(request); request.response().setStatusCode(404).end(); } } else { JsonObject error = new JsonObject().put("error", event.left().getValue()); Renders.renderJson(request, error, 400); } } }); }
From source file:fr.wseduc.rack.controllers.RackController.java
License:Open Source License
private void copyFiles(final HttpServerRequest request, final JsonArray idsArray, final String folder, final UserInfos user, final String destinationCollection) { String criteria = "{ \"_id\" : { \"$in\" : " + idsArray.encode() + "}"; criteria += ", \"to\" : \"" + user.getUserId() + "\" }"; mongo.find(collection, new JsonObject(criteria), new Handler<Message<JsonObject>>() { private void persist(final JsonArray insert, int remains) { if (remains == 0) { mongo.insert(destinationCollection, insert, new Handler<Message<JsonObject>>() { @Override/*from w w w . j a va 2s. c o m*/ public void handle(Message<JsonObject> inserted) { if ("ok".equals(inserted.body().getString("status"))) { /* Increment quota */ long totalSize = 0l; for (Object insertion : insert) { JsonObject added = (JsonObject) insertion; totalSize += added.getJsonObject("metadata", new JsonObject()).getLong("size", 0l); } updateUserQuota(user.getUserId(), totalSize); renderJson(request, inserted.body()); } else { renderError(request, inserted.body()); } } }); } } @Override public void handle(Message<JsonObject> r) { JsonObject src = r.body(); if ("ok".equals(src.getString("status")) && src.getJsonArray("results") != null) { final JsonArray origs = src.getJsonArray("results"); final JsonArray insert = new JsonArray(); final AtomicInteger number = new AtomicInteger(origs.size()); emptySize(user, new Handler<Long>() { @Override public void handle(Long emptySize) { long size = 0; /* Get total file size */ for (Object o : origs) { if (!(o instanceof JsonObject)) continue; JsonObject metadata = ((JsonObject) o).getJsonObject("metadata"); if (metadata != null) { size += metadata.getLong("size", 0l); } } /* If total file size is too big (> quota left) */ if (size > emptySize) { badRequest(request, "files.too.large"); return; } /* Process */ for (Object o : origs) { JsonObject orig = (JsonObject) o; final JsonObject dest = orig.copy(); String now = MongoDb.formatDate(new Date()); dest.remove("_id"); dest.remove("protected"); dest.remove("comments"); dest.put("application", WORKSPACE_NAME); dest.put("owner", user.getUserId()); dest.put("ownerName", dest.getString("toName")); dest.remove("to"); dest.remove("from"); dest.remove("toName"); dest.remove("fromName"); dest.put("created", now); dest.put("modified", now); if (folder != null && !folder.trim().isEmpty()) { dest.put("folder", folder); } else { dest.remove("folder"); } insert.add(dest); final String filePath = orig.getString("file"); if (folder != null && !folder.trim().isEmpty()) { //If the document has a new parent folder, replicate sharing rights String parentName, parentFolder; if (folder.lastIndexOf('_') < 0) { parentName = folder; parentFolder = folder; } else if (filePath != null) { String[] splittedPath = folder.split("_"); parentName = splittedPath[splittedPath.length - 1]; parentFolder = folder; } else { String[] splittedPath = folder.split("_"); parentName = splittedPath[splittedPath.length - 2]; parentFolder = folder.substring(0, folder.lastIndexOf("_")); } QueryBuilder parentFolderQuery = QueryBuilder.start("owner") .is(user.getUserId()).and("folder").is(parentFolder).and("name") .is(parentName); mongo.findOne(collection, MongoQueryBuilder.build(parentFolderQuery), new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { if ("ok".equals(event.body().getString("status"))) { JsonObject parent = event.body().getJsonObject("result"); if (parent != null && parent.getJsonArray("shared") != null && parent.getJsonArray("shared").size() > 0) dest.put("shared", parent.getJsonArray("shared")); if (filePath != null) { storage.copyFile(filePath, new Handler<JsonObject>() { @Override public void handle(JsonObject event) { if (event != null && "ok" .equals(event.getString("status"))) { dest.put("file", event.getString("_id")); persist(insert, number.decrementAndGet()); } } }); } else { persist(insert, number.decrementAndGet()); } } else { renderJson(request, event.body(), 404); } } }); } else if (filePath != null) { storage.copyFile(filePath, new Handler<JsonObject>() { @Override public void handle(JsonObject event) { if (event != null && "ok".equals(event.getString("status"))) { dest.put("file", event.getString("_id")); persist(insert, number.decrementAndGet()); } } }); } else { persist(insert, number.decrementAndGet()); } } } }); } else { notFound(request, src.toString()); } } }); }
From source file:io.apiman.gateway.platforms.vertx3.api.auth.AuthFactory.java
License:Apache License
public static AuthHandler getAuth(Vertx vertx, Router router, VertxEngineConfig apimanConfig, JsonObject auth) { String type = auth.getString("type", "NONE"); JsonObject authConfig = auth.getJsonObject("config", new JsonObject()); switch (AuthType.getType(type)) { case BASIC:// w w w.j a va 2 s .co m return BasicAuth.create(authConfig); case NONE: return NoneAuth.create(); case KEYCLOAK: return KeycloakOAuthFactory.create(vertx, router, apimanConfig, authConfig); default: return NoneAuth.create(); } }
From source file:io.apiman.gateway.platforms.vertx3.common.config.VertxEngineConfig.java
License:Apache License
protected String getClassname(JsonObject obj, String prefix) { String clazzName = System.getProperty(prefix); // TODO Something of a hack because the constants may assume apiman-gateway prefix, which isn't in the vert.x JSON. String strippedPrefix = StringUtils.substringAfter(prefix, "apiman-gateway."); String filteredPrefix = strippedPrefix.isEmpty() ? prefix : strippedPrefix; if (clazzName == null) return obj.getJsonObject(filteredPrefix, new JsonObject()).getString(GATEWAY_CLASS); return clazzName; }
From source file:io.engagingspaces.graphql.marshaller.schema.decorators.GraphQLSchemaDO.java
License:Open Source License
private JsonObject getSchemaJson(JsonObject rootJson) { Set<String> schemas = rootJson.getJsonObject(SCHEMAS, new JsonObject()).fieldNames(); if (schemas.size() == 0 || schemas.size() > 1) { throw new IllegalArgumentException("Failed to unmarshall. Expected 1 schema, found: " + schemas.size()); }/*from w w w . jav a 2 s .c o m*/ String schemaName = schemas.iterator().next(); return rootJson.getJsonObject(SCHEMAS).getJsonObject(schemaName); }
From source file:io.engagingspaces.graphql.query.QueryResult.java
License:Open Source License
/** * Creates a new {@link QueryResult} from * its json representation./*w w w .j av a2 s .c o m*/ * * @param json the json object */ public QueryResult(JsonObject json) { this.data = json.getJsonObject("data", new JsonObject()); this.succeeded = json.getBoolean("succeeded", false); List<QueryError> queryErrors = json.getJsonArray("errors", new JsonArray()).stream() .map(error -> new QueryError((JsonObject) error)).collect(Collectors.toList()); this.errors = queryErrors == null ? Collections.emptyList() : Collections.unmodifiableList(queryErrors); }