Search in sources :

Example 1 with JsonObject

use of org.jboss.hal.js.JsonObject in project console by hal.

the class UploadPayloadProcessor method extractFailure.

private String extractFailure(final JsonObject jsonResponse) {
    String failure = UNKNOWN;
    JsonType type = jsonResponse.get(FAILURE_DESCRIPTION).getType();
    if (type == JsonType.STRING) {
        failure = jsonResponse.getString(FAILURE_DESCRIPTION);
    } else if (type == JsonType.OBJECT) {
        JsonObject failureObject = jsonResponse.getObject(FAILURE_DESCRIPTION);
        for (String key : failureObject.keys()) {
            if (key.contains(FAILURE) && failureObject.getString(key) != null) {
                failure = failureObject.getString(key);
                break;
            }
        }
    }
    return failure;
}
Also used : JsonType(org.jboss.hal.js.JsonType) JsonObject(org.jboss.hal.js.JsonObject)

Example 2 with JsonObject

use of org.jboss.hal.js.JsonObject in project console by hal.

the class ReadChildrenResult method asJson.

JsonObject asJson() {
    JsonObject object = JsonObject.create();
    object.put(NAME, name);
    JsonArray addresses = JsonArray.create();
    int i = 0;
    for (Map.Entry<String, String> entry : this.addresses.entrySet()) {
        JsonObject keyValue = JsonObject.create();
        keyValue.put(KEY, entry.getKey());
        keyValue.put(VALUE, entry.getValue());
        addresses.set(i, keyValue);
        i++;
    }
    object.put(ADDRESSES, addresses);
    return object;
}
Also used : JsonArray(org.jboss.hal.js.JsonArray) JsonObject(org.jboss.hal.js.JsonObject) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with JsonObject

use of org.jboss.hal.js.JsonObject in project console by hal.

the class ExtensionRegistry method verifyMetadata.

@JsIgnore
public void verifyMetadata(String url, MetadataCallback metadataCallback) {
    SafeUri safeUrl = UriUtils.fromString(url);
    XMLHttpRequest xhr = new XMLHttpRequest();
    xhr.onload = event -> {
        int status = (int) xhr.status;
        if (status >= 200 && status < 400) {
            String responseText = xhr.responseText;
            if (Strings.isNullOrEmpty(responseText)) {
                // 415 - Unsupported Media Type
                metadataCallback.result(415, null);
            } else {
                JsonObject extensionJson = Json.parse(responseText);
                metadataCallback.result(status, extensionJson);
            }
        } else {
            metadataCallback.result(status, null);
        }
    };
    // NON-NLS
    xhr.addEventListener("error", event -> metadataCallback.result(503, null), false);
    xhr.open(GET.name(), safeUrl.asString(), true);
    xhr.send();
}
Also used : SafeUri(com.google.gwt.safehtml.shared.SafeUri) JsonObject(org.jboss.hal.js.JsonObject) XMLHttpRequest(elemental2.dom.XMLHttpRequest) Point(org.jboss.hal.core.extension.Extension.Point) JsIgnore(jsinterop.annotations.JsIgnore)

Example 4 with JsonObject

use of org.jboss.hal.js.JsonObject in project console by hal.

the class ReadChildrenRenderer method render.

@Override
public String render(JsonObject item, String query) {
    String name = item.get(NAME).asString();
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.appendHtmlConstant("<div class=\"" + autocompleteSuggestion + "\" data-val=\"" + name + "\">");
    JsonArray addresses = item.getArray(ADDRESSES);
    if (addresses.length() != 0) {
        for (int i = 0; i < addresses.length(); i++) {
            JsonObject keyValue = addresses.getObject(i);
            builder.appendHtmlConstant("<span title=\"" + keyValue.getString(KEY) + "\" class=\"" + address + "\">");
            builder.appendEscaped(keyValue.getString(VALUE));
            builder.appendEscaped(" / ");
            builder.appendHtmlConstant("</span>");
        }
    }
    // NON-NLS
    builder.appendHtmlConstant(highlight(query).replace(name, "<b>$1</b>")).appendHtmlConstant("</div>");
    return builder.toSafeHtml().asString();
}
Also used : JsonArray(org.jboss.hal.js.JsonArray) JsonObject(org.jboss.hal.js.JsonObject) SafeHtmlBuilder(com.google.gwt.safehtml.shared.SafeHtmlBuilder)

Example 5 with JsonObject

use of org.jboss.hal.js.JsonObject in project console by hal.

the class EndpointManager method checkKeycloakAdapter.

private void checkKeycloakAdapter(String baseUrl, Consumer<String> kcExistsCallback, Callback wildflyCallback) {
    String keycloakAdapterUrl = getKeycloakAdapterUrl(baseUrl);
    XMLHttpRequest xhr = new XMLHttpRequest();
    xhr.onload = event -> {
        int status = xhr.status;
        if (status == 200) {
            JsonObject kcConfig = Json.parse(xhr.responseText);
            String keycloakServerJsUrl = kcConfig.getString(AUTH_SERVER_URL) + "/js/keycloak.js";
            kcExistsCallback.accept(keycloakServerJsUrl);
        } else {
            logger.error("Keycloak adapter '{}' doesn't exist - status: {}", keycloakAdapterUrl, status);
            wildflyCallback.execute();
        }
    };
    xhr.addEventListener("error", event -> {
        logger.error("Keycloak adapter '{}' failed: {}", keycloakAdapterUrl, event);
        wildflyCallback.execute();
    });
    xhr.open(GET.name(), keycloakAdapterUrl, true);
    xhr.send();
}
Also used : JsonObject(org.jboss.hal.js.JsonObject) XMLHttpRequest(elemental2.dom.XMLHttpRequest)

Aggregations

JsonObject (org.jboss.hal.js.JsonObject)6 XMLHttpRequest (elemental2.dom.XMLHttpRequest)2 JsonArray (org.jboss.hal.js.JsonArray)2 SafeHtmlBuilder (com.google.gwt.safehtml.shared.SafeHtmlBuilder)1 SafeUri (com.google.gwt.safehtml.shared.SafeUri)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 JsIgnore (jsinterop.annotations.JsIgnore)1 Point (org.jboss.hal.core.extension.Extension.Point)1 JsonType (org.jboss.hal.js.JsonType)1