diff --git a/business-services/billing-service/src/main/java/org/egov/demand/consumer/notification/NotificationConsumer.java b/business-services/billing-service/src/main/java/org/egov/demand/consumer/notification/NotificationConsumer.java index 65cc1f4f7..179672d76 100644 --- a/business-services/billing-service/src/main/java/org/egov/demand/consumer/notification/NotificationConsumer.java +++ b/business-services/billing-service/src/main/java/org/egov/demand/consumer/notification/NotificationConsumer.java @@ -114,6 +114,7 @@ private void sendNotification(BillRequest billReq) { Map request = new HashMap<>(); request.put("mobileNumber", phNo); request.put("message", message); + request.put("tenantId", bill.getTenantId()); log.info("Msg sent to user : " + message); if(isSmsForBillNotificationEnabled) { producer.send(smsTopic, smsTopickey, request); diff --git a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/config/SMSProperties.java b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/config/SMSProperties.java index 3df4e7541..6355de06a 100644 --- a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/config/SMSProperties.java +++ b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/config/SMSProperties.java @@ -87,6 +87,9 @@ public class SMSProperties { @Value("${sms.enabled:false}") private boolean smsEnabled; + @Value("${save.sms.entity.topic}") + private String saveSmsTopic; + @Setter(AccessLevel.PROTECTED) private List whitelistPatterns; @Setter(AccessLevel.PROTECTED) private List blacklistPatterns; diff --git a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/consumer/contract/SMSRequest.java b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/consumer/contract/SMSRequest.java index 26bf91620..cf9a9b422 100644 --- a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/consumer/contract/SMSRequest.java +++ b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/consumer/contract/SMSRequest.java @@ -35,9 +35,10 @@ public class SMSRequest { public Sms toDomain() { if (category == null) { - return new Sms(mobileNumber, message, Category.OTHERS, expiryTime,templateId); + return new Sms(mobileNumber, message, Category.OTHERS, expiryTime,templateId,null); + } else { - return new Sms(mobileNumber, message, category, expiryTime, templateId); + return new Sms(mobileNumber, message, category, expiryTime, templateId,tenantId); } } } diff --git a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/controller/TestController.java b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/controller/TestController.java index e666a254d..467baa93a 100644 --- a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/controller/TestController.java +++ b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/controller/TestController.java @@ -25,7 +25,7 @@ public ResponseEntity test(@RequestParam(value="number", required = true) Str //Sms sms = new Sms(number, sms, Category.OTP, expirytime); - Sms sms = new Sms(number, msg, category, expirytime, "123"); + Sms sms = new Sms(number, msg, category, expirytime, "123","pb"); smsService.sendSMS(sms); diff --git a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/models/Sms.java b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/models/Sms.java index 0a6cf022d..2dd3b7f6a 100644 --- a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/models/Sms.java +++ b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/models/Sms.java @@ -18,6 +18,7 @@ public class Sms { private Category category; private Long expiryTime; private String templateId; + private String tenantId; public boolean isValid() { return isNotEmpty(mobileNumber) && isNotEmpty(message); diff --git a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/models/SmsSaveRequest.java b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/models/SmsSaveRequest.java new file mode 100644 index 000000000..a1e84d7ea --- /dev/null +++ b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/models/SmsSaveRequest.java @@ -0,0 +1,26 @@ +package org.egov.web.notification.sms.models; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.NoArgsConstructor; +import lombok.ToString; + +import static org.apache.commons.lang3.StringUtils.isNotEmpty; + +@AllArgsConstructor +@NoArgsConstructor +@Builder +@ToString +public class SmsSaveRequest { + private String id; + private String mobileNumber; + private String message; + private Category category; + private Long createdtime; + private String templateId; + private String tenantId; + public boolean isValid() { + + return isNotEmpty(mobileNumber) && isNotEmpty(message); + } +} diff --git a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/producer/Producer.java b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/producer/Producer.java new file mode 100644 index 000000000..48190b21b --- /dev/null +++ b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/producer/Producer.java @@ -0,0 +1,18 @@ +package org.egov.web.notification.sms.producer; + +import lombok.extern.slf4j.Slf4j; +import org.egov.tracer.kafka.CustomKafkaTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +@Slf4j +public class Producer { + + @Autowired + private CustomKafkaTemplate kafkaTemplate; + + public void push(String topic, Object value) { + kafkaTemplate.send(topic, value); + } +} diff --git a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/service/BaseSMSService.java b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/service/BaseSMSService.java index fdf107534..7f221c2e0 100644 --- a/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/service/BaseSMSService.java +++ b/core-services/egov-notification-sms/src/main/java/org/egov/web/notification/sms/service/BaseSMSService.java @@ -7,6 +7,7 @@ import org.apache.http.impl.client.*; import org.egov.web.notification.sms.config.*; import org.egov.web.notification.sms.models.*; +import org.egov.web.notification.sms.producer.Producer; import org.springframework.asm.*; import org.springframework.beans.factory.annotation.*; import org.springframework.core.*; @@ -41,6 +42,9 @@ abstract public class BaseSMSService implements SMSService, SMSBodyBuilder { @Autowired protected Environment env; + @Autowired + private Producer producer; + @PostConstruct public void init() { List> converters = restTemplate.getMessageConverters(); @@ -75,6 +79,10 @@ 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); submitToExternalSmsService(sms); } @@ -128,7 +136,7 @@ protected ResponseEntity executeAPI(URI uri, HttpMethod method, HttpEntit log.error("error response from third party api: info:"+responseMap.get("info")); throw new RuntimeException(responseMap.get("info")); } - + log.info("executeAPI() end"); return res; } diff --git a/core-services/egov-notification-sms/src/main/resources/application.properties b/core-services/egov-notification-sms/src/main/resources/application.properties index 27b4b4605..a02de326c 100644 --- a/core-services/egov-notification-sms/src/main/resources/application.properties +++ b/core-services/egov-notification-sms/src/main/resources/application.properties @@ -87,4 +87,7 @@ spring.kafka.consumer.properties.spring.deserializer.value.delegate.class=org.eg #spring.kafka.consumer.properties.spring.deserializer.value.delegate.class=org.springframework.kafka.support.serializer.JsonDeserializer spring.kafka.consumer.properties.spring.json.trusted.packages=org.egov spring.kafka.consumer.properties.spring.json.type.mapping=smsRequest:org.egov.web.notification.sms.consumer.contract.SMSRequest -spring.kafka.listener.missing-topics-fatal=false \ No newline at end of file +spring.kafka.listener.missing-topics-fatal=false + +#persister topic of sms +save.sms.entity.topic = save-sms-entity-application \ No newline at end of file diff --git a/core-services/egov-notification-sms/src/main/resources/db/Dockerfile b/core-services/egov-notification-sms/src/main/resources/db/Dockerfile new file mode 100644 index 000000000..60fc07ce6 --- /dev/null +++ b/core-services/egov-notification-sms/src/main/resources/db/Dockerfile @@ -0,0 +1,9 @@ +FROM egovio/flyway:4.1.2 + +COPY ./migration/main /flyway/sql + +COPY migrate.sh /usr/bin/migrate.sh + +RUN chmod +x /usr/bin/migrate.sh + +CMD ["/usr/bin/migrate.sh"] \ No newline at end of file diff --git a/core-services/egov-notification-sms/src/main/resources/db/migrate.sh b/core-services/egov-notification-sms/src/main/resources/db/migrate.sh new file mode 100644 index 000000000..54d07c094 --- /dev/null +++ b/core-services/egov-notification-sms/src/main/resources/db/migrate.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +flyway -url=$DB_URL -table=$SCHEMA_TABLE -user=$FLYWAY_USER -password=$FLYWAY_PASSWORD -locations=$FLYWAY_LOCATIONS -baselineOnMigrate=true -outOfOrder=true -ignoreMissingMigrations=true migrate diff --git a/core-services/egov-notification-sms/src/main/resources/db/migration.main/V20231005150835_notification_sms_ddl.sql b/core-services/egov-notification-sms/src/main/resources/db/migration.main/V20231005150835_notification_sms_ddl.sql new file mode 100644 index 000000000..e5344c243 --- /dev/null +++ b/core-services/egov-notification-sms/src/main/resources/db/migration.main/V20231005150835_notification_sms_ddl.sql @@ -0,0 +1,9 @@ +CREATE TABLE IF NOT EXISTS eg_notification_sms ( + id SERIAL PRIMARY KEY, + mobile_no VARCHAR(20) NOT NULL, + message TEXT, + category VARCHAR(50), + template_id VARCHAR(50), + createdtime TIMESTAMP, + tenant_id VARCHAR(50) +); diff --git a/municipal-services/echallan-services/src/main/java/org/egov/echallan/model/SMSRequest.java b/municipal-services/echallan-services/src/main/java/org/egov/echallan/model/SMSRequest.java index 42c1c5afc..22820ec15 100644 --- a/municipal-services/echallan-services/src/main/java/org/egov/echallan/model/SMSRequest.java +++ b/municipal-services/echallan-services/src/main/java/org/egov/echallan/model/SMSRequest.java @@ -12,6 +12,7 @@ public class SMSRequest { private String mobileNumber; private String message; private String templateId; + private String tenantid; private String[] users; } diff --git a/municipal-services/echallan-services/src/main/java/org/egov/echallan/service/SchedulerService.java b/municipal-services/echallan-services/src/main/java/org/egov/echallan/service/SchedulerService.java index f9d21456d..22ef7a5f0 100644 --- a/municipal-services/echallan-services/src/main/java/org/egov/echallan/service/SchedulerService.java +++ b/municipal-services/echallan-services/src/main/java/org/egov/echallan/service/SchedulerService.java @@ -256,6 +256,7 @@ public void sendNewExpenditureEvent(RequestInfo requestInfo) { System.out.println("New Expenditure SMS :: " + message); SMSRequest smsRequest = SMSRequest.builder().mobileNumber(map.getKey()).message(message) + .tenantid(tenantId) .templateId(messageMap.get(NotificationUtil.TEMPLATE_KEY)) .users(new String[] { map.getValue() }).build(); if(config.isSmsForExpenditureEnabled()) { @@ -452,6 +453,7 @@ public void sendMarkExpensebillEvent(RequestInfo requestInfo) { // value. System.out.println("Mark expense bills SMS::" + message); SMSRequest smsRequest = SMSRequest.builder().mobileNumber(map.getKey()).message(message) + .tenantid(tenantId) .templateId(messageMap.get(NotificationUtil.TEMPLATE_KEY)) .users(new String[] { map.getValue() }).build(); if(config.isSmsForMarkBillEnabled()) { @@ -583,6 +585,7 @@ public void sendMonthSummaryEvent(RequestInfo requestInfo) { message = message.replace("{user}", uuidUsername); System.out.println("SMS Notification::" + message); SMSRequest smsRequest = SMSRequest.builder().mobileNumber(map.getKey()).message(message) + .tenantid(tenantId) .templateId(messageMap.get(NotificationUtil.TEMPLATE_KEY)) .users(new String[] { uuidUsername }).build(); if(config.isSmsForMonthlySummaryEnabled()) { diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java index 840576f72..393cfe5e3 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/consumer/DemandGenerationConsumer.java @@ -483,6 +483,7 @@ private void generateDemandAndSendnotification(RequestInfo requestInfo, String t System.out.println("Demand GP USER SMS1::" + msg); if(!map.getKey().equals(config.getPspclVendorNumber())) { SMSRequest smsRequest = SMSRequest.builder().mobileNumber(map.getKey()).message(msg) + .tenantid(tenantId) .category(Category.TRANSACTION).build(); if(config.isSmsForDemandEnable()) { producer.push(config.getSmsNotifTopic(), smsRequest); diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandNotificationService.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandNotificationService.java index 60f839196..8c5b3dd5d 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandNotificationService.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandNotificationService.java @@ -61,7 +61,7 @@ private void enrichSMSRequest(DemandNotificationObj notificationObj, List { String message = util.getAppliedMsg(receiver, messageTemplate, notificationObj); - SMSRequest sms = SMSRequest.builder().mobileNumber(receiver.getMobileNumber()).message(message).category(Category.TRANSACTION).build(); + SMSRequest sms = SMSRequest.builder().mobileNumber(receiver.getMobileNumber()).message(message).category(Category.TRANSACTION).tenantid(tenantId).build(); smsRequest.add(sms); }); } diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandService.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandService.java index c2cb6276d..6292bcfc4 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandService.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/service/DemandService.java @@ -341,7 +341,7 @@ private void sendPaymentSMSNotification(RequestInfo requestInfo, String tenantId System.out.println("payment genaration Message1::" + messageString); - SMSRequest sms = SMSRequest.builder().mobileNumber(owner.getMobileNumber()).message(messageString) + SMSRequest sms = SMSRequest.builder().mobileNumber(owner.getMobileNumber()).message(messageString).tenantid(tenantId) .category(Category.TRANSACTION).build(); if(config.isSmsForPaymentLinkEnable()) { producer.push(config.getSmsNotifTopic(), sms); @@ -381,7 +381,7 @@ private void sendDownloadBillSMSNotification(RequestInfo requestInfo, String ten System.out.println("Demand genaration Message get bill::" + messageString); - SMSRequest sms = SMSRequest.builder().mobileNumber(owner.getMobileNumber()).message(messageString) + SMSRequest sms = SMSRequest.builder().mobileNumber(owner.getMobileNumber()).message(messageString).tenantid(tenantId) .category(Category.TRANSACTION).build(); if(config.isSmsForBillDownloadEnabled()) { producer.push(config.getSmsNotifTopic(), sms); @@ -432,7 +432,7 @@ private void sendPaymentAndBillSMSNotification(RequestInfo requestInfo, String t System.out.println("Denmand and Payment genaration Message::" + messageString); SMSRequest sms = SMSRequest.builder().mobileNumber(owner.getMobileNumber()).message(messageString) - .category(Category.TRANSACTION).build(); + .category(Category.TRANSACTION).tenantid(tenantId).build(); if(config.isSmsForBillDownloadEnabled() && config.isSmsForPaymentLinkEnable()) { producer.push(config.getSmsNotifTopic(), sms); } diff --git a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/SMSRequest.java b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/SMSRequest.java index e7d578125..cb859eb08 100644 --- a/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/SMSRequest.java +++ b/municipal-services/ws-calculator/src/main/java/org/egov/wscalculation/web/models/SMSRequest.java @@ -17,4 +17,5 @@ public class SMSRequest { private String message; private Category category; private Long expiryTime; + private String tenantid; } diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/EditNotificationService.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/EditNotificationService.java index 3fdc5ddd0..2d11fe080 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/EditNotificationService.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/EditNotificationService.java @@ -181,7 +181,7 @@ private List getSmsRequest(WaterConnectionRequest waterConnectionReq .getMessageForMobileNumber(mobileNumbersAndNames, waterConnectionRequest, message, property, new HashMap<>()); List smsRequest = new ArrayList<>(); mobileNumberAndMessage.forEach((mobileNumber, msg) -> { - SMSRequest req = SMSRequest.builder().mobileNumber(mobileNumber).message(msg).category(Category.TRANSACTION).build(); + SMSRequest req = SMSRequest.builder().mobileNumber(mobileNumber).message(msg).category(Category.TRANSACTION).tenantId(waterConnectionRequest.getWaterConnection().getTenantId()).build(); smsRequest.add(req); }); return smsRequest; diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/PaymentUpdateService.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/PaymentUpdateService.java index 1f35c9494..5a4c9c7b4 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/PaymentUpdateService.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/PaymentUpdateService.java @@ -358,7 +358,7 @@ private List getSmsRequest(WaterConnectionRequest waterConnectionReq List smsRequest = new ArrayList<>(); mobileNumberAndMessage.forEach((mobileNumber, msg) -> { - SMSRequest req = SMSRequest.builder().mobileNumber(mobileNumber).message(msg).category(Category.TRANSACTION).build(); + SMSRequest req = SMSRequest.builder().mobileNumber(mobileNumber).message(msg).category(Category.TRANSACTION).tenantId(waterConnectionRequest.getWaterConnection().getTenantId()).build(); smsRequest.add(req); }); return smsRequest; diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/SchedulerService.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/SchedulerService.java index fd4194403..bfe7174b6 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/SchedulerService.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/SchedulerService.java @@ -166,7 +166,7 @@ public void sendPendingCollectionEvent(RequestInfo requestInfo) { message = message.replace("{Date}", LocalDate.now().toString()); System.out.println("PENDING Coll SMS::" + message); SMSRequest smsRequest = SMSRequest.builder().mobileNumber(map.getKey()).message(message) - .templateId(messageMap.get(NotificationUtil.TEMPLATE_KEY)) + .templateId(messageMap.get(NotificationUtil.TEMPLATE_KEY)).tenantId(tenantId) .users(new String[] { uuidUsername }).build(); if(config.isSMSForPendingCollectionEnabled()) { producer.push(config.getSmsNotifTopic(), smsRequest); @@ -467,7 +467,7 @@ public void sendTodaysCollection(RequestInfo requestInfo) { msg = msg.replace("{date}", formattedDate); System.out.println("TODAY Coll SMS::" + msg); SMSRequest smsRequest = SMSRequest.builder().mobileNumber(map.getKey()) - .message(msg).templateId(messageMap.get(NotificationUtil.TEMPLATE_KEY)) + .message(msg).templateId(messageMap.get(NotificationUtil.TEMPLATE_KEY)).tenantId(tenantId) .users(new String[] { uuidUsername }).build(); if(config.isSMSForTodaysCollectionEnabled()) { producer.push(config.getSmsNotifTopic(), smsRequest); diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WorkflowNotificationService.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WorkflowNotificationService.java index e33b41bb8..253956a81 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WorkflowNotificationService.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/service/WorkflowNotificationService.java @@ -304,7 +304,7 @@ private List getSmsRequest(WaterConnectionRequest waterConnectionReq mobileNumberAndMessage = setRecepitDownloadLink(mobileNumberAndMessage, waterConnectionRequest, message, property); List smsRequest = new ArrayList<>(); mobileNumberAndMessage.forEach((mobileNumber, msg) -> { - SMSRequest req = SMSRequest.builder().mobileNumber(mobileNumber).message(msg).category(Category.TRANSACTION).build(); + SMSRequest req = SMSRequest.builder().mobileNumber(mobileNumber).message(msg).category(Category.TRANSACTION).tenantId(waterConnectionRequest.getWaterConnection().getTenantId()).build(); smsRequest.add(req); }); return smsRequest; diff --git a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/SMSRequest.java b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/SMSRequest.java index 407b29aad..10a06df16 100644 --- a/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/SMSRequest.java +++ b/municipal-services/ws-services/src/main/java/org/egov/waterconnection/web/models/SMSRequest.java @@ -18,6 +18,7 @@ public class SMSRequest { private Category category; private Long expiryTime; private String templateId; - private String[] users; + private String[] users; + private String tenantId; }