use of org.apache.sling.caconfig.spi.ConfigurationPersistData in project sling by apache.
the class CustomConfigurationPersistenceStrategy method persistConfigurationCollection.
@Override
public boolean persistConfigurationCollection(ResourceResolver resourceResolver, String configResourceCollectionParentPath, ConfigurationCollectionPersistData data) {
Resource configResourceParent = getOrCreateResource(resourceResolver, configResourceCollectionParentPath, ValueMap.EMPTY);
// delete existing children and create new ones
deleteChildren(configResourceParent);
for (ConfigurationPersistData item : data.getItems()) {
String path = configResourceParent.getPath() + "/" + item.getCollectionItemName() + "/" + CHILD_NODE_NAME;
getOrCreateResource(resourceResolver, path, item.getProperties());
}
// if resource collection parent properties are given replace them as well
if (data.getProperties() != null) {
replaceProperties(configResourceParent, data.getProperties());
}
commit(resourceResolver);
return true;
}
use of org.apache.sling.caconfig.spi.ConfigurationPersistData in project sling by apache.
the class CustomConfigurationPersistenceStrategy2 method persistConfigurationCollection.
@Override
public boolean persistConfigurationCollection(ResourceResolver resourceResolver, String configResourceCollectionParentPath, ConfigurationCollectionPersistData data) {
String parentPath = getCollectionParentResourcePath(configResourceCollectionParentPath);
Resource configResourceParent = getOrCreateResource(resourceResolver, parentPath, ValueMap.EMPTY);
// delete existing children and create new ones
deleteChildren(configResourceParent);
for (ConfigurationPersistData item : data.getItems()) {
String path = configResourceParent.getPath() + "/" + item.getCollectionItemName();
getOrCreateResource(resourceResolver, path, item.getProperties());
}
// if resource collection parent properties are given replace them as well
if (data.getProperties() != null) {
replaceProperties(configResourceParent, data.getProperties());
}
commit(resourceResolver);
return true;
}
use of org.apache.sling.caconfig.spi.ConfigurationPersistData in project sling by apache.
the class ConfigurationManagerImplTest method testPersistConfigurationCollection.
@Test
public void testPersistConfigurationCollection() throws Exception {
underTest.persistConfigurationCollection(contextResourceNoConfig, CONFIG_COL_NAME, new ConfigurationCollectionPersistData(ImmutableList.of(new ConfigurationPersistData(ImmutableMap.<String, Object>of("prop1", "value1")).collectionItemName("0"), new ConfigurationPersistData(ImmutableMap.<String, Object>of("prop2", 5)).collectionItemName("1"))));
context.resourceResolver().commit();
String configPath0 = getConfigCollectionItemPersistPath(getConfigCollectionParentPersistPath("/conf/testNoConfig/sling:configs/" + CONFIG_COL_NAME) + "/0");
ValueMap props0 = context.resourceResolver().getResource(configPath0).getValueMap();
assertEquals("value1", props0.get("prop1"));
String configPath1 = getConfigCollectionItemPersistPath(getConfigCollectionParentPersistPath("/conf/testNoConfig/sling:configs/" + CONFIG_COL_NAME) + "/1");
ValueMap props1 = context.resourceResolver().getResource(configPath1).getValueMap();
assertEquals((Integer) 5, props1.get("prop2"));
}
use of org.apache.sling.caconfig.spi.ConfigurationPersistData in project sling by apache.
the class ConfigurationManagerImplTest method testPersistConfiguration.
@Test
public void testPersistConfiguration() throws Exception {
underTest.persistConfiguration(contextResourceNoConfig, CONFIG_NAME, new ConfigurationPersistData(ImmutableMap.<String, Object>of("prop1", "value1")));
context.resourceResolver().commit();
String configPath = getConfigPersistPath("/conf/testNoConfig/sling:configs/" + CONFIG_NAME);
ValueMap props = context.resourceResolver().getResource(configPath).getValueMap();
assertEquals("value1", props.get("prop1"));
}
use of org.apache.sling.caconfig.spi.ConfigurationPersistData in project sling by apache.
the class ConfigurationManagerImplTest method testPersistConfiguration_Nested.
@Test
public void testPersistConfiguration_Nested() throws Exception {
underTest.persistConfiguration(contextResourceLevel2, getConfigResolvePath(getConfigResolvePath(CONFIG_NESTED_NAME) + "/propSub") + "/propSubLevel2", new ConfigurationPersistData(ImmutableMap.<String, Object>of("prop1", "value1_persist")));
context.resourceResolver().commit();
ConfigurationData configData = underTest.getConfiguration(contextResourceLevel2, CONFIG_NESTED_NAME);
ConfigurationData subData = configData.getValues().get("propSub", ConfigurationData.class);
ConfigurationData subDataLevel2 = subData.getValues().get("propSubLevel2", ConfigurationData.class);
assertEquals("value1_persist", subDataLevel2.getValues().get("prop1", String.class));
assertEquals("value1_persist", subDataLevel2.getEffectiveValues().get("prop1", String.class));
assertFalse(subDataLevel2.getValues().get("prop4", false));
assertFalse(subDataLevel2.getEffectiveValues().get("prop4", false));
}
Aggregations