Skip to content

Commit ff32dfa

Browse files
authored
Merge pull request #409 from cap-java/nestedEntityROCFix
Attachment upload fails for Pages/Chapters in Books composition with Invalid CQN error
2 parents 615ca65 + 8aac6d1 commit ff32dfa

4 files changed

Lines changed: 94 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55
The format is based on [Keep a Changelog](http://keepachangelog.com/).
66

7+
## Version 1.7.0
8+
9+
### Added
10+
- ChangeLog support
11+
- MoveAttachments support
12+
- Upload Status support in Attachments
13+
- Internationalization support for error messages
14+
15+
### Fixed
16+
- Prevent unwanted update calls on edit without changes
17+
- Heap Out of Memory error in Large file upload
18+
719
## Version 1.6.2
820

921
### Fixed

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

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ public void processBefore(CdsCreateEventContext context, List<CdsData> data) thr
7272
logger.info("Attachment compositions present in CDS Model : " + attachmentCompositionDetails);
7373
updateName(context, data, attachmentCompositionDetails);
7474
// Remove uploadStatus from attachment data to prevent validation errors
75-
75+
cleanupReadonlyContextsForAttachments(context, entityData, attachmentCompositionDetails);
7676
}
77-
SDMUtils.cleanupReadonlyContexts(data);
7877
}
7978

8079
@After
@@ -536,6 +535,45 @@ private void appendWithSpace(StringBuilder sb) {
536535
}
537536
}
538537

538+
private void cleanupReadonlyContextsForAttachments(
539+
CdsCreateEventContext context,
540+
Map<String, Object> entityData,
541+
Map<String, Map<String, String>> attachmentCompositionDetails) {
542+
String targetEntity = context.getTarget().getQualifiedName();
543+
544+
for (Map.Entry<String, Map<String, String>> entry : attachmentCompositionDetails.entrySet()) {
545+
String attachmentCompositionName = entry.getValue().get("name");
546+
547+
logger.info(
548+
"Cleaning up SDM_READONLY_CONTEXT for composition: {}", attachmentCompositionName);
549+
550+
// Fetch attachments for this specific composition
551+
List<Map<String, Object>> attachments =
552+
AttachmentsHandlerUtils.fetchAttachments(
553+
targetEntity, entityData, attachmentCompositionName);
554+
555+
if (attachments != null && !attachments.isEmpty()) {
556+
logger.info(
557+
"Found {} attachments in composition: {}",
558+
attachments.size(),
559+
attachmentCompositionName);
560+
561+
for (int i = 0; i < attachments.size(); i++) {
562+
Map<String, Object> attachment = attachments.get(i);
563+
if (attachment.containsKey(SDM_READONLY_CONTEXT)) {
564+
logger.info(
565+
" Removing SDM_READONLY_CONTEXT from attachment [{}] in {}",
566+
i,
567+
attachmentCompositionName);
568+
attachment.remove(SDM_READONLY_CONTEXT);
569+
}
570+
}
571+
} else {
572+
logger.info("No attachments found for composition: {}", attachmentCompositionName);
573+
}
574+
}
575+
}
576+
539577
private static class SDMAttachmentData {
540578
final String fileNameInSDM;
541579
final String descriptionInSDM;

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ public void processBefore(CdsUpdateEventContext context, List<CdsData> data) thr
122122
logger.info("Attachment compositions present in CDS Model : " + attachmentCompositionDetails);
123123

124124
updateName(context, data, attachmentCompositionDetails);
125+
126+
// Remove uploadStatus from attachment data to prevent validation errors
127+
cleanupReadonlyContextsForAttachments(context, entityData, attachmentCompositionDetails);
125128
}
126-
SDMUtils.cleanupReadonlyContexts(data);
127129
}
128130

129131
public void updateName(
@@ -582,4 +584,43 @@ private void handleWarnings(
582584
+ contextInfo);
583585
}
584586
}
587+
588+
private void cleanupReadonlyContextsForAttachments(
589+
CdsUpdateEventContext context,
590+
Map<String, Object> entityData,
591+
Map<String, Map<String, String>> attachmentCompositionDetails) {
592+
String targetEntity = context.getTarget().getQualifiedName();
593+
594+
for (Map.Entry<String, Map<String, String>> entry : attachmentCompositionDetails.entrySet()) {
595+
String attachmentCompositionName = entry.getValue().get("name");
596+
597+
logger.info(
598+
"Cleaning up SDM_READONLY_CONTEXT for composition: {}", attachmentCompositionName);
599+
600+
// Fetch attachments for this specific composition
601+
List<Map<String, Object>> attachments =
602+
AttachmentsHandlerUtils.fetchAttachments(
603+
targetEntity, entityData, attachmentCompositionName);
604+
605+
if (attachments != null && !attachments.isEmpty()) {
606+
logger.info(
607+
"Found {} attachments in composition: {}",
608+
attachments.size(),
609+
attachmentCompositionName);
610+
611+
for (int i = 0; i < attachments.size(); i++) {
612+
Map<String, Object> attachment = attachments.get(i);
613+
if (attachment.containsKey(SDM_READONLY_CONTEXT)) {
614+
logger.info(
615+
" Removing SDM_READONLY_CONTEXT from attachment [{}] in {}",
616+
i,
617+
attachmentCompositionName);
618+
attachment.remove(SDM_READONLY_CONTEXT);
619+
}
620+
}
621+
} else {
622+
logger.info("No attachments found for composition: {}", attachmentCompositionName);
623+
}
624+
}
625+
}
585626
}

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,6 @@ public static Set<String> FileNameContainsWhitespace(
6767
return filenamesWithWhitespace;
6868
}
6969

70-
public static void cleanupReadonlyContexts(List<CdsData> data) {
71-
for (CdsData entityData : data) {
72-
// Remove SDM_READONLY_CONTEXT from all attachments in the data
73-
entityData.forEach(
74-
(key, value) -> {
75-
if (value instanceof List) {
76-
List<?> list = (List<?>) value;
77-
for (Object item : list) {
78-
if (item instanceof Map) {
79-
Map<String, Object> attachment = (Map<String, Object>) item;
80-
attachment.remove(SDM_READONLY_CONTEXT);
81-
}
82-
}
83-
}
84-
});
85-
}
86-
}
87-
8870
public static Set<String> FileNameDuplicateInDrafts(
8971
List<CdsData> data, String composition, String targetEntity, String upIdKey) {
9072
Set<String> uniqueFilenames = new HashSet<>();

0 commit comments

Comments
 (0)