public PollingResponse call()

in archaius2-persisted2/src/main/java/com/netflix/archaius/persisted2/JsonPersistedV2Reader.java [152:227]


    public PollingResponse call() throws Exception {
        Map<String, List<ScopedValue>> props = new HashMap<String, List<ScopedValue>>();
        Map<String, List<ScopedValue>> propIds = new HashMap<>();
        
        InputStream is = reader.call();
        if (is == null) {
            return PollingResponse.noop();
        }
        
        try {
            JsonNode node = mapper.readTree(is);
            for (String part : this.path) {
                node = node.path(part);
            }
            
            for (final JsonNode property : node)  {
                String key = null;
                try {
                    key   = property.get(keyField).asText();
                    String value = property.has(valueField) ? property.get(valueField).asText() : "";
                    
                    LinkedHashMap<String, Set<String>> scopes = new LinkedHashMap<String, Set<String>>();
                    
                    for (String scope : this.scopeFields) {
                        String[] values = StringUtils.splitByWholeSeparator(property.has(scope) ? property.get(scope).asText().toLowerCase() : "", ",");
                        scopes.put(scope, values.length == 0 ? Collections.<String>emptySet() : immutableSetFrom(values));
                    }
                    
                    // Filter out scopes that don't match at all
                    if (!this.predicate.evaluate(scopes)) {
                        continue;
                    }
                    
                    // Build up a list of valid scopes
                    List<ScopedValue> variations = props.get(key);
                    if (variations == null) {
                        variations = new ArrayList<ScopedValue>();
                        props.put(key, variations);
                    }
                    variations.add(new ScopedValue(value, scopes));
                    if (readIdField) {
                        propIds.putIfAbsent(key, new ArrayList<>());
                        propIds.get(key).add(
                                new ScopedValue(property.has(idField) ? property.get(idField).asText() : "", scopes));
                    }
                }
                catch (Exception e) {
                    LOG.warn("Unable to process property '{}'", key);
                }
            }
        }
        finally {
            try {
                is.close();
            }
            catch (Exception e) {
                // OK to ignore
            }
        }
        
        // Resolve to a single property value
        final Map<String, String> result = new HashMap<String, String>();
        for (Entry<String, List<ScopedValue>> entry : props.entrySet()) {
            result.put(entry.getKey(), valueResolver.resolve(entry.getKey(), entry.getValue()));
        }

        if (readIdField) {
            final Map<String, String> idResult = new HashMap<>();
            for (Entry<String, List<ScopedValue>> entry : propIds.entrySet()) {
                idResult.put(entry.getKey(), valueResolver.resolve(entry.getKey(), entry.getValue()));
            }
            return PollingResponse.forSnapshot(result, idResult);
        }
        
        return PollingResponse.forSnapshot(result);
    }