use of org.apache.sling.caconfig.management.ConfigurationData in project sling by apache.
the class ConfigurationWebConsolePlugin method printResolutionTestTool.
private void printResolutionTestTool(HttpServletRequest request, PrintWriter pw) {
final String path = this.getParameter(request, "path", null);
String configNameOther = this.getParameter(request, "configNameOther", null);
String configName = this.getParameter(request, "configName", null);
if (configName == null) {
configName = configNameOther;
} else {
configNameOther = null;
}
final boolean resourceCollection = BooleanUtils.toBoolean(this.getParameter(request, "resourceCollection", "false"));
ResourceResolver resolver = null;
try {
Resource contentResource = null;
if (path != null) {
resolver = getResolver();
if (resolver != null) {
contentResource = resolver.getResource(path);
}
}
pw.println("<form method='get'>");
tableStart(pw, "Test Configuration Resolution", 2);
String alertMessage = null;
if (path != null) {
if (resolver == null) {
alertMessage = "Unable to access repository - please check system configuration.";
} else if (contentResource == null) {
alertMessage = "Path does not exist.";
}
}
textField(pw, "Content Path", "path", path, alertMessage);
tableRows(pw);
selectField(pw, "Config Name", "configName", configName, configurationManager.getConfigurationNames());
tableRows(pw);
textField(pw, "Other Config Name", "configNameOther", configNameOther);
tableRows(pw);
checkboxField(pw, "Resource collection", "resourceCollection", resourceCollection);
tableRows(pw);
pw.println("<td></td>");
pw.println("<td><input type='submit' value='Resolve'/></td>");
tableEnd(pw);
pw.println("</form>");
pw.println("<br/>");
if (contentResource != null) {
// context paths
Iterator<ContextResource> contextResources = contextPathStrategyMultiplexer.findContextResources(contentResource);
tableStart(pw, "Context paths", 3);
pw.println("<th>Context path</th>");
pw.println("<th>Config reference</th>");
pw.println("<th>Ranking</th>");
while (contextResources.hasNext()) {
ContextResource contextResource = contextResources.next();
tableRows(pw);
pw.println("<td>" + xss.encodeForHTML(contextResource.getResource().getPath()) + "</td>");
pw.println("<td>" + xss.encodeForHTML(contextResource.getConfigRef()) + "</td>");
pw.println("<td>" + contextResource.getServiceRanking() + "</td>");
}
tableEnd(pw);
pw.println("<br/>");
// resolve configuration
Collection<ConfigurationData> configDatas;
if (resourceCollection) {
configDatas = configurationManager.getConfigurationCollection(contentResource, configName).getItems();
} else {
ConfigurationData configData = configurationManager.getConfiguration(contentResource, configName);
if (configData != null) {
configDatas = Collections.singletonList(configData);
} else {
configDatas = Collections.emptyList();
}
}
tableStart(pw, "Result", 6);
if (configDatas.size() == 0) {
pw.println("<td colspan='6'>");
alertDiv(pw, "No matching item found.");
pw.println("<br/> </td>");
} else {
pw.println("<th>Property</th>");
pw.println("<th>Effective Value</th>");
pw.println("<th>Value</th>");
pw.println("<th>Default</th>");
pw.println("<th>Inherited</th>");
pw.println("<th>Overwritten</th>");
for (ConfigurationData data : configDatas) {
tableRows(pw);
pw.println("<td colspan='6' style='background-color:#f3f3f3'>");
pw.print("Path: " + xss.encodeForHTML(data.getResourcePath()));
pw.println("</td>");
for (String propertyName : data.getPropertyNames()) {
ValueInfo<?> valueInfo = data.getValueInfo(propertyName);
tableRows(pw);
td(pw, propertyName);
td(pw, valueInfo.getEffectiveValue());
td(pw, valueInfo.getValue());
td(pw, valueInfo.isDefault());
String title = null;
if (valueInfo.isInherited()) {
title = "Source path: " + valueInfo.getConfigSourcePath();
}
td(pw, valueInfo.isInherited(), title);
td(pw, valueInfo.isOverridden());
}
}
}
tableEnd(pw);
}
} finally {
if (resolver != null) {
resolver.close();
}
}
}
use of org.apache.sling.caconfig.management.ConfigurationData in project sling by apache.
the class ConfigurationManagerImplTest method testNewCollectionItem.
@Test
public void testNewCollectionItem() {
ConfigurationData newItem = underTest.newCollectionItem(contextResource, CONFIG_COL_NAME);
assertNotNull(newItem);
assertEquals((Integer) 5, newItem.getEffectiveValues().get("prop3", 0));
}
use of org.apache.sling.caconfig.management.ConfigurationData in project sling by apache.
the class ConfigurationManagerImplTest method testGetConfigurationCollection_WithOverride.
@Test
public void testGetConfigurationCollection_WithOverride() {
context.registerService(ConfigurationOverrideProvider.class, new DummyConfigurationOverrideProvider("[/content]" + CONFIG_COL_NAME + "/prop1=\"override1\""));
List<ConfigurationData> configDatas = ImmutableList.copyOf(underTest.getConfigurationCollection(contextResource, CONFIG_COL_NAME).getItems());
assertEquals(2, configDatas.size());
ConfigurationData configData1 = configDatas.get(0);
assertFalse(configData1.isInherited());
assertFalse(configData1.isOverridden());
assertEquals(ImmutableSet.of("prop1", "prop2", "prop3"), configData1.getPropertyNames());
assertEquals("value1", configData1.getValues().get("prop1", String.class));
assertEquals("override1", configData1.getEffectiveValues().get("prop1", String.class));
assertEquals((Integer) 5, configData1.getEffectiveValues().get("prop3", 0));
assertFalse(configData1.getValueInfo("prop1").isInherited());
assertTrue(configData1.getValueInfo("prop1").isOverridden());
assertFalse(configData1.getValueInfo("prop3").isInherited());
assertFalse(configData1.getValueInfo("prop3").isOverridden());
ConfigurationData configData2 = configDatas.get(1);
assertFalse(configData2.isInherited());
assertFalse(configData2.isOverridden());
assertEquals(ImmutableSet.of("prop1", "prop2", "prop3", "prop4"), configData2.getPropertyNames());
assertNull(configData2.getValues().get("prop1", String.class));
assertEquals("override1", configData2.getEffectiveValues().get("prop1", String.class));
assertEquals((Integer) 5, configData2.getEffectiveValues().get("prop3", 0));
assertFalse(configData2.getValueInfo("prop1").isInherited());
assertTrue(configData2.getValueInfo("prop1").isOverridden());
assertFalse(configData2.getValueInfo("prop3").isInherited());
assertFalse(configData2.getValueInfo("prop3").isOverridden());
}
use of org.apache.sling.caconfig.management.ConfigurationData in project sling by apache.
the class ConfigurationManagerImplTest method testGetConfigurationNested_NoConfigResource.
@Test
public void testGetConfigurationNested_NoConfigResource() {
ConfigurationData configData = underTest.getConfiguration(contextResourceNoConfig, CONFIG_NESTED_NAME);
assertNotNull(configData);
assertEquals(ImmutableSet.of("prop1", "propSub", "propSubList"), configData.getPropertyNames());
assertNull(configData.getValues().get("prop1", String.class));
assertEquals("defValue", configData.getEffectiveValues().get("prop1", String.class));
assertEquals(ConfigurationMetadata.class, configData.getValueInfo("propSub").getPropertyMetadata().getType());
assertEquals(ConfigurationMetadata[].class, configData.getValueInfo("propSubList").getPropertyMetadata().getType());
ConfigurationData subData = configData.getValues().get("propSub", ConfigurationData.class);
ConfigurationData subDataEffective = configData.getEffectiveValues().get("propSub", ConfigurationData.class);
assertNotNull(subData);
assertNotNull(subDataEffective);
assertTrue(ConfigurationData.class.isAssignableFrom(configData.getValueInfo("propSub").getValue().getClass()));
assertTrue(ConfigurationData.class.isAssignableFrom(configData.getValueInfo("propSub").getEffectiveValue().getClass()));
assertTrue(ConfigurationData[].class.isAssignableFrom(configData.getValueInfo("propSubList").getValue().getClass()));
assertTrue(ConfigurationData[].class.isAssignableFrom(configData.getValueInfo("propSubList").getEffectiveValue().getClass()));
assertNull(subData.getValues().get("prop1", String.class));
assertEquals("defValue", subData.getEffectiveValues().get("prop1", String.class));
ConfigurationData[] subListData = configData.getValues().get("propSubList", ConfigurationData[].class);
ConfigurationData[] subListDataEffective = configData.getEffectiveValues().get("propSubList", ConfigurationData[].class);
assertNotNull(subListData);
assertNotNull(subListDataEffective);
assertTrue(ConfigurationData[].class.isAssignableFrom(configData.getValueInfo("propSubList").getValue().getClass()));
assertTrue(ConfigurationData[].class.isAssignableFrom(configData.getValueInfo("propSubList").getEffectiveValue().getClass()));
assertEquals(0, subListData.length);
}
use of org.apache.sling.caconfig.management.ConfigurationData in project sling by apache.
the class ConfigurationManagerImplTest method testGetConfigurationCollection_WithResourceCollectionAndPropertyInheritance.
@Test
public void testGetConfigurationCollection_WithResourceCollectionAndPropertyInheritance() {
ConfigurationCollectionData configCollectionData = underTest.getConfigurationCollection(contextResourceLevel3, CONFIG_COL_NAME);
List<ConfigurationData> configDatas = ImmutableList.copyOf(configCollectionData.getItems());
assertEquals(2, configDatas.size());
ConfigurationData configData1 = configDatas.get(0);
assertFalse(configData1.isInherited());
assertTrue(configData1.getPropertyNames().containsAll(ImmutableSet.of("prop1", "prop2", "prop3", "prop4", "prop5")));
assertTrue(configData1.getPropertyNames().containsAll(ImmutableSet.of("prop1", "prop2", "prop3", "prop4", "prop5")));
assertNull(configData1.getValues().get("prop1", String.class));
assertNull(configData1.getValues().get("prop2", String.class));
assertNull(configData1.getValues().get("prop3", Integer.class));
assertFalse(configData1.getValues().get("prop4", Boolean.class));
assertEquals("value5_level3", configData1.getValues().get("prop5", String.class));
assertEquals("value1_level2", configData1.getEffectiveValues().get("prop1", String.class));
assertNull(configData1.getEffectiveValues().get("prop2", String.class));
assertEquals((Integer) 5, configData1.getEffectiveValues().get("prop3", 0));
assertFalse(configData1.getEffectiveValues().get("prop4", Boolean.class));
assertEquals("value5_level3", configData1.getEffectiveValues().get("prop5", String.class));
String configPathLevel2 = getConfigCollectionItemResolvePath(getConfigCollectionParentResolvePath("/conf/test/level2/sling:configs/" + CONFIG_COL_NAME) + "/1");
String configPathLevel3 = getConfigCollectionItemResolvePath(getConfigCollectionParentResolvePath("/conf/test/level2/level3/sling:configs/" + CONFIG_COL_NAME) + "/1");
assertTrue(configData1.getValueInfo("prop1").isInherited());
assertEquals(configPathLevel2, configData1.getValueInfo("prop1").getConfigSourcePath());
assertFalse(configData1.getValueInfo("prop2").isInherited());
assertNull(configData1.getValueInfo("prop2").getConfigSourcePath());
assertFalse(configData1.getValueInfo("prop3").isInherited());
assertNull(configData1.getValueInfo("prop3").getConfigSourcePath());
assertFalse(configData1.getValueInfo("prop4").isInherited());
assertEquals(configPathLevel3, configData1.getValueInfo("prop4").getConfigSourcePath());
assertFalse(configData1.getValueInfo("prop5").isInherited());
assertEquals(configPathLevel3, configData1.getValueInfo("prop5").getConfigSourcePath());
ConfigurationData configData2 = configDatas.get(1);
assertFalse(configData1.isInherited());
assertEquals(ImmutableSet.of("prop1", "prop2", "prop3", "prop4"), configData2.getPropertyNames());
assertNull(configData2.getValues().get("prop1", String.class));
assertEquals((Integer) 5, configData2.getEffectiveValues().get("prop3", 0));
String configPath2 = getConfigCollectionItemResolvePath(getConfigCollectionParentResolvePath("/conf/test/sling:configs/" + CONFIG_COL_NAME) + "/2");
assertTrue(configData2.getValueInfo("prop4").isInherited());
assertEquals(configPath2, configData2.getValueInfo("prop4").getConfigSourcePath());
assertFalse(configData2.getValueInfo("prop3").isInherited());
assertNull(configData2.getValueInfo("prop3").getConfigSourcePath());
assertTrue((Boolean) configCollectionData.getProperties().get(ConfigurationResourceNameConstants.PROPERTY_CONFIG_COLLECTION_INHERIT));
assertTrue(configData1.getValues().get(ConfigurationDefNameConstants.PROPERTY_CONFIG_PROPERTY_INHERIT, false));
}
Aggregations