private ConfigurationMetadataGroup getGroup(ConfigurationMetadataSource source) { if (source == null) { ConfigurationMetadataGroup rootGroup = this.allGroups.get(ROOT_GROUP); if (rootGroup == null) { rootGroup = new ConfigurationMetadataGroup(ROOT_GROUP); this.allGroups.put(ROOT_GROUP, rootGroup); } return rootGroup; } return this.allGroups.get(source.getGroupId()); }
public ConfigurationMetadataSource getSource(String type) { for (ConfigurationMetadataSource source : this.sources) { if (type.equals(source.getType())) { return source; } } return null; }
private ConfigurationMetadataSource parseSource(JSONObject json) throws Exception { ConfigurationMetadataSource source = new ConfigurationMetadataSource(); source.setGroupId(json.getString("name")); source.setType(json.optString("type", null)); String description = json.optString("description", null); source.setDescription(description); source.setShortDescription(this.sentenceExtractor.getFirstSentence(description)); source.setSourceType(json.optString("sourceType", null)); source.setSourceMethod(json.optString("sourceMethod", null)); return source; }
private static ConfigurationMetadataSource getSource(final RawConfigurationMetadata metadata, final ConfigurationMetadataItem item) { if (item.getSourceType() == null) { return null; } val idx = item.getId().lastIndexOf('.'); val name = idx > 0 ? item.getId().substring(0, idx) : StringUtils.EMPTY; return metadata.getSources().stream() .filter(source -> source.getType().equals(item.getSourceType()) && name.equals(source.getGroupId())) .findFirst() .orElse(null); }
/** * Add a {@link ConfigurationMetadataProperty} with the * {@link ConfigurationMetadataSource source} that defines it, if any. * @param property the property to add * @param source the source */ public void add(ConfigurationMetadataProperty property, ConfigurationMetadataSource source) { if (source != null) { putIfAbsent(source.getProperties(), property.getId(), property); } putIfAbsent(getGroup(source).getProperties(), property.getId(), property); }
/** * Register the specified {@link ConfigurationMetadataSource sources}. * @param sources the sources to add */ public void add(Collection<ConfigurationMetadataSource> sources) { for (ConfigurationMetadataSource source : sources) { String groupId = source.getGroupId(); ConfigurationMetadataGroup group = this.allGroups.get(groupId); if (group == null) { group = new ConfigurationMetadataGroup(groupId); this.allGroups.put(groupId, group); } String sourceType = source.getType(); if (sourceType != null) { putIfAbsent(group.getSources(), sourceType, source); } } }
/** * Resolve the name of an item against this instance. * @param item the item to resolve * @see ConfigurationMetadataProperty#setName(String) */ private void resolveName(ConfigurationMetadataItem item) { item.setName(item.getId()); // fallback if (item.getSourceType() == null) { return; } ConfigurationMetadataSource source = getSource(item.getSourceType()); if (source != null) { String groupId = source.getGroupId(); String dottedPrefix = groupId + "."; String id = item.getId(); if (hasLength(groupId) && id.startsWith(dottedPrefix)) { String name = id.substring(dottedPrefix.length()); item.setName(name); } } }