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

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

Introduction

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

Prototype

public List getList() 

Source Link

Document

Get the unerlying List

Usage

From source file:org.entcore.feeder.dictionary.structures.User.java

License:Open Source License

public static void addFunction(String userId, String functionCode, JsonArray s,
        TransactionHelper transactionHelper) {
    String query = "MATCH (u:User { id : {userId}}) "
            + "OPTIONAL MATCH (f1:Function { externalId : {functionCode}}) "
            + "OPTIONAL MATCH (f2:Functions { externalId : {functionCode}}) "
            + "WITH u, collect (f1) + collect(f2) as c " + "UNWIND c as f " + "MERGE u-[rf:HAS_FUNCTION]->f ";

    JsonArray scope = null;//from w  ww  . j a v  a2s  .  co  m
    JsonObject params = new JsonObject().put("userId", userId).put("functionCode", functionCode);
    if (s != null) {
        query += "SET rf.scope = {scope} ";
        scope = new fr.wseduc.webutils.collections.JsonArray(new ArrayList<>(new HashSet<String>(s.getList())));
        params.put("scope", scope);
    }
    transactionHelper.add(query, params);
    if (scope != null) {
        String query2 = "MATCH (u:User { id : {userId}}) "
                + "OPTIONAL MATCH (n1:Structure) WHERE n1.id IN {scope} "
                + "OPTIONAL MATCH (n2:Class) WHERE n2.id IN {scope} "
                + "OPTIONAL MATCH (f1:Function { externalId : {functionCode}}) "
                + "OPTIONAL MATCH (f2:Functions { externalId : {functionCode}}) "
                + "WITH u, collect (n1) + collect(n2) as c1 , collect (f1) + collect(f2) as c2 "
                + "UNWIND c1 as n " + "UNWIND c2 as f "
                + "MERGE (fg:Group:FunctionGroup { externalId : n.id + '-' + {functionCode}}) "
                + "ON CREATE SET fg.id = id(fg) + '-' + timestamp(), fg.name = n.name + '-' + f.name, fg.displayNameSearchField = lower(n.name) + lower(f.name), fg.filter = f.name\n"
                + "CREATE UNIQUE n<-[:DEPENDS]-fg<-[:IN {source:'MANUAL'}]-u " + "RETURN fg.id as groupId ";
        JsonObject p2 = new JsonObject().put("scope", scope).put("functionCode", functionCode).put("userId",
                userId);
        transactionHelper.add(query2, p2);
        countUsersInGroups(null, "FunctionGroup", transactionHelper);
    }
}

From source file:org.entcore.feeder.timetable.AbstractTimetableImporter.java

License:Open Source License

private void persEducNatToGroups(JsonObject object) {
    final JsonArray groups = object.getJsonArray("groups");
    if (groups != null) {
        final JsonArray teacherIds = object.getJsonArray("teacherIds");
        final List<String> ids = new ArrayList<>();
        if (teacherIds != null) {
            ids.addAll(teacherIds.getList());
        }//w  w  w .jav a2  s . co m
        final JsonArray personnelIds = object.getJsonArray("personnelIds");
        if (personnelIds != null) {
            ids.addAll(personnelIds.getList());
        }
        if (!ids.isEmpty()) {
            final JsonArray g = new fr.wseduc.webutils.collections.JsonArray();
            for (Object o : groups) {
                g.add(structureExternalId + "$" + o.toString());
            }
            for (String id : ids) {
                txXDT.add(PERSEDUCNAT_TO_GROUPS,
                        new JsonObject().put("groups", g).put("id", id).put("source", getSource())
                                .put("outDate", DateTime.now().plusDays(1).getMillis())
                                .put("now", importTimestamp));
            }
        }
    }
}

From source file:org.entcore.feeder.timetable.edt.EDTImporter.java

License:Open Source License

private void userExternalId(final Handler<Void> handler) {
    if (!userImportedPronoteId.isEmpty()) {
        final String query = "MATCH (u:User) where u.IDPN IN {pronoteIds} RETURN COLLECT(u.externalId) as externalIds";
        TransactionManager.getNeo4jHelper().execute(query,
                new JsonObject().put("pronoteIds",
                        new fr.wseduc.webutils.collections.JsonArray(new ArrayList<>(userImportedPronoteId))),
                new Handler<Message<JsonObject>>() {
                    @Override//  w  ww  .ja  v  a 2  s  .c  o m
                    public void handle(Message<JsonObject> event) {
                        JsonArray res = event.body().getJsonArray("result");
                        if ("ok".equals(event.body().getString("status")) && res.size() == 1) {
                            JsonArray r = res.getJsonObject(0).getJsonArray("externalIds");
                            if (r != null) {
                                userImportedExternalId.addAll(r.getList());
                            }
                        }
                        handler.handle(null);
                    }
                });
    } else {
        handler.handle(null);
    }
}

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

License:Open Source License

protected static void initLogins(Neo4j neo4j, final long startInit, final boolean remove) {
    String query = "MATCH (u:User) RETURN COLLECT(DISTINCT u.login) as logins, COLLECT(DISTINCT u.loginAlias) as loginAliases";
    neo4j.execute(query, new JsonObject(), new Handler<Message<JsonObject>>() {
        @Override/*  ww w.j a  v a2s  .  c o m*/
        public void handle(Message<JsonObject> message) {
            JsonArray r = message.body().getJsonArray("result");
            if ("ok".equals(message.body().getString("status")) && r != null && r.size() == 1) {
                JsonArray l = (r.getJsonObject(0)).getJsonArray("logins");
                JsonArray aliases = (r.getJsonObject(0)).getJsonArray("loginAliases");

                for (Object alias : aliases) {
                    l.add(alias);
                }

                if (l != null) {
                    final Set<Object> tmp = new HashSet<>(l.getList());
                    if (remove) {
                        for (Object key : logins.keySet()) {
                            if (!tmp.contains(key)) {
                                logins.remove(key);
                            } else {
                                tmp.remove(key);
                            }
                        }
                        putLogin(tmp);
                    } else {
                        putLogin(tmp);
                    }
                }
            }
        }

        protected void putLogin(Set<Object> tmp) {
            for (Object o : tmp) {
                logins.putIfAbsent(o, "");
            }
            log.info("Init delay : " + (System.currentTimeMillis() - startInit));
        }
    });
}

From source file:org.entcore.infra.cron.HardBounceTask.java

License:Open Source License

private void notifyOnTimeline(JsonArray userIds) {
    if (userIds == null)
        return;/*from   w w  w .  j  av a 2s  .  com*/

    List<String> recipients = userIds.getList();
    timeline.notifyTimeline(new JsonHttpServerRequest(new JsonObject()), "userbook.delete-email", null,
            recipients, null, new JsonObject());
}

From source file:org.entcore.workspace.service.impl.WorkspaceSearchingEvents.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public void searchResource(List<String> appFilters, final String userId, JsonArray groupIds,
        JsonArray searchWords, Integer page, Integer limit, final JsonArray columnsHeader, final String locale,
        final Handler<Either<String, JsonArray>> handler) {
    if (appFilters.contains(WorkspaceSearchingEvents.class.getSimpleName())) {

        final List<String> searchWordsLst = searchWords.getList();

        final List<String> groupIdsLst = groupIds.getList();
        final List<DBObject> groups = new ArrayList<>();
        groups.add(QueryBuilder.start("userId").is(userId).get());
        for (String gpId : groupIdsLst) {
            groups.add(QueryBuilder.start("groupId").is(gpId).get());
        }/*from  w  w  w .j  ava 2s. co  m*/

        final QueryBuilder rightsQuery = new QueryBuilder().or(
                QueryBuilder.start("visibility").is(VisibilityFilter.PUBLIC.name()).get(),
                QueryBuilder.start("visibility").is(VisibilityFilter.PROTECTED.name()).get(),
                QueryBuilder.start("visibility").is(VisibilityFilter.PROTECTED.name()).get(),
                QueryBuilder.start("owner").is(userId).get(),
                QueryBuilder.start("shared")
                        .elemMatch(new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get())
                        .get());

        final QueryBuilder worldsQuery = new QueryBuilder();
        worldsQuery.text(MongoDbSearchService.textSearchedComposition(searchWordsLst));

        //searching only the file entry (not folder), if folder match and is returned, the paginate system is impacted
        final QueryBuilder fileQuery = QueryBuilder.start("file").exists(true);

        final QueryBuilder query = new QueryBuilder().and(fileQuery.get(), rightsQuery.get(),
                worldsQuery.get());

        JsonObject sort = new JsonObject().put("modified", -1);
        final JsonObject projection = new JsonObject();
        projection.put("name", 1);
        projection.put("modified", 1);
        projection.put("folder", 1);
        projection.put("owner", 1);
        projection.put("ownerName", 1);
        projection.put("comments", 1);

        final int skip = (0 == page) ? -1 : page * limit;

        //main search on file
        mongo.find(this.collection, MongoQueryBuilder.build(query), sort, projection, skip, limit,
                Integer.MAX_VALUE, validResultsHandler(new Handler<Either<String, JsonArray>>() {
                    @Override
                    public void handle(Either<String, JsonArray> event) {

                        if (event.isRight()) {
                            final JsonArray globalJa = event.right().getValue();
                            //different owner can have the same folder name
                            //if the folder exists, we must find id of folder according to the directory name and the owner,
                            //it's necessary to use the front route for the resource link
                            final QueryBuilder foldersOwnersOrQuery = new QueryBuilder();
                            Boolean isFolderProcessing = false;

                            for (int i = 0; i < globalJa.size(); i++) {
                                final JsonObject j = globalJa.getJsonObject(i);

                                // processing only files that have a folder
                                if (j != null && !StringUtils.isEmpty(j.getString("folder"))) {
                                    isFolderProcessing = true;
                                    final QueryBuilder folderOwnerQuery = new QueryBuilder();
                                    folderOwnerQuery.and(
                                            QueryBuilder.start("folder").is(j.getString("folder")).get(),
                                            QueryBuilder.start("owner").is(j.getString("owner")).get());
                                    foldersOwnersOrQuery.or(folderOwnerQuery.get());
                                }
                            }

                            final Map<String, Map<String, String>> mapOwnerMapNameFolderId = new HashMap<>();
                            //finding ids of folder found.
                            if (isFolderProcessing) {
                                //find only authorized folder entry and not file
                                final QueryBuilder queryFindFolderIds = new QueryBuilder().and(
                                        QueryBuilder.start("file").exists(false).get(), rightsQuery.get(),
                                        foldersOwnersOrQuery.get());
                                //search all folder of main result set and format the search result
                                findFoldersIdAndFormatResult(globalJa, queryFindFolderIds, columnsHeader,
                                        searchWordsLst, locale, userId, handler);
                            } else {
                                //all files without folder
                                final JsonArray res = formatSearchResult(globalJa, columnsHeader,
                                        searchWordsLst, locale, userId, mapOwnerMapNameFolderId);
                                handler.handle(new Either.Right<String, JsonArray>(res));
                            }
                        } else {
                            handler.handle(new Either.Left<String, JsonArray>(event.left().getValue()));
                        }
                        if (log.isDebugEnabled()) {
                            log.debug(
                                    "[WorkspaceSearchingEvents][searchResource] The resources searched by user are finded");
                        }
                    }
                }));
    } else {
        handler.handle(new Either.Right<String, JsonArray>(new fr.wseduc.webutils.collections.JsonArray()));
    }
}

From source file:org.entcore.workspace.service.impl.WorkspaceSearchingEvents.java

License:Open Source License

@SuppressWarnings("unchecked")
private JsonArray formatSearchResult(final JsonArray results, final JsonArray columnsHeader,
        final List<String> words, final String locale, final String userId,
        final Map<String, Map<String, String>> mapOwnerMapNameFolderId) {
    final List<String> aHeader = columnsHeader.getList();
    final JsonArray traity = new fr.wseduc.webutils.collections.JsonArray();

    for (int i = 0; i < results.size(); i++) {
        final JsonObject j = results.getJsonObject(i);
        final JsonObject jr = new JsonObject();

        if (j != null) {
            final String folder = j.getString("folder", "");

            Date modified = new Date();
            try {
                modified = DateUtils.parse(j.getString("modified"), PATTERN);
            } catch (ParseException e) {
                log.error("Can't parse date from modified", e);
            }//from   w ww.  j  a  v  a  2 s .c  o  m
            final String owner = j.getString("owner", "");
            final Map<String, Object> map = formatDescription(
                    j.getJsonArray("comments", new fr.wseduc.webutils.collections.JsonArray()), words, modified,
                    locale);
            jr.put(aHeader.get(0), j.getString("name"));
            jr.put(aHeader.get(1), map.get("description").toString());
            jr.put(aHeader.get(2), new JsonObject().put("$date", ((Date) map.get("modified")).getTime()));
            jr.put(aHeader.get(3), j.getString("ownerName", ""));
            jr.put(aHeader.get(4), owner);
            //default front route (no folder and the file belongs to the owner)
            String resourceURI = "/workspace/workspace";

            if (userId.equals(owner)) {
                if (!StringUtils.isEmpty(folder)) {
                    resourceURI += "#/folder/" + mapOwnerMapNameFolderId.get(owner).get(folder);
                }
            } else {
                //if there is a folder on entry file and this folder is shared
                if (!StringUtils.isEmpty(folder) && mapOwnerMapNameFolderId.containsKey(owner)
                        && mapOwnerMapNameFolderId.get(owner).containsKey(folder)) {
                    resourceURI += "#/shared/folder/" + mapOwnerMapNameFolderId.get(owner).get(folder);
                } else {
                    //only the file is shared
                    resourceURI += "#/shared";
                }
            }
            jr.put(aHeader.get(5), resourceURI);
            traity.add(jr);
        }
    }
    return traity;
}

From source file:org.etourdot.vertx.marklogic.model.client.impl.DocumentsImpl.java

License:Open Source License

@Override
public Documents documents(JsonArray documents) {
    boolean isMap = documents.getList().get(0) instanceof Map;
    documents.getList().stream().map(d1 -> Document.create(isMap ? new JsonObject((Map) d1) : (JsonObject) d1))
            .forEach(d2 -> addDocuments((Document) d2));
    return this;
}

From source file:org.perfcake.reporting.destination.c3chart.C3ChartData.java

License:Apache License

/**
 * Mixes two charts together sorted according to the first index column. Missing data for any index values in either chart are replaced with null.
 * Records with only null values are skipped. The existing chart data are not changed, a new instance is created.
 *
 * @param otherData/*from w  ww. j a  va 2  s .  c  o  m*/
 *       The other chart data to be mixed with this chart data.
 * @return A new chart data combining both input charts.
 */
@SuppressWarnings("unchecked")
C3ChartData combineWith(final C3ChartData otherData) {
    final List<JsonArray> newData = new LinkedList<>();
    int idx1 = getDataStart();
    int idx2 = otherData.getDataStart();

    if (idx1 == -1) {
        if (idx2 == -1) {
            return new C3ChartData(target, newData);
        } else {
            return new C3ChartData(target, new LinkedList<>(otherData.data));
        }
    } else if (idx2 == -2) {
        return new C3ChartData(target, new LinkedList<>(data));
    }

    int size1 = data.get(0).size();
    List nullList1 = getNullList(size1 - 1);

    int size2 = otherData.data.get(0).size();
    List nullList2 = getNullList(size2 - 1);

    while (idx1 < data.size() || idx2 < otherData.data.size()) {
        JsonArray a1 = idx1 < data.size() ? data.get(idx1) : null;
        JsonArray a2 = idx2 < otherData.data.size() ? otherData.data.get(idx2) : null;
        long p1 = a1 != null ? a1.getLong(0) : Long.MAX_VALUE;
        long p2 = a2 != null ? a2.getLong(0) : Long.MAX_VALUE;
        List raw = new LinkedList<>();

        if (p1 == p2) {
            if (!isAllNull(a1) || !isAllNull(a2)) {
                raw.add(p1);
                raw.addAll(a1.getList().subList(1, size1));
                raw.addAll(a2.getList().subList(1, size2));
            }
            idx1++;
            idx2++;
        } else if (p1 < p2) {
            if (!isAllNull(a1)) {
                raw.add(p1);
                raw.addAll(a1.getList().subList(1, size1));
                raw.addAll(nullList2);
            }
            idx1++;
        } else {
            if (!isAllNull(a2)) {
                raw.add(p2);
                raw.addAll(nullList1);
                raw.addAll(a2.getList().subList(1, size2));
            }
            idx2++;
        }

        if (raw.size() > 0) {
            newData.add(new JsonArray(raw));
        }
    }

    return new C3ChartData(target, newData);
}