modules/core/gui/src/main/java/org/rhq/core/gui/configuration/ConfigRenderer.java | 6 modules/core/gui/src/main/java/org/rhq/core/gui/configuration/helper/ConfigurationUtility.java | 11 + modules/core/gui/src/main/java/org/rhq/core/gui/configuration/propset/ConfigurationSet.java | 75 ++++++++-- modules/core/gui/src/main/java/org/rhq/core/gui/configuration/propset/PropertySetRenderer.java | 2 modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/group/EditGroupResourceConfigurationUIBean.java | 2 modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/test/EditTestConfigurationUIBean.java | 2 modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/group/EditGroupPluginConfigurationUIBean.java | 2 7 files changed, 80 insertions(+), 20 deletions(-)
New commits: commit 0a53ca30d70fe38283185673bff7aeae58ea33d5 Author: Lukas Krejci lkrejci@redhat.com Date: Wed Dec 15 16:40:21 2010 +0100
BZ 663377 - Updating group config doesn't introduce "foreign" properties in open maps of individual resources.
diff --git a/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/ConfigRenderer.java b/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/ConfigRenderer.java index 87bd52c..cf48945 100644 --- a/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/ConfigRenderer.java +++ b/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/ConfigRenderer.java @@ -263,7 +263,7 @@ public class ConfigRenderer extends Renderer { // Update member Configurations if this is a group config. if (configurationComponent instanceof ConfigurationSetComponent) { ConfigurationSetComponent configurationSetComponent = ((ConfigurationSetComponent) configurationComponent); - configurationSetComponent.getConfigurationSet().applyGroupConfiguration(); + configurationSetComponent.getConfigurationSet().applyGroupConfigurationForView(); }
// Now add a new component to the JSF component tree. @@ -310,7 +310,7 @@ public class ConfigRenderer extends Renderer { // ...and from member Configurations if this is a group config. if (configurationComponent instanceof ConfigurationSetComponent) { ConfigurationSetComponent configurationSetComponent = ((ConfigurationSetComponent) configurationComponent); - configurationSetComponent.getConfigurationSet().applyGroupConfiguration(); + configurationSetComponent.getConfigurationSet().applyGroupConfigurationForView(); }
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Property at index " + listIndex @@ -370,7 +370,7 @@ public class ConfigRenderer extends Renderer { // ...and from member Configurations if this is a group config. if (configurationComponent instanceof ConfigurationSetComponent) { ConfigurationSetComponent configurationSetComponent = ((ConfigurationSetComponent) configurationComponent); - configurationSetComponent.getConfigurationSet().applyGroupConfiguration(); + configurationSetComponent.getConfigurationSet().applyGroupConfigurationForView(); }
FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Property '" + memberName + "' deleted from map '" diff --git a/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/propset/ConfigurationSet.java b/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/propset/ConfigurationSet.java index d84aa14..959b85f 100644 --- a/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/propset/ConfigurationSet.java +++ b/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/propset/ConfigurationSet.java @@ -67,18 +67,26 @@ public class ConfigurationSet { calculateGroupProperty(childPropertyDefinition, sourceParentPropertyMaps, this.groupConfiguration); }
- public void applyGroupConfiguration() { + public void applyGroupConfigurationForView() { + applyGroupConfiguration(true); + } + + public void applyGroupConfigurationForUpdate() { + applyGroupConfiguration(false); + } + + private void applyGroupConfiguration(boolean forView) { if (this.members.isEmpty()) return; Map<String, PropertyDefinition> childPropertyDefinitions = this.configurationDefinition .getPropertyDefinitions(); - List<AbstractPropertyMap> sourceParentPropertyMaps = new ArrayList(); + List<AbstractPropertyMap> sourceParentPropertyMaps = new ArrayList<AbstractPropertyMap>(); for (ConfigurationSetMember member : this.members) sourceParentPropertyMaps.add(member.getConfiguration()); for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) - mergeProperty(childPropertyDefinition, sourceParentPropertyMaps, this.groupConfiguration); + mergeProperty(childPropertyDefinition, sourceParentPropertyMaps, this.groupConfiguration, forView); } - + public ConfigurationDefinition getConfigurationDefinition() { return configurationDefinition; } @@ -172,8 +180,23 @@ public class ConfigurationSet { // Also add it to each of the source config maps that don't already contain it, so that they can be // rendered as unset on the propSet page. for (AbstractPropertyMap map : sourceParentPropertyMaps) { - if (map.get(memberName) == null) - map.put(new PropertySimple(memberName, null)); + if (map.get(memberName) == null) { + PropertySimple sourceProperty = new PropertySimple(memberName, null); + //ok, this is highly confusing but we have no other way of "marking" + //this kind of property. + //We need to mark the property as not present in the original source map. + //This is different from having an unset value of course. + + //There is no other property on the Property class that we could use for this + //than the override. The confusion here is that the override property is used + //for the exact opposite reason on the target (i.e. the calculated group configuration), + //where it marks the fact that all the properties in the different resource configuration + //are set and have the same value. + //This works, because a member property is never also a calculated one, it can just confuse + //the casual reader of this code ;) + sourceProperty.setOverride(true); + map.put(sourceProperty); + } } Map<String, Integer> valueFrequencies = memberNameValueFrequenciesMap.get(memberName); if (valueFrequencies.size() == 1 @@ -187,7 +210,7 @@ public class ConfigurationSet { }
private static void mergeProperty(PropertyDefinition propertyDefinition, - List<AbstractPropertyMap> memberParentPropertyMaps, AbstractPropertyMap groupParentPropertyMap) { + List<AbstractPropertyMap> memberParentPropertyMaps, AbstractPropertyMap groupParentPropertyMap, boolean forView) { if (propertyDefinition instanceof PropertyDefinitionSimple) { PropertySimple propertySimple = groupParentPropertyMap.getSimple(propertyDefinition.getName()); if (propertySimple != null && propertySimple.getOverride() != null && propertySimple.getOverride()) { @@ -212,7 +235,7 @@ public class ConfigurationSet { PropertyMap groupPropertyMap = groupParentPropertyMap.getMap(propertyDefinition.getName()); groupParentPropertyMap.put(groupPropertyMap); mergePropertyMap((PropertyDefinitionMap) propertyDefinition, nestedSourceParentPropertyMaps, - groupPropertyMap); + groupPropertyMap, forView); } else if (propertyDefinition instanceof PropertyDefinitionList) { PropertyDefinitionList propertyDefinitionList = (PropertyDefinitionList) propertyDefinition; PropertyDefinition listMemberPropertyDefinition = propertyDefinitionList.getMemberDefinition(); @@ -225,18 +248,18 @@ public class ConfigurationSet { }
private static void mergePropertyMap(PropertyDefinitionMap propertyDefinitionMap, - List<AbstractPropertyMap> memberParentPropertyMaps, AbstractPropertyMap groupParentPropertyMap) { + List<AbstractPropertyMap> memberParentPropertyMaps, AbstractPropertyMap groupParentPropertyMap, boolean forView) { Map<String, PropertyDefinition> childPropertyDefinitions = propertyDefinitionMap.getPropertyDefinitions(); if (!childPropertyDefinitions.isEmpty()) { for (PropertyDefinition childPropertyDefinition : childPropertyDefinitions.values()) - mergeProperty(childPropertyDefinition, memberParentPropertyMaps, groupParentPropertyMap); + mergeProperty(childPropertyDefinition, memberParentPropertyMaps, groupParentPropertyMap, forView); } else { - mergeOpenPropertyMap(memberParentPropertyMaps, groupParentPropertyMap); + mergeOpenPropertyMap(memberParentPropertyMaps, groupParentPropertyMap, forView); } }
private static void mergeOpenPropertyMap(List<AbstractPropertyMap> memberParentPropertyMaps, - AbstractPropertyMap groupParentPropertyMap) { + AbstractPropertyMap groupParentPropertyMap, boolean forView) { for (String groupMemberPropertyName : groupParentPropertyMap.getMap().keySet()) { PropertySimple groupMemberProperty = groupParentPropertyMap.getSimple(groupMemberPropertyName); if (groupMemberProperty != null && groupMemberProperty.getOverride() != null @@ -251,6 +274,34 @@ public class ConfigurationSet { sourcePropertySimple.setStringValue(groupMemberProperty.getStringValue()); } } + } else if (!forView) { + //we have a non-homogenic property here and want to update the underlying configurations + //for update. This means that we want to erradicate all the open map properties from the + //underlying configs that are not assigned a value in the calculated group config. + //this to basically undo the appearance of there being all open map properties defined + //in all configurations in each of them. That is needed for the view purposes but leaving + //the configs like that will cause new properties with "empty" values introduced in all the + //resource configs in the group after update. + for (AbstractPropertyMap sourceParentPropertyMap : memberParentPropertyMaps) { + PropertySimple sourcePropertySimple = sourceParentPropertyMap.getSimple(groupMemberPropertyName); + if (sourcePropertySimple == null) { + //there was no such property there - just add it + sourcePropertySimple = new PropertySimple(groupMemberPropertyName, groupMemberProperty + .getStringValue()); + sourceParentPropertyMap.put(sourcePropertySimple); + } else { + //the members of open map are marked with override to signify that they have + //not been originally present in the member configuration. + //If this is true and the group property has null value, it means + //that the user has set no value for this property and thus it should + //be removed again from the member config. + if (groupMemberProperty.getStringValue() == null + && sourcePropertySimple.getOverride() != null && sourcePropertySimple.getOverride()) { + + sourceParentPropertyMap.getMap().remove(sourcePropertySimple.getName()); + } + } + } } } } diff --git a/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/propset/PropertySetRenderer.java b/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/propset/PropertySetRenderer.java index 1d802ef..6ca2650 100644 --- a/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/propset/PropertySetRenderer.java +++ b/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/propset/PropertySetRenderer.java @@ -97,7 +97,7 @@ public class PropertySetRenderer extends Renderer { // will not have been updated yet with any changes made to child UIInput values. String refresh = FacesContextUtility.getOptionalRequestParameter("refresh"); if (refresh != null && refresh.equals(ConfigRenderer.PROPERTY_SET_COMPONENT_ID)) { - propertySetComponent.getConfigurationSet().applyGroupConfiguration(); + propertySetComponent.getConfigurationSet().applyGroupConfigurationForView(); component.getChildren().clear(); }
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/group/EditGroupResourceConfigurationUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/group/EditGroupResourceConfigurationUIBean.java index 1ba9b78..ee1f175 100644 --- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/group/EditGroupResourceConfigurationUIBean.java +++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/group/EditGroupResourceConfigurationUIBean.java @@ -69,7 +69,7 @@ public class EditGroupResourceConfigurationUIBean extends AbstractGroupResourceC // so the managed bean doesn't have to worry about doing it. getConfigurationSet().unmask();
- getConfigurationSet().applyGroupConfiguration(); + getConfigurationSet().applyGroupConfigurationForUpdate(); getConfigurationManager().scheduleGroupResourceConfigurationUpdate( EnterpriseFacesContextUtility.getSubject(), getGroup().getId(), getResourceConfigurations());
diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/test/EditTestConfigurationUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/test/EditTestConfigurationUIBean.java index 0857a37..8e0955c 100644 --- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/test/EditTestConfigurationUIBean.java +++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/configuration/test/EditTestConfigurationUIBean.java @@ -34,7 +34,7 @@ public class EditTestConfigurationUIBean extends AbstractTestConfigurationUIBean public String updateConfiguration() { // Any values changed in the group config (i.e. via the inputs on the main page) need to be // applied to all member configs before persisting them. - getConfigurationSet().applyGroupConfiguration(); + getConfigurationSet().applyGroupConfigurationForUpdate(); // TODO (low priority): Persist the test config somewhere. FacesContextUtility.addMessage(FacesMessage.SEVERITY_INFO, "Configuration updated."); return Outcomes.SUCCESS; diff --git a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/group/EditGroupPluginConfigurationUIBean.java b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/group/EditGroupPluginConfigurationUIBean.java index d1f874a..00e5b2a 100644 --- a/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/group/EditGroupPluginConfigurationUIBean.java +++ b/modules/enterprise/gui/portal-war/src/main/java/org/rhq/enterprise/gui/inventory/group/EditGroupPluginConfigurationUIBean.java @@ -66,7 +66,7 @@ public class EditGroupPluginConfigurationUIBean extends AbstractGroupPluginConfi // TODO: See if there's some way for the config renderer to handle calling applyGroupConfiguration(), // so the managed bean doesn't have to worry about doing it. getConfigurationSet().unmask(); - getConfigurationSet().applyGroupConfiguration(); + getConfigurationSet().applyGroupConfigurationForUpdate(); getConfigurationManager().scheduleGroupPluginConfigurationUpdate( EnterpriseFacesContextUtility.getSubject(), getGroup().getId(), getPluginConfigurations()); } catch (Exception e) {
commit e2f3addc506daa15b3b1d969561dcd9ca836f3b5 Author: Lukas Krejci lkrejci@redhat.com Date: Wed Dec 15 15:50:40 2010 +0100
BZ 662662 - restore the ability to view/edit open maps by "faking" property definitions for the individual properties in the open map.
diff --git a/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/helper/ConfigurationUtility.java b/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/helper/ConfigurationUtility.java index a9214cc..73962f0 100644 --- a/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/helper/ConfigurationUtility.java +++ b/modules/core/gui/src/main/java/org/rhq/core/gui/configuration/helper/ConfigurationUtility.java @@ -26,6 +26,8 @@ import org.rhq.core.domain.configuration.definition.ConfigurationDefinition; import org.rhq.core.domain.configuration.definition.PropertyDefinition; import org.rhq.core.domain.configuration.definition.PropertyDefinitionList; import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap; +import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple; +import org.rhq.core.domain.configuration.definition.PropertySimpleType;
/** * @author Ian Springer @@ -42,7 +44,14 @@ public class ConfigurationUtility { Property subProperty = propertyHierarchy.get(i); if (propertyDefinition instanceof PropertyDefinitionMap) { - propertyDefinition = ((PropertyDefinitionMap)propertyDefinition).get(subProperty.getName()); + if (((PropertyDefinitionMap)propertyDefinition).getPropertyDefinitions().isEmpty()) { + //this is an open map, i.e. a map with no child definitions, meaning that any simple property + //can go in it. + //let's create a definition that mimics the current property... + propertyDefinition = new PropertyDefinitionSimple(subProperty.getName(), null, false, PropertySimpleType.STRING); + } else { + propertyDefinition = ((PropertyDefinitionMap)propertyDefinition).get(subProperty.getName()); + } } else if (propertyDefinition instanceof PropertyDefinitionList) { propertyDefinition = ((PropertyDefinitionList)propertyDefinition).getMemberDefinition(); }