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

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

Introduction

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

Prototype

public JsonArray() 

Source Link

Document

Create an empty instance

Usage

From source file:fr.wseduc.rack.controllers.RackController.java

License:Open Source License

private void createThumbnails(List<String> thumbs, JsonObject srcFile, final String collection,
        final String documentId) {
    Pattern size = Pattern.compile("([0-9]+)x([0-9]+)");
    JsonArray outputs = new JsonArray();
    for (String thumb : thumbs) {
        Matcher m = size.matcher(thumb);
        if (m.matches()) {
            try {
                int width = Integer.parseInt(m.group(1));
                int height = Integer.parseInt(m.group(2));
                if (width == 0 && height == 0)
                    continue;
                JsonObject j = new JsonObject().put("dest",
                        storage.getProtocol() + "://" + storage.getBucket());
                if (width != 0) {
                    j.put("width", width);
                }/*from w  ww.j  a v  a2  s  .  c  om*/
                if (height != 0) {
                    j.put("height", height);
                }
                outputs.add(j);
            } catch (NumberFormatException e) {
                log.error("Invalid thumbnail size.", e);
            }
        }
    }
    if (outputs.size() > 0) {
        JsonObject json = new JsonObject().put("action", "resizeMultiple")
                .put("src",
                        storage.getProtocol() + "://" + storage.getBucket() + ":" + srcFile.getString("_id"))
                .put("destinations", outputs);
        eb.send(imageResizerAddress, json, new Handler<AsyncResult<Message<JsonObject>>>() {
            @Override
            public void handle(AsyncResult<Message<JsonObject>> event) {
                if (event.succeeded()) {
                    JsonObject thumbnails = event.result().body().getJsonObject("outputs");
                    if ("ok".equals(event.result().body().getString("status")) && thumbnails != null) {
                        mongo.update(collection, new JsonObject().put("_id", documentId),
                                new JsonObject().put("$set", new JsonObject().put("thumbnails", thumbnails)));
                    }
                } else {
                    log.error("Error when resize image.", event.cause());
                }
            }
        });
    }
}

From source file:fr.wseduc.smsproxy.providers.ovh.OVHSmsProvider.java

License:Apache License

@Override
public void sendSms(final Message<JsonObject> message) {
    final JsonObject parameters = message.body().getJsonObject("parameters");
    logger.debug("[OVH][sendSms] Called with parameters : " + parameters);

    final Handler<HttpClientResponse> resultHandler = new Handler<HttpClientResponse>() {
        public void handle(HttpClientResponse response) {
            if (response == null) {
                sendError(message, "ovh.apicall.error", null);
            } else {
                response.bodyHandler(new Handler<Buffer>() {
                    public void handle(Buffer body) {
                        final JsonObject response = new JsonObject(body.toString());
                        final JsonArray invalidReceivers = response.getJsonArray("invalidReceivers",
                                new JsonArray());
                        final JsonArray validReceivers = response.getJsonArray("validReceivers",
                                new JsonArray());

                        if (validReceivers.size() == 0) {
                            sendError(message, "invalid.receivers.all", null, new JsonObject(body.toString()));
                        } else if (invalidReceivers.size() > 0) {
                            sendError(message, "invalid.receivers.partial", null,
                                    new JsonObject(body.toString()));
                        } else {
                            message.reply(response);
                        }//from   w w  w.j  a  v a2s .  c o  m
                    }
                });
            }
        }
    };

    Handler<String> serviceCallback = new Handler<String>() {
        public void handle(String service) {
            if (service == null) {
                sendError(message, "ovh.apicall.error", null);
            } else {
                ovhRestClient.post("/sms/" + service + "/jobs/", parameters, resultHandler);
            }
        }
    };

    retrieveSmsService(message, serviceCallback);
}

From source file:io.apiman.gateway.platforms.vertx3.common.config.InheritingHttpServerOptionsConverter.java

License:Apache License

public static void toJson(InheritingHttpServerOptions obj, JsonObject json) {
    json.put("acceptBacklog", obj.getAcceptBacklog());
    json.put("acceptUnmaskedFrames", obj.isAcceptUnmaskedFrames());
    if (obj.getAlpnVersions() != null) {
        JsonArray array = new JsonArray();
        obj.getAlpnVersions().forEach(item -> array.add(item.name()));
        json.put("alpnVersions", array);
    }/*from ww w  .  j a  va2s  . com*/
    if (obj.getClientAuth() != null) {
        json.put("clientAuth", obj.getClientAuth().name());
    }
    json.put("clientAuthRequired", obj.isClientAuthRequired());
    json.put("compressionLevel", obj.getCompressionLevel());
    json.put("compressionSupported", obj.isCompressionSupported());
    if (obj.getCrlPaths() != null) {
        JsonArray array = new JsonArray();
        obj.getCrlPaths().forEach(item -> array.add(item));
        json.put("crlPaths", array);
    }
    if (obj.getCrlValues() != null) {
        JsonArray array = new JsonArray();
        obj.getCrlValues().forEach(item -> array.add(item.getBytes()));
        json.put("crlValues", array);
    }
    json.put("decompressionSupported", obj.isDecompressionSupported());
    if (obj.getEnabledCipherSuites() != null) {
        JsonArray array = new JsonArray();
        obj.getEnabledCipherSuites().forEach(item -> array.add(item));
        json.put("enabledCipherSuites", array);
    }
    if (obj.getEnabledSecureTransportProtocols() != null) {
        JsonArray array = new JsonArray();
        obj.getEnabledSecureTransportProtocols().forEach(item -> array.add(item));
        json.put("enabledSecureTransportProtocols", array);
    }
    json.put("handle100ContinueAutomatically", obj.isHandle100ContinueAutomatically());
    if (obj.getHost() != null) {
        json.put("host", obj.getHost());
    }
    json.put("http2ConnectionWindowSize", obj.getHttp2ConnectionWindowSize());
    json.put("idleTimeout", obj.getIdleTimeout());
    if (obj.getInitialSettings() != null) {
        json.put("initialSettings", obj.getInitialSettings().toJson());
    }
    if (obj.getJdkSslEngineOptions() != null) {
        json.put("jdkSslEngineOptions", obj.getJdkSslEngineOptions().toJson());
    }
    if (obj.getKeyStoreOptions() != null) {
        json.put("keyStoreOptions", obj.getKeyStoreOptions().toJson());
    }
    json.put("logActivity", obj.getLogActivity());
    json.put("maxChunkSize", obj.getMaxChunkSize());
    json.put("maxHeaderSize", obj.getMaxHeaderSize());
    json.put("maxInitialLineLength", obj.getMaxInitialLineLength());
    json.put("maxWebsocketFrameSize", obj.getMaxWebsocketFrameSize());
    json.put("maxWebsocketMessageSize", obj.getMaxWebsocketMessageSize());
    if (obj.getOpenSslEngineOptions() != null) {
        json.put("openSslEngineOptions", obj.getOpenSslEngineOptions().toJson());
    }
    if (obj.getPemKeyCertOptions() != null) {
        json.put("pemKeyCertOptions", obj.getPemKeyCertOptions().toJson());
    }
    if (obj.getPemTrustOptions() != null) {
        json.put("pemTrustOptions", obj.getPemTrustOptions().toJson());
    }
    if (obj.getPfxKeyCertOptions() != null) {
        json.put("pfxKeyCertOptions", obj.getPfxKeyCertOptions().toJson());
    }
    if (obj.getPfxTrustOptions() != null) {
        json.put("pfxTrustOptions", obj.getPfxTrustOptions().toJson());
    }
    json.put("port", obj.getPort());
    json.put("receiveBufferSize", obj.getReceiveBufferSize());
    json.put("reuseAddress", obj.isReuseAddress());
    json.put("sendBufferSize", obj.getSendBufferSize());
    json.put("soLinger", obj.getSoLinger());
    json.put("ssl", obj.isSsl());
    json.put("tcpKeepAlive", obj.isTcpKeepAlive());
    json.put("tcpNoDelay", obj.isTcpNoDelay());
    json.put("trafficClass", obj.getTrafficClass());
    if (obj.getTrustStoreOptions() != null) {
        json.put("trustStoreOptions", obj.getTrustStoreOptions().toJson());
    }
    json.put("useAlpn", obj.isUseAlpn());
    json.put("usePooledBuffers", obj.isUsePooledBuffers());
    if (obj.getWebsocketSubProtocols() != null) {
        json.put("websocketSubProtocols", obj.getWebsocketSubProtocols());
    }
}

From source file:io.apiman.gateway.platforms.vertx3.components.jdbc.VertxJdbcConnection.java

License:Apache License

private JsonArray toJsonArray(Object[] params) {
    JsonArray jsonArray = new JsonArray();
    for (Object o : params) {
        jsonArray.add(o);//from  www. j  a  va 2  s  .c o  m
    }
    return jsonArray;
}

From source file:io.engagingspaces.graphql.marshaller.schema.decorators.GraphQLSchemaDO.java

License:Open Source License

@Override
public Set<GraphQLType> getDictionary() {
    if (schema == null) {
        return schemaJson.getJsonArray(DICTIONARY, new JsonArray()).stream()
                .map(type -> (GraphQLType) context.unmarshall((JsonObject) type)).collect(Collectors.toSet());
    }//  w w  w. ja  va2  s  .com
    return schema.getDictionary().stream().map(context::decoratorOf).collect(Collectors.toSet());
}

From source file:io.engagingspaces.graphql.query.QueryResult.java

License:Open Source License

/**
 * Creates a new {@link QueryResult} from
 * its json representation.//  w w  w  .j  a v a 2  s. co  m
 *
 * @param json the json object
 */
public QueryResult(JsonObject json) {
    this.data = json.getJsonObject("data", new JsonObject());
    this.succeeded = json.getBoolean("succeeded", false);
    List<QueryError> queryErrors = json.getJsonArray("errors", new JsonArray()).stream()
            .map(error -> new QueryError((JsonObject) error)).collect(Collectors.toList());
    this.errors = queryErrors == null ? Collections.emptyList() : Collections.unmodifiableList(queryErrors);
}

From source file:io.fabric8.devops.apps.elasticsearch.helper.service.ElasticSearchOptionsConverter.java

License:Apache License

public static void toJson(ElasticSearchOptions obj, JsonObject json) {
    if (obj.getConfigMap() != null) {
        json.put("configMap", obj.getConfigMap());
    }//from   w  ww  . jav a2  s .  c o m
    json.put("configMapScanPeriod", obj.getConfigMapScanPeriod());
    if (obj.getHost() != null) {
        json.put("host", obj.getHost());
    }
    if (obj.getIndexes() != null) {
        JsonArray array = new JsonArray();
        obj.getIndexes().forEach(item -> array.add(item));
        json.put("indexes", array);
    }
    if (obj.getKubernetesNamespace() != null) {
        json.put("kubernetesNamespace", obj.getKubernetesNamespace());
    }
    json.put("port", obj.getPort());
    json.put("ssl", obj.isSsl());
}

From source file:io.flowly.auth.manager.BaseManager.java

License:Open Source License

/**
 * Retrieves direct and indirect memberships that a user or group holds.
 *
 * @param vertex vertex in the auth graph representing a user or group.
 * @param jsonObject JSON object representing the user or group to which retrieved memberships are added.
 * @param includeEffectiveMemberships indicates if all the user or group memberships are to be retrieved.
 * @param includeDirectMemberships indicates if the user's direct memberships are to be retrieved.
 * @param includePermissions indicates if the permissions granted to each group are to be retrieved.
 *///from  w w w  .j  ava  2s  .  c o  m
protected void getMemberships(Vertex vertex, JsonObject jsonObject, boolean includeEffectiveMemberships,
        boolean includeDirectMemberships, boolean includePermissions) {
    boolean isUserVertex = jsonObject.containsKey(User.USER_ID);
    String uniqueId = isUserVertex ? jsonObject.getString(User.USER_ID) : jsonObject.getString(Group.GROUP_ID);

    if (includeEffectiveMemberships || includePermissions) {
        JsonArray effectiveMemberships = new JsonArray();
        jsonObject.put(User.EFFECTIVE_MEMBERSHIPS, effectiveMemberships);

        List<Vertex> groupVertices = graph.traversal().V(vertex).repeat(__.outE(Schema.E_MEMBER_OF).inV())
                .emit().toList();
        getDistinctMemberships(groupVertices, effectiveMemberships, uniqueId, isUserVertex, includePermissions);
    }

    if (includeDirectMemberships) {
        JsonArray directMemberships = new JsonArray();
        jsonObject.put(User.DIRECT_MEMBERSHIPS, directMemberships);

        getDistinctMemberships(graph.traversal().V(vertex).outE(Schema.E_MEMBER_OF).inV().toList(),
                directMemberships, null, false, false);
    }
}

From source file:io.flowly.auth.manager.GroupManager.java

License:Open Source License

@Override
public JsonArray delete(Object id) {
    JsonArray errors;//from   ww  w  . j av a  2 s  . c o m

    try {
        // Cannot delete administrators group.
        Vertex vertex = getVertex(id);
        if (!ObjectKeys.ADMIN_GROUP_ID.equalsIgnoreCase(getPropertyValue(vertex, Schema.V_P_GROUP_ID))) {
            errors = super.delete(id);
        } else {
            errors = new JsonArray().add("Cannot delete group: " + id);
        }

        commit();
    } catch (Exception ex) {
        rollback();
        errors = new JsonArray().add("Cannot delete group:" + id);
        logger.error(errors.getString(0), ex);
    }

    return errors;
}

From source file:io.flowly.auth.manager.GroupManager.java

License:Open Source License

private void getMembers(Vertex groupVertex, JsonObject group, boolean includeDirectMembers,
        boolean includeEffectiveUsers) {
    if (includeDirectMembers) {
        JsonArray directMembers = new JsonArray();
        group.put(Group.DIRECT_MEMBERS, directMembers);

        graph.traversal().V(groupVertex).outE(Schema.E_MEMBER).inV().sideEffect(m -> {
            Vertex vertex = m.get();/*from   w w  w .  j a  v a2  s  .c  om*/
            if (vertex.label().equals(Schema.V_USER)) {
                directMembers.add(makeUserObject(vertex));
            } else {
                directMembers.add(makeGroupObject(vertex, null, false));
            }

        }).toList();
    }

    // Recursively retrieve all unique users.
    if (includeEffectiveUsers) {
        JsonArray allUsers = new JsonArray();
        group.put(Group.ALL_USERS, allUsers);

        getUsers(groupVertex, allUsers, new HashSet<>());
    }
}