@@ -114,67 +114,77 @@ private void setErrorMessagesInCache(CdsReadEventContext context) {
114114 @ HandlerOrder (HandlerOrder .EARLY + 500 )
115115 public void processBefore (CdsReadEventContext context ) throws IOException {
116116 String repositoryId = SDMConstants .REPOSITORY_ID ;
117+ if (repositoryId == null ) {
118+ return ;
119+ }
120+ setErrorMessagesInCache (context );
117121 if (context .getTarget ().getAnnotationValue (SDMConstants .ANNOTATION_IS_MEDIA_DATA , false )) {
118122 try {
119123 // update the uploadStatus of all blank attachments with success this is for existing
120124 // attachments
121- RepoValue repoValue =
122- sdmService .checkRepositoryType (repositoryId , context .getUserInfo ().getTenant ());
123- Optional <CdsEntity > attachmentDraftEntity =
124- context .getModel ().findEntity (context .getTarget ().getQualifiedName () + "_drafts" );
125- String upIdKey = "" , upID = "" ;
126- if (attachmentDraftEntity .isPresent ()) {
127- upIdKey = SDMUtils .getUpIdKey (attachmentDraftEntity .get ());
128- CqnSelect select = (CqnSelect ) context .get ("cqn" );
129- upID = SDMUtils .fetchUPIDFromCQN (select , attachmentDraftEntity .get ());
130-
131- if (!repoValue .getIsAsyncVirusScanEnabled ()) {
132-
133- dbQuery .updateInProgressUploadStatusToSuccess (
134- attachmentDraftEntity .get (), persistenceService , upID , upIdKey );
135- }
136- if (repoValue .getIsAsyncVirusScanEnabled ()) {
137- processVirusScanInProgressAttachments (context , upID , upIdKey );
125+ RepoValue repoValue = checkRepositoryTypeWithFallback (repositoryId , context );
126+
127+ // Only process virus scan logic if repository info is available
128+ if (repoValue != null ) {
129+ Optional <CdsEntity > attachmentDraftEntity =
130+ context .getModel ().findEntity (context .getTarget ().getQualifiedName () + "_drafts" );
131+ String upIdKey = "" , upID = "" ;
132+ if (attachmentDraftEntity .isPresent ()) {
133+ upIdKey = SDMUtils .getUpIdKey (attachmentDraftEntity .get ());
134+ CqnSelect select = (CqnSelect ) context .get ("cqn" );
135+ upID = SDMUtils .fetchUPIDFromCQN (select , attachmentDraftEntity .get ());
136+
137+ if (!repoValue .getIsAsyncVirusScanEnabled ()) {
138+
139+ dbQuery .updateInProgressUploadStatusToSuccess (
140+ attachmentDraftEntity .get (), persistenceService , upID , upIdKey );
141+ }
142+ if (repoValue .getIsAsyncVirusScanEnabled ()) {
143+ processVirusScanInProgressAttachments (context , upID , upIdKey );
144+ }
138145 }
139- }
140146
141- // Get attachment associations to handle deep reads with expand
142- CdsModel cdsModel = context .getModel ();
143- List <String > fieldNames =
144- getAttachmentAssociations (cdsModel , context .getTarget (), "" , new ArrayList <>());
145-
146- // Create a combined modifier that handles both expand scenarios and repositoryId filter
147- final SDMBeforeReadItemsModifier itemsModifier = new SDMBeforeReadItemsModifier (fieldNames );
148- final Predicate repositoryFilter =
149- CQL .or (CQL .get ("repositoryId" ).eq (repositoryId ), CQL .get ("repositoryId" ).isNull ());
150-
151- CqnSelect modifiedCqn =
152- CQL .copy (
153- context .getCqn (),
154- new Modifier () {
155- @ SuppressWarnings ({"rawtypes" , "unchecked" })
156- @ Override
157- public List items (List items ) {
158- // Always handle items for expand scenarios
159- return itemsModifier .items (items );
160- }
161-
162- @ Override
163- public Predicate where (Predicate where ) {
164- // Always apply repositoryId filter for all reads
165- if (where == null ) {
166- return repositoryFilter ;
147+ // Get attachment associations to handle deep reads with expand
148+ CdsModel cdsModel = context .getModel ();
149+ List <String > fieldNames =
150+ getAttachmentAssociations (cdsModel , context .getTarget (), "" , new ArrayList <>());
151+
152+ // Create a combined modifier that handles both expand scenarios and repositoryId filter
153+ final SDMBeforeReadItemsModifier itemsModifier =
154+ new SDMBeforeReadItemsModifier (fieldNames );
155+ final Predicate repositoryFilter =
156+ CQL .or (CQL .get ("repositoryId" ).eq (repositoryId ), CQL .get ("repositoryId" ).isNull ());
157+
158+ CqnSelect modifiedCqn =
159+ CQL .copy (
160+ context .getCqn (),
161+ new Modifier () {
162+ @ SuppressWarnings ({"rawtypes" , "unchecked" })
163+ @ Override
164+ public List items (List items ) {
165+ // Always handle items for expand scenarios
166+ return itemsModifier .items (items );
167+ }
168+
169+ @ Override
170+ public Predicate where (Predicate where ) {
171+ // Always apply repositoryId filter for all reads
172+ if (where == null ) {
173+ return repositoryFilter ;
174+ }
175+ return CQL .and (where , repositoryFilter );
167176 }
168- return CQL . and ( where , repositoryFilter );
169- }
170- });
171- setErrorMessagesInCache (context );
172- context . setCqn ( modifiedCqn );
177+ } );
178+ context . setCqn ( modifiedCqn );
179+ } else {
180+ context . setCqn (context . getCqn () );
181+ }
173182 } catch (Exception e ) {
174183 logger .error ("Error in SDMReadAttachmentsHandler.processBefore: {}" , e .getMessage (), e );
175184 // Re-throw to maintain error handling behavior
176185 throw e ;
177186 }
187+
178188 } else {
179189 context .setCqn (context .getCqn ());
180190 }
@@ -340,4 +350,24 @@ private void processAttachmentVirusScanStatus(
340350 e .getMessage ());
341351 }
342352 }
353+
354+ /**
355+ * Checks the repository type with fallback handling. Returns null if the check fails, allowing
356+ * the caller to proceed with limited functionality.
357+ *
358+ * @param repositoryId the repository ID to check
359+ * @param context the CDS read event context containing user information
360+ * @return the RepoValue if successful, null otherwise
361+ */
362+ private RepoValue checkRepositoryTypeWithFallback (
363+ String repositoryId , CdsReadEventContext context ) {
364+ try {
365+ return sdmService .checkRepositoryType (repositoryId , context .getUserInfo ().getTenant ());
366+ } catch (Exception e ) {
367+ logger .warn (
368+ "Failed to check repository type, proceeding without repository info: {}" ,
369+ e .getMessage ());
370+ return null ;
371+ }
372+ }
343373}
0 commit comments