@@ -1113,16 +1113,17 @@ def get_model_uses_path_tokens_attribute_names(self, location, only_readable=Fal
1113
1113
# Although the wlst_attribute_value may be a password field, logging it is probably OK since the password is
1114
1114
# encrypted, just like it is in config.xml.
1115
1115
#
1116
- def get_model_attribute_name_and_value (self , location , wlst_attribute_name , wlst_attribute_value ):
1116
+ def get_model_attribute_name_and_value (self , location , wlst_attribute_name , wlst_attribute_value ,
1117
+ ignore_default_match = False ):
1117
1118
"""
1118
1119
Returns the model attribute name and value for the specified WLST attribute name and value.
1119
-
1120
- model_attribute_value will be set to None, if value assigned to wlst_attribute_value arg
1121
- is the default value for model_attribute_name.
1120
+ By default, the model value returned will be None if it matches the default value.
1121
+ If ignore_default_match is True, the model value will be returned regardless of the default value.
1122
1122
:param location: the location
1123
1123
:param wlst_attribute_name: the WLST attribute name
1124
1124
:param wlst_attribute_value: the WLST attribute value
1125
- :return: the name and value
1125
+ :param ignore_default_match: if True, return the model value regardless of the default value
1126
+ :return: the model attribute name and value
1126
1127
:raises: Tool type exception: if an error occurs
1127
1128
"""
1128
1129
_method_name = 'get_model_attribute_name_and_value'
@@ -1131,77 +1132,26 @@ def get_model_attribute_name_and_value(self, location, wlst_attribute_name, wlst
1131
1132
1132
1133
try :
1133
1134
model_attribute_name = None
1134
- # Assume wlst_attribute_value is the same as default value of model_attribute_name
1135
1135
model_attribute_value = None
1136
1136
1137
1137
attribute_info = self ._alias_entries .get_alias_attribute_entry_by_wlst_name (location , wlst_attribute_name )
1138
1138
if attribute_info is not None and not self .__is_model_attribute_ignored (location , attribute_info ):
1139
- data_type , preferred_type , delimiter = \
1140
- alias_utils .compute_read_data_type_for_wlst_and_delimiter_from_attribute_info (attribute_info ,
1141
- wlst_attribute_value )
1142
- model_type = data_type
1143
- if preferred_type :
1144
- model_type = preferred_type
1145
-
1146
- converted_value = alias_utils .convert_to_model_type (model_type , wlst_attribute_value ,
1147
- delimiter = delimiter )
1148
-
1149
1139
model_attribute_name = attribute_info [MODEL_NAME ]
1150
- default_value = self ._get_default_value_for_execution_mode (attribute_info )
1151
1140
1152
- #
1153
- # The logic below to compare the str() representation of the converted value and the default value
1154
- # only works for lists/maps if both the converted value and the default value are the same data type...
1155
- #
1156
- if (model_type in ALIAS_LIST_TYPES or model_type in ALIAS_MAP_TYPES ) \
1157
- and not (default_value == '[]' or default_value is None ):
1158
- # always the model delimiter
1159
- default_value = alias_utils .convert_to_type (model_type , default_value ,
1160
- delimiter = MODEL_LIST_DELIMITER )
1161
-
1162
- if attribute_info [WLST_TYPE ] == STRING and default_value :
1163
- default_value = alias_utils .replace_tokens_in_path (location , default_value )
1164
-
1165
- if model_type == 'password' :
1166
- # WDT doesn't really understand PyArray so convert it to a string before proceeding.
1167
- if isinstance (wlst_attribute_value , array .array ):
1168
- wlst_attribute_value = wlst_attribute_value .tostring ()
1169
-
1170
- if string_utils .is_empty (wlst_attribute_value ) or converted_value == default_value :
1171
- model_attribute_value = None
1172
- else :
1173
- model_attribute_value = wlst_attribute_value
1174
-
1175
- elif model_type == 'boolean' :
1176
- # some boolean attributes have WLST value of null until they are set
1177
- wlst_boolean = _get_boolean_or_none (wlst_attribute_value ) # from unconverted value
1178
- default_boolean = _get_boolean_or_none (default_value )
1179
- if wlst_boolean == default_boolean :
1180
- model_attribute_value = None
1181
- else :
1182
- model_attribute_value = converted_value
1141
+ wlst_type , preferred_type , delimiter = \
1142
+ alias_utils .compute_read_data_type_for_wlst_and_delimiter_from_attribute_info (
1143
+ attribute_info , wlst_attribute_value )
1183
1144
1184
- elif (model_type in ALIAS_LIST_TYPES or data_type in ALIAS_MAP_TYPES ) and \
1185
- (converted_value is None or len (converted_value ) == 0 ):
1186
- if default_value == '[]' or default_value is None :
1187
- model_attribute_value = None
1188
-
1189
- elif self ._model_context is not None and USES_PATH_TOKENS in attribute_info :
1190
- if attribute_info [WLST_TYPE ] == STRING :
1191
- model_attribute_value = self ._model_context .tokenize_path (converted_value )
1192
- else :
1193
- model_attribute_value = self ._model_context .tokenize_classpath (converted_value )
1194
- if model_attribute_value == default_value :
1195
- model_attribute_value = None
1145
+ model_type = wlst_type
1146
+ if preferred_type :
1147
+ model_type = preferred_type
1196
1148
1197
- elif default_value is None :
1198
- model_attribute_value = converted_value
1149
+ default_value = None
1150
+ if not ignore_default_match :
1151
+ default_value = self ._get_model_attribute_default_value (location , attribute_info , model_type )
1199
1152
1200
- elif str_helper .to_string (converted_value ) != str_helper .to_string (default_value ):
1201
- if _strings_are_empty (converted_value , default_value ):
1202
- model_attribute_value = None
1203
- else :
1204
- model_attribute_value = converted_value
1153
+ model_attribute_value = self ._get_model_attribute_value (
1154
+ wlst_attribute_value , default_value , attribute_info , model_type , delimiter )
1205
1155
1206
1156
self ._logger .exiting (class_name = self ._class_name , method_name = _method_name ,
1207
1157
result = {model_attribute_name : model_attribute_value })
@@ -1211,6 +1161,82 @@ def get_model_attribute_name_and_value(self, location, wlst_attribute_name, wlst
1211
1161
self ._raise_exception (ae , _method_name , 'WLSDPLY-19028' , str_helper .to_string (location ),
1212
1162
ae .getLocalizedMessage ())
1213
1163
1164
+ def _get_model_attribute_default_value (self , location , attribute_info , model_type ):
1165
+ """
1166
+ Returns the default value for the specified attribute_info and location.
1167
+ The default value may need some adjustments to be used for comparison with the model value.
1168
+ :param location: the location of the attribute
1169
+ :param attribute_info: information about the attribute from the aliases
1170
+ :param model_type: the model type to use for any conversion
1171
+ :return: the default value
1172
+ """
1173
+ default_value = self ._get_default_value_for_execution_mode (attribute_info )
1174
+
1175
+ # The compare logic compares the str() representation of the converted value and the default value
1176
+ # only works for lists/maps if both the converted value and the default value are the same data type...
1177
+ if (model_type in ALIAS_LIST_TYPES or model_type in ALIAS_MAP_TYPES ) \
1178
+ and not (default_value == '[]' or default_value is None ):
1179
+
1180
+ default_value = alias_utils .convert_to_type (
1181
+ model_type , default_value , delimiter = MODEL_LIST_DELIMITER ) # always the model delimiter
1182
+
1183
+ if attribute_info [WLST_TYPE ] == STRING and default_value :
1184
+ # the alias default may contain location tokens, such as "logs/%SERVERTEMPLATE%.log"
1185
+ default_value = alias_utils .replace_tokens_in_path (location , default_value )
1186
+
1187
+ return default_value
1188
+
1189
+ def _get_model_attribute_value (self , wlst_value , default_value , attribute_info , model_type , delimiter ):
1190
+ """
1191
+ Returns the model attribute value for the specified WLST value and default value.
1192
+ The model value returned will be None if it matches the default model value.
1193
+ :param wlst_value: the attribute value from WLST
1194
+ :param default_value: the default value to use for comparison
1195
+ :param attribute_info: information about the attribute from the aliases
1196
+ :param model_type: the model type to use for any conversion
1197
+ :param delimiter: the delimiter used for parsing the WLST value
1198
+ :return: the value for use in the model
1199
+ """
1200
+ converted_value = alias_utils .convert_to_model_type (model_type , wlst_value , delimiter = delimiter )
1201
+
1202
+ # tokenize model paths, such as "@@ORACLE_HOME@@/directory"
1203
+
1204
+ if converted_value and (USES_PATH_TOKENS in attribute_info ):
1205
+ if attribute_info [WLST_TYPE ] == STRING :
1206
+ converted_value = self ._model_context .tokenize_path (converted_value )
1207
+ else :
1208
+ converted_value = self ._model_context .tokenize_classpath (converted_value )
1209
+
1210
+ # Compare model value with default
1211
+
1212
+ result_model_value = None
1213
+
1214
+ if model_type == 'boolean' :
1215
+ # some boolean attributes have WLST value of null until they are set
1216
+ result_model_value = _get_boolean_or_none (wlst_value ) # from unconverted value
1217
+ default_boolean = _get_boolean_or_none (default_value )
1218
+ if result_model_value == default_boolean :
1219
+ result_model_value = None
1220
+ else :
1221
+ result_model_value = converted_value
1222
+
1223
+ elif (model_type in ALIAS_LIST_TYPES or model_type in ALIAS_MAP_TYPES ) and \
1224
+ (converted_value is None or len (converted_value ) == 0 ):
1225
+ # match empty lists or maps to default values "[]" or None
1226
+ if default_value == '[]' or default_value is None :
1227
+ result_model_value = None
1228
+
1229
+ elif default_value is None :
1230
+ result_model_value = converted_value
1231
+
1232
+ elif str_helper .to_string (converted_value ) != str_helper .to_string (default_value ):
1233
+ if _strings_are_empty (converted_value , default_value ):
1234
+ result_model_value = None
1235
+ else :
1236
+ result_model_value = converted_value
1237
+
1238
+ return result_model_value
1239
+
1214
1240
def get_model_attribute_name (self , location , wlst_attribute_name , exclude_ignored = True ):
1215
1241
"""
1216
1242
Returns the model attribute name for the specified WLST attribute name and value. If the model attribute name
@@ -1462,6 +1488,20 @@ def decrypt_password(self, text):
1462
1488
1463
1489
return rtnval
1464
1490
1491
+ def get_production_default (self , location , model_attribute ):
1492
+ result = None
1493
+ attribute_info = self ._alias_entries .get_alias_attribute_entry_by_model_name (location , model_attribute )
1494
+ if attribute_info is not None and PRODUCTION_DEFAULT in attribute_info :
1495
+ result = attribute_info [PRODUCTION_DEFAULT ]
1496
+ return result
1497
+
1498
+ def get_secure_default (self , location , model_attribute ):
1499
+ result = None
1500
+ attribute_info = self ._alias_entries .get_alias_attribute_entry_by_model_name (location , model_attribute )
1501
+ if attribute_info is not None and SECURE_DEFAULT in attribute_info :
1502
+ result = attribute_info [SECURE_DEFAULT ]
1503
+ return result
1504
+
1465
1505
def is_derived_default (self , location , model_attribute ):
1466
1506
"""
1467
1507
Return whether the default is derived by WLST.
0 commit comments