Search in sources :

Example 46 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project spring-cloud-connectors by spring-cloud.

the class RedisJedisClientConfigurer method configurePool.

private void configurePool(JedisClientConfigurationBuilder clientConfiguration, PooledServiceConnectorConfig config) {
    if (config.getPoolConfig() != null) {
        JedisPoolConfig poolConfig = new JedisPoolConfig();
        BeanWrapper target = new BeanWrapperImpl(poolConfig);
        BeanWrapper source = new BeanWrapperImpl(config.getPoolConfig());
        Util.setCorrespondingProperties(target, source);
        clientConfiguration.usePooling().poolConfig(poolConfig);
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) JedisPoolConfig(redis.clients.jedis.JedisPoolConfig)

Example 47 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project spring-cloud-connectors by spring-cloud.

the class HikariCpPooledDataSourceCreator method setBasicDataSourceProperties.

protected void setBasicDataSourceProperties(DataSource basicDataSource, RelationalServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig, String driverClassName, String validationQuery) {
    BeanWrapper target = new BeanWrapperImpl(basicDataSource);
    target.setPropertyValue("driverClassName", driverClassName);
    target.setPropertyValue("jdbcUrl", serviceInfo.getJdbcUrl());
    if (validationQuery != null) {
        target.setPropertyValue("connectionTestQuery", validationQuery);
    }
    configurer.configure(basicDataSource, (DataSourceConfig) serviceConnectorConfig);
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl)

Example 48 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project spring-cloud-connectors by spring-cloud.

the class DataSourceConfigurer method configureConnection.

private void configureConnection(DataSource dataSource, DataSourceConfig config) {
    if (config.getConnectionConfiguration() != null) {
        BeanWrapper target = new BeanWrapperImpl(dataSource);
        BeanWrapper connectionSource = new BeanWrapperImpl(config.getConnectionConfiguration());
        setCorrespondingProperties(target, connectionSource);
    }
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl)

Example 49 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project midpoint by Evolveum.

the class ConnectorFactoryBuiltinImpl method generateConnectorConfigurationSchema.

private PrismSchema generateConnectorConfigurationSchema(ConnectorStruct struct) {
    Class<? extends ConnectorInstance> connectorClass = struct.connectorClass;
    PropertyDescriptor connectorConfigurationProp = UcfUtil.findAnnotatedProperty(connectorClass, ManagedConnectorConfiguration.class);
    MutablePrismSchema connectorSchema = prismContext.schemaFactory().createPrismSchema(struct.connectorObject.getNamespace());
    // Create configuration type - the type used by the "configuration" element
    MutablePrismContainerDefinition<?> configurationContainerDef = connectorSchema.createContainerDefinition(ResourceType.F_CONNECTOR_CONFIGURATION.getLocalPart(), SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_TYPE_LOCAL_NAME);
    Class<?> configurationClass = connectorConfigurationProp.getPropertyType();
    BeanWrapper configurationClassBean = new BeanWrapperImpl(configurationClass);
    for (PropertyDescriptor prop : configurationClassBean.getPropertyDescriptors()) {
        if (UcfUtil.hasAnnotation(prop, ConfigurationItem.class)) {
            ItemDefinition<?> itemDef = createConfigurationItemDefinition(configurationContainerDef, prop);
            LOGGER.trace("Configuration item definition for {}: {}", prop.getName(), itemDef);
        }
    }
    return connectorSchema;
}
Also used : BeanWrapper(org.springframework.beans.BeanWrapper) PropertyDescriptor(java.beans.PropertyDescriptor) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) MutablePrismSchema(com.evolveum.midpoint.prism.schema.MutablePrismSchema)

Example 50 with BeanWrapper

use of org.springframework.beans.BeanWrapper in project midpoint by Evolveum.

the class AbstractManagedConnectorInstance method applyConfigurationToConfigurationClass.

private void applyConfigurationToConfigurationClass(PrismContainerValue<?> configurationContainer) throws ConfigurationException {
    BeanWrapper connectorBean = new BeanWrapperImpl(this);
    PropertyDescriptor connectorConfigurationProp = UcfUtil.findAnnotatedProperty(connectorBean, ManagedConnectorConfiguration.class);
    if (connectorConfigurationProp == null) {
        return;
    }
    Class<?> configurationClass = connectorConfigurationProp.getPropertyType();
    Object configurationObject;
    try {
        configurationObject = configurationClass.getDeclaredConstructor().newInstance();
    } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        throw new ConfigurationException("Cannot instantiate configuration " + configurationClass);
    }
    BeanWrapper configurationClassBean = new BeanWrapperImpl(configurationObject);
    for (Item<?, ?> configurationItem : configurationContainer.getItems()) {
        ItemDefinition<?> configurationItemDefinition = configurationItem.getDefinition();
        String itemLocalName = configurationItem.getElementName().getLocalPart();
        if (configurationItemDefinition != null && configurationItemDefinition.isMultiValue()) {
            Object[] realValuesArray = configurationItem.getRealValuesArray(Object.class);
            configurationClassBean.setPropertyValue(itemLocalName, realValuesArray);
        } else {
            Object realValue = configurationItem.getRealValue();
            configurationClassBean.setPropertyValue(itemLocalName, realValue);
        }
    }
    connectorBean.setPropertyValue(connectorConfigurationProp.getName(), configurationObject);
}
Also used : BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) PropertyDescriptor(java.beans.PropertyDescriptor) InvocationTargetException(java.lang.reflect.InvocationTargetException) BeanWrapper(org.springframework.beans.BeanWrapper) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException)

Aggregations

BeanWrapper (org.springframework.beans.BeanWrapper)144 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)79 Test (org.junit.jupiter.api.Test)31 NumberTestBean (org.springframework.beans.testfixture.beans.NumberTestBean)21 BooleanTestBean (org.springframework.beans.testfixture.beans.BooleanTestBean)20 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)19 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)18 IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)18 TestBean (org.springframework.beans.testfixture.beans.TestBean)18 Consumes (javax.ws.rs.Consumes)16 PUT (javax.ws.rs.PUT)16 Path (javax.ws.rs.Path)16 PropertyEditorSupport (java.beans.PropertyEditorSupport)14 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)14 HashSet (java.util.HashSet)12 BeansException (org.springframework.beans.BeansException)12 PropertyDescriptor (java.beans.PropertyDescriptor)11 OnmsNode (org.opennms.netmgt.model.OnmsNode)9 Test (org.junit.Test)6 BigDecimal (java.math.BigDecimal)5