Warm tip: This article is reproduced from stackoverflow.com, please click
sap-cloud-sdk

E-Tag handling for odatav2 in SAP Cloud SDK VDM

发布于 2020-04-16 12:24:25

Using LATEST java SAP Cloud Sdk

We are trying to perform an update to OutboundDelivery in S/4 system. We are using API_OUTBOUND_DELIVERY_SRV version 2 for it. The service requires us to use etag, i.e. it requires us to provide a header - if-match with the corresponding value of the etag.

We are using VDM for performing the update and are making use of com.sap.cloud.sdk.s4hana.datamodel.odata.namespaces.outbounddeliveryv2.batch.OutboundDeliveryV2ServiceBatch. Please find the code snippet used for update, below:

...
OutboundDeliveryV2ServiceBatch service = // Instantiate service;

List<OutbDeliverItem> itemsToUpdate = new ArrayList<>();

items.add(OutbDeliveryItem.builder()
            .deliveryDocument("some key")
            .deliveryDocumentItem("some key")
            .build());

// Assume more additions to items
...
...
...

OutboundDeliveryV2ServiceBatchChangeSet changeSet = service.beginChangeSet();

items.forEach(changeSet::updateOutbDeliveryItem);

changeSet.endChangeSet();

BatchResponse response = service.execute(someDestination);
...

As soon as service.execute(someDestination) is executed, the update is not performed on S/4 and the logs on S/4 give following error:

The Data Service Request is required to be conditional. Try using the "If-Match" header.

My questions:

  1. Why does the VDM/SDK not take care of etag handling internally? According to the section Optimistic concurrency control in this blog, it is mentioned that it is taken care of automatically in javascript sdk but what about java sdk?
  2. Is it possible to pass this header by using VDM somehow? If yes then how?
  3. Or do we have to let go of the optimistic concurrency control from our service in S/4?

Please note that we have to use the batch operation itself due to performance reasons.

Questioner
cleancoder
Viewed
43
MatKuhr 2020-02-05 17:52

The ETags are missing because the items to be updated are programmatically created in your application using the builder pattern. Therefore, no ETags are present on them when you execute update and the SDK has none available to set the "If-Match" header when building up the request.

The solution is to fetch the items from the server first. This also ensures that you have the latest version of them for the update which is a prerequisite for updating them.