all the application configurations has been defined in application.conf, application-dev.conf and application-prod.conf. Also made the ktor server configuration in external file.
This commit is contained in:
parent
48877ddcec
commit
0516c2c964
@ -2,9 +2,6 @@
|
||||
<configuration default="false" name="ApplicationKt" type="KtorApplicationConfigurationType" factoryName="Ktor" nameIsGenerated="true">
|
||||
<envs>
|
||||
<env name="KTOR_ENV" value="dev" />
|
||||
<env name="DB_USER" value="pacs_db" />
|
||||
<env name="DB_PASSWORD" value="pacs_db" />
|
||||
<env name="DB_HOST" value="localhost" />
|
||||
</envs>
|
||||
<option name="MAIN_CLASS_NAME" value="net.ipksindia.ApplicationKt" />
|
||||
<module name="neft-server.main" />
|
||||
|
@ -3,14 +3,13 @@ package net.ipksindia
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.engine.*
|
||||
import io.ktor.server.netty.*
|
||||
import net.ipksindia.config.AppConfig
|
||||
import net.ipksindia.plugins.*
|
||||
|
||||
fun main() {
|
||||
embeddedServer(Netty, port = 8083, host = "0.0.0.0", module = Application::module)
|
||||
.start(wait = true)
|
||||
}
|
||||
fun main(args: Array<String>):Unit = EngineMain.main(args)
|
||||
|
||||
fun Application.module() {
|
||||
AppConfig.validateConfig()
|
||||
configureSerialization()
|
||||
configureRouting()
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.ipksindia
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.json.Json
|
||||
import net.ipksindia.config.AppConfig
|
||||
import net.ipksindia.model.NeftTransaction
|
||||
import net.ipksindia.model.TransferTransaction
|
||||
import okhttp3.MediaType.Companion.toMediaType
|
||||
@ -18,11 +19,7 @@ import javax.net.ssl.HostnameVerifier
|
||||
|
||||
class TransactionExecutor() {
|
||||
|
||||
private val protocol = "https"
|
||||
private val host = "180.179.110.185"
|
||||
private val port = "443"
|
||||
private val rootRoute = "IPKS_Queue_Generation"
|
||||
private val remoteUrl = "$protocol://$host:$port/$rootRoute"
|
||||
private val transactionUrl = AppConfig.remoteServerConfig.transactionUrl
|
||||
|
||||
fun executePair(transactionPair: Pair<TransferTransaction, NeftTransaction>): Pair<TransactionResponse, TransactionResponse> {
|
||||
|
||||
@ -36,8 +33,6 @@ class TransactionExecutor() {
|
||||
|
||||
private fun execute(postBody: String): TransactionResponse {
|
||||
// println(postBody)
|
||||
val transferRoute = "IpksApi"
|
||||
val transferURL = "$remoteUrl/$transferRoute"
|
||||
val jsonMediaType = "application/json; charset=utf-8".toMediaType()
|
||||
|
||||
val httpClient = OkHttpClient
|
||||
@ -47,7 +42,7 @@ class TransactionExecutor() {
|
||||
|
||||
val request = Request
|
||||
.Builder()
|
||||
.url(transferURL)
|
||||
.url(transactionUrl)
|
||||
.post(postBody.toRequestBody(jsonMediaType))
|
||||
.build()
|
||||
|
||||
@ -63,14 +58,14 @@ class TransactionExecutor() {
|
||||
val message = try { responseObj.getString("message") }catch(_: JSONException) { "" }
|
||||
val error = try { responseObj.getInt("error") } catch(_: JSONException) { 1 }
|
||||
|
||||
val response = if(responseBody.contains("SUCCESS")) {
|
||||
if(responseBody.contains("SUCCESS")) {
|
||||
val queueNo = try { responseObj.getJSONObject("response").getString("QueueId") } catch(_: JSONException) { "" }
|
||||
return TransactionSuccessResponse(status, message, queueNo, error)
|
||||
} else {
|
||||
val errorMsg = try { responseObj.getJSONObject("response").getString("errorMsg") } catch(_: JSONException) { responseBody }
|
||||
return TransactionFailureResponse(status, message, errorMsg, error)
|
||||
}
|
||||
return response
|
||||
|
||||
}
|
||||
|
||||
}
|
86
src/main/kotlin/net/ipksindia/config/AppConfig.kt
Normal file
86
src/main/kotlin/net/ipksindia/config/AppConfig.kt
Normal file
@ -0,0 +1,86 @@
|
||||
package net.ipksindia.config
|
||||
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.slf4j.LoggerFactory
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
object AppConfig {
|
||||
|
||||
private val logger = LoggerFactory.getLogger(AppConfig::class.java)
|
||||
|
||||
private val environment = ConfigFactory.load().getString("ktor.environment")
|
||||
private val config = when (environment) {
|
||||
"prod" -> ConfigFactory.load("application-prod.conf")
|
||||
else -> ConfigFactory.load("application-dev.conf")
|
||||
}
|
||||
|
||||
fun validateConfig() {
|
||||
val requiredKeys = listOf(
|
||||
"database.host",
|
||||
"database.port",
|
||||
"database.name",
|
||||
"database.user",
|
||||
"database.password",
|
||||
"bank.server.protocol",
|
||||
"bank.server.host",
|
||||
"bank.server.port",
|
||||
"bank.server.rootRoute",
|
||||
"bank.server.transactionRoute"
|
||||
)
|
||||
|
||||
val missingKeys = requiredKeys.filterNot { config.hasPath(it) }
|
||||
|
||||
if (missingKeys.isNotEmpty()) {
|
||||
logger.error("Missing configuration keys: {}", missingKeys.toString())
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
val dbPort = config.getInt("database.port")
|
||||
val remoteServerPort = config.getInt("bank.server.port")
|
||||
if (dbPort !in 1..65535) {
|
||||
logger.error("Invalid database port: {}", dbPort)
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
if (remoteServerPort !in 1..65535) {
|
||||
logger.error("Invalid remote server port: {}", remoteServerPort)
|
||||
exitProcess(1)
|
||||
}
|
||||
}
|
||||
|
||||
val databaseConfig = DatabaseConfig(
|
||||
config.getString("database.host"),
|
||||
config.getInt("database.port"),
|
||||
config.getString("database.name"),
|
||||
config.getString("database.user"),
|
||||
config.getString("database.password")
|
||||
)
|
||||
|
||||
val remoteServerConfig = RemoteServerConfig(
|
||||
config.getString("bank.server.protocol"),
|
||||
config.getString("bank.server.host"),
|
||||
config.getInt("bank.server.port"),
|
||||
config.getString("bank.server.rootRoute"),
|
||||
config.getString("bank.server.transactionRoute")
|
||||
)
|
||||
}
|
||||
|
||||
data class RemoteServerConfig(
|
||||
val protocol: String,
|
||||
val host: String,
|
||||
val port: Int,
|
||||
val rootRoute: String,
|
||||
val transactionRoute: String
|
||||
) {
|
||||
val transactionUrl = "$protocol://$host:$port/$rootRoute/$transactionRoute"
|
||||
}
|
||||
|
||||
data class DatabaseConfig(
|
||||
val host: String,
|
||||
val port: Int,
|
||||
val name: String,
|
||||
val user: String,
|
||||
val password: String
|
||||
) {
|
||||
val dbUrl = "jdbc:oracle:thin:@$host:$port:$name"
|
||||
}
|
@ -1,44 +1,16 @@
|
||||
package net.ipksindia.dao
|
||||
|
||||
import model.TransactionRequest
|
||||
import net.ipksindia.config.AppConfig
|
||||
import java.sql.Date
|
||||
import java.sql.DriverManager
|
||||
import java.sql.ResultSet
|
||||
import java.util.*
|
||||
|
||||
class TransactionDao {
|
||||
private val transactionRequestQuery = """
|
||||
SELECT
|
||||
txn_no,
|
||||
TRIM(src_ac_no) AS src_ac_no,
|
||||
TRIM(dest_ac_no) AS dest_ac_no,
|
||||
ifsc_code,
|
||||
txn_amt,
|
||||
txn_date,
|
||||
t.teller_id,
|
||||
CASE
|
||||
WHEN t.ifsc_code LIKE 'WBSC%' THEN 'FAILED'
|
||||
ELSE 'RECEIVED'
|
||||
END AS status,
|
||||
SUBSTR(REGEXP_REPLACE(REGEXP_REPLACE(UPPER(beneficiary_name), '[^A-Z0-9 ]', ''), ' {2,}', ' '), 1, 35) AS beneficiary_name,
|
||||
beneficiary_add,
|
||||
t.pacs_id,
|
||||
comm_txn_no,
|
||||
comm_txn_amt,
|
||||
dccb_code,
|
||||
TO_NUMBER(cbs_br_code) AS br_code,
|
||||
SUBSTR(REGEXP_REPLACE(REGEXP_REPLACE(UPPER(remm_name), '[^A-Z0-9 ]', ''), ' {2,}', ' '),1,35) AS remitter_name,
|
||||
ipks_accno AS pacs_acc_no,
|
||||
da.link_accno AS cbs_sb_acc_no,
|
||||
'pacs_db' AS db_name
|
||||
FROM neft_rtgs_txn t
|
||||
JOIN dep_account da ON t.ipks_accno = da.key_1
|
||||
WHERE
|
||||
t.txn_date = (SELECT system_date FROM system_date)
|
||||
AND t.STATUS = 'A'
|
||||
AND t.bank_channel = 'SCB'
|
||||
AND da.link_accno IS NOT NULL
|
||||
""".trimIndent()
|
||||
class TransactionDao() {
|
||||
|
||||
private val dbUrl = AppConfig.databaseConfig.dbUrl
|
||||
private val dbUser = AppConfig.databaseConfig.user
|
||||
private val dbPassword = AppConfig.databaseConfig.password
|
||||
|
||||
private val singleTransactionRequestQuery = """
|
||||
SELECT
|
||||
@ -97,11 +69,12 @@ class TransactionDao {
|
||||
""".trimIndent()
|
||||
|
||||
fun updateSuccessTransaction(request: TransactionRequest, transferQueueNumber: String, neftQueueNumber: String) {
|
||||
val dbUrl = getDatabaseUrl()
|
||||
val (dbUser, dbPassword) = getUserCredentials()
|
||||
|
||||
DriverManager.getConnection(dbUrl, dbUser, dbPassword).use { connection ->
|
||||
connection.prepareStatement(transactionUpdateQuery).also {
|
||||
DriverManager
|
||||
.getConnection(dbUrl, dbUser, dbPassword)
|
||||
.use { connection ->
|
||||
connection
|
||||
.prepareStatement(transactionUpdateQuery)
|
||||
.also {
|
||||
it.setString(1, request.transactionNumber)
|
||||
it.setString(2, request.pacsCurrentAccountNumber)
|
||||
it.setString(3, request.neftBeneficiaryAccountNumber)
|
||||
@ -121,68 +94,23 @@ class TransactionDao {
|
||||
it.setString(17, transferQueueNumber)
|
||||
it.setString(18, request.pacsAccountNumber)
|
||||
it.setString(19, neftQueueNumber)
|
||||
}.use {
|
||||
it.executeUpdate()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
fun getTransactionRequests(): List<TransactionRequest> {
|
||||
|
||||
val transactionList: List<TransactionRequest>
|
||||
val dbUrl = getDatabaseUrl()
|
||||
val (dbUser, dbPassword) = getUserCredentials()
|
||||
|
||||
DriverManager.getConnection(dbUrl, dbUser, dbPassword).use { connection ->
|
||||
connection.prepareStatement(transactionRequestQuery).executeQuery().use {
|
||||
transactionList = mapToObject(it)
|
||||
.use { it.executeUpdate() }
|
||||
}
|
||||
}
|
||||
|
||||
return transactionList
|
||||
}
|
||||
fun getTransactionRequest(transactionNumber: String): TransactionRequest? {
|
||||
val dbUrl = getDatabaseUrl()
|
||||
val (dbUser, dbPassword) = getUserCredentials()
|
||||
|
||||
return DriverManager.getConnection(dbUrl, dbUser, dbPassword).use { connection ->
|
||||
connection.prepareStatement(singleTransactionRequestQuery).apply {
|
||||
setString(1, transactionNumber)
|
||||
}.executeQuery().use {
|
||||
mapToObject(it).firstOrNull()
|
||||
return DriverManager
|
||||
.getConnection(dbUrl, dbUser, dbPassword)
|
||||
.use { connection ->
|
||||
connection
|
||||
.prepareStatement(singleTransactionRequestQuery)
|
||||
.apply { setString(1, transactionNumber) }
|
||||
.executeQuery()
|
||||
.use { mapToObject(it).firstOrNull() }
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun getDatabaseUrl(): String {
|
||||
val prop = loadProp()
|
||||
|
||||
val dbHost = getProp(prop, "DB_HOST")
|
||||
val dbPort = getProp(prop, "DB_PORT")
|
||||
val dbName = getProp(prop, "DB_NAME")
|
||||
|
||||
return "jdbc:oracle:thin:@$dbHost:$dbPort:$dbName"
|
||||
}
|
||||
|
||||
private fun getUserCredentials(): Pair<String, String> {
|
||||
val prop = loadProp()
|
||||
|
||||
val dbUser = getProp(prop, "DB_USER")
|
||||
val dbPassword = getProp(prop, "DB_PASSWORD")
|
||||
|
||||
return Pair(dbUser, dbPassword)
|
||||
}
|
||||
|
||||
private fun loadProp(): Properties {
|
||||
|
||||
val props = javaClass.classLoader.getResourceAsStream("application.properties").use {
|
||||
Properties().apply { load(it) }
|
||||
}
|
||||
return props
|
||||
}
|
||||
|
||||
private fun getProp(prop: Properties, key: String): String {
|
||||
return prop.getProperty(key) ?: throw RuntimeException("property $prop not found")
|
||||
}
|
||||
|
||||
private fun mapToObject(rs: ResultSet): List<TransactionRequest> {
|
||||
val list = mutableListOf<TransactionRequest>()
|
||||
@ -212,5 +140,4 @@ class TransactionDao {
|
||||
return list
|
||||
}
|
||||
|
||||
|
||||
}
|
17
src/main/resources/application-dev.conf
Normal file
17
src/main/resources/application-dev.conf
Normal file
@ -0,0 +1,17 @@
|
||||
database {
|
||||
host = "localhost"
|
||||
port = 1521
|
||||
name = "IPKSDB"
|
||||
user = "pacs_db"
|
||||
password = "pacs_db"
|
||||
}
|
||||
|
||||
bank {
|
||||
server {
|
||||
protocol = "http"
|
||||
host = "localhost"
|
||||
port = 8080
|
||||
rootRoute = "IPKS_Queue_Generation"
|
||||
transactionRoute = "IpksApi"
|
||||
}
|
||||
}
|
17
src/main/resources/application-prod.conf
Normal file
17
src/main/resources/application-prod.conf
Normal file
@ -0,0 +1,17 @@
|
||||
database {
|
||||
host = "ipksprod3.c7q7defafeea.ap-south-1.rds.amazonaws.com"
|
||||
port = 1521
|
||||
name = "IPKS"
|
||||
user = ${DB_USER}
|
||||
password = ${DB_PASSWORD}
|
||||
}
|
||||
|
||||
bank {
|
||||
server {
|
||||
protocol = "https"
|
||||
host = "180.179.110.185"
|
||||
port = 443
|
||||
rootRoute = "IPKS_Queue_Generation"
|
||||
transactionRoute = "IpksApi"
|
||||
}
|
||||
}
|
9
src/main/resources/application.conf
Normal file
9
src/main/resources/application.conf
Normal file
@ -0,0 +1,9 @@
|
||||
ktor {
|
||||
environment = ${KTOR_ENV}
|
||||
deployment {
|
||||
port = 8083
|
||||
}
|
||||
application {
|
||||
modules = [ net.ipksindia.ApplicationKt.module ]
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
DB_NAME=IPKS
|
||||
#DB_HOST=testipksdb.c7q7defafeea.ap-south-1.rds.amazonaws.com
|
||||
#DB_HOST=localhost
|
||||
DB_HOST=ipksprod3.c7q7defafeea.ap-south-1.rds.amazonaws.com
|
||||
DB_PORT=1521
|
||||
DB_USER=pacs_db
|
||||
DB_PASSWORD=pacs_db
|
Loading…
x
Reference in New Issue
Block a user