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()); }
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); }
/** * 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); } } }