gpt4 book ai didi

odata - 如何在 olingo 中创建复杂类型集合

转载 作者:行者123 更新时间:2023-12-01 09:55:27 25 4
gpt4 key购买 nike

我尝试按照下面的 olingo 文档来创建一个 odata 服务。

AnnotationProcessor

但我无法创建具有类型为 ComplexType 列表的属性的实体。任何人都有它的例子。还是只是不支持?

最佳答案

也许 Utsav 的答案在当时是正确的,但 Odata v4 确实支持具有类型为“ComplexType 列表”的属性的实体。
证明:this sample entityType Person 具有属性 AddressInfo,其类型是 ComplexType 的集合:

<ComplexType Name="Location" OpenType="true">
<Property Name="Address" Type="Edm.String" Nullable="false"/>
<Property Name="City" Type="Microsoft.OData.SampleService.Models.TripPin.City" Nullable="false"/>
</ComplexType>
...
<EntityType Name="Person" OpenType="true">
<Property Name="AddressInfo" Type="Collection(Microsoft.OData.SampleService.Models.TripPin.Location)"/>
...
</EntityType>

关于 Olingo 实现,在您的 CSDL 提供程序中,您必须正确定义您的复杂类型实体,然后定义您希望成为此复杂类型集合的属性。然后你必须正确处理结果。

1。在 CSDL 提供程序中定义元数据

在您的提供者的 getSchemas() 方法中,您必须声明您的复杂类型:

    List <CsdlComplexType> complexTypes = new ArrayList<>();
//...initialization of complexTypes list...
schema.setComplexTypes(complexTypes);

getEntityType() 方法中,您必须将属性创建为复杂类型对象的集合:

    //...initialization of entityType...
List<CsdlProperty> properties = new ArrayList<>();
FullQualifiedName type;
//...initialization of the type as a complex type...
properties.add(new CsdlProperty().setName("propertyName").setType(type).setCollection(true));
entityType.setProperties(properties);
//...

2。处理结果

在您的处理器实现中,您必须正确构建您的实体:例如,在 EntityCollectionProcessor 实现的 readEntityCollection() 方法中,您应该有类似的内容:

    EntityCollection entities = new EntityCollection();
List<Entity> eList = entities.getEntities();
Entity e = new Entity();
List<Map> data;
//...initialization of complex type's data...
List<ComplexValue> properties = new ArrayList<>();
for (Object complexObject : data) {
ComplexValue complexValue = new ComplexValue();
for (Map.Entry<String, Object> entry : complexObject.entrySet()) {
complexValue.getValue().add(new Property(null, entry.getKey(), ValueType.PRIMITIVE, entry.getValue()));
}
properties.add(complexValue);
}
e.addProperty(new Property(null, "propertyName", ValueType.COLLECTION_COMPLEX, properties););
eList.add(e);

//...serialize and set the result to response

关于odata - 如何在 olingo 中创建复杂类型集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28916364/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com