Example usage for javax.json Json createObjectBuilder

List of usage examples for javax.json Json createObjectBuilder

Introduction

In this page you can find the example usage for javax.json Json createObjectBuilder.

Prototype

public static JsonObjectBuilder createObjectBuilder() 

Source Link

Document

Creates a JSON object builder

Usage

From source file:be.fedict.dcat.datagovbe.Drupal.java

/**
 * Create a JsonArrayBuilder with a list of Drupal text fields
 * /*from   w  w  w . j  a va 2s. com*/
 * @param l list of URLs (as string)
 * @return JsonArrayBuilder containing text fields JSON objects
 */
private static JsonArrayBuilder fieldArrayJson(List<String> l) {
    JsonArrayBuilder builder = Json.createArrayBuilder();
    for (String s : l) {
        builder.add(Json.createObjectBuilder().add(Drupal.VALUE, s));
    }
    return builder;
}

From source file:example.SimpleChaincode.java

private String newErrorJson(final Throwable throwable, final String message, final Object... args) {
    final JsonObjectBuilder builder = Json.createObjectBuilder();
    if (message != null)
        builder.add("Error", String.format(message, args));
    if (throwable != null) {
        final StringWriter buffer = new StringWriter();
        throwable.printStackTrace(new PrintWriter(buffer));
        builder.add("Stacktrace", buffer.toString());
    }/* w  ww. j ava  2  s . c o  m*/
    return builder.build().toString();
}

From source file:com.yoshio3.azuread.graph.GraphAPIImpl.java

public ADUserMemberOfGroups getMemberOfGroup(String userID) {
    String graphURL = String.format("https://%s/%s/users/%s/getMemberGroups", GRAPH_SEVER, tenant, userID);
    JsonObject model = Json.createObjectBuilder().add("securityEnabledOnly", "false").build();
    StringWriter stWriter = new StringWriter();
    try (JsonWriter jsonWriter = Json.createWriter(stWriter)) {
        jsonWriter.writeObject(model);//from  w  w w .  jav a 2  s.  co  m
    }
    String jsonData = stWriter.toString();

    Response response = jaxrsClient.target(graphURL).request().header("Host", GRAPH_SEVER)
            .header("Accept", "application/json, text/plain, */*").header("Content-Type", "application/json")
            .header("api-version", "1.6").header("Authorization", authString).post(Entity.json(jsonData));
    ADUserMemberOfGroups memberOfGrups = response.readEntity(ADUserMemberOfGroups.class);
    LOGGER.log(Level.INFO, memberOfGrups.toString());
    return memberOfGrups;
}

From source file:io.bitgrillr.gocddockerexecplugin.DockerExecPluginTest.java

@Test
public void handleExecute() throws Exception {
    UnitTestUtils.mockJobConsoleLogger();
    PowerMockito.mockStatic(DockerUtils.class);
    PowerMockito.doNothing().when(DockerUtils.class);
    DockerUtils.pullImage(anyString());/*from  w  ww . j  a  va 2s.  co m*/
    when(DockerUtils.createContainer(anyString(), anyString(), anyMap())).thenReturn("123");
    when(DockerUtils.getContainerUid(anyString())).thenReturn("4:5");
    when(DockerUtils.execCommand(anyString(), any(), any())).thenReturn(0);
    PowerMockito.doNothing().when(DockerUtils.class);
    DockerUtils.removeContainer(anyString());
    when(DockerUtils.getCommandString(anyString(), any())).thenCallRealMethod();
    PowerMockito.mockStatic(SystemHelper.class);
    when(SystemHelper.getSystemUid()).thenReturn("7:8");

    DefaultGoPluginApiRequest request = new DefaultGoPluginApiRequest(null, null, "execute");
    JsonObject requestBody = Json.createObjectBuilder()
            .add("config", Json.createObjectBuilder()
                    .add("IMAGE", Json.createObjectBuilder().add("value", "ubuntu:latest").build())
                    .add("COMMAND", Json.createObjectBuilder().add("value", "echo").build())
                    .add("ARGUMENTS", Json.createObjectBuilder().add("value", "Hello\nWorld").build()).build())
            .add("context", Json.createObjectBuilder().add("workingDirectory", "pipelines/test")
                    .add("environmentVariables",
                            Json.createObjectBuilder().add("TEST1", "value1").add("TEST2", "value2").build())
                    .build())
            .build();
    request.setRequestBody(requestBody.toString());
    final GoPluginApiResponse response = new DockerExecPlugin().handle(request);

    PowerMockito.verifyStatic(DockerUtils.class);
    DockerUtils.pullImage("ubuntu:latest");
    PowerMockito.verifyStatic(DockerUtils.class);
    DockerUtils.createContainer("ubuntu:latest",
            Paths.get(System.getProperty("user.dir"), "pipelines/test").toAbsolutePath().toString(),
            Stream.<Map.Entry<String, String>>builder().add(new SimpleEntry<>("TEST1", "value1"))
                    .add(new SimpleEntry<>("TEST2", "value2")).build()
                    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
    PowerMockito.verifyStatic(DockerUtils.class);
    DockerUtils.getContainerUid("123");
    PowerMockito.verifyStatic(DockerUtils.class);
    DockerUtils.execCommand("123", "root", "chown", "-R", "4:5", ".");
    PowerMockito.verifyStatic(DockerUtils.class);
    DockerUtils.execCommand("123", null, "echo", "Hello", "World");
    PowerMockito.verifyStatic(DockerUtils.class);
    DockerUtils.execCommand("123", "root", "chown", "-R", "7:8", ".");
    PowerMockito.verifyStatic(DockerUtils.class);
    DockerUtils.removeContainer("123");
    assertEquals("Expected 2xx response", DefaultGoPluginApiResponse.SUCCESS_RESPONSE_CODE,
            response.responseCode());
    final JsonObject responseBody = Json.createReader(new StringReader(response.responseBody())).readObject();
    assertEquals("Expected success", Boolean.TRUE, responseBody.getBoolean("success"));
    assertEquals("Wrong message", "Command 'echo 'Hello' 'World'' completed with status 0",
            Json.createReader(new StringReader(response.responseBody())).readObject().getString("message"));
}

From source file:concretis.web.rest.CommentRestService.java

private Response okJsonResponse(long commentId) {
    JsonObject result = Json.createObjectBuilder().add("commentId", commentId).build();
    return Response.ok(result).build();
}

From source file:co.runrightfast.vertx.core.eventbus.MessageConsumerConfig.java

public JsonObject toJson() {
    return Json.createObjectBuilder().add("addressMessageMapping", addressMessageMapping.toJson())
            .add("local", local).add("maxBufferedMessages", maxBufferedMessages).build();
}

From source file:be.fedict.dcat.datagovbe.Drupal.java

/**
 * Get Drupal taxonomy terms as JSON Array
 *
 * @param terms//  w  ww .  j a va  2  s.  co m
 * @return JsonArrayBuilder
 */
private static JsonArrayBuilder arrayTermsJson(Collection<String> terms) {
    JsonArrayBuilder arr = Json.createArrayBuilder();

    for (String term : terms) {
        if (term.startsWith(Drupal.TAXO_PREFIX)) {
            String id = term.substring(term.lastIndexOf('/') + 1);
            arr.add(Json.createObjectBuilder().add(Drupal.ID, id).build());
        }
    }
    return arr;
}

From source file:au.org.ands.vocabs.toolkit.db.AccessPointUtils.java

/** Update the portal's format setting for a file access point.
 * @param ap the access point/*from   w w w  .j a v  a2 s  .  co m*/
 * @param newFormat the access point's new format setting,
 * or null otherwise.
 */
public static void updateFormat(final AccessPoint ap, final String newFormat) {
    if (!"file".equals(ap.getType())) {
        // Not the right type.
        return;
    }
    JsonNode dataJson = TaskUtils.jsonStringToTree(ap.getPortalData());
    JsonObjectBuilder jobPortal = Json.createObjectBuilder();
    Iterator<Entry<String, JsonNode>> dataJsonIterator = dataJson.fields();
    while (dataJsonIterator.hasNext()) {
        Entry<String, JsonNode> entry = dataJsonIterator.next();
        jobPortal.add(entry.getKey(), entry.getValue().asText());
    }
    jobPortal.add("format", newFormat);
    ap.setPortalData(jobPortal.build().toString());
    updateAccessPoint(ap);
}

From source file:no.sintef.jarfter.PostgresqlInteractor.java

public JsonObject selectAllTransfomations(String filter_uri) throws JarfterException {
    checkConnection();/*from   www.  ja  v  a 2s .co  m*/

    String table = "transformations";
    String uri = "uri";
    String name = "name";
    String metadata = "metadata";
    String clojure = "clojure";
    JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
    try {
        PreparedStatement st = conn.prepareStatement("SELECT " + uri + ", " + name + ", " + metadata + ", "
                + clojure + " FROM transformations WHERE uri ~ ?;");
        if (filter_uri == null) {
            st.setString(1, ".*");
        } else {
            st.setString(1, filter_uri);
        }
        log("selectAllTransfomations - calling executeQuery");
        ResultSet rs = st.executeQuery();
        while (rs.next()) {
            JsonObjectBuilder job = Json.createObjectBuilder();
            job.add(uri, rs.getString(uri));
            job.add(name, rs.getString(name));
            job.add(metadata, rs.getString(metadata));
            job.add(clojure, rs.getString(clojure));
            jsonArrayBuilder.add(job.build());
        }

        rs.close();
        st.close();
    } catch (SQLException sqle) {
        log("selectAllTransformations - got SQLException");
        error(sqle);
        throw new JarfterException(JarfterException.Error.SQL_UNKNOWN_ERROR, sqle.getLocalizedMessage());
    }
    return Json.createObjectBuilder().add(table, jsonArrayBuilder.build()).build();
}

From source file:co.runrightfast.vertx.demo.testHarness.jmx.DemoMXBeanImpl.java

void handleGetVerticleDeploymentsResponse(final Message<GetVerticleDeployments.Response> responseMessage) {
    final GetVerticleDeployments.Response response = responseMessage.body();
    final JsonObject json = Json.createObjectBuilder().add("headers", toJsonObject(responseMessage.headers()))
            .add("body", ProtobufUtils.protobuMessageToJson(response)).build();
    log.info(JsonUtils.toVertxJsonObject(json).encodePrettily());
}