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 .aliases .model_constants import MODEL_LIST_DELIMITER
54
55
55
56
_class_name = 'alias_utils'
56
57
_logger = PlatformLogger ('wlsdeploy.aliases' )
@@ -256,9 +257,9 @@ def parse_curly_braces(value):
256
257
idx2 = alist [i ].index (':' )
257
258
idx3 = alist [i ].index ('}' )
258
259
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 :]
260
261
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 :]
262
263
return alist
263
264
264
265
@@ -558,7 +559,7 @@ def is_attribute_server_start_arguments(location, model_attribute_name):
558
559
:return: True if so, False otherwise
559
560
"""
560
561
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
562
563
563
564
564
565
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
593
594
if WLST_TYPE in attribute_info :
594
595
data_type = attribute_info [WLST_TYPE ]
595
596
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 )
612
613
613
614
return data_type , delimiter
614
615
615
616
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
+
616
643
def get_number_of_directories_to_strip (desired_path_type , actual_path_type ):
617
644
"""
618
645
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):
640
667
"""
641
668
642
669
_method_name = 'convert_from_type'
670
+ new_value = None
643
671
if value is not None and data_type == 'password' :
644
672
# The password is an array of bytes coming back from the WLST get() method and only
645
673
# 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):
649
677
elif value is not None and isinstance (value , ObjectName ):
650
678
new_value = value .getKeyProperty ('Name' )
651
679
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 )
659
681
660
682
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 )
689
687
690
688
return new_value
691
689
@@ -718,33 +716,34 @@ def convert_to_type(data_type, value, subtype=None, delimiter=None):
718
716
_logger .throwing (ex , class_name = _class_name , method_name = _method_name )
719
717
raise ex
720
718
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
748
747
749
748
return new_value
750
749
@@ -804,11 +803,54 @@ def get_security_provider_model_folder_name(mbean_name):
804
803
result = SECURITY_PROVIDER_MBEAN_NAME_MAP [mbean_name ]
805
804
return result
806
805
806
+
807
807
###############################################################################
808
808
# Private functions #
809
809
###############################################################################
810
810
811
811
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
+
812
854
def _get_path_separator (value ):
813
855
"""
814
856
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):
1045
1087
:return: an array or a string containing the same contents as the provided iterable
1046
1088
"""
1047
1089
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 )
1058
1099
return myarray
1059
1100
1060
1101
0 commit comments