Search in sources :

Example 21 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project microservice_framework by CJSCommonPlatform.

the class DefaultJsonValidationLoggerHelper method buildResponse.

private JsonObject buildResponse(final ValidationException validationException) {
    final JsonObjectBuilder builder = createObjectBuilder();
    Optional.ofNullable(validationException.getMessage()).ifPresent(message -> builder.add("message", message));
    Optional.ofNullable(validationException.getViolatedSchema()).ifPresent(schema -> builder.add("violatedSchema", getSchemaName(schema)));
    Optional.ofNullable(validationException.getPointerToViolation()).ifPresent(violation -> builder.add("violation", violation));
    final JsonArrayBuilder arrayBuilder = createArrayBuilder();
    validationException.getCausingExceptions().forEach(exception -> arrayBuilder.add(buildResponse(exception)));
    builder.add("causingExceptions", arrayBuilder.build());
    return builder.build();
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 22 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project microservice_framework by CJSCommonPlatform.

the class DefaultJsonEnvelope method toString.

@Override
public String toString() {
    final JsonObjectBuilder builder = Json.createObjectBuilder();
    if (metadata != null) {
        builder.add("id", String.valueOf(metadata.id())).add("name", metadata.name());
        metadata.clientCorrelationId().ifPresent(s -> builder.add(CORRELATION, s));
        metadata.sessionId().ifPresent(s -> builder.add(SESSION_ID, s));
        metadata.userId().ifPresent(s -> builder.add(USER_ID, s));
        final JsonArrayBuilder causationBuilder = Json.createArrayBuilder();
        final List<UUID> causes = metadata.causation();
        if (causes != null) {
            metadata.causation().forEach(uuid -> causationBuilder.add(String.valueOf(uuid)));
        }
        builder.add("causation", causationBuilder);
    }
    return builder.build().toString();
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) UUID(java.util.UUID)

Example 23 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project fabric-sdk-java by hyperledger.

the class RegistrationRequest method toJsonObject.

// Convert the registration request to a JSON object
JsonObject toJsonObject() {
    JsonObjectBuilder ob = Json.createObjectBuilder();
    ob.add("id", enrollmentID);
    ob.add("type", type);
    if (this.secret != null) {
        ob.add("secret", secret);
    }
    if (null != maxEnrollments) {
        ob.add("max_enrollments", maxEnrollments);
    }
    if (affiliation != null) {
        ob.add("affiliation", affiliation);
    }
    JsonArrayBuilder ab = Json.createArrayBuilder();
    for (Attribute attr : attrs) {
        ab.add(attr.toJsonObject());
    }
    if (caName != null) {
        ob.add(HFCAClient.FABRIC_CA_REQPROP, caName);
    }
    ob.add("attrs", ab.build());
    return ob.build();
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 24 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project Manga by herrlock.

the class MDObject method handle.

@Override
public void handle(final String target, final Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException {
    logger.traceEntry();
    JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
    for (Entry<UUID, MDObject> entry : this.dlContext.entrySet()) {
        UUID key = entry.getKey();
        MDObject value = entry.getValue();
        MDownloader mdownloader = value.getMdownloader();
        arrayBuilder.add(// 
        Json.createObjectBuilder().add("uuid", // 
        key.toString()).add("url", // 
        value.getUrl()).add("started", // 
        mdownloader.getStarted()).add("progress", // 
        mdownloader.getProgress()).add("maxProgress", mdownloader.getMaxProgress()));
    }
    Json.createWriter(response.getOutputStream()).write(arrayBuilder.build());
    response.setContentType(MediaType.JSON_UTF_8.toString());
    response.setStatus(HttpServletResponse.SC_OK);
    baseRequest.setHandled(true);
}
Also used : MDownloader(de.herrlock.manga.downloader.MDownloader) JsonArrayBuilder(javax.json.JsonArrayBuilder) UUID(java.util.UUID)

Example 25 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project dataverse by IQSS.

the class UtilIT method createDataverse.

static Response createDataverse(String alias, String category, String apiToken) {
    JsonArrayBuilder contactArrayBuilder = Json.createArrayBuilder();
    contactArrayBuilder.add(Json.createObjectBuilder().add("contactEmail", getEmailFromUserName(getRandomIdentifier())));
    JsonArrayBuilder subjectArrayBuilder = Json.createArrayBuilder();
    subjectArrayBuilder.add("Other");
    JsonObject dvData = Json.createObjectBuilder().add("alias", alias).add("name", alias).add("dataverseContacts", contactArrayBuilder).add("dataverseSubjects", subjectArrayBuilder).add(category != null ? "dataverseType" : "notTheKeyDataverseType", category != null ? category : "whatever").build();
    Response createDataverseResponse = given().body(dvData.toString()).contentType(ContentType.JSON).when().post("/api/dataverses/:root?key=" + apiToken);
    return createDataverseResponse;
}
Also used : Response(com.jayway.restassured.response.Response) JsonObject(javax.json.JsonObject) JsonArrayBuilder(javax.json.JsonArrayBuilder)

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