Package org.rhq.core.domain.common.composite

Examples of org.rhq.core.domain.common.composite.SystemSetting


            .getInternalName());

        // verify each new setting and persist them to the database
        // note that if a new setting is the same as the old one, we do nothing - leave the old entity as is
        for (Map.Entry<SystemSetting, String> e : settings.entrySet()) {
            SystemSetting prop = e.getKey();

            String value = e.getValue();

            if (!skipValidation) {
                verifyNewSystemConfigurationProperty(prop, value, settings);
            }

            SystemConfiguration existingConfig = existingConfigMap.get(prop.getInternalName());
            if (e.getKey() == SystemSetting.LAST_SYSTEM_CONFIG_UPDATE_TIME) {
                //we don't let the user persist their own last system config update time
                //in any manner
                lastUpdateTime = existingConfig;
            } else if (existingConfig == null) {
                value = transformSystemConfigurationPropertyToDb(prop, value, null);
                existingConfig = new SystemConfiguration(prop.getInternalName(), value);
                entityManager.persist(existingConfig);
                changed = true;
                existingConfigMap.put(existingConfig.getPropertyKey(), existingConfig);
            } else {
                //make sure we compare the new value with a database-agnostic value
                //it is important to compare in the database-agnostic format instead
                //of database specific because the conversion isn't reflective.
                //Some legacy code somewhere is (or just used to) store booleans as "0"s and "1"s
                //even though they are stored as strings and thus don't suffer from Oracle's
                //lack of support for boolean data type. If we encounter such values, we convert
                //them to "false"/"true" and store that value to database. This is a one way operation
                //and therefore we need to compare the database-agnostic (i.e. "true"/"false") and
                //not database specific.
                //
                //More importantly though, we store the password fields obfuscated, so we need to compare apples with
                //apples here.
                String existingValue = transformSystemConfigurationPropertyFromDb(prop,
                    existingConfig.getPropertyValue(), true);
                //we need to unmask the new value so that we can compare for changes. only after that can we transform
                //it into the DB format.
                value = unmask(prop, value, existingValue);

                //also for oracle, treat null and empty string as the same.
                if ((isEmpty(existingValue) && !isEmpty(value))
                    || (null != existingValue && !existingValue.equals(value))) {
                    //SystemSetting#isReadOnly should be a superset of the "fReadOnly" field in the database
                    //but let's just be super paranoid here...
                    if ((prop.isReadOnly() || (existingConfig.getFreadOnly() != null && existingConfig.getFreadOnly()
                        .booleanValue())) && !(isStorageSetting(prop) || ignoreReadOnly)) {
                        throw new IllegalArgumentException("The setting [" + prop.getInternalName()
                            + "] is read-only - you cannot change its current value! Current value is ["
                            + existingConfig.getPropertyValue() + "] while the new value was [" + value + "].");
                    }

                    //transform to the database-specific format
View Full Code Here


        return map;
    }

    private void transformToSystemSettingsFormat(Map<String, String> map) {
        for (Map.Entry<String, String> e : map.entrySet()) {
            SystemSetting prop = SystemSetting.getByInternalName(e.getKey());
            if (prop != null) {
                //this is a legacy method that supplies values in the DB-specific format.
                //we therefore have to transform the values as if they came from the database.
                String value = transformSystemConfigurationPropertyFromDb(prop, e.getValue(), false);
                e.setValue(value);
View Full Code Here

        transformToSystemSettingsFormat(map);

        SystemSettings settings = SystemSettings.fromMap(map);
        for (Map.Entry<SystemSetting, String> e : settings.entrySet()) {
            SystemSetting prop = e.getKey();
            String value = e.getValue();

            verifyNewSystemConfigurationProperty(prop, value, settings);
        }
    }
View Full Code Here

    private void fillCache(Collection<SystemConfiguration> configs) {
        SystemSettings settings = new SystemSettings();

        for (SystemConfiguration config : configs) {
            SystemSetting prop = SystemSetting.getByInternalName(config.getPropertyKey());
            if (prop == null) {
                LOG.warn("The database contains unknown system configuration setting [" + config.getPropertyKey()
                    + "].");
                continue;
            }
View Full Code Here

        Properties properties = null;
        if (systemSettings != null) {
            properties = new Properties();
            Set<Entry<SystemSetting, String>> entries = systemSettings.entrySet();
            for (Entry<SystemSetting, String> entry : entries) {
                SystemSetting key = entry.getKey();
                if (key != null) {
                    String value = entry.getValue();
                    if (value != null) {
                        properties.put(key.name(), value);
                    }
                }
            }
            //now load default/shared LDAP properties as we always have
            // Set our default factory name if one is not given
View Full Code Here

    private void checkFormats(SystemSettings settings, Properties config) {
        assert settings.size() == config.size() : "The old and new style system settings differ in size";

        for (String name : config.stringPropertyNames()) {
            SystemSetting setting = SystemSetting.getByInternalName(name);

            String oldStyleValue = config.getProperty(name);
            String newStyleValue = settings.get(setting);

            assert setting != null : "Could not find a system setting called '" + name + "'.";
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.common.composite.SystemSetting

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.