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:io.flowly.auth.manager.UserManager.java

License:Open Source License

@Override
public JsonArray delete(Object id) {
    JsonArray errors;//ww  w  .j a  v  a  2 s .  co m

    try {
        // Cannot delete admin user.
        Vertex vertex = getVertex(id);
        if (!getPropertyValue(vertex, Schema.V_P_USER_ID).equals(ObjectKeys.ADMIN_USER_ID)) {
            errors = super.delete(id);
        } else {
            errors = new JsonArray().add("Cannot delete user: " + id);
        }

        commit();
    } catch (Exception ex) {
        rollback();
        errors = new JsonArray().add("Cannot delete user:" + id);
        logger.error(errors.getString(0), ex);
    }

    return errors;
}

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 . j  a va2s  . 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.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 .ja va2s. 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.//ww  w  .  j  a v  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.data.Resource.java

License:Open Source License

/**
 * Ensure that the resource 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  w  ww .  j  a v  a 2  s.  c  om*/
public JsonArray validate(boolean ifKeySpecified) {
    JsonArray errors = new JsonArray();

    if (!ifKeySpecified || containsKey(RESOURCE_ID)) {
        validateStringProperty(errors, getResourceId(), "Resource Id cannot be blank.");
    }

    return errors;
}

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

License:Open Source License

/**
 * Ensure that the group 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.
 *///  w  w  w .j  a  v a  2  s .com
public JsonArray validate(boolean ifKeySpecified) {
    JsonArray errors = new JsonArray();

    if (!ifKeySpecified || containsKey(GROUP_ID)) {
        validateStringProperty(errors, getGroupId(), "Group Id cannot be blank.");
    }

    return errors;
}

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

License:Open Source License

@Override
public JsonArray validate() {
    return new JsonArray();
}

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 w  w w .  ja v  a 2 s .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  . ja  va  2  s .com*/
        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  a2 s .co  m
    ob.put("properties", propsArray);
    ob.put("cpus", getCPUs()).put("memory", getMemory()).put("disksize", getDiskSize()).put("status",
            getStatus().toString());
    return ob;
}