Search in sources :

Example 86 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project cxf by apache.

the class BookJsonStore method bookToJson.

private JsonObject bookToJson(final Book book) {
    final JsonObjectBuilder builder = Json.createObjectBuilder().add("id", book.getId()).add("name", book.getName());
    if (!book.getChapters().isEmpty()) {
        final JsonArrayBuilder chapters = Json.createArrayBuilder();
        for (final BookChapter chapter : book.getChapters()) {
            chapters.add(Json.createObjectBuilder().add("id", chapter.getId()).add("title", chapter.getTitle()));
        }
        builder.add("chapters", chapters);
    }
    return builder.build();
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 87 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project quickstart by wildfly.

the class TokenUtil method generateJWT.

public static String generateJWT(final String principal, final String birthdate, final String... groups) throws Exception {
    PrivateKey privateKey = loadPrivateKey("private.pem");
    JWSSigner signer = new RSASSASigner(privateKey);
    JsonArrayBuilder groupsBuilder = Json.createArrayBuilder();
    for (String group : groups) {
        groupsBuilder.add(group);
    }
    long currentTime = System.currentTimeMillis() / 1000;
    JsonObjectBuilder claimsBuilder = Json.createObjectBuilder().add("sub", principal).add("upn", principal).add("iss", "quickstart-jwt-issuer").add("aud", "jwt-audience").add("groups", groupsBuilder.build()).add("birthdate", birthdate).add("jti", UUID.randomUUID().toString()).add("iat", currentTime).add("exp", currentTime + 14400);
    JWSObject jwsObject = new JWSObject(new JWSHeader.Builder(JWSAlgorithm.RS256).type(new JOSEObjectType("jwt")).keyID("Test Key").build(), new Payload(claimsBuilder.build().toString()));
    jwsObject.sign(signer);
    return jwsObject.serialize();
}
Also used : JOSEObjectType(com.nimbusds.jose.JOSEObjectType) PrivateKey(java.security.PrivateKey) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) RSASSASigner(com.nimbusds.jose.crypto.RSASSASigner) Payload(com.nimbusds.jose.Payload) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) JWSObject(com.nimbusds.jose.JWSObject) JWSSigner(com.nimbusds.jose.JWSSigner)

Example 88 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project opentheso by miledrousset.

the class Rest_new method getlistAllPublicTheso__.

private String getlistAllPublicTheso__(HikariDataSource ds) {
    ThesaurusHelper thesaurusHelper = new ThesaurusHelper();
    List<String> listPublicTheso = thesaurusHelper.getAllIdOfThesaurus(ds, false);
    NodeThesaurus nodeThesaurus;
    String datasJson;
    JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder();
    for (String idTheso : listPublicTheso) {
        JsonObjectBuilder job = Json.createObjectBuilder();
        job.add("idTheso", idTheso);
        JsonArrayBuilder jsonArrayBuilderLang = Json.createArrayBuilder();
        nodeThesaurus = thesaurusHelper.getNodeThesaurus(ds, idTheso);
        for (Thesaurus thesaurus : nodeThesaurus.getListThesaurusTraduction()) {
            JsonObjectBuilder jobLang = Json.createObjectBuilder();
            jobLang.add("lang", thesaurus.getLanguage());
            jobLang.add("title", thesaurus.getTitle());
            jsonArrayBuilderLang.add(jobLang.build());
        }
        if (!nodeThesaurus.getListThesaurusTraduction().isEmpty()) {
            job.add("labels", jsonArrayBuilderLang.build());
        }
        jsonArrayBuilder.add(job.build());
    }
    datasJson = jsonArrayBuilder.build().toString();
    if (datasJson != null)
        return datasJson;
    else
        return null;
}
Also used : Thesaurus(mom.trd.opentheso.bdd.datas.Thesaurus) NodeThesaurus(mom.trd.opentheso.bdd.helper.nodes.thesaurus.NodeThesaurus) ThesaurusHelper(mom.trd.opentheso.bdd.helper.ThesaurusHelper) NodeThesaurus(mom.trd.opentheso.bdd.helper.nodes.thesaurus.NodeThesaurus) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 89 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project jersey by jersey.

the class DocumentFilteringResource method filter.

@POST
public JsonArray filter(final JsonArray properties) {
    final JsonArrayBuilder documents = Json.createArrayBuilder();
    final List<JsonString> propertyList = properties.getValuesAs(JsonString.class);
    for (final JsonObject jsonObject : DocumentStorage.getAll()) {
        final JsonObjectBuilder documentBuilder = Json.createObjectBuilder();
        for (final JsonString property : propertyList) {
            final String key = property.getString();
            if (jsonObject.containsKey(key)) {
                documentBuilder.add(key, jsonObject.get(key));
            }
        }
        final JsonObject document = documentBuilder.build();
        if (!document.isEmpty()) {
            documents.add(document);
        }
    }
    return documents.build();
}
Also used : JsonObject(javax.json.JsonObject) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonString(javax.json.JsonString) JsonString(javax.json.JsonString) JsonObjectBuilder(javax.json.JsonObjectBuilder) POST(javax.ws.rs.POST)

Example 90 with JsonArrayBuilder

use of javax.json.JsonArrayBuilder in project torodb by torodb.

the class ToroIndexConverter method to.

@Override
public String to(NamedToroIndex userObject) {
    JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
    objectBuilder.add(NAME_KEY, userObject.getName());
    if (userObject.isUnique()) {
        objectBuilder.add(UNIQUE_KEY, true);
    }
    JsonArrayBuilder attsBuilder = Json.createArrayBuilder();
    JsonArrayBuilder descBuilder = Json.createArrayBuilder();
    int attPosition = 0;
    boolean hasDescending = false;
    for (Map.Entry<AttributeReference, IndexType> entry : userObject.getAttributes().entrySet()) {
        attsBuilder.add(entry.getKey().toString());
        if (IndexType.desc.equals(entry.getValue())) {
            descBuilder.add(attPosition);
            hasDescending = true;
        }
        attPosition++;
    }
    objectBuilder.add(ATTS_KEY, attsBuilder);
    if (hasDescending) {
        objectBuilder.add(DESCENDING, descBuilder);
    }
    StringWriter stringWriter = new StringWriter(200);
    JsonWriter jsonWriter = Json.createWriter(stringWriter);
    jsonWriter.writeObject(objectBuilder.build());
    return stringWriter.toString();
}
Also used : StringWriter(java.io.StringWriter) AttributeReference(com.torodb.core.language.AttributeReference) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) IndexType(com.torodb.core.model.IndexedAttributes.IndexType) Map(java.util.Map) JsonWriter(javax.json.JsonWriter)

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