@@ -53,75 +53,98 @@ public SDMCreateAttachmentsHandler(
5353 @ Before
5454 @ HandlerOrder (HandlerOrder .EARLY )
5555 public void processBefore (CdsCreateEventContext context , List <CdsData > data ) throws IOException {
56- // Get the combined mapping of attachment composition paths and names
57- Map <String , String > compositionPathMapping =
58- AttachmentsHandlerUtils .getAttachmentPathMapping (
59- context .getModel (), context .getTarget (), persistenceService );
60- logger .info ("Attachment compositions present in CDS Model : " + compositionPathMapping );
61- for (Map .Entry <String , String > entry : compositionPathMapping .entrySet ()) {
62- String attachmentCompositionDefinition = entry .getKey ();
63- String attachmentCompositionName = entry .getValue ();
64- updateName (context , data , attachmentCompositionDefinition , attachmentCompositionName );
56+ // Get comprehensive attachment composition details for each entity
57+ for (CdsData entityData : data ) {
58+ Map <String , Map <String , String >> attachmentCompositionDetails =
59+ AttachmentsHandlerUtils .getAttachmentCompositionDetails (
60+ context .getModel (),
61+ context .getTarget (),
62+ persistenceService ,
63+ context .getTarget ().getQualifiedName (),
64+ entityData );
65+ logger .info ("Attachment compositions present in CDS Model : " + attachmentCompositionDetails );
66+
67+ updateName (context , data , attachmentCompositionDetails );
6568 }
6669 }
6770
6871 public void updateName (
6972 CdsCreateEventContext context ,
7073 List <CdsData > data ,
71- String attachmentCompositionDefinition ,
72- String attachmentCompositionName )
74+ Map <String , Map <String , String >> attachmentCompositionDetails )
7375 throws IOException {
74- Map <String , String > propertyTitles = new HashMap <>();
75- Map <String , String > secondaryPropertiesWithInvalidDefinitions = new HashMap <>();
76- String targetEntity = context .getTarget ().getQualifiedName ();
77- Boolean isError = false ;
78- isError = AttachmentsHandlerUtils .validateFileNames (context , data , attachmentCompositionName );
79- if (!isError ) {
80- List <String > fileNameWithRestrictedCharacters = new ArrayList <>();
81- List <String > duplicateFileNameList = new ArrayList <>();
82- List <String > filesNotFound = new ArrayList <>();
83- List <String > filesWithUnsupportedProperties = new ArrayList <>();
84- Map <String , String > badRequest = new HashMap <>();
85- List <String > noSDMRoles = new ArrayList <>();
86- for (Map <String , Object > entity : data ) {
87- List <Map <String , Object >> attachments =
88- AttachmentsHandlerUtils .fetchAttachments (
89- targetEntity , entity , attachmentCompositionName );
90- if (attachments == null || attachments .isEmpty ()) {
91- logger .info (
92- "No attachments found for composition [{}] in entity [{}]. Skipping processing." ,
93- attachmentCompositionName ,
94- targetEntity );
95- continue ;
76+ for (Map .Entry <String , Map <String , String >> entry : attachmentCompositionDetails .entrySet ()) {
77+ String attachmentCompositionDefinition = entry .getKey ();
78+ String attachmentCompositionName = entry .getValue ().get ("name" );
79+ String parentTitle = entry .getValue ().get ("parentTitle" );
80+ Map <String , String > propertyTitles = new HashMap <>();
81+ Map <String , String > secondaryPropertiesWithInvalidDefinitions = new HashMap <>();
82+ String targetEntity = context .getTarget ().getQualifiedName ();
83+ Boolean isError = false ;
84+
85+ // Extract composition name (last part after the final ".")
86+ String compositionName = attachmentCompositionName ;
87+ if (attachmentCompositionName != null && attachmentCompositionName .contains ("." )) {
88+ String [] parts = attachmentCompositionName .split ("\\ ." );
89+ compositionName = parts [parts .length - 1 ];
90+ }
91+ String contextInfo =
92+ "\n \n Table: "
93+ + compositionName
94+ + "\n Page: "
95+ + (parentTitle != null ? parentTitle : "Unknown" );
96+
97+ isError =
98+ AttachmentsHandlerUtils .validateFileNames (
99+ context , data , attachmentCompositionName , contextInfo );
100+ if (!isError ) {
101+ List <String > fileNameWithRestrictedCharacters = new ArrayList <>();
102+ List <String > duplicateFileNameList = new ArrayList <>();
103+ List <String > filesNotFound = new ArrayList <>();
104+ List <String > filesWithUnsupportedProperties = new ArrayList <>();
105+ Map <String , String > badRequest = new HashMap <>();
106+ List <String > noSDMRoles = new ArrayList <>();
107+ for (Map <String , Object > entity : data ) {
108+ List <Map <String , Object >> attachments =
109+ AttachmentsHandlerUtils .fetchAttachments (
110+ targetEntity , entity , attachmentCompositionName );
111+ if (attachments == null || attachments .isEmpty ()) {
112+ logger .info (
113+ "No attachments found for composition [{}] in entity [{}]. Skipping processing." ,
114+ attachmentCompositionName ,
115+ targetEntity );
116+ continue ;
117+ }
118+ Optional <CdsEntity > attachmentEntity =
119+ context .getModel ().findEntity (attachmentCompositionDefinition );
120+ propertyTitles = SDMUtils .getPropertyTitles (attachmentEntity , attachments .get (0 ));
121+ secondaryPropertiesWithInvalidDefinitions =
122+ SDMUtils .getSecondaryPropertiesWithInvalidDefinition (
123+ attachmentEntity , attachments .get (0 ));
124+ processEntity (
125+ context ,
126+ entity ,
127+ fileNameWithRestrictedCharacters ,
128+ duplicateFileNameList ,
129+ filesNotFound ,
130+ filesWithUnsupportedProperties ,
131+ badRequest ,
132+ attachmentCompositionDefinition ,
133+ attachmentEntity ,
134+ secondaryPropertiesWithInvalidDefinitions ,
135+ noSDMRoles ,
136+ attachmentCompositionName );
137+ handleWarnings (
138+ context ,
139+ fileNameWithRestrictedCharacters ,
140+ duplicateFileNameList ,
141+ filesNotFound ,
142+ filesWithUnsupportedProperties ,
143+ badRequest ,
144+ propertyTitles ,
145+ noSDMRoles ,
146+ contextInfo );
96147 }
97- Optional <CdsEntity > attachmentEntity =
98- context .getModel ().findEntity (attachmentCompositionDefinition );
99- propertyTitles = SDMUtils .getPropertyTitles (attachmentEntity , attachments .get (0 ));
100- secondaryPropertiesWithInvalidDefinitions =
101- SDMUtils .getSecondaryPropertiesWithInvalidDefinition (
102- attachmentEntity , attachments .get (0 ));
103- processEntity (
104- context ,
105- entity ,
106- fileNameWithRestrictedCharacters ,
107- duplicateFileNameList ,
108- filesNotFound ,
109- filesWithUnsupportedProperties ,
110- badRequest ,
111- attachmentCompositionDefinition ,
112- attachmentEntity ,
113- secondaryPropertiesWithInvalidDefinitions ,
114- noSDMRoles ,
115- attachmentCompositionName );
116- handleWarnings (
117- context ,
118- fileNameWithRestrictedCharacters ,
119- duplicateFileNameList ,
120- filesNotFound ,
121- filesWithUnsupportedProperties ,
122- badRequest ,
123- propertyTitles ,
124- noSDMRoles );
125148 }
126149 }
127150 }
@@ -306,19 +329,22 @@ private void handleWarnings(
306329 List <String > filesWithUnsupportedProperties ,
307330 Map <String , String > badRequest ,
308331 Map <String , String > propertyTitles ,
309- List <String > noSDMRoles ) {
332+ List <String > noSDMRoles ,
333+ String contextInfo ) {
310334 if (!fileNameWithRestrictedCharacters .isEmpty ()) {
311335 context
312336 .getMessages ()
313- .warn (SDMConstants .nameConstraintMessage (fileNameWithRestrictedCharacters ));
337+ .warn (SDMConstants .nameConstraintMessage (fileNameWithRestrictedCharacters ) + contextInfo );
314338 }
315339 if (!duplicateFileNameList .isEmpty ()) {
316340 context
317341 .getMessages ()
318- .warn (String .format (SDMConstants .duplicateFilenameFormat (duplicateFileNameList )));
342+ .warn (
343+ String .format (SDMConstants .duplicateFilenameFormat (duplicateFileNameList ))
344+ + contextInfo );
319345 }
320346 if (!filesNotFound .isEmpty ()) {
321- context .getMessages ().warn (SDMConstants .fileNotFound (filesNotFound ));
347+ context .getMessages ().warn (SDMConstants .fileNotFound (filesNotFound ) + contextInfo );
322348 }
323349 if (!filesWithUnsupportedProperties .isEmpty ()) {
324350 List <String > invalidPropertyNames = new ArrayList <>();
@@ -334,15 +360,19 @@ private void handleWarnings(
334360 invalidPropertyNames .add (propertyTitles .get (file ));
335361 }
336362 if (!invalidPropertyNames .isEmpty ()) {
337- context .getMessages ().warn (SDMConstants .unsupportedPropertiesMessage (invalidPropertyNames ));
363+ context
364+ .getMessages ()
365+ .warn (SDMConstants .unsupportedPropertiesMessage (invalidPropertyNames ) + contextInfo );
338366 }
339367 }
340368
341369 if (!badRequest .isEmpty ()) {
342- context .getMessages ().warn (SDMConstants .badRequestMessage (badRequest ));
370+ context .getMessages ().warn (SDMConstants .badRequestMessage (badRequest ) + contextInfo );
343371 }
344372 if (!noSDMRoles .isEmpty ()) {
345- context .getMessages ().warn (SDMConstants .noSDMRolesMessage (noSDMRoles , "create" ));
373+ context
374+ .getMessages ()
375+ .warn (SDMConstants .noSDMRolesMessage (noSDMRoles , "create" ) + contextInfo );
346376 }
347377 }
348378}
0 commit comments