Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PATCH Member of a Collection Sends all Fields Instead of Changed Fields #883

Open
SpaceCondor opened this issue Jun 28, 2022 · 4 comments
Open
Labels
enhancement New feature or request Java Related to documentation on the SAP Cloud SDK for Java

Comments

@SpaceCondor
Copy link

Issue Description

When modifying a member of a collection property of an object and then issuing a PATCH request, the entire collection and all properties are sent as opposed to just the member and properties that have been updated.

A real world scenario would be updating the sales price of the second line of an order.

Example Code:

// build OData Request
var getDocumentRequest = service.withServicePath("example.com").getOrdersByKey(12345);
var getOrderResponse = getDocumentRequest.execute(....);
var order = getOrderResponse.get();

for (var orderLine : order.getLines()) {

    if(orderLine.getLineNum() == 2) {
          orderLine.setPrice(100);
    }

}

// build OData Request
var updateOrderRequest = service.withServicePath("example.com").updateOrders(order);

In the above scenario I'd expect to see a request like:

PATCH https://example.com/Orders(12345)

{
  "OrderLines": [
    {
      "LineNum": 2,
      "Price": 100
    }
  ]
}

But instead I am getting all order lines and all fields of all order lines.

I understand that I can exclude particular fields from updates and also force include fields, but I don't think I can specify the above behavior?

@SpaceCondor SpaceCondor added the Java Related to documentation on the SAP Cloud SDK for Java label Jun 28, 2022
@Johannes-Schneider
Copy link
Contributor

Hi @SpaceCondor,

thanks for reaching our to us.
The observed behavior is indeed a known shortcoming of the Cloud SDK.

I will reach out to our PO (@newtork) to discuss whether we can find time to implement this feature.
Would you mind elaborating a bit about the urgency from your side?
Is this issue blocking your development or is it more like an inconvenience?

Thanks and best regards,
Johannes

@Johannes-Schneider Johannes-Schneider added the enhancement New feature or request label Jun 29, 2022
@SpaceCondor
Copy link
Author

Hey @Johannes-Schneider

If needed I can construct the request directly as opposed to utilizing the cloud SDK so it is more of an inconvenience.

Within SAP B1, the Service Layer will often produce errors when doing PATCH requests and sending entire objects.

@newtork
Copy link
Contributor

newtork commented Jun 29, 2022

Hi @SpaceCondor,

Currently we are in preparation for the upcoming next major release. This will likely keep us busy within the next weeks.
As long as you have the option to use a temporary workaround, I would like to kindly ask for patience until Q4 2022.

Please let me know in case this request is much more urgent and requires higher priority.

The following request could be used as workaround while leveraging our Generic OData Client:

final String jsonPayload = "{"
        + "  \"OrderLines\": ["
        + "    {"
        + "      \"LineNum\": 2,"
        + "      \"Price\": 100"
        + "    }"
        + "  ]"
        + "}";

final ODataEntityKey entityKey = ODataEntityKey.of(Collections.singletonMap("OrderId", 12345), ODataProtocol.V2);

final ODataRequestUpdate request = new ODataRequestUpdate(
    "/service/path/", // service path
    "Orders", // entity set name
    entityKey,
    jsonPayload,
    UpdateStrategy.MODIFY_WITH_PATCH,
    null, // no version identifier
    ODataProtocol.V2);

final HttpDestination httpDestination = DestinationAccessor.getDestination("MyDestination").asHttp();
final HttpClient httpClient = HttpClientAccessor.getHttpClient(httpDestination);
request.execute(httpClient);

Best regards
Alexander

@SpaceCondor
Copy link
Author

@newtork Thank you for the feedback and I completely understand regarding the launch of version 4 of the SDK being a priority.

I will use the provided workaround for now and if it becomes more urgent I will let you know. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Java Related to documentation on the SAP Cloud SDK for Java
Projects
None yet
Development

No branches or pull requests

3 participants