use of org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata in project sling by apache.
the class ConfigurationDataImpl method resolveNestedConfigs.
private void resolveNestedConfigs(Map<String, Object> props) {
if (configMetadata == null) {
return;
}
for (PropertyMetadata<?> propertyMetadata : configMetadata.getPropertyMetadata().values()) {
if (propertyMetadata.isNestedConfiguration()) {
ConfigurationMetadata nestedConfigMetadata = propertyMetadata.getConfigurationMetadata();
String relatedConfigPath = resolvedConfigurationResource != null ? resolvedConfigurationResource.getPath() : null;
String nestedConfigName;
if (configResourceCollection) {
String collectionItemName = StringUtils.defaultString(getCollectionItemName(), "newItem");
nestedConfigName = configurationPersistenceStrategy.getCollectionParentConfigName(configName, relatedConfigPath) + "/" + configurationPersistenceStrategy.getCollectionItemConfigName(collectionItemName, relatedConfigPath) + "/" + nestedConfigMetadata.getName();
} else {
nestedConfigName = configurationPersistenceStrategy.getConfigName(configName, relatedConfigPath) + "/" + nestedConfigMetadata.getName();
}
if (propertyMetadata.getType().equals(ConfigurationMetadata.class)) {
ConfigurationData configData = configurationManager.getConfiguration(contextResource, nestedConfigName);
props.put(propertyMetadata.getName(), configData);
} else if (propertyMetadata.getType().equals(ConfigurationMetadata[].class)) {
Collection<ConfigurationData> configDatas = configurationManager.getConfigurationCollection(contextResource, nestedConfigName).getItems();
props.put(propertyMetadata.getName(), configDatas.toArray(new ConfigurationData[configDatas.size()]));
}
}
}
}
use of org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata in project sling by apache.
the class ConfigurationManagerImpl method newCollectionItem.
@Override
public ConfigurationData newCollectionItem(Resource resource, String configName) {
ConfigNameUtil.ensureValidConfigName(configName);
ConfigurationMetadata configMetadata = getConfigurationMetadata(configName);
if (configMetadata != null) {
return new ConfigurationDataImpl(configMetadata, resource, configName, this, configurationManagementSettings, configurationOverrideMultiplexer, configurationPersistenceStrategy, true);
}
return null;
}
use of org.apache.sling.caconfig.spi.metadata.ConfigurationMetadata in project sling by apache.
the class ConfigurationManagerImpl method getConfigurationCollection.
@SuppressWarnings("unchecked")
@Override
public ConfigurationCollectionData getConfigurationCollection(Resource resource, String configName) {
ConfigNameUtil.ensureValidConfigName(configName);
if (log.isDebugEnabled()) {
log.debug("Get configuration collection for context path {}, name '{}'", resource.getPath(), configName);
}
ConfigurationMetadata configMetadata = getConfigurationMetadata(configName);
List<ConfigurationData> configData = new ArrayList<>();
// get all possible colection parent config names
Collection<String> collectionParentConfigNames = configurationPersistenceStrategy.getAllCollectionParentConfigNames(configName);
// get configuration resource items
List<Iterator<Resource>> configResourceInheritanceChains = new ArrayList<>();
for (String collectionParentConfigName : collectionParentConfigNames) {
Collection<Iterator<Resource>> result = configurationResourceResolvingStrategy.getResourceCollectionInheritanceChain(resource, configurationResourceResolverConfig.configBucketNames(), collectionParentConfigName);
if (result != null) {
configResourceInheritanceChains.addAll(result);
}
}
String writebackConfigResourceCollectionParentPath = null;
if (configResourceInheritanceChains != null) {
for (Iterator<Resource> configResourceInheritanceChain : configResourceInheritanceChains) {
ResettableIterator resettableConfigResourceInheritanceChain = new ListIteratorWrapper(configResourceInheritanceChain);
Resource configResource = applyPersistenceAndInheritance(resource.getPath(), configName, resettableConfigResourceInheritanceChain, true);
resettableConfigResourceInheritanceChain.reset();
Resource untransformedConfigResource = (Resource) resettableConfigResourceInheritanceChain.next();
if (configResource != null) {
// get writeback resource for "reverse inheritance detection"
Resource writebackConfigResource = null;
String writebackConfigResourcePath = null;
for (String configBucketName : configurationResourceResolverConfig.configBucketNames()) {
writebackConfigResourceCollectionParentPath = configurationResourceResolvingStrategy.getResourceCollectionParentPath(resource, configBucketName, configName);
if (writebackConfigResourceCollectionParentPath != null) {
writebackConfigResourceCollectionParentPath = configurationPersistenceStrategy.getCollectionParentResourcePath(writebackConfigResourceCollectionParentPath);
writebackConfigResourcePath = writebackConfigResourceCollectionParentPath + "/" + untransformedConfigResource.getName();
writebackConfigResource = configResource.getResourceResolver().getResource(writebackConfigResourcePath);
if (writebackConfigResource != null) {
writebackConfigResource = configurationPersistenceStrategy.getCollectionItemResource(writebackConfigResource);
break;
}
}
}
if (log.isTraceEnabled() && configResource != null) {
log.trace("+ Found config resource for context path " + resource.getPath() + ": " + configResource.getPath() + " " + MapUtil.traceOutput(configResource.getValueMap()) + ", " + "writeback config resource: " + writebackConfigResourcePath);
}
resettableConfigResourceInheritanceChain.reset();
configData.add(new ConfigurationDataImpl(configMetadata, configResource, writebackConfigResource, applyPersistence(resettableConfigResourceInheritanceChain, true), resource, configName, this, configurationManagementSettings, configurationOverrideMultiplexer, configurationPersistenceStrategy, true, untransformedConfigResource.getName()));
}
}
}
// fallback for writeback path detection when no configuration resources does exist yet
if (writebackConfigResourceCollectionParentPath == null) {
for (String configBucketName : configurationResourceResolverConfig.configBucketNames()) {
writebackConfigResourceCollectionParentPath = configurationResourceResolvingStrategy.getResourceCollectionParentPath(resource, configBucketName, configName);
if (writebackConfigResourceCollectionParentPath != null) {
break;
}
}
}
// get properties of parent resource of the current level
Map<String, Object> resourceCollectionParentProps = null;
if (writebackConfigResourceCollectionParentPath != null) {
Resource writebackConfigResourceCollectionParent = resource.getResourceResolver().getResource(writebackConfigResourceCollectionParentPath);
if (writebackConfigResourceCollectionParent != null) {
resourceCollectionParentProps = writebackConfigResourceCollectionParent.getValueMap();
}
}
return new ConfigurationCollectionDataImpl(configName, configData, writebackConfigResourceCollectionParentPath, resourceCollectionParentProps, configurationManagementSettings);
}
Aggregations