【问题标题】:How to add Annotations elements in metadata generated by Apache Olingo V2.0?如何在 Apache Olingo V2.0 生成的元数据中添加注释元素?
【发布时间】:2015-12-15 05:28:07
【问题描述】:

我为生成元数据的系统实体开发了 Odata 服务,但我不知道如何向其中添加 Annotations 元素。生成的示例元数据如下:-

    <?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>

我需要在上面的元数据中添加以下元素

<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>

我遇到了org.apache.olingo.commons.api.edm.provider.annotation 包,但找不到任何合适的 API。请让我知道我应该如何进行。 提前致谢。

【问题讨论】:

    标签: java odata olingo


    【解决方案1】:

    OData V3 引入了您想要使用的注释,这就是 Olingo V2 库不直接支持它们的原因。

    您可以使用 EdmProvider AnnotationElement 和 AnnotationAttribute 类来模拟这种行为。例如,您可以创建一个名为“Annotations”的 AnnotationElement,然后该元素将具有“AnnotationAttribute”Target=SomeString。由于“AnnotationElement”可以有子元素,因此您可以将 Collection 元素放在那里。命名空间也使用“AnnotationAttributes”处理。 您只能将注释附加到从 EdmAnnototatable 接口派生的 Edm 元素。所以这与 V3 有所不同。

    这是目前使用 Olingo V2 获得此行为的唯一方法。

    【讨论】:

    • 谢谢@chrisam。 AnnotationElement,AnnotationAttribute 为我完成。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-21
    • 1970-01-01
    • 2016-11-14
    • 2015-09-29
    • 2016-10-09
    • 1970-01-01
    • 2018-08-26
    相关资源
    最近更新 更多