1313import org .apache .http .entity .StringEntity ;
1414import org .apache .http .impl .client .HttpClientBuilder ;
1515import org .apache .http .util .EntityUtils ;
16+ import org .joda .time .DateTime ;
1617import org .slf4j .Logger ;
1718import org .slf4j .LoggerFactory ;
1819import org .springframework .beans .factory .annotation .Autowired ;
1920import org .springframework .context .annotation .PropertySource ;
2021import org .springframework .stereotype .Service ;
2122
22- import java .io .File ;
23- import java .io . IOException ;
23+ import java .io .* ;
24+ import java .net . URL ;
2425import java .nio .charset .StandardCharsets ;
2526import java .text .ParseException ;
2627import java .text .SimpleDateFormat ;
@@ -40,6 +41,10 @@ public class SmsServiceImpl implements SmsService {
4041 @ Autowired
4142 private FrontLineWorkersDao frontLineWorkersDao ;
4243
44+ public void setMACourseCompletionDao (MACourseCompletionDao maCourseCompletionDao ) {
45+ this .maCourseCompletionDao = maCourseCompletionDao ;
46+ }
47+
4348
4449 private String sms_template_id = getProperty ("sms.templateId.default" );
4550 private String sms_entity_id = getProperty ("sms.entityId.default" );
@@ -119,10 +124,10 @@ public String buildCertificateSMS(CourseCompletionDTO courseCompletionDTO, Strin
119124 try {
120125 phoneNo = courseCompletionDTO .getMobileNumber ();
121126 } catch (NullPointerException e ) {
122- LOGGER .info ("Phone number does not exist for FLW ID: {}" , courseCompletionDTO .getFlwId (), e );
127+ LOGGER .info ("Phone number does not exist for FLW ID: {}" , courseCompletionDTO .getFlwId ());
123128 return null ;
124129 } catch (Exception e ) {
125- LOGGER .error ("Unexpected error while fetching phone number for FLW ID: {}" , courseCompletionDTO .getFlwId (), e );
130+ LOGGER .error ("Unexpected error while fetching phone number for FLW ID: {}" , courseCompletionDTO .getFlwId ());
126131 return null ;
127132 }
128133
@@ -136,7 +141,7 @@ public String buildCertificateSMS(CourseCompletionDTO courseCompletionDTO, Strin
136141 StandardCharsets .UTF_8
137142 );
138143 } catch (IOException e ) {
139- LOGGER .error ("Error reading SMS template file" , e );
144+ LOGGER .error ("Error reading SMS template file" );
140145 return null ;
141146 }
142147
@@ -149,23 +154,26 @@ public String buildCertificateSMS(CourseCompletionDTO courseCompletionDTO, Strin
149154
150155 // Replace placeholders in the template
151156 try {
157+ String messageType = retrieveAshaCourseCompletionMessageType (courseCompletionDTO .getLanguageId ());
152158 template = template
153159 .replace ("<phoneNumber>" , String .valueOf (phoneNo ))
154160 .replace ("<senderId>" , senderId )
155161 .replace ("<messageContent>" , messageContent )
156162 .replace ("<notificationUrl>" , callbackEndpoint )
157163 .replace ("<smsTemplateId>" , sms_template_id )
158164 .replace ("<smsEntityId>" , sms_entity_id )
159- .replace ("<smsTelemarketerId>" , sms_telemarketer_id );
165+ .replace ("<smsTelemarketerId>" , sms_telemarketer_id )
166+ .replace ("<correlationId>" , DateTime .now ().toString ())
167+ .replace ("<messageType>" , messageType );
160168 } catch (Exception e ) {
161- LOGGER .error ("Error replacing placeholders in SMS template" , e );
169+ LOGGER .error ("Error replacing placeholders in SMS template" );
162170 return null ;
163171 }
164172
165173 return template ;
166174 }
167175
168- public String buildOTPSMS (MACourseFirstCompletion maCourseFirstCompletion , String messageContent ) {
176+ public String buildOTPSMS (MACourseFirstCompletion maCourseFirstCompletion , String messageContent , long languageId ) {
169177 long phoneNumber ;
170178 String template = null ;
171179
@@ -175,7 +183,7 @@ public String buildOTPSMS(MACourseFirstCompletion maCourseFirstCompletion, Strin
175183 try {
176184 phoneNumber = maCourseCompletionDao .getAshaPhoneNo (maCourseFirstCompletion .getFlwId ());
177185 } catch (NullPointerException e ) {
178- LOGGER .error ("Phone number not found for FLW ID: {}" , maCourseFirstCompletion .getFlwId (), e );
186+ LOGGER .error ("Phone number not found for FLW ID: {}" , maCourseFirstCompletion .getFlwId ());
179187 return null ;
180188 }
181189
@@ -189,22 +197,25 @@ public String buildOTPSMS(MACourseFirstCompletion maCourseFirstCompletion, Strin
189197 StandardCharsets .UTF_8
190198 );
191199 } catch (IOException e ) {
192- LOGGER .error ("Error reading SMS template file." , e );
200+ LOGGER .error ("Error reading SMS template file" );
193201 return null ;
194202 }
195203
196204 // Populate SMS template
197205 try {
198206 String callbackEndpoint = retrieveAshaSMSCallBackEndPoint ("OTP" );
207+ String messageType = retrieveAshaCourseCompletionMessageType (languageId );
199208 template = template .replace ("<phoneNumber>" , String .valueOf (phoneNumber ))
200209 .replace ("<senderId>" , senderId )
201210 .replace ("<messageContent>" , messageContent )
202211 .replace ("<notificationUrl>" , callbackEndpoint )
203212 .replace ("<smsTemplateId>" , sms_template_id )
204213 .replace ("<smsEntityId>" , sms_entity_id )
205- .replace ("<smsTelemarketerId>" , sms_telemarketer_id );
214+ .replace ("<smsTelemarketerId>" , sms_telemarketer_id )
215+ .replace ("<correlationId>" , DateTime .now ().toString ())
216+ .replace ("<messageType>" , messageType );
206217 } catch (Exception e ) {
207- LOGGER .error ("Error populating SMS template." , e );
218+ LOGGER .error ("Error populating SMS template." );
208219 return null ;
209220 }
210221
0 commit comments