Skip to content

Commit 1cfd96e

Browse files
Merge branch 'develop' into changelog_its
2 parents bd3487a + 6c0c556 commit 1cfd96e

3 files changed

Lines changed: 35 additions & 39 deletions

File tree

sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMUpdateAttachmentsHandler.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -225,25 +225,27 @@ public void processAttachment(
225225
dbQuery.getAttachmentForID(attachmentEntity.get(), persistenceService, id);
226226
SDMCredentials sdmCredentials = tokenHandler.getSDMCredentials();
227227

228-
// Fetch from SDM if not in DB
229-
String descriptionInDB = null;
230-
if (fileNameInDB == null) {
228+
String fileNameInSDM = null;
229+
String descriptionInSDM = null;
230+
231+
if (fileNameInDB == null || descriptionInRequest != null) {
231232
List<String> sdmAttachmentData =
232233
AttachmentsHandlerUtils.fetchAttachmentDataFromSDM(
233234
sdmService, objectId, sdmCredentials, context.getUserInfo().isSystemUser());
234-
fileNameInDB = sdmAttachmentData.get(0);
235-
descriptionInDB = sdmAttachmentData.get(1);
235+
236+
if (sdmAttachmentData != null && sdmAttachmentData.size() >= 2) {
237+
fileNameInSDM = sdmAttachmentData.get(0);
238+
descriptionInSDM = sdmAttachmentData.get(1);
239+
}
240+
241+
if (fileNameInDB == null) {
242+
fileNameInDB = fileNameInSDM;
243+
}
236244
}
237245

238246
Map<String, String> propertiesInDB =
239247
dbQuery.getPropertiesForID(
240248
attachmentEntity.get(), persistenceService, id, secondaryTypeProperties);
241-
242-
// Extract note (description) from DB if it exists
243-
if (propertiesInDB != null && propertiesInDB.containsKey("note")) {
244-
descriptionInDB = propertiesInDB.get("note");
245-
}
246-
247249
// Prepare document and updated properties
248250

249251
Map<String, String> updatedSecondaryProperties =
@@ -260,10 +262,10 @@ public void processAttachment(
260262

261263
// Update filename and description properties
262264
AttachmentsHandlerUtils.updateFilenameProperty(
263-
fileNameInDB, filenameInRequest, null, updatedSecondaryProperties);
265+
fileNameInDB, filenameInRequest, fileNameInSDM, updatedSecondaryProperties);
264266

265267
AttachmentsHandlerUtils.updateDescriptionProperty(
266-
descriptionInDB, descriptionInRequest, null, updatedSecondaryProperties, true);
268+
null, descriptionInRequest, descriptionInSDM, updatedSecondaryProperties, true);
267269

268270
// Send update to SDM only if there are changes
269271
if (updatedSecondaryProperties.isEmpty()) {
@@ -294,7 +296,7 @@ public void processAttachment(
294296
filenameInRequest,
295297
propertiesInDB,
296298
secondaryTypeProperties,
297-
descriptionInDB,
299+
descriptionInSDM,
298300
noSDMRoles,
299301
duplicateFileNameList,
300302
filesNotFound);
@@ -310,7 +312,7 @@ public void processAttachment(
310312
filenameInRequest,
311313
propertiesInDB,
312314
secondaryTypeProperties,
313-
descriptionInDB,
315+
descriptionInSDM,
314316
filesWithUnsupportedProperties,
315317
badRequest);
316318
}

sdm/src/main/java/com/sap/cds/sdm/utilities/SDMUtils.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -350,21 +350,15 @@ public static Map<String, String> getUpdatedSecondaryProperties(
350350
for (Map.Entry<String, String> entry : secondaryTypeProperties.entrySet()) {
351351
String property = entry.getKey();
352352
String value = entry.getValue();
353-
String valueInDB = propertiesInDB.get(property);
353+
String valueInDB = propertiesInDB.get(value);
354354
Object valueInMap = propertiesMap.get(property);
355355

356-
if ((valueInMap == null && valueInDB != null)
357-
|| (valueInMap != null && !valueInMap.equals(valueInDB))) {
358-
logger.debug(
359-
"Property '{}' changed - DB value: {}, Request value: {}",
360-
property,
361-
valueInDB,
362-
valueInMap);
363-
if (valueInMap != null) {
364-
updatedSecondaryProperties.put(value, valueInMap.toString());
365-
} else {
366-
updatedSecondaryProperties.put(value, null);
367-
}
356+
// Convert valueInMap to String for proper comparison
357+
String valueInMapAsString = valueInMap != null ? valueInMap.toString() : null;
358+
359+
if ((valueInMapAsString == null && valueInDB != null)
360+
|| (valueInMapAsString != null && !valueInMapAsString.equals(valueInDB))) {
361+
updatedSecondaryProperties.put(value, valueInMapAsString);
368362
}
369363
}
370364

sdm/src/test/java/unit/com/sap/cds/sdm/utilities/SDMUtilsTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,9 +1485,9 @@ void testGetUpdatedSecondaryProperties_WithModifiedValues_ReturnsUpdated() {
14851485
secondaryTypeProperties.put("prop3", "Property 3");
14861486

14871487
Map<String, String> propertiesInDB = new HashMap<>();
1488-
propertiesInDB.put("prop1", "oldValue1");
1489-
propertiesInDB.put("prop2", "oldValue2");
1490-
propertiesInDB.put("prop3", "unchangedValue");
1488+
propertiesInDB.put("Property 1", "oldValue1");
1489+
propertiesInDB.put("Property 2", "oldValue2");
1490+
propertiesInDB.put("Property 3", "unchangedValue");
14911491

14921492
Map<String, String> result =
14931493
SDMUtils.getUpdatedSecondaryProperties(
@@ -1512,7 +1512,7 @@ void testGetUpdatedSecondaryProperties_WithNullValueInAttachment_ReturnsNullValu
15121512
secondaryTypeProperties.put("prop1", "Property 1");
15131513

15141514
Map<String, String> propertiesInDB = new HashMap<>();
1515-
propertiesInDB.put("prop1", "oldValue");
1515+
propertiesInDB.put("Property 1", "oldValue");
15161516

15171517
Map<String, String> result =
15181518
SDMUtils.getUpdatedSecondaryProperties(
@@ -1535,7 +1535,7 @@ void testGetUpdatedSecondaryProperties_WithValueInDBNull_ReturnsUpdated() {
15351535
secondaryTypeProperties.put("prop1", "Property 1");
15361536

15371537
Map<String, String> propertiesInDB = new HashMap<>();
1538-
propertiesInDB.put("prop1", null);
1538+
propertiesInDB.put("Property 1", null);
15391539

15401540
Map<String, String> result =
15411541
SDMUtils.getUpdatedSecondaryProperties(
@@ -1560,8 +1560,8 @@ void testGetUpdatedSecondaryProperties_WithNoChanges_ReturnsEmpty() {
15601560
secondaryTypeProperties.put("prop2", "Property 2");
15611561

15621562
Map<String, String> propertiesInDB = new HashMap<>();
1563-
propertiesInDB.put("prop1", "sameValue1");
1564-
propertiesInDB.put("prop2", "sameValue2");
1563+
propertiesInDB.put("Property 1", "sameValue1");
1564+
propertiesInDB.put("Property 2", "sameValue2");
15651565

15661566
Map<String, String> result =
15671567
SDMUtils.getUpdatedSecondaryProperties(
@@ -1631,10 +1631,10 @@ void testGetUpdatedSecondaryProperties_WithMultipleChanges_ReturnsAllUpdated() {
16311631
secondaryTypeProperties.put("prop4", "Property 4");
16321632

16331633
Map<String, String> propertiesInDB = new HashMap<>();
1634-
propertiesInDB.put("prop1", "old1");
1635-
propertiesInDB.put("prop2", "old2");
1636-
propertiesInDB.put("prop3", null);
1637-
propertiesInDB.put("prop4", "same4");
1634+
propertiesInDB.put("Property 1", "old1");
1635+
propertiesInDB.put("Property 2", "old2");
1636+
propertiesInDB.put("Property 3", null);
1637+
propertiesInDB.put("Property 4", "same4");
16381638

16391639
Map<String, String> result =
16401640
SDMUtils.getUpdatedSecondaryProperties(

0 commit comments

Comments
 (0)