我使用的是Apache Olingo v2。 SAP是服务器,我负责客户端。 我尝试用导航实体编写一个实体。我解释一下我想说的话。 有一个名为HUIDENT的实体集,该集包含一个名为ToHuContent的导航属性。
<EntityType Name="HUIDENT" sap:content-version="1">
<Key>
<PropertyRef Name="Lgnum"/>
<PropertyRef Name="Huident"/>
</Key>
<Property Name="Lgnum" Type="Edm.String" Nullable="false" MaxLength="4" sap:label="Numéro magasin" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Huident" Type="Edm.String" Nullable="false" MaxLength="20" sap:label="Unité manutent." sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<NavigationProperty Name="ToHuContent" Relationship="SERVICE_HU_CONTENT_SRV.Assoc_Hu_Content" FromRole="FromRole_Assoc_Hu_Content" ToRole="ToRole_Assoc_Hu_Content"/>
</EntityType>
HUCONTENT是
<EntityType Name="HUCONTENT" sap:content-version="1">
<Key>
<PropertyRef Name="Lgnum"/>
<PropertyRef Name="Huident"/>
</Key>
<Property Name="Lgnum" Type="Edm.String" Nullable="false" MaxLength="4" sap:label="Numéro magasin" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Huident" Type="Edm.String" Nullable="false" MaxLength="20" sap:label="Unité manutent." sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Matnr" Type="Edm.String" Nullable="false" MaxLength="40" sap:label="Produit" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Ean11" Type="Edm.String" Nullable="false" MaxLength="18" sap:label="Code EAN/UPC" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Batchid" Type="Edm.Binary" Nullable="false" sap:label="Lot" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Quan" Type="Edm.Decimal" Nullable="false" Precision="31" Scale="14" sap:unit="Unit" sap:label="Quantité" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Unit" Type="Edm.String" Nullable="false" MaxLength="3" sap:label="Unité" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false" sap:semantics="unit-of-measure"/>
<Property Name="Maktx" Type="Edm.String" Nullable="false" MaxLength="40" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<Property Name="Brand" Type="Edm.String" Nullable="false" MaxLength="4" sap:label="Brand" sap:creatable="false" sap:updatable="false" sap:sortable="false" sap:filterable="false"/>
<NavigationProperty Name="ToHuIdent" Relationship="SERVICE_HU_CONTENT_SRV.Assoc_Hu_Content" FromRole="ToRole_Assoc_Hu_Content" ToRole="FromRole_Assoc_Hu_Content"/>
</EntityType>
我想发送一个有一些HUCONTENT的HUIDENT,但我不知道如何做到这一点。 我想要一个像这样的饲料
<?xml version="1.0" encoding="utf-8"?>
<entry xml:base="secretUrl" xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<id>secretUrl/HUIDENTSet(Lgnum='IN01',Huident='155000000000001757')</id>
<title type="text">HUIDENTSet(Lgnum='IN01',Huident='155000000000001757')</title>
<updated>2016-05-26T22:48:07Z</updated>
<category term="SERVICE.HUIDENT" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="HUIDENTSet(Lgnum='IN01',Huident='155000000000001757')" rel="self" title="HUIDENT"/>
<link href="HUIDENTSet(Lgnum='IN01',Huident='155000000000001757')/ToHuContent" rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ToHuContent" type="application/atom+xml;type=feed" title="ToHuContent">
<m:inline>
<feed xml:base="secretUrl/SERVICE/">
<entry>
<content type="application/xml">
<m:properties>
<d:Lgnum>IN01</d:Lgnum>
<d:Huident>155000000000001757</d:Huident>
<d:Epc>12345</d:Epc>
<d:Matnr>1543473</d:Matnr>
<d:Ean>122333</d:Ean>
<d:Expiration_date>2016-05-27T00:00:00</d:Expiration_date>
<d:CRreatedAt>2016-05-26T22:48:00</d:CRreatedAt>
</m:properties>
</content>
</entry>
<entry>
<content type="application/xml">
<m:properties>
<d:Lgnum>IN01</d:Lgnum>
<d:Huident>155000000000001757</d:Huident>
<d:Epc>12345</d:Epc>
<d:RfidStatus/>
<d:Matnr>1543473</d:Matnr>
<d:Expiration_date>2016-05-27T00:00:00</d:Expiration_date>
<d:CRreatedAt>2016-05-26T22:48:00</d:CRreatedAt>
</m:properties>
</content>
</entry>
</feed>
</m:inline>
</link>
<content type="application/xml">
<m:properties>
<d:Lgnum>IN01</d:Lgnum>
<d:Huident>155000000000001757</d:Huident>
</m:properties>
</content>
</entry>
使用Olingo我有点像
final EntityProviderWriteProperties properties = EntityProviderWriteProperties
.serviceRoot(new URI(this.serviceRoot + "/"))
.build();
final ODataResponse response = EntityProvider.writeEntry("application/xml", entitySet, new ImmutableMap.Builder<String, Object>()
.put("Lgnum", "IN01")
.put("Huident", "1")
.build(), properties);
我不知道在哪里可以设置HUCONTENT实体。
答案 0 :(得分:0)
好的,我找到了解决方案。 对我来说,这个原则没有经过深思熟虑。 我解释一下。 首先,向您的实体添加一个导航属性,您需要将一个Map添加到EntityProviderWriteProperties。
final Map<String, Map<String, Object>> toHuContent = new ImmutableMap.Builder<String, Map<String, Object>>()
.put(<YOUR_NAVIGATION_PROPERTY>, new ImmutableMap.Builder<String, Object>().build())
.build();
final EntityProviderWriteProperties properties = EntityProviderWriteProperties
.serviceRoot(new URI(this.serviceRoot + "/"))
.additionalLinks(toHuContent)
.build();
然后,您需要提供展开的树
final ExpandSelectTreeNode node = ExpandSelectTreeNode.entitySet(entitySet).expandedLinks(Lists.newArrayList(<YOUR_NAVIGATION_PROPERTY>).build();
final EntityProviderWriteProperties properties = EntityProviderWriteProperties
.serviceRoot(new URI(this.serviceRoot + "/"))
.additionalLinks(toHuContent)
.expandSelectTree(node)
.build();
最后,要填充导航属性,您需要回调
final EntityProviderWriteProperties properties = EntityProviderWriteProperties
.serviceRoot(new URI(this.serviceRoot + "/"))
.additionalLinks(toHuContent)
.expandSelectTree(node)
.callbacks(new ImmutableMap.Builder<String, ODataCallback>().put(<YOUR_NAVIGATION_PROPERTY>, new PopulateInlineEntry()).build())
.build();
回调需要实现OnWriteFeedContent
@Log4j
public class PopulateInlineEntry implements OnWriteFeedContent {
@Override
public WriteFeedCallbackResult retrieveFeedResult(final WriteFeedCallbackContext writeFeedCallbackContext) throws ODataApplicationException {
final EntityProviderWriteProperties currentWriteProperties = writeFeedCallbackContext.getCurrentWriteProperties();
final WriteFeedCallbackResult result = new WriteFeedCallbackResult();
result.setInlineProperties(currentWriteProperties);
result.setFeedData(Lists.<Map<String, Object>>newArrayList(
new ImmutableMap.Builder<String, Object>()
.put("Lgnum", "IN01")
.put("Huident", "1")
.put("Epc", "1")
.build(),
new ImmutableMap.Builder<String, Object>()
.put("Lgnum", "IN01")
.put("Huident", "1")
.put("Epc", "2")
.build()
));
return result;
}
}
我理解使用树和回调而不是附加链接...... 我阅读了Olingo图书馆的代码,图书馆需要树,附加链接和回调。
我希望这个答案对某人有用