Skip to content

Commit 80e1a66

Browse files
addressing review comments
1 parent b3a1d8d commit 80e1a66

File tree

5 files changed

+14
-19
lines changed

5 files changed

+14
-19
lines changed

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.slf4j.Logger;
1313
import org.slf4j.LoggerFactory;
1414

15-
@ServiceName(value = "*", type = ApplicationService.class)
1615
public class AttachmentsHandlerUtils {
1716

1817
private static final Logger logger = LoggerFactory.getLogger(AttachmentsHandlerUtils.class);
@@ -55,7 +54,7 @@ public static Map<String, String> getAttachmentPathMapping(
5554

5655
return pathMapping;
5756
} catch (Exception e) {
58-
logger.error("Error getting attachment path mapping", e);
57+
logger.error("Error getting attachment path mapping", e.getMessage());
5958
return new HashMap<>();
6059
}
6160
}
@@ -64,11 +63,11 @@ private static void processDirectAttachmentComposition(
6463
CdsEntity entity, Map<String, String> pathMapping, Object composition) {
6564
String compositionName = ((com.sap.cds.reflect.CdsElement) composition).getName();
6665
if (((com.sap.cds.reflect.CdsElement) composition).getType().isAssociation()) {
67-
CdsAssociationType assocType =
66+
CdsAssociationType associationType =
6867
(CdsAssociationType) ((com.sap.cds.reflect.CdsElement) composition).getType();
6968
String targetAspect =
70-
assocType.getTargetAspect().isPresent()
71-
? assocType.getTargetAspect().get().getQualifiedName()
69+
associationType.getTargetAspect().isPresent()
70+
? associationType.getTargetAspect().get().getQualifiedName()
7271
: null;
7372

7473
if (isDirectAttachmentTargetAspect(targetAspect)) {
@@ -90,18 +89,18 @@ private static void processNestedAttachmentComposition(
9089
String compositionTargetEntityName = "";
9190

9291
if (((com.sap.cds.reflect.CdsElement) composition).getType().isAssociation()) {
93-
CdsAssociationType assocType =
92+
CdsAssociationType associationType =
9493
(CdsAssociationType) ((com.sap.cds.reflect.CdsElement) composition).getType();
9594
String targetAspect =
96-
assocType.getTargetAspect().isPresent()
97-
? assocType.getTargetAspect().get().getQualifiedName()
95+
associationType.getTargetAspect().isPresent()
96+
? associationType.getTargetAspect().get().getQualifiedName()
9897
: null;
9998

10099
if (isDirectAttachmentTargetAspect(targetAspect)) {
101100
return; // Skip direct attachment compositions
102101
}
103102

104-
compositionTargetEntityName = assocType.getTarget().getQualifiedName();
103+
compositionTargetEntityName = associationType.getTarget().getQualifiedName();
105104
}
106105

107106
processCompositionTargetEntity(
@@ -252,7 +251,6 @@ private static List<Map<String, Object>> processAttachmentKey(
252251
// Check if the parent matches (if parentKey is specified)
253252
if (parentKey == null || isCorrectParentContext(currentParentKey, parentKey)) {
254253
try {
255-
@SuppressWarnings("unchecked")
256254
List<Map<String, Object>> attachments = (List<Map<String, Object>>) value;
257255
result.addAll(attachments);
258256
} catch (ClassCastException e) {
@@ -268,7 +266,6 @@ private static List<Map<String, Object>> processNestedMap(
268266
List<Map<String, Object>> result = new ArrayList<>();
269267

270268
try {
271-
@SuppressWarnings("unchecked")
272269
Map<String, Object> nestedMap = (Map<String, Object>) value;
273270
result.addAll(findNestedAttachments(nestedMap, attachmentKey, parentKey, key));
274271
} catch (ClassCastException e) {
@@ -286,7 +283,6 @@ private static List<Map<String, Object>> processNestedList(
286283
List<?> list = (List<?>) value;
287284
for (Object item : list) {
288285
if (item instanceof Map) {
289-
@SuppressWarnings("unchecked")
290286
Map<String, Object> itemMap = (Map<String, Object>) item;
291287
result.addAll(findNestedAttachments(itemMap, attachmentKey, parentKey, key));
292288
}

sdm/src/main/java/com/sap/cds/sdm/service/handler/SDMAttachmentsServiceHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ private String getUpIdKey(CdsEntity attachmentDraftEntity) {
188188
if (upAssociation.isPresent()) {
189189
CdsElement association = upAssociation.get();
190190
// get association type
191-
CdsAssociationType assocType = association.getType();
191+
CdsAssociationType associationType = association.getType();
192192
// get the refs of the association
193-
List<String> fkElements = assocType.refs().map(ref -> "up__" + ref.path()).toList();
193+
List<String> fkElements = associationType.refs().map(ref -> "up__" + ref.path()).toList();
194194
upIdKey = fkElements.get(0);
195195
}
196196
return upIdKey;

sdm/src/main/java/com/sap/cds/sdm/service/handler/SDMCustomServiceHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ public void copyAttachments(AttachmentCopyEventContext context) throws IOExcepti
106106
Optional<CdsElement> upAssociation = attachmentDraftEntity.get().findAssociation("up_");
107107
if (upAssociation.isPresent()) {
108108
CdsElement association = upAssociation.get();
109-
CdsAssociationType assocType = association.getType();
110-
List<String> fkElements = assocType.refs().map(ref -> "up__" + ref.path()).toList();
109+
CdsAssociationType associationType = association.getType();
110+
List<String> fkElements = associationType.refs().map(ref -> "up__" + ref.path()).toList();
111111
upIdKey = fkElements.get(0);
112112
}
113113
Map<String, Object> updatedFields = new HashMap<>();

sdm/src/main/java/com/sap/cds/sdm/service/handler/SDMServiceGenericHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ private String getUpIdKey(CdsEntity attachmentDraftEntity) {
210210
if (upAssociation.isPresent()) {
211211
CdsElement association = upAssociation.get();
212212
// get association type
213-
CdsAssociationType assocType = association.getType();
213+
CdsAssociationType associationType = association.getType();
214214
// get the refs of the association
215-
List<String> fkElements = assocType.refs().map(ref -> "up__" + ref.path()).toList();
215+
List<String> fkElements = associationType.refs().map(ref -> "up__" + ref.path()).toList();
216216
upIdKey = fkElements.get(0);
217217
}
218218
return upIdKey;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,6 @@ void testElementWithoutAnnotation() {
643643
void testElementWithAnnotation() {
644644
CdsEntity entity = mock(CdsEntity.class);
645645
CdsElement element = mock(CdsElement.class);
646-
@SuppressWarnings("unchecked")
647646
CdsAnnotation<Object> annotation = mock(CdsAnnotation.class);
648647
when(annotation.getValue()).thenReturn("name");
649648

0 commit comments

Comments
 (0)