Example usage for io.vertx.core.json JsonObject size

List of usage examples for io.vertx.core.json JsonObject size

Introduction

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

Prototype

public int size() 

Source Link

Document

Get the number of entries in the JSON object

Usage

From source file:org.entcore.feeder.ManualFeeder.java

License:Open Source License

public void createGroup(Message<JsonObject> message) {
    final JsonObject group = message.body().getJsonObject("group");
    if (group == null || group.size() == 0) {
        sendError(message, "missing.group");
        return;//from w w w .  j  a  v a  2s .co m
    }
    final String structureId = message.body().getString("structureId");
    final String classId = message.body().getString("classId");
    executeTransaction(message, new VoidFunction<TransactionHelper>() {
        @Override
        public void apply(TransactionHelper tx) throws ValidationException {
            Group.manualCreateOrUpdate(group, structureId, classId, tx);
        }
    });
}

From source file:org.entcore.feeder.utils.Validator.java

License:Open Source License

protected Validator(JsonObject schema, boolean notStoreLogins) {
    if (schema == null || schema.size() == 0) {
        throw new IllegalArgumentException("Missing schema.");
    }/*from ww w .  ja  v  a 2 s.  c o  m*/
    this.validate = schema.getJsonObject("validate");
    this.generate = schema.getJsonObject("generate");
    this.required = schema.getJsonArray("required");
    this.modifiable = schema.getJsonArray("modifiable");
    if (validate == null || generate == null || required == null || modifiable == null) {
        throw new IllegalArgumentException("Invalid schema.");
    }
    this.notStoreLogins = notStoreLogins;
}

From source file:org.entcore.feeder.utils.Validator.java

License:Open Source License

public String modifiableValidate(JsonObject object) {
    if (object == null) {
        return "Null object.";
    }/*from   w  w w  . ja  va  2s.  co  m*/
    final Set<String> attributes = new HashSet<>(object.fieldNames());
    JsonObject generatedAttributes = null;
    for (String attr : attributes) {
        JsonObject v = validate.getJsonObject(attr);
        if (v == null || !modifiable.contains(attr)) {
            object.remove(attr);
        } else {
            Object value = object.getValue(attr);
            String validator = v.getString("validator");
            String type = v.getString("type", "");
            String err;
            switch (type) {
            case "string":
                if (!required.contains(attr)
                        && (value == null || (value instanceof String && ((String) value).isEmpty()))) {
                    err = null;
                } else {
                    err = validString(attr, value, validator);
                }
                break;
            case "array-string":
                if (!required.contains(attr)
                        && (value == null || (value instanceof JsonArray && ((JsonArray) value).size() == 0))) {
                    err = null;
                } else {
                    err = validStringArray(attr, value, validator);
                }
                break;
            case "boolean":
                err = validBoolean(attr, value);
                break;
            case "login-alias":
                err = validLoginAlias(attr, value, validator);
                break;
            default:
                err = "Missing type validator: " + type;
            }
            if (err != null) {
                return err;
            }
            if (value != null && generate.containsKey(attr)) {
                JsonObject g = generate.getJsonObject(attr);
                if (g != null && "displayName".equals(g.getString("generator"))) {
                    if (generatedAttributes == null) {
                        generatedAttributes = new JsonObject();
                    }
                    generatedAttributes.put(attr + SEARCH_FIELD, removeAccents(value.toString()).toLowerCase());
                }
            }
        }
    }
    if (generatedAttributes != null) {
        object.mergeIn(generatedAttributes);
    }
    JsonObject g = generate.getJsonObject("modified");
    if (g != null) {
        nowDate("modified", object);
    }
    return (object.size() > 0) ? null : "Empty object.";
}

From source file:org.entcore.registry.services.impl.DefaultAppRegistryService.java

License:Open Source License

@Override
public void updateRole(String roleId, JsonObject role, JsonArray actions,
        Handler<Either<String, JsonObject>> handler) {
    if (defaultValidationParamsNull(handler, roleId, role, actions))
        return;//from  w ww.j  a v  a2  s . c o  m
    role.remove("id");
    String updateValues = "";
    if (role.size() > 0) {
        updateValues = "SET " + nodeSetPropertiesFromJson("role", role);
    }
    String updateActions = "RETURN DISTINCT role.id as id";
    if (actions.size() > 0) {
        updateActions = "DELETE r " + "WITH role " + "MATCH (n:Action) " + "WHERE n.name IN {actions} "
                + "CREATE UNIQUE role-[:AUTHORIZE]->n " + "RETURN DISTINCT role.id as id";
    }
    String query = "MATCH (role:Role {id : {roleId}}) " + "OPTIONAL MATCH role-[r:AUTHORIZE]->(a:Action) "
            + updateValues + updateActions;
    role.put("actions", actions).put("roleId", roleId);
    neo.execute(query, role, validUniqueResultHandler(handler));
}

From source file:org.entcore.timeline.events.DefaultTimelineEventStore.java

License:Open Source License

@Override
public void get(final UserInfos user, List<String> types, int offset, int limit, JsonObject restrictionFilter,
        boolean mine, final Handler<JsonObject> result) {
    final String recipient = user.getUserId();
    final String externalId = user.getExternalId();
    if (recipient != null && !recipient.trim().isEmpty()) {
        final JsonObject query = new JsonObject().put("deleted", new JsonObject().put("$exists", false))
                .put("date", new JsonObject().put("$lt", MongoDb.now()));
        if (externalId == null || externalId.trim().isEmpty()) {
            query.put(mine ? "sender" : "recipients.userId", recipient);
        } else {//from   w  w w . j  av  a2  s  .c om
            query.put(mine ? "sender" : "recipients.userId", new JsonObject().put("$in",
                    new fr.wseduc.webutils.collections.JsonArray().add(recipient).add(externalId)));
        }
        query.put("reportAction.action", new JsonObject().put("$ne", "DELETE"));
        if (types != null && !types.isEmpty()) {
            if (types.size() == 1) {
                query.put("type", types.get(0));
            } else {
                JsonArray typesFilter = new fr.wseduc.webutils.collections.JsonArray();
                for (String t : types) {
                    typesFilter.add(new JsonObject().put("type", t));
                }
                query.put("$or", typesFilter);
            }
        }
        if (restrictionFilter != null && restrictionFilter.size() > 0) {
            JsonArray nor = new fr.wseduc.webutils.collections.JsonArray();
            for (String type : restrictionFilter.getMap().keySet()) {
                for (Object eventType : restrictionFilter.getJsonArray(type,
                        new fr.wseduc.webutils.collections.JsonArray())) {
                    nor.add(new JsonObject().put("type", type).put("event-type", eventType.toString()));
                }
                query.put("$nor", nor);
            }
        }
        JsonObject sort = new JsonObject().put("created", -1);
        JsonObject keys = new JsonObject().put("message", 1).put("params", 1).put("date", 1).put("sender", 1)
                .put("comments", 1).put("type", 1).put("event-type", 1).put("resource", 1)
                .put("sub-resource", 1).put("add-comment", 1);
        if (!mine) {
            keys.put("recipients",
                    new JsonObject().put("$elemMatch", new JsonObject().put("userId", user.getUserId())));
            keys.put("reporters",
                    new JsonObject().put("$elemMatch", new JsonObject().put("userId", user.getUserId())));
        }

        mongo.find(TIMELINE_COLLECTION, query, sort, keys, offset, limit, 100,
                new Handler<Message<JsonObject>>() {
                    @Override
                    public void handle(Message<JsonObject> message) {
                        result.handle(message.body());
                    }
                });
    } else {
        result.handle(invalidArguments());
    }
}