2

I have question regarding SAP Cloud SDK. First of all, I need to say that this is one really good library for consuming OData services and I just wanted to pointed that you are doing good job! Tutorials on generating VDMs and other stuff are simply awesome!

Onto the question. How can I call Bound Functions or Actions from client? I have searched/watched videos and only thing I found was that on May 5, 2020 in video SAP Cloud SDK: Update Call for SAP Community you said that Bound functions are not yet supported. What is the status of that and how could I implement client using bound functions?

Hope you will be able to help me. Matija

P.S. Get All, Get By Key, Post, Patch, Delete, Unbound Functions and Actions work FLAWLESS

2 Answers2

2

As of version 3.46.0 the SAP Cloud SDK for Java has built in support for bound functions and actions.

This allows for building requests directly from the VDM. The entity classes will expose all functions and actions bound to them on the API. Check the documentation for how to use the API.

MatKuhr
  • 505
  • 4
  • 13
  • Thank you very much for providing this information. Big shotout to your organisation - I really appreciate on your quick response - second day of releasing, good job! But now I have another one. With new update, I am getting not implemented methods after generating code with metadata. This is what is not implemented: - com.sap.cloud.sdk.datamodel.odatav4.core.VdmObject.getOdataType() Since I am not Java developer, could you please help me out what would be causing this problem? Thank you in advance! – Matija Lazar Jun 16 '21 at 15:02
  • Hi Matija, thanks for the feedback! Please open a new question for the issue and make sure to provide the service metadata if possible so that we can try to reproduce the problem. Also, please make sure Lombok is installed and working. Thx! – MatKuhr Jun 21 '21 at 07:29
1

Thanks for the kind words about the SDK! That is a great encouragement for the team.

We're actively working on supporting OData v4 bound functions/actions at the moment. The type-safe support for these operations should be released rather soon. Preliminary you can expect it between the end of March and the beginning of April, no guarantees though. We'll communicate it via our release notes.

As a workaround, you can leverage our generic OData client, which already provides support for the bound function and action calls.

Here is a generic code snippet to make such a call:

// this code will build the following URL:
// "/service/Entity(key1='foo%2Fbar',key2=123)/Model.Function(param1='foo%2Fbar',param2=123)"

ODataEntityKey key = new ODataEntityKey(ODataProtocol.V4)
    .addKeyProperty("key1", "foo/bar")
    .addKeyProperty("key2", 123);

ODataFunctionParameters  params = new ODataFunctionParameters(ODataProtocol.V4)
    .addKeyProperty("param1", "foo/bar")
    .addKeyProperty("param2", 123);

ODataResourcePath functionPath =
    new ODataResourcePath()
        .addSegment("Entity", key)
        .addSegment("Model.Function", params);

ODataRequestFunction request =
    new ODataRequestFunction("/service", functionPath, null, ODataProtocol.V4);

We hope it helps! Let us know if we can help with anything else.

Artyom Kovalyov
  • 374
  • 3
  • 11
  • 1
    Thank you for provided solution, it really helped and it worked. I will just add few things for anyone who is searching how to implement above generic code. HttpDestination destination = DefaultHttpDestination.builder(DefaultMetadataService.DEFAULT_SERVICE_PATH).build(); HttpClient client = HttpClientAccessor.getHttpClient(destination); ODataRequestFunction request = new ODataRequestFunction("/service", functionPath, null, OdataProtocol.V4).execute(client); And then use requst.as({modelName}.class) to get access to properties. – Matija Lazar Feb 23 '21 at 09:40
  • 1
    Thanks for the valuable addition, @MatijaLazar. The response mapping makes sense! – Artyom Kovalyov Feb 25 '21 at 09:41