Skip to content

Commit 05011f8

Browse files
newtorkJonas-Isr
andauthored
fix: (OData v4) Use correct ETag / If-Match header for entity bound actions (#897)
Co-authored-by: Jonas Israel <[email protected]>
1 parent 3939e82 commit 05011f8

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

datamodel/odata-v4/odata-v4-api-sample/src/test/java/com/sap/cloud/sdk/datamodel/odatav4/sample/SdkGroceryStoreServiceTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.time.OffsetDateTime;
88
import java.time.ZoneOffset;
99
import java.util.Arrays;
10-
import java.util.Collections;
1110
import java.util.List;
1211

1312
import org.junit.jupiter.api.BeforeEach;
@@ -116,15 +115,17 @@ void testFilterPurchaseHistory()
116115
.build();
117116

118117
final Customer customer = Customer.builder().id(1337).build();
118+
customer.setVersionIdentifier("123");
119+
119120
final ActionResponseCollection<PurchaseHistoryItem> historyItems =
120121
service
121122
.forEntity(customer)
122123
.applyAction(
123124
Customer
124125
.filterPurchaseHistory(
125-
Collections.singleton(Receipt.builder().customerId(1337).id(4242).build()),
126-
Arrays.asList("milk", "eggs"),
127-
Arrays.asList(ProductCategory.DAIRY, ProductCategory.MEAT),
126+
List.of(Receipt.builder().customerId(1337).id(4242).build()),
127+
List.of("milk", "eggs"),
128+
List.of(ProductCategory.DAIRY, ProductCategory.MEAT),
128129
dateRange))
129130
.execute(destination);
130131

datamodel/odata-v4/odata-v4-api-sample/src/test/resources/SdkGroceryStoreServiceTest/mappings/SdkGroceryStoreServiceTest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@
208208
"Content-Type": {
209209
"equalTo": "application/json"
210210
},
211+
"If-Match": {
212+
"equalTo": "123"
213+
},
211214
"Accept": {
212215
"equalTo": "application/json"
213216
},

datamodel/odata-v4/odata-v4-core/src/main/java/com/sap/cloud/sdk/datamodel/odatav4/core/ServiceWithNavigableEntitiesImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import javax.annotation.Nonnull;
44

5+
import org.apache.http.HttpHeaders;
6+
57
import com.sap.cloud.sdk.datamodel.odata.client.expression.ODataResourcePath;
68

79
import io.vavr.control.Option;
@@ -124,10 +126,10 @@ public <ResultT> SingleValueActionRequestBuilder<ResultT> applyAction(
124126
action.getReturnType());
125127
maybeEntity
126128
.filter(e -> e.getVersionIdentifier().isDefined())
127-
.map(VdmEntity<EntityT>::getVersionIdentifier)
129+
.map(VdmEntity::getVersionIdentifier)
128130
.filter(Option::isDefined)
129131
.map(Option::get)
130-
.forEach(eTag -> requestBuilder.withHeader("ETag", eTag));
132+
.forEach(eTag -> requestBuilder.withHeader(HttpHeaders.IF_MATCH, eTag));
131133
return requestBuilder;
132134
}
133135

@@ -145,10 +147,10 @@ public <ResultT> CollectionValueActionRequestBuilder<ResultT> applyAction(
145147
action.getReturnType());
146148
maybeEntity
147149
.filter(e -> e.getVersionIdentifier().isDefined())
148-
.map(VdmEntity<EntityT>::getVersionIdentifier)
150+
.map(VdmEntity::getVersionIdentifier)
149151
.filter(Option::isDefined)
150152
.map(Option::get)
151-
.forEach(eTag -> requestBuilder.withHeader("ETag", eTag));
153+
.forEach(eTag -> requestBuilder.withHeader(HttpHeaders.IF_MATCH, eTag));
152154
return requestBuilder;
153155
}
154156
}

datamodel/odata-v4/odata-v4-core/src/test/java/com/sap/cloud/sdk/datamodel/odatav4/core/BoundActionTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import java.util.Collections;
66

7+
import org.apache.http.HttpHeaders;
78
import org.junit.jupiter.api.Test;
89

910
import com.sap.cloud.sdk.datamodel.odatav4.referenceservice.namespaces.trippin.Location;
@@ -25,7 +26,8 @@ void testActionOnEntityWithEtag()
2526

2627
assertThat(action.toRequest().getRelativeUri()).hasToString(targetUrl);
2728
assertThat(action.toRequest().getActionParameters()).hasToString("{}");
28-
assertThat(action.toRequest().getHeaders()).containsEntry("ETag", Collections.singletonList("some-etag"));
29+
assertThat(action.toRequest().getHeaders())
30+
.containsEntry(HttpHeaders.IF_MATCH, Collections.singletonList("some-etag"));
2931
}
3032

3133
@Test
@@ -38,7 +40,7 @@ void testActionOnEntityNoEtag()
3840

3941
assertThat(action.toRequest().getRelativeUri()).hasToString(targetUrl);
4042
assertThat(action.toRequest().getActionParameters()).hasToString("{}");
41-
assertThat(action.toRequest().getHeaders()).doesNotContainEntry("ETag", Collections.singletonList("some-etag"));
43+
assertThat(action.toRequest().getHeaders()).doesNotContainKey(HttpHeaders.IF_MATCH);
4244
}
4345

4446
@Test

release_notes.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
### 🐛 Fixed Issues
2424

2525
- [OpenAPI] Fix code generator for transitive dependency version inconsistencies for Jackson.
26-
- [ODatav4] Fixed an issue when generating clients.
26+
- [ODatav4] Fix incorrect HTTP header name when sending entity version identifier in bound-action requests.
27+
- [ODatav4] Fix an issue when generating clients.
2728
- Property names: `value`, `item` and `properties` are now allowed.
2829

0 commit comments

Comments
 (0)