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;
}
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;
}
}
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;
}
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;
}
Aggregations