Merge pull request #2477 from medici/LA-265/navi-test-library
integrating navi test library for database queries
This commit is contained in:
@@ -39,7 +39,7 @@ RUN echo ${RELEASE_STORE_FILE} | base64 -d >> app/navi-release-key.jks
|
||||
RUN bash -c " \
|
||||
|
||||
if [ $FLAVOR = E2ETEST ] ; then \
|
||||
./gradlew clean :app:testDevDebugUnitTest --tests com.naviapp.CustomerDataCleanup -PtestType=\"e2e\" executeE2ETests; \
|
||||
./gradlew clean :app:testDevDebugUnitTest --tests com.naviapp.AndroidCustomerDataCleanup -PtestType=\"e2e\" executeE2ETests; \
|
||||
\
|
||||
elif [ $FLAVOR = DEV ] ; then \
|
||||
./gradlew clean \
|
||||
|
||||
@@ -322,7 +322,7 @@ dependencies {
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-web:3.2.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.2.0'
|
||||
|
||||
debugImplementation 'com.navi.medici.test-library:database-library:0.0.26-SNAPSHOT'
|
||||
androidTestImplementation('com.google.guava:guava:28.2-android') {
|
||||
exclude group: "com.google.code.findbugs", module: "jsr305"
|
||||
}
|
||||
|
||||
36
app/src/test/java/com/naviapp/AndroidCustomerDataCleanup.kt
Normal file
36
app/src/test/java/com/naviapp/AndroidCustomerDataCleanup.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.naviapp
|
||||
|
||||
import com.navi.test.common_library.RunEnvironment
|
||||
import com.navi.test.database_library.helpers.CustomerDataCleanup
|
||||
import com.naviapp.dbCore.Environment
|
||||
import com.naviapp.mock_setup.*
|
||||
import org.junit.Test
|
||||
|
||||
|
||||
class AndroidCustomerDataCleanup {
|
||||
|
||||
private val env = Environment.get()
|
||||
private val runEnv = RunEnvironment.fromString(env)
|
||||
|
||||
@Test
|
||||
fun cleanUpCustomer() {
|
||||
val cleanup = CustomerDataCleanup(runEnv)
|
||||
(20..35).forEach { cleanup.cleanUpCustomerByPhoneNumber("66666255$it") }
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun ckycMockSetup() {
|
||||
MockSetupHelper.enableCKYCMock(SearchAndDownloadComplete)
|
||||
println("SearchAndDownloadComplete phone: ${SearchAndDownloadComplete.phoneNumber}")
|
||||
MockSetupHelper.enableCKYCMock(CKYCSearchFail)
|
||||
println("CKYCSearchFail phone: ${CKYCSearchFail.phoneNumber}")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nsdlMockSetup() {
|
||||
MockSetupHelper.enableNSDlMock(NSDLHappyPath)
|
||||
println("NSDl Happy Path phone: ${SearchAndDownloadComplete.phoneNumber}")
|
||||
MockSetupHelper.enableNSDlMock(NSDLSourceDown)
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
package com.naviapp
|
||||
|
||||
import com.naviapp.dbCore.DatabaseWrapper
|
||||
import com.naviapp.dbCore.Environment
|
||||
import com.naviapp.dbCore.SuperAppDB
|
||||
import com.naviapp.dbCore.clients.CustomerReadDbClient
|
||||
import com.naviapp.dbCore.clients.CustomersDbClient
|
||||
import com.naviapp.dbCore.clients.LoanAccountsDbClient
|
||||
import com.naviapp.dbCore.constants.Databases
|
||||
import com.naviapp.mock_setup.*
|
||||
import org.junit.Test
|
||||
|
||||
|
||||
class CustomerDataCleanup {
|
||||
|
||||
private val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
|
||||
@Test
|
||||
fun cleanUpCustomer() {
|
||||
(20..35).forEach { cleanUpCustomerByPhoneNumber("66666255$it") }
|
||||
// NSDLMockType.allNSDLMockTypes.forEach { MockSetupHelper.enableNSDlMock(it) }
|
||||
// CKYCMockType.allCKYCMockTypes.forEach { MockSetupHelper.enableCKYCMock(it) }
|
||||
}
|
||||
|
||||
fun cleanUpCustomerByPhoneNumber(phoneNumber: String) {
|
||||
CustomerReadDbClient.cleanUpCustomerReadData(phoneNumber)
|
||||
val customerId = CustomersDbClient.getCustomerReferenceId(phoneNumber)
|
||||
if (customerId.isNotEmpty() || customerId.isNotBlank()) {
|
||||
LoanAccountsDbClient.cleanUpLoanAccountsForCustomerId(customerId)
|
||||
CustomersDbClient.cleanUpCustomerData(phoneNumber)
|
||||
}
|
||||
cleanUpCustomerInSuperAppByPhoneNumber(phoneNumber)
|
||||
}
|
||||
|
||||
private fun cleanUpCustomerInSuperAppByPhoneNumber(phoneNumber: String) {
|
||||
dbWrapper.execute(
|
||||
Databases.SA_CUSTOMER,
|
||||
listOf(
|
||||
SAQueries.deleteCustomerDevicesForPhoneNumberFromSA(phoneNumber),
|
||||
SAQueries.deleteEntryFromSACustomersTableByPhoneNumber(phoneNumber)
|
||||
),
|
||||
SuperAppDB
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun ckycMockSetup() {
|
||||
MockSetupHelper.enableCKYCMock(SearchAndDownloadComplete)
|
||||
println("SearchAndDownloadComplete phone: ${SearchAndDownloadComplete.phoneNumber}")
|
||||
MockSetupHelper.enableCKYCMock(CKYCSearchFail)
|
||||
println("CKYCSearchFail phone: ${CKYCSearchFail.phoneNumber}")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nsdlMockSetup() {
|
||||
MockSetupHelper.enableNSDlMock(NSDLHappyPath)
|
||||
println("NSDl Happy Path phone: ${SearchAndDownloadComplete.phoneNumber}")
|
||||
MockSetupHelper.enableNSDlMock(NSDLSourceDown)
|
||||
}
|
||||
|
||||
|
||||
private object SAQueries {
|
||||
fun deleteCustomerDevicesForPhoneNumberFromSA(phoneNumber: String) =
|
||||
"DELETE FROM customer_devices WHERE customer_id = (SELECT id FROM customers WHERE phone_number = '$phoneNumber');"
|
||||
|
||||
fun deleteEntryFromSACustomersTableByPhoneNumber(phoneNumber: String) =
|
||||
"DELETE FROM customers WHERE phone_number = '$phoneNumber';"
|
||||
}
|
||||
|
||||
|
||||
// fun getRandomMockedPhoneNumber(): String {
|
||||
// var phoneNumber: String
|
||||
//
|
||||
// do phoneNumber = "55555${generateDigits(5)}"
|
||||
// while (phoneNumber.contains("55555555"))
|
||||
//
|
||||
// return phoneNumber
|
||||
// }
|
||||
|
||||
// fun generateDigits(n: Int): Long {
|
||||
// val m = 10.0.pow(n - 1.toDouble()).toLong()
|
||||
// return m + Random.nextLong(9 * m)
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// fun `Mock Data Setup for Name mismatch`() {
|
||||
// val appVersionCode = "73"
|
||||
// val androidVersion = "Android_10"
|
||||
// val phoneNumber = mockDataPhoneNumber.e2e.phoneNumberMockNameMismatch
|
||||
// val newCustomerReferenceId: String = MockReferenceIds.ReferenceIdNameMismatch
|
||||
// val deviceId = generateDigits(16).toString()
|
||||
// val sessionToken: String
|
||||
// with(OtpClient(phoneNumber, deviceId, appVersionCode, androidVersion)) {
|
||||
// registerDevice()
|
||||
// sessionToken = getSessionToken()
|
||||
// }
|
||||
// var customerReferenceId: String = CustomersDbClient.getCustomerReferenceId(phoneNumber)
|
||||
// CustomersDbClient.updateCustomerReferenceId(newCustomerReferenceId,customerReferenceId)
|
||||
// AuthServiceDbClient.updateCustomerReferenceId(newCustomerReferenceId,customerReferenceId)
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// fun `Mock Data Setup for Same Name`() {
|
||||
// val appVersionCode = "73"
|
||||
// val androidVersion = "Android_10"
|
||||
// val phoneNumber = mockDataPhoneNumber.e2e.phoneNumberMockSameName
|
||||
// val newCustomerReferenceId: String = MockReferenceIds.ReferenceIdSameName
|
||||
// val deviceId = generateDigits(16).toString()
|
||||
// var sessionToken: String
|
||||
// with(OtpClient(phoneNumber, deviceId, appVersionCode, androidVersion)) {
|
||||
// registerDevice()
|
||||
// sessionToken = getSessionToken()
|
||||
// }
|
||||
// val customerReferenceId: String = CustomersDbClient.getCustomerReferenceId(phoneNumber)
|
||||
// CustomersDbClient.updateCustomerReferenceId(newCustomerReferenceId,customerReferenceId)
|
||||
// AuthServiceDbClient.updateCustomerReferenceId(newCustomerReferenceId,customerReferenceId)
|
||||
//
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// fun BrowserStackRun(){
|
||||
// print("Uploading and Running the tests on browserStack")
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.naviapp.dbCore
|
||||
|
||||
data class DatabaseConfiguration(
|
||||
val db: String,
|
||||
var url: String,
|
||||
val userName: String,
|
||||
val password: String,
|
||||
val port: Int
|
||||
)
|
||||
|
||||
interface DB {
|
||||
val asString: String
|
||||
}
|
||||
|
||||
object LendingDB : DB {
|
||||
override val asString: String = "LENDING_DB"
|
||||
}
|
||||
|
||||
object SuperAppDB : DB {
|
||||
override val asString: String = "SUPER_APP_DB"
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package com.naviapp.dbCore
|
||||
|
||||
import com.naviapp.common.JsonParser
|
||||
import com.naviapp.common.PathConstants
|
||||
import java.nio.file.Paths
|
||||
import java.sql.Connection
|
||||
import java.sql.DriverManager
|
||||
import java.sql.ResultSet
|
||||
import java.sql.Statement
|
||||
import java.util.*
|
||||
|
||||
class DatabaseWrapper(private val environment: String) {
|
||||
|
||||
private val excludeTables = listOf("databasechangelog", "databasechangeloglock")
|
||||
private lateinit var dbConfigurationList: List<DatabaseConfiguration>
|
||||
|
||||
fun execute(dbName: String, sqlStatements: List<String>, db: DB = LendingDB) {
|
||||
try {
|
||||
val dataSource = getConnection(dbName, db)
|
||||
dataSource.use { connection -> sqlStatements.forEach { getSqlStatement(connection, it).execute(it) } }
|
||||
} catch (error: Exception) {
|
||||
throw Error(error)
|
||||
}
|
||||
}
|
||||
|
||||
fun getResultSet(dbName: String, sqlStatement: String, db: DB = LendingDB): ResultSet {
|
||||
try {
|
||||
val dataSource = getConnection(dbName, db)
|
||||
dataSource.use { connection -> return getSqlStatement(connection, sqlStatement).executeQuery(sqlStatement) }
|
||||
} catch (error: Exception) {
|
||||
throw Error(error)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getConnection(dbName: String, db: DB): Connection {
|
||||
val propertiesMap = getConnectionProperties()
|
||||
|
||||
val dbConfiguration = dbConfigurationList.find {
|
||||
it.db == db.asString
|
||||
} ?: throw Exception("DB config is null, please verify DatabaseConfiguration.json files")
|
||||
|
||||
val dataBase = if (environment.equals("automation", ignoreCase = true)) {
|
||||
dbName.replace("_automation", "")
|
||||
} else dbName
|
||||
|
||||
return DriverManager.getConnection(
|
||||
"${dbConfiguration.url}:${dbConfiguration.port}/$dataBase",
|
||||
propertiesMap[dbConfiguration.db]
|
||||
)
|
||||
}
|
||||
|
||||
private fun getSqlStatement(connection: Connection, sqlStatement: String): Statement =
|
||||
(if (sqlStatement.contains(excludeTables.component1()) || sqlStatement.contains(excludeTables.component2())) {
|
||||
null
|
||||
} else connection.createStatement()) ?: throw Exception("SQL statement is null")
|
||||
|
||||
private fun getConnectionProperties(): Map<String, Properties> {
|
||||
try {
|
||||
val dbConfigFilePath =
|
||||
when (environment.toLowerCase()) {
|
||||
"qa" -> "QaDbConfiguration.json"
|
||||
"localhost" -> "LocalHostDbConfiguration.json"
|
||||
else -> {
|
||||
"DatabaseConfiguration.json"
|
||||
}
|
||||
}
|
||||
|
||||
val propertiesMap: MutableMap<String, Properties> = emptyMap<String, Properties>().toMutableMap()
|
||||
|
||||
val dbConfigPath = Paths.get(PathConstants.srcResourcesDirectory, dbConfigFilePath).toString()
|
||||
dbConfigurationList = JsonParser.getData(dbConfigPath)
|
||||
dbConfigurationList.forEach{
|
||||
it.url = it.url.replace("PLACEHOLDER", environment)
|
||||
|
||||
val properties = Properties()
|
||||
properties.setProperty("user", it.userName)
|
||||
properties.setProperty("password", it.password)
|
||||
propertiesMap[it.db] = properties
|
||||
}
|
||||
return propertiesMap.toMap()
|
||||
} catch (error: Exception) {
|
||||
throw error(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
package com.naviapp.dbCore
|
||||
|
||||
const val DEV = "dev"
|
||||
const val QA = "qa"
|
||||
const val DEV = "dev"
|
||||
const val QA = "qa"
|
||||
|
||||
object Environment {
|
||||
|
||||
private var environment: String? = null
|
||||
private var environment: String? = null
|
||||
|
||||
fun get(): String = environment ?: DEV
|
||||
fun get(): String = environment ?: DEV
|
||||
|
||||
fun set(value: String) {
|
||||
environment = value
|
||||
}
|
||||
fun set(value: String) {
|
||||
environment = value
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.naviapp.dbCore.clients
|
||||
|
||||
import com.naviapp.dbCore.DatabaseWrapper
|
||||
import com.naviapp.dbCore.Environment
|
||||
import com.naviapp.dbCore.constants.AuthDbQueries
|
||||
import com.naviapp.dbCore.constants.CleanupQueries
|
||||
import com.naviapp.dbCore.constants.Databases
|
||||
|
||||
object AuthServiceDbClient {
|
||||
|
||||
fun deleteCustomer(phoneNumber: String) {
|
||||
val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
|
||||
val deletePhoneNumberInAuthService =
|
||||
CleanupQueries.CustomersCleanup.DeleteCustomerInAuthService.replace("PLACEHOLDER", phoneNumber)
|
||||
|
||||
dbWrapper.execute(Databases.AuthService, listOf(deletePhoneNumberInAuthService))
|
||||
}
|
||||
|
||||
fun updateCustomerReferenceId(newCustomerReferenceId: String,customerReferenceId: String){
|
||||
val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
val updateReferenceId = AuthDbQueries.updateCustomerReferenceId.replace("NEWPLACEHOLDER",newCustomerReferenceId)
|
||||
.replace("PLACEHOLDER", customerReferenceId)
|
||||
dbWrapper.execute(
|
||||
Databases.AuthService, listOf(updateReferenceId)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.naviapp.dbCore.clients
|
||||
|
||||
import com.naviapp.dbCore.DatabaseWrapper
|
||||
import com.naviapp.dbCore.Environment
|
||||
import com.naviapp.dbCore.constants.CleanupQueries
|
||||
import com.naviapp.dbCore.constants.CustomerDbQueries
|
||||
import com.naviapp.dbCore.constants.Databases
|
||||
|
||||
object CreditDecisionClient {
|
||||
|
||||
fun deleteCreditDecisionDataForCustomer(customerReferenceId: String) {
|
||||
val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
|
||||
val underwritingIdQuery =
|
||||
CustomerDbQueries.GetUnderwritingId.replace("PLACEHOLDER", customerReferenceId)
|
||||
|
||||
val underwritingResponse =
|
||||
dbWrapper.getResultSet(Databases.CreditUnderwriting, underwritingIdQuery)
|
||||
|
||||
var underwritingId = ""
|
||||
|
||||
val underwritingIdPresent = underwritingResponse?.next() ?: false
|
||||
if (underwritingIdPresent) {
|
||||
underwritingId =
|
||||
underwritingResponse?.getString("underwriting_id") ?: throw error("Underwriting Id is null")
|
||||
}
|
||||
|
||||
val deleteFeaturesQuery =
|
||||
CleanupQueries.CustomersCleanup.DeleteFeatures.replace("PLACEHOLDER", underwritingId)
|
||||
|
||||
val deleteUnderWritingQuery =
|
||||
CleanupQueries.CustomersCleanup.DeleteUnderwritingId.replace("PLACEHOLDER", customerReferenceId)
|
||||
|
||||
dbWrapper.execute(
|
||||
Databases.CreditUnderwriting, listOf(
|
||||
deleteFeaturesQuery,
|
||||
deleteUnderWritingQuery
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
package com.naviapp.dbCore.clients
|
||||
|
||||
import com.naviapp.dbCore.DatabaseWrapper
|
||||
import com.naviapp.dbCore.Environment
|
||||
import com.naviapp.dbCore.constants.CleanupQueries
|
||||
import com.naviapp.dbCore.constants.CustomerDbQueries
|
||||
import com.naviapp.dbCore.constants.Databases
|
||||
|
||||
object CustomerReadDbClient {
|
||||
|
||||
fun cleanUpCustomerReadData(phoneNumber: String) {
|
||||
val customerId = getCustomerId(phoneNumber)
|
||||
customerId.forEach { i ->
|
||||
deleteCustomerStatusData(i)
|
||||
}
|
||||
val customerReferenceId = getCustomerReferenceId(phoneNumber)
|
||||
customerReferenceId.forEach { i ->
|
||||
deleteCustomerData(phoneNumber, i)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCustomerId(phoneNumber: String): MutableList<String> {
|
||||
val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
val customerIdList: MutableList<String> = mutableListOf()
|
||||
val getCustomerId = CustomerDbQueries.GetCustomerIdMatchingPhoneNumber
|
||||
.replace("PLACEHOLDER", phoneNumber)
|
||||
|
||||
val customerId = dbWrapper.getResultSet(Databases.CustomerRead, getCustomerId)
|
||||
while (customerId?.next()!!) {
|
||||
var i = 0
|
||||
customerIdList.add(i, customerId?.getString("id"))
|
||||
i++
|
||||
}
|
||||
return customerIdList
|
||||
}
|
||||
|
||||
|
||||
private fun deleteCustomerStatusData(customerId: String) {
|
||||
val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
|
||||
val deleteCustomerStatusQuery =
|
||||
CleanupQueries.CustomerReadCleanup.DeleteCustomerStatus.replace("PLACEHOLDER", customerId)
|
||||
|
||||
dbWrapper.execute(
|
||||
Databases.CustomerRead, listOf(
|
||||
deleteCustomerStatusQuery
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
fun getCustomerReferenceId(phoneNumber: String): MutableList<String> {
|
||||
val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
val customerReferenceId: MutableList<String> = mutableListOf()
|
||||
val getCustomerReferenceId = CustomerDbQueries.GetCustomerReferenceIdMatchingPhoneNumber
|
||||
.replace("PLACEHOLDER", phoneNumber)
|
||||
|
||||
val customerId = dbWrapper.getResultSet(Databases.CustomerRead, getCustomerReferenceId)
|
||||
while (customerId?.next()!!) {
|
||||
var i = 0
|
||||
customerReferenceId.add(i, customerId?.getString("reference_id"))
|
||||
i++
|
||||
}
|
||||
return customerReferenceId
|
||||
}
|
||||
|
||||
private fun deleteCustomerData(phoneNumber: String, customerReferenceId: String) {
|
||||
val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
|
||||
val deleteLookupCustomerQuery =
|
||||
CleanupQueries.CustomerReadCleanup.DeleteLookupCustomers.replace("PLACEHOLDER", customerReferenceId)
|
||||
|
||||
val deleteCustomerQuery =
|
||||
CleanupQueries.CustomerReadCleanup.DeleteCustomers.replace("PLACEHOLDER", phoneNumber)
|
||||
|
||||
dbWrapper.execute(
|
||||
Databases.CustomerRead, listOf(
|
||||
deleteLookupCustomerQuery,
|
||||
deleteCustomerQuery
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,134 +0,0 @@
|
||||
package com.naviapp.dbCore.clients
|
||||
|
||||
import com.naviapp.dbCore.DatabaseWrapper
|
||||
import com.naviapp.dbCore.Environment
|
||||
import com.naviapp.dbCore.constants.CleanupQueries
|
||||
import com.naviapp.dbCore.constants.CustomerDbQueries
|
||||
import com.naviapp.dbCore.constants.Databases
|
||||
|
||||
object CustomersDbClient {
|
||||
|
||||
private val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
|
||||
fun getCustomerReferenceId(phoneNumber: String): String {
|
||||
|
||||
val getCustomerId = CustomerDbQueries.GetCustomerReferenceIdMatchingPhoneNumber
|
||||
.replace("PLACEHOLDER", phoneNumber)
|
||||
|
||||
val customerId = dbWrapper.getResultSet(Databases.Customer, getCustomerId)
|
||||
val customerIdFound = customerId?.next() ?: false
|
||||
return if (customerIdFound) customerId?.getString("reference_id")
|
||||
?: throw error("Customer Id is null for $phoneNumber")
|
||||
else ""
|
||||
}
|
||||
|
||||
fun cleanUpCustomerData(phoneNumber: String) {
|
||||
val customerId = getCustomerId(phoneNumber)
|
||||
val customerReferenceId = getCustomerReferenceId(phoneNumber)
|
||||
|
||||
LoanOriginationManagerClient.cleanUpLoanApplicationAndOfferData(customerReferenceId)
|
||||
MASDbClient.deleteStatusesForCustomer(customerReferenceId)
|
||||
deleteCustomerData(customerId.toString(), customerReferenceId)
|
||||
AuthServiceDbClient.deleteCustomer(phoneNumber)
|
||||
}
|
||||
|
||||
private fun getCustomerId(phoneNumber: String): Int {
|
||||
try {
|
||||
val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
val getCustomerId = CustomerDbQueries.GetCustomerIdMatchingPhoneNumber
|
||||
.replace("PLACEHOLDER", phoneNumber)
|
||||
|
||||
val customerId = dbWrapper.getResultSet(Databases.Customer, getCustomerId)
|
||||
val customerIdFound = customerId?.next() ?: false
|
||||
return if (customerIdFound) {
|
||||
customerId?.getInt("id") ?: throw error("Customer Id is null for $phoneNumber")
|
||||
} else {
|
||||
throw error("Customer not fond. $phoneNumber")
|
||||
}
|
||||
} catch (error: Exception) {
|
||||
throw error(error)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getCustomerIdByPhoneNumber(phoneNumber: String): Int {
|
||||
try {
|
||||
val getCustomerId = CustomerDbQueries.GetCustomerIdMatchingPhoneNumber
|
||||
.replace("PLACEHOLDER", phoneNumber)
|
||||
|
||||
val customerId = dbWrapper.getResultSet(Databases.Customer, getCustomerId)
|
||||
val customerIdFound = customerId.next()
|
||||
return if (customerIdFound) {
|
||||
customerId.getInt("id")
|
||||
} else {
|
||||
throw error("Customer not fond. $phoneNumber")
|
||||
}
|
||||
} catch (error: Exception) {
|
||||
throw error(error)
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteCustomerData(customerId: String, customerReferenceId: String) {
|
||||
val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
|
||||
val deleteDocumentsQuery =
|
||||
CleanupQueries.CustomersCleanup
|
||||
.DeleteDocumentsFromCustomersTable.replace(
|
||||
"PLACEHOLDER", customerId
|
||||
)
|
||||
|
||||
val deleteStatusesQuery =
|
||||
CleanupQueries.CustomersCleanup.DeleteStatuses.replace("PLACEHOLDER", customerId)
|
||||
|
||||
val deleteBankAccountsQuery =
|
||||
CleanupQueries.CustomersCleanup.DeleteBankAccounts.replace("PLACEHOLDER", customerId)
|
||||
|
||||
val deleteAddressesQuery =
|
||||
CleanupQueries.CustomersCleanup.DeleteAddresses.replace("PLACEHOLDER", customerId)
|
||||
|
||||
val deleteCustomerQuery =
|
||||
CleanupQueries.CustomersCleanup.DeleteCustomer.replace("PLACEHOLDER", customerReferenceId)
|
||||
|
||||
val deleteCustomerDevices =
|
||||
CleanupQueries.CustomersCleanup.DeleteCustomerDevices.replace("PLACEHOLDER", customerId)
|
||||
|
||||
val deleteExcessPaymentsQuery =
|
||||
CleanupQueries.CustomersCleanup.DeleteExcessPayments.replace("PLACEHOLDER", customerReferenceId)
|
||||
|
||||
val deleteExternalId =
|
||||
CleanupQueries.CustomersCleanup.DeleteExternalId.replace("PLACEHOLDER",customerId)
|
||||
|
||||
val deleteBankStatementReports =
|
||||
CleanupQueries.CustomersCleanup.DeleteBankStatementReports.replace("PLACEHOLDER", customerReferenceId)
|
||||
|
||||
|
||||
dbWrapper.execute(
|
||||
Databases.Customer, listOf(
|
||||
deleteDocumentsQuery,
|
||||
deleteBankAccountsQuery,
|
||||
deleteAddressesQuery,
|
||||
deleteStatusesQuery,
|
||||
deleteCustomerDevices,
|
||||
deleteExcessPaymentsQuery,
|
||||
deleteExternalId,
|
||||
deleteBankStatementReports
|
||||
)
|
||||
)
|
||||
|
||||
if (customerId.toInt() > 100) {
|
||||
dbWrapper.execute(
|
||||
Databases.Customer, listOf(deleteCustomerQuery)
|
||||
)
|
||||
|
||||
CreditDecisionClient.deleteCreditDecisionDataForCustomer(customerReferenceId)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateCustomerReferenceId(newCustomerReferenceId: String,customerReferenceId: String){
|
||||
val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
val updateReferenceId = CustomerDbQueries.updateCustomerReferenceId
|
||||
.replace("NEWPLACEHOLDER", newCustomerReferenceId).replace("PLACEHOLDER",customerReferenceId)
|
||||
dbWrapper.execute(
|
||||
Databases.Customer, listOf(updateReferenceId)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,233 +0,0 @@
|
||||
package com.naviapp.dbCore.clients
|
||||
|
||||
import com.naviapp.dbCore.DatabaseWrapper
|
||||
import com.naviapp.dbCore.Environment
|
||||
import com.naviapp.dbCore.constants.CleanupQueries
|
||||
import com.naviapp.dbCore.constants.Databases
|
||||
import org.shadow.apache.commons.lang3.StringUtils
|
||||
|
||||
object LoanAccountsDbClient {
|
||||
|
||||
fun cleanUpLoanAccountsForCustomerId(customerId: String) {
|
||||
val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
val loanAccounts = mutableListOf<String>()
|
||||
val schedules = mutableListOf<String>()
|
||||
|
||||
val deleteInvoiceLineItemsQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteInvoiceLineItems.replace("PLACEHOLDER", customerId)
|
||||
val deleteInvoicesQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteInvoices.replace("PLACEHOLDER", customerId)
|
||||
|
||||
val getLoanAccountsQuery = CleanupQueries.LoanAccountsCleanup.GetLoanAccountMatchingCustomerId
|
||||
.replace("PLACEHOLDER", customerId)
|
||||
|
||||
val loanAccountResultSet = dbWrapper.getResultSet(Databases.LoanAccounts, getLoanAccountsQuery)
|
||||
|
||||
if (loanAccountResultSet != null) {
|
||||
|
||||
while (loanAccountResultSet.next()) {
|
||||
loanAccounts.add(loanAccountResultSet.getString("id"))
|
||||
}
|
||||
|
||||
|
||||
loanAccounts.forEach {
|
||||
val loanAccountId = it
|
||||
val dueIds = mutableListOf<String>()
|
||||
val dueComponentIds = mutableListOf<String>()
|
||||
|
||||
val deleteLoanAccountQuery = CleanupQueries.LoanAccountsCleanup.DeleteLoanAccountMatchingId
|
||||
.replace("PLACEHOLDER", loanAccountId)
|
||||
|
||||
val deleteProcessingFeeAmortizationsEntry =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteProcessingFeeAmortizationsEntry
|
||||
.replace("PLACEHOLDER", loanAccountId)
|
||||
|
||||
val deleteDisbursementEntry =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteDisbursementsTableMatchingLoanAccountId
|
||||
.replace("PLACEHOLDER", loanAccountId)
|
||||
|
||||
val deleteRefundsEntry =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteRefundsTableMatchingLoanAccountId
|
||||
.replace("PLACEHOLDER", loanAccountId)
|
||||
|
||||
val deleteAddOnEntry =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteAddOnTableMatchingLoanAccountId
|
||||
.replace("PLACEHOLDER", loanAccountId)
|
||||
|
||||
val deleteRepaymentsQuery = CleanupQueries.LoanAccountsCleanup.DeleteRepaymentsMatchingLoanAccountId
|
||||
.replace("PLACEHOLDER", loanAccountId)
|
||||
|
||||
val deleteAmortizationSchedulesQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteAmortizationScheduleForMatchingLoanAccountId
|
||||
.replace("PLACEHOLDER", loanAccountId)
|
||||
|
||||
val deleteFeeAmortizationQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteFeeAmortizationSchedulesMatchingLoanAccountId
|
||||
.replace("PLACEHOLDER", loanAccountId)
|
||||
|
||||
val deleteInterestHistoriesQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteInterestHistoriesQueryMatchingLoanAccountId
|
||||
.replace("PLACEHOLDER", loanAccountId)
|
||||
|
||||
val deleteInterestAccrualEntriesQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteInterestAccrualEntriesSummary.replace(
|
||||
"PLACEHOLDER",
|
||||
loanAccountId
|
||||
)
|
||||
|
||||
val deleteCapitalizedInterestsQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteCapitalizedInterests.replace("PLACEHOLDER", loanAccountId)
|
||||
dbWrapper.execute(Databases.LoanAccounts, listOf(deleteCapitalizedInterestsQuery))
|
||||
|
||||
val deleteInterestSummaryQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteInterestSummary.replace("PLACEHOLDER", loanAccountId)
|
||||
|
||||
val getScheduleIdQuery = CleanupQueries.LoanAccountsCleanup.GetScheduleIdMatchingLoanAccountId.replace(
|
||||
"PLACEHOLDER",
|
||||
loanAccountId
|
||||
)
|
||||
val getScheduleIdResultSet = dbWrapper.getResultSet(Databases.LoanAccounts, getScheduleIdQuery)
|
||||
if (getScheduleIdResultSet != null) {
|
||||
while (getScheduleIdResultSet.next()) {
|
||||
schedules.add(getScheduleIdResultSet.getString("id"))
|
||||
}
|
||||
}
|
||||
schedules.forEach {
|
||||
val deleteScheduleItemsTableEntryQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteScheduleItemsMatchingScheduleId.replace(
|
||||
"PLACEHOLDER",
|
||||
it
|
||||
)
|
||||
dbWrapper.execute(Databases.LoanAccounts, listOf(deleteScheduleItemsTableEntryQuery))
|
||||
}
|
||||
|
||||
val deleteSchedulesEntryQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteSchedulesTableMatchingLoanAccountId.replace(
|
||||
"PLACEHOLDER",
|
||||
loanAccountId
|
||||
)
|
||||
|
||||
val deleteRescheduleRequestQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteRescheduleRequest.replace(
|
||||
"PLACEHOLDER",
|
||||
loanAccountId
|
||||
)
|
||||
|
||||
val deleteDefermentRequestQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteDefermentRequest.replace(
|
||||
"PLACEHOLDER",
|
||||
loanAccountId
|
||||
)
|
||||
|
||||
val deleteExcessAllocationQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteExcessAllocationsRequest.replace(
|
||||
"PLACEHOLDER",
|
||||
loanAccountId
|
||||
)
|
||||
|
||||
val deleteRepaymentRequestQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteRepaymentRequest.replace(
|
||||
"PLACEHOLDER",
|
||||
loanAccountId
|
||||
)
|
||||
|
||||
val deleteLoanCampaignsQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteLoanCampaignsRequest.replace(
|
||||
"PLACEHOLDER",
|
||||
loanAccountId
|
||||
)
|
||||
|
||||
val deleteLoanAccountsForCustomerQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteLoanAccountsMatchingCustomerReferenceId.replace(
|
||||
"PLACEHOLDER",
|
||||
customerId
|
||||
)
|
||||
|
||||
val dueIdsResultSet = dbWrapper.getResultSet(
|
||||
Databases.LoanAccounts,
|
||||
CleanupQueries.LoanAccountsCleanup.GetDueIdsMatchingLoanAccounts.replace(
|
||||
"PLACEHOLDER",
|
||||
loanAccountId
|
||||
)
|
||||
)
|
||||
|
||||
while (dueIdsResultSet?.next() ?: throw error("Error")) {
|
||||
dueIds.add(dueIdsResultSet.getString("id"))
|
||||
}
|
||||
|
||||
if (dueIds.isNotEmpty()) {
|
||||
val dueIdsToQueryDueComponents = StringUtils.join(dueIds, ",")
|
||||
|
||||
val dueComponentIdsResultSet = dbWrapper.getResultSet(
|
||||
Databases.LoanAccounts,
|
||||
CleanupQueries.LoanAccountsCleanup.GetDueComponentIdsMatchingDueId.replace(
|
||||
"PLACEHOLDER",
|
||||
dueIdsToQueryDueComponents
|
||||
)
|
||||
)
|
||||
|
||||
while (dueComponentIdsResultSet?.next() ?: throw error("Error")) {
|
||||
dueComponentIds.add(dueComponentIdsResultSet.getString("id"))
|
||||
}
|
||||
|
||||
if (dueComponentIds.isNotEmpty()) {
|
||||
|
||||
val deleteComponentAdjustmentsMatchingDueComponents =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteComponentAdjustmentsMatchingDueComponents
|
||||
.replace("PLACEHOLDER", StringUtils.join(dueComponentIds, ","))
|
||||
|
||||
val repaymentEntriesDeleteQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteRepaymentEntriesMatchingDueEntries.replace(
|
||||
"PLACEHOLDER",
|
||||
StringUtils.join(dueComponentIds, ",")
|
||||
)
|
||||
|
||||
val dueComponentsDeleteQuery =
|
||||
CleanupQueries.LoanAccountsCleanup.DeleteDueComponentsMatchingDues
|
||||
.replace("PLACEHOLDER", dueIdsToQueryDueComponents)
|
||||
|
||||
val duesDeleteQuery = CleanupQueries.LoanAccountsCleanup.DeleteDuesMatchingLoanAccountId
|
||||
.replace("PLACEHOLDER", loanAccountId)
|
||||
dbWrapper.execute(
|
||||
Databases.LoanAccounts, listOf(
|
||||
deleteAddOnEntry,
|
||||
deleteDisbursementEntry,
|
||||
repaymentEntriesDeleteQuery,
|
||||
deleteComponentAdjustmentsMatchingDueComponents,
|
||||
dueComponentsDeleteQuery,
|
||||
duesDeleteQuery
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
dbWrapper.execute(
|
||||
Databases.LoanAccounts, listOf(
|
||||
deleteAmortizationSchedulesQuery,
|
||||
deleteFeeAmortizationQuery,
|
||||
deleteRescheduleRequestQuery,
|
||||
deleteDefermentRequestQuery,
|
||||
deleteExcessAllocationQuery,
|
||||
deleteRepaymentRequestQuery,
|
||||
deleteRefundsEntry,
|
||||
deleteLoanCampaignsQuery,
|
||||
deleteRepaymentsQuery,
|
||||
deleteAddOnEntry,
|
||||
deleteDisbursementEntry,
|
||||
deleteProcessingFeeAmortizationsEntry,
|
||||
deleteCapitalizedInterestsQuery,
|
||||
deleteSchedulesEntryQuery,
|
||||
deleteInterestHistoriesQuery,
|
||||
deleteLoanAccountQuery,
|
||||
deleteInterestAccrualEntriesQuery,
|
||||
deleteInterestSummaryQuery,
|
||||
deleteInvoiceLineItemsQuery,
|
||||
deleteInvoicesQuery
|
||||
)
|
||||
)
|
||||
|
||||
dbWrapper.execute(Databases.Customer, listOf(deleteLoanAccountsForCustomerQuery))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
package com.naviapp.dbCore.clients
|
||||
|
||||
import com.naviapp.dbCore.DatabaseWrapper
|
||||
import com.naviapp.dbCore.Environment
|
||||
import com.naviapp.dbCore.constants.CleanupQueries
|
||||
import com.naviapp.dbCore.constants.CustomerDbQueries
|
||||
import com.naviapp.dbCore.constants.Databases
|
||||
|
||||
object LoanOriginationManagerClient {
|
||||
|
||||
fun cleanUpLoanApplicationAndOfferData(customerReferenceId: String) {
|
||||
val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
|
||||
val loanApplicationId = getLoanApplicationId(customerReferenceId)
|
||||
|
||||
val deleteLoanApplicationStatusesQuery =
|
||||
CleanupQueries.CustomersCleanup.DeleteLoanApplicationStatuses.replace("PLACEHOLDER", loanApplicationId)
|
||||
|
||||
val deleteDocumentsQuery =
|
||||
CleanupQueries.CustomersCleanup.DeleteCustomerDocuments.replace("PLACEHOLDER", customerReferenceId)
|
||||
|
||||
val deleteAgreementsQuery =
|
||||
CleanupQueries.CustomersCleanup.DeleteAgreements.replace("PLACEHOLDER", customerReferenceId)
|
||||
|
||||
val deleteLoanApplicationsQuery =
|
||||
CleanupQueries.CustomersCleanup.DeleteLoanApplications.replace("PLACEHOLDER", customerReferenceId)
|
||||
|
||||
val deleteLoanOffersQuery =
|
||||
CleanupQueries.CustomersCleanup.DeleteLoanOffers.replace("PLACEHOLDER", customerReferenceId)
|
||||
|
||||
val deleteLoanOfferRejectionsQuery =
|
||||
CleanupQueries.CustomersCleanup.DeleteLoanOfferRejections.replace("PLACEHOLDER", customerReferenceId)
|
||||
|
||||
dbWrapper.execute(
|
||||
Databases.LoanOriginationManager, listOf(
|
||||
deleteDocumentsQuery,
|
||||
deleteAgreementsQuery,
|
||||
deleteLoanApplicationsQuery,
|
||||
deleteLoanOffersQuery,
|
||||
deleteLoanOfferRejectionsQuery
|
||||
)
|
||||
)
|
||||
|
||||
if (loanApplicationId.isNotBlank() || loanApplicationId.isNotEmpty()) {
|
||||
dbWrapper.execute(
|
||||
Databases.LoanOriginationManager, listOf(deleteLoanApplicationStatusesQuery)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getLoanApplicationId(customerReferenceId: String): String {
|
||||
val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
|
||||
|
||||
val loanApplicationIdQuery =
|
||||
CustomerDbQueries.GetLoanApplicationId.replace("PLACEHOLDER", customerReferenceId)
|
||||
|
||||
val loanApplicationResponse =
|
||||
dbWrapper.getResultSet(Databases.LoanOriginationManager, loanApplicationIdQuery)
|
||||
|
||||
val loanApplicationIdPresent = loanApplicationResponse?.next()
|
||||
return if (loanApplicationIdPresent == true)
|
||||
loanApplicationResponse.getString("id") ?: throw error("Loan Application Id is null")
|
||||
else ""
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.naviapp.dbCore.clients
|
||||
|
||||
import com.naviapp.dbCore.DatabaseWrapper
|
||||
import com.naviapp.dbCore.Environment
|
||||
import com.naviapp.dbCore.constants.CleanupQueries
|
||||
import com.naviapp.dbCore.constants.Databases
|
||||
|
||||
object MASDbClient {
|
||||
|
||||
fun deleteStatusesForCustomer(customerReferenceId: String) {
|
||||
val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
|
||||
val deleteStatusesFromMobileApplicationQuery =
|
||||
CleanupQueries.CustomersCleanup.DeleteStatuses.replace("PLACEHOLDER", "'$customerReferenceId'")
|
||||
|
||||
dbWrapper.execute(
|
||||
Databases.MobileApplication, listOf(deleteStatusesFromMobileApplicationQuery)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.naviapp.dbCore.constants
|
||||
|
||||
object AuthDbQueries {
|
||||
const val updateCustomerReferenceId =
|
||||
"update users set customer_reference_id = 'NEWPLACEHOLDER' where customer_reference_id = 'PLACEHOLDER'"
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
package com.naviapp.dbCore.constants
|
||||
|
||||
object CleanupQueries {
|
||||
|
||||
object CustomerReadCleanup {
|
||||
const val DeleteLookupCustomers = "DELETE FROM lookup_customers WHERE customer_reference_id = 'PLACEHOLDER'"
|
||||
const val DeleteLoanAccounts = "DELETE FROM loan_accounts WHERE customer_reference_id = 'PLACEHOLDER'"
|
||||
const val DeleteCustomers = "DELETE FROM customers WHERE phone_number = 'PLACEHOLDER'"
|
||||
const val DeleteCustomerStatus = "DELETE FROM customer_statuses WHERE customer_id = 'PLACEHOLDER'"
|
||||
const val LoanAccountDue = "DELETE FROM loan_account_dues WHERE loan_account_id = 'PLACEHOLDER'"
|
||||
}
|
||||
|
||||
object CustomersCleanup {
|
||||
val DeleteCustomerDocuments =
|
||||
"""DELETE FROM documents
|
||||
|USING loan_applications
|
||||
|WHERE documents.loan_application_id = loan_applications.id
|
||||
|AND loan_applications.customer_reference_id = 'PLACEHOLDER'""".trimMargin()
|
||||
|
||||
const val DeleteDocumentsFromCustomersTable =
|
||||
"DELETE from documents WHERE customer_id = PLACEHOLDER"
|
||||
|
||||
val DeleteAgreements =
|
||||
"""DELETE FROM loan_agreements
|
||||
|USING loan_applications
|
||||
|WHERE loan_agreements.loan_application_id = loan_applications.id
|
||||
|AND loan_applications.customer_reference_id = 'PLACEHOLDER'""".trimMargin()
|
||||
|
||||
const val DeleteLoanApplications =
|
||||
"DELETE FROM loan_applications WHERE customer_reference_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteStatuses = "DELETE FROM statuses WHERE customer_id = PLACEHOLDER"
|
||||
|
||||
const val DeleteFeatures = "DELETE FROM features WHERE underwriting_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteUnderwritingId =
|
||||
"DELETE FROM underwriting_ids where customer_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteLoanApplicationStatuses = "DELETE FROM statuses WHERE loan_application_id = PLACEHOLDER"
|
||||
|
||||
const val DeleteLoanOffers = "DELETE FROM loan_offers WHERE customer_reference_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteLoanOfferRejections =
|
||||
"DELETE FROM loan_offer_rejections WHERE customer_reference_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteBankAccounts = "DELETE FROM bank_accounts WHERE customer_id = PLACEHOLDER"
|
||||
|
||||
const val DeleteAddresses = "DELETE from addresses WHERE customer_id = PLACEHOLDER"
|
||||
|
||||
const val DeleteCustomer = "DELETE FROM customers WHERE reference_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteCustomerDevices = "DELETE FROM customer_devices WHERE customer_id = PLACEHOLDER"
|
||||
|
||||
const val DeleteCustomerInAuthService = "DELETE FROM users WHERE phone_number = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteExcessPayments = "DELETE FROM excess_payments WHERE customer_reference_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteExternalId = "DELETE FROM external_ids WHERE customer_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteBankStatementReports = "DELETE FROM bank_statement_reports WHERE customer_reference_id = 'PLACEHOLDER'"
|
||||
}
|
||||
|
||||
object LoanAccountsCleanup {
|
||||
const val GetLoanAccountMatchingCustomerId =
|
||||
"SELECT id FROM loan_accounts WHERE customer_id = 'PLACEHOLDER'"
|
||||
|
||||
const val GetDueIdsMatchingLoanAccounts =
|
||||
"SELECT id FROM dues WHERE loan_account_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteProcessingFeeAmortizationsEntry =
|
||||
"DELETE FROM fee_amortization_schedules WHERE loan_account_id = PLACEHOLDER"
|
||||
|
||||
const val GetDueComponentIdsMatchingDueId =
|
||||
"SELECT id FROM due_components WHERE due_id in (PLACEHOLDER)"
|
||||
|
||||
const val DeleteRefundsTableMatchingLoanAccountId =
|
||||
"DELETE FROM refunds WHERE loan_account_id = PLACEHOLDER"
|
||||
|
||||
const val GetScheduleIdMatchingLoanAccountId =
|
||||
"SELECT id from schedules where loan_account_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteScheduleItemsMatchingScheduleId =
|
||||
"DELETE FROM schedule_items where schedule_id = 'PLACEHOLDER'"
|
||||
|
||||
val DeleteSchedulesTableMatchingLoanAccountId =
|
||||
"DELETE FROM schedules WHERE loan_account_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteRescheduleRequest =
|
||||
"DELETE FROM reschedule_requests WHERE loan_account_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteDefermentRequest =
|
||||
"DELETE FROM deferment_requests WHERE loan_account_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteExcessAllocationsRequest =
|
||||
"DELETE FROM excess_allocations WHERE loan_account_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteRepaymentRequest =
|
||||
"DELETE FROM repayment_requests WHERE loan_account_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteLoanCampaignsRequest =
|
||||
"DELETE FROM loan_campaigns WHERE loan_account_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteRepaymentEntriesMatchingDueEntries =
|
||||
"DELETE FROM repayment_entries WHERE due_component_id in (PLACEHOLDER)"
|
||||
|
||||
const val DeleteComponentAdjustmentsMatchingDueComponents =
|
||||
"DELETE FROM component_adjustments WHERE due_component_id in (PLACEHOLDER)"
|
||||
|
||||
const val DeleteFeeAmortizationSchedulesMatchingLoanAccountId =
|
||||
"DELETE FROM fee_amortization_schedules WHERE loan_account_id = PLACEHOLDER"
|
||||
|
||||
const val DeleteInterestHistoriesQueryMatchingLoanAccountId =
|
||||
"DELETE FROM interest_histories WHERE loan_account_id = PLACEHOLDER"
|
||||
|
||||
val DeleteInvoiceLineItems =
|
||||
"""DELETE FROM invoice_line_items
|
||||
|USING invoices
|
||||
|WHERE invoice_line_items.invoice_id = invoices.id
|
||||
|AND invoices.customer_id = 'PLACEHOLDER'""".trimMargin()
|
||||
|
||||
const val DeleteInvoices = "DELETE FROM invoices WHERE customer_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteRepaymentsMatchingLoanAccountId = "DELETE FROM repayments WHERE loan_account_id = PLACEHOLDER"
|
||||
|
||||
const val DeleteCapitalizedInterests = "DELETE FROM capitalized_interests WHERE loan_account_id = PLACEHOLDER"
|
||||
|
||||
const val DeleteDueComponentsMatchingDues = "DELETE FROM due_components WHERE due_id in (PLACEHOLDER)"
|
||||
|
||||
const val DeleteDuesMatchingLoanAccountId = "DELETE FROM dues WHERE loan_account_id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteAmortizationScheduleForMatchingLoanAccountId =
|
||||
"Delete from amortization_schedules where loan_account_id = PLACEHOLDER"
|
||||
|
||||
val DeleteInterestAccrualEntriesSummary =
|
||||
"""DELETE FROM interest_accrual_entries
|
||||
|USING loan_accounts
|
||||
|WHERE loan_accounts.interest_summary_id = interest_accrual_entries.interest_summary_id
|
||||
|AND loan_accounts.id = PLACEHOLDER""".trimMargin()
|
||||
|
||||
val DeleteInterestSummary =
|
||||
"""DELETE FROM interest_summary
|
||||
|USING loan_accounts
|
||||
|WHERE loan_accounts.interest_summary_id = interest_summary.id
|
||||
|AND loan_accounts.id = PLACEHOLDER""".trimMargin()
|
||||
|
||||
const val DeleteLoanAccountMatchingId = "DELETE FROM loan_accounts WHERE id = 'PLACEHOLDER'"
|
||||
|
||||
const val DeleteDisbursementsTableMatchingLoanAccountId =
|
||||
"DELETE FROM disbursements WHERE loan_account_id = PLACEHOLDER"
|
||||
|
||||
const val DeleteAddOnTableMatchingLoanAccountId =
|
||||
"DELETE FROM addons WHERE loan_account_id = PLACEHOLDER"
|
||||
|
||||
val DeleteLoanAccountsMatchingCustomerReferenceId =
|
||||
"""DELETE FROM loan_accounts USING customers
|
||||
| WHERE customers.id = loan_accounts.customer_id
|
||||
| AND customers.reference_id = 'PLACEHOLDER'""".trimMargin()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.naviapp.dbCore.constants
|
||||
|
||||
object CustomerDbQueries {
|
||||
|
||||
const val GetCustomerIdMatchingPhoneNumber =
|
||||
"SELECT id from customers WHERE phone_number = 'PLACEHOLDER'"
|
||||
|
||||
const val GetCustomerReferenceIdMatchingPhoneNumber =
|
||||
"SELECT reference_id from customers WHERE phone_number = 'PLACEHOLDER'"
|
||||
|
||||
const val GetLoanApplicationId =
|
||||
"SELECT id FROM loan_applications WHERE customer_reference_id = 'PLACEHOLDER'"
|
||||
|
||||
const val GetUnderwritingId = "Select underwriting_id from underwriting_ids WHERE customer_id = 'PLACEHOLDER'"
|
||||
|
||||
const val updateCustomerReferenceId = "update customers set reference_id = 'NEWPLACEHOLDER' where reference_id = 'PLACEHOLDER'"
|
||||
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.naviapp.dbCore.constants
|
||||
|
||||
import com.naviapp.dbCore.Environment
|
||||
|
||||
object Databases {
|
||||
val Product = "product_${Environment.get()}"
|
||||
val Customer = "customer_${Environment.get()}"
|
||||
val Accounting = "accounting_${Environment.get()}"
|
||||
val LoanOriginationManager = "loan_origination_manager_${Environment.get()}"
|
||||
val LoanAccounts = "loan_accounts_${Environment.get()}"
|
||||
val OpsApplication = "ops_application_${Environment.get()}"
|
||||
val MakerChecker = "maker_checker_${Environment.get()}"
|
||||
val AuthService = "auth_service_${Environment.get()}"
|
||||
val MobileApplication = "mobile_application_${Environment.get()}"
|
||||
val CreditUnderwriting = "credit_underwriting_${Environment.get()}"
|
||||
val Payments = "payment_service_${Environment.get()}"
|
||||
val CustomerRead = "customer_read_${Environment.get()}"
|
||||
const val SA_CUSTOMER = "customer_service"
|
||||
}
|
||||
@@ -1,32 +1,31 @@
|
||||
package com.naviapp.mock_setup
|
||||
|
||||
import com.naviapp.CustomerDataCleanup
|
||||
import com.navi.test.database_library.DatabaseName
|
||||
import com.navi.test.database_library.DatabaseWrapper
|
||||
import com.navi.test.database_library.helpers.CustomerDataCleanup
|
||||
import com.naviapp.FileReader
|
||||
import com.naviapp.clients.SuperAppServiceClient
|
||||
import com.naviapp.common.PathConstants
|
||||
import com.naviapp.common.RandomGenerator
|
||||
import com.naviapp.constants.E2EConstants
|
||||
import com.naviapp.dbCore.DatabaseWrapper
|
||||
import com.naviapp.dbCore.Environment
|
||||
import com.naviapp.dbCore.constants.Databases
|
||||
import java.util.*
|
||||
|
||||
object CustomerSetupHelper {
|
||||
|
||||
private val env = Environment.get()
|
||||
private val dbWrapper = DatabaseWrapper(env)
|
||||
private val dbWrapper = DatabaseWrapper(environment)
|
||||
private val cleanup = CustomerDataCleanup(environment)
|
||||
|
||||
fun setupCustomer(phoneNumber: String, customerType: CustomerType) {
|
||||
val table = CustomerSetupData(UUID.randomUUID().toString(), customerType.featureJSON)
|
||||
|
||||
fun commonSetup() {
|
||||
val customerRefId = "55544555-5555-5555-5555-${RandomGenerator.generateUUID().substring(24, 36)}"
|
||||
CustomerDataCleanup().cleanUpCustomerByPhoneNumber(phoneNumber)
|
||||
cleanup.cleanUpCustomerByPhoneNumber(phoneNumber)
|
||||
val deviceId = RandomGenerator.generateDigits(16).toString()
|
||||
SuperAppServiceClient.getOtpValidateResponseForSuperApp(deviceId, phoneNumber, E2EConstants.androidVersion)
|
||||
MockSetupHelper.updateNaviRefIdInSACustomersTable(customerRefId, phoneNumber)
|
||||
dbWrapper.execute(Databases.CreditUnderwriting, listOf(table.insertIntoFeatures()))
|
||||
dbWrapper.execute(Databases.CreditUnderwriting, listOf(table.insertIntoUnderwritingIds(customerRefId)))
|
||||
dbWrapper.execute(DatabaseName.CREDIT_UNDERWRITING, listOf(table.insertIntoFeatures()))
|
||||
dbWrapper.execute(DatabaseName.CREDIT_UNDERWRITING, listOf(table.insertIntoUnderwritingIds(customerRefId)))
|
||||
}
|
||||
|
||||
when(customerType){
|
||||
@@ -43,7 +42,7 @@ object CustomerSetupHelper {
|
||||
commonSetup()
|
||||
val algo360FeatureJson = FileReader.readDataFromFile(PathConstants.algo360.toString())
|
||||
val algo360Source = "ALGO360"
|
||||
dbWrapper.execute(Databases.CreditUnderwriting, listOf(table.insertIntoFeatures(algo360FeatureJson, algo360Source)))
|
||||
dbWrapper.execute(DatabaseName.CREDIT_UNDERWRITING, listOf(table.insertIntoFeatures(algo360FeatureJson, algo360Source)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
package com.naviapp.mock_setup
|
||||
|
||||
import com.navi.test.common_library.RunEnvironment
|
||||
import com.navi.test.database_library.DatabaseName
|
||||
import com.navi.test.database_library.DatabaseWrapper
|
||||
import com.navi.test.database_library.SuperAppDB
|
||||
import com.navi.test.database_library.helpers.CustomerDataCleanup
|
||||
import com.naviapp.MobileApplicationServiceHeaders
|
||||
import com.naviapp.clients.MobileApplicationServiceClient
|
||||
import com.naviapp.clients.SuperAppServiceClient
|
||||
import com.naviapp.CustomerDataCleanup
|
||||
import com.naviapp.MobileApplicationServiceHeaders
|
||||
import com.naviapp.common.RandomGenerator
|
||||
import com.naviapp.constants.E2EConstants
|
||||
import com.naviapp.dbCore.DatabaseWrapper
|
||||
import com.naviapp.dbCore.Environment
|
||||
import com.naviapp.dbCore.SuperAppDB
|
||||
import com.naviapp.dbCore.constants.Databases
|
||||
|
||||
val environment = RunEnvironment.fromString(Environment.get())
|
||||
|
||||
object MockSetupHelper {
|
||||
private val dbWrapper = DatabaseWrapper(Environment.get())
|
||||
private val dbWrapper = DatabaseWrapper(environment)
|
||||
private val cleanup = CustomerDataCleanup(environment)
|
||||
|
||||
fun enableMock(mockType: MockType): Pair<MobileApplicationServiceHeaders, String> =
|
||||
when (mockType) {
|
||||
@@ -31,7 +34,7 @@ object MockSetupHelper {
|
||||
doMockSetup(mockType)
|
||||
|
||||
private fun doMockSetup(mockType: MockType): Pair<MobileApplicationServiceHeaders, String> {
|
||||
CustomerDataCleanup().cleanUpCustomerByPhoneNumber(mockType.phoneNumber)
|
||||
cleanup.cleanUpCustomerByPhoneNumber(mockType.phoneNumber)
|
||||
val deviceId = RandomGenerator.generateDigits(16).toString()
|
||||
MobileApplicationServiceClient.registerDevice(deviceId)
|
||||
val sessionToken = SuperAppServiceClient.getOtpValidateResponseForSuperApp(
|
||||
@@ -47,28 +50,28 @@ object MockSetupHelper {
|
||||
|
||||
fun deleteDataFromStatusesTable(customerRefId: String) {
|
||||
dbWrapper.execute(
|
||||
Databases.MobileApplication,
|
||||
DatabaseName.MOBILE_APPLICATION,
|
||||
listOf(Queries.deleteEntryFromStatusesTable(customerRefId))
|
||||
)
|
||||
}
|
||||
|
||||
fun updateCustomerIdInUsersTable(phoneNumber: String, customerRefId: String) {
|
||||
dbWrapper.execute(
|
||||
Databases.AuthService,
|
||||
DatabaseName.AUTH_SERVICE,
|
||||
listOf(Queries.updateCustomerRefIdInAuthServiceUsersTable(phoneNumber, customerRefId))
|
||||
)
|
||||
}
|
||||
|
||||
fun updateCustomerIdInCustomersTable(phoneNumber: String, customerRefId: String) {
|
||||
dbWrapper.execute(
|
||||
Databases.Customer,
|
||||
DatabaseName.CUSTOMER,
|
||||
listOf(Queries.updateCustomerRefInCustomersTable(phoneNumber, customerRefId))
|
||||
)
|
||||
}
|
||||
|
||||
fun updateNaviRefIdInSACustomersTable(customerRefId: String, phoneNumber: String) {
|
||||
dbWrapper.execute(
|
||||
Databases.SA_CUSTOMER,
|
||||
DatabaseName.SA_CUSTOMER,
|
||||
listOf(Queries.updateNaviRefIdInSACustomersTable(customerRefId, phoneNumber)),
|
||||
SuperAppDB
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user