From 3928ceb7d0036643e39f08c697157a58401fbb2b Mon Sep 17 00:00:00 2001 From: PujaDeshmukh17 Date: Wed, 12 Aug 2026 17:17:50 +0530 Subject: [PATCH 1/5] Fix for isActiveEntity error --- pom.xml | 2 +- .../com/sap/cds/sdm/persistence/DBQuery.java | 109 ++++--- .../sap/cds/sdm/persistence/DBQueryTest.java | 265 +++++++++++++++--- 3 files changed, 304 insertions(+), 72 deletions(-) diff --git a/pom.xml b/pom.xml index ec233baa7..6cffa3ce5 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ - 1.9.3 + 1.9.4 17 ${java.version} ${java.version} diff --git a/sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java b/sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java index 508c05a84..ca88fc7d7 100644 --- a/sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java +++ b/sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java @@ -50,10 +50,18 @@ public Result getAttachmentsForUPID( upID, upIdKey, attachmentEntity.getQualifiedName()); - CqnSelect q = - Select.from(attachmentEntity) - .columns("fileName", "ID", "IsActiveEntity", "folderId", "repositoryId", "mimeType") - .where(doc -> doc.get(upIdKey).eq(upID)); + CqnSelect q; + if (attachmentEntity.findElement("IsActiveEntity").isPresent()) { + q = + Select.from(attachmentEntity) + .columns("fileName", "ID", "IsActiveEntity", "folderId", "repositoryId", "mimeType") + .where(doc -> doc.get(upIdKey).eq(upID)); + } else { + q = + Select.from(attachmentEntity) + .columns("fileName", "ID", "folderId", "repositoryId", "mimeType") + .where(doc -> doc.get(upIdKey).eq(upID)); + } Result result = persistenceService.run(q); logger.debug("Found {} attachment(s) for upID: {}", result.rowCount(), upID); return result; @@ -376,14 +384,26 @@ public Result getAttachmentsForUPIDAndRepository( upID, SDMConstants.REPOSITORY_ID, attachmentEntity.getQualifiedName()); - CqnSelect q = - Select.from(attachmentEntity) - .columns("fileName", "ID", "IsActiveEntity", "folderId", "repositoryId") - .where( - doc -> - doc.get(upIdKey) - .eq(upID) - .and(doc.get("repositoryId").eq(SDMConstants.REPOSITORY_ID))); + CqnSelect q; + if (attachmentEntity.findElement("IsActiveEntity").isPresent()) { + q = + Select.from(attachmentEntity) + .columns("fileName", "ID", "IsActiveEntity", "folderId", "repositoryId") + .where( + doc -> + doc.get(upIdKey) + .eq(upID) + .and(doc.get("repositoryId").eq(SDMConstants.REPOSITORY_ID))); + } else { + q = + Select.from(attachmentEntity) + .columns("fileName", "ID", "folderId", "repositoryId") + .where( + doc -> + doc.get(upIdKey) + .eq(upID) + .and(doc.get("repositoryId").eq(SDMConstants.REPOSITORY_ID))); + } Result result = persistenceService.run(q); logger.debug( "Found {} attachment(s) for upID: {} with repositoryId: {}", @@ -477,17 +497,28 @@ public List getAttachmentsForFolder( logger.debug("Fetching attachments for folderId: {} from entity: {}", folderId, entity); Optional attachmentEntity = context.getModel().findEntity(entity + "_drafts"); List cmisDocuments = new ArrayList<>(); - CqnSelect q = - Select.from(attachmentEntity.get()) - .columns( - "fileName", - "IsActiveEntity", - "ID", - "folderId", - "repositoryId", - "objectId", - "uploadStatus") - .where(doc -> doc.get("folderId").eq(folderId)); + boolean draftHasIsActiveEntity = + attachmentEntity.isPresent() + && attachmentEntity.get().findElement("IsActiveEntity").isPresent(); + CqnSelect q; + if (draftHasIsActiveEntity) { + q = + Select.from(attachmentEntity.get()) + .columns( + "fileName", + "IsActiveEntity", + "ID", + "folderId", + "repositoryId", + "objectId", + "uploadStatus") + .where(doc -> doc.get("folderId").eq(folderId)); + } else { + q = + Select.from(attachmentEntity.get()) + .columns("fileName", "ID", "folderId", "repositoryId", "objectId", "uploadStatus") + .where(doc -> doc.get("folderId").eq(folderId)); + } Result result = persistenceService.run(q); for (Row row : result.list()) { CmisDocument cmisDocument = new CmisDocument(); @@ -508,17 +539,27 @@ public List getAttachmentsForFolder( folderId, entity); attachmentEntity = context.getModel().findEntity(entity); - q = - Select.from(attachmentEntity.get()) - .columns( - "fileName", - "IsActiveEntity", - "ID", - "folderId", - "repositoryId", - "objectId", - "uploadStatus") - .where(doc -> doc.get("folderId").eq(folderId)); + boolean activeHasIsActiveEntity = + attachmentEntity.isPresent() + && attachmentEntity.get().findElement("IsActiveEntity").isPresent(); + if (activeHasIsActiveEntity) { + q = + Select.from(attachmentEntity.get()) + .columns( + "fileName", + "IsActiveEntity", + "ID", + "folderId", + "repositoryId", + "objectId", + "uploadStatus") + .where(doc -> doc.get("folderId").eq(folderId)); + } else { + q = + Select.from(attachmentEntity.get()) + .columns("fileName", "ID", "folderId", "repositoryId", "objectId", "uploadStatus") + .where(doc -> doc.get("folderId").eq(folderId)); + } result = persistenceService.run(q); for (Row row : result.list()) { CmisDocument cmisDocument = new CmisDocument(); diff --git a/sdm/src/test/java/unit/com/sap/cds/sdm/persistence/DBQueryTest.java b/sdm/src/test/java/unit/com/sap/cds/sdm/persistence/DBQueryTest.java index e4228af82..73d835bc6 100644 --- a/sdm/src/test/java/unit/com/sap/cds/sdm/persistence/DBQueryTest.java +++ b/sdm/src/test/java/unit/com/sap/cds/sdm/persistence/DBQueryTest.java @@ -6,14 +6,18 @@ import com.sap.cds.Result; import com.sap.cds.Row; +import com.sap.cds.feature.attachments.service.model.servicehandler.AttachmentMarkAsDeletedEventContext; import com.sap.cds.ql.cqn.CqnSelect; import com.sap.cds.ql.cqn.CqnUpdate; +import com.sap.cds.reflect.CdsElement; import com.sap.cds.reflect.CdsEntity; +import com.sap.cds.reflect.CdsModel; import com.sap.cds.sdm.constants.SDMConstants; import com.sap.cds.sdm.model.CmisDocument; import com.sap.cds.sdm.persistence.DBQuery; import com.sap.cds.services.persistence.PersistenceService; import java.util.List; +import java.util.Optional; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -25,6 +29,9 @@ class DBQueryTest { @Mock private CdsEntity mockDraftEntity; @Mock private CdsEntity mockActiveEntity; + @Mock private CdsElement mockCdsElement; + @Mock private CdsModel mockCdsModel; + @Mock private AttachmentMarkAsDeletedEventContext mockDeleteContext; @Mock private PersistenceService mockPersistenceService; @Mock private Result mockResult; @Mock private Row mockRow; @@ -303,42 +310,226 @@ void testUpdateUploadStatusByScanStatus_NoRecordsUpdated() { } @Test - void testUpdateUploadStatusByScanStatus_AllScanStatuses() { - // Test all scan status mappings - String objectId = "object-123"; - Result mockResult = mock(Result.class); - when(mockResult.rowCount()).thenReturn(1L); - when(mockPersistenceService.run(any(CqnUpdate.class))).thenReturn(mockResult); - - // Test QUARANTINED -> UPLOAD_STATUS_VIRUS_DETECTED - dbQuery.updateUploadStatusByScanStatus( - mockDraftEntity, - null, - mockPersistenceService, - objectId, - SDMConstants.ScanStatus.QUARANTINED); - - // Test PENDING -> UPLOAD_STATUS_IN_PROGRESS - dbQuery.updateUploadStatusByScanStatus( - mockDraftEntity, null, mockPersistenceService, objectId, SDMConstants.ScanStatus.PENDING); - - // Test SCANNING -> VIRUS_SCAN_INPROGRESS - dbQuery.updateUploadStatusByScanStatus( - mockDraftEntity, null, mockPersistenceService, objectId, SDMConstants.ScanStatus.SCANNING); - - // Test FAILED -> UPLOAD_STATUS_SCAN_FAILED - dbQuery.updateUploadStatusByScanStatus( - mockDraftEntity, null, mockPersistenceService, objectId, SDMConstants.ScanStatus.FAILED); - - // Test CLEAN -> UPLOAD_STATUS_SUCCESS - dbQuery.updateUploadStatusByScanStatus( - mockDraftEntity, null, mockPersistenceService, objectId, SDMConstants.ScanStatus.CLEAN); - - // Test BLANK -> UPLOAD_STATUS_SUCCESS - dbQuery.updateUploadStatusByScanStatus( - mockDraftEntity, null, mockPersistenceService, objectId, SDMConstants.ScanStatus.BLANK); - - // Verify all updates were called - verify(mockPersistenceService, times(6)).run(any(CqnUpdate.class)); + void testGetAttachmentsForUPID_WithIsActiveEntity() { + String upID = "testUpID"; + String upIdKey = "up__ID"; + + when(mockDraftEntity.findElement("IsActiveEntity")).thenReturn(Optional.of(mockCdsElement)); + + Result result = mock(Result.class); + when(result.rowCount()).thenReturn(1L); + when(mockPersistenceService.run(any(CqnSelect.class))).thenReturn(result); + + Result actual = + dbQuery.getAttachmentsForUPID(mockDraftEntity, mockPersistenceService, upID, upIdKey); + + assertNotNull(actual); + verify(mockPersistenceService, times(1)).run(any(CqnSelect.class)); + verify(mockDraftEntity).findElement("IsActiveEntity"); + } + + @Test + void testGetAttachmentsForUPID_WithoutIsActiveEntity() { + String upID = "testUpID"; + String upIdKey = "up__ID"; + + when(mockDraftEntity.findElement("IsActiveEntity")).thenReturn(Optional.empty()); + + Result result = mock(Result.class); + when(result.rowCount()).thenReturn(1L); + when(mockPersistenceService.run(any(CqnSelect.class))).thenReturn(result); + + Result actual = + dbQuery.getAttachmentsForUPID(mockDraftEntity, mockPersistenceService, upID, upIdKey); + + assertNotNull(actual); + verify(mockPersistenceService, times(1)).run(any(CqnSelect.class)); + verify(mockDraftEntity).findElement("IsActiveEntity"); + } + + @Test + void testGetAttachmentsForUPIDAndRepository_WithIsActiveEntity() { + String upID = "testUpID"; + String upIdKey = "up__ID"; + + when(mockDraftEntity.findElement("IsActiveEntity")).thenReturn(Optional.of(mockCdsElement)); + + Result result = mock(Result.class); + when(result.rowCount()).thenReturn(1L); + when(mockPersistenceService.run(any(CqnSelect.class))).thenReturn(result); + + Result actual = + dbQuery.getAttachmentsForUPIDAndRepository( + mockDraftEntity, mockPersistenceService, upID, upIdKey); + + assertNotNull(actual); + verify(mockPersistenceService, times(1)).run(any(CqnSelect.class)); + verify(mockDraftEntity).findElement("IsActiveEntity"); + } + + @Test + void testGetAttachmentsForUPIDAndRepository_WithoutIsActiveEntity() { + String upID = "testUpID"; + String upIdKey = "up__ID"; + + when(mockDraftEntity.findElement("IsActiveEntity")).thenReturn(Optional.empty()); + + Result result = mock(Result.class); + when(result.rowCount()).thenReturn(1L); + when(mockPersistenceService.run(any(CqnSelect.class))).thenReturn(result); + + Result actual = + dbQuery.getAttachmentsForUPIDAndRepository( + mockDraftEntity, mockPersistenceService, upID, upIdKey); + + assertNotNull(actual); + verify(mockPersistenceService, times(1)).run(any(CqnSelect.class)); + verify(mockDraftEntity).findElement("IsActiveEntity"); + } + + @Test + void testGetAttachmentsForFolder_DraftEntity_WithIsActiveEntity() { + String entity = "TestEntity"; + String folderId = "folder-1"; + + when(mockDeleteContext.getModel()).thenReturn(mockCdsModel); + when(mockCdsModel.findEntity(entity + "_drafts")).thenReturn(Optional.of(mockDraftEntity)); + when(mockDraftEntity.findElement("IsActiveEntity")).thenReturn(Optional.of(mockCdsElement)); + + Row row = mock(Row.class); + when(row.get("folderId")).thenReturn("folder-1"); + when(row.get("repositoryId")).thenReturn("repo-1"); + when(row.get("fileName")).thenReturn("file.pdf"); + when(row.get("ID")).thenReturn("id-1"); + when(row.get("objectId")).thenReturn("obj-1"); + when(row.get("uploadStatus")).thenReturn("Clean"); + + Result draftResult = mock(Result.class); + when(draftResult.list()).thenReturn(List.of(row)); + when(mockPersistenceService.run(any(CqnSelect.class))).thenReturn(draftResult); + + List docs = + dbQuery.getAttachmentsForFolder( + entity, mockPersistenceService, folderId, mockDeleteContext); + + assertNotNull(docs); + assertEquals(1, docs.size()); + assertEquals("file.pdf", docs.get(0).getFileName()); + verify(mockPersistenceService, times(1)).run(any(CqnSelect.class)); + verify(mockDraftEntity).findElement("IsActiveEntity"); + } + + @Test + void testGetAttachmentsForFolder_DraftEntity_WithoutIsActiveEntity() { + String entity = "TestEntity"; + String folderId = "folder-1"; + + when(mockDeleteContext.getModel()).thenReturn(mockCdsModel); + when(mockCdsModel.findEntity(entity + "_drafts")).thenReturn(Optional.of(mockDraftEntity)); + when(mockDraftEntity.findElement("IsActiveEntity")).thenReturn(Optional.empty()); + + Row row = mock(Row.class); + when(row.get("folderId")).thenReturn("folder-1"); + when(row.get("repositoryId")).thenReturn("repo-1"); + when(row.get("fileName")).thenReturn("file.pdf"); + when(row.get("ID")).thenReturn("id-1"); + when(row.get("objectId")).thenReturn("obj-1"); + when(row.get("uploadStatus")).thenReturn("Clean"); + + Result draftResult = mock(Result.class); + when(draftResult.list()).thenReturn(List.of(row)); + when(mockPersistenceService.run(any(CqnSelect.class))).thenReturn(draftResult); + + List docs = + dbQuery.getAttachmentsForFolder( + entity, mockPersistenceService, folderId, mockDeleteContext); + + assertNotNull(docs); + assertEquals(1, docs.size()); + assertEquals("file.pdf", docs.get(0).getFileName()); + verify(mockPersistenceService, times(1)).run(any(CqnSelect.class)); + verify(mockDraftEntity).findElement("IsActiveEntity"); + } + + @Test + void testGetAttachmentsForFolder_FallsBackToActiveEntity_WithIsActiveEntity() { + String entity = "TestEntity"; + String folderId = "folder-1"; + + when(mockDeleteContext.getModel()).thenReturn(mockCdsModel); + when(mockCdsModel.findEntity(entity + "_drafts")).thenReturn(Optional.of(mockDraftEntity)); + when(mockDraftEntity.findElement("IsActiveEntity")).thenReturn(Optional.of(mockCdsElement)); + + Result emptyDraftResult = mock(Result.class); + when(emptyDraftResult.list()).thenReturn(List.of()); + + when(mockCdsModel.findEntity(entity)).thenReturn(Optional.of(mockActiveEntity)); + when(mockActiveEntity.findElement("IsActiveEntity")).thenReturn(Optional.of(mockCdsElement)); + + Row row = mock(Row.class); + when(row.get("folderId")).thenReturn("folder-1"); + when(row.get("repositoryId")).thenReturn("repo-1"); + when(row.get("fileName")).thenReturn("active-file.pdf"); + when(row.get("ID")).thenReturn("id-2"); + when(row.get("objectId")).thenReturn("obj-2"); + when(row.get("uploadStatus")).thenReturn("Clean"); + + Result activeResult = mock(Result.class); + when(activeResult.list()).thenReturn(List.of(row)); + + when(mockPersistenceService.run(any(CqnSelect.class))) + .thenReturn(emptyDraftResult) + .thenReturn(activeResult); + + List docs = + dbQuery.getAttachmentsForFolder( + entity, mockPersistenceService, folderId, mockDeleteContext); + + assertNotNull(docs); + assertEquals(1, docs.size()); + assertEquals("active-file.pdf", docs.get(0).getFileName()); + verify(mockPersistenceService, times(2)).run(any(CqnSelect.class)); + verify(mockActiveEntity).findElement("IsActiveEntity"); + } + + @Test + void testGetAttachmentsForFolder_FallsBackToActiveEntity_WithoutIsActiveEntity() { + String entity = "TestEntity"; + String folderId = "folder-1"; + + when(mockDeleteContext.getModel()).thenReturn(mockCdsModel); + when(mockCdsModel.findEntity(entity + "_drafts")).thenReturn(Optional.of(mockDraftEntity)); + when(mockDraftEntity.findElement("IsActiveEntity")).thenReturn(Optional.empty()); + + Result emptyDraftResult = mock(Result.class); + when(emptyDraftResult.list()).thenReturn(List.of()); + + when(mockCdsModel.findEntity(entity)).thenReturn(Optional.of(mockActiveEntity)); + when(mockActiveEntity.findElement("IsActiveEntity")).thenReturn(Optional.empty()); + + Row row = mock(Row.class); + when(row.get("folderId")).thenReturn("folder-1"); + when(row.get("repositoryId")).thenReturn("repo-1"); + when(row.get("fileName")).thenReturn("active-file.pdf"); + when(row.get("ID")).thenReturn("id-2"); + when(row.get("objectId")).thenReturn("obj-2"); + when(row.get("uploadStatus")).thenReturn("Clean"); + + Result activeResult = mock(Result.class); + when(activeResult.list()).thenReturn(List.of(row)); + + when(mockPersistenceService.run(any(CqnSelect.class))) + .thenReturn(emptyDraftResult) + .thenReturn(activeResult); + + List docs = + dbQuery.getAttachmentsForFolder( + entity, mockPersistenceService, folderId, mockDeleteContext); + + assertNotNull(docs); + assertEquals(1, docs.size()); + assertEquals("active-file.pdf", docs.get(0).getFileName()); + verify(mockPersistenceService, times(2)).run(any(CqnSelect.class)); + verify(mockActiveEntity).findElement("IsActiveEntity"); } } From dd1007847fac8b9f3b743c0cea71a8c10c5da32a Mon Sep 17 00:00:00 2001 From: PujaDeshmukh17 Date: Wed, 12 Aug 2026 19:12:47 +0530 Subject: [PATCH 2/5] Changelog update --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e173cec2f..9e8cab955 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ 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.9.4 + +### Fixed +- Fix `element does not exist` error when querying attachments on non-draft entities. Queries in `getAttachmentsForUPID`, `getAttachmentsForUPIDAndRepository`, and `getAttachmentsForFolder` now conditionally include the `IsActiveEntity` column only when the field is present on the attachment entity. + ## Version 1.9.3 ### Fixed From f9afcd8b0c18d3844e32c812315bb152385cc94c Mon Sep 17 00:00:00 2001 From: PujaDeshmukh17 Date: Thu, 13 Aug 2026 11:00:57 +0530 Subject: [PATCH 3/5] Review comments --- .../com/sap/cds/sdm/persistence/DBQuery.java | 109 +++++++----------- 1 file changed, 40 insertions(+), 69 deletions(-) diff --git a/sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java b/sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java index ca88fc7d7..bcb53a4f3 100644 --- a/sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java +++ b/sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java @@ -50,18 +50,16 @@ public Result getAttachmentsForUPID( upID, upIdKey, attachmentEntity.getQualifiedName()); - CqnSelect q; + List columns = + new ArrayList<>( + java.util.Arrays.asList("fileName", "ID", "folderId", "repositoryId", "mimeType")); if (attachmentEntity.findElement("IsActiveEntity").isPresent()) { - q = - Select.from(attachmentEntity) - .columns("fileName", "ID", "IsActiveEntity", "folderId", "repositoryId", "mimeType") - .where(doc -> doc.get(upIdKey).eq(upID)); - } else { - q = - Select.from(attachmentEntity) - .columns("fileName", "ID", "folderId", "repositoryId", "mimeType") - .where(doc -> doc.get(upIdKey).eq(upID)); + columns.add("IsActiveEntity"); } + CqnSelect q = + Select.from(attachmentEntity) + .columns(columns.toArray(new String[0])) + .where(doc -> doc.get(upIdKey).eq(upID)); Result result = persistenceService.run(q); logger.debug("Found {} attachment(s) for upID: {}", result.rowCount(), upID); return result; @@ -384,26 +382,20 @@ public Result getAttachmentsForUPIDAndRepository( upID, SDMConstants.REPOSITORY_ID, attachmentEntity.getQualifiedName()); - CqnSelect q; + List columns = + new ArrayList<>( + java.util.Arrays.asList("fileName", "ID", "folderId", "repositoryId")); if (attachmentEntity.findElement("IsActiveEntity").isPresent()) { - q = - Select.from(attachmentEntity) - .columns("fileName", "ID", "IsActiveEntity", "folderId", "repositoryId") - .where( - doc -> - doc.get(upIdKey) - .eq(upID) - .and(doc.get("repositoryId").eq(SDMConstants.REPOSITORY_ID))); - } else { - q = - Select.from(attachmentEntity) - .columns("fileName", "ID", "folderId", "repositoryId") - .where( - doc -> - doc.get(upIdKey) - .eq(upID) - .and(doc.get("repositoryId").eq(SDMConstants.REPOSITORY_ID))); + columns.add("IsActiveEntity"); } + CqnSelect q = + Select.from(attachmentEntity) + .columns(columns.toArray(new String[0])) + .where( + doc -> + doc.get(upIdKey) + .eq(upID) + .and(doc.get("repositoryId").eq(SDMConstants.REPOSITORY_ID))); Result result = persistenceService.run(q); logger.debug( "Found {} attachment(s) for upID: {} with repositoryId: {}", @@ -497,28 +489,17 @@ public List getAttachmentsForFolder( logger.debug("Fetching attachments for folderId: {} from entity: {}", folderId, entity); Optional attachmentEntity = context.getModel().findEntity(entity + "_drafts"); List cmisDocuments = new ArrayList<>(); - boolean draftHasIsActiveEntity = - attachmentEntity.isPresent() - && attachmentEntity.get().findElement("IsActiveEntity").isPresent(); - CqnSelect q; - if (draftHasIsActiveEntity) { - q = - Select.from(attachmentEntity.get()) - .columns( - "fileName", - "IsActiveEntity", - "ID", - "folderId", - "repositoryId", - "objectId", - "uploadStatus") - .where(doc -> doc.get("folderId").eq(folderId)); - } else { - q = - Select.from(attachmentEntity.get()) - .columns("fileName", "ID", "folderId", "repositoryId", "objectId", "uploadStatus") - .where(doc -> doc.get("folderId").eq(folderId)); + List draftColumns = + new ArrayList<>( + java.util.Arrays.asList("fileName", "ID", "folderId", "repositoryId", "objectId", "uploadStatus")); + if (attachmentEntity.isPresent() + && attachmentEntity.get().findElement("IsActiveEntity").isPresent()) { + draftColumns.add("IsActiveEntity"); } + CqnSelect q = + Select.from(attachmentEntity.get()) + .columns(draftColumns.toArray(new String[0])) + .where(doc -> doc.get("folderId").eq(folderId)); Result result = persistenceService.run(q); for (Row row : result.list()) { CmisDocument cmisDocument = new CmisDocument(); @@ -539,27 +520,17 @@ public List getAttachmentsForFolder( folderId, entity); attachmentEntity = context.getModel().findEntity(entity); - boolean activeHasIsActiveEntity = - attachmentEntity.isPresent() - && attachmentEntity.get().findElement("IsActiveEntity").isPresent(); - if (activeHasIsActiveEntity) { - q = - Select.from(attachmentEntity.get()) - .columns( - "fileName", - "IsActiveEntity", - "ID", - "folderId", - "repositoryId", - "objectId", - "uploadStatus") - .where(doc -> doc.get("folderId").eq(folderId)); - } else { - q = - Select.from(attachmentEntity.get()) - .columns("fileName", "ID", "folderId", "repositoryId", "objectId", "uploadStatus") - .where(doc -> doc.get("folderId").eq(folderId)); + List activeColumns = + new ArrayList<>( + java.util.Arrays.asList("fileName", "ID", "folderId", "repositoryId", "objectId", "uploadStatus")); + if (attachmentEntity.isPresent() + && attachmentEntity.get().findElement("IsActiveEntity").isPresent()) { + activeColumns.add("IsActiveEntity"); } + q = + Select.from(attachmentEntity.get()) + .columns(activeColumns.toArray(new String[0])) + .where(doc -> doc.get("folderId").eq(folderId)); result = persistenceService.run(q); for (Row row : result.list()) { CmisDocument cmisDocument = new CmisDocument(); From 2d90af4dc90a545ed78543f467d4e72dff9cf496 Mon Sep 17 00:00:00 2001 From: PujaDeshmukh17 Date: Thu, 13 Aug 2026 11:05:02 +0530 Subject: [PATCH 4/5] UT --- .../sap/cds/sdm/persistence/DBQueryTest.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/sdm/src/test/java/unit/com/sap/cds/sdm/persistence/DBQueryTest.java b/sdm/src/test/java/unit/com/sap/cds/sdm/persistence/DBQueryTest.java index 73d835bc6..fa0be92fe 100644 --- a/sdm/src/test/java/unit/com/sap/cds/sdm/persistence/DBQueryTest.java +++ b/sdm/src/test/java/unit/com/sap/cds/sdm/persistence/DBQueryTest.java @@ -309,6 +309,46 @@ void testUpdateUploadStatusByScanStatus_NoRecordsUpdated() { verify(mockPersistenceService, times(1)).run(any(CqnUpdate.class)); } + @Test + void testUpdateUploadStatusByScanStatus_AllScanStatuses() { + // Test all scan status mappings + String objectId = "object-123"; + Result mockResult = mock(Result.class); + when(mockResult.rowCount()).thenReturn(1L); + when(mockPersistenceService.run(any(CqnUpdate.class))).thenReturn(mockResult); + + // Test QUARANTINED -> UPLOAD_STATUS_VIRUS_DETECTED + dbQuery.updateUploadStatusByScanStatus( + mockDraftEntity, + null, + mockPersistenceService, + objectId, + SDMConstants.ScanStatus.QUARANTINED); + + // Test PENDING -> UPLOAD_STATUS_IN_PROGRESS + dbQuery.updateUploadStatusByScanStatus( + mockDraftEntity, null, mockPersistenceService, objectId, SDMConstants.ScanStatus.PENDING); + + // Test SCANNING -> VIRUS_SCAN_INPROGRESS + dbQuery.updateUploadStatusByScanStatus( + mockDraftEntity, null, mockPersistenceService, objectId, SDMConstants.ScanStatus.SCANNING); + + // Test FAILED -> UPLOAD_STATUS_SCAN_FAILED + dbQuery.updateUploadStatusByScanStatus( + mockDraftEntity, null, mockPersistenceService, objectId, SDMConstants.ScanStatus.FAILED); + + // Test CLEAN -> UPLOAD_STATUS_SUCCESS + dbQuery.updateUploadStatusByScanStatus( + mockDraftEntity, null, mockPersistenceService, objectId, SDMConstants.ScanStatus.CLEAN); + + // Test BLANK -> UPLOAD_STATUS_SUCCESS + dbQuery.updateUploadStatusByScanStatus( + mockDraftEntity, null, mockPersistenceService, objectId, SDMConstants.ScanStatus.BLANK); + + // Verify all updates were called + verify(mockPersistenceService, times(6)).run(any(CqnUpdate.class)); + } + @Test void testGetAttachmentsForUPID_WithIsActiveEntity() { String upID = "testUpID"; From ec5f67a4b9f870172c96ba10dfdb62d2a67a7af6 Mon Sep 17 00:00:00 2001 From: PujaDeshmukh17 Date: Thu, 13 Aug 2026 11:06:31 +0530 Subject: [PATCH 5/5] spotless --- .../main/java/com/sap/cds/sdm/persistence/DBQuery.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java b/sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java index bcb53a4f3..490df8902 100644 --- a/sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java +++ b/sdm/src/main/java/com/sap/cds/sdm/persistence/DBQuery.java @@ -383,8 +383,7 @@ public Result getAttachmentsForUPIDAndRepository( SDMConstants.REPOSITORY_ID, attachmentEntity.getQualifiedName()); List columns = - new ArrayList<>( - java.util.Arrays.asList("fileName", "ID", "folderId", "repositoryId")); + new ArrayList<>(java.util.Arrays.asList("fileName", "ID", "folderId", "repositoryId")); if (attachmentEntity.findElement("IsActiveEntity").isPresent()) { columns.add("IsActiveEntity"); } @@ -491,7 +490,8 @@ public List getAttachmentsForFolder( List cmisDocuments = new ArrayList<>(); List draftColumns = new ArrayList<>( - java.util.Arrays.asList("fileName", "ID", "folderId", "repositoryId", "objectId", "uploadStatus")); + java.util.Arrays.asList( + "fileName", "ID", "folderId", "repositoryId", "objectId", "uploadStatus")); if (attachmentEntity.isPresent() && attachmentEntity.get().findElement("IsActiveEntity").isPresent()) { draftColumns.add("IsActiveEntity"); @@ -522,7 +522,8 @@ public List getAttachmentsForFolder( attachmentEntity = context.getModel().findEntity(entity); List activeColumns = new ArrayList<>( - java.util.Arrays.asList("fileName", "ID", "folderId", "repositoryId", "objectId", "uploadStatus")); + java.util.Arrays.asList( + "fileName", "ID", "folderId", "repositoryId", "objectId", "uploadStatus")); if (attachmentEntity.isPresent() && attachmentEntity.get().findElement("IsActiveEntity").isPresent()) { activeColumns.add("IsActiveEntity");