Skip to content

Commit 67fe066

Browse files
committed
PR Review based modification
- remove unwanted disabled tag on test - add best and since tag on java doc to all public api - code reduction on createPatchObjectRecursiveDelta - generalize containsNestedChangedFields with type validation - comment correction
1 parent 42c8347 commit 67fe066

File tree

5 files changed

+43
-37
lines changed

5 files changed

+43
-37
lines changed

datamodel/odata-client/src/main/java/com/sap/cloud/sdk/datamodel/odata/client/request/UpdateStrategy.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*/
44
package com.sap.cloud.sdk.datamodel.odata.client.request;
55

6+
import com.google.common.annotations.Beta;
7+
68
/**
79
* The strategy to use when updating existing entities.
810
*/
@@ -21,18 +23,24 @@ public enum UpdateStrategy
2123

2224
/**
2325
* Request to update the entity is sent with the HTTP method PATCH and its payload contains the changed fields
24-
* including the changes in nested fields.
26+
* including the changes in nested non-entity type fields.
2527
*
2628
* The request payload contains only the changed fields. Navigation properties are not supported.
29+
*
30+
* @since 5.16.0
2731
*/
32+
@Beta
2833
MODIFY_WITH_PATCH_RECURSIVE_DELTA,
2934

3035
/**
3136
* Request to update the entity is sent with the HTTP method PATCH and its payload contains the changed fields
32-
* including the changes in nested fields.
37+
* including the changes in nested non-entity type fields.
3338
*
3439
* The request payload contains the full value of complex fields for changes in any nested field. Navigation
3540
* properties are not supported.
41+
*
42+
* @since 5.16.0
3643
*/
44+
@Beta
3745
MODIFY_WITH_PATCH_RECURSIVE_FULL;
3846
}

datamodel/odata/odata-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/odata/helper/FluentHelperUpdateToRequestTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.apache.http.HttpVersion;
2121
import org.apache.http.client.HttpClient;
2222
import org.apache.http.message.BasicHttpResponse;
23-
import org.junit.jupiter.api.Disabled;
2423
import org.junit.jupiter.api.Test;
2524

2625
import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination;
@@ -254,7 +253,6 @@ void testUpdatePatchComplexPropertyFull()
254253
}
255254

256255
@Test
257-
@Disabled( " Test is failing as the getChangedFields() method on Complex Type is not working as expected." )
258256
void testIgnoreVersionIdentifier()
259257
{
260258
product.setVersionIdentifier(versionIdentifier);

datamodel/odata/odata-core/src/main/java/com/sap/cloud/sdk/datamodel/odata/helper/FluentHelperUpdate.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import org.apache.http.client.HttpClient;
1616

17+
import com.google.common.annotations.Beta;
1718
import com.sap.cloud.sdk.cloudplatform.connectivity.Destination;
1819
import com.sap.cloud.sdk.cloudplatform.connectivity.HttpClientAccessor;
1920
import com.sap.cloud.sdk.datamodel.odata.client.ODataProtocol;
@@ -271,7 +272,9 @@ public final FluentHelperT modifyingEntity()
271272
* @return The same fluent helper which will modify the entity in the remote system.
272273
* @throws IllegalArgumentException
273274
* If an unknown ModifyPatchStrategy is provided.
275+
* @since 5.16.0
274276
*/
277+
@Beta
275278
@Nonnull
276279
public final FluentHelperT modifyingEntity( @Nonnull final ModifyPatchStrategy strategy )
277280
{

datamodel/odata/odata-core/src/main/java/com/sap/cloud/sdk/datamodel/odata/helper/ModifyPatchStrategy.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package com.sap.cloud.sdk.datamodel.odata.helper;
22

3+
import com.google.common.annotations.Beta;
4+
35
/**
46
* Strategy to determine how a patch operation should be applied to an entity.
7+
*
8+
* @since 5.16.0
59
*/
10+
@Beta
611
public enum ModifyPatchStrategy
712
{
813
/** Only the top level fields can be patched */

datamodel/odata/odata-core/src/main/java/com/sap/cloud/sdk/datamodel/odata/helper/ODataEntitySerializer.java

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.Collection;
1010
import java.util.HashSet;
1111
import java.util.List;
12-
import java.util.Map;
1312
import java.util.Set;
1413
import java.util.function.BiConsumer;
1514
import java.util.function.BiPredicate;
@@ -150,8 +149,7 @@ static String serializeEntityForUpdatePatchRecursiveFull(
150149
.entrySet()
151150
.stream()
152151
.filter(entry -> !patchObject.has(entry.getKey()))
153-
.filter(entry -> entry.getValue() instanceof VdmComplex<?>)
154-
.filter(entry -> containsNestedChangedFields((VdmComplex<?>) entry.getValue()))
152+
.filter(entry -> containsNestedChangedFields(entry.getValue()))
155153
.forEach(entry -> patchObject.add(entry.getKey(), fullEntityJson.get(entry.getKey())));
156154

157155
log.debug("The following object is serialized for update : {}.", patchObject);
@@ -162,23 +160,23 @@ static String serializeEntityForUpdatePatchRecursiveFull(
162160
/**
163161
* Checks if the given complex object contains any changed fields in its nested fields.
164162
*
165-
* @param vdmComplex
163+
* @param obj
166164
* the complex object to check
167165
* @return true if the complex object contains any changed fields, false otherwise
168166
*/
169-
private static boolean containsNestedChangedFields( final VdmComplex<?> vdmComplex )
167+
private static boolean containsNestedChangedFields( final Object obj )
170168
{
171-
if( !vdmComplex.getChangedFields().isEmpty() ) {
172-
return true;
169+
if( obj instanceof VdmComplex<?> vdmComplex ) {
170+
if( !vdmComplex.getChangedFields().isEmpty() ) {
171+
return true;
172+
}
173+
for( Object complexField : vdmComplex.toMapOfFields().values() ) {
174+
if( containsNestedChangedFields(complexField) ) {
175+
return true;
176+
}
177+
}
173178
}
174-
175-
return vdmComplex
176-
.toMapOfFields()
177-
.values()
178-
.stream()
179-
.filter(complexField -> complexField instanceof VdmComplex<?>)
180-
.map(complexField -> (VdmComplex<?>) complexField)
181-
.anyMatch(ODataEntitySerializer::containsNestedChangedFields);
179+
return false;
182180
}
183181

184182
/**
@@ -237,24 +235,18 @@ static String serializeEntityForUpdatePatchRecursiveDelta(
237235
{
238236
final JsonObject patch = new JsonObject();
239237

240-
// Process all complex fields
241-
vdmObject
242-
.toMapOfFields()
243-
.entrySet()
244-
.stream()
245-
.filter(entry -> entry.getValue() instanceof VdmComplex<?>)
246-
.map(entry -> {
247-
final String fieldName = entry.getKey();
248-
final VdmComplex<?> complexField = (VdmComplex<?>) entry.getValue();
249-
// Recursively build patch for the complex field
250-
final JsonObject childJsonObject =
251-
createPatchObjectRecursiveDelta(complexField, jsonObject.getAsJsonObject(fieldName));
252-
return Map.entry(fieldName, childJsonObject);
253-
})
254-
.filter(entry -> !entry.getValue().isEmpty())
255-
.forEach(entry -> patch.add(entry.getKey(), entry.getValue()));
256-
257-
// Add changed primitive fields
238+
// Process all complex fields and recursively build patch for the complex field
239+
vdmObject.toMapOfFields().forEach(( fieldName, val ) -> {
240+
if( val instanceof VdmComplex<?> complexField ) {
241+
final var childJsonObject = jsonObject.getAsJsonObject(fieldName);
242+
final var childJsonObjectDelta = createPatchObjectRecursiveDelta(complexField, childJsonObject);
243+
if( !childJsonObjectDelta.isEmpty() ) {
244+
patch.add(fieldName, childJsonObjectDelta);
245+
}
246+
}
247+
});
248+
249+
// Add explicitly changed fields
258250
vdmObject.getChangedFields().keySet().forEach(key -> patch.add(key, jsonObject.get(key)));
259251

260252
return patch;

0 commit comments

Comments
 (0)