Java 如何在ApacheOlingoV2.0生成的元数据中添加注释元素?
我为一个系统实体开发了Odata服务,该服务生成元数据,但我不知道如何向其中添加Java 如何在ApacheOlingoV2.0生成的元数据中添加注释元素?,java,odata,olingo,Java,Odata,Olingo,我为一个系统实体开发了Odata服务,该服务生成元数据,但我不知道如何向其中添加注释元素。生成的元数据示例如下:- <?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">
注释元素。生成的元数据示例如下:-
<?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>
我需要在上面的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>
我遇到了org.apache.olingo.commons.api.edm.provider.annotation
包,但找不到任何合适的api。请让我知道我应该如何进行。
提前感谢。您想要使用的注释是在OData V3中引入的,这就是为什么Olingo V2库不直接支持它们的原因
不过,您可以使用EdmProvider AnnotationElement和AnnotationAttribute类来模拟此行为。例如,您可以创建一个名为“Annotations”的AnnotationElement,然后该元素将具有“AnnotationAttribute”Target=SomeString。因为“AnnotationElement”可以有子元素,所以可以将集合元素放在那里。名称空间也使用“AnnotationAttributes”进行处理。
只能将注释附着到从EdmAnnotatable界面派生的Edm图元。所以这与V3不同
这是目前使用Olingo V2获得此行为的唯一方法。谢谢@chrisam。AnnotationElement,AnnotationAttribute为我完成。