List of usage examples for io.vertx.core.json JsonArray JsonArray
public JsonArray()
From source file:org.folio.auth.permissions_module.impl.MongoPermissionsStore.java
@Override public Future<Boolean> removeSubPermission(String permission, String sub, String tenant) { Future<Boolean> future = Future.future(); JsonObject query = new JsonObject().put("permission_name", permission).put("tenant", tenant); JsonObject update = new JsonObject().put("$pull", new JsonObject().put("sub_permissions", new JsonObject().put("$in", new JsonArray().add(sub)))); mongoClient.update("permissions", query, update, res -> { if (!res.succeeded()) { future.fail("Unable to remove sub permissiion"); } else {//from w ww .j av a 2s .co m future.complete(true); } }); return future; }
From source file:org.folio.auth.permissions_module.impl.MongoPermissionsStore.java
@Override public Future<Boolean> addUser(String user, String tenant) { JsonObject query = new JsonObject().put("username", user).put("tenant", tenant); Future<Boolean> future = Future.future(); mongoClient.find("users", query, res -> { if (res.result().size() > 0) { future.complete(false);/*from www.j a v a 2 s . co m*/ } else { JsonObject insert = new JsonObject().put("username", user).put("tenant", tenant).put("permissions", new JsonArray()); mongoClient.insert("users", insert, res2 -> { if (res2.succeeded()) { future.complete(true); } else { future.fail("Unable to insert new user"); } }); } }); return future; }
From source file:org.folio.auth.permissions_module.impl.MongoPermissionsStore.java
public Future<JsonArray> getPermissionsForUser(String user, String tenant, Boolean expand) { JsonObject query = new JsonObject().put("username", user).put("tenant", tenant); Future<JsonArray> future = Future.future(); mongoClient.find("users", query, (AsyncResult<List<JsonObject>> res) -> { if (res.result().size() < 1) { future.fail("No such user"); } else {//from ww w . j a v a 2s . c om JsonObject userObject = res.result().get(0); logger.debug("Permissions> Permissions for user " + user + ": " + userObject.encode()); JsonArray permissions = userObject.getJsonArray("permissions"); if (expand) { ArrayList<Future> futureList = new ArrayList<>(); for (Object o : permissions) { String permissionName = (String) o; Future<JsonArray> expandPermissionFuture = this.getExpandedPermissions(permissionName, tenant); futureList.add(expandPermissionFuture); } logger.debug("Permissions> Assembling CompositeFuture of " + futureList.size() + " permissions to expand"); CompositeFuture compositeFuture = CompositeFuture.all(futureList); compositeFuture.setHandler(res2 -> { if (res2.failed()) { future.fail(res2.cause()); } else { JsonArray allPermissions = new JsonArray(); for (Future f : futureList) { JsonArray arr = (JsonArray) f.result(); for (Object o : arr) { String perm = (String) o; if (!allPermissions.contains(perm)) { allPermissions.add(perm); } } } logger.debug( "Permissions> Returning list of " + allPermissions.size() + " permissions"); future.complete(allPermissions); } }); } else { future.complete(permissions); } } }); return future; }
From source file:org.gooru.nucleus.handlers.resources.processors.repositories.activejdbc.dbhandlers.DBHelper.java
static JsonObject getDuplicateResourcesByURL(String inputURL) { JsonObject returnValue = null;//from w w w .ja v a 2s . c o m try { PGobject contentFormat = new PGobject(); contentFormat.setType(AJEntityResource.CONTENT_FORMAT_TYPE); contentFormat.setValue(AJEntityResource.VALID_CONTENT_FORMAT_FOR_RESOURCE); LazyList<AJEntityResource> result = AJEntityResource .findBySQL(AJEntityResource.SQL_GETDUPLICATERESOURCESBYURL, inputURL, contentFormat); LOGGER.debug("getDuplicateResourcesByURL ! : {} ", result.toString()); if (result.size() > 0) { JsonArray retArray = new JsonArray(); for (AJEntityResource model : result) { retArray.add(model.get(AJEntityResource.RESOURCE_ID).toString()); } returnValue = new JsonObject().put("duplicate_ids", retArray); } } catch (SQLException se) { LOGGER.error("getDuplicateResourcesByURL ! : {} ", se); } return returnValue; }
From source file:org.gooru.nucleus.handlers.resources.processors.repositories.activejdbc.dbhandlers.DBHelper.java
static JsonObject getCopiesOfAResource(AJEntityResource resource, String originalResourceId) { JsonObject returnValue = null;/* ww w . j a va 2s .c o m*/ setPGObject(resource, AJEntityResource.CONTENT_FORMAT, AJEntityResource.CONTENT_FORMAT_TYPE, AJEntityResource.VALID_CONTENT_FORMAT_FOR_RESOURCE); LazyList<AJEntityResource> result = AJEntityResource.findBySQL(AJEntityResource.SQL_GETCOPIESOFARESOURCE, AJEntityResource.VALID_CONTENT_FORMAT_FOR_RESOURCE, originalResourceId); if (result.size() > 0) { JsonArray idArray = new JsonArray(); JsonArray collectionIdArray = new JsonArray(); String collectionId; for (AJEntityResource model : result) { idArray.add(model.get(AJEntityResource.RESOURCE_ID).toString()); collectionId = model.getString(AJEntityResource.COLLECTION_ID); if (collectionId != null && !collectionId.isEmpty()) { collectionIdArray.add(collectionId); } } returnValue = new JsonObject().put("resource_copy_ids", idArray) .put(AJEntityResource.COLLECTION_ID, collectionIdArray).put("id", originalResourceId); LOGGER.debug("getCopiesOfAResource ! : {} ", returnValue.toString()); } return returnValue; }
From source file:org.hawkular.apm.examples.vertx.opentracing.orderlog.OrderLogVerticle.java
License:Apache License
private void setupConsumers() { logger.info("Setting up consumers"); getVertx().eventBus().consumer("joined").handler( message -> logger.info(String.format("Acknowledging that %s just joined", message.body()))); MessageConsumer<JsonObject> ordersConfirmedConsumer = getVertx().eventBus().consumer("Orders.confirmed"); MessageConsumer<JsonObject> getOrdersConsumer = getVertx().eventBus().consumer("OrderLog.getOrders"); getOrdersConsumer.handler(message -> { JsonObject order = message.body(); SpanContext spanCtx = tracer.extract(Format.Builtin.TEXT_MAP, new VertxMessageExtractAdapter(order)); try (Span getOrdersSpan = tracer.buildSpan("GetOrders").asChildOf(spanCtx).start()) { try (Span ignored = tracer.buildSpan("RetrieveOrders").asChildOf(getOrdersSpan) .withTag("database.url", "OrdersDB") .withTag("database.statement", "SELECT order FROM Orders WHERE accountId = ?").start()) { String acctId = order.getString("accountId"); JsonArray myOrders = orders.get(acctId); if (myOrders == null) { sendError(1, "Account not found", message, getOrdersSpan); } else { message.reply(myOrders); }/*from w ww. ja v a2 s . c o m*/ } } }).completionHandler(result -> { if (result.succeeded()) { getVertx().eventBus().send("joined", "OrderLog.getOrders"); logger.info("Registration has completed."); } else { logger.warning("Could not register: " + result.cause().getMessage()); } }); ordersConfirmedConsumer.handler(message -> { JsonObject order = message.body(); SpanContext spanCtx = tracer.extract(Format.Builtin.TEXT_MAP, new VertxMessageExtractAdapter(order)); try (Span orderConfirmedSpan = tracer.buildSpan("StoreOrder").asChildOf(spanCtx).start()) { try (Span ignored = tracer.buildSpan("WriteOrder").asChildOf(orderConfirmedSpan) .withTag("database.url", "OrdersDB") .withTag("database.statement", "UPDATE Orders SET order=?").start()) { String acctId = order.getString("accountId"); JsonArray myOrders = orders.get(acctId); if (myOrders == null) { myOrders = new JsonArray(); orders.put(acctId, myOrders); } myOrders.add(order); } } }).completionHandler(result -> { if (result.succeeded()) { getVertx().eventBus().send("joined", "Orders.confirmed"); logger.info("Registration has completed."); } else { logger.warning("Could not register: " + result.cause().getMessage()); } }); }
From source file:org.hawkular.apm.examples.vertx.opentracing.OrderLog.java
License:Apache License
protected void initOrdersConfirmedConsumer(EventBus eb, Tracer tracer) { ordersConfirmedConsumer = eb.consumer("Orders.confirmed"); ordersConfirmedConsumer.handler(message -> { JsonObject order = message.body(); SpanContext spanCtx = tracer.extract(Format.Builtin.TEXT_MAP, new VertxMessageExtractAdapter(order)); try (Span orderConfirmedSpan = tracer.buildSpan("StoreOrder").asChildOf(spanCtx) .withTag("service", "OrderLog").start()) { try (Span storeOrderSpan = tracer.buildSpan("WriteOrder").asChildOf(orderConfirmedSpan) .withTag("database.url", "OrdersDB") .withTag("database.statement", "UPDATE Orders SET order=?").start()) { String acctId = order.getString("accountId"); JsonArray myOrders = orders.get(acctId); if (myOrders == null) { myOrders = new JsonArray(); orders.put(acctId, myOrders); }/* w w w. j a va2s . com*/ myOrders.add(order); } } }); }
From source file:org.hawkular.metrics.clients.ptrans.Configuration.java
License:Apache License
private static JsonObject getHttpHeaders(Properties properties) { JsonObject jsonObject = new JsonObject(); Set<Object> keys = properties.keySet(); String namePrefix = "metrics.http.header."; String nameSuffix = ".name"; Set<String> headerIds = keys.stream().filter(k -> k instanceof String).map(String.class::cast) .filter(name -> name.startsWith(namePrefix) && name.endsWith(nameSuffix)) .map(name -> name.substring(namePrefix.length(), name.length() - nameSuffix.length())) .collect(Collectors.toSet()); headerIds.forEach(headerId -> {//w w w . jav a2 s. c om String headerName = properties.getProperty(namePrefix + headerId + nameSuffix); String valuePrefix = namePrefix + headerId + ".value."; List<Integer> headerPriorities = keys.stream().filter(k -> k instanceof String).map(String.class::cast) .filter(name -> name.startsWith(valuePrefix)).map(name -> name.substring(valuePrefix.length())) .filter(orderStr -> orderStr.matches("\\d{1,2}")).map(Integer::valueOf).sorted() .collect(toList()); if (!headerPriorities.isEmpty()) { if (headerPriorities.size() == 1) { String headerValue = properties.getProperty(valuePrefix + headerPriorities.iterator().next()); jsonObject.put(headerName, headerValue); } else { JsonArray headerValues = new JsonArray(); headerPriorities.forEach(headerPriority -> { String headerValue = properties.getProperty(valuePrefix + headerPriority); headerValues.add(headerValue); }); jsonObject.put(headerName, headerValues); } } }); return jsonObject; }
From source file:org.jberet.vertx.rest.JBeretRouterConfig.java
License:Open Source License
private static void getJobs(final RoutingContext routingContext) { final JobEntity[] jobEntities = JobService.getInstance().getJobs(); final JsonArray jsonArray = new JsonArray(); for (JobEntity jobEntity : jobEntities) { jsonArray.add(JsonObject.mapFrom(jobEntity)); }/*w w w .ja v a2 s.c o m*/ sendJsonResponse(routingContext, jsonArray.encodePrettily()); }
From source file:org.jberet.vertx.rest.JBeretRouterConfig.java
License:Open Source License
private static void getStepExecutions(final RoutingContext routingContext) { final long jobExecutionId = getIdAsLong(routingContext, "jobExecutionId"); final StepExecutionEntity[] stepExecutions = JobService.getInstance().getStepExecutions(jobExecutionId); final JsonArray jsonArray = new JsonArray(); for (StepExecutionEntity e : stepExecutions) { jsonArray.add(JsonObject.mapFrom(e)); }/* w ww.ja va 2 s .c om*/ sendJsonResponse(routingContext, jsonArray.encodePrettily()); }