|
1 | 1 | """
|
2 |
| -Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved. |
| 2 | +Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. |
3 | 3 | Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
|
4 | 4 | """
|
5 | 5 | import copy
|
6 | 6 | from org.python.modules import jarray
|
7 | 7 | import re
|
8 |
| -from sets import Set |
9 | 8 | from array import array
|
10 | 9 |
|
11 | 10 | from java.io import File
|
|
24 | 23 | from oracle.weblogic.deploy.aliases import VersionUtils
|
25 | 24 |
|
26 | 25 | from wlsdeploy.aliases.alias_constants import ChildFoldersTypes
|
| 26 | +from wlsdeploy.aliases.model_constants import MODEL_LIST_DELIMITER |
27 | 27 | from wlsdeploy.exception import exception_helper
|
28 | 28 | from wlsdeploy.logging.platform_logger import PlatformLogger
|
29 | 29 |
|
|
51 | 51 | from wlsdeploy.aliases.alias_constants import WLST_READ_TYPE
|
52 | 52 | from wlsdeploy.aliases.alias_constants import WLST_TYPE
|
53 | 53 | from wlsdeploy.aliases.alias_constants import WLST_SUBFOLDERS_PATH
|
| 54 | +from wlsdeploy.util import model_helper |
54 | 55 |
|
55 | 56 | _class_name = 'alias_utils'
|
56 | 57 | _logger = PlatformLogger('wlsdeploy.aliases')
|
57 | 58 | _windows_path_regex = re.compile(r'^[a-zA-Z]:[\\/].*')
|
58 | 59 |
|
59 | 60 |
|
60 |
| -def merge_model_and_existing_lists(model_list, existing_list, string_list_separator_char=','): |
| 61 | +def merge_model_and_existing_lists(model_list, existing_list, location_path="(unknown)", attribute_name="(unknown)"): |
61 | 62 | """
|
62 | 63 | Merge the two lists so that the resulting list contains all of the elements in both lists one time.
|
63 |
| - :param model_list: the list to merge |
64 |
| - :param existing_list: the existing list |
65 |
| - :param string_list_separator_char: the character separator to use to split the lists if either list is a string |
| 64 | + :param model_list: the list to merge, possibly a string or None |
| 65 | + :param existing_list: the existing list, possibly a string or None |
| 66 | + :param location_path: optional, the path of the attribute location, for logging |
| 67 | + :param attribute_name: optional, the attribute name, for logging |
66 | 68 | :return: the merged list as a list or a string, depending on the type of the model_list
|
67 | 69 | :raises: DeployException: if either list is not either a string or a list
|
68 | 70 | """
|
69 | 71 | _method_name = 'merge_model_and_existing_lists'
|
70 | 72 |
|
71 |
| - _logger.entering(model_list, existing_list, string_list_separator_char, |
72 |
| - class_name=_class_name, method_name=_method_name) |
73 |
| - if existing_list is None or len(existing_list) == 0: |
74 |
| - result = model_list |
75 |
| - elif model_list is None or len(model_list) == 0: |
76 |
| - result = existing_list |
77 |
| - if isinstance(model_list, basestring) and not isinstance(existing_list, basestring): |
78 |
| - result = string_list_separator_char.join(existing_list) |
| 73 | + _logger.entering(model_list, existing_list, location_path, attribute_name, class_name=_class_name, |
| 74 | + method_name=_method_name) |
| 75 | + |
| 76 | + if model_list is None: |
| 77 | + result_is_string = isinstance(existing_list, basestring) |
79 | 78 | else:
|
80 |
| - model_list_is_string = isinstance(model_list, basestring) |
81 |
| - model_set = _create_set(model_list, string_list_separator_char, 'WLSDPLY-08000') |
82 |
| - existing_set = _create_set(existing_list, string_list_separator_char, 'WLSDPLY-08001') |
| 79 | + result_is_string = isinstance(model_list, basestring) |
| 80 | + |
| 81 | + result = create_list(existing_list, 'WLSDPLY-08001') |
| 82 | + model_iterator = create_list(model_list, 'WLSDPLY-08000') |
| 83 | + |
| 84 | + for item in model_iterator: |
| 85 | + if model_helper.is_delete_name(item): |
| 86 | + item_name = model_helper.get_delete_item_name(item) |
| 87 | + if item_name in result: |
| 88 | + result.remove(item_name) |
| 89 | + else: |
| 90 | + _logger.warning('WLSDPLY-08022', item_name, attribute_name, location_path, class_name=_class_name, |
| 91 | + method_name=_method_name) |
| 92 | + |
| 93 | + elif item not in result: |
| 94 | + result.append(item) |
83 | 95 |
|
84 |
| - result = list(existing_set.union(model_set)) |
85 |
| - if model_list_is_string: |
86 |
| - result = string_list_separator_char.join(result) |
| 96 | + if result_is_string: |
| 97 | + result = MODEL_LIST_DELIMITER.join(result) |
87 | 98 |
|
88 | 99 | _logger.exiting(class_name=_class_name, method_name=_method_name, result=result)
|
89 | 100 | return result
|
@@ -784,6 +795,31 @@ def get_dictionary_mode(alias_dict):
|
784 | 795 | return alias_dict[WLST_MODE]
|
785 | 796 | return None
|
786 | 797 |
|
| 798 | + |
| 799 | +def create_list(list_value, message_key): |
| 800 | + """ |
| 801 | + Create a list from the specified list value. |
| 802 | + :param list_value: the model value to be examined, should be a string, list, or array |
| 803 | + :param message_key: the key of the message to display if list item type is invalid |
| 804 | + :return: a list containing the list value's elements |
| 805 | + :raises: DeployException: if either list is not either a string or a list |
| 806 | + """ |
| 807 | + _method_name = '_create_list' |
| 808 | + |
| 809 | + item_type = type(list_value) |
| 810 | + if (list_value is None) or (len(list_value) == 0): |
| 811 | + item_list = [] |
| 812 | + elif isinstance(list_value, basestring): |
| 813 | + item_list = [x.strip() for x in list_value.split(MODEL_LIST_DELIMITER)] |
| 814 | + elif item_type is list or item_type is array: |
| 815 | + item_list = list(list_value) |
| 816 | + else: |
| 817 | + ex = exception_helper.create_deploy_exception(message_key, str(item_type)) |
| 818 | + _logger.throwing(ex, class_name=_class_name, method_name=_method_name) |
| 819 | + raise ex |
| 820 | + |
| 821 | + return item_list |
| 822 | + |
787 | 823 | ###############################################################################
|
788 | 824 | # Private functions #
|
789 | 825 | ###############################################################################
|
@@ -1104,27 +1140,3 @@ def _create_mbean_array(iterable, subtype):
|
1104 | 1140 | myarray[idx] = element
|
1105 | 1141 | idx += 1
|
1106 | 1142 | return myarray
|
1107 |
| - |
1108 |
| - |
1109 |
| -def _create_set(list_item, string_list_separator_char, message_key): |
1110 |
| - """ |
1111 |
| - Create a set object from the specified list item. |
1112 |
| - :param list_item: the item to be examined, should be a string, list, or array |
1113 |
| - :param string_list_separator_char: the character separator to use to split the lists if either list is a string |
1114 |
| - :param message_key: the key of the message to display if list item type is invalid |
1115 |
| - :return: a set containing the list item's elements |
1116 |
| - :raises: DeployException: if either list is not either a string or a list |
1117 |
| - """ |
1118 |
| - _method_name = '_create_set' |
1119 |
| - |
1120 |
| - item_type = type(list_item) |
1121 |
| - if item_type in [str, unicode]: |
1122 |
| - item_set = Set([x.strip() for x in list_item.split(string_list_separator_char)]) |
1123 |
| - elif item_type is list or item_type is array: |
1124 |
| - item_set = Set(list_item) |
1125 |
| - else: |
1126 |
| - ex = exception_helper.create_deploy_exception(message_key, str(item_type)) |
1127 |
| - _logger.throwing(ex, class_name=_class_name, method_name=_method_name) |
1128 |
| - raise ex |
1129 |
| - |
1130 |
| - return item_set |
|
0 commit comments