cancel
Showing results for 
Search instead for 
Did you mean: 

OData batch with cloud sdk for java

0 Kudos

Hi,

We're looking into creating a batch update to our on-prem SAP servive from the cloud. We're using the Odata gateway, cloud connector etc. Our java app is deployed on SAP CloudFoundry and reading data with the cloud sdk for java works fine.

Now we need to start updating data and want to do that with a odata batch update. I've been looking into the docs and blog posts, but I cannot find any good java code examples on this.

Can someone provide a good example on how to use the cloud SDK for java on batch updates?

Thanks,

Danny

artemkovalov
Employee
Employee
0 Kudos

Hi dannykruitbosch,

It's true that for SDK v3 we haven't documented it all around yet. Do you use OData v2 or OData v4? I'll ask the team to give you some examples then.

Best,

Artem

View Entire Topic
former_member186608
Active Participant

We are aware that a documentation or a tutorial is missing and have that on the radar.

In the meantime, hereafter is a brief outline of invoking batch requests with the OData VDM. I'll use the Business Partner OData API to demonstrate the usage.

final BusinessPartnerService service = new DefaultBusinessPartnerService();
final HttpDestination destination = obtainHttpDestination();
final BusinessPartnerAddress address1 = createBusinessPartnerAddress();
final BusinessPartnerAddress address2 = createBusinessPartnerAddress();

final BatchResponse result =
    service
        .batch()
        .beginChangeSet()
        .createBusinessPartnerAddress(address1)
        .createBusinessPartnerAddress(address2)
        .endChangeSet()
        .executeRequest(destination);

final Try<BatchResponseChangeSet> changeSetTry = result.get(0);
//error handling can be made with the Try type, like Try#isSuccess

if (changeSetTry.isSucces()) {
    //now you can access the created entities
    final List<VdmEntity<?>> createdEntities = changeSet.get().getCreatedEntities();  
}

Kindly follow-up with additional replies to refine your question if my response does not help you.

0 Kudos

Thanks,

I'll try this out later today and get back on the results.

One thing I'm wondering about, is that this is based on the generated typed client (using the odata-generator-cli).

Is there a more generalized ("low level") way of using the SDK without having the dependency on a generated client

Something like:

final Dienst dienst0 = Dienst.builder().build(); //own object, not generated from odata EDMX

final ServiceProps props = getServiceProps();

final ODataUpdateRequest updateRequest = ODataUpdateRequestBuilder
        .withEntity(props.getName(), props.getEntitySet(), )
        .withBodyAs(dienst0)
        .build();


ChangeSetBuilder builder = ChangeSetBuilder.getInstance();

final ChangeSet set = builder.addUpdateRequest(updateRequest).build();

final BatchRequest batchReq = BatchRequestBuilder.withService("odata/ZCU_PE_ORDER_SRV")
        .addChangeSet(set)
        .build();

BatchResult result = batchReq
        .execute(props.getDestination());
former_member186608
Active Participant
0 Kudos

You could check out the class ODataRequestBatch.

Be aware that you would need to update to the Cloud SDK latest version. Furthermore, kindly note that the Cloud SDK recommends to use the type-safe generated client library in any case.

NagaPrakashT
Contributor
0 Kudos

Hi marco.dahms,

To get the created entities below code is to be used, but what is the type of "changeSet", i dont see a way to get the instance of it

finalList<VdmEntity<?>> createdEntities = changeSet.get().getCreatedEntities();
former_member186608
Active Participant
0 Kudos

Here is the code snippet you might find useful:

final Try<BatchResponseChangeSet> changeSetTry = result.get(0);
//error handling can be made with the Try type, like Try#isSuccess

if (changeSetTry.isSucces()) {
    //now you can access the created entities
    final List<VdmEntity<?>> createdEntities = changeSetTry.get().getCreatedEntities();  
NagaPrakashT
Contributor
0 Kudos

Hi marco.dahms

I got below message, when trying to read the batch response.

Payload batch item delimiter for changeset \"[}\" could not be extracted from OData batch response except." }

former_member186608
Active Participant
0 Kudos

Kindly open a new question on Stackoverflow: https://stackoverflow.com/questions/tagged/sap-cloud-sdk

Please provide all relevant details such as your full code snippet, the SAP Cloud SDK version you use (please use always the latest version) and share the full stack trace with us.

The provided error message is insufficient to provide you a solution.