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.directory.services.impl.DefaultUserService.java

License:Open Source License

@Override
public void listAdmin(String structureId, String classId, String groupId, JsonArray expectedProfiles,
        String filterActivated, String nameFilter, UserInfos userInfos,
        Handler<Either<String, JsonArray>> results) {
    JsonObject params = new JsonObject();
    String filter = "";
    String filterProfile = "WHERE 1=1 ";
    String optionalMatch = "OPTIONAL MATCH u-[:IN]->(:ProfileGroup)-[:DEPENDS]->(class:Class)-[:BELONGS]->(s) "
            + "OPTIONAL MATCH u-[:RELATED]->(parent: User) " + "OPTIONAL MATCH (child: User)-[:RELATED]->u "
            + "OPTIONAL MATCH u-[rf:HAS_FUNCTION]->fg-[:CONTAINS_FUNCTION*0..1]->(f:Function) ";
    if (expectedProfiles != null && expectedProfiles.size() > 0) {
        filterProfile += "AND p.name IN {expectedProfiles} ";
        params.put("expectedProfiles", expectedProfiles);
    }//from www  . j a  v  a2s .co  m
    if (classId != null && !classId.trim().isEmpty()) {
        filter = "(n:Class {id : {classId}})<-[:DEPENDS]-(g:ProfileGroup)<-[:IN]-";
        params.put("classId", classId);
    } else if (structureId != null && !structureId.trim().isEmpty()) {
        filter = "(n:Structure {id : {structureId}})<-[:DEPENDS]-(g:ProfileGroup)<-[:IN]-";
        params.put("structureId", structureId);
    } else if (groupId != null && !groupId.trim().isEmpty()) {
        filter = "(n:Group {id : {groupId}})<-[:IN]-";
        params.put("groupId", groupId);
    }
    String condition = "";
    String functionMatch = "WITH u MATCH (s:Structure)<-[:DEPENDS]-(pg:ProfileGroup)-[:HAS_PROFILE]->(p:Profile), u-[:IN]->pg ";
    if (!userInfos.getFunctions().containsKey(SUPER_ADMIN) && !userInfos.getFunctions().containsKey(ADMIN_LOCAL)
            && !userInfos.getFunctions().containsKey(CLASS_ADMIN)) {
        results.handle(new Either.Left<String, JsonArray>("forbidden"));
        return;
    } else if (userInfos.getFunctions().containsKey(ADMIN_LOCAL)) {
        UserInfos.Function f = userInfos.getFunctions().get(ADMIN_LOCAL);
        List<String> scope = f.getScope();
        if (scope != null && !scope.isEmpty()) {
            condition = "AND s.id IN {scope} ";
            params.put("scope", new fr.wseduc.webutils.collections.JsonArray(scope));
        }
    } else if (userInfos.getFunctions().containsKey(CLASS_ADMIN)) {
        UserInfos.Function f = userInfos.getFunctions().get(CLASS_ADMIN);
        List<String> scope = f.getScope();
        if (scope != null && !scope.isEmpty()) {
            functionMatch = "WITH u MATCH (c:Class)<-[:DEPENDS]-(cpg:ProfileGroup)-[:DEPENDS]->(pg:ProfileGroup)-[:HAS_PROFILE]->(p:Profile), u-[:IN]->pg ";
            condition = "AND c.id IN {scope} ";
            params.put("scope", new fr.wseduc.webutils.collections.JsonArray(scope));
        }
    }
    if (nameFilter != null && !nameFilter.trim().isEmpty()) {
        condition += "AND u.displayName =~ {regex}  ";
        params.put("regex", "(?i)^.*?" + Pattern.quote(nameFilter.trim()) + ".*?$");
    }
    if (filterActivated != null) {
        if ("inactive".equals(filterActivated)) {
            condition += "AND NOT(u.activationCode IS NULL)  ";
        } else if ("active".equals(filterActivated)) {
            condition += "AND u.activationCode IS NULL ";
        }
    }

    String query = "MATCH " + filter + "(u:User) " + functionMatch + filterProfile + condition + optionalMatch
            + "RETURN DISTINCT u.id as id, p.name as type, u.externalId as externalId, "
            + "u.activationCode as code, "
            + "CASE WHEN u.loginAlias IS NOT NULL THEN u.loginAlias ELSE u.login END as login, "
            + "u.firstName as firstName, "
            + "u.lastName as lastName, u.displayName as displayName, u.source as source, u.attachmentId as attachmentId, "
            + "u.birthDate as birthDate, u.blocked as blocked, "
            + "extract(function IN u.functions | last(split(function, \"$\"))) as aafFunctions, "
            + "collect(distinct {id: s.id, name: s.name}) as structures, "
            + "collect(distinct {id: class.id, name: class.name}) as allClasses, "
            + "collect(distinct [f.externalId, rf.scope]) as functions, "
            + "CASE WHEN parent IS NULL THEN [] ELSE collect(distinct {id: parent.id, firstName: parent.firstName, lastName: parent.lastName}) END as parents, "
            + "CASE WHEN child IS NULL THEN [] ELSE collect(distinct {id: child.id, firstName: child.firstName, lastName: child.lastName, attachmentId : child.attachmentId }) END as children, "
            + "HEAD(COLLECT(distinct parent.externalId)) as parent1ExternalId, " + // Hack for GEPI export
            "HEAD(TAIL(COLLECT(distinct parent.externalId))) as parent2ExternalId, " + // Hack for GEPI export
            "COUNT(distinct class.id) > 0 as hasClass " + // Hack for Esidoc export
            "ORDER BY type DESC, displayName ASC ";
    neo.execute(query, params, validResultHandler(results));
}

From source file:org.entcore.directory.services.impl.DefaultUserService.java

License:Open Source License

@Override
public void addFunction(String id, String functionCode, JsonArray scope, String inherit,
        Handler<Either<String, JsonObject>> result) {
    JsonObject action = new JsonObject().put("action", "manual-add-user-function").put("userId", id)
            .put("function", functionCode).put("inherit", inherit).put("scope", scope);
    eb.send(Directory.FEEDER, action, ar -> {
        if (ar.succeeded()) {
            JsonArray res = ((JsonObject) ar.result().body()).getJsonArray("results");
            JsonObject json = new JsonObject();
            if (res.size() == 2) {
                JsonArray r = res.getJsonArray(1);
                if (r.size() == 1) {
                    json = r.getJsonObject(0);
                }//  w ww.  j  av a 2s.c om
            }
            result.handle(new Either.Right<>(json));
        } else {
            result.handle(new Either.Left<>(ar.cause().getMessage()));
        }
    });
}

From source file:org.entcore.directory.services.impl.DefaultUserService.java

License:Open Source License

@Override
public void listByUAI(List<String> UAI, JsonArray expectedTypes, boolean isExportFull, JsonArray fields,
        Handler<Either<String, JsonArray>> results) {
    if (UAI == null || UAI.isEmpty()) {
        results.handle(new Either.Left<String, JsonArray>("missing.uai"));
        return;//w  w w  .  j  a  v  a 2 s  .com
    } else {
        for (String uaiCode : UAI) {
            if (!StringValidation.isUAI(uaiCode)) {
                results.handle(new Either.Left<String, JsonArray>("invalid.uai"));
                return;
            }
        }
    }

    if (fields == null || fields.size() == 0) {
        fields = new fr.wseduc.webutils.collections.JsonArray().add("id").add("externalId").add("lastName")
                .add("firstName").add("login");
    }

    //user's fields for Full Export
    if (isExportFull) {
        fields.add("email");
        fields.add("emailAcademy");
        fields.add("mobile");
        fields.add("deleteDate");
        fields.add("functions");
        fields.add("displayName");
    }

    // Init params and filter for all type of queries
    String filter = "WHERE s.UAI IN {uai} ";

    JsonObject params = new JsonObject().put("uai", new fr.wseduc.webutils.collections.JsonArray(UAI));

    StringBuilder query = new StringBuilder();
    query.append("MATCH (s:Structure)<-[:DEPENDS]-(cpg:ProfileGroup)");

    // filter by types if needed OR full export
    if (isExportFull || (expectedTypes != null && expectedTypes.size() > 0)) {
        query.append("-[:HAS_PROFILE]->(p:Profile)");
    }
    // filter by types if needed
    if (expectedTypes != null && expectedTypes.size() > 0) {

        filter += "AND p.name IN {expectedTypes} ";
        params.put("expectedTypes", expectedTypes);
    }

    query.append(", cpg<-[:IN]-(u:User) ").append(filter);

    if (fields.contains("administrativeStructure")) {
        query.append("OPTIONAL MATCH u-[:ADMINISTRATIVE_ATTACHMENT]->sa ");
    }

    query.append("RETURN DISTINCT ");

    for (Object field : fields) {
        if ("type".equals(field) || "profile".equals(field)) {
            query.append(" HEAD(u.profiles)");
        } else if ("administrativeStructure".equals(field)) {
            query.append(" sa.externalId ");
        } else {
            query.append(" u.").append(field);
        }
        query.append(" as ").append(field).append(",");
    }
    query.deleteCharAt(query.length() - 1);

    //Full Export : profiles and Structure
    if (isExportFull) {
        query.append(", p.name as profiles");
        query.append(", s.externalId as structures")
                .append(" , CASE WHEN size(u.classes) > 0  THEN  last(collect(u.classes)) END as classes");
    }

    neo.execute(query.toString(), params, validResultHandler(results));
}

From source file:org.entcore.feeder.aaf.PersonnelImportProcessing.java

License:Open Source License

protected String detectProfile(JsonObject object) {
    Boolean isTeacher = object.getBoolean("isTeacher");
    if (isTeacher != null) {
        return isTeacher ? TEACHER_PROFILE_EXTERNAL_ID : PERSONNEL_PROFILE_EXTERNAL_ID;
    } else {/* w  w w  .  ja  v a2  s. c  o  m*/
        JsonArray functions = object.getJsonArray("functions");
        if (object.getBoolean("teaches", false)) {
            return TEACHER_PROFILE_EXTERNAL_ID;
        } else if (functions != null && functions.size() > 0) {
            for (Object function : functions.getList()) {
                if (function != null
                        && (function.toString().contains("$DOC$") || function.toString().contains("$ENS$"))) {
                    return TEACHER_PROFILE_EXTERNAL_ID;
                }
            }
        }
        return PERSONNEL_PROFILE_EXTERNAL_ID;
    }
}

From source file:org.entcore.feeder.aaf.PersonnelImportProcessing.java

License:Open Source License

protected void createGroups(JsonArray groups, List<String> classes, List<String[]> linkStructureGroups) {
    if (groups != null && groups.size() > 0) {
        for (Object o : groups) {
            if (!(o instanceof String))
                continue;
            String[] g = ((String) o).split("\\$");
            if (g.length == 2 || g.length == 3) {
                Structure s = importer.getStructure(g[0]);
                if (s != null) {
                    String groupExternalId = s.getExternalId() + "$" + g[1];
                    s.createFunctionalGroupIfAbsent(groupExternalId, g[1]);
                    if (linkStructureGroups != null) {
                        final String[] group = new String[3];
                        group[0] = s.getExternalId();
                        group[1] = groupExternalId;
                        group[2] = (g.length == 3) ? g[2] : "";
                        linkStructureGroups.add(group);
                    }/*ww w. j  a  v a 2  s.c om*/
                    if (classes != null) {
                        final List<String> lc = importer.getGroupClasses().get(groupExternalId);
                        if (lc != null) {
                            classes.addAll(lc);
                        }
                    }
                }
            }
        }
    }
}

From source file:org.entcore.feeder.aaf.PersonnelImportProcessing.java

License:Open Source License

protected String[][] createClasses(JsonArray classes) {
    String[][] linkStructureClasses = null;
    if (classes != null && classes.size() > 0) {
        linkStructureClasses = new String[classes.size()][3];
        int i = 0;
        for (Object o : classes) {
            if (!(o instanceof String))
                continue;
            String[] c = ((String) o).split("\\$");
            if (c.length == 2 || c.length == 3) {
                Structure s = importer.getStructure(c[0]);
                if (s != null) {
                    String classExternalId = s.getExternalId() + "$" + c[1];
                    s.createClassIfAbsent(classExternalId, c[1]);
                    linkStructureClasses[i][0] = s.getExternalId();
                    linkStructureClasses[i][1] = classExternalId;
                    linkStructureClasses[i++][2] = (c.length == 3) ? c[2] : "";
                }/*from  w  ww.j a  v  a2s . c  o m*/
            }
        }
    }
    return linkStructureClasses;
}

From source file:org.entcore.feeder.aaf.PersonnelImportProcessing.java

License:Open Source License

protected void createFunctionGroups(JsonArray functions, List<String[]> linkStructureGroups) {
    if (functions != null && functions.size() > 0) {
        for (Object o : functions) {
            if (!(o instanceof String))
                continue;
            String[] g = ((String) o).split("\\$");
            if (g.length == 5) {
                Structure s = importer.getStructure(g[0]);
                String groupExternalId;
                if (s != null) {
                    if ("ENS".equals(g[1])) {
                        groupExternalId = s.getExternalId() + "$" + g[3];
                        s.createFunctionGroupIfAbsent(groupExternalId, g[4], "Discipline");
                    } else if (!"-".equals(g[1])) {
                        groupExternalId = s.getExternalId() + "$" + g[1];
                        s.createFunctionGroupIfAbsent(groupExternalId, g[2], "Func");
                    } else {
                        continue;
                    }//from  ww w. j  av a 2 s .c om
                    if (linkStructureGroups != null) {
                        final String[] group = new String[3];
                        group[0] = s.getExternalId();
                        group[1] = groupExternalId;
                        linkStructureGroups.add(group);
                    }
                }
            }
        }
    }
}

From source file:org.entcore.feeder.aaf.PersonnelImportProcessing.java

License:Open Source License

protected void createHeadTeacherGroups(JsonArray headTeacher, List<String[]> linkStructureGroups) {
    if (headTeacher != null && headTeacher.size() > 0) {
        for (Object o : headTeacher) {
            if (!(o instanceof String))
                continue;
            String[] g = ((String) o).split("\\$");
            if (g.length == 2) {
                Structure s = importer.getStructure(g[0]);
                if (s != null) {
                    String structureGroupExternalId = s.getExternalId() + "-ht";
                    String classGroupExternalId = s.getExternalId() + "$" + g[1] + "-ht";
                    s.createHeadTeacherGroupIfAbsent(structureGroupExternalId, classGroupExternalId, g[1]);
                    if (linkStructureGroups != null) {
                        final String[] structureGroup = new String[2];
                        structureGroup[0] = s.getExternalId();
                        structureGroup[1] = structureGroupExternalId;
                        linkStructureGroups.add(structureGroup);
                        final String[] classGroup = new String[2];
                        classGroup[0] = s.getExternalId();
                        classGroup[1] = classGroupExternalId;
                        linkStructureGroups.add(classGroup);
                    }//from ww  w .  jav  a2  s.c om
                }
            }
        }
    }
}

From source file:org.entcore.feeder.aaf.StudentImportProcessing.java

License:Open Source License

protected JsonArray parseRelativeField(JsonArray relative) {
    JsonArray res = null;/*from  w  w w . j av  a  2 s .com*/
    if (relative != null && relative.size() > 0) {
        res = new fr.wseduc.webutils.collections.JsonArray();
        for (Object o : relative) {
            if (!(o instanceof String))
                continue;
            String[] r = ((String) o).split("\\$");
            if (r.length == 6 && !"0".equals(r[3])) {
                res.add(r[0]);
            }
        }
    }
    return res;
}

From source file:org.entcore.feeder.aaf.StudentImportProcessing.java

License:Open Source License

protected String[][] createGroups(JsonArray groups) {
    String[][] linkStructureGroups = null;
    if (groups != null && groups.size() > 0) {
        linkStructureGroups = new String[groups.size()][2];
        int i = 0;
        for (Object o : groups) {
            if (!(o instanceof String))
                continue;
            String[] g = ((String) o).split("\\$");
            if (g.length == 2) {
                Structure s = importer.getStructure(g[0]);
                if (s != null) {
                    String groupExternalId = s.getExternalId() + "$" + g[1];
                    s.createFunctionalGroupIfAbsent(groupExternalId, g[1]);
                    linkStructureGroups[i][0] = s.getExternalId();
                    linkStructureGroups[i++][1] = groupExternalId;
                }/*from  w  w w.  j  a v  a  2  s  .c  o  m*/
            }
        }
    }
    return linkStructureGroups;
}