Search in sources :

Example 76 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project Payara by payara.

the class RestCollectionResponseBody method populateJson.

@Override
protected void populateJson(JsonObject object) throws JsonException {
    super.populateJson(object);
    JsonArrayBuilder array = Json.createArrayBuilder();
    for (RestModel item : getItems()) {
        array.add(JsonUtil.getJsonValue(item));
    }
    object.put("items", array.build());
}
Also used : RestModel(org.glassfish.admin.rest.composite.RestModel) JsonArrayBuilder(javax.json.JsonArrayBuilder)

Example 77 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project Payara by payara.

the class ResponseBody method populateJson.

protected void populateJson(JsonObject object) throws JsonException {
    if (!getMessages().isEmpty()) {
        JsonArrayBuilder array = Json.createArrayBuilder();
        for (Message message : getMessages()) {
            array.add(message.toJson());
        }
        object.put("messages", array.build());
    }
    if (includeResourceLinks && !getResourceLinks().isEmpty()) {
        JsonArrayBuilder array = Json.createArrayBuilder();
        for (ResourceLink link : getResourceLinks()) {
            array.add(link.toJson());
        }
        object.put("resources", array.build());
    }
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder)

Example 78 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project Payara by payara.

the class OptionsResultJsonProvider method getRespresenationForMethodMetaData.

public JsonArray getRespresenationForMethodMetaData(OptionsResult proxy) {
    JsonArrayBuilder arr = Json.createArrayBuilder();
    Set<String> methods = proxy.methods();
    for (String methodName : methods) {
        try {
            MethodMetaData methodMetaData = proxy.getMethodMetaData(methodName);
            JsonObjectBuilder method = Json.createObjectBuilder();
            method.add(NAME, methodName);
            // method.put(QUERY_PARAMETERS, getQueryParams(methodMetaData));
            method.add(MESSAGE_PARAMETERS, getMessageParams(methodMetaData));
            arr.add(method.build());
        } catch (JsonException ex) {
            RestLogging.restLogger.log(Level.SEVERE, null, ex);
        }
    }
    return arr.build();
}
Also used : JsonException(javax.json.JsonException) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 79 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project Payara by payara.

the class RemoteRestAdminCommand method parseMetadata.

/**
 * Parse the JSon metadata for the command.
 *
 * @param str the string
 * @return the etag to compare the command cache model
 */
private CachedCommandModel parseMetadata(String str, String etag) {
    if (logger.isLoggable(Level.FINER)) {
        // XXX - assume "debug" == "FINER"
        logger.finer("------- RAW METADATA RESPONSE ---------");
        logger.log(Level.FINER, "ETag: {0}", etag);
        logger.finer(str);
        logger.finer("------- RAW METADATA RESPONSE ---------");
    }
    if (str == null) {
        return null;
    }
    try (JsonParser parser = Json.createParser(new StringReader(str))) {
        boolean sawFile = false;
        parser.next();
        JsonObject obj = parser.getObject();
        obj = obj.getJsonObject("command");
        CachedCommandModel cm = new CachedCommandModel(obj.getString("@name"), etag);
        cm.dashOk = parseBoolean(obj, "@unknown-options-are-operands", false);
        cm.managedJob = parseBoolean(obj, "@managed-job", false);
        cm.setUsage(obj.getString("usage", null));
        JsonValue optns = obj.get("option");
        if (!JsonValue.NULL.equals(optns) && optns != null) {
            JsonArray jsonOptions;
            if (optns instanceof JsonArray) {
                jsonOptions = (JsonArray) optns;
            } else {
                JsonArrayBuilder optBuilder = Json.createArrayBuilder();
                optBuilder.add(optns);
                jsonOptions = optBuilder.build();
            }
            for (int i = 0; i < jsonOptions.size(); i++) {
                JsonObject jsOpt = jsonOptions.getJsonObject(i);
                String type = jsOpt.getString("@type");
                ParamModelData opt = new ParamModelData(jsOpt.getString("@name"), typeOf(type), parseBoolean(jsOpt, "@optional", false), jsOpt.getString("@default", null), jsOpt.getString("@short", null), parseBoolean(jsOpt, "@obsolete", false), jsOpt.getString("@alias", null));
                opt.param._acceptableValues = jsOpt.getString("@acceptable-values", "");
                if ("PASSWORD".equals(type)) {
                    opt.param._password = true;
                    opt.prompt = jsOpt.getString("@prompt", null);
                    opt.promptAgain = jsOpt.getString("@prompt-again", null);
                } else if ("FILE".equals(type)) {
                    sawFile = true;
                }
                if (parseBoolean(jsOpt, "@primary", false)) {
                    opt.param._primary = true;
                }
                if (parseBoolean(jsOpt, "@multiple", false)) {
                    if (opt.type == File.class) {
                        opt.type = File[].class;
                    } else {
                        opt.type = List.class;
                    }
                    opt.param._multiple = true;
                }
                cm.add(opt);
            }
        }
        if (sawFile) {
            cm.add(new ParamModelData("upload", Boolean.class, true, null));
            addedUploadOption = true;
            cm.setAddedUploadOption(true);
        }
        if (notify) {
            cm.add(new ParamModelData("notify", Boolean.class, false, "false"));
        }
        this.usage = cm.getUsage();
        return cm;
    } catch (Exception ex) {
        logger.log(Level.SEVERE, "Can not parse command metadata", ex);
        return null;
    }
}
Also used : JsonValue(javax.json.JsonValue) JsonObject(javax.json.JsonObject) ParamModelData(com.sun.enterprise.admin.util.CommandModelData.ParamModelData) CachedCommandModel(com.sun.enterprise.admin.util.CachedCommandModel) SSLException(javax.net.ssl.SSLException) JsonArray(javax.json.JsonArray) JsonArrayBuilder(javax.json.JsonArrayBuilder) SmartFile(com.sun.enterprise.universal.io.SmartFile) JsonParser(javax.json.stream.JsonParser)

Example 80 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project Payara by payara.

the class OidcProvider method userinfoEndpoint.

@Path("/userinfo")
@Produces(APPLICATION_JSON)
@GET
public Response userinfoEndpoint(@HeaderParam(AUTHORIZATION_HEADER) String authorizationHeader) {
    String accessToken = authorizationHeader.substring(BEARER_TYPE.length() + 1);
    ResponseBuilder builder;
    JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();
    if (ACCESS_TOKEN_VALUE.equals(accessToken)) {
        builder = Response.ok();
        jsonBuilder.add(SUBJECT_IDENTIFIER, getSubject()).add("name", "Gaurav").add("family_name", "Gupta   ").add("given_name", "Gaurav Gupta").add("profile", "https://abc.com/+jGauravGupta").add("picture", "https://abc.com/photo.jpg").add("email", "gaurav.gupta.jc@gmail.com").add("email_verified", true).add("gender", "male").add("locale", "en");
        if (rolesInUserInfoEndpoint) {
            JsonArrayBuilder groupsBuilder = Json.createArrayBuilder();
            userGroups.forEach(g -> {
                groupsBuilder.add(g);
            });
            jsonBuilder.add(OpenIdConstant.GROUPS, groupsBuilder);
        }
    } else {
        jsonBuilder.add(ERROR_PARAM, "invalid_access_token");
        builder = Response.serverError();
    }
    return builder.entity(jsonBuilder.build().toString()).build();
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

JsonArrayBuilder (javax.json.JsonArrayBuilder)177 JsonObjectBuilder (javax.json.JsonObjectBuilder)103 JsonObject (javax.json.JsonObject)36 Map (java.util.Map)29 Path (javax.ws.rs.Path)26 GET (javax.ws.rs.GET)24 HashMap (java.util.HashMap)19 JsonArray (javax.json.JsonArray)18 ArrayList (java.util.ArrayList)15 List (java.util.List)15 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)12 IOException (java.io.IOException)12 Dataverse (edu.harvard.iq.dataverse.Dataverse)10 Dataset (edu.harvard.iq.dataverse.Dataset)9 User (edu.harvard.iq.dataverse.authorization.users.User)9 JsonValue (javax.json.JsonValue)9 StringWriter (java.io.StringWriter)8 JsonString (javax.json.JsonString)7 Date (java.util.Date)6 JsonException (javax.json.JsonException)6