@Override
public ConfigMetadataRepository readRepository(InputStream in) throws IOException {
String content = read(in);
JSONObject json = new JSONObject(content);
SimpleConfigMetadataRepository repository = new SimpleConfigMetadataRepository();
if (json.has(GROUPS)) {
JSONObject rootGroups = json.getJSONObject(GROUPS);
for (Object o : rootGroups.keySet()) {
String groupName = (String) o;
JSONObject rootGroup = rootGroups.getJSONObject(groupName);
ConfigMetadataGroup group = ConfigMetadataGroup.root(groupName);
readGroup(rootGroup, group);
repository.registerRootGroup(group);
}
}
if (json.has(ITEMS)) {
ConfigMetadataGroup group = ConfigMetadataGroup.root("");
JSONObject items = json.getJSONObject(ITEMS);
for (Object o : items.keySet()) {
String itemName = (String) o;
JSONObject item = items.getJSONObject(itemName);
group.registerItem(readItem(group, item, itemName));
}
repository.registerRootGroup(group);
}
return repository;
}