Pinchez25 opened a new pull request, #4511:
URL: https://github.com/apache/fineract/pull/4511

   ## PR: Fix SMS Message Triggered Flow - Ensure Consistent ID Generation
   
   ### Problem
   In the current implementation, `SmsMessageApiQueueResourceData` is being 
created before the `SmsMessage` is saved to the database. This leads to a 
critical issue where `smsMessage.getId()` returns null when attempting to 
create queue data for triggered messages.
   
   ### Root Cause
   - Messages were being processed before being persisted to the database
   - No guarantee of database-generated IDs being available
   - Inconsistent handling between direct and triggered message flows
   
   ### Solution
   Modify the `sendTriggeredMessages` method in 
`SmsMessageScheduledJobServiceImpl` to:
   1. Save all SMS messages to the database first
   2. Flush the database to ensure ID generation
   3. Create queue data using the newly generated message IDs
   4. Maintain existing logic for notification messages
   
   ### Key Changes
   - Added a two-step process for message handling
   - Explicitly save and flush messages before creating queue data
   - Ensure queue data is created with valid database-generated IDs
   
   ### Benefits
   - Resolves ID generation inconsistency
   - Prevents null ID issues in triggered message processing
   - Maintains existing message sending and notification logic
   
   ### Testing
   - Verify triggered messages are saved with correct IDs
   - Confirm queue data creation works consistently
   - Ensure no regression in existing message sending flows
   
   ### Code Diff Highlights
   ```java
   // Save messages first to get IDs
   if (!toSaveMessages.isEmpty()) {
       this.smsMessageRepository.saveAll(toSaveMessages);
       this.smsMessageRepository.flush();
       
       // Now create queue data with saved message IDs
       for (Map.Entry<SmsCampaign, Collection<SmsMessage>> entry : 
smsDataMap.entrySet()) {
           Collection<SmsMessageApiQueueResourceData> apiQueueResourceDatas = 
new ArrayList<>();
           for (SmsMessage smsMessage : entry.getValue()) {
               if (!smsMessage.isNotification()) {
                   SmsMessageApiQueueResourceData apiQueueResourceData = 
SmsMessageApiQueueResourceData.instance(
                       smsMessage.getId(), null, null, null, 
smsMessage.getMobileNo(), 
                       smsMessage.getMessage(), entry.getKey().getProviderId());
                   apiQueueResourceDatas.add(apiQueueResourceData);
               }
           }
           // ... rest of the implementation
       }
   }
   ```
   
   ### Additional Notes
   - No breaking changes expected
   - Minimal impact on existing system architecture


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to