Example usage for io.vertx.core.json JsonObject getJsonArray

List of usage examples for io.vertx.core.json JsonObject getJsonArray

Introduction

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

Prototype

public JsonArray getJsonArray(String key) 

Source Link

Document

Get the JsonArray value with the specified key

Usage

From source file:org.etourdot.vertx.marklogic.http.impl.response.DefaultMultiPartResponse.java

License:Open Source License

private List<Document> transformPartToDocument(Map<String, List<HttpPart>> responseParts) {
    List<Document> documents = new ArrayList<>();
    for (Map.Entry<String, List<HttpPart>> responsePartEntry : responseParts.entrySet()) {
        Document document = Document.create();
        for (HttpPart part : responsePartEntry.getValue()) {
            document.format(part.getFormat());
            document.uri(part.getDocumentUri());
            if (part.isMetadata()) {
                JsonObject metadata = part.getBuffer().toJsonObject();
                document.collections(metadata.getJsonArray(MarkLogicConstants.COLLECTIONS));
                document.permissions(metadata.getJsonArray(MarkLogicConstants.PERMISSIONS));
                document.properties(metadata.getJsonObject(MarkLogicConstants.PROPERTIES));
                document.quality(metadata.getInteger(MarkLogicConstants.QUALITY));
            } else if (part.isContent()) {
                if (document.isJson()) {
                    document.content(part.getBuffer().toJsonObject());
                } else {
                    document.content(part.getBuffer());
                }/*from   w  w  w  .  j av  a2 s  .co m*/
            }
        }
        documents.add(document);
    }
    return documents;
}

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

License:Open Source License

public DocumentImpl(JsonObject jsonObject) {
    this();//  w  w w.j  av a 2 s  . co  m
    requireNonNull(jsonObject);

    ofNullable(jsonObject.getString(URI)).ifPresent(this::uri);
    ofNullable(jsonObject.getValue(CONTENT)).ifPresent(this::contentObject);
    ofNullable(jsonObject.getJsonArray(COLLECTIONS)).ifPresent(this::collections);
    ofNullable(jsonObject.getJsonArray(PERMISSIONS)).ifPresent(this::permissions);
    ofNullable(jsonObject.getInteger(QUALITY)).ifPresent(this::quality);
    ofNullable(jsonObject.getJsonObject(PROPERTIES)).ifPresent(this::properties);
    ofNullable(jsonObject.getString(EXTENSION)).ifPresent(this::extension);
    ofNullable(jsonObject.getString(DIRECTORY)).ifPresent(this::directory);
    ofNullable(jsonObject.getLong(VERSION)).ifPresent(this::version);
    ofNullable(jsonObject.getString(EXTRACT)).ifPresent(this::extract);
    ofNullable(jsonObject.getString(LANG)).ifPresent(this::lang);
    ofNullable(jsonObject.getString(REPAIR)).ifPresent(this::repair);
    ofNullable(jsonObject.getString(FORMAT)).ifPresent(this::format);
    ofNullable(jsonObject.getString(MIME_TYPE)).ifPresent(this::contentType);
    if (!hasContentType()) {
        contentType(jsonObject.getString(CONTENT_TYPE));
    }
    forceFormatOrContentType();
}

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

License:Open Source License

public DocumentsImpl(JsonObject jsonObject) {
    this();//from www .  j av a 2 s  .co m
    requireNonNull(jsonObject);
    documents(jsonObject.getJsonArray(DOCUMENTS));
    ofNullable(jsonObject.getJsonObject(TRANSFORM)).ifPresent(this::transform);
    ofNullable(jsonObject.getString(TXID)).ifPresent(this::txid);
    ofNullable(jsonObject.getString(FOREST_NAME)).ifPresent(this::forestName);
    ofNullable(jsonObject.getString(TEMPORAL_COLLECTION)).ifPresent(this::temporalCollection);
    ofNullable(jsonObject.getString(SYSTEM_TIME)).ifPresent(this::systemTime);
    ofNullable(jsonObject.getJsonArray(CATEGORIES)).ifPresent(this::categories);
}

From source file:org.etourdot.vertx.marklogic.model.management.Permission.java

License:Open Source License

public Permission(JsonObject jsonObject) {
    requireNonNull(jsonObject);/*w  w w .  j a  v  a  2 s  .c om*/

    ofNullable(jsonObject.getString(ROLE_NAME)).ifPresent(this::roleName);
    ofNullable(jsonObject.getJsonArray(CAPABILITIES)).ifPresent(this::capabilities);
}

From source file:org.etourdot.vertx.marklogic.model.management.Privilege.java

License:Open Source License

public Privilege(JsonObject jsonObject) {
    super(jsonObject);
    name(jsonObject.getString("privilege-name"));
    this.action = jsonObject.getString("action");
    this.kind = jsonObject.getString("kind");
    this.roles = jsonObject.getJsonArray("role");
}

From source file:org.etourdot.vertx.marklogic.model.management.Role.java

License:Open Source License

public Role(JsonObject jsonObject) {
    super(jsonObject);
    name(jsonObject.getString("role-name"));
    this.roles = jsonObject.getJsonArray("role");
    this.privileges = jsonObject.getJsonArray("privilege");
    this.permissions = jsonObject.getJsonArray("permission");
    this.collections = jsonObject.getJsonArray("collection");
}

From source file:org.etourdot.vertx.marklogic.model.management.User.java

License:Open Source License

public User(JsonObject jsonObject) {
    super(jsonObject);
    name(jsonObject.getString("user-name"));
    this.password = jsonObject.getString("password");
    this.roles = jsonObject.getJsonArray("role");
    this.permissions = jsonObject.getJsonArray("permission");
    this.collections = jsonObject.getJsonArray("collection");
}

From source file:org.etourdot.vertx.marklogic.model.options.RestApiOptions.java

License:Open Source License

public RestApiOptions(JsonObject jsonObject) {
    this();/*from w w  w.  ja  v  a  2s. c  o m*/
    requireNonNull(jsonObject);

    ofNullable(jsonObject.getValue("remove-content")).ifPresent(this::removeContent);
    ofNullable(jsonObject.getValue("remove-modules")).ifPresent(this::removeModules);
    ofNullable(jsonObject.getString("retrieve-instance")).ifPresent(this::retrieveInstance);
    ofNullable(jsonObject.getString("retrieve-database")).ifPresent(this::retrieveDatabase);
    ofNullable(jsonObject.getJsonArray("rest-apis")).ifPresent(this::restApis);
    ofNullable(jsonObject.getJsonObject("rest-api")).ifPresent(this::restApi);
}

From source file:org.etourdot.vertx.marklogic.model.options.SearchOptions.java

License:Open Source License

public SearchOptions(JsonObject jsonObject) {
    this();/*w w  w .j a  v  a2 s.  c  o  m*/
    requireNonNull(jsonObject);

    ofNullable(jsonObject.getJsonArray(CATEGORIES)).ifPresent(this::categories);
    ofNullable(jsonObject.getJsonArray(COLLECTIONS)).ifPresent(this::collections);
    ofNullable(jsonObject.getString(DIRECTORY)).ifPresent(this::directory);
    ofNullable(jsonObject.getLong(START)).ifPresent(this::start);
    ofNullable(jsonObject.getLong(PAGELEN)).ifPresent(this::pageLen);
    ofNullable(jsonObject.getString(VIEW)).ifPresent(this::view);
    ofNullable(jsonObject.getString(EXPRESSION)).ifPresent(this::expression);
    ofNullable(jsonObject.getJsonObject(QBE)).ifPresent(this::qbe);
    ofNullable(jsonObject.getJsonObject(STRUCT_QUERY)).ifPresent(this::structuredQuery);
}

From source file:org.folio.auth.login_module.impl.ModuleUserSource.java

@Override
public Future<UserResult> getUser(String username) {
    if (okapiUrl == null || vertx == null || requestToken == null || tenant == null) {
        throw new RuntimeException(
                "You must call setOkapiUrl, setVertx, setRequestToken and setTenant before calling this method");
    }// w  ww.  j a va2  s .  c o  m
    Future<UserResult> future = Future.future();
    HttpClientOptions options = new HttpClientOptions();
    options.setConnectTimeout(10);
    options.setIdleTimeout(10);
    HttpClient client = vertx.createHttpClient(options);
    JsonObject query = new JsonObject().put("username", username);
    String requestUrl = null;
    try {
        requestUrl = okapiUrl + "/users/?query=" + URLEncoder.encode(query.encode(), "UTF-8");
    } catch (Exception e) {
        future.fail(e);
        return future;
    }
    logger.debug("Requesting userdata from URL at " + requestUrl);
    client.getAbs(requestUrl, res -> {
        if (res.statusCode() != 200) {
            future.fail("Got status code " + res.statusCode());
        } else {
            res.bodyHandler(buf -> {
                logger.debug("Got content from server: " + buf.toString());
                JsonObject result = buf.toJsonObject();
                if (result.getInteger("total_records") > 1) {
                    future.fail("Not unique username");
                } else if (result.getInteger("total_records") == 0) {
                    UserResult userResult = new UserResult(username, false);
                    future.complete(userResult);
                } else {
                    UserResult userResult = new UserResult(username, true,
                            result.getJsonArray("users").getJsonObject(0).getBoolean("active"));
                    future.complete(userResult);
                }
            });
        }
    }).putHeader("X-Okapi-Tenant", tenant).putHeader("Authorization", "Bearer " + requestToken)
            .putHeader("Content-type", "application/json").putHeader("Accept", "application/json").end();
    return future;
}