private SimpleConfigurationMetadataRepository add(final InputStream in, final Charset charset) { try { val metadata = this.reader.read(in, charset); return create(metadata); } catch (final Exception ex) { throw new IllegalStateException("Failed to read configuration metadata", ex); } }
public RawConfigurationMetadata read(InputStream in, Charset charset) throws IOException { try { JSONObject json = readJson(in, charset); List<ConfigurationMetadataSource> groups = parseAllSources(json); List<ConfigurationMetadataItem> items = parseAllItems(json); List<ConfigurationMetadataHint> hints = parseAllHints(json); return new RawConfigurationMetadata(groups, items, hints); } catch (Exception ex) { if (ex instanceof IOException) { throw (IOException) ex; } if (ex instanceof RuntimeException) { throw (RuntimeException) ex; } throw new IllegalStateException(ex); } }
private List<ConfigurationMetadataHint> parseAllHints(JSONObject root) throws Exception { List<ConfigurationMetadataHint> result = new ArrayList<>(); if (!root.has("hints")) { return result; } JSONArray items = root.getJSONArray("hints"); for (int i = 0; i < items.length(); i++) { JSONObject item = items.getJSONObject(i); result.add(parseHint(item)); } return result; }
private ConfigurationMetadataItem parseItem(JSONObject json) throws Exception { ConfigurationMetadataItem item = new ConfigurationMetadataItem(); item.setId(json.getString("name")); item.setType(json.optString("type", null)); String description = json.optString("description", null); item.setDescription(description); item.setShortDescription(this.sentenceExtractor.getFirstSentence(description)); item.setDefaultValue(readItemValue(json.opt("defaultValue"))); item.setDeprecation(parseDeprecation(json)); item.setSourceType(json.optString("sourceType", null)); item.setSourceMethod(json.optString("sourceMethod", null)); return item; }
private List<ConfigurationMetadataSource> parseAllSources(JSONObject root) throws Exception { List<ConfigurationMetadataSource> result = new ArrayList<>(); if (!root.has("groups")) { return result; } JSONArray sources = root.getJSONArray("groups"); for (int i = 0; i < sources.length(); i++) { JSONObject source = sources.getJSONObject(i); result.add(parseSource(source)); } return result; }
private List<ConfigurationMetadataItem> parseAllItems(JSONObject root) throws Exception { List<ConfigurationMetadataItem> result = new ArrayList<>(); if (!root.has("properties")) { return result; } JSONArray items = root.getJSONArray("properties"); for (int i = 0; i < items.length(); i++) { JSONObject item = items.getJSONObject(i); result.add(parseItem(item)); } return result; }
private Deprecation parseDeprecation(JSONObject object) throws Exception { if (object.has("deprecation")) { JSONObject deprecationJsonObject = object.getJSONObject("deprecation"); Deprecation deprecation = new Deprecation(); deprecation.setLevel(parseDeprecationLevel( deprecationJsonObject.optString("level", null))); String reason = deprecationJsonObject.optString("reason", null); deprecation.setReason(reason); deprecation.setShortReason(this.sentenceExtractor.getFirstSentence(reason)); deprecation .setReplacement(deprecationJsonObject.optString("replacement", null)); return deprecation; } return object.optBoolean("deprecated") ? new Deprecation() : null; }
JSONObject value = values.getJSONObject(i); ValueHint valueHint = new ValueHint(); valueHint.setValue(readItemValue(value.get("value"))); String description = value.optString("description", null); valueHint.setDescription(description); String key = (String) keys.next(); valueProvider.getParameters().put(key, readItemValue(parameters.get(key)));
private SimpleConfigurationMetadataRepository add(InputStream in, Charset charset) throws IOException { try { RawConfigurationMetadata metadata = this.reader.read(in, charset); return create(metadata); } catch (Exception ex) { throw new IllegalStateException("Failed to read configuration metadata", ex); } }