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 #600 from egovernments/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pradeepkumarcm-egov authored Oct 9, 2023
2 parents 2939f8b + 9abdb9d commit 1d121f6
Show file tree
Hide file tree
Showing 30 changed files with 189 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ private void sendNotification(BillRequest billReq) {
Map<String, Object> 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);
Expand Down
12 changes: 12 additions & 0 deletions core-services/egov-notification-sms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public class SMSProperties {
@Value("${sms.enabled:false}")
private boolean smsEnabled;

@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 @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 Long 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);
}
}
Original file line number Diff line number Diff line change
@@ -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<String, Object> kafkaTemplate;

public void push(String topic, Object value) {
kafkaTemplate.send(topic, value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.egov.web.notification.sms.repository.builder;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.jdbc.core.JdbcTemplate;

@Component
@Slf4j
@Repository
public class SmsNotificationRepository {

@Autowired
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 @@ -7,6 +7,8 @@
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.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 @@ -41,6 +43,12 @@ abstract public class BaseSMSService implements SMSService, SMSBodyBuilder {
@Autowired
protected Environment env;

@Autowired
private Producer producer;

@Autowired
private SmsNotificationRepository smsNotificationRepository;

@PostConstruct
public void init() {
List<HttpMessageConverter<?>> converters = restTemplate.getMessageConverters();
Expand Down Expand Up @@ -75,6 +83,14 @@ public void sendSMS(Sms sms) {
return;
}
log.info("calling submitToExternalSmsService() method");
if(smsProperties.isSaveSmsEnable()) {
Long id = smsNotificationRepository.getNextSequence();
String mobileNumber = sms.getMobileNumber();
mobileNumber = mobileNumber.substring(0, 2) + mobileNumber.substring(6);
SmsSaveRequest smsSaveRequest = SmsSaveRequest.builder().id(id).mobileNumber(mobileNumber).message(sms.getMessage())
.category(sms.getCategory()).templateId(sms.getTemplateId()).tenantId(sms.getTenantId()).createdtime(System.currentTimeMillis()).build();
producer.push(smsProperties.getSaveSmsTopic(), smsSaveRequest);
}
submitToExternalSmsService(sms);
}

Expand Down Expand Up @@ -128,7 +144,7 @@ protected <T> ResponseEntity<T> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ sms.extra.config.map={'extraParam': 'abc'}
# this should be the name of class with first letter in small
sms.url.dont_encode_url = true


# DB CONNECTION CONFIGURATIONS
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/devdb
spring.datasource.username=postgres
spring.datasource.password=postgres

# FLYWAY CONFIGURATIONS
flyway.url=jdbc:postgresql://localhost:5432/devdb
flyway.user=postgres
flyway.password=postgres
flyway.baseline-on-migrate=true
flyway.outOfOrder=true
flyway.locations=classpath:/db/migration/main
flyway.enabled=true
flyway.table=eg_notification_sms_schema

# KAFKA CONSUMER CONFIGURATIONS
spring.kafka.consumer.auto_commit=true
spring.kafka.consumer.auto_commit_interval=100
Expand Down Expand Up @@ -87,4 +104,8 @@ 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
spring.kafka.listener.missing-topics-fatal=false

#persister topic of sms
save.sms.entity.topic = save-sms-entity-application
save.sms.entity.enabled = true
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE IF NOT EXISTS eg_notification_sms (
id bigint NOT NULL,
mobile_no VARCHAR(20) NOT NULL,
message TEXT,
category VARCHAR(50),
template_id VARCHAR(50),
createdtime bigint,
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);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ class ExpensesDetailsModel {
expensesAmount?.first.amount ?? totalAmount?.toInt().toString() ?? '';
billDateCtrl.text = DateFormats.timeStampToDate(billDate);
paidDateCtrl.text =
paidDate == 0 ? '' : DateFormats.timeStampToDate(paidDate);
paidDate == null || paidDate == 0 ? '' : DateFormats.timeStampToDate(paidDate);
billIssuedDateCtrl.text =
billIssuedDate == 0 ? '' : DateFormats.timeStampToDate(billIssuedDate);
isBillPaid ??= false;
isBillPaid = paidDate != null && paidDate != 0 ? isBillPaid : false;
challanNumberCtrl.text = challanNo?.toString() ?? '';
fromDateCtrl.text = DateFormats.timeStampToDate(taxPeriodFrom);
toDateCtrl.text = DateFormats.timeStampToDate(taxPeriodTo);
Expand All @@ -179,7 +179,7 @@ class ExpensesDetailsModel {
selectedVendor = Vendor(vendorName ?? '', vendorId ?? '');
}

if (isBillPaid!) {
if (isBillPaid! && paidDate != null && paidDate != 0) {
allowEdit = false;
} else {
paidDateCtrl.text = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,9 @@ class HouseholdRegisterProvider with ChangeNotifier {
TableData('${name ?? ''}'),
TableData('${fatherName ?? ''}'),
TableData(
'${connection.additionalDetails?.collectionPendingAmount != null ? double.parse(connection.additionalDetails?.collectionPendingAmount ?? '') < 0.0 ? '-' : '${connection.additionalDetails?.collectionPendingAmount}' : '-'}'),
'${connection.additionalDetails?.collectionPendingAmount != null ? double.parse(connection.additionalDetails?.collectionPendingAmount ?? '') < 0.0 ? '-' : '₹ ${double.parse(connection.additionalDetails?.collectionPendingAmount ?? '0').abs()}' : '-'}'),
TableData(
'${connection.additionalDetails?.collectionPendingAmount != null ? double.parse(connection.additionalDetails?.collectionPendingAmount ?? '') < 0.0 ? '-₹ ${double.parse(connection.additionalDetails?.collectionPendingAmount ?? '').abs()}' : '-' : '-'}'),
'${connection.additionalDetails?.collectionPendingAmount != null ? double.parse(connection.additionalDetails?.collectionPendingAmount ?? '') < 0.0 ? '₹ ${double.parse(connection.additionalDetails?.collectionPendingAmount ?? '0').abs()}' : '-' : '-'}'),
TableData(
'${connection.status.toString() == Constants.CONNECTION_STATUS.last ? 'Y' : 'N'}',
style: TextStyle(
Expand Down Expand Up @@ -405,8 +405,8 @@ class HouseholdRegisterProvider with ChangeNotifier {
'${connection.connectionNo ?? ''} ${connection.connectionType == 'Metered' ? '- M' : ''}',
'${connection.connectionHolders?.first.name ?? ''}',
'${connection.connectionHolders?.first.fatherOrHusbandName ?? ''}',
'${connection.additionalDetails?.collectionPendingAmount != null ? double.parse(connection.additionalDetails?.collectionPendingAmount ?? '') < 0.0 ? '-' : '${connection.additionalDetails?.collectionPendingAmount}' : '-'}',
'${connection.additionalDetails?.collectionPendingAmount != null ? double.parse(connection.additionalDetails?.collectionPendingAmount ?? '') < 0.0 ? '- ₹ ${double.parse(connection.additionalDetails?.collectionPendingAmount ?? '').abs()}' : '₹ 0' : '₹ 0'}',
'${connection.additionalDetails?.collectionPendingAmount != null ? double.parse(connection.additionalDetails?.collectionPendingAmount ?? '') < 0.0 ? '-' : '₹ ${double.parse(connection.additionalDetails?.collectionPendingAmount ?? '0').abs()}' : '-'}',
'${connection.additionalDetails?.collectionPendingAmount != null ? double.parse(connection.additionalDetails?.collectionPendingAmount ?? '') < 0.0 ? '₹ ${double.parse(connection.additionalDetails?.collectionPendingAmount ?? '0').abs()}' : '₹ 0' : '₹ 0'}',
'${connection.status.toString() == Constants.CONNECTION_STATUS.last ? 'Y' : 'N'}',
'${connection.additionalDetails?.lastDemandGeneratedDate != null && connection.additionalDetails?.lastDemandGeneratedDate != '' ? DateFormats.timeStampToDate(int.parse(connection.additionalDetails?.lastDemandGeneratedDate ?? '')) : '-'}'
])
Expand All @@ -418,8 +418,8 @@ class HouseholdRegisterProvider with ChangeNotifier {
'${connection.oldConnectionNo ?? ''}',
'${connection.connectionHolders?.first.name ?? ''}',
'${connection.connectionHolders?.first.fatherOrHusbandName ?? ''}',
'${connection.additionalDetails?.collectionPendingAmount != null ? double.parse(connection.additionalDetails?.collectionPendingAmount ?? '') < 0.0 ? '-' : '${connection.additionalDetails?.collectionPendingAmount}' : '-'}',
'${connection.additionalDetails?.collectionPendingAmount != null ? double.parse(connection.additionalDetails?.collectionPendingAmount ?? '') < 0.0 ? '- ₹ ${double.parse(connection.additionalDetails?.collectionPendingAmount ?? '').abs()}' : '₹ 0' : '₹ 0'}',
'${connection.additionalDetails?.collectionPendingAmount != null ? double.parse(connection.additionalDetails?.collectionPendingAmount ?? '') < 0.0 ? '-' : '₹ ${double.parse(connection.additionalDetails?.collectionPendingAmount ?? '0').abs()}' : '-'}',
'${connection.additionalDetails?.collectionPendingAmount != null ? double.parse(connection.additionalDetails?.collectionPendingAmount ?? '') < 0.0 ? '₹ ${double.parse(connection.additionalDetails?.collectionPendingAmount ?? '0').abs()}' : '₹ 0' : '₹ 0'}',
'${connection.status.toString() == Constants.CONNECTION_STATUS.last ? 'Y' : 'N'}',
'${connection.additionalDetails?.lastDemandGeneratedDate != null && connection.additionalDetails?.lastDemandGeneratedDate != '' ? DateFormats.timeStampToDate(int.parse(connection.additionalDetails?.lastDemandGeneratedDate ?? '')) : '-'}'
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class _ExpenseDetailsState extends State<ExpenseDetails> {
FilteringTextInputFormatter.allow(
RegExp(r"^[1-9][0-9]{0,5}$"))
],
placeHolder: '${i18.expense.AMOUNT} (₹)',
labelSuffix: '(₹)',
isDisabled: (expenseDetails.allowEdit ?? true)
? false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class _PaymentSuccessState extends State<PaymentSuccess> {
backButton: false,
isWithoutLogin: true,
isConsumer: true,
amount: '${transactionObject.transaction!.first.currencyCode! ?? ''} ${transactionObject.transaction!.first.txnAmount! ?? '0'}',
amount: '${transactionObject.transaction!.first.txnAmount! ?? '0'}',
)
: NoLoginFailurePage(i18.payment.PAYMENT_FAILED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class SMSRequest {
private String mobileNumber;
private String message;
private String templateId;
private String tenantid;
private String[] users;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void enrichSMSRequest(DemandNotificationObj notificationObj, List<SMSReq
enrichNotificationReceivers(receiverList, notificationObj);
receiverList.forEach(receiver -> {
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);
});
}
Expand Down
Loading

0 comments on commit 1d121f6

Please sign in to comment.