Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,15 @@ private void revertLinksForComposition(

CdsModel model = context.getModel();
String draftEntityName = attachmentCompositionDefinition + "_drafts";
CdsEntity draftEntity = model.findEntity(draftEntityName).get();
CdsEntity activeEntity = model.findEntity(attachmentCompositionDefinition).get();
Optional<CdsEntity> draftEntityOpt = model.findEntity(draftEntityName);
Optional<CdsEntity> activeEntityOpt = model.findEntity(attachmentCompositionDefinition);
if (!draftEntityOpt.isPresent() || !activeEntityOpt.isPresent()) {
logger.debug(
"Entity not found in model, skipping revert for: {}", attachmentCompositionDefinition);
return;
}
CdsEntity draftEntity = draftEntityOpt.get();
CdsEntity activeEntity = activeEntityOpt.get();

final String upIdKey = SDMUtils.getUpIdKey(draftEntity);
if (upIdKey == null || upIdKey.isEmpty()) {
Expand All @@ -299,6 +306,9 @@ private void revertLinksForComposition(

Result draftLinks = persistenceService.run(selectDraftLinks);
logger.debug("Found {} draft links to process", draftLinks.rowCount());
if (draftLinks.rowCount() == 0) {
return;
}
SDMCredentials sdmCredentials = tokenHandler.getSDMCredentials();
Boolean isSystemUser = context.getUserInfo().isSystemUser();

Expand Down
2 changes: 0 additions & 2 deletions sdm/src/main/resources/cds/com.sap.cds/sdm/attachments.cds
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ extend aspect Attachments with {
type : String @(UI: {IsImageURL: true}) default 'sap-icon://document';
uploadStatus : UploadStatusCode default 'uploading' @readonly ;
uploadStatusNav : Association to one UploadScanStates on uploadStatusNav.code = uploadStatus;
} actions {
action downloadSelectedAttachments(ids: String) returns String;
}
entity UploadScanStates : CodeList {
key code : UploadStatusCode @Common.Text: name @Common.TextArrangement: #TextOnly;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,7 @@ void testRevertLinksForComposition() throws Exception {

Result draftLinksResult = mock(Result.class);
Row draftLinkRow = mock(Row.class);
when(draftLinksResult.rowCount()).thenReturn(1L);
when(draftLinksResult.iterator()).thenReturn(Arrays.asList(draftLinkRow).iterator());
when(persistenceService.run(any(CqnSelect.class))).thenReturn(draftLinksResult);

Expand Down Expand Up @@ -2244,8 +2245,8 @@ void testRevertLinksForComposition_NoLinksToRevert() throws Exception {
});

verify(persistenceService, times(1)).run(any(CqnSelect.class));
verify(tokenHandler, times(1)).getSDMCredentials();
verify(context, times(1)).getUserInfo();
verify(tokenHandler, never()).getSDMCredentials();
verify(context, never()).getUserInfo();
}

@Test
Expand All @@ -2266,6 +2267,7 @@ void testRevertLinksForComposition_SameUrls() throws Exception {

Result draftLinksResult = mock(Result.class);
Row draftLinkRow = mock(Row.class);
when(draftLinksResult.rowCount()).thenReturn(1L);
when(draftLinksResult.iterator()).thenReturn(Arrays.asList(draftLinkRow).iterator());

when(draftLinkRow.get("ID")).thenReturn("attachment123");
Expand Down
Loading