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

Commit

Permalink
Merge pull request #592 from egovernments/PFM-4871
Browse files Browse the repository at this point in the history
Pfm 4871
  • Loading branch information
pradeepkumarcm-egov authored Oct 6, 2023
2 parents fe1b344 + 2153189 commit 8d6abf9
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 7 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 @@ -90,6 +90,9 @@ public class SMSProperties {
@Value("${save.sms.entity.topic}")
private String saveSmsTopic;

@Value("${save.sms.entity.enabled}")
private boolean isSaveSmsEnable;

@Setter(AccessLevel.PROTECTED) private List<Pattern> whitelistPatterns;
@Setter(AccessLevel.PROTECTED) private List<Pattern> blacklistPatterns;

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 @@ -79,10 +83,13 @@ public void sendSMS(Sms sms) {
return;
}
log.info("calling submitToExternalSmsService() method");
SmsSaveRequest smsSaveRequest = SmsSaveRequest.builder().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);
if(smsProperties.isSaveSmsEnable()) {
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);
}
submitToExternalSmsService(sms);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ spring.kafka.consumer.properties.spring.json.type.mapping=smsRequest:org.egov.we
spring.kafka.listener.missing-topics-fatal=false

#persister topic of sms
save.sms.entity.topic = save-sms-entity-application
save.sms.entity.topic = save-sms-entity-application
save.sms.entity.enabled = true
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 8d6abf9

Please sign in to comment.