Class sap.ui.model.odata.ODataMetaModelModule: sap/ui/model/odata/ODataMetaModel

extends MetaModel

Implementation of an OData meta model which offers a unified access to both OData V2 meta data 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.

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:

  • label;
  • creatable, deletable, deletable-path, pageable, requires-filter, searchable, topable, updatable and updatable-path on entity sets;
  • creatable, display-format ("UpperCase" and "NonNegative"), field-control, filterable, filter-restriction, heading, precision, quickinfo, required-in-filter, sortable, text, unit, updatable and visible on properties;
  • semantics; the following values are supported:
    • "bday", "city", "country", "email" (including support for types, for example "email;type=home,pref"), "familyname", "givenname", "honorific", "middlename", "name", "nickname", "note", "org", "org-unit", "org-role", "photo", "pobox", "region", "street", "suffix", "tel" (including support for types, for example "tel;type=cell,pref"), "title" and "zip" (mapped to V4 annotation com.sap.vocabularies.Communication.v1.Contact);
    • "class", "dtend", "dtstart", "duration", "fbtype", "location", "status", "transp" and "wholeday" (mapped to V4 annotation com.sap.vocabularies.Communication.v1.Event);
    • "body", "from", "received", "sender" and "subject" (mapped to V4 annotation com.sap.vocabularies.Communication.v1.Message);
    • "completed", "due", "percent-complete" and "priority" (mapped to V4 annotation com.sap.vocabularies.Communication.v1.Task).
For example:
		{
			"name" : "BusinessPartnerID",
			...
			"sap:label" : "Bus. Part. ID",
			"com.sap.vocabularies.Common.v1.Label" : {
				"String" : "Bus. Part. ID"
			}
		}

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!


Since: 1.27.0.
Constructor Summary
new sap.ui.model.odata.ODataMetaModel(oMetadata, oAnnotations?, oODataModelInterface?)DO NOT CALL this private constructor for a new ODataMetaModel, but rather use getMetaModel instead!
Method Summary
sap.ui.model.odata.ODataMetaModel.extend(sClassName, oClassInfo?, FNMetaImpl?)Creates a new subclass of class sap.ui.model.odata.ODataMetaModel with name sClassName and enriches it with the information contained in oClassInfo.
sap.ui.model.odata.ODataMetaModel.getMetadata()Returns a metadata object for class sap.ui.model.odata.ODataMetaModel.
getMetaContext(sPath?)Returns the OData meta model context corresponding to the given OData model path.
getODataAssociationEnd(oEntityType, sName)Returns the OData association end corresponding to the given entity type's navigation property of given name.
getODataAssociationSetEnd(oEntityType, sName)Returns the OData association set end corresponding to the given entity type's navigation property of given name.
getODataComplexType(sQualifiedName, bAsPath?)Returns the OData complex type with the given qualified name, either as a path or as an object, as indicated.
getODataEntityContainer(bAsPath?)Returns the OData default entity container.
getODataEntitySet(sName, bAsPath?)Returns the OData entity set with the given simple name from the default entity container.
getODataEntityType(sQualifiedName, bAsPath?)Returns the OData entity type with the given qualified name, either as a path or as an object, as indicated.
getODataFunctionImport(sName, bAsPath?)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(oType, vName, bAsPath?)Returns the given OData type's property (not navigation property!) of given name.
getODataValueLists(oPropertyContext)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.
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!
setLegacySyntax(bLegacySyntax)Legacy syntax not supported by OData meta model!
Methods borrowed from class sap.ui.base.Object
Constructor Detail
new sap.ui.model.odata.ODataMetaModel(oMetadata, oAnnotations?, oODataModelInterface?)
DO NOT CALL this private constructor for a new ODataMetaModel, but rather use getMetaModel instead!
Parameters:
{sap.ui.model.odata.ODataMetadata}oMetadata the OData model's meta data object
{sap.ui.model.odata.ODataAnnotations}oAnnotations? the OData model's annotations object
{object}oODataModelInterface? the private interface object of the OData model which provides friend access to selected methods
{function}oODataModelInterface.addAnnotationUrl? the addAnnotationUrl method of the OData model, in case this feature is supported
{Promise}oODataModelInterface.annotationsLoadedPromise? a promise which is resolved by the OData model once meta data and annotations have been fully loaded
Method Detail
sap.ui.model.odata.ODataMetaModel.extend(sClassName, oClassInfo?, FNMetaImpl?): function
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.

Parameters:
{string}sClassName Name of the class being created
{object}oClassInfo? Object literal with information about the class
{function}FNMetaImpl? Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata
Returns:
{function} Created class / constructor function
sap.ui.model.odata.ODataMetaModel.getMetadata(): sap.ui.base.Metadata
Returns a metadata object for class sap.ui.model.odata.ODataMetaModel.
Returns:
{sap.ui.base.Metadata} Metadata object describing this class
getMetaContext(sPath?): sap.ui.model.Context
Returns the OData meta model context corresponding to the given OData model path.
Parameters:
{string}sPath? 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
Exceptions:
{Error} in case no context can be determined
Returns:
{sap.ui.model.Context} the context for the corresponding meta data object, i.e. an entity type or its property, or null in case no path is given
getODataAssociationEnd(oEntityType, sName): object
Returns the OData association end corresponding to the given entity type's navigation property of given name.
Parameters:
{object}oEntityType an entity type as returned by getODataEntityType
{string}sName the name of a navigation property within this entity type
Returns:
{object} the OData association end or null if no such association end is found
getODataAssociationSetEnd(oEntityType, sName): object
Returns the OData association set end corresponding to the given entity type's navigation property of given name.
Parameters:
{object}oEntityType an entity type as returned by getODataEntityType
{string}sName the name of a navigation property within this entity type
Returns:
{object} the OData association set end or null if no such association set end is found
getODataComplexType(sQualifiedName, bAsPath?): object|string
Returns the OData complex type with the given qualified name, either as a path or as an object, as indicated.
Parameters:
{string}sQualifiedName a qualified name, e.g. "ACME.Address"
{boolean}bAsPath? determines whether the complex type is returned as a path or as an object
Returns:
{object|string} (the path to) the complex type with the given qualified name; undefined (for a path) or null (for an object) if no such type is found
getODataEntityContainer(bAsPath?): object|string
Returns the OData default entity container.
Parameters:
{boolean}bAsPath? determines whether the entity container is returned as a path or as an object
Returns:
{object|string} (the path to) the default entity container; undefined (for a path) or null (for an object) if no such container is found
getODataEntitySet(sName, bAsPath?): object|string
Returns the OData entity set with the given simple name from the default entity container.
Parameters:
{string}sName a simple name, e.g. "ProductSet"
{boolean}bAsPath? determines whether the entity set is returned as a path or as an object
Returns:
{object|string} (the path to) the entity set with the given simple name; undefined (for a path) or null (for an object) if no such set is found
getODataEntityType(sQualifiedName, bAsPath?): object|string
Returns the OData entity type with the given qualified name, either as a path or as an object, as indicated.
Parameters:
{string}sQualifiedName a qualified name, e.g. "ACME.Product"
{boolean}bAsPath? determines whether the entity type is returned as a path or as an object
Returns:
{object|string} (the path to) the entity type with the given qualified name; undefined (for a path) or null (for an object) if no such type is found
getODataFunctionImport(sName, bAsPath?): object|string
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.
Parameters:
{string}sName a simple or qualified name, e.g. "Save" or "MyService.Entities/Save"
{boolean}bAsPath? determines whether the function import is returned as a path or as an object
Since:
1.29.0
Returns:
{object|string} (the path to) the function import with the given simple name; undefined (for a path) or null (for an object) if no such function import is found
getODataProperty(oType, vName, bAsPath?): object|string
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";
    
Parameters:
{object}oType a complex type as returned by getODataComplexType, or an entity type as returned by getODataEntityType
{string|string[]}vName 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!
{boolean}bAsPath? determines whether the property is returned as a path or as an object
Returns:
{object|string} (the path to) the last OData property found; undefined (for a path) or null (for an object) if no property was found at all
getODataValueLists(oPropertyContext): Promise
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.
Parameters:
{sap.ui.model.Context}oPropertyContext a model context for a structural property of an entity type or a complex type, as returned by getMetaContext
Since:
1.29.1
Returns:
{Promise} a Promise that gets resolved as soon as the value lists as well as the required model elements have been loaded
loaded(): Promise
Returns a promise which is fulfilled once the meta model data is loaded and can be used.
Returns:
{Promise} a Promise
refresh(): void
Refresh not supported by OData meta model!
Exceptions:
{Error}
setLegacySyntax(bLegacySyntax): void
Legacy syntax not supported by OData meta model!
Parameters:
{boolean}bLegacySyntax must not be true!
Exceptions:
{Error} if bLegacySyntax is true