Skip to content

Commit 47dac58

Browse files
authored
Process newly added elements recursively for extract domain resource (#1142)
* Process newly added elements recursively for extract domain resource * Use get_element method with default value to reduce cognitive complexity
1 parent 327ba42 commit 47dac58

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

core/src/main/python/wlsdeploy/tool/util/targets/output_file_helper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,16 @@ def _update_dictionary(output_dictionary, model_dictionary, schema_folder, schem
140140

141141
value = _convert_value(value, element_type)
142142

143-
if key not in output_dictionary:
144-
output_dictionary[key] = value
145-
elif isinstance(value, dict):
143+
if isinstance(value, dict):
144+
output_dictionary[key] = dictionary_utils.get_element(output_dictionary, key, PyOrderedDict())
146145
next_schema_path = wko_schema_helper.append_path(schema_path, key)
147146
_update_dictionary(output_dictionary[key], value, property_folder, next_schema_path, output_file_path)
148147
elif isinstance(value, list):
149148
if not value:
150149
# if the model has an empty list, override output value
151150
output_dictionary[key] = value
152151
else:
152+
output_dictionary[key] = dictionary_utils.get_element(output_dictionary, key, [])
153153
next_schema_path = wko_schema_helper.append_path(schema_path, key)
154154
_update_list(output_dictionary[key], value, property_folder, next_schema_path, output_file_path)
155155
else:

core/src/main/python/wlsdeploy/util/dictionary_utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates. All rights reserved.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import java.util.Properties as JProperties
@@ -57,15 +57,16 @@ def is_empty_dictionary_element(dictionary, element_name):
5757
return result
5858

5959

60-
def get_element(dictionary, element_name):
60+
def get_element(dictionary, element_name, default_value=None):
6161
"""
6262
Retrieve the value for the provided element name from the dictionary.
63-
Return None if name is not in the dictionary.
63+
Return default value or None if name is not in the dictionary.
6464
:param dictionary: to find the element name
6565
:param element_name: for which to retrieve the value
66-
:return: value from the dictionary
66+
:param default_value: value to return if key is not in dictionary
67+
:return: value from the dictionary, or default_value
6768
"""
68-
result = None
69+
result = default_value
6970
if element_name in dictionary:
7071
result = dictionary[element_name]
7172
return result

0 commit comments

Comments
 (0)