List of usage examples for io.vertx.core.json JsonArray getList
public List getList()
From source file:org.entcore.archive.services.impl.FileSystemExportService.java
License:Open Source License
@Override public void export(final UserInfos user, final String locale, final HttpServerRequest request, final Handler<Either<String, String>> handler) { userExportExists(user, new Handler<Boolean>() { @Override/*from ww w. j a v a2 s . c om*/ public void handle(Boolean event) { if (Boolean.FALSE.equals(event)) { long now = System.currentTimeMillis(); final String exportId = now + "_" + user.getUserId(); userExportInProgress.put(user.getUserId(), now); final String exportDirectory = exportPath + File.separator + exportId; fs.mkdirs(exportDirectory, new Handler<AsyncResult<Void>>() { @Override public void handle(AsyncResult<Void> event) { if (event.succeeded()) { final Set<String> g = (user.getGroupsIds() != null) ? new HashSet<>(user.getGroupsIds()) : new HashSet<String>(); User.getOldGroups(user.getUserId(), new Handler<JsonArray>() { @Override public void handle(JsonArray objects) { g.addAll(objects.getList()); JsonObject j = new JsonObject().put("action", "export") .put("exportId", exportId).put("userId", user.getUserId()) .put("groups", new fr.wseduc.webutils.collections.JsonArray( new ArrayList<>(g))) .put("path", exportDirectory).put("locale", locale) .put("host", Renders.getScheme(request) + "://" + request.headers().get("Host")); eb.publish("user.repository", j); handler.handle(new Either.Right<String, String>(exportId)); } }); } else { log.error("Create export directory error.", event.cause()); handler.handle(new Either.Left<String, String>("export.directory.create.error")); } } }); } else { handler.handle(new Either.Left<String, String>("export.exists")); } } }); }
From source file:org.entcore.blog.events.BlogSearchingEvents.java
License:Open Source License
@Override public void searchResource(List<String> appFilters, String userId, JsonArray groupIds, final JsonArray searchWords, final Integer page, final Integer limit, final JsonArray columnsHeader, final String locale, final Handler<Either<String, JsonArray>> handler) { if (appFilters.contains(BlogSearchingEvents.class.getSimpleName())) { final List<String> groupIdsLst = groupIds.getList(); final List<DBObject> groups = new ArrayList<DBObject>(); groups.add(QueryBuilder.start("userId").is(userId).get()); for (String gpId : groupIdsLst) { groups.add(QueryBuilder.start("groupId").is(gpId).get()); }//w w w .j av a 2 s . 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("author.userId").is(userId).get(), QueryBuilder.start("shared") .elemMatch(new QueryBuilder().or(groups.toArray(new DBObject[groups.size()])).get()) .get()); final JsonObject projection = new JsonObject(); projection.put("_id", 1); //search all blogs of user mongo.find(Blog.BLOGS_COLLECTION, MongoQueryBuilder.build(rightsQuery), null, projection, new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { final Either<String, JsonArray> ei = validResults(event); if (ei.isRight()) { final JsonArray blogsResult = ei.right().getValue(); final Set<String> setIds = new HashSet<String>(); for (int i = 0; i < blogsResult.size(); i++) { final JsonObject j = blogsResult.getJsonObject(i); setIds.add(j.getString("_id")); } //search posts for the blogs found searchPosts(page, limit, searchWords.getList(), setIds, new Handler<Either<String, JsonArray>>() { @Override public void handle(Either<String, JsonArray> event) { if (event.isRight()) { if (log.isDebugEnabled()) { log.debug( "[BlogSearchingEvents][searchResource] The resources searched by user are found"); } final JsonArray res = formatSearchResult( event.right().getValue(), columnsHeader, searchWords.getList()); handler.handle(new Right<String, JsonArray>(res)); } else { handler.handle(new Either.Left<String, JsonArray>( event.left().getValue())); } } }); } else { handler.handle(new Either.Left<String, JsonArray>(ei.left().getValue())); } } }); } else { handler.handle(new Right<String, JsonArray>(new JsonArray())); } }
From source file:org.entcore.blog.events.BlogSearchingEvents.java
License:Open Source License
private JsonArray formatSearchResult(final JsonArray results, final JsonArray columnsHeader, final List<String> words) { final List<String> aHeader = columnsHeader.getList(); final JsonArray traity = new 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 blogId = j.getJsonObject("blog").getString("$id"); jr.put(aHeader.get(0), j.getString("title")); jr.put(aHeader.get(1), j.getString("content", "")); jr.put(aHeader.get(2), j.getJsonObject("modified")); jr.put(aHeader.get(3), j.getJsonObject("author").getString("username")); jr.put(aHeader.get(4), j.getJsonObject("author").getString("userId")); jr.put(aHeader.get(5), "/blog#/view/" + blogId + "/" + j.getString("_id")); traity.add(jr);/*w w w . j ava2 s . c o m*/ } } return traity; }
From source file:org.entcore.cas.controllers.ConfigurationController.java
License:Open Source License
public void loadPatterns() { eb.send("wse.app.registry.bus", new JsonObject().put("action", "list-cas-connectors"), handlerToAsyncHandler(new Handler<Message<JsonObject>>() { @Override//from w w w .j av a 2 s . co m public void handle(Message<JsonObject> event) { if ("ok".equals(event.body().getString("status"))) { services.cleanPatterns(); JsonArray externalApps = event.body().getJsonArray("result"); for (Object o : externalApps) { if (!(o instanceof JsonObject)) continue; JsonObject j = (JsonObject) o; String service = j.getString("service"); JsonArray patterns = j.getJsonArray("patterns"); if (service != null && !service.trim().isEmpty() && patterns != null && patterns.size() > 0) { services.addPatterns(service, Arrays.copyOf(patterns.getList().toArray(), patterns.size(), String[].class)); } } } else { log.error(event.body().getString("message")); } } })); }
From source file:org.entcore.cas.controllers.ConfigurationController.java
License:Open Source License
@BusAddress(value = "cas.configuration", local = false) public void cas(Message<JsonObject> message) { switch (message.body().getString("action", "")) { case "list-services": message.reply(new JsonObject().put("status", "ok").put("result", services.getInfos(message.body().getString("accept-language", "fr")))); break;// w w w . j a v a2s.com case "add-patterns": String service = message.body().getString("service"); JsonArray patterns = message.body().getJsonArray("patterns"); message.reply(new JsonObject().put("status", services.addPatterns(service, Arrays.copyOf(patterns.getList().toArray(), patterns.size(), String[].class)) ? "ok" : "error")); break; default: message.reply(new JsonObject().put("status", "error").put("message", "invalid.action")); } }
From source file:org.entcore.cas.services.PronoteRegisteredService.java
License:Open Source License
@Override protected void prepareUser(User user, String userId, String service, JsonObject data) { user.setUser(data.getString(principalAttributeName)); user.setAttributes(new HashMap<String, String>()); try {// ww w.j a va 2 s .c o m if (data.getString("lastName") != null && data.getString("firstName") != null) { user.getAttributes().put("nom", data.getString("lastName")); user.getAttributes().put("prenom", data.getString("firstName")); } if (data.getString("birthDate") != null) { user.getAttributes().put("dateNaissance", data.getString("birthDate").replaceAll("([0-9]+)-([0-9]+)-([0-9]+)", "$3/$2/$1")); } if (data.getString("postalCode") != null) { user.getAttributes().put("codePostal", data.getString("postalCode")); } String category = null; JsonArray types = data.getJsonArray("type"); for (Object type : types.getList()) { switch (type.toString()) { case "Student": category = checkProfile(category, "National_1"); break; case "Teacher": category = checkProfile(category, "National_3"); break; case "Relative": category = checkProfile(category, "National_2"); break; case "Personnel": category = checkProfile(category, "National_4"); break; } } if (category != null) { user.getAttributes().put("categories", category); } } catch (Exception e) { log.error("Failed to transform User for Pronote"); } }
From source file:org.entcore.common.share.impl.GenericShareService.java
License:Open Source License
protected void shareValidation(String resourceId, String userId, JsonObject share, Handler<Either<String, JsonObject>> handler) { final JsonObject groups = share.getJsonObject("groups"); final JsonObject users = share.getJsonObject("users"); final JsonObject shareBookmark = share.getJsonObject("bookmarks"); final HashMap<String, Set<String>> membersActions = new HashMap<>(); if (groups != null && groups.size() > 0) { for (String attr : groups.fieldNames()) { JsonArray actions = groups.getJsonArray(attr); if (actionsExists(actions.getList())) { membersActions.put(attr, new HashSet<>(actions.getList())); }/*from w ww .ja v a 2 s .c o m*/ } } if (users != null && users.size() > 0) { for (String attr : users.fieldNames()) { JsonArray actions = users.getJsonArray(attr); if (actionsExists(actions.getList())) { membersActions.put(attr, new HashSet<>(actions.getList())); } } } if (shareBookmark != null && shareBookmark.size() > 0) { final JsonObject p = new JsonObject().put("userId", userId); StatementsBuilder statements = new StatementsBuilder(); for (String sbId : shareBookmark.fieldNames()) { final String csbId = cleanId(sbId); final String query = "MATCH (:User {id:{userId}})-[:HAS_SB]->(sb:ShareBookmark) " + "RETURN DISTINCT '" + csbId + "' as id, TAIL(sb." + csbId + ") as members "; statements.add(query, p); } Neo4j.getInstance().executeTransaction(statements.build(), null, true, Neo4jResult.validResultsHandler(sbRes -> { if (sbRes.isRight()) { JsonArray a = sbRes.right().getValue(); for (Object o : a) { JsonObject r = ((JsonArray) o).getJsonObject(0); JsonArray actions = shareBookmark.getJsonArray(r.getString("id")); JsonArray mIds = r.getJsonArray("members"); if (actions != null && mIds != null && mIds.size() > 0 && actionsExists(actions.getList())) { for (Object mId : mIds) { Set<String> actionsShare = membersActions.get(mId.toString()); if (actionsShare == null) { actionsShare = new HashSet<>(new HashSet<>(actions.getList())); membersActions.put(mId.toString(), actionsShare); // } else { // actionsShare.addAll(new HashSet<>(actions.getList())); } } } } shareValidationVisible(userId, resourceId, handler, membersActions, shareBookmark.fieldNames()); } else { handler.handle(new Either.Left<>(sbRes.left().getValue())); } })); } else { shareValidationVisible(userId, resourceId, handler, membersActions, null); } }
From source file:org.entcore.common.share.impl.GenericShareService.java
License:Open Source License
private void shareValidationVisible(String userId, String resourceId, Handler<Either<String, JsonObject>> handler, HashMap<String, Set<String>> membersActions, Set<String> shareBookmarkIds) { // final String preFilter = "AND m.id IN {members} "; final Set<String> members = membersActions.keySet(); final JsonObject params = new JsonObject().put("members", new JsonArray(new ArrayList<>(members))); // final String customReturn = "RETURN DISTINCT visibles.id as id, has(visibles.login) as isUser"; // UserUtils.findVisibles(eb, userId, customReturn, params, true, true, false, null, preFilter, res -> { checkMembers(params, res -> {/*from w w w. j a v a2 s .c o m*/ if (res != null) { final JsonArray users = new JsonArray(); final JsonArray groups = new JsonArray(); final JsonArray shared = new JsonArray(); final JsonArray notifyMembers = new JsonArray(); for (Object o : res) { JsonObject j = (JsonObject) o; final String attr = j.getString("id"); if (Boolean.TRUE.equals(j.getBoolean("isUser"))) { users.add(attr); notifyMembers.add(new JsonObject().put("userId", attr)); prepareSharedArray(resourceId, "userId", shared, attr, membersActions.get(attr)); } else { groups.add(attr); notifyMembers.add(new JsonObject().put("groupId", attr)); prepareSharedArray(resourceId, "groupId", shared, attr, membersActions.get(attr)); } } handler.handle(new Either.Right<>(params.put("shared", shared).put("groups", groups) .put("users", users).put("notify-members", notifyMembers))); if (shareBookmarkIds != null && res.size() < members.size()) { members.removeAll(groups.getList()); members.removeAll(users.getList()); resyncShareBookmark(userId, members, shareBookmarkIds); } } else { handler.handle(new Either.Left<>("Invalid members count.")); } }); }
From source file:org.entcore.common.sql.SqlResult.java
License:Open Source License
private static JsonArray transform(JsonObject body) { JsonArray f = body.getJsonArray("fields"); JsonArray r = body.getJsonArray("results"); JsonArray result = new fr.wseduc.webutils.collections.JsonArray(); if (f != null && r != null) { JsonArray jsonbAttributes = body.getJsonArray("jsonb_fields"); List ja = (jsonbAttributes != null) ? jsonbAttributes.getList() : new ArrayList<>(); for (Object o : r) { if (!(o instanceof JsonArray)) continue; JsonArray a = (JsonArray) o; JsonObject j = new fr.wseduc.webutils.collections.JsonObject(); for (int i = 0; i < f.size(); i++) { Object item = a.getValue(i); if (item instanceof Boolean) { j.put(f.getString(i), (Boolean) item); } else if (item instanceof Number) { j.put(f.getString(i), (Number) item); } else if (item instanceof JsonArray) { j.put(f.getString(i), (JsonArray) item); } else if (item != null && ja.contains(f.getValue(i))) { String stringRepresentation = item.toString().trim(); if (stringRepresentation.startsWith("[")) { j.put(f.getString(i), new fr.wseduc.webutils.collections.JsonArray(item.toString())); } else { j.put(f.getString(i), new fr.wseduc.webutils.collections.JsonObject(item.toString())); }//from ww w . j a v a 2s. c o m } else if (item != null) { j.put(f.getString(i), item.toString()); } else { j.put(f.getString(i), (String) null); } } result.add(j); } } return result; }
From source file:org.entcore.communication.controllers.CommunicationController.java
License:Open Source License
@Post("/visible") @SecuredAction(value = "", type = ActionType.AUTHENTICATED) public void searchVisible(HttpServerRequest request) { RequestUtils.bodyToJson(request, filter -> UserUtils.getUserInfos(eb, request, user -> { if (user != null) { String preFilter = ""; String match = ""; String where = ""; String nbUsers = ""; String groupTypes = ""; JsonObject params = new JsonObject(); JsonArray expectedTypes = null; if (filter != null && filter.size() > 0) { for (String criteria : filter.fieldNames()) { switch (criteria) { case "structures": case "classes": JsonArray itemssc = filter.getJsonArray(criteria); if (itemssc == null || itemssc.isEmpty() || ("structures".equals(criteria) && filter.getJsonArray("classes") != null && !filter.getJsonArray("classes").isEmpty())) continue; if (!params.containsKey("nIds")) { params.put("nIds", itemssc); } else { params.getJsonArray("nIds").addAll(itemssc); }/*from w w w.j a v a 2s.c o m*/ if (!match.contains("-[:DEPENDS")) { if (!match.contains("MATCH ")) { match = "MATCH "; where = " WHERE "; } else { match += ", "; where += "AND "; } match += "(visibles)-[:IN*0..1]->()-[:DEPENDS]->(n) "; where += "n.id IN {nIds} "; } if ("structures".equals(criteria)) { match = match.replaceFirst("\\[:DEPENDS]", "[:DEPENDS*1..2]"); } break; case "profiles": case "functions": JsonArray itemspf = filter.getJsonArray(criteria); if (itemspf == null || itemspf.isEmpty()) continue; if (!params.containsKey("filters")) { params.put("filters", itemspf); } else { //params.getJsonArray("filters").addAll(itemspf); params.put("filters2", itemspf); } if (!match.contains("MATCH ")) { match = "MATCH "; where = " WHERE "; } else { match += ", "; where += "AND "; } if (!match.contains("(visibles)-[:IN*0..1]->(g)")) { match += "(visibles)-[:IN*0..1]->(g)"; where += "g.filter IN {filters} "; } else { match += "(visibles)-[:IN*0..1]->(g2) "; where += "g2.filter IN {filters2} "; } break; case "search": final String search = filter.getString(criteria); if (isNotEmpty(search)) { preFilter = "AND m.displayNameSearchField CONTAINS {search} "; String sanitizedSearch = StringValidation.sanitize(search); params.put("search", sanitizedSearch); } break; case "types": JsonArray types = filter.getJsonArray(criteria); if (types != null && types.size() > 0 && CommunicationService.EXPECTED_TYPES.containsAll(types.getList())) { expectedTypes = types; } break; case "nbUsersInGroups": if (filter.getBoolean("nbUsersInGroups", false)) { nbUsers = ", visibles.nbUsers as nbUsers"; } break; case "groupType": if (filter.getBoolean("groupType", false)) { groupTypes = ", labels(visibles) as groupType, visibles.filter as groupProfile"; } break; } } } final boolean returnGroupType = !groupTypes.isEmpty(); final String customReturn = match + where + "RETURN DISTINCT visibles.id as id, visibles.name as name, " + "visibles.displayName as displayName, visibles.groupDisplayName as groupDisplayName, " + "HEAD(visibles.profiles) as profile" + nbUsers + groupTypes; communicationService.visibleUsers(user.getUserId(), null, expectedTypes, true, true, false, preFilter, customReturn, params, user.getType(), visibles -> { if (visibles.isRight()) { renderJson(request, UserUtils.translateAndGroupVisible(visibles.right().getValue(), I18n.acceptLanguage(request), returnGroupType)); } else { leftToResponse(request, visibles.left()); } }); } else { badRequest(request, "invalid.user"); } })); }