Warm tip: This article is reproduced from serverfault.com, please click

sap cloud sdk-Odata查询批量请求

(sap cloud sdk - Odata Query Batch Request)

发布于 2021-01-14 13:19:52

我们正在使用 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--

Questioner
Arun Kumar
Viewed
0
Alexander Dümont 2021-03-22 18:01:21

更新 (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 BatchRequestBuilderBatchRequest或者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();
}

亲切的问候

亚历山大