Skip to content

Commit 2e1ba41

Browse files
committed
github-code-quality security fix
1 parent d4e5043 commit 2e1ba41

4 files changed

Lines changed: 58 additions & 16 deletions

File tree

sdm/src/main/java/com/sap/cds/sdm/model/AttachmentMoveContext.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.sap.cds.sdm.model;
22

33
import com.sap.cds.reflect.CdsEntity;
4+
import java.util.Collections;
45
import java.util.List;
56
import java.util.Map;
67

@@ -56,6 +57,14 @@ public AttachmentProcessingResults getProcessingResults() {
5657
}
5758

5859
public List<Map<String, String>> getFailedAttachments() {
59-
return failedAttachments;
60+
return Collections.unmodifiableList(failedAttachments);
61+
}
62+
63+
/**
64+
* Internal method for adding failed attachments during processing. For internal use only - do not
65+
* expose to external callers.
66+
*/
67+
public void addFailedAttachment(Map<String, String> failure) {
68+
failedAttachments.add(failure);
6069
}
6170
}

sdm/src/main/java/com/sap/cds/sdm/model/DatabaseFailureContext.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.sap.cds.sdm.model;
22

33
import com.sap.cds.sdm.service.handler.AttachmentMoveEventContext;
4+
import java.util.Collections;
45
import java.util.List;
56
import java.util.Map;
67

@@ -63,6 +64,14 @@ public AttachmentMoveEventContext getContext() {
6364
}
6465

6566
public List<Map<String, String>> getFailedAttachments() {
66-
return failedAttachments;
67+
return Collections.unmodifiableList(failedAttachments);
68+
}
69+
70+
/**
71+
* Internal method for adding failed attachments during processing. For internal use only - do not
72+
* expose to external callers.
73+
*/
74+
public void addFailedAttachment(Map<String, String> failure) {
75+
failedAttachments.add(failure);
6776
}
6877
}

sdm/src/main/java/com/sap/cds/sdm/model/ValidatedAttachmentData.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.sap.cds.sdm.model;
22

33
import com.sap.cds.reflect.CdsEntity;
4+
import java.util.Collections;
45
import java.util.List;
56
import java.util.Map;
67
import org.json.JSONObject;
@@ -80,15 +81,39 @@ public CdsEntity getTargetEntity() {
8081
}
8182

8283
public List<String> getSuccessfulObjectIds() {
83-
return successfulObjectIds;
84+
return Collections.unmodifiableList(successfulObjectIds);
8485
}
8586

8687
public List<List<String>> getMovedAttachmentsMetadata() {
87-
return movedAttachmentsMetadata;
88+
return Collections.unmodifiableList(movedAttachmentsMetadata);
8889
}
8990

9091
public List<CmisDocument> getPopulatedDocuments() {
91-
return populatedDocuments;
92+
return Collections.unmodifiableList(populatedDocuments);
93+
}
94+
95+
/**
96+
* Internal method for adding successful object IDs during processing. For internal use only - do
97+
* not expose to external callers.
98+
*/
99+
public void addSuccessfulObjectId(String objectId) {
100+
successfulObjectIds.add(objectId);
101+
}
102+
103+
/**
104+
* Internal method for adding moved attachments metadata during processing. For internal use only
105+
* - do not expose to external callers.
106+
*/
107+
public void addMovedAttachmentMetadata(List<String> metadata) {
108+
movedAttachmentsMetadata.add(metadata);
109+
}
110+
111+
/**
112+
* Internal method for adding populated documents during processing. For internal use only - do
113+
* not expose to external callers.
114+
*/
115+
public void addPopulatedDocument(CmisDocument document) {
116+
populatedDocuments.add(document);
92117
}
93118

94119
public CmisDocument getSourceCmisDocument() {

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ private void processSingleAttachmentMove(AttachmentMoveContext moveContext) {
759759
Map<String, String> failure = new HashMap<>();
760760
failure.put(OBJECT_ID_KEY, moveContext.getObjectId());
761761
failure.put(FAILURE_REASON_KEY, "SDM move failed: " + e.getMessage());
762-
moveContext.getFailedAttachments().add(failure);
762+
moveContext.addFailedAttachment(failure);
763763
} catch (Exception e) {
764764
// Validation/processing failed
765765
logger.error(
@@ -770,7 +770,7 @@ private void processSingleAttachmentMove(AttachmentMoveContext moveContext) {
770770
Map<String, String> failure = new HashMap<>();
771771
failure.put(OBJECT_ID_KEY, moveContext.getObjectId());
772772
failure.put(FAILURE_REASON_KEY, "Validation/processing failed: " + e.getMessage());
773-
moveContext.getFailedAttachments().add(failure);
773+
moveContext.addFailedAttachment(failure);
774774
}
775775
}
776776

@@ -801,15 +801,14 @@ private void processValidatedAttachment(ValidatedAttachmentData data) {
801801
filteredSecondaryProps);
802802

803803
// Add to successful results
804-
data.getSuccessfulObjectIds().add(data.getObjectId());
805-
data.getMovedAttachmentsMetadata()
806-
.add(
807-
List.of(
808-
data.getFileName(),
809-
data.getMimeType(),
810-
data.getDescription(),
811-
data.getMovedObjectId()));
812-
data.getPopulatedDocuments().add(populatedDocument);
804+
data.addSuccessfulObjectId(data.getObjectId());
805+
data.addMovedAttachmentMetadata(
806+
List.of(
807+
data.getFileName(),
808+
data.getMimeType(),
809+
data.getDescription(),
810+
data.getMovedObjectId()));
811+
data.addPopulatedDocument(populatedDocument);
813812
}
814813

815814
/**

0 commit comments

Comments
 (0)