Example usage for com.google.gson JsonObject addProperty

List of usage examples for com.google.gson JsonObject addProperty

Introduction

In this page you can find the example usage for com.google.gson JsonObject addProperty.

Prototype

public void addProperty(String property, Character value) 

Source Link

Document

Convenience method to add a char member.

Usage

From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.executors.AgentStatusReportExecutor.java

License:Apache License

public GoPluginApiResponse execute() throws Exception {
    String elasticAgentId = request.getElasticAgentId();
    JobIdentifier jobIdentifier = request.getJobIdentifier();
    LOG.info(String.format("[status-report] Generating status report for agent: %s with job: %s",
            elasticAgentId, jobIdentifier));

    try {/*  w  w w . ja  v  a 2 s.c  o  m*/
        agentInstances.refreshAll(pluginRequest);
        final DockerClient dockerClient = dockerClientFactory.docker(pluginRequest.getPluginSettings());
        Service dockerService = findService(elasticAgentId, jobIdentifier, dockerClient);

        DockerServiceElasticAgent elasticAgent = DockerServiceElasticAgent.fromService(dockerService,
                dockerClient);
        final String statusReportView = builder.build(builder.getTemplate("agent-status-report.template.ftlh"),
                elasticAgent);

        JsonObject responseJSON = new JsonObject();
        responseJSON.addProperty("view", statusReportView);

        return DefaultGoPluginApiResponse.success(responseJSON.toString());
    } catch (Exception e) {
        return StatusReportGenerationErrorHandler.handle(builder, e);
    }
}

From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.executors.GetPluginSettingsIconExecutor.java

License:Apache License

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("content-type", "image/png");
    jsonObject.addProperty("data", Base64.encodeBase64String(Util.readResourceBytes("/docker-swarm.png")));
    DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200,
            GSON.toJson(jsonObject));//from w  w  w. j a  va  2s. c om
    return defaultGoPluginApiResponse;

}

From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.executors.StatusReportExecutor.java

License:Apache License

public GoPluginApiResponse execute() {
    try {//from   w w  w  . j  a va  2  s  .c om
        LOG.debug("[status-report] Generating status report.");
        agentInstances.refreshAll(pluginRequest);
        final DockerClient dockerClient = dockerClientFactory.docker(pluginRequest.getPluginSettings());
        final SwarmCluster swarmCluster = new SwarmCluster(dockerClient);
        final Template template = statusReportViewBuilder.getTemplate("status-report.template.ftlh");
        final String statusReportView = statusReportViewBuilder.build(template, swarmCluster);

        JsonObject responseJSON = new JsonObject();
        responseJSON.addProperty("view", statusReportView);

        return DefaultGoPluginApiResponse.success(responseJSON.toString());
    } catch (Exception e) {
        return StatusReportGenerationErrorHandler.handle(statusReportViewBuilder, e);
    }
}

From source file:cd.go.contrib.elasticagents.dockerswarm.elasticagent.reports.StatusReportGenerationErrorHandler.java

License:Apache License

public static GoPluginApiResponse handle(PluginStatusReportViewBuilder builder, Exception e) {
    try {/*from www  . j  ava2  s .  c  o  m*/
        LOG.error(format("Error while generating status report: {0}", e.getMessage()), e);
        final Template template = builder.getTemplate("error.template.ftlh");
        final String errorView = builder.build(template, new StatusReportGenerationError(e));

        final JsonObject responseJSON = new JsonObject();
        responseJSON.addProperty("view", errorView);

        return DefaultGoPluginApiResponse.success(responseJSON.toString());
    } catch (Exception ex) {
        LOG.error(format("Failed to generate error report: {0}", e.getMessage()), e);
        return DefaultGoPluginApiResponse.error(format("Failed to generate error report: {0}.", e.toString()));
    }
}

From source file:cd.go.contrib.elasticagents.marathon.executors.GetPluginSettingsIconExecutor.java

License:Apache License

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("content_type", "image/svg+xml");
    jsonObject.addProperty("data", BaseEncoding.base64().encode(Util.readResourceBytes("/plugin-icon.svg")));
    return new DefaultGoPluginApiResponse(200, GSON.toJson(jsonObject));
}

From source file:cd.go.contrib.elasticagents.marathon.executors.GetProfileViewExecutor.java

License:Apache License

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("template", Util.readResource("/profile.template.html"));
    return new DefaultGoPluginApiResponse(200, GSON.toJson(jsonObject));
}

From source file:cd.go.contrib.elasticagents.marathon.executors.GetViewRequestExecutor.java

License:Apache License

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("template", Util.readResource("/plugin-settings.template.html"));
    return new DefaultGoPluginApiResponse(200, GSON.toJson(jsonObject));
}

From source file:cd.go.contrib.elasticagents.openstack.executors.GetPluginSettingsIconExecutor.java

License:Apache License

@Override
public GoPluginApiResponse execute() throws Exception {
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("content_type", "image/svg+xml");
    jsonObject.addProperty("data",
            Base64.encodeBase64String(Util.readResourceBytes("/openstack-logo-vertical" + ".svg")));
    DefaultGoPluginApiResponse defaultGoPluginApiResponse = new DefaultGoPluginApiResponse(200,
            GSON.toJson(jsonObject));/*from w w w  . j a  v a 2  s. com*/
    return defaultGoPluginApiResponse;

}

From source file:cf.adriantodt.David.modules.db.DBModule.java

License:LGPL

private DBModule() {
    mainConfig = ConfigUtils.get("main",
            ImmutableMap.<String, java.util.function.Predicate<JsonElement>>builder()
                    .put("ownerID", ConfigUtils::isJsonString).put("token", ConfigUtils::isJsonString).build(),
            () -> {/*w  ww .  java  2 s  .c  o  m*/
                JsonObject object = new JsonObject();
                object.add("ownerID", null);
                object.add("token", null);
                return object;
            }, false, true);

    JsonObject dbConfig = ConfigUtils.get("db",
            ImmutableMap.<String, java.util.function.Predicate<JsonElement>>builder()
                    .put("hostname", ConfigUtils::isJsonString)
                    .put("port", element -> ConfigUtils.isJsonNumber(element) && element.getAsInt() != 0)
                    .build(),
            () -> {
                JsonObject object = new JsonObject();
                object.addProperty("hostname", "localhost");
                object.addProperty("port", 28015);
                return object;
            }, true, true);

    conn = r.connection().hostname(dbConfig.get("hostname").getAsString()).port(dbConfig.get("port").getAsInt())
            .db("bot").connect();
}

From source file:cf.adriantodt.David.modules.rest.GetController.java

License:LGPL

public static JsonElement toJson(Guild g) {
    JsonObject guild = new JsonObject();
    guild.addProperty("id", g.getId());
    guild.addProperty("name", g.getName());
    guild.addProperty("avatar", g.getIconUrl());
    guild.addProperty("vip", GuildModule.fromDiscord(g).getFlag("vip"));
    return guild;
}