List of usage examples for io.vertx.core.json JsonArray isEmpty
public boolean isEmpty()
From source file:org.folio.auth.permissions_module.impl.MongoPermissionsStore.java
@Override public Future<JsonArray> getExpandedPermissions(String permission, String tenant) { //System.out.println("Permissions> Expanding permission '"+ permission + "' on tenant '"+ // tenant + "'"); JsonObject query = new JsonObject().put("permission_name", permission).put("tenant", tenant); JsonArray permList = new JsonArray(); Future<JsonArray> future = Future.future(); mongoClient.find("permissions", query, res -> { if (res.succeeded() && res.result().size() > 0) { //System.out.println("Permissions> Successfully queried mongo for '"+ permission + "' on tenant '"+ // tenant + "'"); /*/* w ww .j a v a2 s . c o m*/ If there are no subpermissions, go ahead and complete the future with the given value of the JsonArray If there are subpermissions, create a list of new futures, by calling walkPerms for each sub permission, then create a composite future from these new futures, with a handler that completes the original future when they return */ JsonObject permObj = res.result().get(0); permList.add(permission); JsonArray subPerms = permObj.getJsonArray("sub_permissions"); LinkedList<Future> futureList = new LinkedList<>(); if (subPerms != null && !subPerms.isEmpty()) { logger.debug("Permissions> " + subPerms.size() + " subs to process for '" + permission + "'"); for (Object o : subPerms) { String sub = (String) o; Future<JsonArray> newFuture = getExpandedPermissions(sub, tenant); futureList.add(newFuture); } logger.debug("Permissions> Creating CompositeFuture to expand " + permission + " into " + futureList.size() + " subs: " + subPerms.encode()); CompositeFuture compositeFuture = CompositeFuture.all(futureList); compositeFuture.setHandler(res2 -> { if (res2.succeeded()) { //Get output of contained futures and complete the future here for (Future f : futureList) { JsonArray arr = (JsonArray) f.result(); for (Object o : arr) { permList.add(o); } } future.complete(permList); } else { future.fail("Unable to populate permissions: " + res2.cause().getMessage()); } }); } else { //System.out.println("Permissions> No sub-permissions found for '" + permission + "'"); future.complete(permList); } } else { future.fail("No permission '" + permission + "' found for tenant '" + tenant + "'"); } }); return future; }