@@ -73,7 +73,11 @@ def _build_rs_ri_from_cisu(cls, edxl_json: Dict[str, Any]) -> Dict[str, Any]:
7373
7474 @classmethod
7575 def _build_rs_sr_from_resource (
76- cls , edxl_json : Dict [str , Any ], resource : Dict [str , Any ], case_id : str
76+ cls ,
77+ edxl_json : Dict [str , Any ],
78+ resource : Dict [str , Any ],
79+ case_id : str ,
80+ replacement_distribution_id : str | None = None ,
7781 ) -> Dict [str , Any ]:
7882 """Build an RS-SR from a single RC-RI resource, reusing the EDXL envelope."""
7983 logger .info (
@@ -83,8 +87,9 @@ def _build_rs_sr_from_resource(
8387 )
8488 output_json = cls .copy_cisu_input_content (edxl_json )
8589
86- # Set a new distributionID for the RS-SR message
87- cls .set_distribution_id (output_json , f"{ edxl_json ['senderID' ]} _{ uuid .uuid4 ()} " )
90+ if replacement_distribution_id is not None :
91+ # Set a new distributionID for the RS-SR message
92+ cls .set_distribution_id (output_json , replacement_distribution_id )
8893
8994 output_use_case_json = {
9095 "caseId" : case_id ,
@@ -173,7 +178,12 @@ def from_cisu_to_rs(cls, edxl_json: Dict[str, Any]) -> List[Dict[str, Any]]:
173178 converted_messages = [cls ._build_rs_ri_from_cisu (edxl_json )]
174179 for resource in resources :
175180 converted_messages .append (
176- cls ._build_rs_sr_from_resource (edxl_json , resource , case_id )
181+ cls ._build_rs_sr_from_resource (
182+ edxl_json ,
183+ resource ,
184+ case_id ,
185+ f"{ edxl_json ['senderID' ]} _{ uuid .uuid4 ()} " ,
186+ )
177187 )
178188 return converted_messages
179189
@@ -200,12 +210,22 @@ def from_cisu_to_rs(cls, edxl_json: Dict[str, Any]) -> List[Dict[str, Any]]:
200210 rs_ri = cls ._build_rs_ri_from_cisu (edxl_json )
201211 messages .append (rs_ri )
202212
203- for resource in modified_status_resources :
213+ for idx , resource in enumerate ( modified_status_resources ) :
204214 logger .info (
205215 "Resource %s has a modified status — adding RS-SR to output." ,
206216 resource .get ("resourceId" ),
207217 )
208- rs_sr = cls ._build_rs_sr_from_resource (edxl_json , resource , case_id )
218+ should_not_use_original_distribution_id = (
219+ engaged_resources_updated is True or idx != 0
220+ )
221+ replacement_distribution_id = (
222+ f"{ edxl_json ['senderID' ]} _{ uuid .uuid4 ()} "
223+ if should_not_use_original_distribution_id
224+ else None
225+ )
226+ rs_sr = cls ._build_rs_sr_from_resource (
227+ edxl_json , resource , case_id , replacement_distribution_id
228+ )
209229 messages .append (rs_sr )
210230
211231 if not messages :
0 commit comments