@@ -703,6 +703,10 @@ public boolean stop() {
703
703
@ Override
704
704
@ DB
705
705
public String updateConfiguration (final long userId , final String name , final String category , String value , final String scope , final Long resourceId ) {
706
+ if (Boolean .class == getConfigurationTypeWrapperClass (name )) {
707
+ value = value .toLowerCase ();
708
+ }
709
+
706
710
final String validationMsg = validateConfigurationValue (name , value , scope );
707
711
if (validationMsg != null ) {
708
712
logger .error ("Invalid value [{}] for configuration [{}] due to [{}]." , value , name , validationMsg );
@@ -1241,18 +1245,9 @@ protected String validateConfigurationValue(String name, String value, String sc
1241
1245
return "Invalid scope id provided for the parameter " + name ;
1242
1246
}
1243
1247
}
1244
- Class <?> type ;
1245
- Config configuration = Config .getConfig (name );
1246
- if (configuration == null ) {
1247
- logger .warn ("Did not find configuration " + name + " in Config.java. Perhaps moved to ConfigDepot" );
1248
- ConfigKey <?> configKey = _configDepot .get (name );
1249
- if (configKey == null ) {
1250
- logger .warn ("Did not find configuration " + name + " in ConfigDepot too." );
1251
- return null ;
1252
- }
1253
- type = configKey .type ();
1254
- } else {
1255
- type = configuration .getType ();
1248
+ Class <?> type = getConfigurationTypeWrapperClass (name );
1249
+ if (type == null ) {
1250
+ return null ;
1256
1251
}
1257
1252
1258
1253
validateSpecificConfigurationValues (name , value , type );
@@ -1262,7 +1257,28 @@ protected String validateConfigurationValue(String name, String value, String sc
1262
1257
return String .format ("Value [%s] is not a valid [%s]." , value , type );
1263
1258
}
1264
1259
1265
- return validateValueRange (name , value , type , configuration );
1260
+ return validateValueRange (name , value , type , Config .getConfig (name ));
1261
+ }
1262
+
1263
+ /**
1264
+ * Returns the configuration type's wrapper class.
1265
+ * @param name name of the configuration.
1266
+ * @return if the configuration exists, returns its type's wrapper class; if not, returns null.
1267
+ */
1268
+ protected Class <?> getConfigurationTypeWrapperClass (String name ) {
1269
+ Config configuration = Config .getConfig (name );
1270
+ if (configuration != null ) {
1271
+ return configuration .getType ();
1272
+ }
1273
+
1274
+ logger .warn ("Did not find configuration [{}] in Config.java. Perhaps moved to ConfigDepot." , name );
1275
+ ConfigKey <?> configKey = _configDepot .get (name );
1276
+ if (configKey == null ) {
1277
+ logger .warn ("Did not find configuration [{}] in ConfigDepot too." , name );
1278
+ return null ;
1279
+ }
1280
+
1281
+ return configKey .type ();
1266
1282
}
1267
1283
1268
1284
protected void validateConfigurationAllowedOnlyForDefaultAdmin (String configName , String value ) {
@@ -1299,7 +1315,7 @@ protected void validateConfigurationAllowedOnlyForDefaultAdmin(String configName
1299
1315
* <ul>
1300
1316
* <li>String: any value, including null;</li>
1301
1317
* <li>Character: any value, including null;</li>
1302
- * <li>Boolean: strings that equal "true" or "false" (case-sensitive );</li>
1318
+ * <li>Boolean: strings that equal "true" or "false" (case-insensitive );</li>
1303
1319
* <li>Integer, Short, Long: strings that contain a valid int/short/long;</li>
1304
1320
* <li>Float, Double: strings that contain a valid float/double, except infinity.</li>
1305
1321
* </ul>
@@ -8176,36 +8192,32 @@ public ConfigKey<?>[] getConfigKeys() {
8176
8192
};
8177
8193
}
8178
8194
8195
+
8196
+ /**
8197
+ * Returns a string representing the specified configuration's type.
8198
+ * @param configName name of the configuration.
8199
+ * @return if the configuration exists, returns its type; if not, returns {@link Configuration.ValueType#String}.
8200
+ */
8179
8201
@ Override
8180
8202
public String getConfigurationType (final String configName ) {
8181
8203
final ConfigurationVO cfg = _configDao .findByName (configName );
8182
8204
if (cfg == null ) {
8183
- logger .warn ("Configuration " + configName + " not found" );
8205
+ logger .warn ("Configuration [{}] not found" , configName );
8184
8206
return Configuration .ValueType .String .name ();
8185
8207
}
8186
8208
8187
8209
if (weightBasedParametersForValidation .contains (configName )) {
8188
8210
return Configuration .ValueType .Range .name ();
8189
8211
}
8190
8212
8191
- Class <?> type = null ;
8192
- final Config c = Config .getConfig (configName );
8193
- if (c == null ) {
8194
- logger .warn ("Configuration " + configName + " no found. Perhaps moved to ConfigDepot" );
8195
- final ConfigKey <?> configKey = _configDepot .get (configName );
8196
- if (configKey == null ) {
8197
- logger .warn ("Couldn't find configuration " + configName + " in ConfigDepot too." );
8198
- return Configuration .ValueType .String .name ();
8199
- }
8200
- type = configKey .type ();
8201
- } else {
8202
- type = c .getType ();
8203
- }
8204
-
8205
- return getInputType (type , cfg );
8213
+ Class <?> type = getConfigurationTypeWrapperClass (configName );
8214
+ return parseConfigurationTypeIntoString (type , cfg );
8206
8215
}
8207
8216
8208
- private String getInputType (Class <?> type , ConfigurationVO cfg ) {
8217
+ /**
8218
+ * Parses a configuration type's wrapper class into its string representation.
8219
+ */
8220
+ protected String parseConfigurationTypeIntoString (Class <?> type , ConfigurationVO cfg ) {
8209
8221
if (type == null ) {
8210
8222
return Configuration .ValueType .String .name ();
8211
8223
}
0 commit comments