Example usage for javax.json JsonObjectBuilder add

List of usage examples for javax.json JsonObjectBuilder add

Introduction

In this page you can find the example usage for javax.json JsonObjectBuilder add.

Prototype

JsonObjectBuilder add(String name, JsonArrayBuilder builder);

Source Link

Document

Adds a name/ JsonArray pair to the JSON object associated with this object builder.

Usage

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

/** Create a sissvoc access point for a version.
 * Don't duplicate it, if it already exists.
 * @param version The version for which the access point is to be created.
 * @param portalUri The URI to put into the portalData.
 * @param source The source of the endpoint, either SYSTEM_SOURCE
 * or USER_SOURCE.//from w  w w  .  j a va2  s  .  co  m
 */
public static void createSissvocAccessPoint(final Version version, final String portalUri,
        final String source) {
    List<AccessPoint> aps = getAccessPointsForVersionAndType(version, AccessPoint.SISSVOC_TYPE);
    for (AccessPoint ap : aps) {
        if (portalUri.equals(getPortalUri(ap))) {
            // Already exists. Don't bother checking the source.
            return;
        }
    }
    // No existing access point for this file, so create a new one.
    AccessPoint ap = new AccessPoint();
    ap.setVersionId(version.getId());
    ap.setType(AccessPoint.SISSVOC_TYPE);
    JsonObjectBuilder jobPortal = Json.createObjectBuilder();
    JsonObjectBuilder jobToolkit = Json.createObjectBuilder();
    jobPortal.add("uri", portalUri);
    jobPortal.add("source", source);
    ap.setPortalData(jobPortal.build().toString());
    ap.setToolkitData(jobToolkit.build().toString());
    AccessPointUtils.saveAccessPoint(ap);
}

From source file:org.apache.nifi.reporting.SiteToSiteProvenanceReportingTask.java

private static void addField(final JsonObjectBuilder builder, final JsonBuilderFactory factory,
        final String key, final Map<String, String> values) {
    if (values == null) {
        return;/*from  w w  w.j a  va2  s . c om*/
    }

    final JsonObjectBuilder mapBuilder = factory.createObjectBuilder();
    for (final Map.Entry<String, String> entry : values.entrySet()) {
        if (entry.getKey() == null || entry.getValue() == null) {
            continue;
        }

        mapBuilder.add(entry.getKey(), entry.getValue());
    }

    builder.add(key, mapBuilder);
}

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// w  w  w  . j  av a2s  .  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:org.dcm4che3.tool.qc.QC.java

private static JsonObject toIssuerObject(Issuer issuer) {
    JsonObjectBuilder builder = Json.createObjectBuilder().add("localNamespaceEntityID",
            emptyIfNull(issuer.getLocalNamespaceEntityID()));
    if (issuer.getUniversalEntityID() != null)
        builder.add("universalEntityID", emptyIfNull(issuer.getUniversalEntityID()))
                .add("universalEntityIDType", emptyIfNull(issuer.getUniversalEntityIDType()));
    return builder.build();
}

From source file:org.dcm4che3.tool.qc.QC.java

private static JsonObject toCodeObject(Code qcRejectionCode) {
    JsonObjectBuilder codeBuilder = Json.createObjectBuilder()
            .add("codeValue", emptyIfNull(qcRejectionCode.getCodeValue()))
            .add("codeMeaning", emptyIfNull(qcRejectionCode.getCodeMeaning()))
            .add("codingSchemeDesignator", emptyIfNull(qcRejectionCode.getCodingSchemeDesignator()));
    if (qcRejectionCode.getCodingSchemeVersion() != null)
        codeBuilder.add("codingSchemeVersion", qcRejectionCode.getCodingSchemeVersion());
    return codeBuilder.build();
}

From source file:nl.sidn.dnslib.message.records.SSHFPResourceRecord.java

@Override
public JsonObject toJSon() {
    JsonObjectBuilder builder = super.createJsonBuilder();
    return builder.add("rdata", Json.createObjectBuilder().add("algorithm", algorithm)
            .add("fptype", fingerprintType).add("fingerprint", Hex.encodeHexString(fingerprint))).build();
}

From source file:nl.sidn.dnslib.message.records.NotImplementedResourceRecord.java

@Override
public JsonObject toJSon() {
    String actualClass = null;// w  w w.  jav  a  2s  .co m
    String actualType = null;
    if (classz == null) {
        actualClass = "CLASS" + (int) rawClassz;
    } else {
        actualClass = classz.name();
    }

    if (type == null) {
        actualType = "TYPE" + (int) rawType;
    } else {
        actualType = "" + type;
    }

    JsonObjectBuilder builder = Json.createObjectBuilder();
    return builder.add("rdata", Json.createObjectBuilder().add("class", actualClass).add("type", actualType)
            .add("rdlength", (int) rdLength).add("rdata", Hex.encodeHexString(rdata))).build();
}

From source file:org.acruxsource.sandbox.spring.jmstows.websocket.ChatHandler.java

public void sendMessage(final ChatMessage message) throws IOException {
    logger.info("Sending message to all participants");

    for (WebSocketSession session : sessions) {
        if (session.isOpen()) {
            DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_PATTERN);
            JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
            jsonObjectBuilder.add("name", message.getName());
            jsonObjectBuilder.add("message", message.getMessage());
            jsonObjectBuilder.add("date", dateFormat.format(message.getDate()));
            session.sendMessage(new TextMessage(jsonObjectBuilder.build().toString()));
        } else {//from w  ww. ja v  a 2s  . c o  m
            sessions.remove(session);
        }
    }
}

From source file:nl.sidn.dnslib.message.records.AbstractResourceRecord.java

public JsonObject toJSon() {
    JsonObjectBuilder builder = createJsonBuilder();
    return builder.add("rdata", Json.createObjectBuilder().add("dummy", "toddo")).build();
}

From source file:nl.sidn.dnslib.message.records.dnssec.DSResourceRecord.java

@Override
public JsonObject toJSon() {
    JsonObjectBuilder builder = super.createJsonBuilder();
    return builder.add("rdata",
            Json.createObjectBuilder().add("keytag", (int) keytag)
                    .add("algorithm", algorithm != null ? algorithm.name() : "")
                    .add("digest-type", digestType.name()).add("digest", hex))
            .build();//from   w w w.  j a v a  2s . co  m
}