From e8253e008868fc670940cffc0330cf71731ab29b Mon Sep 17 00:00:00 2001 From: PujaDeshmukh17 Date: Tue, 8 Sep 2026 11:21:26 +0530 Subject: [PATCH 1/4] Fix for non draft issue --- pom.xml | 2 +- .../SDMReadAttachmentsHandler.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 43e0f514..ae1735a1 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ - 1.10.3.1-SNAPSHOT + 1.10.3.2-SNAPSHOT 21 ${java.version} ${java.version} diff --git a/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java b/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java index c203f9a8..5a77a7ec 100644 --- a/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java +++ b/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java @@ -147,6 +147,21 @@ public void processBefore(CdsReadEventContext context) throws IOException { repoValue.getIsAsyncVirusScanEnabled()); Optional attachmentDraftEntity = context.getModel().findEntity(context.getTarget().getQualifiedName() + "_drafts"); + logger.debug( + "Draft entity: {}", + attachmentDraftEntity.isPresent() + ? attachmentDraftEntity.get().getQualifiedName() + : "No draft entity"); + Optional attachmentActiveEntity = + context.getModel().findEntity(context.getTarget().getQualifiedName()); + logger.debug( + "Active entity: {}", + attachmentActiveEntity.isPresent() + ? attachmentActiveEntity.get().getQualifiedName() + : "No active entity"); + if (attachmentDraftEntity.isEmpty() && attachmentActiveEntity.isPresent()) { + attachmentDraftEntity = attachmentActiveEntity; + } String upIdKey = "", upID = ""; if (attachmentDraftEntity.isPresent()) { upIdKey = SDMUtils.getUpIdKey(attachmentDraftEntity.get()); From 71a10ccef3921ed542e9dff4eca6529ea538cc06 Mon Sep 17 00:00:00 2001 From: PujaDeshmukh17 Date: Tue, 8 Sep 2026 13:36:38 +0530 Subject: [PATCH 2/4] Adding check for active entity --- .../SDMReadAttachmentsHandler.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java b/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java index 5a77a7ec..b58dcd6b 100644 --- a/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java +++ b/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java @@ -145,13 +145,6 @@ public void processBefore(CdsReadEventContext context) throws IOException { logger.debug( "Repository value found. Async virus scan enabled: {}", repoValue.getIsAsyncVirusScanEnabled()); - Optional attachmentDraftEntity = - context.getModel().findEntity(context.getTarget().getQualifiedName() + "_drafts"); - logger.debug( - "Draft entity: {}", - attachmentDraftEntity.isPresent() - ? attachmentDraftEntity.get().getQualifiedName() - : "No draft entity"); Optional attachmentActiveEntity = context.getModel().findEntity(context.getTarget().getQualifiedName()); logger.debug( @@ -159,9 +152,16 @@ public void processBefore(CdsReadEventContext context) throws IOException { attachmentActiveEntity.isPresent() ? attachmentActiveEntity.get().getQualifiedName() : "No active entity"); - if (attachmentDraftEntity.isEmpty() && attachmentActiveEntity.isPresent()) { - attachmentDraftEntity = attachmentActiveEntity; - } + Optional attachmentDraftEntity = + context + .getModel() + .findEntity(context.getTarget().getQualifiedName() + "_drafts") + .or(() -> attachmentActiveEntity); + logger.debug( + "Draft entity: {}", + attachmentDraftEntity.isPresent() + ? attachmentDraftEntity.get().getQualifiedName() + : "No draft entity"); String upIdKey = "", upID = ""; if (attachmentDraftEntity.isPresent()) { upIdKey = SDMUtils.getUpIdKey(attachmentDraftEntity.get()); From 25e9b53191c95f558764084c9d77823c8b736f95 Mon Sep 17 00:00:00 2001 From: PujaDeshmukh17 Date: Tue, 8 Sep 2026 13:45:13 +0530 Subject: [PATCH 3/4] sonar fix --- .../SDMReadAttachmentsHandler.java | 195 +++++++++--------- 1 file changed, 97 insertions(+), 98 deletions(-) diff --git a/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java b/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java index b58dcd6b..0365f926 100644 --- a/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java +++ b/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java @@ -133,110 +133,109 @@ public void processBefore(CdsReadEventContext context) throws IOException { return; } setErrorMessagesInCache(context); - if (SDMApplicationHandlerHelper.isMediaEntity(context.getTarget())) { - try { - // update the uploadStatus of all blank attachments with success this is for existing - // attachments - logger.debug("Target is a media entity, processing attachment logic"); - RepoValue repoValue = checkRepositoryTypeWithFallback(repositoryId, context); - - // Only process virus scan logic if repository info is available - if (repoValue != null) { - logger.debug( - "Repository value found. Async virus scan enabled: {}", - repoValue.getIsAsyncVirusScanEnabled()); - Optional attachmentActiveEntity = - context.getModel().findEntity(context.getTarget().getQualifiedName()); - logger.debug( - "Active entity: {}", - attachmentActiveEntity.isPresent() - ? attachmentActiveEntity.get().getQualifiedName() - : "No active entity"); - Optional attachmentDraftEntity = - context - .getModel() - .findEntity(context.getTarget().getQualifiedName() + "_drafts") - .or(() -> attachmentActiveEntity); - logger.debug( - "Draft entity: {}", - attachmentDraftEntity.isPresent() - ? attachmentDraftEntity.get().getQualifiedName() - : "No draft entity"); - String upIdKey = "", upID = ""; - if (attachmentDraftEntity.isPresent()) { - upIdKey = SDMUtils.getUpIdKey(attachmentDraftEntity.get()); - CqnSelect select = (CqnSelect) context.get("cqn"); - upID = SDMUtils.fetchUPIDFromCQN(select, attachmentDraftEntity.get()); - logger.debug("Processing attachments for upID: {}", upID); - - if (!repoValue.getIsAsyncVirusScanEnabled()) { - logger.debug("Sync virus scan mode: updating in-progress upload status to success"); - dbQuery.updateInProgressUploadStatusToSuccess( - attachmentDraftEntity.get(), persistenceService, upID, upIdKey); - } - if (repoValue.getIsAsyncVirusScanEnabled()) { - logger.debug("Async virus scan mode: processing virus scan in-progress attachments"); - processVirusScanInProgressAttachments(context, upID, upIdKey); - } - } - - // Get attachment associations to handle deep reads with expand - CdsModel cdsModel = context.getModel(); - List fieldNames = - getAttachmentAssociations(cdsModel, context.getTarget(), "", new ArrayList<>()); - logger.debug("Found {} attachment associations", fieldNames.size()); - - // Create a combined modifier that handles both expand scenarios and repositoryId filter - final SDMBeforeReadItemsModifier itemsModifier = - new SDMBeforeReadItemsModifier(fieldNames); - final Predicate repositoryFilter = - CQL.or(CQL.get("repositoryId").eq(repositoryId), CQL.get("repositoryId").isNull()); - logger.debug( - "Creating CQN modifier with {} field names and repository filter", fieldNames.size()); - - CqnSelect modifiedCqn = - CQL.copy( - context.getCqn(), - new Modifier() { - @SuppressWarnings({"rawtypes", "unchecked"}) - @Override - public List items(List items) { - // Always handle items for expand scenarios - return itemsModifier.items(items); - } - - @Override - public Predicate where(Predicate where) { - // Always apply repositoryId filter for all reads - if (where == null) { - return repositoryFilter; - } - return CQL.and(where, repositoryFilter); - } - }); - context.setCqn(modifiedCqn); - logger.debug("CQN query modified with repository filter and required fields"); - } else { - logger.warn( - "Repository value is null for repository ID: {}. Proceeding with limited functionality", - repositoryId); - context.setCqn(context.getCqn()); - } - } catch (Exception e) { - logger.error("Error in SDMReadAttachmentsHandler.processBefore: {}", e.getMessage(), e); - // Re-throw to maintain error handling behavior - throw e; - } - - } else { + if (!SDMApplicationHandlerHelper.isMediaEntity(context.getTarget())) { logger.debug( "Target entity {} is not a media entity, skipping attachment processing", context.getTarget().getQualifiedName()); - context.setCqn(context.getCqn()); + return; + } + try { + logger.debug("Target is a media entity, processing attachment logic"); + RepoValue repoValue = checkRepositoryTypeWithFallback(repositoryId, context); + if (repoValue != null) { + processMediaEntityRead(context, repositoryId, repoValue); + } else { + logger.warn( + "Repository value is null for repository ID: {}. Proceeding with limited functionality", + repositoryId); + } + } catch (Exception e) { + logger.error("Error in SDMReadAttachmentsHandler.processBefore: {}", e.getMessage(), e); + throw e; } logger.debug("END: Read attachments processing completed"); } + private void processMediaEntityRead( + CdsReadEventContext context, String repositoryId, RepoValue repoValue) { + logger.debug( + "Repository value found. Async virus scan enabled: {}", + repoValue.getIsAsyncVirusScanEnabled()); + Optional attachmentActiveEntity = + context.getModel().findEntity(context.getTarget().getQualifiedName()); + logger.debug( + "Active entity: {}", + attachmentActiveEntity.isPresent() + ? attachmentActiveEntity.get().getQualifiedName() + : "No active entity"); + Optional attachmentDraftEntity = + context + .getModel() + .findEntity(context.getTarget().getQualifiedName() + "_drafts") + .or(() -> attachmentActiveEntity); + logger.debug( + "Draft entity: {}", + attachmentDraftEntity.isPresent() + ? attachmentDraftEntity.get().getQualifiedName() + : "No draft entity"); + + if (attachmentDraftEntity.isPresent()) { + processUploadStatus(context, repoValue, attachmentDraftEntity.get()); + } + + List fieldNames = + getAttachmentAssociations( + context.getModel(), context.getTarget(), "", new ArrayList<>()); + logger.debug("Found {} attachment associations", fieldNames.size()); + + CqnSelect modifiedCqn = buildModifiedCqn(context, repositoryId, fieldNames); + context.setCqn(modifiedCqn); + logger.debug("CQN query modified with repository filter and required fields"); + } + + private void processUploadStatus( + CdsReadEventContext context, RepoValue repoValue, CdsEntity attachmentEntity) { + String upIdKey = SDMUtils.getUpIdKey(attachmentEntity); + CqnSelect select = (CqnSelect) context.get("cqn"); + String upID = SDMUtils.fetchUPIDFromCQN(select, attachmentEntity); + logger.debug("Processing attachments for upID: {}", upID); + + if (!repoValue.getIsAsyncVirusScanEnabled()) { + logger.debug("Sync virus scan mode: updating in-progress upload status to success"); + dbQuery.updateInProgressUploadStatusToSuccess( + attachmentEntity, persistenceService, upID, upIdKey); + } else { + logger.debug("Async virus scan mode: processing virus scan in-progress attachments"); + processVirusScanInProgressAttachments(context, upID, upIdKey); + } + } + + private CqnSelect buildModifiedCqn( + CdsReadEventContext context, String repositoryId, List fieldNames) { + final SDMBeforeReadItemsModifier itemsModifier = new SDMBeforeReadItemsModifier(fieldNames); + final Predicate repositoryFilter = + CQL.or(CQL.get("repositoryId").eq(repositoryId), CQL.get("repositoryId").isNull()); + logger.debug( + "Creating CQN modifier with {} field names and repository filter", fieldNames.size()); + return CQL.copy( + context.getCqn(), + new Modifier() { + @SuppressWarnings({"rawtypes", "unchecked"}) + @Override + public List items(List items) { + return itemsModifier.items(items); + } + + @Override + public Predicate where(Predicate where) { + if (where == null) { + return repositoryFilter; + } + return CQL.and(where, repositoryFilter); + } + }); + } + /** * Recursively get all attachment associations in the entity tree. This is needed to properly * handle deep navigation like Books/covers with $expand=statusNav @@ -734,4 +733,4 @@ private static final class FacetInfo { this.maxCount = maxCount; } } -} +} \ No newline at end of file From af1474f83379f0a0d29a56a89dc14a0f8fb763e0 Mon Sep 17 00:00:00 2001 From: PujaDeshmukh17 Date: Tue, 8 Sep 2026 13:50:13 +0530 Subject: [PATCH 4/4] spotless --- .../applicationservice/SDMReadAttachmentsHandler.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java b/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java index 0365f926..8c515765 100644 --- a/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java +++ b/sdm/src/main/java/com/sap/cds/sdm/handler/applicationservice/SDMReadAttachmentsHandler.java @@ -184,8 +184,7 @@ private void processMediaEntityRead( } List fieldNames = - getAttachmentAssociations( - context.getModel(), context.getTarget(), "", new ArrayList<>()); + getAttachmentAssociations(context.getModel(), context.getTarget(), "", new ArrayList<>()); logger.debug("Found {} attachment associations", fieldNames.size()); CqnSelect modifiedCqn = buildModifiedCqn(context, repositoryId, fieldNames); @@ -733,4 +732,4 @@ private static final class FacetInfo { this.maxCount = maxCount; } } -} \ No newline at end of file +}