Search in sources :

Example 6 with ConfigurationPropertyName

use of org.springframework.boot.context.properties.source.ConfigurationPropertyName in project spring-boot by spring-projects.

the class ConfigurationPropertiesReportEndpoint method applyInput.

private Map<String, Object> applyInput(String qualifiedKey) {
    ConfigurationPropertyName currentName = getCurrentName(qualifiedKey);
    ConfigurationProperty candidate = getCandidate(currentName);
    PropertySource<?> propertySource = getPropertySource(candidate);
    if (propertySource != null) {
        Object value = stringifyIfNecessary(candidate.getValue());
        SanitizableData data = new SanitizableData(propertySource, currentName.toString(), value);
        return getInput(candidate, this.sanitizer.sanitize(data));
    }
    return Collections.emptyMap();
}
Also used : ConfigurationProperty(org.springframework.boot.context.properties.source.ConfigurationProperty) ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName) SanitizableData(org.springframework.boot.actuate.endpoint.SanitizableData)

Example 7 with ConfigurationPropertyName

use of org.springframework.boot.context.properties.source.ConfigurationPropertyName in project spring-boot by spring-projects.

the class ValidationErrorsTests method getErrorsShouldAdaptFieldErrorsToBeOriginProviders.

@Test
void getErrorsShouldAdaptFieldErrorsToBeOriginProviders() {
    Set<ConfigurationProperty> boundProperties = new LinkedHashSet<>();
    ConfigurationPropertyName name1 = ConfigurationPropertyName.of("foo.bar");
    Origin origin1 = MockOrigin.of("line1");
    boundProperties.add(new ConfigurationProperty(name1, "boot", origin1));
    ConfigurationPropertyName name2 = ConfigurationPropertyName.of("foo.baz.bar");
    Origin origin2 = MockOrigin.of("line2");
    boundProperties.add(new ConfigurationProperty(name2, "boot", origin2));
    List<ObjectError> allErrors = new ArrayList<>();
    allErrors.add(new FieldError("objectname", "bar", "message"));
    ValidationErrors errors = new ValidationErrors(ConfigurationPropertyName.of("foo.baz"), boundProperties, allErrors);
    assertThat(Origin.from(errors.getAllErrors().get(0))).isEqualTo(origin2);
}
Also used : ConfigurationProperty(org.springframework.boot.context.properties.source.ConfigurationProperty) LinkedHashSet(java.util.LinkedHashSet) Origin(org.springframework.boot.origin.Origin) MockOrigin(org.springframework.boot.origin.MockOrigin) ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName) ObjectError(org.springframework.validation.ObjectError) ArrayList(java.util.ArrayList) FieldError(org.springframework.validation.FieldError) Test(org.junit.jupiter.api.Test)

Example 8 with ConfigurationPropertyName

use of org.springframework.boot.context.properties.source.ConfigurationPropertyName in project spring-boot by spring-projects.

the class IndexedElementsBinder method getKnownIndexedChildren.

private MultiValueMap<String, ConfigurationPropertyName> getKnownIndexedChildren(ConfigurationPropertySource source, ConfigurationPropertyName root) {
    MultiValueMap<String, ConfigurationPropertyName> children = new LinkedMultiValueMap<>();
    if (!(source instanceof IterableConfigurationPropertySource)) {
        return children;
    }
    for (ConfigurationPropertyName name : (IterableConfigurationPropertySource) source.filter(root::isAncestorOf)) {
        ConfigurationPropertyName choppedName = name.chop(root.getNumberOfElements() + 1);
        if (choppedName.isLastElementIndexed()) {
            String key = choppedName.getLastElement(Form.UNIFORM);
            children.add(key, name);
        }
    }
    return children;
}
Also used : IterableConfigurationPropertySource(org.springframework.boot.context.properties.source.IterableConfigurationPropertySource) ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap)

Example 9 with ConfigurationPropertyName

use of org.springframework.boot.context.properties.source.ConfigurationPropertyName in project spring-boot by spring-projects.

the class NoUnboundElementsBindHandler method isOverriddenCollectionElement.

private boolean isOverriddenCollectionElement(ConfigurationPropertyName candidate) {
    int lastIndex = candidate.getNumberOfElements() - 1;
    if (candidate.isLastElementIndexed()) {
        ConfigurationPropertyName propertyName = candidate.chop(lastIndex);
        return this.boundNames.contains(propertyName);
    }
    Indexed indexed = getIndexed(candidate);
    if (indexed != null) {
        String zeroethProperty = indexed.getName() + "[0]";
        if (this.boundNames.contains(ConfigurationPropertyName.of(zeroethProperty))) {
            String nestedZeroethProperty = zeroethProperty + "." + indexed.getNestedPropertyName();
            return isCandidateValidPropertyName(nestedZeroethProperty);
        }
    }
    return false;
}
Also used : ConfigurationPropertyName(org.springframework.boot.context.properties.source.ConfigurationPropertyName)

Aggregations

ConfigurationPropertyName (org.springframework.boot.context.properties.source.ConfigurationPropertyName)9 Test (org.junit.jupiter.api.Test)4 ConfigurationProperty (org.springframework.boot.context.properties.source.ConfigurationProperty)4 ArrayList (java.util.ArrayList)2 SanitizableData (org.springframework.boot.actuate.endpoint.SanitizableData)2 Origin (org.springframework.boot.origin.Origin)2 LinkedHashSet (java.util.LinkedHashSet)1 BindContext (org.springframework.boot.context.properties.bind.BindContext)1 BindHandler (org.springframework.boot.context.properties.bind.BindHandler)1 Bindable (org.springframework.boot.context.properties.bind.Bindable)1 Binder (org.springframework.boot.context.properties.bind.Binder)1 ValidationBindHandler (org.springframework.boot.context.properties.bind.validation.ValidationBindHandler)1 IterableConfigurationPropertySource (org.springframework.boot.context.properties.source.IterableConfigurationPropertySource)1 MockConfigurationPropertySource (org.springframework.boot.context.properties.source.MockConfigurationPropertySource)1 MockOrigin (org.springframework.boot.origin.MockOrigin)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)1 FieldError (org.springframework.validation.FieldError)1 ObjectError (org.springframework.validation.ObjectError)1