protected String getAugeasPathRelativeToParent(PropertyDefinition propDef, AugeasNode parentNode, Augeas augeas) { return propDef.getName(); }
/** * Check if the Kind of Definition and Property match. I.e. if a PropertyMap corresponds to a PropertyDefinitionMap * @param propDef PropertyDefinition to match * @param property Property to match with the definition * @param messages List of messages to add validation errors to. * @return true if the kinds are matching */ private static boolean checkIfCompatible(final PropertyDefinition propDef, final Property property, final List<String> messages) { boolean good = false ; if (propDef instanceof PropertyDefinitionSimple && property instanceof PropertySimple) { good = true; } else if (propDef instanceof PropertyDefinitionMap && property instanceof PropertyMap) { good = true; } else if (propDef instanceof PropertyDefinitionList && property instanceof PropertyList) { good = true; } if (!good) { String name = propDef.getName(); messages.add("The type of property for [" + name + "] does not match the definition"); } return good; } }
public void put(PropertyDefinition propertyDefinition) { if (this.propertyDefinitions == null) { this.propertyDefinitions = new LinkedHashMap<String, PropertyDefinition>(); } this.propertyDefinitions.put(propertyDefinition.getName(), propertyDefinition); propertyDefinition.setConfigurationDefinition(this); }
private static PropertyType conforms(Property p, PropertyDefinition d) { if (p == null) { return PropertyType.UNKNOWN; } if (!p.getName().equals(d.getName())) { return null; } if (p instanceof PropertySimple && d instanceof PropertyDefinitionSimple) { return PropertyType.SIMPLE; } else if (p instanceof PropertyList && d instanceof PropertyDefinitionList) { return PropertyType.LIST; } else if (p instanceof PropertyMap && d instanceof PropertyDefinitionMap) { return PropertyType.MAP; } else if (p instanceof PropertySimple && d instanceof PropertyDefinitionDynamic) { return PropertyType.DYNAMIC; } else { return null; } }
private Boolean isOverride(PropertyDefinition propertyDefinition) { if (!(propertyDefinition instanceof PropertyDefinitionSimple)) { return false; } Property property = this.propertyMap.get(propertyDefinition.getName()); if (property == null) { return false; } Boolean override = ((PropertySimple) property).getOverride(); return ((override != null) && override); }
private boolean isPropertyDefined(PropertyDefinition propDef, AbstractPropertyMap parentPropMap) { Property prop = parentPropMap.get(propDef.getName()); if (prop == null) { return false; } else { return (!(prop instanceof PropertySimple) || ((PropertySimple) prop).getStringValue() != null); } }
public static ValueExpression createValueExpressionForPropertyDefiniton( String configurationDefinitionExpressionString, PropertyDefinition propertyDefinition) { StringBuilder stringBuilder = new StringBuilder("#{"); stringBuilder.append(FacesExpressionUtility.unwrapExpressionString(configurationDefinitionExpressionString)); LinkedList<PropertyDefinition> propertyDefinitionHierarchy = getPropertyDefinitionHierarchy(propertyDefinition); for (PropertyDefinition subPropertyDefinition : propertyDefinitionHierarchy) { PropertyDefinition parentPropertyDefinition = getParentPropertyDefinition(subPropertyDefinition); stringBuilder.append("."); if (parentPropertyDefinition == null || parentPropertyDefinition instanceof PropertyDefinitionMap) { // top-level property or map member property stringBuilder.append("propertyDefinitions['").append(subPropertyDefinition.getName()).append("']"); } else { // list member property stringBuilder.append("memberDefinition"); } } stringBuilder.append("}"); @SuppressWarnings({"UnnecessaryLocalVariable"}) ValueExpression valueExpression = FacesExpressionUtility.createValueExpression(stringBuilder.toString(), PropertyDefinition.class); return valueExpression; }
private static void traverse(PropertyDefinitionMap definition, PropertyMap map, List<PropertySimple> replacementCandidates) { for(PropertyDefinition def: definition.getMap().values()) { Property prop = map.get(def.getName()); propertySwitch(def, prop, replacementCandidates); } }
/** * Check that the passed configuration is valid wrt the passed definition * @param configuration A Configuration to check * @param definition A Definition to check the Configuration against * @return List of validation failure messages. List is empty if no errors were found. */ public static List<String> checkConfigurationWrtDefinition(Configuration configuration, ConfigurationDefinition definition) { List<String> messages = new ArrayList<String>(); if (configuration==null) { messages.add("Configuration is null"); } if (definition==null) { messages.add("Definition is null"); } if (configuration==null || definition==null) { return messages; } // Basic validation is done, now have a look at the properties for (PropertyDefinition propDef : definition.getPropertyDefinitions().values()) { String name = propDef.getName(); Property property = configuration.get(name); checkProperty(messages, propDef, property); } return messages; }
/** * @param def * @return Map of propertyName to types for the config def * @throws NotFoundException */ public static LinkedHashMap<String, CtClass> translateParameters(ClassPool cp, ConfigurationDefinition def) throws NotFoundException { LinkedHashMap<String, CtClass> result = new LinkedHashMap<String, CtClass>(); if (def == null || def.getPropertyDefinitions() == null) { return result; } for (PropertyDefinition pd : def.getPropertyDefinitions().values()) { if (pd instanceof PropertyDefinitionSimple) { PropertyDefinitionSimple simple = (PropertyDefinitionSimple) pd; String name = pd.getName(); CtClass paramType = getSimpleTypeClass(cp, simple); result.put(name, paramType); } } return result; }
private static void validatePropertySimple(PropertyDefinition propertyDefinition, PropertySimple propertySimple, PropertySimple currentPropertySimple, List<String> errorMessages) { // make sure required properties have a value if (propertyDefinition.isRequired() && (propertySimple.getStringValue() == null)) { errorMessages.add("Required property '" + propertyDefinition.getName() + "' has a null value."); propertySimple.setStringValue(""); } // make sure readOnly properties are not being changed if (propertyDefinition.isReadOnly() && null != currentPropertySimple) { String currentValue = currentPropertySimple.getStringValue(); // if there is no current value allow an initial value to be set for the readOnly property. if (!(null == currentValue || currentValue.trim().isEmpty() || propertySimple.getStringValue().equals( currentValue))) { errorMessages.add("ReadOnly property '" + propertyDefinition.getName() + "' has a value [" + propertySimple.getStringValue() + "] different than the current value [" + currentValue + "]. It is not allowed to change."); } } }
private boolean isInvalidRequiredProperty(PropertyDefinition propertyDefinition) { boolean isInvalidRequiredProperty = false; if ((propertyDefinition instanceof PropertyDefinitionSimple) && propertyDefinition.isRequired()) { PropertySimple propertySimple = this.propertyMap.getSimple(propertyDefinition.getName()); String errorMessage = propertySimple.getErrorMessage(); if ((null == propertySimple.getStringValue()) || "".equals(propertySimple.getStringValue()) || ((null != errorMessage) && (!"".equals(errorMessage.trim())))) { // Required properties with no value, or an invalid value (assumed if we see an error message) should never // be set to read-only, otherwise the user will have no way to give the property a value and thereby // get things to a valid state. isInvalidRequiredProperty = true; } } return isInvalidRequiredProperty; }
public static void obfuscatePasswords(ConfigurationDefinition definition, Configuration config) { if (config == null || config.getMap().isEmpty()) { return; } if (definition == null || definition.getPropertyDefinitions().isEmpty()) { return; } List<PropertySimple> replacementCandidates = new ArrayList<PropertySimple>(); for(PropertyDefinition def : definition.getPropertyDefinitions().values()) { Property prop = config.get(def.getName()); propertySwitch(def, prop, replacementCandidates); } for(PropertySimple prop : replacementCandidates) { replace(prop); } }
private void ensureDisplayNameIsSet(RecipeParseResults recipeParseResults) { if (recipeParseResults != null && recipeParseResults.getConfigurationDefinition() != null) { ConfigurationDefinition configDef = recipeParseResults.getConfigurationDefinition(); for (PropertyDefinition propDef : configDef.getPropertyDefinitions().values()) { if (propDef instanceof PropertyDefinitionSimple) { if (propDef.getDisplayName() == null) { propDef.setDisplayName(propDef.getName()); } } } } return; } }
/** * This default setup of configuration properties can map to mbean attributes * * @return the configuration of the component */ public Configuration loadResourceConfiguration() { Configuration configuration = new Configuration(); ConfigurationDefinition configurationDefinition = this.resourceContext.getResourceType() .getResourceConfigurationDefinition(); for (PropertyDefinition property : configurationDefinition.getPropertyDefinitions().values()) { if (property instanceof PropertyDefinitionSimple) { EmsAttribute attribute = getEmsBean().getAttribute(property.getName()); if (attribute != null) { configuration.put(new PropertySimple(property.getName(), attribute.refresh())); } } } return configuration; }
/** * checks if plugin configuration has set all required properties * @param plugin * @throws PluginConfigurationRequiredException if plugin is missing required configuration * @throws Exception in case of any other error */ private void checkForRequiredConfiguration(ServerPlugin plugin) throws Exception { ConfigurationDefinition configDef = getServerPluginConfigurationDefinition(new PluginKey(plugin)); Configuration configuration = plugin.getPluginConfiguration(); for (PropertyDefinition propDef : configDef.getPropertyDefinitions().values()) { if (propDef.isRequired() && propDef instanceof PropertyDefinitionSimple) { Property prop = configuration.get(propDef.getName()); PropertySimple simple = (PropertySimple) prop; if (simple == null || simple.getStringValue() == null || "".equals(simple.getStringValue())) { throw new PluginConfigurationRequiredException("Plugin [" + plugin.getDisplayName() + "] could not be enabled, because some required configuration fields are not set."); } } } }
/** * Copies the parameters of an OperationDefinition into to an object that can be * returned to a REST-client, so that this knows which fields are to be filled in, * of which type they are and which ones are required * @param def OperationsDefinition to "copy" * @param definitionRest The definition to fill in */ private void copyParamsForDefinition(OperationDefinition def, OperationDefinitionRest definitionRest) { ConfigurationDefinition cd = def.getParametersConfigurationDefinition(); if (cd==null) { return; } for (Map.Entry<String,PropertyDefinition> entry : cd.getPropertyDefinitions().entrySet()) { PropertyDefinition pd = entry.getValue(); if (pd instanceof PropertyDefinitionSimple) { PropertyDefinitionSimple pds = (PropertyDefinitionSimple) pd; SimplePropDef prop = new SimplePropDef(); prop.setName(pds.getName()); prop.setRequired(pds.isRequired()); prop.setType(pds.getType()); prop.setDefaultValue(pds.getDefaultValue()); definitionRest.addParam(prop); } log.debug("copyParams: " + pd.getName() + " not yet supported"); } }
private void addPropertyMapSummaryDataCells(UIComponent parent, PropertyDefinitionMap listMemberMapPropertyDefinition, PropertyMap listMemberMapProperty) { for (PropertyDefinition summaryPropertyDefinition : listMemberMapPropertyDefinition .getSummaryPropertyDefinitions()) { Property mapMemberProperty = listMemberMapProperty.get(summaryPropertyDefinition.getName()); if (!(mapMemberProperty instanceof PropertySimple)) { throw new IllegalStateException("Property '" + mapMemberProperty.getName() + "' is defined as a map of simples but contains one or more non-simple members."); } PropertySimple mapMemberSimpleProperty = (PropertySimple) mapMemberProperty; FacesComponentUtility.addVerbatimText(parent, "<td class='" + PROPERTY_MAP_SUMMARY_DATA_CELL_STYLE_CLASS + "'>"); if (mapMemberSimpleProperty.getStringValue() == null) { FacesComponentUtility.addOutputText(parent, this.config, "not set", CssStyleClasses.REQUIRED_MARKER_TEXT); } else { FacesComponentUtility.addOutputText(parent, this.config, mapMemberSimpleProperty.getStringValue(), PROPERTY_MAP_SUMMARY_DATA_TEXT_STYLE_CLASS); } FacesComponentUtility.addVerbatimText(parent, "</td>\n"); } }