Zebronix_777
Zebronix_777

Reputation: 355

How to add Annotations elements in metadata generated by Apache Olingo V2.0?

I have developed Odata service for a system entity which generates a metadata but however I cant figure out how to add Annotations element to it. Sample Metadata generated is as follows :-

    <?xml version="1.0" encoding="utf-8"?>
    <edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:sap="http://www.sap.com/Protocols/SAPData" Version="1.0">
        <edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
            m:DataServiceVersion="1.0">
            <Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="myNamespace" sap:schema-version="1">
                <EntityType Name="System">
                    <Key>
                        <PropertyRef Name="Id" />
                    </Key>
                    <Property Name="Id" Type="Edm.Int32" Nullable="false" />
                    <Property Name="name" Type="Edm.String" sap:label="System Name" sap:creatable="false"
                        sap:updatable="false" sap:sortable="false" sap:required-in-filter="true"/> 
                    <Property Name="description" Type="Edm.String" />
                    <Property Name="status" Type="Edm.String" />
                    <Property Name="type" Type="Edm.String" />
                </EntityType>
                <EntityContainer Name="ODataEntityContainer" m:IsDefaultEntityContainer="true">
                    <EntitySet Name="Systems" EntityType="myNamespace.System" />
                    <FunctionImport Name="NumberOfSystems" ReturnType="Collection(myNamespace.System)"
                        m:HttpMethod="GET" />
                </EntityContainer>

        </Schema>
    </edmx:DataServices>
</edmx:Edmx>

I need to add following elements to above metatada

<Annotations Target="myNamespace.System"
                xmlns="http://docs.oasis-open.org/odata/ns/edm">
                <Annotation Term="com.sap.vocabularies.UI.v1.LineItem">
                    <Collection>
                        <Record Type="com.sap.vocabularies.UI.v1.DataField">
                            <PropertyValue Property="Value" Path="name" />
                        </Record>
                        <Record Type="com.sap.vocabularies.UI.v1.DataField">
                            <PropertyValue Property="Value" Path="description"/>
                        </Record>
                        <Record Type="com.sap.vocabularies.UI.v1.DataField">
                            <PropertyValue Property="Value" Path="status" />
                        </Record>
                    </Collection>
                </Annotation>
            </Annotations>

I came across the org.apache.olingo.commons.api.edm.provider.annotation package but cant find any suitable API. Please let me know how should I proceed. Thanks in advance.

Upvotes: 1

Views: 1927

Answers (1)

chrisam
chrisam

Reputation: 543

The annotations you would like to use have been introduced with OData V3 which is why they are not directly supported with the Olingo V2 library.

You can use the EdmProvider AnnotationElement and AnnotationAttribute classes to mimic this behaviour though. For example You can create a AnnotationElement with the name "Annotations" this element will then have the "AnnotationAttribute" Target=SomeString. Since an "AnnotationElement" can have child elements you can put your Collection element there. Namespaces are also handled with "AnnotationAttributes". You can only attach the annotation to Edm elements which are derived from the EdmAnnotatable interface. So this is a difference to V3.

This is currently the only way to get this behaviour with Olingo V2.

Upvotes: 2

Related Questions