Skip to content

Commit 7b17240

Browse files
online working
1 parent 4587ade commit 7b17240

File tree

10 files changed

+215
-127
lines changed

10 files changed

+215
-127
lines changed

core/src/main/java/oracle/weblogic/deploy/aliases/TypeUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ public static Object convertToType(Class<?> targetType, Object value, String del
187187
strValue = String.valueOf((char[]) value);
188188
} else {
189189
strValue = value.toString().trim();
190+
LOGGER.fine("The string value is {0}", strValue);
191+
if (strValue.length() == 0) {
192+
return null;
193+
}
190194
}
191195

192196
Object result;
@@ -277,6 +281,7 @@ private static Object[] convertToObjectArray(Object value, String strValue, Stri
277281
} else {
278282
result = convertStringToList(strValue, delimiter).toArray(new String[0]);
279283
}
284+
LOGGER.fine("before convert {0} and after convert {1}", value, strValue);
280285
return result;
281286
}
282287

core/src/main/python/wlsdeploy/aliases/alias_utils.py

Lines changed: 132 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
from wlsdeploy.aliases.alias_constants import WLST_READ_TYPE
5252
from wlsdeploy.aliases.alias_constants import WLST_TYPE
5353
from wlsdeploy.aliases.alias_constants import WLST_SUBFOLDERS_PATH
54+
from wlsdeploy.aliases.model_constants import MODEL_LIST_DELIMITER
5455

5556
_class_name = 'alias_utils'
5657
_logger = PlatformLogger('wlsdeploy.aliases')
@@ -256,9 +257,9 @@ def parse_curly_braces(value):
256257
idx2 = alist[i].index(':')
257258
idx3 = alist[i].index('}')
258259
if i == 0:
259-
alist[i] = alist[i][0:idx1]+alist[i][idx1+2:idx2]+alist[i][idx3+1:]
260+
alist[i] = alist[i][0:idx1] + alist[i][idx1 + 2:idx2] + alist[i][idx3 + 1:]
260261
else:
261-
alist[i] = alist[i][0:idx1]+alist[i][idx2+1:idx3]+alist[i][idx3+1:]
262+
alist[i] = alist[i][0:idx1] + alist[i][idx2 + 1:idx3] + alist[i][idx3 + 1:]
262263
return alist
263264

264265

@@ -558,7 +559,7 @@ def is_attribute_server_start_arguments(location, model_attribute_name):
558559
:return: True if so, False otherwise
559560
"""
560561
return location.get_folder_path() == _server_start_location_folder_path and \
561-
model_attribute_name == _server_start_argument_attribute_name
562+
model_attribute_name == _server_start_argument_attribute_name
562563

563564

564565
def compute_delimiter_from_data_type(data_type, value):
@@ -593,26 +594,52 @@ def compute_read_data_type_and_delimiter_from_attribute_info(attribute_info, val
593594
if WLST_TYPE in attribute_info:
594595
data_type = attribute_info[WLST_TYPE]
595596
delimiter = compute_delimiter_from_data_type(data_type, value)
596-
else:
597-
if WLST_READ_TYPE in attribute_info:
598-
data_type = attribute_info[WLST_READ_TYPE]
599-
read_delimiter = compute_delimiter_from_data_type(data_type, value)
600-
if read_delimiter is not None:
601-
delimiter = read_delimiter
602-
603-
if PREFERRED_MODEL_TYPE in attribute_info:
604-
data_type = attribute_info[PREFERRED_MODEL_TYPE]
605-
#
606-
# This code does not consider the delimiter defined by the preferred_model_type field unless there is
607-
# no other delimiter defined by wlst_type or wlst_read_type. This is required to handle the use case
608-
# where the value read from WLST had a different separator than the preferred_model_type.
609-
#
610-
if delimiter is None:
611-
delimiter = compute_delimiter_from_data_type(data_type, value)
597+
598+
if WLST_READ_TYPE in attribute_info:
599+
data_type = attribute_info[WLST_READ_TYPE]
600+
read_delimiter = compute_delimiter_from_data_type(data_type, value)
601+
if read_delimiter is not None:
602+
delimiter = read_delimiter
603+
604+
if PREFERRED_MODEL_TYPE in attribute_info:
605+
data_type = attribute_info[PREFERRED_MODEL_TYPE]
606+
#
607+
# This code does not consider the delimiter defined by the preferred_model_type field unless there is
608+
# no other delimiter defined by wlst_type or wlst_read_type. This is required to handle the use case
609+
# where the value read from WLST had a different separator than the preferred_model_type.
610+
#
611+
if delimiter is None:
612+
delimiter = compute_delimiter_from_data_type(data_type, value)
612613

613614
return data_type, delimiter
614615

615616

617+
def compute_read_data_type_for_wlst_and_delimiter_from_attribute_info(attribute_info, value):
618+
"""
619+
Get the WLST read data type and delimiter from the attribute
620+
:param attribute_info: attribute dictionary
621+
:param value: the attribute value
622+
:return: the data type and delimiter
623+
"""
624+
data_type = None
625+
preferred_data_type = None
626+
delimiter = None
627+
if WLST_TYPE in attribute_info:
628+
data_type = attribute_info[WLST_TYPE]
629+
delimiter = compute_delimiter_from_data_type(data_type, value)
630+
631+
if WLST_READ_TYPE in attribute_info:
632+
data_type = attribute_info[WLST_READ_TYPE]
633+
read_delimiter = compute_delimiter_from_data_type(data_type, value)
634+
if read_delimiter is not None:
635+
delimiter = read_delimiter
636+
637+
if PREFERRED_MODEL_TYPE in attribute_info:
638+
preferred_data_type = attribute_info[PREFERRED_MODEL_TYPE]
639+
640+
return data_type, preferred_data_type, delimiter
641+
642+
616643
def get_number_of_directories_to_strip(desired_path_type, actual_path_type):
617644
"""
618645
Compute the number of directories to strip off the path based on the desired path and actual path types.
@@ -640,6 +667,7 @@ def convert_from_type(data_type, value, preferred=None, delimiter=None):
640667
"""
641668

642669
_method_name = 'convert_from_type'
670+
new_value = None
643671
if value is not None and data_type == 'password':
644672
# The password is an array of bytes coming back from the WLST get() method and only
645673
# java.lang.String() is able to properly convert it to the cipher text string. However,
@@ -649,43 +677,13 @@ def convert_from_type(data_type, value, preferred=None, delimiter=None):
649677
elif value is not None and isinstance(value, ObjectName):
650678
new_value = value.getKeyProperty('Name')
651679
else:
652-
try:
653-
new_value = TypeUtils.convertToType(data_type, value, delimiter)
654-
except NumberFormatException, nfe:
655-
ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter,
656-
nfe.getLocalizedMessage(), error=nfe)
657-
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
658-
raise ex
680+
new_value = _jconvert_to_type(data_type, value, delimiter)
659681

660682
if preferred:
661-
delimiter = compute_delimiter_from_data_type(preferred, value)
662-
try:
663-
if data_type == LONG:
664-
new_value = Long(new_value)
665-
elif data_type == JAVA_LANG_BOOLEAN:
666-
new_value = Boolean(new_value)
667-
elif data_type == JARRAY:
668-
new_value = _create_array(new_value, delimiter)
669-
elif data_type == PROPERTIES:
670-
if preferred == DICTIONARY:
671-
new_value =
672-
elif data_type == LIST:
673-
new_value = list(new_value)
674-
elif data_type in (COMMA_DELIMITED_STRING, DELIMITED_STRING, SEMI_COLON_DELIMITED_STRING,
675-
SPACE_DELIMITED_STRING, PATH_SEPARATOR_DELIMITED_STRING):
676-
#
677-
# This code intentionally ignores the delimiter value passed in and computes it from the data type.
678-
# This is required to handle the special case where the value we read from WLST might have a
679-
# different delimiter than the model value. In this use case, the value passed into the method
680-
# is the WLST value delimiter and the data_type is the preferred_model_type, so we compute the
681-
# model delimiter from the data_type directly.
682-
#
683-
delimiter = compute_delimiter_from_data_type(data_type, new_value)
684-
new_value = delimiter.join(new_value)
685-
except TypeError, te:
686-
ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter, te)
687-
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
688-
raise ex
683+
# now put it into the preferred model type, but the model delimiter should ALWAYS be the
684+
# model default delimiter
685+
delimiter = MODEL_LIST_DELIMITER
686+
new_value = _jconvert_to_type(preferred, new_value, delimiter)
689687

690688
return new_value
691689

@@ -718,33 +716,34 @@ def convert_to_type(data_type, value, subtype=None, delimiter=None):
718716
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
719717
raise ex
720718

721-
try:
722-
if data_type == LONG:
723-
new_value = Long(new_value)
724-
elif data_type == JAVA_LANG_BOOLEAN:
725-
new_value = Boolean(new_value)
726-
elif data_type == JARRAY:
727-
if subtype is None or subtype == 'java.lang.String':
728-
new_value = _create_string_jarray(new_value)
729-
else:
730-
new_value = _create_mbean_array(new_value, subtype)
731-
elif data_type == LIST:
732-
new_value = list(new_value)
733-
elif data_type in (COMMA_DELIMITED_STRING, DELIMITED_STRING, SEMI_COLON_DELIMITED_STRING,
734-
SPACE_DELIMITED_STRING, PATH_SEPARATOR_DELIMITED_STRING):
735-
#
736-
# This code intentionally ignores the delimiter value passed in and computes it from the data type.
737-
# This is required to handle the special case where the value we read from WLST might have a
738-
# different delimiter than the model value. In this use case, the value passed into the method
739-
# is the WLST value delimiter and the data_type is the preferred_model_type, so we compute the
740-
# model delimiter from the data_type directly.
741-
#
742-
delimiter = compute_delimiter_from_data_type(data_type, new_value)
743-
new_value = delimiter.join(new_value)
744-
except TypeError, te:
745-
ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter, te)
746-
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
747-
raise ex
719+
if new_value is not None:
720+
try:
721+
if data_type == LONG:
722+
new_value = Long(new_value)
723+
elif data_type == JAVA_LANG_BOOLEAN:
724+
new_value = Boolean(new_value)
725+
elif data_type == JARRAY:
726+
if subtype is None or subtype == 'java.lang.String':
727+
new_value = _create_string_jarray(new_value)
728+
else:
729+
new_value = _create_mbean_array(new_value, subtype)
730+
elif data_type == LIST:
731+
new_value = list(new_value)
732+
elif data_type in (COMMA_DELIMITED_STRING, DELIMITED_STRING, SEMI_COLON_DELIMITED_STRING,
733+
SPACE_DELIMITED_STRING, PATH_SEPARATOR_DELIMITED_STRING):
734+
#
735+
# This code intentionally ignores the delimiter value passed in and computes it from the data type.
736+
# This is required to handle the special case where the value we read from WLST might have a
737+
# different delimiter than the model value. In this use case, the value passed into the method
738+
# is the WLST value delimiter and the data_type is the preferred_model_type, so we compute the
739+
# model delimiter from the data_type directly.
740+
#
741+
delimiter = compute_delimiter_from_data_type(data_type, new_value)
742+
new_value = delimiter.join(new_value)
743+
except TypeError, te:
744+
ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter, te)
745+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
746+
raise ex
748747

749748
return new_value
750749

@@ -804,11 +803,54 @@ def get_security_provider_model_folder_name(mbean_name):
804803
result = SECURITY_PROVIDER_MBEAN_NAME_MAP[mbean_name]
805804
return result
806805

806+
807807
###############################################################################
808808
# Private functions #
809809
###############################################################################
810810

811811

812+
def _jconvert_to_type(data_type, value, delimiter):
813+
_method_name = '_jconvert_to_type'
814+
try:
815+
converted = TypeUtils.convertToType(data_type, value, delimiter)
816+
except NumberFormatException, nfe:
817+
ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter,
818+
nfe.getLocalizedMessage(), error=nfe)
819+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
820+
raise ex
821+
_logger.fine('the converted is {0} converter from original {1} and the alias type is {2}', converted, value, data_type)
822+
try:
823+
if data_type == LONG:
824+
converted = Long(converted)
825+
elif data_type == JAVA_LANG_BOOLEAN:
826+
converted = Boolean(converted)
827+
elif data_type == JARRAY:
828+
converted = _create_array(converted, delimiter)
829+
# elif data_type == PROPERTIES:
830+
# if preferred == DICTIONARY:
831+
# new_value = _jconvert_to_type(preferred, new_value, delimiter)
832+
elif data_type == LIST:
833+
if converted:
834+
converted = list(converted)
835+
elif data_type in (COMMA_DELIMITED_STRING, DELIMITED_STRING, SEMI_COLON_DELIMITED_STRING,
836+
SPACE_DELIMITED_STRING, PATH_SEPARATOR_DELIMITED_STRING):
837+
#
838+
# This code intentionally ignores the delimiter value passed in and computes it from the data type.
839+
# This is required to handle the special case where the value we read from WLST might have a
840+
# different delimiter than the model value. In this use case, the value passed into the method
841+
# is the WLST value delimiter and the data_type is the preferred_model_type, so we compute the
842+
# model delimiter from the data_type directly.
843+
#
844+
delimiter = compute_delimiter_from_data_type(data_type, converted)
845+
if delimiter and converted:
846+
converted = delimiter.join(converted)
847+
except TypeError, te:
848+
ex = exception_helper.create_alias_exception('WLSDPLY-08021', value, data_type, delimiter, str(te))
849+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
850+
raise ex
851+
return converted
852+
853+
812854
def _get_path_separator(value):
813855
"""
814856
Get the path separator to use for this value. If the value is a string and contains
@@ -1045,16 +1087,15 @@ def _create_array(iterable, delimiter):
10451087
:return: an array or a string containing the same contents as the provided iterable
10461088
"""
10471089
myarray = []
1048-
for element in iterable:
1049-
if isinstance(element, ObjectName):
1050-
myarray.append(element.getKeyProperty('Name'))
1051-
elif not delimiter or isinstance(element, String):
1052-
myarray.append(str(element))
1053-
else:
1054-
myarray.append(element)
1055-
if delimiter:
1056-
# make it to a string
1057-
myarray = delimiter.join(myarray)
1090+
_logger.fine('The iterable is {0} of type {1}', iterable, type(iterable))
1091+
if iterable:
1092+
for element in iterable:
1093+
if isinstance(element, ObjectName):
1094+
myarray.append(element.getKeyProperty('Name'))
1095+
elif delimiter or isinstance(element, String):
1096+
myarray.append(str(element))
1097+
else:
1098+
myarray.append(element)
10581099
return myarray
10591100

10601101

core/src/main/python/wlsdeploy/aliases/aliases.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ def get_wlst_attribute_name_and_value(self, location, model_attribute_name, mode
379379
else:
380380
merged_value = model_attribute_value
381381

382+
382383
if data_type == JARRAY:
383384
subtype = 'java.lang.String'
384385
if SET_MBEAN_TYPE in attribute_info:
@@ -810,18 +811,18 @@ def get_model_attribute_name_and_value(self, location, wlst_attribute_name, wlst
810811

811812
attribute_info = self._alias_entries.get_alias_attribute_entry_by_wlst_name(location, wlst_attribute_name)
812813
if attribute_info is not None and not self.__is_model_attribute_read_only(location, attribute_info):
813-
data_type, delimiter = \
814-
alias_utils.compute_read_data_type_and_delimiter_from_attribute_info(attribute_info,
814+
data_type, preferred_type, delimiter = \
815+
alias_utils.compute_read_data_type_for_wlst_and_delimiter_from_attribute_info(attribute_info,
815816
wlst_attribute_value)
816817

817-
preferred_type = None
818-
if PREFERRED_MODEL_TYPE in attribute_info:
819-
preferred_type = attribute_info[PREFERRED_MODEL_TYPE]
820-
self._logger.fine('wlst attribute {0} data type {1} delimiter {2}')
821818
converted_value = alias_utils.convert_from_type(data_type, wlst_attribute_value, delimiter=delimiter,
822819
preferred=preferred_type)
823820
model_attribute_name = attribute_info[MODEL_NAME]
824821
default_value = attribute_info[VALUE][DEFAULT]
822+
if preferred_type:
823+
data_type = preferred_type
824+
# never use anything but model default delimiter
825+
delimiter = MODEL_LIST_DELIMITER
825826
#
826827
# The logic below to compare the str() representation of the converted value and the default value
827828
# only works for lists/maps if both the converted value and the default value are the same data type...
@@ -854,11 +855,11 @@ def get_model_attribute_name_and_value(self, location, wlst_attribute_name, wlst
854855
if USES_PATH_TOKENS in attribute_info:
855856
model_attribute_value = self._model_context.tokenize_path(model_attribute_value)
856857

857-
if wlst_attribute_name not in ('Id', 'Tag', 'Name') and model_attribute_name is None:
858-
ex = exception_helper.create_alias_exception('WLSDPLY-08406', wlst_attribute_name,
859-
location.get_folder_path())
860-
self._logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
861-
raise ex
858+
if wlst_attribute_name not in ('Id', 'Tag', 'Tags', 'Type', 'Name') and model_attribute_name is None:
859+
ex = exception_helper.create_alias_exception('WLSDPLY-08406', wlst_attribute_name,
860+
location.get_folder_path())
861+
self._logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
862+
raise ex
862863
self._logger.exiting(class_name=self._class_name, method_name=_method_name,
863864
result={model_attribute_name: model_attribute_value})
864865
return model_attribute_name, model_attribute_value

0 commit comments

Comments
 (0)