Example usage for javax.json JsonObject entrySet

List of usage examples for javax.json JsonObject entrySet

Introduction

In this page you can find the example usage for javax.json JsonObject entrySet.

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

From source file:org.hyperledger.fabric.sdk.NetworkConfig.java

private void createAllPeers() throws NetworkConfigurationException {

    // Sanity checks
    if (peers != null) {
        throw new NetworkConfigurationException("INTERNAL ERROR: peers has already been initialized!");
    }/*from ww  w.  j av  a  2s  .  co  m*/

    if (eventHubs != null) {
        throw new NetworkConfigurationException("INTERNAL ERROR: eventHubs has already been initialized!");
    }

    peers = new HashMap<>();
    eventHubs = new HashMap<>();

    // peers is a JSON object containing a nested object for each peer
    JsonObject jsonPeers = getJsonObject(jsonConfig, "peers");

    //out("Peers: " + (jsonPeers == null ? "null" : jsonPeers.toString()));
    if (jsonPeers != null) {

        for (Entry<String, JsonValue> entry : jsonPeers.entrySet()) {
            String peerName = entry.getKey();

            JsonObject jsonPeer = getJsonValueAsObject(entry.getValue());
            if (jsonPeer == null) {
                throw new NetworkConfigurationException(
                        format("Error loading config. Invalid peer entry: %s", peerName));
            }

            Node peer = createNode(peerName, jsonPeer, "url");
            if (peer == null) {
                throw new NetworkConfigurationException(
                        format("Error loading config. Invalid peer entry: %s", peerName));
            }
            peers.put(peerName, peer);

            // Also create an event hub with the same name as the peer
            Node eventHub = createNode(peerName, jsonPeer, "eventUrl"); // may not be present
            if (null != eventHub) {
                eventHubs.put(peerName, eventHub);
            }
        }
    }

}

From source file:org.hyperledger.fabric.sdk.NetworkConfig.java

private Map<String, JsonObject> findCertificateAuthorities() throws NetworkConfigurationException {
    Map<String, JsonObject> ret = new HashMap<>();

    JsonObject jsonCertificateAuthorities = getJsonObject(jsonConfig, "certificateAuthorities");
    if (null != jsonCertificateAuthorities) {

        for (Entry<String, JsonValue> entry : jsonCertificateAuthorities.entrySet()) {
            String name = entry.getKey();

            JsonObject jsonCA = getJsonValueAsObject(entry.getValue());
            if (jsonCA == null) {
                throw new NetworkConfigurationException(
                        format("Error loading config. Invalid CA entry: %s", name));
            }/*from   w  ww. j a  va 2  s.  c  o  m*/
            ret.put(name, jsonCA);
        }
    }

    return ret;

}

From source file:org.hyperledger.fabric.sdk.NetworkConfig.java

private void createAllOrganizations(Map<String, JsonObject> foundCertificateAuthorities)
        throws NetworkConfigurationException {

    // Sanity check
    if (organizations != null) {
        throw new NetworkConfigurationException("INTERNAL ERROR: organizations has already been initialized!");
    }//w w  w  . j a  va  2s  .  c  o  m

    organizations = new HashMap<>();

    // organizations is a JSON object containing a nested object for each Org
    JsonObject jsonOrganizations = getJsonObject(jsonConfig, "organizations");

    if (jsonOrganizations != null) {

        for (Entry<String, JsonValue> entry : jsonOrganizations.entrySet()) {
            String orgName = entry.getKey();

            JsonObject jsonOrg = getJsonValueAsObject(entry.getValue());
            if (jsonOrg == null) {
                throw new NetworkConfigurationException(
                        format("Error loading config. Invalid Organization entry: %s", orgName));
            }

            OrgInfo org = createOrg(orgName, jsonOrg, foundCertificateAuthorities);
            organizations.put(orgName, org);
        }
    }

}

From source file:org.hyperledger.fabric.sdk.NetworkConfig.java

private Channel reconstructChannel(HFClient client, String channelName, JsonObject jsonChannel)
        throws NetworkConfigurationException {

    Channel channel = null;/*from  w  ww  . j  av a 2s.co  m*/

    try {
        channel = client.newChannel(channelName);

        // orderers is an array of orderer name strings
        JsonArray ordererNames = getJsonValueAsArray(jsonChannel.get("orderers"));
        boolean foundOrderer = false;

        //out("Orderer names: " + (ordererNames == null ? "null" : ordererNames.toString()));
        if (ordererNames != null) {
            for (JsonValue jsonVal : ordererNames) {

                String ordererName = getJsonValueAsString(jsonVal);
                Orderer orderer = getOrderer(client, ordererName);
                if (orderer == null) {
                    throw new NetworkConfigurationException(
                            format("Error constructing channel %s. Orderer %s not defined in configuration",
                                    channelName, ordererName));
                }
                channel.addOrderer(orderer);
                foundOrderer = true;
            }
        }

        // peers is an object containing a nested object for each peer
        JsonObject jsonPeers = getJsonObject(jsonChannel, "peers");
        boolean foundPeer = false;

        //out("Peers: " + (peers == null ? "null" : peers.toString()));
        if (jsonPeers != null) {

            for (Entry<String, JsonValue> entry : jsonPeers.entrySet()) {
                String peerName = entry.getKey();

                if (logger.isTraceEnabled()) {
                    logger.trace(format("NetworkConfig.reconstructChannel: Processing peer %s", peerName));
                }

                JsonObject jsonPeer = getJsonValueAsObject(entry.getValue());
                if (jsonPeer == null) {
                    throw new NetworkConfigurationException(format(
                            "Error constructing channel %s. Invalid peer entry: %s", channelName, peerName));
                }

                Peer peer = getPeer(client, peerName);
                if (peer == null) {
                    throw new NetworkConfigurationException(
                            format("Error constructing channel %s. Peer %s not defined in configuration",
                                    channelName, peerName));
                }

                // Set the various roles
                PeerOptions peerOptions = PeerOptions.createPeerOptions();

                for (PeerRole peerRole : PeerRole.values()) {
                    setPeerRole(channelName, peerOptions, jsonPeer, peerRole);
                }

                foundPeer = true;

                // Add the event hub associated with this peer
                EventHub eventHub = getEventHub(client, peerName);
                if (eventHub != null) {
                    channel.addEventHub(eventHub);
                    if (peerOptions.peerRoles == null) { // means no roles were found but there is an event hub so define all roles but eventing.
                        peerOptions.setPeerRoles(EnumSet.of(PeerRole.ENDORSING_PEER, PeerRole.CHAINCODE_QUERY,
                                PeerRole.LEDGER_QUERY));
                    }
                }
                channel.addPeer(peer, peerOptions);

            }

        }

        if (!foundPeer) {
            // peers is a required field
            throw new NetworkConfigurationException(
                    format("Error constructing channel %s. At least one peer must be specified", channelName));
        }

    } catch (InvalidArgumentException e) {
        throw new IllegalArgumentException(e);
    }

    return channel;
}

From source file:org.hyperledger.fabric.sdk.NetworkConfig.java

private static Properties extractProperties(JsonObject json, String fieldName) {
    Properties props = new Properties();

    // Extract any other grpc options
    JsonObject options = getJsonObject(json, fieldName);
    if (options != null) {

        for (Entry<String, JsonValue> entry : options.entrySet()) {
            String key = entry.getKey();
            JsonValue value = entry.getValue();
            props.setProperty(key, getJsonValue(value));
        }/*  w  ww .j  a va 2 s .  co  m*/
    }
    return props;
}

From source file:org.owasp.dependencycheck.analyzer.NodePackageAnalyzer.java

/**
 * Adds information to an evidence collection from the node json configuration.
 *
 * @param json information from node.js//w  w  w. ja v a2 s. com
 * @param collection a set of evidence about a dependency
 * @param key the key to obtain the data from the json information
 */
private void addToEvidence(JsonObject json, EvidenceCollection collection, String key) {
    if (json.containsKey(key)) {
        final JsonValue value = json.get(key);
        if (value instanceof JsonString) {
            collection.addEvidence(PACKAGE_JSON, key, ((JsonString) value).getString(), Confidence.HIGHEST);
        } else if (value instanceof JsonObject) {
            final JsonObject jsonObject = (JsonObject) value;
            for (final Map.Entry<String, JsonValue> entry : jsonObject.entrySet()) {
                final String property = entry.getKey();
                final JsonValue subValue = entry.getValue();
                if (subValue instanceof JsonString) {
                    collection.addEvidence(PACKAGE_JSON, String.format("%s.%s", key, property),
                            ((JsonString) subValue).getString(), Confidence.HIGHEST);
                } else {
                    LOGGER.warn("JSON sub-value not string as expected: {}", subValue);
                }
            }
        } else {
            LOGGER.warn("JSON value not string or JSON object as expected: {}", value);
        }
    }
}