Skip to content

Commit 5f264d3

Browse files
fix: [ODatav4] Support for property name properties
1 parent a1120bf commit 5f264d3

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

datamodel/odata-v4/odata-v4-api-sample/src/main/java/com/sap/cloud/sdk/datamodel/odatav4/sample/namespaces/sdkgrocerystore/Receipt.java

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,26 @@ public class Receipt extends VdmEntity<Receipt> implements VdmEntitySet
117117
Receipt.class,
118118
"ProductCounts",
119119
ProductCount.class);
120+
/**
121+
* Constraints: Nullable
122+
* <p>
123+
* Original property name from the Odata EDM: <b>properties</b>
124+
* </p>
125+
*
126+
* @return The properties contained in this {@link VdmEntity}.
127+
*/
128+
@Nullable
129+
@ElementName( "properties" )
130+
private java.util.Collection<ProductCount> properties;
131+
/**
132+
* Use with available request builders to apply the <b>properties</b> complex property to query operations.
133+
*
134+
*/
135+
public final static com.sap.cloud.sdk.datamodel.odatav4.core.ComplexProperty.Collection<Receipt, ProductCount> PROPERTIES =
136+
new com.sap.cloud.sdk.datamodel.odatav4.core.ComplexProperty.Collection<Receipt, ProductCount>(
137+
Receipt.class,
138+
"properties",
139+
ProductCount.class);
120140
/**
121141
* Navigation property <b>Customer</b> for <b>Receipt</b> to single <b>Customer</b>.
122142
*
@@ -203,6 +223,21 @@ public void setProductCounts( @Nullable final java.util.Collection<ProductCount>
203223
this.productCounts = productCounts;
204224
}
205225

226+
/**
227+
* Constraints: Nullable
228+
* <p>
229+
* Original property name from the Odata EDM: <b>properties</b>
230+
* </p>
231+
*
232+
* @param properties
233+
* The properties to set.
234+
*/
235+
public void setProperties( @Nullable final java.util.Collection<ProductCount> properties )
236+
{
237+
rememberChangedField("properties", this.properties);
238+
this.properties = properties;
239+
}
240+
206241
@Override
207242
protected String getEntityCollection()
208243
{
@@ -227,6 +262,7 @@ protected Map<String, Object> toMapOfFields()
227262
cloudSdkValues.put("CustomerId", getCustomerId());
228263
cloudSdkValues.put("TotalAmount", getTotalAmount());
229264
cloudSdkValues.put("ProductCounts", getProductCounts());
265+
cloudSdkValues.put("properties", getProperties());
230266
return cloudSdkValues;
231267
}
232268

@@ -261,8 +297,8 @@ protected void fromMap( final Map<String, Object> inputValues )
261297
final Object value = cloudSdkValues.remove("ProductCounts");
262298
if( value instanceof Iterable ) {
263299
final LinkedList<ProductCount> productCounts = new LinkedList<ProductCount>();
264-
for( Object properties : ((Iterable<?>) value) ) {
265-
if( properties instanceof Map ) {
300+
for( Object cloudSdkProperties : ((Iterable<?>) value) ) {
301+
if( cloudSdkProperties instanceof Map ) {
266302
final ProductCount item = new ProductCount();
267303
@SuppressWarnings( "unchecked" )
268304
final Map<String, Object> inputMap = ((Map<String, Object>) value);
@@ -276,6 +312,25 @@ protected void fromMap( final Map<String, Object> inputValues )
276312
setProductCounts(null);
277313
}
278314
}
315+
if( cloudSdkValues.containsKey("properties") ) {
316+
final Object value = cloudSdkValues.remove("properties");
317+
if( value instanceof Iterable ) {
318+
final LinkedList<ProductCount> properties = new LinkedList<ProductCount>();
319+
for( Object cloudSdkProperties : ((Iterable<?>) value) ) {
320+
if( cloudSdkProperties instanceof Map ) {
321+
final ProductCount item = new ProductCount();
322+
@SuppressWarnings( "unchecked" )
323+
final Map<String, Object> inputMap = ((Map<String, Object>) value);
324+
item.fromMap(inputMap);
325+
properties.add(item);
326+
}
327+
}
328+
setProperties(properties);
329+
}
330+
if( (value == null) && (getProperties() != null) ) {
331+
setProperties(null);
332+
}
333+
}
279334
}
280335
// navigation properties
281336
{

datamodel/odata-v4/odata-v4-api-sample/src/main/resources/SDK_Grocery_Store.edmx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Property Name="CustomerId" Type="Edm.Int32" Nullable="false"/>
6161
<Property Name="TotalAmount" Type="Edm.Decimal" Nullable="false"/>
6262
<Property Name="ProductCounts" Type="Collection(GroceryStore.ProductCount)" Nullable="false"/>
63+
<Property Name="properties" Type="Collection(GroceryStore.ProductCount)"/>
6364
<NavigationProperty Name="Customer" Type="GroceryStore.Customer" Partner="Receipts"/>
6465
</EntityType>
6566
<EntityType Name="Address">

datamodel/odata-v4/odata-v4-generator/src/main/java/com/sap/cloud/sdk/datamodel/odatav4/generator/NamespaceClassGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ else if( isPrimitive ) {
721721
final JBlock ifValueIsList = ifFoundBody._if(value._instanceof(typeIterable))._then();
722722
final JVar listInst = ifValueIsList.decl(JMod.FINAL, listType, javaFieldName, JExpr._new(listType));
723723
final JExpression iter = JExpr.cast(typeIterable.narrow(codeModel.wildcard()), value);
724-
final JForEach forEach = ifValueIsList.forEach(typeObject, "properties", iter);
724+
final JForEach forEach = ifValueIsList.forEach(typeObject, "cloudSdkProperties", iter);
725725
final JBlock isMap = forEach.body()._if(forEach.var()._instanceof(codeModel.ref(Map.class)))._then();
726726
final JVar item = isMap.decl(JMod.FINAL, javaType, "item", JExpr._new(javaType));
727727
isMap.directStatement("@SuppressWarnings(\"unchecked\")");

0 commit comments

Comments
 (0)