我们正在使用 SAP SDK 3.25.0 并通过一些过滤器调用批处理请求读取查询。我得到了所有记录的响应,可以看出过滤器工作不正常。
我在这里提到了这个博客,但我遇到了同样的解码 URL 问题YY1_QuantityContractTracki?$filter=((CustomerName eq %27Ford%27) and (SalesSchedulingAgreement eq %270030000141%27)) and (PurchaseOrderByCustomer eq %27TEST%27)&$select=SalesSchedulingAgreement,PurchaseOrderByCustomer,Customer,CustomerName,SalesSchedulingAgreementItem,Material,MaterialByCustomer&$format=json
下面是我正在使用的查询程序。
我在这里错过了什么。请让我们知道谢谢,Arun Pai
final BatchRequestBuilder builder = BatchRequestBuilder.withService("/sap/opu/odata/sap/YY1_QUANTITYCONTRACTTRACKI_CDS");
for (Contract contract : contracts) {
FilterExpression mainFilter = new FilterExpression("CustomerName", "eq", ODataType.of(contract.getCustomerName()))
.and(new FilterExpression("SalesSchedulingAgreement", "eq", ODataType.of(contract.getSchAgrmntNo())))
.and(new FilterExpression("PurchaseOrderByCustomer", "eq", ODataType.of(contract.getCustRefNo())));
final ODataQuery oDataQuery = ODataQueryBuilder
.withEntity(sapConfig.getEssentialsContractServiceUrl(),
sapConfig.getEssentialsContractListEntity())
.select("SalesSchedulingAgreement", "PurchaseOrderByCustomer", "Customer", "CustomerName",
"SalesSchedulingAgreementItem", "Material", "MaterialByCustomer")
.filter(mainFilter)
.build();
builder.addQueryRequest(oDataQuery);
}
final BatchRequest batchRequest = builder.build();
final BatchResult batchResult = batchRequest.execute(httpClient);
更新
我今天已将版本更改为 3.35.0,连接版本为 1.40.11,但它也不起作用。下面是在控制台中打印的日志请求
2021-01-15 19:15:03.831 INFO 42640 --- [io-8084-exec-10] cscsocimpl.BatchRequestImpl:--batch_123 内容类型:应用程序/http 内容传输编码:二进制
GET YY1_QuantityContractTracki?%24filter%3D%28%28CustomerName+eq+%2527Ford27%29+and+%28SalesSchedulingAgreement+eq+%25270030000141%2527%29%29+and+%28%29+and+%28Purchase%Scheduling%2%SchedulingAgreement2%SchedulingAgreement2%SchedulingAgreement2%Scheduling+%28%27%28%SchedulingAgreement 2CPurchaseOrderByCustomer%2CCustomer%2CCustomerName%2CSalesSchedulingAgreementItem%2CMaterial%2CMaterialByCustomer%26%24format%3Djson HTTP/1.1 接受:application/json;odata=verbose
--batch_123--
更新 (22.03.2021)
随着本周SAP Cloud SDK 的发布,3.41.0
我们将启用对类型安全 API 上 OData 批处理请求中的读取操作的支持。请在相应的文档中找到相关章节。例子:
BusinessPartnerService service;
BusinessPartnerAddress addressToCreate1;
BusinessPartnerAddress addressToCreate2;
BusinessPartnerFluentHelper requestTenEntities = service.getAllBusinessPartner().top(10);
BusinessPartnerByKeyFluentHelper requestSingleEntity = service.getBusinessPartnerByKey("bupa9000");
BatchResponse result =
service
.batch()
.addReadOperations(requestTenEntities)
.addReadOperations(requestSingleEntity)
.executeRequest(destination);
List<BusinessPartner> entities = result.getReadResult(requestTenEntities);
BusinessPartner entity = result.getReadResult(requestSingleEntity);
原回复:
我来自SAP Cloud SDK团队。通常,我们建议用户为其 OData 服务交互生成类。通过这种方式,你可以轻松确保请求符合规范,同时兼顾类型安全。
不幸的是,我无法帮助你使用 的 API BatchRequestBuilder
,BatchRequest
或者BatchResult
因为它们不是SAP Cloud SDK 的直接一部分,也不是由我们维护的。相反,我们建议我们自己的请求构建器。
如果类的生成,上面的联系,是不适合你的选择,那么我会建议尝试我们的专家API为特色的通用的OData客户端的SAP云SDK。这是我们也将在内部用于生成的请求构建器的代码:
String servicePath = "/sap/opu/odata/sap/YY1_QUANTITYCONTRACTTRACKI_CDS";
ODataRequestBatch requestBatch = new ODataRequestBatch(servicePath, ODataProtocol.V2);
Map<Contract, ODataRequestRead> batchedRequests = new HashMap<>();
// iterate over contracts, construct OData query objects and add them to the OData batch request builder
for (Contract contract : contracts) {
String entityName = sapConfig.getEssentialsContractListEntity();
String serviceUrl = sapConfig.getEssentialsContractServiceUrl();
StructuredQuery structuredQuery = StructuredQuery.onEntity(entityName, ODataProtocol.V2);
structuredQuery.select("SalesSchedulingAgreement", "PurchaseOrderByCustomer", "Customer", "CustomerName", "SalesSchedulingAgreementItem", "Material", "MaterialByCustomer");
structuredQuery.filter(FieldReference.of("SalesSchedulingAgreement").equalTo(contract.getSchAgrmntNo()));
structuredQuery.filter(FieldReference.of("PurchaseOrderByCustomer").equalTo(contract.getCustRefNo()));
String encodedQuery = structuredQuery.getEncodedQueryString();
ODataRequestRead requestRead = new ODataRequestRead(serviceUrl, entityName, encodedQuery, ODataProtocol.V2);
batchedRequests.put(contract, requestRead);
requestBatch.addRead(requestRead);
}
// execute the OData batch request
ODataRequestResultMultipartGeneric batchResult = requestBatch.execute(httpClient);
// extract information from batch response, by referring to the individual OData request references
for( Map.Entry<Contract, ODataRequestRead> requestMapping : batchedRequests.entrySet() ) {
ODataRequestResultGeneric queryResult = batchResult.getResult(requestMapping.getValue());
List<Map<String, Object>> itemsForQuery = queryResult.asListOfMaps();
}
亲切的问候
亚历山大
谢谢。上述解决方案有效。我可以在结构化查询类中看到标签@Beta。这会改吗??
正确的。Maven 模块的大多数类
com.sap.cloud.sdk.datamodel:odata-client
都带有@Beta
注释,表明某些公共 API 可能仍会发生变化。截至今天,上述 API 是从OData V2的批处理结果读取 OData 读取响应的唯一选项。这会改变吗?是的,当然。要么扩展OData V2请求构建器 API,要么通用 OData 客户端(此处)为非测试版。不幸的是,我不能保证一个时间表。这种变化对您的项目来说是关键/紧急的吗?是的。这很关键,因为我在我们的项目中使用它来使功能稳定。如果我使用 Odata Generator -VDM 模型,这个问题可以解决吗??请建议
@ArunKumar,我们有它在待办事项中,当您计划将其用于生产时,我将其重新优先考虑到顶部。您是否有一个时间框架来有效地发布与您的计划相匹配的内容?我会看看我们能做些什么。
我们计划在 2 月中旬左右发布,并在 2 月的第一周发布开发截止日期。如果可以在那个时候发布,那就太好了!使用 Odata 生成器的另一个问题 - vdm 模型作为选项,它会起作用吗?