Search in sources :

Example 1 with Rule

use of io.vertx.up.atom.Rule in project vertx-zero by silentbalanceyh.

the class FileRigor method verify.

@Override
public WebException verify(final Map<String, List<Rule>> rulers, final Object body) {
    WebException error = null;
    if (!rulers.isEmpty()) {
        // Merge rulers here.
        final Set<Rule> rules = new HashSet<>();
        Observable.fromIterable(rulers.keySet()).map(rulers::get).flatMap(Observable::fromIterable).subscribe(rules::add);
        // Rules here.
        error = Ruler.verify(rules, "BODY", body);
    }
    return error;
}
Also used : WebException(io.vertx.up.exception.WebException) Rule(io.vertx.up.atom.Rule) HashSet(java.util.HashSet)

Example 2 with Rule

use of io.vertx.up.atom.Rule in project vertx-zero by silentbalanceyh.

the class Validator method buildRulers.

private Map<String, List<Rule>> buildRulers(final String key) {
    if (RULERS.containsKey(key)) {
        return RULERS.get(key);
    } else {
        final JsonObject rule = ZeroCodex.getCodex(key);
        final Map<String, List<Rule>> ruler = new LinkedHashMap<>();
        if (null != rule) {
            Fn.itJObject(rule, (value, field) -> {
                // Checked valid rule config
                final List<Rule> rulers = this.buildRulers(value);
                if (!rulers.isEmpty()) {
                    ruler.put(field, rulers);
                }
            });
            if (!ruler.isEmpty()) {
                RULERS.put(key, ruler);
            }
        }
        return ruler;
    }
}
Also used : JsonObject(io.vertx.core.json.JsonObject) Rule(io.vertx.up.atom.Rule)

Example 3 with Rule

use of io.vertx.up.atom.Rule in project vertx-zero by silentbalanceyh.

the class Validator method buildRulers.

private List<Rule> buildRulers(final Object config) {
    final List<Rule> rulers = new ArrayList<>();
    if (null != config && config instanceof JsonArray) {
        final JsonArray configData = (JsonArray) config;
        Fn.itJArray(configData, JsonObject.class, (item, index) -> {
            final Rule ruler = Rule.create(item);
            if (null != ruler) {
                rulers.add(ruler);
            }
        });
    }
    return rulers;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Rule(io.vertx.up.atom.Rule)

Example 4 with Rule

use of io.vertx.up.atom.Rule in project vertx-zero by silentbalanceyh.

the class JObjectRigor method verify.

@Override
public WebException verify(final Map<String, List<Rule>> rulers, final Object body) {
    WebException error = null;
    if (!rulers.isEmpty()) {
        // Extract first element to JsonObject
        if (null != body) {
            final JsonObject data = (JsonObject) body;
            // Verify the whole JsonObject
            for (final String field : rulers.keySet()) {
                final Object value = data.getValue(field);
                final List<Rule> rules = rulers.get(field);
                // Verify each field.
                error = Ruler.verify(rules, field, value);
                if (null != error) {
                    break;
                }
            }
        }
    }
    return error;
}
Also used : WebException(io.vertx.up.exception.WebException) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) Rule(io.vertx.up.atom.Rule)

Aggregations

Rule (io.vertx.up.atom.Rule)4 JsonObject (io.vertx.core.json.JsonObject)2 WebException (io.vertx.up.exception.WebException)2 JsonArray (io.vertx.core.json.JsonArray)1 HashSet (java.util.HashSet)1