Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Version 1.7.0

### Added
- ChangeLog support
- MoveAttachments support
- Upload Status support in Attachments
- Internationalization support for error messages

### Fixed
- Prevent unwanted update calls on edit without changes
- Heap Out of Memory error in Large file upload

## Version 1.6.2

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ public void processBefore(CdsCreateEventContext context, List<CdsData> data) thr
logger.info("Attachment compositions present in CDS Model : " + attachmentCompositionDetails);
updateName(context, data, attachmentCompositionDetails);
// Remove uploadStatus from attachment data to prevent validation errors

cleanupReadonlyContextsForAttachments(context, entityData, attachmentCompositionDetails);
}
SDMUtils.cleanupReadonlyContexts(data);
}

@After
Expand Down Expand Up @@ -536,6 +535,45 @@ private void appendWithSpace(StringBuilder sb) {
}
}

private void cleanupReadonlyContextsForAttachments(
CdsCreateEventContext context,
Map<String, Object> entityData,
Map<String, Map<String, String>> attachmentCompositionDetails) {
String targetEntity = context.getTarget().getQualifiedName();

for (Map.Entry<String, Map<String, String>> entry : attachmentCompositionDetails.entrySet()) {
String attachmentCompositionName = entry.getValue().get("name");

logger.info(
"Cleaning up SDM_READONLY_CONTEXT for composition: {}", attachmentCompositionName);

// Fetch attachments for this specific composition
List<Map<String, Object>> attachments =
AttachmentsHandlerUtils.fetchAttachments(
targetEntity, entityData, attachmentCompositionName);

if (attachments != null && !attachments.isEmpty()) {
logger.info(
"Found {} attachments in composition: {}",
attachments.size(),
attachmentCompositionName);

for (int i = 0; i < attachments.size(); i++) {
Map<String, Object> attachment = attachments.get(i);
if (attachment.containsKey(SDM_READONLY_CONTEXT)) {
logger.info(
" Removing SDM_READONLY_CONTEXT from attachment [{}] in {}",
i,
attachmentCompositionName);
attachment.remove(SDM_READONLY_CONTEXT);
}
}
} else {
logger.info("No attachments found for composition: {}", attachmentCompositionName);
}
}
}

private static class SDMAttachmentData {
final String fileNameInSDM;
final String descriptionInSDM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ public void processBefore(CdsUpdateEventContext context, List<CdsData> data) thr
logger.info("Attachment compositions present in CDS Model : " + attachmentCompositionDetails);

updateName(context, data, attachmentCompositionDetails);

// Remove uploadStatus from attachment data to prevent validation errors
cleanupReadonlyContextsForAttachments(context, entityData, attachmentCompositionDetails);
}
SDMUtils.cleanupReadonlyContexts(data);
}

public void updateName(
Expand Down Expand Up @@ -582,4 +584,43 @@ private void handleWarnings(
+ contextInfo);
}
}

private void cleanupReadonlyContextsForAttachments(
CdsUpdateEventContext context,
Map<String, Object> entityData,
Map<String, Map<String, String>> attachmentCompositionDetails) {
String targetEntity = context.getTarget().getQualifiedName();

for (Map.Entry<String, Map<String, String>> entry : attachmentCompositionDetails.entrySet()) {
String attachmentCompositionName = entry.getValue().get("name");

logger.info(
"Cleaning up SDM_READONLY_CONTEXT for composition: {}", attachmentCompositionName);

// Fetch attachments for this specific composition
List<Map<String, Object>> attachments =
AttachmentsHandlerUtils.fetchAttachments(
targetEntity, entityData, attachmentCompositionName);

if (attachments != null && !attachments.isEmpty()) {
logger.info(
"Found {} attachments in composition: {}",
attachments.size(),
attachmentCompositionName);

for (int i = 0; i < attachments.size(); i++) {
Map<String, Object> attachment = attachments.get(i);
if (attachment.containsKey(SDM_READONLY_CONTEXT)) {
logger.info(
" Removing SDM_READONLY_CONTEXT from attachment [{}] in {}",
i,
attachmentCompositionName);
attachment.remove(SDM_READONLY_CONTEXT);
}
}
} else {
logger.info("No attachments found for composition: {}", attachmentCompositionName);
}
}
}
}
18 changes: 0 additions & 18 deletions sdm/src/main/java/com/sap/cds/sdm/utilities/SDMUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,6 @@ public static Set<String> FileNameContainsWhitespace(
return filenamesWithWhitespace;
}

public static void cleanupReadonlyContexts(List<CdsData> data) {
for (CdsData entityData : data) {
// Remove SDM_READONLY_CONTEXT from all attachments in the data
entityData.forEach(
(key, value) -> {
if (value instanceof List) {
List<?> list = (List<?>) value;
for (Object item : list) {
if (item instanceof Map) {
Map<String, Object> attachment = (Map<String, Object>) item;
attachment.remove(SDM_READONLY_CONTEXT);
}
}
}
});
}
}

public static Set<String> FileNameDuplicateInDrafts(
List<CdsData> data, String composition, String targetEntity, String upIdKey) {
Set<String> uniqueFilenames = new HashSet<>();
Expand Down
Loading