Skip to content

Commit 6fd2137

Browse files
Adding comments to newly added public facing methods
1 parent 80e1a66 commit 6fd2137

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/helper/AttachmentsHandlerUtils.java

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import com.sap.cds.reflect.CdsModel;
66
import com.sap.cds.sdm.handler.common.SDMAssociationCascader;
77
import com.sap.cds.sdm.handler.common.SDMAttachmentsReader;
8-
import com.sap.cds.services.cds.ApplicationService;
9-
import com.sap.cds.services.handler.annotations.ServiceName;
108
import com.sap.cds.services.persistence.PersistenceService;
119
import java.util.*;
1210
import org.slf4j.Logger;
@@ -20,6 +18,20 @@ private AttachmentsHandlerUtils() {
2018
// Doesn't do anything
2119
}
2220

21+
/**
22+
* Retrieves a list of attachment entity paths for the given CDS entity.
23+
*
24+
* <p>This method creates an SDMAttachmentsReader instance to traverse the entity's structure and
25+
* identify all paths that lead to attachment entities within the CDS model. It uses an
26+
* SDMAssociationCascader to handle cascading through entity associations and compositions to find
27+
* nested attachment relationships.
28+
*
29+
* @param model the CDS model containing entity definitions and relationships
30+
* @param entity the target CDS entity to analyze for attachment paths
31+
* @param persistenceService the persistence service used for data access operations
32+
* @return a list of strings representing paths to attachment entities, or an empty list if no
33+
* attachments are found or if an error occurs during processing
34+
*/
2335
public static List<String> getAttachmentEntityPaths(
2436
CdsModel model, CdsEntity entity, PersistenceService persistenceService) {
2537
try {
@@ -31,6 +43,21 @@ public static List<String> getAttachmentEntityPaths(
3143
}
3244
}
3345

46+
/**
47+
* Creates a mapping of attachment entity paths to their corresponding actual paths within the CDS
48+
* model.
49+
*
50+
* <p>This method analyzes both direct and nested attachment compositions within the given entity.
51+
* It processes direct attachments that are immediate compositions of the entity, and also
52+
* traverses nested compositions to find attachments in related entities. The resulting mapping
53+
* provides a translation between logical attachment paths and their actual implementation paths.
54+
*
55+
* @param model the CDS model containing entity definitions and relationships
56+
* @param entity the target CDS entity to analyze for attachment path mappings
57+
* @param persistenceService the persistence service used for data access operations
58+
* @return a map where keys are attachment entity paths and values are the corresponding actual
59+
* paths, or an empty map if no attachments are found or if an error occurs during processing
60+
*/
3461
public static Map<String, String> getAttachmentPathMapping(
3562
CdsModel model, CdsEntity entity, PersistenceService persistenceService) {
3663
try {
@@ -144,6 +171,22 @@ private static boolean isDirectAttachmentTargetAspect(String targetAspect) {
144171
return targetAspect != null && targetAspect.equalsIgnoreCase("sap.attachments.Attachments");
145172
}
146173

174+
/**
175+
* Fetches attachment data from a nested entity structure based on the target entity and
176+
* composition name.
177+
*
178+
* <p>This method processes the target entity path to extract the entity name, wraps the provided
179+
* entity data with a parent structure, and then searches for attachments within the nested
180+
* structure. It parses the attachment composition name to identify both the attachment key (e.g.,
181+
* "attachments") and the parent key (e.g., "chapters") for precise attachment location.
182+
*
183+
* @param targetEntity the qualified name of the target entity (e.g., "ServiceName.EntityName")
184+
* @param entity the entity data structure containing potential attachment information
185+
* @param attachmentCompositionName the composition path to the attachments (e.g.,
186+
* "chapters.attachments")
187+
* @return a list of maps representing attachment objects found in the entity structure, or an
188+
* empty list if no attachments are found
189+
*/
147190
public static List<Map<String, Object>> fetchAttachments(
148191
String targetEntity, Map<String, Object> entity, String attachmentCompositionName) {
149192
String[] targetEntityPath = targetEntity.split("\\.");
@@ -309,6 +352,18 @@ private static boolean isCorrectParentContext(String currentParentKey, String ex
309352
return expectedParentKey.equals(currentParentKey);
310353
}
311354

355+
/**
356+
* Wraps an entity data structure with a parent container using the specified target entity name.
357+
*
358+
* <p>This utility method creates a new map with the target entity name as the key and the
359+
* provided entity data as the value. This is necessary because the root of the target entity in
360+
* the CdsData object is not mentioned explicitly, and hence interferes with the recursive
361+
* fetching of attachment compositions.
362+
*
363+
* @param root the entity data structure to be wrapped
364+
* @param targetEntity the name to use as the parent key for wrapping the entity data
365+
* @return a new map containing the target entity name as key and the root entity data as value
366+
*/
312367
public static Map<String, Object> wrapEntityWithParent(
313368
Map<String, Object> root, String targetEntity) {
314369
Map<String, Object> wrapper = new HashMap<>();

0 commit comments

Comments
 (0)