added code for sanitize result upload values if if the result is NAN or infinity for molbio integration
This commit is contained in:
@@ -19,8 +19,8 @@ android {
|
|||||||
applicationId "in.sminnovations.hpostesting.dev"
|
applicationId "in.sminnovations.hpostesting.dev"
|
||||||
minSdk 21
|
minSdk 21
|
||||||
targetSdk 34
|
targetSdk 34
|
||||||
versionCode 119
|
versionCode 120
|
||||||
versionName "2.1.119"
|
versionName "2.1.120"
|
||||||
|
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,7 +149,9 @@ class HomeFragment : Fragment() {
|
|||||||
": USER DATA",
|
": USER DATA",
|
||||||
originalUserDataList.count().toString() + " : " + userData._id
|
originalUserDataList.count().toString() + " : " + userData._id
|
||||||
)
|
)
|
||||||
|
var accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||||
|
// Upload results after processing all userData to avoid duplicates and ensure all modifications are done
|
||||||
|
if(accessToken.isNotEmpty()) {
|
||||||
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
if (!userData.molbioFlag && isTokenAvailable && Constants.MOLBIO_INTEGRATION) {
|
||||||
val currentTimeFormatted = SimpleDateFormat(
|
val currentTimeFormatted = SimpleDateFormat(
|
||||||
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
"yyyy-MM-dd'T'HH:mm:ssZZZZZ",
|
||||||
@@ -176,6 +178,7 @@ class HomeFragment : Fragment() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Log.d("USER DATA LIST SIZE", resultList.results?.count().toString())
|
Log.d("USER DATA LIST SIZE", resultList.results?.count().toString())
|
||||||
|
|
||||||
resultList.results?.forEach { result ->
|
resultList.results?.forEach { result ->
|
||||||
@@ -188,15 +191,16 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
resultList.results?.forEach { result ->
|
||||||
|
result.rawData?.let { sanitizeDoubleValues(it) }
|
||||||
|
}
|
||||||
|
|
||||||
var accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
// Then, check if there are any results to upload.
|
||||||
// Upload results after processing all userData to avoid duplicates and ensure all modifications are done
|
|
||||||
if(accessToken.isNotEmpty()) {
|
|
||||||
if (resultList.results?.isNotEmpty() == true) {
|
if (resultList.results?.isNotEmpty() == true) {
|
||||||
hemoCubeViewModel.uploadResult(resultList)
|
hemoCubeViewModel.uploadResult(resultList)
|
||||||
Log.d("resultcount1","resultcount")
|
Log.d("resultcount1", "Uploading sanitized results")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -279,7 +283,12 @@ class HomeFragment : Fragment() {
|
|||||||
deviceId = sharedPreference.getString(Constants.DEVICE_ID, "").toString()
|
deviceId = sharedPreference.getString(Constants.DEVICE_ID, "").toString()
|
||||||
if(userID.isNotEmpty() && password.isNotEmpty()) {
|
if(userID.isNotEmpty() && password.isNotEmpty()) {
|
||||||
Log.d("istoken",isTokenAvailable.toString())
|
Log.d("istoken",isTokenAvailable.toString())
|
||||||
if (isTokenAvailable) {
|
if (!isTokenAvailable) {
|
||||||
|
Log.d("istoken1",isTokenAvailable.toString())
|
||||||
|
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||||
|
isTokenAvailable = true
|
||||||
|
|
||||||
|
}else if(isTokenAvailable){
|
||||||
Log.d("istoken7",isTokenAvailable.toString())
|
Log.d("istoken7",isTokenAvailable.toString())
|
||||||
isTokenAvailable = true
|
isTokenAvailable = true
|
||||||
hemoCubeViewModel.startPeriodicCheckUpdate()
|
hemoCubeViewModel.startPeriodicCheckUpdate()
|
||||||
@@ -288,10 +297,6 @@ class HomeFragment : Fragment() {
|
|||||||
if(isTokenExpired(accessToken)) {
|
if(isTokenExpired(accessToken)) {
|
||||||
Log.d("istoken8",isTokenAvailable.toString())
|
Log.d("istoken8",isTokenAvailable.toString())
|
||||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
||||||
}else {
|
|
||||||
Log.d("istoken1",isTokenAvailable.toString())
|
|
||||||
hemoCubeViewModel.login(createLoginRequestData(userID, password))
|
|
||||||
isTokenAvailable = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (userID.isEmpty() && password.isEmpty() && deviceId.isNotEmpty()) {
|
} else if (userID.isEmpty() && password.isEmpty() && deviceId.isNotEmpty()) {
|
||||||
@@ -332,6 +337,36 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
||||||
|
when (it) {
|
||||||
|
is Result.Success -> {
|
||||||
|
|
||||||
|
Log.d("success,","uploded")
|
||||||
|
it.data.data?.forEach { id ->
|
||||||
|
id.rawData?.let { it1 ->
|
||||||
|
hemoCubeViewModel.updateMolbioFlag(
|
||||||
|
it1._id
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Toast.makeText(activity, "Molbio Result is successfully uploaded", Toast.LENGTH_LONG)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
is Result.Error -> {
|
||||||
|
binding.btnSubmit.visibility = View.VISIBLE
|
||||||
|
//Remove this line of code while deploying to IOCL
|
||||||
|
it.exception.let { message ->
|
||||||
|
Toast.makeText(activity, "$message", Toast.LENGTH_LONG)
|
||||||
|
.show()
|
||||||
|
Log.d("resultuploadfail", message.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
hemoCubeViewModel.uploadLogs.observe(viewLifecycleOwner) { response ->
|
hemoCubeViewModel.uploadLogs.observe(viewLifecycleOwner) { response ->
|
||||||
when (response) {
|
when (response) {
|
||||||
is Result.Success -> {
|
is Result.Success -> {
|
||||||
@@ -461,31 +496,6 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
|
||||||
when (it) {
|
|
||||||
is Result.Success -> {
|
|
||||||
it.data.data?.forEach { id ->
|
|
||||||
id.rawData?.let { it1 ->
|
|
||||||
hemoCubeViewModel.updateMolbioFlag(
|
|
||||||
it1._id
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
is Result.Error -> {
|
|
||||||
binding.btnSubmit.visibility = View.VISIBLE
|
|
||||||
//Remove this line of code while deploying to IOCL
|
|
||||||
it.exception.let { message ->
|
|
||||||
Toast.makeText(activity, "An error occurred: $message", Toast.LENGTH_LONG)
|
|
||||||
.show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -851,6 +861,21 @@ class HomeFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun sanitizeDoubleValues(hemoCubeTestData: HemoCubeTestData): HemoCubeTestData {
|
||||||
|
hemoCubeTestData::class.java.declaredFields.forEach { field ->
|
||||||
|
if (field.type == Double::class.javaObjectType || field.type == Double::class.javaPrimitiveType) {
|
||||||
|
field.isAccessible = true
|
||||||
|
val value = field.get(hemoCubeTestData) as Double?
|
||||||
|
if (value != null && (value.isInfinite() || value.isNaN())) {
|
||||||
|
field.set(hemoCubeTestData, 0.0) // Replace with a suitable default value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return hemoCubeTestData
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun showUploadDialog(context: Context) {
|
private fun showUploadDialog(context: Context) {
|
||||||
val builder = AlertDialog.Builder(context)
|
val builder = AlertDialog.Builder(context)
|
||||||
builder.setTitle(R.string.upload_db_registration_title)
|
builder.setTitle(R.string.upload_db_registration_title)
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ class HemoCubeFragment : Fragment() {
|
|||||||
uploadedToCloud = true
|
uploadedToCloud = true
|
||||||
var accessToken = sharedPreferences.getString(Constants.ACCESS_TOKEN, "").toString()
|
var accessToken = sharedPreferences.getString(Constants.ACCESS_TOKEN, "").toString()
|
||||||
showToast(R.string.test_upload)
|
showToast(R.string.test_upload)
|
||||||
if (Constants.MOLBIO_INTEGRATION && accessToken.isNotEmpty()) {
|
if (Constants.MOLBIO_INTEGRATION) {
|
||||||
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
hemoCubeViewModel.resultUpload.observe(viewLifecycleOwner) {
|
||||||
when (it) {
|
when (it) {
|
||||||
is Result.Success -> {
|
is Result.Success -> {
|
||||||
|
|||||||
@@ -328,8 +328,7 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
Log.i("Testdb", "Data uploaded to Firestore successfully")
|
||||||
fireBaseUpload.postValue("Success")
|
fireBaseUpload.postValue("Success")
|
||||||
testDetails.localFlag = true
|
testDetails.localFlag = true
|
||||||
var accessToken = sharedPreference.getString(Constants.ACCESS_TOKEN, "").toString()
|
if (Constants.MOLBIO_INTEGRATION) {
|
||||||
if (Constants.MOLBIO_INTEGRATION && accessToken.isNotEmpty()) {
|
|
||||||
uploadResult(
|
uploadResult(
|
||||||
MolbioV2ResultRequest(
|
MolbioV2ResultRequest(
|
||||||
mutableListOf(
|
mutableListOf(
|
||||||
@@ -417,6 +416,8 @@ class HemoCubeViewModel @Inject constructor(
|
|||||||
Log.e("Testdb", "Error uploading data to Firestore: $response")
|
Log.e("Testdb", "Error uploading data to Firestore: $response")
|
||||||
fireBaseUpload.postValue("Error")
|
fireBaseUpload.postValue("Error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else -> {}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
Log.e("Testdb", "Exception during data upload: ${e.message}")
|
||||||
|
|||||||
Reference in New Issue
Block a user