Example usage for io.vertx.core.json JsonArray JsonArray

List of usage examples for io.vertx.core.json JsonArray JsonArray

Introduction

In this page you can find the example usage for io.vertx.core.json JsonArray JsonArray.

Prototype

public JsonArray() 

Source Link

Document

Create an empty instance

Usage

From source file:org.etourdot.vertx.marklogic.model.client.impl.DocumentsImpl.java

License:Open Source License

public DocumentsImpl() {
    this.documents = new JsonArray();
}

From source file:org.etourdot.vertx.marklogic.model.management.Privilege.java

License:Open Source License

public Privilege() {
    roles = new JsonArray();
}

From source file:org.etourdot.vertx.marklogic.model.management.Role.java

License:Open Source License

public Role() {
    roles = new JsonArray();
    privileges = new JsonArray();
}

From source file:org.etourdot.vertx.marklogic.model.options.DatabasesOptions.java

License:Open Source License

/**
 * Range element indexes/*from  w  ww . j  ava2  s .c o  m*/
 */
public DatabasesOptions addRangeElementIndex(RangeElementIndex index) {
    if (operation == null) {
        operation = new JsonObject();
    }
    JsonArray indexes = operation.getJsonArray("range-element-indexes");
    if (indexes == null) {
        indexes = new JsonArray();
    }
    indexes.add(index.toJson());
    return this;
}

From source file:org.etourdot.vertx.marklogic.model.options.DatabasesOptions.java

License:Open Source License

/**
 * Range attribute indexes/*  w ww.j a va 2  s .  co m*/
 */
public DatabasesOptions addRangeAttributeIndex(RangeAttributeIndex index) {
    if (operation == null) {
        operation = new JsonObject();
    }
    JsonArray indexes = operation.getJsonArray("range-element-attribute-indexes");
    if (indexes == null) {
        indexes = new JsonArray();
    }
    indexes.add(index.toJson());
    return this;
}

From source file:org.etourdot.vertx.marklogic.model.options.RestApiOptions.java

License:Open Source License

public void restApi(JsonObject jsonObject) {
    this.restApis = new JsonArray();
    this.restApis.add(jsonObject);
}

From source file:org.folio.auth.permissions_module.impl.MongoPermissionsStore.java

@Override
public Future<Boolean> addPermission(String permission, String tenant) {
    Future<Boolean> future = Future.future();
    JsonObject query = new JsonObject().put("permission_name", permission).put("tenant", tenant);
    mongoClient.find("permissions", query, res -> {
        if (res.succeeded() && res.result().size() > 0) { //permission already exists
            future.fail("Permission already exists");
        } else {/*w ww .  ja  va 2  s.com*/
            JsonObject insert = new JsonObject().put("permission_name", permission).put("tenant", tenant)
                    .put("sub_permissions", new JsonArray());
            mongoClient.insert("permissions", insert, res2 -> {
                if (res2.succeeded()) {
                    future.complete(true);
                } else {
                    future.fail("Unable to insert permission: " + res2.cause().getMessage());
                }
            });
        }
    });
    return future;
}

From source file:org.folio.auth.permissions_module.impl.MongoPermissionsStore.java

@Override
public Future<JsonArray> getSubPermissions(String permission, String 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.failed() || res.result().size() < 1) {
            future.fail("Query unsuccessful");
        } else {//from w  w  w .java  2  s  .  com
            JsonObject permObject = res.result().get(0);
            future.complete(permObject.getJsonArray("sub_permissions"));
        }
    });
    return future;
}

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 + "'");
            /*//from ww w.  j  a va 2s. 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;
}

From source file:org.folio.auth.permissions_module.impl.MongoPermissionsStore.java

@Override
public Future<Boolean> removePermission(String permission, String tenant) {
    Future<Boolean> future = Future.future();
    JsonObject query = new JsonObject().put("permission_name", permission).put("tenant", tenant);
    mongoClient.find("permissions", query, res -> {
        if (res.failed() || res.result().size() < 1) {
            future.fail("Unable to find permission to delete");
        } else {/*from w  w w.ja  v  a2  s  .co m*/
            //Find all permissions that list this permission as a sub
            /*
            JsonObject subQuery = new JsonObject().put("sub_permissions", new JsonObject()
              .put("$in", new JsonArray().add(permission)));
             */
            JsonObject subUpdate = new JsonObject().put("$pullAll",
                    new JsonObject().put("sub_permissions", new JsonArray().add(permission)));
            mongoClient.updateCollectionWithOptions("permissions", new JsonObject(), subUpdate, updateOptions,
                    res2 -> {
                        if (res2.failed()) {
                            future.fail("Unable to remove sub permissions: " + res2.cause().getMessage());
                        } else {
                            //Now delete the actual permission, since the sub permissions are clean
                            mongoClient.removeDocument("permissions", query, res3 -> {
                                if (res3.failed()) {
                                    future.fail("Unable to delete permission: " + res3.cause().getMessage());
                                } else {
                                    future.complete(true);
                                }
                            });
                        }
                    });
        }
    });
    return future;
}