def _print_model_folder_sample(self, section_name, model_path_tokens,
                                   control_option):
        """
        Prints a model sample for a folder in a model, when more than just the section_name[:] is provided.
        :param section_name: the name of the model section
        :param model_path_tokens: a Python list of path elements built from model path
        :param control_option: A command-line switch that controls what is output to STDOUT
        """
        _method_name = '_print_model_folder_sample'

        print("")

        # write the parent folders leading up to the specified folder.
        # include any name folders.

        indent = 0
        _print_indent(section_name + ":", indent)
        indent += 1

        model_path = section_name + ":"
        current_folder = self._schema
        for token in model_path_tokens[1:]:
            properties = _get_properties(current_folder)

            valid_subfolder_keys = _get_folder_names(properties)
            if token not in valid_subfolder_keys:
                ex = exception_helper.create_cla_exception(
                    "WLSDPLY-10111", model_path, token,
                    ', '.join(valid_subfolder_keys))
                self._logger.throwing(ex,
                                      class_name=self._class_name,
                                      method_name=_method_name)
                raise ex

            current_folder = properties[token]

            _print_indent(token + ":", indent)
            indent += 1

            if wko_schema_helper.is_multiple_folder(current_folder):
                name = token + '-1'
                _print_indent(name + ":", indent)
                indent += 1

            model_path = model_path + "/" + token

        # list the attributes and folders, as specified

        if model_help_utils.show_attributes(control_option):
            # Print the attributes associated with schema folder
            self._print_attributes_sample(current_folder, indent)

        if model_help_utils.show_folders(control_option):
            self._print_subfolders_sample(current_folder, control_option,
                                          indent, model_path)
    def _print_subfolders_sample(self, schema_folder, control_option,
                                 indent_level, path):
        """
        Prints a model sample section for the folders in a model location.
        :param schema_folder: the schema folder being printed
        :param control_option: a command-line switch that controls what is output to STDOUT
        :param indent_level: the level to indent by, before printing output
        """
        _method_name = '_print_subfolders_sample'

        folder_info = _get_properties(schema_folder)
        folder_map = dict()
        multi_folders = []

        for key in folder_info:
            property_map = folder_info[key]

            if property_map is not None:
                if wko_schema_helper.is_single_folder(property_map):
                    folder_map[key] = property_map

                elif wko_schema_helper.is_multiple_folder(property_map):
                    folder_map[key] = wko_schema_helper.get_array_item_info(
                        property_map)
                    multi_folders.append(key)

        folder_keys = list(folder_map.keys())
        folder_keys.sort()

        for key in folder_keys:
            folder_info = folder_map[key]

            if control_option != ControlOptions.RECURSIVE:
                print("")

            key_level = indent_level
            _print_indent(key + ":", key_level)

            child_level = key_level
            if key in multi_folders:
                name = key + "-1"
                child_level += 1
                _print_indent(name + ":", child_level)

            if control_option == ControlOptions.RECURSIVE:
                # Call this method recursively
                self._print_subfolders_sample(folder_info, control_option,
                                              child_level + 1, path)
            else:
                next_path = path + "/" + key
                _print_indent("# see " + next_path, child_level + 1)
Exemplo n.º 3
0
    def _process_folder(self, model_dict, schema_folder, target_dict,
                        schema_path, model_path):
        """
        Transfer folders and attributes from the model dictionary to the target domain resource dictionary.
        :param model_dict: the source model dictionary
        :param schema_folder: the schema for this folder
        :param target_dict: the target dictionary for the domain resource file.
        :param schema_path: the path of schema elements (no multi-element names), used for supported check
        :param model_path: the path of model elements (including multi-element names), used for logging
        """
        folder_properties = schema_folder["properties"]

        for key, model_value in model_dict.items():
            properties = folder_properties[key]

            if wko_schema_helper.is_single_folder(properties):
                # single object instance
                next_schema_path = wko_schema_helper.append_path(
                    schema_path, key)
                next_model_path = model_path + "/" + key
                if not wko_schema_helper.is_unsupported_folder(
                        next_schema_path):
                    next_target_dict = PyOrderedDict()
                    target_dict[key] = next_target_dict
                    self._process_folder(model_value, properties,
                                         next_target_dict, next_schema_path,
                                         next_model_path)

            elif wko_schema_helper.is_multiple_folder(properties):
                # multiple object instances
                next_schema_path = wko_schema_helper.append_path(
                    schema_path, key)
                next_model_path = model_path + "/" + key
                if not wko_schema_helper.is_unsupported_folder(
                        next_schema_path):
                    item_info = wko_schema_helper.get_array_item_info(
                        properties)
                    target_dict[key] = \
                        self._process_multiple_folder(model_value, item_info, next_schema_path, next_model_path)

            elif wko_schema_helper.is_simple_map(properties):
                # map of key / value pairs
                target_dict[key] = model_value

            else:
                # simple type or array of simple type, such as number, string
                property_type = wko_schema_helper.get_type(properties)
                target_dict[key] = _get_target_value(model_value,
                                                     property_type)
def _get_folder_names(schema_properties):
    """
    Return the folder names (single and multiple) described by the schema properties.
    :param schema_properties: the properties to be examined
    :return: a list of folder names
    """
    folder_names = []
    for key in schema_properties:
        property_map = schema_properties[key]
        if property_map is not None:
            if wko_schema_helper.is_single_folder(
                    property_map) or wko_schema_helper.is_multiple_folder(
                        property_map):
                folder_names.append(key)
    return folder_names
def _get_properties(schema_folder):
    # in array elements, the properties are under "items"
    if wko_schema_helper.is_multiple_folder(schema_folder):
        return schema_folder['items']['properties']
    else:
        return schema_folder['properties']
Exemplo n.º 6
0
    def validate_folder(self, model_folder, schema_folder, schema_path,
                        model_path):
        """
        Validate the specified model folder against the specified schema folder
        :param model_folder: the model folder to validate
        :param schema_folder: the schema folder to validate against
        :param schema_path: the path of schema elements (no multi-element names), used for supported check
        :param model_path: the path of model elements (including multi-element names), used for logging
        """
        _method_name = 'validate_folder'
        self._log_debug(str(model_path))

        if not isinstance(model_folder, dict):
            self._logger.severe("WLSDPLY-05038",
                                model_path,
                                class_name=self._class_name,
                                method_name=_method_name)
            return

        schema_properties = wko_schema_helper.get_properties(schema_folder)

        for key in model_folder:
            properties = dictionary_utils.get_element(schema_properties, key)
            model_value = model_folder[key]

            if properties is not None:

                if wko_schema_helper.is_single_folder(properties):
                    # single object instance
                    self._log_debug('  ' + key + ': folder')
                    next_schema_path = wko_schema_helper.append_path(
                        schema_path, key)
                    next_model_path = model_path + "/" + key
                    if self._check_folder_path(next_schema_path,
                                               next_model_path):
                        self.validate_folder(model_value, properties,
                                             next_schema_path, next_model_path)

                elif wko_schema_helper.is_multiple_folder(properties):
                    # multiple object instances
                    self._log_debug('  ' + key + ': multiple folder')
                    next_schema_path = wko_schema_helper.append_path(
                        schema_path, key)
                    next_model_path = model_path + "/" + key
                    if self._check_folder_path(next_schema_path,
                                               next_model_path):
                        item_info = wko_schema_helper.get_array_item_info(
                            properties)
                        self._validate_multiple_folder(model_value, item_info,
                                                       next_schema_path,
                                                       next_model_path)

                elif wko_schema_helper.is_simple_map(properties):
                    # map of key / value pairs
                    element_type = wko_schema_helper.get_map_element_type(
                        properties)
                    self._log_debug('  ' + key + ': map of ' + element_type)
                    self._validate_simple_map(model_value, key, model_path)

                elif wko_schema_helper.is_simple_array(properties):
                    # array of simple type
                    element_type = wko_schema_helper.get_array_element_type(
                        properties)
                    self._log_debug('  ' + key + ': array of ' + element_type)
                    self._validate_simple_array(model_value, key, model_path)

                else:
                    # simple type
                    property_type = wko_schema_helper.get_type(properties)
                    self._log_debug('  ' + key + ': ' + property_type)
                    self._validate_simple_type(model_value, property_type, key,
                                               model_path)

            else:
                self._logger.severe("WLSDPLY-05026",
                                    key,
                                    len(schema_properties),
                                    model_path,
                                    class_name=self._class_name,
                                    method_name=_method_name)