Пример #1
0
    def _set_operation_info(self, _info, operation_type, _schema_info):
        if operation_type is None:
            return
        if operation_type.is_function():
            _info.type = PROPERTY_TYPE.E_FUNCTION
        else:
            _info.type = PROPERTY_TYPE.E_ACTION
        _operation_info = operation_info()
        ret_type = operation_type.get_operation_return_type()
        if ret_type is None:
            _operation_info.return_type = "void"
            _operation_info.executor_name = "operation_query_void"
        else:
            if ret_type.get_type_kind() == edm_type_kind_t.Collection:
                element_type = odata_client_python.to_collection_type(ret_type).get_element_type()
                if element_type is None:
                    return
                _operation_info.return_type = element_type.get_name()
                if element_type.get_type_kind() == edm_type_kind_t.Primitive:
                    _operation_info.return_type = odata_client_python.edm_model_utility.get_strong_type_name_from_edm_type_name(odata_client_python.to_primitive_type(element_type))
                elif element_type.get_type_kind() in (edm_type_kind_t.Complex,
                        edm_type_kind_t.Entity,
                        edm_type_kind_t.Enum):
                    _operation_info.return_type = _schema_info.class_map[element_type.get_name()].class_name
                _operation_info.executor_name = self._get_executor_name_from_edm_type(element_type)
            else:
                if ret_type.get_type_kind() == edm_type_kind_t.Primitive:
                    _operation_info.return_type = odata_client_python.edm_model_utility.get_strong_type_name_from_edm_type_name(odata_client_python.to_primitive_type(ret_type))
                elif ret_type.get_type_kind() in (edm_type_kind_t.Complex,
                        edm_type_kind_t.Entity,
                        edm_type_kind_t.Enum):
                    _operation_info.return_type = _schema_info.class_map[ret_type.get_name()].class_name
                _operation_info.executor_name = self._get_executor_name_from_edm_type(ret_type)

        first = True
        for param_iter in operation_type.get_operation_parameters():
            if first and operation_type.is_bound():
                first = False
                continue
            param = operation_param()
            param_type = param_iter.get_param_type()
            if param_type is None:
                continue
            param.edm_name = param_iter.get_param_name()
            if param_type.get_type_kind() == edm_type_kind_t.Primitive:
                param.member_strong_type_name = odata_client_python.edm_model_utility.get_strong_type_name_from_edm_type_name(odata_client_python.to_primitive_type(param_type))
                param.member_type = PROPERTY_TYPE.E_PRIMITIVE
            elif param_type.get_type_kind() == edm_type_kind_t.Complex:
                param.member_strong_type_name = _schema_info.class_map[param_type.get_name()].class_name
                param.member_type = PROPERTY_TYPE.E_COMPLEX
            elif param_type.get_type_kind() == edm_type_kind_t.Entity:
                param.member_strong_type_name = _schema_info.class_map[param_type.get_name()].class_name
                param.member_type = PROPERTY_TYPE.E_ENTITY
            elif param_type.get_type_kind() == edm_type_kind_t.Enum:
                param.member_strong_type_name = _schema_info.class_map[param_type.get_name()].class_name
                param.member_type = PROPERTY_TYPE.E_ENUM
            elif param_type.get_type_kind() == edm_type_kind_t.Collection:
                collection_type = odata_client_python.to_collection_type(param_type)
                element_type = collection_type.get_element_type()
                if element_type.get_type_kind() == edm_type_kind_t.Complex:
                    param.member_strong_type_name = _schema_info.class_map[element_type.get_name()].class_name
                    param.member_type = PROPERTY_TYPE.E_COLLECTION_COMPLEX
                elif element_type.get_type_kind() == edm_type_kind_t.Entity:
                    param.member_strong_type_name = _schema_info.class_map[element_type.get_name()].class_name
                    param.member_type = PROPERTY_TYPE.E_COLLECTION_ENTITY
                elif element_type.get_type_kind() == edm_type_kind_t.Primitive:
                    param.member_strong_type_name = odata_client_python.edm_model_utility.get_strong_type_name_from_edm_type_name(odata_client_python.to_primitive_type(element_type))
                    param.member_type = PROPERTY_TYPE.E_COLLECTION_PRIMITIVE
                elif element_type.get_type_kind() == edm_type_kind_t.Enum:
                    param.member_strong_type_name = _schema_info.class_map[element_type.get_name()].class_name
                    param.member_type = PROPERTY_TYPE.E_COLLECTION_ENUM
            param.member_name = param_iter.get_param_name()
            _operation_info.params.append(param)

        _info.operation_info = _operation_info
Пример #2
0
    def _initialize_property_info_of_class(self, schema, _schema_info):
        if schema is None:
            return

        entity_types = schema.get_entity_types_vector()
        for entity_type in entity_types:
            class_property_map = {}
            properties = entity_type.get_properties_vector()
            for property_type in properties:
                if property_type.get_property_type().get_type_kind() == edm_type_kind_t.Unknown:
                    continue
                _info = property_info()
                _info.edm_name = property_type.get_name()
                _info.class_member_name = property_type.get_name().lower()
                _info.is_nullable = property_type.is_nullable()
                _info.is_key = _info.edm_name in entity_type.key()

                type_kind = property_type.get_property_type().get_type_kind()
                if type_kind == edm_type_kind_t.Primitive:
                    _info.strong_type_name = odata_client_python.edm_model_utility.get_strong_type_name_from_edm_type_name(odata_client_python.to_primitive_type(property_type.get_property_type()))
                    _info.type = PROPERTY_TYPE.E_PRIMITIVE
                elif type_kind == edm_type_kind_t.Complex:
                    _info.strong_type_name = _schema_info.class_map[property_type.get_property_type().get_name()].class_name
                    _info.type = PROPERTY_TYPE.E_COMPLEX
                elif type_kind == edm_type_kind_t.Navigation:
                    navigation_type = odata_client_python.to_navigation_type(property_type.get_property_type())
                    if navigation_type.get_navigation_type().get_type_kind() == edm_type_kind_t.Entity:
                        _info.strong_type_name = _schema_info.class_map[navigation_type.get_navigation_type().get_name()].class_name
                        _info.type = PROPERTY_TYPE.E_ENTITY
                    elif navigation_type.get_navigation_type().get_type_kind() == edm_type_kind_t.Collection:
                        collection_entity_type = odata_client_python.to_collection_type(navigation_type.get_navigation_type())
                        _info.strong_type_name = _schema_info.class_map[collection_entity_type.get_element_type().get_name()].class_name
                        _info.type = PROPERTY_TYPE.E_COLLECTION_ENTITY
                elif type_kind == edm_type_kind_t.Enum:
                    if property_type.get_property_type().get_name() not in _schema_info.class_map:
                        _info.strong_type_name = property_type.get_property_type().get_name()
                    else:
                        _info.strong_type_name = _schema_info.class_map[property_type.get_property_type().get_name()].class_name
                    _info.type = PROPERTY_TYPE.E_ENUM
                elif type_kind == edm_type_kind_t.Collection:
                    collection_type = odata_client_python.to_collection_type(property_type.get_property_type())
                    element_type = collection_type.get_element_type()
                    if element_type.get_type_kind() == edm_type_kind_t.Complex:
                        _info.strong_type_name = _schema_info.class_map[element_type.get_name()].class_name
                        _info.type = PROPERTY_TYPE.E_COLLECTION_COMPLEX
                    elif element_type.get_type_kind() == edm_type_kind_t.Primitive:
                        _info.strong_type_name = odata_client_python.edm_model_utility.get_strong_type_name_from_edm_type_name(odata_client_python.to_primitive_type(element_type))
                        _info.type = PROPERTY_TYPE.E_COLLECTION_PRIMITIVE
                    elif element_type.get_type_kind() == edm_type_kind_t.Enum:
                        if element_type.get_name() not in _schema_info.class_map:
                            _info.strong_type_name = element_type.get_name()
                        else:
                            _info.strong_type_name = _schema_info.class_map[element_type.get_name()].class_name
                        _info.type = PROPERTY_TYPE.E_COLLECTION_ENUM

                self._set_default_value(_info, property_type)
                self._set_strong_type_name(_info)
                class_property_map[property_type.get_name()] = _info

            _schema_info.class_property_map[entity_type.get_name()] = class_property_map

        complex_types = schema.get_complex_types_vector()
        for complex_type in complex_types:
            class_property_map = {}
            for property_type in complex_type.get_properties_vector():
                if property_type.get_property_type().get_type_kind() == edm_type_kind_t.Unknown:
                    continue
                _info = property_info()
                _info.edm_name = property_type.get_name()
                _info.class_member_name = property_type.get_name().lower()
                _info.is_nullable = property_type.is_nullable()
                _info.default_value = property_type.default_value()
                
                type_kind = property_type.get_property_type().get_type_kind()
                if type_kind == edm_type_kind_t.Primitive:
                    _info.strong_type_name = odata_client_python.edm_model_utility.get_strong_type_name_from_edm_type_name(odata_client_python.to_primitive_type(property_type.get_property_type()))
                    _info.type = PROPERTY_TYPE.E_PRIMITIVE
                elif type_kind == edm_type_kind_t.Complex:
                    _info.strong_type_name = _schema_info.class_map[property_type.get_property_type().get_name()].class_name
                    _info.type = PROPERTY_TYPE.E_COMPLEX
                elif type_kind == edm_type_kind_t.Enum:
                    if property_type.get_property_type().get_name() not in _schema_info.class_map:
                        _info.strong_type_name = property_type.get_property_type().get_name()
                    else:
                        _info.strong_type_name = _schema_info.class_map[property_type.get_property_type().get_name()].class_name
                    _info.type = PROPERTY_TYPE.E_ENUM
                elif type_kind == edm_type_kind_t.Collection:
                    collection_type = odata_client_python.to_collection_type(property_type.get_property_type())
                    element_type = collection_type.get_element_type()
                    if element_type.get_type_kind() == edm_type_kind_t.Complex:
                        _info.strong_type_name = _schema_info.class_map[element_type.get_name()].class_name
                        _info.type = PROPERTY_TYPE.E_COLLECTION_COMPLEX
                    elif element_type.get_type_kind() == edm_type_kind_t.Primitive:
                        _info.strong_type_name = odata_client_python.edm_model_utility.get_strong_type_name_from_edm_type_name(odata_client_python.to_primitive_type(element_type))
                        _info.type = PROPERTY_TYPE.E_COLLECTION_PRIMITIVE
                    elif element_type.get_type_kind() == edm_type_kind_t.Enum:
                        if element_type.get_name() not in _schema_info.class_map:
                            _info.strong_type_name = element_type.get_name()
                        else:
                            _info.strong_type_name = _schema_info.class_map[element_type.get_name()].class_name
                        _info.type = PROPERTY_TYPE.E_COLLECTION_ENUM
                self._set_default_value(_info, property_type)
                self._set_strong_type_name(_info)
                class_property_map[property_type.get_name()] = _info

            _schema_info.class_property_map[complex_type.get_name()] = class_property_map

        operation_types = schema.get_operation_types_vector()
        for operation_type in operation_types:
            if operation_type.is_bound() and len(operation_type.get_operation_parameters()) > 0:
                bounded_type = operation_type.get_operation_parameters()[0].get_param_type()
                if bounded_type is None:
                    continue
                if bounded_type.get_type_kind() != edm_type_kind_t.Entity:
                    continue
                if bounded_type.get_name() not in _schema_info.class_property_map:
                    continue
                class_property_map = _schema_info.class_property_map[bounded_type.get_name()]

                function_property_info = property_info()
                function_property_info.edm_name = operation_type.get_name()
                function_property_info.class_member_name = operation_type.get_name()
                self._set_operation_info(function_property_info, operation_type, _schema_info)

                class_property_map[operation_type.get_name()] = function_property_info
                _schema_info.class_property_map[bounded_type.get_name()] = class_property_map

        enum_member_name = {}
        enum_types = schema.get_enum_types_vector()
        for enum_type in enum_types:
            class_property_map = {}
            enum_members = enum_type.get_enum_members()
            for enum_member in enum_members:
                _info = property_info()
                _info.edm_name = enum_member.get_enum_member_name()
                member_name = enum_member.get_enum_member_name()
                # TODO: other key words
                if member_name == "None":
                    member_name = '_' + member_name
                if member_name not in enum_member_name:
                    _info.class_member_name = member_name
                else:
                    _info.class_member_name = enum_type.get_name() + "_" + member_name
                enum_member_name[_info.class_member_name] = _info.class_member_name
                _info.default_value = str(enum_member.get_enum_member_value())

                class_property_map[enum_member.get_enum_member_name()] = _info

            _schema_info.class_property_map[enum_type.get_name()] = class_property_map

        if (len(schema.get_containers_vector()) == 1):
            entity_container = schema.find_container()
            class_property_map = {}
            for entity_set in entity_container.get_entity_set_vector():
                _info = property_info()
                _info.edm_name = entity_set.get_name()
                _info.strong_type_name = entity_set.get_entity_type().get_name()
                _info.class_member_name = "query_" + entity_set.get_name().lower()
                _info.type = PROPERTY_TYPE.E_CONTAINER_ENTITY_SET
                class_property_map[_info.class_member_name] = _info

            for singleton in entity_container.get_singleton_vector():
                _info = property_info()
                _info.edm_name = singleton.get_name()
                _info.strong_type_name = singleton.get_entity_type().get_name()
                _info.class_member_name = "query_" + singleton.get_name().lower()
                _info.type = PROPERTY_TYPE.E_CONTAINER_SINGLETON
                class_property_map[_info.class_member_name] = _info

            for operation_import in entity_container.get_operation_import_vector():
                if operation_import is None:
                    continue
                operation_type = operation_import.get_operation_type()
                if operation_type is None:
                    continue
                function_property_info = property_info()
                function_property_info.edm_name = operation_type.get_name()
                function_property_info.class_member_name = operation_type.get_name()
                self._set_operation_info(function_property_info, operation_type, _schema_info)
                class_property_map[operation_import.get_name()] = function_property_info

            _schema_info.class_property_map[entity_container.get_name()] = class_property_map