List of usage examples for io.vertx.core Future result
@Override T result();
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 va 2s . co m 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; }