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
2 changes: 2 additions & 0 deletions src/main/java/com/iemr/common/CommonApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate;

Expand All @@ -40,6 +41,7 @@

@SpringBootApplication
@EnableScheduling
@EnableAsync
public class CommonApplication extends SpringBootServletInitializer {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ public ResponseEntity<ApiResponse<?>> getStructuredForm(@PathVariable String for
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ public class Translation {
private String assameseTranslation;
@Column(name = "is_active")
private Boolean isActive;

}
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,5 @@ public void setVillagename(String villagename) {
public int hashCode() {
return Objects.hash(userId, usrMappingId, name, userName, serviceId, serviceName, isNational, stateId, stateName, workingDistrictId, workingDistrictName, workingLocationId, serviceProviderId, locationName, workingLocationAddress, roleId, roleName, providerServiceMapId, agentId, psmStatusId, psmStatus, userServciceRoleDeleted, userDeleted, serviceProviderDeleted, roleDeleted, providerServiceMappingDeleted, isInbound, isOutbound, blockid, blockname, villageid, villagename);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
@Repository
public interface FieldRepository extends JpaRepository<FormField, Long> {
List<FormField> findByForm_FormIdOrderBySequenceAsc(String formId);
List<FormField> findByForm_FormIdAndStateCodeOrderBySequenceAsc(
String formId,
Integer stateCode
);


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public interface TranslationRepo extends JpaRepository<Translation, Long> {

Optional<Translation> findByLabelKeyAndIsActive(String labelKey, boolean isActive);


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface UserServiceRoleRepo extends JpaRepository<UserServiceRole, Inte
UserServiceRole findByUserName(String userName);
UserServiceRole findByUserId(Integer userId);



}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;

import com.iemr.common.model.beneficiary.RMNCHBeneficiaryDetailsRmnch;
import com.iemr.common.service.welcomeSms.WelcomeBenificarySmsService;
Expand Down Expand Up @@ -198,7 +199,7 @@
}

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

Check failure on line 202 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=AZzc88flDndTluncIAcV&open=AZzc88flDndTluncIAcV&pullRequest=339

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

Expand Down Expand Up @@ -234,9 +235,27 @@
} 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());
// ========== SEND SMS BUT DON'T FAIL IF IT ERRORS ==========
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 247 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=AZzc88flDndTluncIAcW&open=AZzc88flDndTluncIAcW&pullRequest=339

Check warning on line 247 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=AZzc88flDndTluncIAcT&open=AZzc88flDndTluncIAcT&pullRequest=339
String smsResult = welcomeBenificarySmsService.sendWelcomeSMStoBenificiary(
phoneNo,
beneficiaryName.trim(),
beneficiary.getBeneficiaryID()
);
logger.info("[SMS] Result: " + smsResult);

Check warning on line 253 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=AZzc88flDndTluncIAcX&open=AZzc88flDndTluncIAcX&pullRequest=339

Check warning on line 253 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=AZzc88flDndTluncIAcU&open=AZzc88flDndTluncIAcU&pullRequest=339
} 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 257 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=AZzc88flDndTluncIAcY&open=AZzc88flDndTluncIAcY&pullRequest=339
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ public interface FormMasterService {

FormResponseDTO getStructuredFormByFormId(String formId,String lang,String token);



void deleteField(Long fieldId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ public FormField updateField(FieldDTO dto) {
@Override
public FormResponseDTO getStructuredFormByFormId(String formId,String lang,String token) {
int stateId =0 ;

try {
UserServiceRole userServiceRole= userServiceRoleRepo.findByUserName(jwtUtil.getUsernameFromToken(token));
if(userServiceRole!=null){
Expand All @@ -126,11 +125,10 @@ public FormResponseDTO getStructuredFormByFormId(String formId,String lang,Strin
FormDefinition form = formRepo.findByFormId(formId)
.orElseThrow(() -> new IllegalArgumentException("Invalid form ID"));

List<FormField> fields = fieldRepo.findByForm_FormIdOrderBySequenceAsc(formId);
List<FormField> fields = fieldRepo.findByForm_FormIdAndStateCodeOrderBySequenceAsc(formId,stateId);
ObjectMapper objectMapper = new ObjectMapper();

Integer finalStateId = stateId;
List<FieldResponseDTO> fieldDtos = fields.stream().filter(formField -> Objects.equals(formField.getStateCode(), finalStateId) || formField.getStateCode()==0)
List<FieldResponseDTO> fieldDtos = fields.stream()
.map(field -> {
String labelKey = field.getFieldId(); // field label already contains label_key

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;

final RestTemplate restTemplate = new RestTemplate();

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()));
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";
// 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;
}
}
1 change: 0 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,3 @@ allowed.file.extensions=msg,pdf,png,jpeg,doc,docx,xlsx,xls,csv,txt
##sms details for beneficiary otp cosent
sms-template-name = otp_consent

cors.allowed-origin =