List of usage examples for io.vertx.core.json JsonArray JsonArray
public JsonArray(Buffer buf)
From source file:org.eclipse.hono.service.credentials.impl.FileBasedCredentialsService.java
License:Open Source License
protected void loadCredentialsData() { if (filename != null) { final FileSystem fs = vertx.fileSystem(); log.debug("trying to load credentials information from file {}", filename); if (fs.existsBlocking(filename)) { final AtomicInteger credentialsCount = new AtomicInteger(); fs.readFile(filename, readAttempt -> { if (readAttempt.succeeded()) { JsonArray allObjects = new JsonArray(new String(readAttempt.result().getBytes())); for (Object obj : allObjects) { JsonObject tenant = (JsonObject) obj; String tenantId = tenant.getString(FIELD_TENANT); Map<String, JsonArray> credentialsMap = new HashMap<>(); for (Object credentialsObj : tenant.getJsonArray(ARRAY_CREDENTIALS)) { JsonObject credentials = (JsonObject) credentialsObj; JsonArray authIdCredentials; if (credentialsMap.containsKey(credentials.getString(FIELD_AUTH_ID))) { authIdCredentials = credentialsMap.get(credentials.getString(FIELD_AUTH_ID)); } else { authIdCredentials = new JsonArray(); }/*ww w.j a va2s . c om*/ authIdCredentials.add(credentials); credentialsMap.put(credentials.getString(FIELD_AUTH_ID), authIdCredentials); credentialsCount.incrementAndGet(); } credentials.put(tenantId, credentialsMap); } log.info("successfully loaded {} credentials from file [{}]", credentialsCount.get(), filename); } else { log.warn("could not load credentials from file [{}]", filename, readAttempt.cause()); } }); } else { log.debug("credentials file {} does not exist (yet)", filename); } } }
From source file:org.eclipse.hono.service.registration.impl.FileBasedRegistrationService.java
License:Open Source License
private void loadRegistrationData() { if (filename != null) { final FileSystem fs = vertx.fileSystem(); log.debug("trying to load device registration information from file {}", filename); if (fs.existsBlocking(filename)) { final AtomicInteger deviceCount = new AtomicInteger(); fs.readFile(filename, readAttempt -> { if (readAttempt.succeeded()) { JsonArray allObjects = new JsonArray(new String(readAttempt.result().getBytes())); for (Object obj : allObjects) { JsonObject tenant = (JsonObject) obj; String tenantId = tenant.getString(FIELD_TENANT); Map<String, JsonObject> deviceMap = new HashMap<>(); for (Object deviceObj : tenant.getJsonArray(ARRAY_DEVICES)) { JsonObject device = (JsonObject) deviceObj; deviceMap.put(device.getString(FIELD_HONO_ID), device.getJsonObject(FIELD_DATA)); deviceCount.incrementAndGet(); }/*from w w w . j av a2 s. c o m*/ identities.put(tenantId, deviceMap); } log.info("successfully loaded {} device identities from file [{}]", deviceCount.get(), filename); } else { log.warn("could not load device identities from file [{}]", filename, readAttempt.cause()); } }); } else { log.debug("device identity file {} does not exist (yet)", filename); } } }
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 a 2s . c om 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.share.impl.GenericShareService.java
License:Open Source License
private void resyncShareBookmark(String userId, Set<String> members, Set<String> shareBookmarkIds) { final StringBuilder query = new StringBuilder( "MATCH (:User {id:{userId}})-[:HAS_SB]->(sb:ShareBookmark) SET "); for (String sb : shareBookmarkIds) { query.append("sb.").append(sb).append(" = FILTER(mId IN sb.").append(sb) .append(" WHERE NOT(mId IN {members})), "); }/*from w w w . j a v a 2 s . com*/ JsonObject params = new JsonObject().put("userId", userId).put("members", new JsonArray(new ArrayList<>(members))); Neo4j.getInstance().execute(query.substring(0, query.length() - 2), params, res -> { if ("ok".equals(res.body().getString("status"))) { log.info("Resync share bookmark for user " + userId); } else { log.error("Error when resync share bookmark for user " + userId + " : " + res.body().getString("message")); } }); }
From source file:org.entcore.cursus.controllers.CursusController.java
License:Open Source License
@Get("/sales") @SecuredAction(value = "", type = ActionType.AUTHENTICATED) public void getSales(final HttpServerRequest request) { final String cardNb = request.params().get("cardNb"); if (cardNb == null) { badRequest(request);//from w w w .j a va 2 s .c om return; } service.getUserInfo(cardNb, new Handler<Either<String, JsonArray>>() { public void handle(Either<String, JsonArray> result) { if (result.isLeft()) { badRequest(request); return; } final String id = result.right().getValue().getJsonObject(0).getInteger("id").toString(); String birthDateEncoded = result.right().getValue().getJsonObject(0).getString("dateNaissance"); try { birthDateEncoded = birthDateEncoded.replace("/Date(", ""); birthDateEncoded = birthDateEncoded.substring(0, birthDateEncoded.indexOf("+")); final Date birthDate = new Date(Long.parseLong(birthDateEncoded)); UserUtils.getUserInfos(eb, request, new Handler<UserInfos>() { public void handle(UserInfos infos) { DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { Date sessionBirthDate = format.parse(infos.getBirthDate()); if (sessionBirthDate.compareTo(birthDate) == 0) { service.getSales(id, cardNb, new Handler<Either<String, JsonArray>>() { public void handle(Either<String, JsonArray> result) { if (result.isLeft()) { badRequest(request); return; } JsonObject finalResult = new JsonObject() .put("wallets", new JsonArray(cursusMap.get("wallets"))) .put("sales", result.right().getValue()); renderJson(request, finalResult); } }); } else { badRequest(request); } } catch (ParseException e) { badRequest(request); return; } } }); } catch (Exception e) { badRequest(request); } } }); }
From source file:org.entcore.directory.services.impl.DefaultSchoolService.java
License:Open Source License
@Override public void searchCriteria(List<String> structures, Handler<Either<String, JsonObject>> handler) { final String query = "MATCH (s:Structure) " + "WHERE s.id IN {structures} " + "OPTIONAL MATCH (s)<-[:BELONGS]-(c:Class) " + "OPTIONAL MATCH (s)<-[:DEPENDS]-(fg:FunctionGroup) " + "OPTIONAL MATCH (s)<-[:DEPENDS]-(htg:HTGroup) " + "RETURN COLLECT(DISTINCT { id: s.id, name: s.name}) as structures, " + "COLLECT(DISTINCT { id: c.id, name: c.name}) as classes, " + "CASE WHEN LENGTH(COLLECT(distinct htg)) = 0 THEN COLLECT(DISTINCT fg.filter) ELSE COLLECT(DISTINCT fg.filter) + 'HeadTeacher' END as functions, " + "['Teacher', 'Personnel', 'Student', 'Relative', 'Guest'] as profiles, " + "['ManualGroup','FunctionalGroup','CommunityGroup'] as groupTypes"; neo.execute(query, new JsonObject().put("structures", new JsonArray(structures)), validUniqueResultHandler(handler)); }
From source file:org.entcore.feeder.timetable.udt.UDTImporter.java
License:Open Source License
private void persistUsedGroups() { txXDT.add(PERSIST_USED_GROUPS, new JsonObject().put("structureExternalId", structureExternalId) .put("usedGroups", new JsonArray(new ArrayList<>(usedGroupInCourses)))); }
From source file:org.etourdot.vertx.marklogic.impl.MarkLogicDocumentImpl.java
License:Open Source License
void readDocument(String docId, List<String> categories, Handler<AsyncResult<JsonObject>> resultHandler) { JsonArray docIds = new JsonArray(Collections.singletonList(docId)); readDocuments(docIds, categories, (result) -> { if (result.failed()) { resultHandler.handle(Future.failedFuture(result.cause())); } else {//from www . j av a 2 s . co m resultHandler.handle(Future.succeededFuture(result.result().getJsonObject(0))); } }); }
From source file:org.jboss.weld.vertx.examples.translator.DummyDataVerticle.java
License:Apache License
@Override public void start() throws Exception { // Read data.properties Properties properties = new Properties(); properties.load(DummyDataVerticle.class.getResourceAsStream("data.properties")); for (Entry<Object, Object> entry : properties.entrySet()) { translationData.put(entry.getKey().toString().toLowerCase(), Arrays.asList(entry.getValue().toString().split(","))); }/* www.j ava2 s.c o m*/ vertx.eventBus().consumer(REQUEST_DATA, (m) -> { String word = m.body().toString(); LOGGER.info("Find translation data for {0}", word); List<String> result = translationData.get(word.toLowerCase()); if (result == null) { result = Collections.emptyList(); } if (result.isEmpty()) { LOGGER.warn("No translation data available for: {0}", word); } m.reply(new JsonObject().put("word", word).put("translations", new JsonArray(result))); }); }
From source file:org.pac4j.vertx.core.DefaultJsonConverter.java
License:Apache License
@Override public Object encodeObject(Object value) { if (value == null) { return null; } else if (isPrimitiveType(value)) { return value; } else if (value instanceof Object[]) { Object[] src = ((Object[]) value); List<Object> list = new ArrayList<>(src.length); for (Object object : src) { list.add(encodeObject(object)); }/*from w ww . ja v a 2 s .c o m*/ return new JsonArray(list); } else { try { return new JsonObject().put("class", value.getClass().getName()).put("value", new JsonObject(encode(value))); } catch (Exception e) { throw new TechnicalException("Error while encoding object", e); } } }