@@ -134,17 +134,18 @@ def get_variable_names(text):
134
134
return names
135
135
136
136
137
- def substitute (dictionary , variables , model_context ):
137
+ def substitute (dictionary , variables , model_context , validation_result = None ):
138
138
"""
139
139
Substitute fields in the specified dictionary with variable values.
140
140
:param dictionary: the dictionary in which to substitute variables
141
141
:param variables: a dictionary of variables for substitution
142
142
:param model_context: used to resolve variables in file paths
143
143
"""
144
- _process_node (dictionary , variables , model_context )
144
+ _process_node (dictionary , variables , model_context , validation_result )
145
+ return validation_result
145
146
146
147
147
- def _process_node (nodes , variables , model_context ):
148
+ def _process_node (nodes , variables , model_context , validation_result ):
148
149
"""
149
150
Process variables in the node.
150
151
:param nodes: the dictionary to process
@@ -160,18 +161,18 @@ def _process_node(nodes, variables, model_context):
160
161
value = nodes [key ]
161
162
162
163
# if the key changes with substitution, remove old key and map value to new key
163
- new_key = _substitute (key , variables , model_context )
164
+ new_key = _substitute (key , variables , model_context , validation_result )
164
165
if new_key is not key :
165
166
nodes .pop (key )
166
167
nodes [new_key ] = value
167
168
168
169
if isinstance (value , dict ):
169
- _process_node (value , variables , model_context )
170
+ _process_node (value , variables , model_context , validation_result )
170
171
elif type (value ) is str :
171
- nodes [key ] = _substitute (value , variables , model_context )
172
+ nodes [key ] = _substitute (value , variables , model_context , validation_result )
172
173
173
174
174
- def _substitute (text , variables , model_context ):
175
+ def _substitute (text , variables , model_context , validation_result ):
175
176
"""
176
177
Substitute the variable placeholders with the variable value.
177
178
:param text: the text to process for variable placeholders
@@ -204,17 +205,25 @@ def _substitute(text, variables, model_context):
204
205
key = token [7 :- 2 ]
205
206
# for @@PROP:key@@ variables, throw an exception if key is not found.
206
207
if key not in variables :
207
- ex = exception_helper .create_variable_exception ('WLSDPLY-01732' , key )
208
- _logger .throwing (ex , class_name = _class_name , method_name = method_name )
209
- raise ex
208
+ if model_context .get_validation_method () == 'strict' :
209
+ if validation_result :
210
+ validation_result .add_error ('WLSDPLY-01732' , key )
211
+ ex = exception_helper .create_variable_exception ('WLSDPLY-01732' , key )
212
+ _logger .throwing (ex , class_name = _class_name , method_name = method_name )
213
+ raise ex
214
+ else :
215
+ if validation_result :
216
+ validation_result .add_info ('WLSDPLY-01732' , key )
217
+ continue
218
+
210
219
value = variables [key ]
211
220
text = text .replace (token , value )
212
221
213
222
tokens = _file_variable_pattern .findall (text )
214
223
if tokens :
215
224
for token in tokens :
216
225
path = token [7 :- 2 ]
217
- value = _read_value_from_file (path )
226
+ value = _read_value_from_file (path , model_context , validation_result )
218
227
text = text .replace (token , value )
219
228
220
229
# special case for @@FILE:@@ORACLE_HOME@@/dir/name.txt@@
@@ -223,13 +232,13 @@ def _substitute(text, variables, model_context):
223
232
for token in tokens :
224
233
path = token [7 :- 2 ]
225
234
path = model_context .replace_token_string (path )
226
- value = _read_value_from_file (path )
235
+ value = _read_value_from_file (path , model_context , validation_result )
227
236
text = text .replace (token , value )
228
237
229
238
return text
230
239
231
240
232
- def _read_value_from_file (file_path ):
241
+ def _read_value_from_file (file_path , model_context , validation_result ):
233
242
"""
234
243
Read a single text value from the first line in the specified file.
235
244
:param file_path: the file from which to read the value
@@ -243,9 +252,18 @@ def _read_value_from_file(file_path):
243
252
line = file_reader .readLine ()
244
253
file_reader .close ()
245
254
except IOException , e :
246
- ex = exception_helper .create_variable_exception ('WLSDPLY-01733' , file_path , e .getLocalizedMessage (), error = e )
247
- _logger .throwing (ex , class_name = _class_name , method_name = method_name )
248
- raise ex
255
+ if model_context .get_validation_method () == 'strict' :
256
+ if validation_result :
257
+ validation_result .add_error ('WLSDPLY-01733' , file_path , e .getLocalizedMessage ())
258
+ ex = exception_helper .create_variable_exception ('WLSDPLY-01733' , file_path , e .getLocalizedMessage (), error = e )
259
+ _logger .throwing (ex , class_name = _class_name , method_name = method_name )
260
+ raise ex
261
+ else :
262
+ if validation_result :
263
+ validation_result .add_info ('WLSDPLY-01733' , file_path , e .getLocalizedMessage ())
264
+ _logger .info ('WLSDPLY-01733' , file_path , e .getLocalizedMessage (), error = e ,
265
+ class_name = _class_name , method_name = method_name )
266
+ line = ''
249
267
250
268
if line is None :
251
269
ex = exception_helper .create_variable_exception ('WLSDPLY-01734' , file_path )
0 commit comments