Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #43 from blotoutio/defect/courutine_exception_handler
Browse files Browse the repository at this point in the history
Fixed defect for init initializer
  • Loading branch information
nitinblotout authored Feb 23, 2022
2 parents 879f774 + cade35c commit 38d98f0
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 81 deletions.
7 changes: 6 additions & 1 deletion blotoutSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ allprojects{
repositories{
maven {url 'https://jitpack.io'}
}
configurations.all {
resolutionStrategy {
force 'org.xerial:sqlite-jdbc:3.34.0'
}
}
}


Expand All @@ -54,7 +59,7 @@ afterEvaluate {
release(MavenPublication) {
from components.release
groupId 'com.analytics.blotout'
version '0.10.0'
version '0.10.2'
artifactId 'Blotout'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ import android.app.Application
import android.content.Context
import android.util.Log
import com.analytics.blotout.model.*
import com.analytics.blotout.model.CompletionHandler
import com.analytics.blotout.network.HostConfiguration
import com.analytics.blotout.repository.EventRepository
import com.analytics.blotout.repository.impl.SharedPreferenceSecureVaultImpl
import com.analytics.blotout.util.Constant
import com.analytics.blotout.util.Errors
import com.analytics.blotout.util.serializeToMap
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.*
import java.lang.Exception

open class BlotoutAnalyticsInternal : BlotoutAnalyticsInterface {

companion object {
private const val TAG = "AnalyticsInternal"
private var isSdkinitiliazed = false
}


Expand All @@ -28,7 +27,10 @@ open class BlotoutAnalyticsInternal : BlotoutAnalyticsInterface {
blotoutAnalyticsConfiguration: BlotoutAnalyticsConfiguration,
completionHandler: CompletionHandler
) {
CoroutineScope(Dispatchers.Default).launch {
val handler = CoroutineExceptionHandler { _, exception ->
completionHandler.onError(code=ErrorCodes.ERROR_CODE_NETWORK_ERROR, msg = exception.localizedMessage)
}
CoroutineScope(Dispatchers.IO+handler).launch {

val secureVault = SharedPreferenceSecureVaultImpl(application.getSharedPreferences("vault", Context.MODE_PRIVATE), "crypto")
val hostConfiguration = HostConfiguration(baseUrl = blotoutAnalyticsConfiguration.endPointUrl, baseKey = blotoutAnalyticsConfiguration.blotoutSDKKey)
Expand All @@ -50,6 +52,7 @@ open class BlotoutAnalyticsInternal : BlotoutAnalyticsInterface {
.fetchManifestConfiguration()
when(result){
is Result.Success->{
isSdkinitiliazed = true
DependencyInjectorImpl.getInstance().initialize()
completionHandler.onSuccess()
}
Expand All @@ -74,21 +77,25 @@ open class BlotoutAnalyticsInternal : BlotoutAnalyticsInterface {

@Synchronized
override fun capture(eventName: String, eventInfo: HashMap<String, Any>){
CoroutineScope(Dispatchers.Default).launch {
try {

val eventsRepository =
EventRepository(
DependencyInjectorImpl.getInstance().getSecureStorageService()
)
var result = eventInfo.let {
eventsRepository.prepareCodifiedEvent(
eventName = eventName,
eventInfo = eventInfo
)
val sdkEnable = DependencyInjectorImpl.getInstance().getSecureStorageService()
.fetchBoolean(Constant.IS_SDK_ENABLE)
if(sdkEnable && isSdkinitiliazed) {
CoroutineScope(Dispatchers.Default).launch {
try {

val eventsRepository =
EventRepository(
DependencyInjectorImpl.getInstance().getSecureStorageService()
)
var result = eventInfo.let {
eventsRepository.prepareCodifiedEvent(
eventName = eventName,
eventInfo = eventInfo
)
}
} catch (e: Exception) {
Log.e(TAG, e.toString())
}
} catch (e: Exception) {
Log.e(TAG, e.toString())
}
}
}
Expand All @@ -99,6 +106,9 @@ open class BlotoutAnalyticsInternal : BlotoutAnalyticsInterface {
eventInfo: HashMap<String, Any>,
isPHI: Boolean
) {
val sdkEnable = DependencyInjectorImpl.getInstance().getSecureStorageService()
.fetchBoolean(Constant.IS_SDK_ENABLE)
if(sdkEnable && isSdkinitiliazed) {
CoroutineScope(Dispatchers.Default).launch {
try {
val eventsRepository =
Expand All @@ -108,27 +118,34 @@ open class BlotoutAnalyticsInternal : BlotoutAnalyticsInterface {
var result = eventsRepository.preparePersonalEvent(eventName, eventInfo, isPHI)
} catch (e: Exception) {
Log.e(TAG, e.toString())
}

} }
}
}

@Synchronized
override fun mapID(mapIDData: MapIDData, withInformation: HashMap<String, Any>?) {
CoroutineScope(Dispatchers.Default).launch {
try {
val _withInformation = withInformation ?: hashMapOf()
_withInformation[Constant.BO_EVENT_MAP_ID] = mapIDData.externalID
_withInformation[Constant.BO_EVENT_MAP_Provider] = mapIDData.provider
val eventsRepository =
EventRepository(DependencyInjectorImpl.getInstance().getSecureStorageService())
var result =
eventsRepository.prepareCodifiedEvent(
eventName = Constant.BO_EVENT_MAP_ID,
eventInfo = _withInformation
)

} catch (e: Exception) {
Log.e(TAG,e.toString())
val sdkEnable = DependencyInjectorImpl.getInstance().getSecureStorageService()
.fetchBoolean(Constant.IS_SDK_ENABLE)
if(sdkEnable && isSdkinitiliazed) {
CoroutineScope(Dispatchers.Default).launch {
try {
val _withInformation = withInformation ?: hashMapOf()
_withInformation[Constant.BO_EVENT_MAP_ID] = mapIDData.externalID
_withInformation[Constant.BO_EVENT_MAP_Provider] = mapIDData.provider
val eventsRepository =
EventRepository(
DependencyInjectorImpl.getInstance().getSecureStorageService()
)
var result =
eventsRepository.prepareCodifiedEvent(
eventName = Constant.BO_EVENT_MAP_ID,
eventInfo = _withInformation
)

} catch (e: Exception) {
Log.e(TAG, e.toString())
}
}
}
}
Expand All @@ -145,60 +162,78 @@ open class BlotoutAnalyticsInternal : BlotoutAnalyticsInterface {

@Synchronized
override fun transaction(transactionData: TransactionData, withInformation: HashMap<String, Any>) {
CoroutineScope(Dispatchers.Default).launch {
try {
val _withInformation = withInformation ?: hashMapOf()
_withInformation.putAll(transactionData.serializeToMap())
val eventsRepository =
EventRepository(DependencyInjectorImpl.getInstance().getSecureStorageService())
var result =
eventsRepository.prepareCodifiedEvent(
eventName = Constant.BO_EVENT_TRANSACTION_NAME,
eventInfo = _withInformation
)

} catch (e: Exception) {
Log.e(TAG,e.toString())
val sdkEnable = DependencyInjectorImpl.getInstance().getSecureStorageService()
.fetchBoolean(Constant.IS_SDK_ENABLE)
if(sdkEnable && isSdkinitiliazed) {
CoroutineScope(Dispatchers.Default).launch {
try {
val _withInformation = withInformation ?: hashMapOf()
_withInformation.putAll(transactionData.serializeToMap())
val eventsRepository =
EventRepository(
DependencyInjectorImpl.getInstance().getSecureStorageService()
)
var result =
eventsRepository.prepareCodifiedEvent(
eventName = Constant.BO_EVENT_TRANSACTION_NAME,
eventInfo = _withInformation
)

} catch (e: Exception) {
Log.e(TAG, e.toString())
}
}
}
}

@Synchronized
override fun item(itemData: Item, withInformation: HashMap<String, Any>) {
CoroutineScope(Dispatchers.Default).launch {
try {
val _withInformation = withInformation ?: hashMapOf()
_withInformation.putAll(itemData.serializeToMap())
val eventsRepository =
EventRepository(DependencyInjectorImpl.getInstance().getSecureStorageService())
var result =
eventsRepository.prepareCodifiedEvent(
eventName = Constant.BO_EVENT_TRANSACTION_ITEM_NAME,
eventInfo = _withInformation
)

} catch (e: Exception) {
Log.e(TAG,e.toString())
val sdkEnable = DependencyInjectorImpl.getInstance().getSecureStorageService()
.fetchBoolean(Constant.IS_SDK_ENABLE)
if(sdkEnable && isSdkinitiliazed) {
CoroutineScope(Dispatchers.Default).launch {
try {
val _withInformation = withInformation ?: hashMapOf()
_withInformation.putAll(itemData.serializeToMap())
val eventsRepository =
EventRepository(
DependencyInjectorImpl.getInstance().getSecureStorageService()
)
var result =
eventsRepository.prepareCodifiedEvent(
eventName = Constant.BO_EVENT_TRANSACTION_ITEM_NAME,
eventInfo = _withInformation
)

} catch (e: Exception) {
Log.e(TAG, e.toString())
}
}
}
}

@Synchronized
override fun persona(personaData: Persona , withInformation: HashMap<String, Any>) {
CoroutineScope(Dispatchers.Default).launch {
try {
val _withInformation = withInformation ?: hashMapOf()
_withInformation.putAll(personaData.serializeToMap())
val eventsRepository =
EventRepository(DependencyInjectorImpl.getInstance().getSecureStorageService())
var result =
eventsRepository.prepareCodifiedEvent(
eventName = Constant.BO_EVENT_PERSONA_NAME,
eventInfo = _withInformation
)

} catch (e: Exception) {
Log.e(TAG,e.toString())
val sdkEnable = DependencyInjectorImpl.getInstance().getSecureStorageService()
.fetchBoolean(Constant.IS_SDK_ENABLE)
if(sdkEnable && isSdkinitiliazed) {
CoroutineScope(Dispatchers.Default).launch {
try {
val _withInformation = withInformation ?: hashMapOf()
_withInformation.putAll(personaData.serializeToMap())
val eventsRepository =
EventRepository(
DependencyInjectorImpl.getInstance().getSecureStorageService()
)
var result =
eventsRepository.prepareCodifiedEvent(
eventName = Constant.BO_EVENT_PERSONA_NAME,
eventInfo = _withInformation
)

} catch (e: Exception) {
Log.e(TAG, e.toString())
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import retrofit2.http.*

interface RemoteApiService {

@Retry(3)
@POST(Constant.BO_SDK_REST_API_MANIFEST_PULL_PATH)
suspend fun getSDKManifest(): Response<ManifestConfigurationResponse>

@Retry(3)
@POST(Constant.BO_SDK_REST_API_EVENTS_PUSH_PATH)
fun postEvents(@Body body: Events) : Call<Any>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ object Constant {

const val BOSDK_MAJOR_VERSION = 0
const val BOSDK_MINOR_VERSION = 10
const val BOSDK_PATCH_VERSION = 0
const val BOSDK_PATCH_VERSION = 2


const val BO_PII = "pii"
Expand Down

0 comments on commit 38d98f0

Please sign in to comment.