List of usage examples for io.vertx.core.json JsonArray isEmpty
public boolean isEmpty()
From source file:de.neofonie.deployer.DeployerVerticle.java
License:Open Source License
/** * Iterate and deploy verticles//from w ww .j av a2 s .co m */ private void deployVerticle(final Message<JsonObject> event) { // iterate over all candidates to be deployed Set<String> candidates = this.workingCopy.fieldNames(); // detach from underlying json Map<String, JsonObject> initiants = new HashMap<>(); candidates.forEach(id -> { JsonObject info = this.workingCopy.getJsonObject(id); JsonArray dependsOn = info.getJsonArray("dependsOn"); if (dependsOn != null && deployed.getList().containsAll(dependsOn.getList()) || dependsOn == null || dependsOn.isEmpty()) { initiants.put(id, info); } }); // remove the initiants initiants.keySet().forEach(id -> this.workingCopy.remove(id)); // setup latch for the reply CountDownLatch latch = new CountDownLatch(initiants.size()); if (initiants.isEmpty()) { event.reply(Boolean.TRUE); return; } // run over all dependencies initiants.forEach((id, info) -> { // get the name of the verticle String name = info.getString("name"); final JsonObject localConfig = new JsonObject(); localConfig.mergeIn(globalConfig); localConfig.mergeIn(info.getJsonObject("config", new JsonObject())); Handler<AsyncResult<String>> handler = innerEvent -> { if (innerEvent.succeeded()) { // add service to deployed-list deployed.add(id); // re-emit vertx.eventBus().send(LOOPBACK, workingCopy, (AsyncResult<Message<Boolean>> recursiveReply) -> { // always decrease latch latch.countDown(); if (recursiveReply.succeeded() && recursiveReply.result().body()) { if (latch.getCount() == 0) { event.reply(recursiveReply.result().body() & Boolean.TRUE); } } else { event.fail(500, this.getFailure(id, recursiveReply)); } }); } else { event.fail(500, id + " >> " + innerEvent.cause().getMessage()); } }; LOG.log(Level.INFO, "Deploying: ''{0}''", new Object[] { id }); DeploymentOptions deploymentOptions = new DeploymentOptions(info); vertx.deployVerticle(name, deploymentOptions.setConfig(localConfig), handler); }); }
From source file:io.sqp.proxy.vertx.VertxBackendConnectionPool.java
License:Open Source License
private void loadConfigurations(JsonArray backendConfs) throws ConfigurationException { // first validate the configuration object if (backendConfs == null || backendConfs.isEmpty()) { throw new ConfigurationException("No backend was configured."); }/*from w w w . j a v a 2s .c om*/ if (backendConfs.size() > 1) { logger.log(Level.WARNING, "Only one backend configuration is supported at the moment. The rest is ignored."); } JsonObject firstConf = backendConfs.getJsonObject(0); if (firstConf == null) { throwInvalidConfiguration("It's not a valid JSON object."); } // Every backend needs a specific 'config' configuration map JsonObject backendSpecificConf = firstConf.getJsonObject("config"); if (backendSpecificConf == null) { throwInvalidConfiguration("Backend specific configuration is missing."); } _backendSpecificConfiguration = backendSpecificConf.getMap(); // The 'type' defines the subclass of BackendConnection that is the heart of the backend String backendType = firstConf.getString("type"); if (backendType == null) { throwInvalidConfiguration("No type specified."); } // Get the class from the class loader and verify it's a subclass of BackendConnection Class<?> uncastedBackendClass = null; try { uncastedBackendClass = Class.forName(backendType); } catch (ClassNotFoundException e) { throwInvalidConfiguration("Class '" + backendType + "' specified as 'type' was not found."); } try { _backendClass = uncastedBackendClass.asSubclass(Backend.class); } catch (ClassCastException e) { throwInvalidConfiguration("Class '" + backendType + "' is not a valid Backend implementation."); } }
From source file:org.eclipse.hono.service.credentials.BaseCredentialsService.java
License:Open Source License
private boolean containsValidSecretValue(final JsonObject credentials) { final Object obj = credentials.getValue(FIELD_SECRETS); if (JsonArray.class.isInstance(obj)) { JsonArray secrets = (JsonArray) obj; if (secrets.isEmpty()) { log.debug("credentials request contains empty {} object in payload - not supported", FIELD_SECRETS); return false; } else {/* w w w .j ava 2s .co m*/ for (int i = 0; i < secrets.size(); i++) { JsonObject currentSecret = secrets.getJsonObject(i); if (!containsValidTimestampIfPresentForField(currentSecret, FIELD_SECRETS_NOT_BEFORE) || !containsValidTimestampIfPresentForField(currentSecret, FIELD_SECRETS_NOT_AFTER)) { log.debug("credentials request did contain invalid timestamp values in payload"); return false; } } return true; } } else { log.debug("credentials request does not contain a {} array in payload - not supported", FIELD_SECRETS); return false; } }
From source file:org.entcore.common.sql.SqlStatementsBuilder.java
License:Open Source License
public SqlStatementsBuilder insert(String table, JsonArray fields, JsonArray values, String returning) { if (table != null && !table.trim().isEmpty() && values != null && !values.isEmpty()) { JsonObject statement = new JsonObject().put("action", "insert").put("table", table) .put("fields", fields).put("values", values); if (returning != null && !returning.trim().isEmpty()) { statement.put("returning", returning); }//w ww .j ava2 s. c om statements.add(statement); } return this; }
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. jav a 2 s . c om*/ 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"); } })); }
From source file:org.entcore.conversation.controllers.ConversationController.java
License:Open Source License
@Put("trash") @SecuredAction(value = "", type = ActionType.RESOURCE) @ResourceFilter(MultipleMessageUserFilter.class) public void trash(final HttpServerRequest request) { bodyToJson(request, new Handler<JsonObject>() { @Override// ww w .j a v a 2 s . com public void handle(JsonObject body) { JsonArray ids = body.getJsonArray("id"); if (ids == null || ids.isEmpty()) { badRequest(request); return; } getUserInfos(eb, request, new Handler<UserInfos>() { @Override public void handle(final UserInfos user) { if (user != null) { conversationService.trash(ids.getList(), user, defaultResponseHandler(request)); } else { unauthorized(request); } } }); } }); }
From source file:org.entcore.conversation.controllers.ConversationController.java
License:Open Source License
@Put("restore") @SecuredAction(value = "", type = ActionType.RESOURCE) @ResourceFilter(MultipleMessageUserFilter.class) public void restore(final HttpServerRequest request) { bodyToJson(request, new Handler<JsonObject>() { @Override//from w ww. ja va2 s .co m public void handle(JsonObject body) { JsonArray ids = body.getJsonArray("id"); if (ids == null || ids.isEmpty()) { badRequest(request); return; } getUserInfos(eb, request, new Handler<UserInfos>() { @Override public void handle(final UserInfos user) { if (user != null) { conversationService.restore(ids.getList(), user, defaultResponseHandler(request)); } else { unauthorized(request); } } }); } }); }
From source file:org.entcore.conversation.controllers.ConversationController.java
License:Open Source License
@Put("delete") @SecuredAction(value = "", type = ActionType.RESOURCE) @ResourceFilter(MultipleMessageUserFilter.class) public void delete(final HttpServerRequest request) { bodyToJson(request, new Handler<JsonObject>() { @Override/*from w w w . jav a 2 s . c o m*/ public void handle(JsonObject body) { JsonArray ids = body.getJsonArray("id"); if (ids == null || ids.isEmpty()) { badRequest(request); return; } deleteMessages(request, ids.getList(), false); } }); }
From source file:org.entcore.conversation.controllers.ConversationController.java
License:Open Source License
@Post("toggleUnread") @SecuredAction(value = "", type = ActionType.RESOURCE) @ResourceFilter(MultipleMessageUserFilter.class) public void toggleUnread(final HttpServerRequest request) { bodyToJson(request, new Handler<JsonObject>() { @Override/* w w w . j a v a2 s.c om*/ public void handle(JsonObject body) { final JsonArray ids = body.getJsonArray("id"); final Boolean unread = body.getBoolean("unread"); if (ids == null || ids.isEmpty() || unread == null) { badRequest(request); return; } UserUtils.getUserInfos(eb, request, new Handler<UserInfos>() { @Override public void handle(final UserInfos user) { if (user != null) { conversationService.toggleUnread(ids.getList(), unread, user, defaultResponseHandler(request)); } else { unauthorized(request); } } }); } }); }
From source file:org.entcore.directory.controllers.ShareBookmarkController.java
License:Open Source License
@Get("/sharebookmark/:id") @SecuredAction(value = "", type = ActionType.AUTHENTICATED) public void get(HttpServerRequest request) { UserUtils.getUserInfos(eb, request, user -> { if (user != null) { final String id = request.params().get("id"); if ("all".equals(id)) { shareBookmarkService.list(user.getUserId(), arrayResponseHandler(request)); } else { shareBookmarkService.get(user.getUserId(), id, r -> { if (r.isRight()) { final JsonObject res = r.right().getValue(); JsonArray members = res.getJsonArray("members"); if (members == null || members.isEmpty()) { shareBookmarkService.delete(user.getUserId(), id, dres -> { if (dres.isLeft()) { log.error("Error deleting sharebookmark " + id + " : " + dres.left().getValue()); }//from ww w . j ava 2 s .c o m }); notFound(request, "empty.sharebookmark"); return; } res.mergeIn(UserUtils.translateAndGroupVisible(members, I18n.acceptLanguage(request), true)); res.remove("members"); renderJson(request, res); } else { leftToResponse(request, r.left()); } }); } } else { badRequest(request, "invalid.user"); } }); }