class sap.ui.model.odata.ODataMetaModel

Visiblity: public
UX Guidelines:
Implements:
Available since: N/A
Module: sap/ui/model/odata/ODataMetaModel
Application Component: CA-UI5-COR

Implementation of an OData meta model which offers a unified access to both OData V2 metadata and V4 annotations. It uses the existing sap.ui.model.odata.ODataMetadata as a foundation and merges V4 annotations from the existing sap.ui.model.odata.ODataAnnotations directly into the corresponding model element.

This model is not prepared to be inherited from.

Also, annotations from the "http://www.sap.com/Protocols/SAPData" namespace are lifted up from the extensions array and transformed from objects into simple properties with an "sap:" prefix for their name. Note that this happens in addition, thus the following example shows both representations. This way, such annotations can be addressed via a simple relative path instead of searching an array.

		{
			"name" : "BusinessPartnerID",
			"extensions" : [{
				"name" : "label",
				"value" : "Bus. Part. ID",
				"namespace" : "http://www.sap.com/Protocols/SAPData"
			}],
			"sap:label" : "Bus. Part. ID"
		}

As of 1.29.0, the corresponding vocabulary-based annotations for the following "SAP Annotations for OData Version 2.0" are added, if they are not yet defined in the V4 annotations:

For example:
		{
			"name" : "BusinessPartnerID",
			...
			"sap:label" : "Bus. Part. ID",
			"com.sap.vocabularies.Common.v1.Label" : {
				"String" : "Bus. Part. ID"
			}
		}
Note: Annotation terms are not merged, but replaced as a whole ("PUT" semantics). That means, if you have, for example, an OData V2 annotation sap:sortable=false at a property PropA, the corresponding OData V4 annotation is added to each entity set to which this property belongs:
		"Org.OData.Capabilities.V1.SortRestrictions": {
			"NonSortableProperties" : [
				{"PropertyPath" : "BusinessPartnerID"}
			]
		}
If the same term "Org.OData.Capabilities.V1.SortRestrictions" targeting one of these entity sets is also contained in an annotation file, the complete OData V4 annotation converted from the OData V2 annotation is replaced by the one contained in the annotation file for the specified target. Converted annotations never use a qualifier and are only overwritten by the same annotation term without a qualifier.

This model is read-only and thus only supports OneTime binding mode. No events (parseError, requestCompleted, requestFailed, requestSent) are fired!

Within the meta model, the objects are arranged in arrays. /dataServices/schema, for example, is an array of schemas where each schema has an entityType property with an array of entity types, and so on. So, /dataServices/schema/0/entityType/16 can be the path to the entity type with name "Order" in the schema with namespace "MySchema". However, these paths are not stable: If an entity type with lower index is removed from the schema, the path to Order changes to /dataServices/schema/0/entityType/15.

To avoid problems with changing indexes, getObject and getProperty support XPath-like queries for the indexes (since 1.29.1). Each index can be replaced by a query in square brackets. You can, for example, address the schema using the path /dataServices/schema/[${namespace}==='MySchema'] or the entity using /dataServices/schema/[${namespace}==='MySchema']/entityType/[sap.ui.core==='Order'].

The syntax inside the square brackets is the same as in expression binding. The query is executed for each object in the array until the result is true (truthy) for the first time. This object is then chosen.

BEWARE: Access to this OData meta model will fail before the promise returned by loaded has been resolved!


Constructor

DO NOT CALL this private constructor for a new ODataMetaModel, but rather use getMetaModel instead!

new sap.ui.model.odata.ODataMetaModel(oMetadata, oAnnotations?, oDataModel)
Param Type Default Value Description
oMetadata sap.ui.model.odata.ODataMetadata

the OData model's metadata object

oAnnotations? sap.ui.model.odata.ODataAnnotations

the OData model's annotations object

oDataModel sap.ui.model.odata.v2.ODataModel

the data model instance


Methods Overview

Method Description
sap.ui.model.odata.ODataMetaModel.extend

Creates a new subclass of class sap.ui.model.odata.ODataMetaModel with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.model.MetaModel.extend.

getMetaContext

Returns the OData meta model context corresponding to the given OData model path.

sap.ui.model.odata.ODataMetaModel.getMetadata

Returns a metadata object for class sap.ui.model.odata.ODataMetaModel.

getODataAssociationEnd

Returns the OData association end corresponding to the given entity type's navigation property of given name.

getODataAssociationSetEnd

Returns the OData association set end corresponding to the given entity type's navigation property of given name.

getODataComplexType

Returns the OData complex type with the given qualified name, either as a path or as an object, as indicated.

getODataEntityContainer

Returns the OData default entity container. If there is only a single schema with a single entity container, the entity container does not need to be marked as default explicitly.

getODataEntitySet

Returns the OData entity set with the given simple name from the default entity container.

getODataEntityType

Returns the OData entity type with the given qualified name, either as a path or as an object, as indicated.

getODataFunctionImport

Returns the OData function import with the given simple or qualified name from the default entity container or the respective entity container specified in the qualified name.

getODataProperty

Returns the given OData type's property (not navigation property!) of given name.

If an array is given instead of a single name, it is consumed (via Array.prototype.shift) piece by piece. Each element is interpreted as a property name of the current type, and the current type is replaced by that property's type. This is repeated until an element is encountered which cannot be resolved as a property name of the current type anymore; in this case, the last property found is returned and vName contains only the remaining names, with vName[0] being the one which was not found.

Examples:

  • Get address property of business partner:
    var oEntityType = oMetaModel.getODataEntityType("GWSAMPLE_BASIC.BusinessPartner"),
        oAddressProperty = oMetaModel.getODataProperty(oEntityType, "Address");
    oAddressProperty.name === "Address";
    oAddressProperty.type === "GWSAMPLE_BASIC.CT_Address";
    
  • Get street property of address type:
    var oComplexType = oMetaModel.getODataComplexType("GWSAMPLE_BASIC.CT_Address"),
        oStreetProperty = oMetaModel.getODataProperty(oComplexType, "Street");
    oStreetProperty.name === "Street";
    oStreetProperty.type === "Edm.String";
    
  • Get address' street property directly from business partner:
    var aParts = ["Address", "Street"];
    oMetaModel.getODataProperty(oEntityType, aParts) === oStreetProperty;
    aParts.length === 0;
    
  • Trying to get address' foo property directly from business partner:
    aParts = ["Address", "foo"];
    oMetaModel.getODataProperty(oEntityType, aParts) === oAddressProperty;
    aParts.length === 1;
    aParts[0] === "foo";
    

getODataValueLists

Returns a Promise which is resolved with a map representing the com.sap.vocabularies.Common.v1.ValueList annotations of the given property or rejected with an error. The key in the map provided on successful resolution is the qualifier of the annotation or the empty string if no qualifier is defined. The value in the map is the JSON object for the annotation. The map is empty if the property has no com.sap.vocabularies.Common.v1.ValueList annotations.

loaded

Returns a promise which is fulfilled once the meta model data is loaded and can be used.

refresh

Refresh not supported by OData meta model!

requestCurrencyCodes

Requests the currency customizing based on the code list reference given in the entity container's com.sap.vocabularies.CodeList.v1.CurrencyCodes annotation. The corresponding HTTP request uses the HTTP headers obtained via sap.ui.model.odata.v2.ODataModel#getHttpHeaders from this meta model's data model.

References:

  • #requestUnitsOfMeasure

requestUnitsOfMeasure

Requests the unit customizing based on the code list reference given in the entity container's com.sap.vocabularies.CodeList.v1.UnitOfMeasure annotation. The corresponding HTTP request uses the HTTP headers obtained via sap.ui.model.odata.v2.ODataModel#getHttpHeaders from this meta model's data model.

References:

  • #requestCurrencyCodes

setLegacySyntax

Legacy syntax not supported by OData meta model!

sap.ui.model.odata.ODataMetaModel.extend

Creates a new subclass of class sap.ui.model.odata.ODataMetaModel with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.model.MetaModel.extend.

Param Type DefaultValue Description
sClassName string

Name of the class being created

oClassInfo object

Object literal with information about the class

FNMetaImpl function

Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class

getMetaContext

Returns the OData meta model context corresponding to the given OData model path.

Param Type DefaultValue Description
sPath string

an absolute path pointing to an entity or property, e.g. "/ProductSet(1)/ToSupplier/BusinessPartnerID"; this equals the resource path component of a URI according to OData V2 URI conventions

sap.ui.model.odata.ODataMetaModel.getMetadata

Returns a metadata object for class sap.ui.model.odata.ODataMetaModel.

getODataAssociationEnd

Returns the OData association end corresponding to the given entity type's navigation property of given name.

Param Type DefaultValue Description
oEntityType object

an entity type as returned by getODataEntityType

sName string

the name of a navigation property within this entity type

getODataAssociationSetEnd

Returns the OData association set end corresponding to the given entity type's navigation property of given name.

Param Type DefaultValue Description
oEntityType object

an entity type as returned by getODataEntityType

sName string

the name of a navigation property within this entity type

getODataComplexType

Returns the OData complex type with the given qualified name, either as a path or as an object, as indicated.

Param Type DefaultValue Description
sQualifiedName string

a qualified name, e.g. "ACME.Address"

bAsPath boolean false

determines whether the complex type is returned as a path or as an object

getODataEntityContainer

Returns the OData default entity container. If there is only a single schema with a single entity container, the entity container does not need to be marked as default explicitly.

Param Type DefaultValue Description
bAsPath boolean false

determines whether the entity container is returned as a path or as an object

getODataEntitySet

Returns the OData entity set with the given simple name from the default entity container.

Param Type DefaultValue Description
sName string

a simple name, e.g. "ProductSet"

bAsPath boolean false

determines whether the entity set is returned as a path or as an object

getODataEntityType

Returns the OData entity type with the given qualified name, either as a path or as an object, as indicated.

Param Type DefaultValue Description
sQualifiedName string

a qualified name, e.g. "ACME.Product"

bAsPath boolean false

determines whether the entity type is returned as a path or as an object

getODataFunctionImport

Returns the OData function import with the given simple or qualified name from the default entity container or the respective entity container specified in the qualified name.

Param Type DefaultValue Description
sName string

a simple or qualified name, e.g. "Save" or "MyService.Entities/Save"

bAsPath boolean false

determines whether the function import is returned as a path or as an object

getODataProperty

Returns the given OData type's property (not navigation property!) of given name.

If an array is given instead of a single name, it is consumed (via Array.prototype.shift) piece by piece. Each element is interpreted as a property name of the current type, and the current type is replaced by that property's type. This is repeated until an element is encountered which cannot be resolved as a property name of the current type anymore; in this case, the last property found is returned and vName contains only the remaining names, with vName[0] being the one which was not found.

Examples:

Param Type DefaultValue Description
oType object

a complex type as returned by getODataComplexType, or an entity type as returned by getODataEntityType

vName string string[]

the name of a property within this type (e.g. "Address"), or an array of such names (e.g. ["Address", "Street"]) in order to drill-down into complex types; BEWARE that this array is modified by removing each part which is understood!

bAsPath boolean false

determines whether the property is returned as a path or as an object

getODataValueLists

Returns a Promise which is resolved with a map representing the com.sap.vocabularies.Common.v1.ValueList annotations of the given property or rejected with an error. The key in the map provided on successful resolution is the qualifier of the annotation or the empty string if no qualifier is defined. The value in the map is the JSON object for the annotation. The map is empty if the property has no com.sap.vocabularies.Common.v1.ValueList annotations.

Param Type DefaultValue Description
oPropertyContext sap.ui.model.Context

a model context for a structural property of an entity type or a complex type, as returned by getMetaContext

loaded

Returns a promise which is fulfilled once the meta model data is loaded and can be used.

refresh

Refresh not supported by OData meta model!

requestCurrencyCodes

Requests the currency customizing based on the code list reference given in the entity container's com.sap.vocabularies.CodeList.v1.CurrencyCodes annotation. The corresponding HTTP request uses the HTTP headers obtained via sap.ui.model.odata.v2.ODataModel#getHttpHeaders from this meta model's data model.

References:

requestUnitsOfMeasure

Requests the unit customizing based on the code list reference given in the entity container's com.sap.vocabularies.CodeList.v1.UnitOfMeasure annotation. The corresponding HTTP request uses the HTTP headers obtained via sap.ui.model.odata.v2.ODataModel#getHttpHeaders from this meta model's data model.

References:

setLegacySyntax

Legacy syntax not supported by OData meta model!

Param Type DefaultValue Description
bLegacySyntax boolean

must not be true!