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

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

Introduction

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

Prototype

public JsonArray add(Object value) 

Source Link

Document

Add an Object to the JSON array.

Usage

From source file:io.flowly.auth.manager.UserManager.java

License:Open Source License

/**
 * Calculate the effective permissions granted to the given user.
 * The effective permission on each resource is the cumulative grants
 * given to the user either directly or indirectly.
 *
 * @param user JSON object representing the user in the auth graph.
 *///from  ww  w  .ja  v a 2  s  .  c  o m
private void getEffectivePermissions(JsonObject user) {
    JsonArray effectivePermissions = new JsonArray();

    // Holds the resource Ids and their respective permissions that have the cumulative
    // grant value (simple integer - rwx).
    Map<String, JsonObject> definedPermissions = new HashMap<>();

    // Start with direct permissions.
    getEffectivePermissions(user.getJsonArray(Permission.DIRECT_PERMISSIONS), definedPermissions);

    // Check permissions defined on groups.
    JsonArray effectiveMemberships = user.getJsonArray(User.EFFECTIVE_MEMBERSHIPS);

    if (effectiveMemberships != null) {
        for (Object mbr : effectiveMemberships) {
            JsonObject membership = (JsonObject) mbr;

            getEffectivePermissions(membership.getJsonArray(Permission.DIRECT_PERMISSIONS), definedPermissions);
        }
    }

    for (JsonObject permission : definedPermissions.values()) {
        effectivePermissions.add(permission);
    }

    user.put(Permission.EFFECTIVE_PERMISSIONS, effectivePermissions);
}

From source file:io.flowly.core.data.Entity.java

License:Open Source License

protected void validateStringProperty(JsonArray errors, String value, String message) {
    if (StringUtils.isBlank(value)) {
        errors.add(message);
    }//from  ww  w  .j  av  a2 s . c o m
}

From source file:io.flowly.core.data.FlowInstanceStep.java

License:Open Source License

public void addConnectingObjectId(String connectingObjectId) {
    JsonArray connectingObjectIds = getJsonArray(_FLOW_OBJECT_CONNECTING_OBJECT_IDS);

    if (connectingObjectIds == null) {
        connectingObjectIds = new JsonArray();
        put(_FLOW_OBJECT_CONNECTING_OBJECT_IDS, connectingObjectIds);
    }/*from   w  w  w. j  av  a2s  .c o  m*/

    connectingObjectIds.add(connectingObjectId);
}

From source file:io.flowly.core.data.manager.GraphManager.java

License:Open Source License

/**
 * Remove the vertex from the graph./*  w  ww.j av a 2  s  .  c  o m*/
 *
 * @param id the vertex id in auth graph.
 * @return an empty list or a list of validation errors based on whether the vertex was deleted or not.
 */
public JsonArray delete(Object id) {
    JsonArray errors = new JsonArray();

    try {
        Vertex vertex = getVertex(id);

        if (vertex != null) {
            // removing a vertex removes all its incident edges as well.
            vertex.remove();
        } else {
            errors.add("Vertex does not exist: " + id);
        }

        commit();
    } catch (Exception ex) {
        rollback();
        String error = "Unable to delete vertex: " + id;
        logger.error(error, ex);
        errors.add(error);
    }

    return errors;
}

From source file:io.flowly.core.security.User.java

License:Open Source License

/**
 * Ensure that the user attributes are valid.
 *
 * @param ifKeySpecified flag indicating that values should only be validated if the keys are specified.
 * @return an empty list or a list of validation errors based on whether the validation passed or not.
 *//*from  www .j a  va  2s  .  c om*/
public JsonArray validate(boolean ifKeySpecified) {
    JsonArray errors = new JsonArray();

    if (!ifKeySpecified || containsKey(USER_ID)) {
        validateStringProperty(errors, getUserId(), "User Id cannot be blank.");
    }

    if (!ifKeySpecified || containsKey(FIRST_NAME)) {
        validateStringProperty(errors, getFirstName(), "First name cannot be blank.");
    }

    if (!ifKeySpecified || containsKey(LAST_NAME)) {
        validateStringProperty(errors, getLastName(), "Last name cannot be blank.");
    }

    if (containsKey(PASSWORD)) {
        String password = getPassword();
        String confirmPassword = getString(CONFIRM_PASSWORD);

        validateStringProperty(errors, password, "Password cannot be blank.");
        validateStringProperty(errors, confirmPassword, "Confirm password cannot be blank.");

        if (!password.equals(confirmPassword)) {
            errors.add("Specified password does not match confirmed password.");
        }
    }

    return errors;
}

From source file:io.flowly.engine.data.manager.FlowReadManager.java

License:Open Source License

public JsonArray getFlows(String subjectId) {
    JsonArray flows = new JsonArray();

    try {//from  w  ww  .j a v a2 s .  c o m
        for (Vertex flowVertex : graph.traversal().V().has(Schema.V_P_FLOW_ID).toList()) {
            FlowMetadata flowMetadata = new FlowMetadata();
            flowMetadata.setFlowId((String) flowVertex.property(Schema.V_P_FLOW_ID).value());
            flowMetadata.setFlowType((String) flowVertex.property(Schema.V_P_FLOW_TYPE).value());
            flowMetadata.setAppId((String) flowVertex.property(Schema.V_P_APP_ID).value());

            flows.add(flowMetadata);
        }

        commit();
    } catch (Exception ex) {
        rollback();
        logger.error("Unable to get flows for: " + subjectId, ex);
        flows.clear();
    }

    return flows;
}

From source file:io.github.jdocker.DockerHost.java

License:Apache License

public JsonObject toJSON() {
    JsonObject ob = new JsonObject().put("name", getName()).put("uri", getUri());
    JsonArray propsArray = new JsonArray();
    for (Map.Entry<String, String> en : properties.entrySet()) {
        propsArray.add(new JsonObject().put(en.getKey(), en.getValue()));
    }/* w  w w . j  a v a  2  s .  com*/
    ob.put("properties", propsArray);
    ob.put("cpus", getCPUs()).put("memory", getMemory()).put("disksize", getDiskSize()).put("status",
            getStatus().toString());
    return ob;
}

From source file:io.github.jdocker.Machine.java

License:Apache License

public JsonObject toJSON() {
    JsonObject ob = new JsonObject().put("name", getName()).put("uri", getUri());
    JsonArray propsArray = new JsonArray();
    for (Map.Entry<String, String> en : properties.entrySet()) {
        propsArray.add(new JsonObject().put(en.getKey(), en.getValue()));
    }//from   ww w. j  a v a2  s.co m
    ob.put("properties", propsArray);
    return ob;
}

From source file:io.github.jdocker.MachineConfig.java

License:Apache License

public JsonObject toJSON() {
    JsonObject o = new JsonObject().put("type", MachineConfig.class.getName()).put("name", getName())
            .put("driver", getDriver()).put("uri", installURL);
    if (unmanagedMachine != null) {
        o.put("unmanagedMachine", unmanagedMachine.toJSON());
    }//ww w  .  ja v a  2s .c  o m
    if (swarmConfig != null) {
        o.put("swarmConfig", swarmConfig.toJson());
    }
    // labelsl
    JsonArray array = new JsonArray();
    for (Map.Entry<String, String> en : labels.entrySet()) {
        if (en.getKey().equals(en.getValue())) {
            array.add(en.getValue());
        } else {
            array.add(en.getKey() + '=' + en.getValue());
        }
    }
    o.put("labels", array);
    array = new JsonArray();
    for (String env : machineEnvironment) {
        array.add(env);
    }
    o.put("machineEnvironment", array);
    array = new JsonArray();
    for (String env : insecureRegistries) {
        array.add(env);
    }
    o.put("insecureRegistries", array);
    array = new JsonArray();
    for (String env : engineOptions) {
        array.add(env);
    }
    o.put("engineOptions", array);
    return o;
}

From source file:io.github.jdocker.SwarmConfig.java

License:Apache License

public JsonObject toJson() {
    JsonObject o = new JsonObject();
    o.put("dockerHost", dockerHost);
    o.put("swarmImage", swarmImage);
    o.put("swarmMaster", swarmMaster);
    o.put("swarmDiscoveryToken", swarmDiscoveryToken);
    o.put("swarmStrategy", swarmStrategy);
    o.put("swarmHostUri", swarmHostURI);
    o.put("swarmAdvertizeUri", swarmAdvertizeURI);
    JsonArray array = new JsonArray();
    for (String env : swarmEnvironment) {
        array.add(env);
    }/*  w w w  .  j  a v  a 2s.c o  m*/
    o.put("swarmEnvironment", array);
    return o;
}