Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
}

@Override
public String save(BeneficiaryModel beneficiaryModel, HttpServletRequest servletRequest) throws Exception {

Check failure on line 190 in src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 24 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ2VVIvUQqbQGjdUulB0&open=AZ2VVIvUQqbQGjdUulB0&pullRequest=396

logger.info("benificiaryDetails: " + beneficiaryModel);

Expand Down Expand Up @@ -223,9 +223,26 @@
} else {
return response.toString();
}
if(beneficiary!=null){
if(beneficiary.getBenPhoneMaps().get(0).getPhoneNo()!=null){
welcomeBenificarySmsService.sendWelcomeSMStoBenificiary(beneficiary.getBenPhoneMaps().get(0).getPhoneNo(),beneficiary.getFirstName()+" "+beneficiary.getLastName(),beneficiary.getBeneficiaryID());
if (beneficiary != null && beneficiary.getBenPhoneMaps() != null && !beneficiary.getBenPhoneMaps().isEmpty()) {
String phoneNo = beneficiary.getBenPhoneMaps().get(0).getPhoneNo();

if (phoneNo != null && !phoneNo.trim().isEmpty()) {
String beneficiaryName = (beneficiary.getFirstName() != null ? beneficiary.getFirstName() : "") + " " +
(beneficiary.getLastName() != null ? beneficiary.getLastName() : "");

try {
logger.info("[SMS] Attempting to send welcome SMS to: " + phoneNo);

Check warning on line 234 in src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the built-in formatting to construct this argument.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ2VVIvUQqbQGjdUulBy&open=AZ2VVIvUQqbQGjdUulBy&pullRequest=396

Check warning on line 234 in src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Format specifiers should be used instead of string concatenation.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ2VVIvUQqbQGjdUulB1&open=AZ2VVIvUQqbQGjdUulB1&pullRequest=396
String smsResult = welcomeBenificarySmsService.sendWelcomeSMStoBenificiary(
phoneNo,
beneficiaryName.trim(),
beneficiary.getBeneficiaryID()
);
logger.info("[SMS] Result: " + smsResult);

Check warning on line 240 in src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Format specifiers should be used instead of string concatenation.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ2VVIvUQqbQGjdUulB2&open=AZ2VVIvUQqbQGjdUulB2&pullRequest=396

Check warning on line 240 in src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the built-in formatting to construct this argument.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ2VVIvUQqbQGjdUulBz&open=AZ2VVIvUQqbQGjdUulBz&pullRequest=396
} catch (Exception smsError) {
// SMS failed but beneficiary is already created - don't fail the request
logger.warn("[SMS] Failed to send SMS: " + smsError.getMessage() +
" - But beneficiary already created successfully");

Check warning on line 244 in src/main/java/com/iemr/common/service/beneficiary/RegisterBenificiaryServiceImpl.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Format specifiers should be used instead of string concatenation.

See more on https://sonarcloud.io/project/issues?id=PSMRI_Common-API&issues=AZ2VVIvUQqbQGjdUulB3&open=AZ2VVIvUQqbQGjdUulB3&pullRequest=396
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

Expand Down Expand Up @@ -46,58 +47,57 @@ public class WelcomeBenificarySmsServiceImpl implements WelcomeBenificarySmsServ

private String smsTemplateName = "welcome_sms";

private String smsTemplate;
private String smsTemplate =null;

@Override
@Async
public String sendWelcomeSMStoBenificiary(String contactNo, String beneficiaryName, String beneficiaryId) {
final RestTemplate restTemplate = new RestTemplate();

Optional<SMSTemplate> smsTemplateData = smsTemplateRepository.findBySmsTemplateName(smsTemplateName);
if (smsTemplateData.isPresent()) {
smsTemplate = smsTemplateRepository.findBySmsTemplateID(smsTemplateData.get().getSmsTemplateID()).getSmsTemplate();

}

logger.info("sms template" + smsTemplate);


String sendSMSAPI = SMS_GATEWAY_URL;

try {
String sendSMSAPI = SMS_GATEWAY_URL;

String message = smsTemplate.replace("$$BENE_NAME$$", beneficiaryName).replace("$$BEN_ID$$", beneficiaryId);
// Build payload
Map<String, Object> payload = new HashMap<>();
payload.put("customerId", smsUserName);
payload.put("destinationAddress", contactNo);
payload.put("message", message);
payload.put("sourceAddress", smsSourceAddress);
payload.put("messageType", "SERVICE_IMPLICIT");
payload.put("dltTemplateId", smsTemplateData.get().getDltTemplateId());
payload.put("entityId", smsEntityId);
// Set headers
HttpHeaders headers = new HttpHeaders();
String auth = smsUserName + ":" + smsPassword;
headers.add("Authorization",
"Basic " + Base64.getEncoder().encodeToString(auth.getBytes()));

headers.setContentType(MediaType.APPLICATION_JSON);
logger.info("payload: " + payload);
HttpEntity<Map<String, Object>> request = new HttpEntity<>(payload, headers);

// Call API
ResponseEntity<String> response = restTemplate.postForEntity(sendSMSAPI, request, String.class);
logger.info("sms-response:" + response.getBody());
if (response.getStatusCode().value() == 200) {
return "OTP sent successfully on register mobile number";
} else {
return "Fail";
final RestTemplate restTemplate = new RestTemplate();

Optional<SMSTemplate> smsTemplateData = smsTemplateRepository.findBySmsTemplateName(smsTemplateName);
if (smsTemplateData.isPresent()) {
smsTemplate = smsTemplateRepository.findBySmsTemplateID(smsTemplateData.get().getSmsTemplateID()).getSmsTemplate();
}
if(smsTemplate!=null){
String message = smsTemplate.replace("$$BENE_NAME$$", beneficiaryName).replace("$$BEN_ID$$", beneficiaryId);
// Build payload
Map<String, Object> payload = new HashMap<>();
payload.put("customerId", smsUserName);
payload.put("destinationAddress", contactNo);
payload.put("message", message);
payload.put("sourceAddress", smsSourceAddress);
payload.put("messageType", "SERVICE_IMPLICIT");
payload.put("dltTemplateId", smsTemplateData.get().getDltTemplateId());
payload.put("entityId", smsEntityId);
// Set headers
HttpHeaders headers = new HttpHeaders();
String auth = smsUserName + ":" + smsPassword;
headers.add("Authorization",
"Basic " + Base64.getEncoder().encodeToString(auth.getBytes()));

headers.setContentType(MediaType.APPLICATION_JSON);
logger.info("payload: " + payload);
HttpEntity<Map<String, Object>> request = new HttpEntity<>(payload, headers);

// Call API
ResponseEntity<String> response = restTemplate.postForEntity(sendSMSAPI, request, String.class);
logger.info("sms-response:" + response.getBody());
if (response.getStatusCode().value() == 200) {
return "OTP sent successfully on register mobile number";
} else {
return "Fail";

}
}


} catch (Exception e) {
return "Error sending SMS: " + e.getMessage().toString();
}

return null;
}
}
Loading