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

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

Introduction

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

Prototype

public int size() 

Source Link

Document

Get the number of values in this JSON array

Usage

From source file:org.entcore.registry.filters.RoleGroupFilter.java

License:Open Source License

@Override
public void authorize(HttpServerRequest request, Binding binding, UserInfos user,
        final Handler<Boolean> handler) {
    Map<String, UserInfos.Function> functions = user.getFunctions();
    final String groupId = request.params().get("groupId");
    final String roleId = request.params().get("roleId");

    if (groupId == null || groupId.trim().isEmpty() || roleId == null || roleId.trim().isEmpty()) {
        handler.handle(false);//from  w w  w.  j  a v  a  2  s. c  o m
        return;
    }

    if (functions == null || functions.isEmpty()) {
        handler.handle(false);
        return;
    }
    if (functions.containsKey(DefaultFunctions.SUPER_ADMIN)) {
        handler.handle(true);
        return;
    }
    final UserInfos.Function adminLocal = functions.get(DefaultFunctions.ADMIN_LOCAL);
    if (adminLocal == null || adminLocal.getScope() == null) {
        handler.handle(false);
        return;
    }

    final JsonObject params = new JsonObject().put("groupId", groupId).put("roleId", roleId)
            .put("scopedStructures", new fr.wseduc.webutils.collections.JsonArray(adminLocal.getScope()));

    final String regularQuery = "MATCH (s:Structure)<-[:BELONGS*0..1]-()<-[:DEPENDS]-(:Group {id: {groupId}}), (r:Role) "
            + "WHERE s.id IN {scopedStructures} AND r.id = {roleId} "
            + "AND NOT((:Application {locked: true})-[:PROVIDE]->(:Action)<-[:AUTHORIZE]-(r)) "
            + "OPTIONAL MATCH (ext:Application:External)-[:PROVIDE]->(:Action)<-[:AUTHORIZE]-(r) "
            + "RETURN count(distinct r) = 1 as exists, count(distinct ext) as externalApps";
    final String externalQuery = "MATCH (r:Role {id : {roleId}}), "
            + "(ext:Application:External)-[:PROVIDE]->(:Action)<-[:AUTHORIZE]-(r), "
            + "(s:Structure)-[:HAS_ATTACHMENT*0..]->(p:Structure) "
            + "WHERE s.id IN {scopedStructures} AND p.id = ext.structureId AND (ext.inherits = true OR p = s) "
            + "RETURN (count(distinct r) = 1 AND count(distinct ext) = {nbExt}) as exists";

    neo4j.execute(regularQuery, params, new Handler<Message<JsonObject>>() {
        public void handle(Message<JsonObject> event) {
            JsonArray r = event.body().getJsonArray("result");
            if ("ok".equals(event.body().getString("status")) && r != null && r.size() == 1) {
                boolean exists = r.getJsonObject(0).getBoolean("exists", false);
                int nbExt = r.getJsonObject(0).getInteger("nbExt", 0);
                if (!exists) {
                    handler.handle(false);
                } else if (nbExt == 0) {
                    handler.handle(true);
                } else {
                    neo4j.execute(externalQuery, params.put("nbExt", nbExt),
                            new Handler<Message<JsonObject>>() {
                                public void handle(Message<JsonObject> event) {
                                    JsonArray r = event.body().getJsonArray("result");
                                    if ("ok".equals(event.body().getString("status")) && r != null
                                            && r.size() == 1) {
                                        handler.handle(r.getJsonObject(0).getBoolean("exists", false));
                                    } else {
                                        handler.handle(false);
                                    }
                                }
                            });
                }
            } else {
                handler.handle(false);
            }

        }
    });

}

From source file:org.entcore.registry.filters.WidgetLinkFilter.java

License:Open Source License

@Override
public void authorize(HttpServerRequest request, Binding binding, UserInfos user,
        final Handler<Boolean> handler) {

    Map<String, UserInfos.Function> functions = user.getFunctions();

    if (functions == null || functions.isEmpty()) {
        handler.handle(false);/* w  ww.  j a  va 2s . c o m*/
        return;
    }
    if (functions.containsKey(DefaultFunctions.SUPER_ADMIN)) {
        handler.handle(true);
        return;
    }
    final UserInfos.Function adminLocal = functions.get(DefaultFunctions.ADMIN_LOCAL);
    if (adminLocal == null || adminLocal.getScope() == null) {
        handler.handle(false);
        return;
    }

    final String groupId = request.params().get("groupId");
    if (groupId == null || groupId.trim().isEmpty()) {
        handler.handle(false);
        return;
    }

    String query = "MATCH (s:Structure)<-[:BELONGS*0..1]-()<-[:DEPENDS]-(g:Group {id : {groupId}}) "
            + "WHERE s.id IN {adminScope} " + "RETURN count(g) = 1 as exists";
    JsonObject params = new JsonObject().put("groupId", groupId).put("adminScope",
            new fr.wseduc.webutils.collections.JsonArray(adminLocal.getScope()));

    neo4j.execute(query, params, new Handler<Message<JsonObject>>() {
        public void handle(Message<JsonObject> event) {
            JsonArray r = event.body().getJsonArray("result");
            handler.handle("ok".equals(event.body().getString("status")) && r != null && r.size() == 1
                    && r.getJsonObject(0).getBoolean("exists", false));
        }
    });
}

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 www . j  a v a 2 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.registry.services.impl.DefaultAppRegistryService.java

License:Open Source License

@Override
public void linkRolesToGroup(String groupId, JsonArray roleIds, Handler<Either<String, JsonObject>> handler) {
    JsonObject params = new JsonObject();
    params.put("groupId", groupId);
    if (groupId != null && !groupId.trim().isEmpty()) {
        String deleteQuery = "MATCH (m:Group)-[r:AUTHORIZED]-(:Role) " + "WHERE m.id = {groupId} " + "DELETE r";
        if (roleIds == null || roleIds.size() == 0) {
            neo.execute(deleteQuery, params, validEmptyHandler(handler));
        } else {/*  w  ww  .  j av  a2  s. co m*/
            StatementsBuilder s = new StatementsBuilder().add(deleteQuery, params);
            String createQuery = "MATCH (n:Role), (m:Group) " + "WHERE m.id = {groupId} AND n.id IN {roles} "
                    + "CREATE UNIQUE m-[:AUTHORIZED]->n";
            s.add(createQuery, params.copy().put("roles", roleIds));
            neo.executeTransaction(s.build(), null, true, validEmptyHandler(handler));
        }
    } else {
        handler.handle(new Either.Left<String, JsonObject>("invalid.arguments"));
    }
}

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

License:Open Source License

@Override
public void createApplication(String structureId, JsonObject application, JsonArray actions,
        final Handler<Either<String, JsonObject>> handler) {
    if (defaultValidationParamsNull(handler, application, application.getString("name")))
        return;// w w w.j  ava2 s.  c  om
    final String applicationName = application.getString("name");
    final String id = UUID.randomUUID().toString();
    final String address = application.getString("address");
    application.put("scope", new fr.wseduc.webutils.collections.JsonArray(
            "[\"" + application.getString("scope", "").replaceAll("\\s", "\",\"") + "\"]"));
    application.put("id", id);
    final String createApplicationQuery = "MATCH (n:Application) " + "WHERE n.name = {applicationName} "
            + "WITH count(*) AS exists " + "WHERE exists=0 " + "CREATE (m:Application {props}) "
            + "RETURN m.id as id";
    final JsonObject params = new JsonObject().put("applicationName", applicationName);
    if (structureId != null && !structureId.trim().isEmpty()) {
        application.put("structureId", structureId);
    }
    final StatementsBuilder b = new StatementsBuilder().add(createApplicationQuery,
            params.copy().put("props", application));
    if (actions != null && actions.size() > 0) {
        for (Object o : actions) {
            JsonObject json = (JsonObject) o;
            String type;
            List<String> removeLabels = new ArrayList<>();
            removeLabels.add("ResourceAction");
            removeLabels.add("AuthenticatedAction");
            removeLabels.add("WorkflowAction");
            switch (json.getString("type", "WORKFLOW")) {
            case "RESOURCE":
                type = "Resource";
                break;
            case "AUTHENTICATED":
                type = "Authenticated";
                break;
            default:
                type = "Workflow";
                break;
            }
            removeLabels.remove(type + "Action");
            String createAction = "MERGE (a:Action {name:{name}}) " + "REMOVE a:"
                    + Joiner.on(":").join(removeLabels) + " "
                    + "SET a.displayName = {displayName}, a.type = {type}, a:" + type + "Action " + "WITH a "
                    + "MATCH (n:Application) " + "WHERE n.name = {applicationName} "
                    + "CREATE UNIQUE n-[r:PROVIDE]->a " + "RETURN a.name as name";
            b.add(createAction, json.put("applicationName", applicationName).put("type",
                    "SECURED_ACTION_" + json.getString("type", "WORKFLOW")));
        }
        final String removeNotWorkflowInRole = "MATCH (:Role)-[r:AUTHORIZE]->(a:Action) "
                + "WHERE a:ResourceAction OR a:AuthenticatedAction " + "DELETE r";
        b.add(removeNotWorkflowInRole);
    } else if (address != null && !address.trim().isEmpty()) {
        String query2 = "MATCH (n:Application) " + "WHERE n.id = {id} "
                + "CREATE UNIQUE n-[r:PROVIDE]->(a:Action:WorkflowAction {type: {type}, "
                + "name:{name}, displayName:{displayName}}) " + "RETURN a.name as name";
        b.add(query2, new JsonObject().put("id", id).put("type", "SECURED_ACTION_WORKFLOW")
                .put("name", applicationName + "|address").put("displayName", applicationName + ".address"));
    }
    neo.executeTransaction(b.build(), null, true, new Handler<Message<JsonObject>>() {
        @Override
        public void handle(Message<JsonObject> m) {
            JsonArray results = m.body().getJsonArray("results");
            if ("ok".equals(m.body().getString("status")) && results != null) {
                JsonArray r = results.getJsonArray(0);
                JsonObject j;
                if (r.size() > 0) {
                    j = r.getJsonObject(0);
                } else {
                    j = new JsonObject();
                }
                handler.handle(new Either.Right<String, JsonObject>(j));
            } else {
                handler.handle(new Either.Left<String, JsonObject>(m.body().getString("message")));
            }
        }
    });
}

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

License:Open Source License

@Override
public void getApplication(String applicationId, final Handler<Either<String, JsonObject>> handler) {
    String query = "MATCH (n:Application) " + "WHERE n.id = {id} " + "RETURN n.id as id, n.name as name, "
            + "n.grantType as grantType, n.secret as secret, n.address as address, "
            + "n.icon as icon, n.target as target, n.displayName as displayName, "
            + "n.scope as scope, n.pattern as pattern, n.casType as casType";
    JsonObject params = new JsonObject().put("id", applicationId);
    neo.execute(query, params, new Handler<Message<JsonObject>>() {
        @Override/*from ww w .j av a2 s . co m*/
        public void handle(Message<JsonObject> res) {
            JsonArray r = res.body().getJsonArray("result");
            if (r != null && r.size() == 1) {
                JsonObject j = r.getJsonObject(0);
                JsonArray scope = j.getJsonArray("scope");
                if (scope != null && scope.size() > 0) {
                    j.put("scope", Joiner.on(" ").join(scope));
                } else {
                    j.put("scope", "");
                }
            }
            handler.handle(validUniqueResult(res));
        }
    });
}

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

License:Open Source License

@Override
public void listCasConnectors(final Handler<Either<String, JsonArray>> handler) {
    String query = "MATCH (app:Application) " + "WHERE has(app.casType) and app.casType <> '' "
            + "RETURN app.casType as service, app.address as address, COLLECT(app.pattern) as patterns";
    neo.execute(query, (JsonObject) null, validResultHandler(new Handler<Either<String, JsonArray>>() {
        public void handle(Either<String, JsonArray> event) {
            if (event.isLeft()) {
                handler.handle(event);//from  w  w w  .  ja  v a2 s .c  om
                return;
            }
            JsonArray results = event.right().getValue();
            for (Object o : results) {
                JsonObject app = (JsonObject) o;
                String address = app.getString("address", "");
                JsonArray patterns = app.getJsonArray("patterns",
                        new fr.wseduc.webutils.collections.JsonArray());
                if (patterns.size() == 0 || patterns.size() > 0 && patterns.getString(0).isEmpty()) {
                    final URL addressURL = checkCasUrl(address);

                    if (addressURL != null) {
                        String pattern = "^\\Q" + addressURL.getProtocol() + "://" + addressURL.getHost()
                                + (addressURL.getPort() > 0 ? ":" + addressURL.getPort() : "") + "\\E.*";
                        patterns.add(pattern);
                    } else {
                        log.error("Url for registered service : " + app.getString("service", "")
                                + " is malformed : " + address);
                    }
                }
            }
            handler.handle(new Either.Right<String, JsonArray>(results));
        }
    }));
}

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

License:Open Source License

@Override
public void listExternalApps(String structureId, final Handler<Either<String, JsonArray>> handler) {
    String filter = "";
    JsonObject params = null;/*from   w  w w .  j  av a 2 s .c om*/
    if (structureId != null && !structureId.trim().isEmpty()) {
        filter = ", (s:Structure)-[:HAS_ATTACHMENT*0..]->(p:Structure) "
                + "WHERE HAS(app.structureId) AND s.id = {structure} AND p.id = app.structureId AND r.structureId = app.structureId "
                + "AND (app.inherits = true OR p = s) ";
        params = new JsonObject().put("structure", structureId);
    }
    String query = "MATCH (app:Application:External)-[:PROVIDE]->(act:Action)<-[:AUTHORIZE]-(r:Role) " + filter
            + "WITH app, r, collect(distinct act) as roleActions " + "MATCH (app)-[:PROVIDE]->(action:Action) "
            + "RETURN distinct app as application, collect(action) as actions, collect(distinct {role: r, actions: roleActions}) as roles";
    neo.execute(query, params, validResultHandler(new Handler<Either<String, JsonArray>>() {
        public void handle(Either<String, JsonArray> event) {
            if (event.isLeft()) {
                handler.handle(event);
                return;
            }
            JsonArray rows = event.right().getValue();
            for (Object objRow : rows) {
                JsonObject row = (JsonObject) objRow;
                JsonObject application = row.getJsonObject("application");
                JsonArray actions = row.getJsonArray("actions");
                JsonArray roles = row.getJsonArray("roles");

                JsonObject appData = application.getJsonObject("data");
                JsonArray scope = appData.getJsonArray("scope");
                if (scope != null && scope.size() > 0) {
                    appData.put("scope", Joiner.on(" ").join(scope));
                } else {
                    appData.put("scope", "");
                }
                row.put("data", appData);
                row.remove("application");

                JsonArray actionsCopy = new fr.wseduc.webutils.collections.JsonArray();
                for (Object actionObj : actions) {
                    JsonObject action = (JsonObject) actionObj;
                    JsonObject data = action.getJsonObject("data");
                    actionsCopy.add(data);
                }
                row.put("actions", actionsCopy);

                for (Object roleObj : roles) {
                    JsonObject role = (JsonObject) roleObj;
                    JsonObject data = role.getJsonObject("role").getJsonObject("data");
                    role.put("role", data);
                    JsonArray acts = role.getJsonArray("actions");
                    JsonArray actsCopy = new fr.wseduc.webutils.collections.JsonArray();
                    for (Object actionObj : acts) {
                        JsonObject action = (JsonObject) actionObj;
                        actsCopy.add(action.getJsonObject("data"));
                    }
                    role.put("actions", actsCopy);

                }
            }

            handler.handle(event);
        }
    }));
}

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

License:Open Source License

@Override
public void createExternalApplication(String structureId, final JsonObject application,
        final Handler<Either<String, JsonObject>> handler) {
    if (defaultValidationParamsNull(handler, application, application.getString("name"), structureId,
            application.getString("address")))
        return;//  w  w  w.j  a  va2s.  c o  m

    final String applicationName = application.getString("name");
    final String id = UUID.randomUUID().toString();
    application.put("scope", new fr.wseduc.webutils.collections.JsonArray(
            "[\"" + application.getString("scope", "").replaceAll("\\s", "\",\"") + "\"]"));
    application.put("id", id);
    application.put("structureId", structureId);

    /* App creation query */
    final String createApplicationQuery = "MATCH (n:Application) " + "WHERE n.name = {applicationName} "
            + "WITH count(*) AS exists " + "WHERE exists=0 " + "CREATE (m:Application:External {props}) "
            + "RETURN m.id as id";

    final StatementsBuilder b = new StatementsBuilder().add(createApplicationQuery,
            new JsonObject().put("applicationName", applicationName).put("props", application));

    /* Underlying action & role creation query */
    String createActionsAndRolesQuery = "MATCH (n:Application) " + "WHERE n.id = {id} "
            + "CREATE UNIQUE n-[r:PROVIDE]->(a:Action:WorkflowAction {type: {type}, "
            + "name:{name}, displayName:{displayName}}) " + "WITH a "
            + "CREATE UNIQUE (r:Role {id: {roleId}, name: {roleName}, structureId: {structureId}})-[:AUTHORIZE]->(a) "
            + "RETURN r.id as roleId";
    b.add(createActionsAndRolesQuery,
            new JsonObject().put("id", id).put("roleId", UUID.randomUUID().toString())
                    .put("type", "SECURED_ACTION_WORKFLOW").put("name", applicationName + "|address")
                    .put("roleName", applicationName + "- ACCESS ").put("structureId", structureId)
                    .put("displayName", applicationName + ".address"));

    neo.executeTransaction(b.build(), null, true, new Handler<Message<JsonObject>>() {
        @Override
        public void handle(Message<JsonObject> m) {
            JsonArray results = m.body().getJsonArray("results");
            if ("ok".equals(m.body().getString("status")) && results != null) {
                JsonArray appRes = results.getJsonArray(0);
                JsonArray roleRes = results.getJsonArray(1);
                JsonObject j = new JsonObject()
                        .mergeIn(appRes.size() > 0 ? appRes.getJsonObject(0) : new JsonObject())
                        .mergeIn(roleRes.size() > 0 ? roleRes.getJsonObject(0) : new JsonObject());
                handler.handle(new Either.Right<String, JsonObject>(j));
            } else {
                handler.handle(new Either.Left<String, JsonObject>(m.body().getString("message")));
            }
        }
    });
}

From source file:org.entcore.session.AuthManager.java

License:Open Source License

private void generateSessionInfos(final String userId, final Handler<JsonObject> handler) {
    final String query = "MATCH (n:User {id : {id}}) " + "WHERE HAS(n.login) "
            + "OPTIONAL MATCH n-[:IN]->(gp:Group) " + "OPTIONAL MATCH gp-[:DEPENDS]->(s:Structure) "
            + "OPTIONAL MATCH gp-[:DEPENDS]->(c:Class) "
            + "OPTIONAL MATCH n-[rf:HAS_FUNCTION]->fg-[:CONTAINS_FUNCTION*0..1]->(f:Function) "
            + "OPTIONAL MATCH n<-[:RELATED]-(child:User) " + "RETURN distinct "
            + "n.classes as classNames, n.level as level, n.login as login, COLLECT(distinct [c.id, c.name]) as classes, "
            + "n.lastName as lastName, n.firstName as firstName, n.externalId as externalId, n.federated as federated, "
            + "n.birthDate as birthDate, "
            + "n.displayName as username, HEAD(n.profiles) as type, COLLECT(distinct [child.id, child.lastName, child.firstName]) as childrenInfo, "
            + "COLLECT(distinct [s.id, s.name]) as structures, COLLECT(distinct [f.externalId, rf.scope]) as functions, "
            + "COLLECT(distinct s.UAI) as uai, "
            + "COLLECT(distinct gp.id) as groupsIds, n.federatedIDP as federatedIDP, n.functions as aafFunctions";
    final String query2 = "MATCH (n:User {id : {id}})-[:IN]->()-[:AUTHORIZED]->(:Role)-[:AUTHORIZE]->(a:Action)"
            + "<-[:PROVIDE]-(app:Application) " + "WHERE HAS(n.login) "
            + "RETURN DISTINCT COLLECT(distinct [a.name,a.displayName,a.type]) as authorizedActions, "
            + "COLLECT(distinct [app.name,app.address,app.icon,app.target,app.displayName,app.display,app.prefix]) as apps";
    final String query3 = "MATCH (u:User {id: {id}})-[:IN]->(g:Group)-[auth:AUTHORIZED]->(w:Widget) "
            + "WHERE HAS(u.login) "
            + "AND ( NOT(w<-[:HAS_WIDGET]-(:Application)-[:PROVIDE]->(:WorkflowAction)) "
            + "XOR w<-[:HAS_WIDGET]-(:Application)-[:PROVIDE]->(:WorkflowAction)<-[:AUTHORIZE]-(:Role)<-[:AUTHORIZED]-g )  "
            + "OPTIONAL MATCH (w)<-[:HAS_WIDGET]-(app:Application) "
            + "WITH w, app, collect(auth) as authorizations " + "RETURN DISTINCT COLLECT({"
            + "id: w.id, name: w.name, " + "path: coalesce(app.address, '') + w.path, "
            + "js: coalesce(app.address, '') + w.js, " + "i18n: coalesce(app.address, '') + w.i18n, "
            + "application: app.name, "
            + "mandatory: ANY(a IN authorizations WHERE HAS(a.mandatory) AND a.mandatory = true)"
            + "}) as widgets";
    final String query4 = "MATCH (s:Structure) return s.id as id, s.externalId as externalId";
    final String query5 = "MATCH (u:User {id: {id}})-[:PREFERS]->(uac:UserAppConf) RETURN uac AS preferences";
    JsonObject params = new JsonObject();
    params.put("id", userId);
    JsonArray statements = new fr.wseduc.webutils.collections.JsonArray()
            .add(new JsonObject().put("statement", query).put("parameters", params))
            .add(new JsonObject().put("statement", query2).put("parameters", params))
            .add(new JsonObject().put("statement", query3).put("parameters", params))
            .add(new JsonObject().put("statement", query4))
            .add(new JsonObject().put("statement", query5).put("parameters", params));
    neo4j.executeTransaction(statements, null, true, new Handler<Message<JsonObject>>() {

        @Override//from  w  ww .j a  va  2s . co m
        public void handle(Message<JsonObject> message) {
            JsonArray results = message.body().getJsonArray("results");
            if ("ok".equals(message.body().getString("status")) && results != null && results.size() == 5
                    && results.getJsonArray(0).size() > 0 && results.getJsonArray(1).size() > 0) {
                JsonObject j = results.getJsonArray(0).getJsonObject(0);
                JsonObject j2 = results.getJsonArray(1).getJsonObject(0);
                JsonObject j3 = results.getJsonArray(2).getJsonObject(0);
                JsonObject structureMapping = new JsonObject();
                for (Object o : results.getJsonArray(3)) {
                    if (!(o instanceof JsonObject))
                        continue;
                    JsonObject jsonObject = (JsonObject) o;
                    structureMapping.put(jsonObject.getString("externalId"), jsonObject.getString("id"));
                }
                j.put("userId", userId);
                JsonObject functions = new JsonObject();
                JsonArray actions = new fr.wseduc.webutils.collections.JsonArray();
                JsonArray apps = new fr.wseduc.webutils.collections.JsonArray();
                for (Object o : getOrElse(j2.getJsonArray("authorizedActions"),
                        new fr.wseduc.webutils.collections.JsonArray())) {
                    if (!(o instanceof JsonArray))
                        continue;
                    JsonArray a = (JsonArray) o;
                    actions.add(new JsonObject().put("name", a.getString(0)).put("displayName", a.getString(1))
                            .put("type", a.getString(2)));
                }
                for (Object o : getOrElse(j2.getJsonArray("apps"),
                        new fr.wseduc.webutils.collections.JsonArray())) {
                    if (!(o instanceof JsonArray))
                        continue;
                    JsonArray a = (JsonArray) o;
                    apps.add(new JsonObject().put("name", (String) a.getString(0))
                            .put("address", (String) a.getString(1)).put("icon", (String) a.getString(2))
                            .put("target", (String) a.getString(3)).put("displayName", (String) a.getString(4))
                            .put("display", ((a.getValue(5) == null) || a.getBoolean(5)))
                            .put("prefix", (String) a.getString(6)));
                }
                for (Object o : getOrElse(j.getJsonArray("aafFunctions"),
                        new fr.wseduc.webutils.collections.JsonArray())) {
                    if (o == null)
                        continue;
                    String[] sf = o.toString().split("\\$");
                    if (sf.length == 5) {
                        JsonObject jo = functions.getJsonObject(sf[1]);
                        if (jo == null) {
                            jo = new JsonObject().put("code", sf[1]).put("functionName", sf[2])
                                    .put("scope", new fr.wseduc.webutils.collections.JsonArray())
                                    .put("structureExternalIds", new fr.wseduc.webutils.collections.JsonArray())
                                    .put("subjects", new JsonObject());
                            functions.put(sf[1], jo);
                        }
                        JsonObject subject = jo.getJsonObject("subjects").getJsonObject(sf[3]);
                        if (subject == null) {
                            subject = new JsonObject().put("subjectCode", sf[3]).put("subjectName", sf[4])
                                    .put("scope", new fr.wseduc.webutils.collections.JsonArray())
                                    .put("structureExternalIds",
                                            new fr.wseduc.webutils.collections.JsonArray());
                            jo.getJsonObject("subjects").put(sf[3], subject);
                        }
                        jo.getJsonArray("structureExternalIds").add(sf[0]);
                        subject.getJsonArray("structureExternalIds").add(sf[0]);
                        String sid = structureMapping.getString(sf[0]);
                        if (sid != null) {
                            jo.getJsonArray("scope").add(sid);
                            subject.getJsonArray("scope").add(sid);
                        }
                    }
                }
                j.remove("aafFunctions");
                for (Object o : getOrElse(j.getJsonArray("functions"),
                        new fr.wseduc.webutils.collections.JsonArray())) {
                    if (!(o instanceof JsonArray))
                        continue;
                    JsonArray a = (JsonArray) o;
                    String code = a.getString(0);
                    if (code != null) {
                        functions.put(code, new JsonObject().put("code", code).put("scope", a.getJsonArray(1)));
                    }
                }
                final JsonObject children = new JsonObject();
                final List<String> childrenIds = new ArrayList<String>();
                for (Object o : getOrElse(j.getJsonArray("childrenInfo"),
                        new fr.wseduc.webutils.collections.JsonArray())) {
                    if (!(o instanceof JsonArray))
                        continue;
                    final JsonArray a = (JsonArray) o;
                    final String childId = a.getString(0);
                    if (childId != null) {
                        childrenIds.add(childId);
                        JsonObject jo = children.getJsonObject(childId);
                        if (jo == null) {
                            jo = new JsonObject().put("lastName", a.getString(1)).put("firstName",
                                    a.getString(2));
                            children.put(childId, jo);
                        }
                    }
                }
                j.remove("childrenInfo");
                final List<String> classesIds = new ArrayList<String>();
                final List<String> classesNames = new ArrayList<String>();
                for (Object o : getOrElse(j.getJsonArray("classes"),
                        new fr.wseduc.webutils.collections.JsonArray())) {
                    if (!(o instanceof JsonArray))
                        continue;
                    final JsonArray c = (JsonArray) o;
                    if (c.getString(0) != null) {
                        classesIds.add(c.getString(0));
                        classesNames.add(c.getString(1));
                    }
                }
                j.remove("classes");
                final List<String> structureIds = new ArrayList<String>();
                final List<String> structureNames = new ArrayList<String>();
                for (Object o : getOrElse(j.getJsonArray("structures"),
                        new fr.wseduc.webutils.collections.JsonArray())) {
                    if (!(o instanceof JsonArray))
                        continue;
                    final JsonArray s = (JsonArray) o;
                    if (s.getString(0) != null) {
                        structureIds.add(s.getString(0));
                        structureNames.add(StringUtils.trimToBlank(s.getString(1)));
                    }
                }
                j.remove("structures");
                j.put("structures", new fr.wseduc.webutils.collections.JsonArray(structureIds));
                j.put("structureNames", new fr.wseduc.webutils.collections.JsonArray(structureNames));
                j.put("classes", new fr.wseduc.webutils.collections.JsonArray(classesIds));
                j.put("realClassesNames", new fr.wseduc.webutils.collections.JsonArray(classesNames));
                j.put("functions", functions);
                j.put("authorizedActions", actions);
                j.put("apps", apps);
                j.put("childrenIds", new fr.wseduc.webutils.collections.JsonArray(childrenIds));
                j.put("children", children);
                final JsonObject cache = (results.getJsonArray(4) != null && results.getJsonArray(4).size() > 0
                        && results.getJsonArray(4).getJsonObject(0) != null)
                                ? results.getJsonArray(4).getJsonObject(0)
                                : new JsonObject();
                j.put("cache", cache);
                j.put("widgets",
                        getOrElse(j3.getJsonArray("widgets"), new fr.wseduc.webutils.collections.JsonArray()));
                handler.handle(j);
            } else {
                handler.handle(null);
            }
        }
    });
}