Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Commit

Permalink
PFM-4871: added the changes to persist sms in a table in mgramseva
Browse files Browse the repository at this point in the history
  • Loading branch information
debasishchakraborty-egovt committed Oct 6, 2023
1 parent f9818bc commit 2153189
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
5 changes: 5 additions & 0 deletions core-services/egov-notification-sms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.3.23</version>
</dependency>

</dependencies>
<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@Builder
@ToString
public class SmsSaveRequest {
private String id;
private Long id;
private String mobileNumber;
private String message;
private Category category;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.egov.web.notification.sms.repository.builder;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.jdbc.core.JdbcTemplate;

@Component
@Slf4j
@Repository
public class SmsNotificationRepository {

private JdbcTemplate jdbcTemplate;

public static final String SELECT_NEXT_SEQUENCE_USER = "select nextval('seq_eg_notification_sms')";

public Long getNextSequence() {
return jdbcTemplate.queryForObject(SELECT_NEXT_SEQUENCE_USER, Long.class);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.egov.web.notification.sms.config.*;
import org.egov.web.notification.sms.models.*;
import org.egov.web.notification.sms.producer.Producer;
import org.egov.web.notification.sms.repository.builder.SmsNotificationRepository;
import org.springframework.asm.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.core.*;
Expand Down Expand Up @@ -45,6 +46,9 @@ abstract public class BaseSMSService implements SMSService, SMSBodyBuilder {
@Autowired
private Producer producer;

@Autowired
private SmsNotificationRepository smsNotificationRepository;

@PostConstruct
public void init() {
List<HttpMessageConverter<?>> converters = restTemplate.getMessageConverters();
Expand Down Expand Up @@ -80,7 +84,8 @@ public void sendSMS(Sms sms) {
}
log.info("calling submitToExternalSmsService() method");
if(smsProperties.isSaveSmsEnable()) {
SmsSaveRequest smsSaveRequest = SmsSaveRequest.builder().mobileNumber(sms.getMobileNumber()).message(sms.getMessage())
Long id = smsNotificationRepository.getNextSequence();
SmsSaveRequest smsSaveRequest = SmsSaveRequest.builder().id(id).mobileNumber(sms.getMobileNumber()).message(sms.getMessage())
.category(sms.getCategory()).templateId(sms.getTemplateId()).tenantId(sms.getTenantId()).createdtime(System.currentTimeMillis()).build();
log.info("SMS request to save sms topic" + smsSaveRequest);
producer.push(smsProperties.getSaveSmsTopic(), smsSaveRequest);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
CREATE TABLE IF NOT EXISTS eg_notification_sms (
id SERIAL PRIMARY KEY,
id bigint NOT NULL,
mobile_no VARCHAR(20) NOT NULL,
message TEXT,
category VARCHAR(50),
template_id VARCHAR(50),
createdtime TIMESTAMP,
tenant_id VARCHAR(50)
);
CREATE SEQUENCE seq_eg_notification_sms
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER TABLE eg_notification_sms ADD CONSTRAINT eg_notification_sms_pkey PRIMARY KEY (id);

0 comments on commit 2153189

Please sign in to comment.