From 5be65aa932cb71252669e7e09d2a1a948a1caf6d Mon Sep 17 00:00:00 2001 From: kapmaurya Date: Mon, 20 Jan 2025 20:54:53 +0530 Subject: [PATCH 01/13] datastore-migration-kmpl --- .../MifosDispatchers.kt | 26 +++ .../org.mifos.core.datastore/Parcelize.kt | 39 ++++ .../PreferencesMapper.kt | 107 +++++++++++ .../org.mifos.core.datastore/RoleInfo.kt | 20 ++ .../org.mifos.core.datastore/UserInfo.kt | 27 +++ .../UserPreferencesDataSource.kt | 174 ++++++++++++++++++ .../UserPreferencesRepository.kt | 46 +++++ .../UserPreferencesRepositoryImpl.kt | 127 +++++++++++++ .../di/PreferenceModule.kt | 33 ++++ .../org.mifos.core.datastore/model/Client.kt | 35 ++++ .../model/ClientPreferences.kt | 51 +++++ .../model/DefaultAccount.kt | 27 +++ .../model/RolePreferences.kt | 29 +++ .../model/UpdatedClient.kt | 22 +++ .../model/UserInfoPreferences.kt | 43 +++++ 15 files changed, 806 insertions(+) create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt new file mode 100644 index 00000000000..65c5fa6872d --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +import org.koin.core.annotation.Qualifier + +@Qualifier +@Retention(AnnotationRetention.RUNTIME) +annotation class Dispatcher(val mifosDispatcher: MifosDispatchers) + +enum class MifosDispatchers { + Default, + IO, + Unconfined, +} + +@Qualifier +@Retention(AnnotationRetention.RUNTIME) +annotation class ApplicationScope diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt new file mode 100644 index 00000000000..a5c53c24d83 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +expect annotation class Parcelize() + +//expect annotation class IgnoredOnParcel() + +expect interface Parceler

{ + fun create(parcel: Parcel): P + + fun P.write(parcel: Parcel, flags: Int) +} + +expect annotation class TypeParceler>() + +expect class Parcel { + fun readByte(): Byte + fun readInt(): Int + + fun readFloat(): Float + fun readDouble(): Double + fun readString(): String? + + fun writeByte(value: Byte) + fun writeInt(value: Int) + + fun writeFloat(value: Float) + + fun writeDouble(value: Double) + fun writeString(value: String?) +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt new file mode 100644 index 00000000000..775e03a7e31 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt @@ -0,0 +1,107 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +import org.mifos.core.datastore.model.ClientPreferences +import org.mifos.core.datastore.model.RolePreferences +import org.mifos.core.datastore.model.UserInfoPreferences +import org.mifos.core.model.client.Client +import org.mifos.core.model.user.RoleInfo +import org.mifos.core.model.user.UserInfo + +fun ClientPreferences.toClientInfo(): Client { + return Client( + id = id, + accountNo = accountNo, + externalId = externalId, + active = active, + activationDate = activationDate, + firstname = firstname, + lastname = lastname, + displayName = displayName, + mobileNo = mobileNo, + emailAddress = emailAddress, + dateOfBirth = dateOfBirth, + isStaff = isStaff, + officeId = officeId, + officeName = officeName, + savingsProductName = savingsProductName, + ) +} + +fun Client.toClientPreferences(): ClientPreferences { + return ClientPreferences( + id = id, + accountNo = accountNo, + externalId = externalId, + active = active, + activationDate = activationDate, + firstname = firstname, + lastname = lastname, + displayName = displayName, + mobileNo = mobileNo, + emailAddress = emailAddress, + dateOfBirth = dateOfBirth, + isStaff = isStaff, + officeId = officeId, + officeName = officeName, + savingsProductName = savingsProductName, + ) +} + +fun RolePreferences.toRoleInfo(): RoleInfo { + return RoleInfo( + id = id, + name = name, + description = description, + disabled = disabled, + ) +} + +fun RoleInfo.toRolePreferences(): RolePreferences { + return RolePreferences( + id = id, + name = name, + description = description, + disabled = disabled, + ) +} + +fun UserInfoPreferences.toUserInfo(): UserInfo { + return UserInfo( + username = username, + userId = userId, + base64EncodedAuthenticationKey = base64EncodedAuthenticationKey, + authenticated = authenticated, + officeId = officeId, + officeName = officeName, + roles = roles.map { it.toRoleInfo() }, + permissions = permissions, + clients = clients, + shouldRenewPassword = shouldRenewPassword, + isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired, + ) +} + +fun UserInfo.toUserInfoPreferences(): UserInfoPreferences { + return UserInfoPreferences( + username = username, + userId = userId, + base64EncodedAuthenticationKey = base64EncodedAuthenticationKey, + authenticated = authenticated, + officeId = officeId, + officeName = officeName, + roles = roles.map { it.toRolePreferences() }, + permissions = permissions, + clients = clients, + shouldRenewPassword = shouldRenewPassword, + isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired, + ) +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt new file mode 100644 index 00000000000..89e9025cef6 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + + + +@Parcelize +data class RoleInfo( + val id: String, + val name: String, + val description: String, + val disabled: Boolean, +) : Parcelable diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt new file mode 100644 index 00000000000..7a03a94a1c7 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + + + +@Parcelize +data class UserInfo( + val username: String, + val userId: Long, + val base64EncodedAuthenticationKey: String, + val authenticated: Boolean, + val officeId: Int, + val officeName: String, + val roles: List, + val permissions: List, + val clients: List, + val shouldRenewPassword: Boolean, + val isTwoFactorAuthenticationRequired: Boolean, +) : Parcelable diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt new file mode 100644 index 00000000000..cf107862b08 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt @@ -0,0 +1,174 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +@file:OptIn(ExperimentalSerializationApi::class, ExperimentalSettingsApi::class) + +package org.mifos.core.datastore + +import com.russhwolf.settings.ExperimentalSettingsApi +import com.russhwolf.settings.Settings +import com.russhwolf.settings.serialization.decodeValue +import com.russhwolf.settings.serialization.decodeValueOrNull +import com.russhwolf.settings.serialization.encodeValue +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.withContext +import kotlinx.serialization.ExperimentalSerializationApi +import org.mifos.core.datastore.UserPreferencesDataSource.Companion.DEFAULT_ACCOUNT +import org.mifos.core.datastore.model.ClientPreferences +import org.mifos.core.datastore.model.UserInfoPreferences +//import org.mifos.core.datastore.model.Client +//import org.mifos.core.datastore.model.UpdatedClient +import org.mifos.core.model.user.UserInfo + +private const val USER_INFO_KEY = "userInfo" +private const val CLIENT_INFO_KEY = "clientInfo" + +@OptIn(ExperimentalSerializationApi::class) +class UserPreferencesDataSource( + private val settings: Settings, + private val dispatcher: CoroutineDispatcher, +) { + private val _userInfo = MutableStateFlow( + settings.decodeValue( + key = USER_INFO_KEY, + serializer = UserInfoPreferences.serializer(), + defaultValue = settings.decodeValueOrNull( + key = USER_INFO_KEY, + serializer = UserInfoPreferences.serializer(), + ) ?: UserInfoPreferences.DEFAULT, + ), + ) + + private val _clientInfo = MutableStateFlow( + settings.decodeValue( + key = CLIENT_INFO_KEY, + serializer = ClientPreferences.serializer(), + defaultValue = settings.decodeValueOrNull( + key = CLIENT_INFO_KEY, + serializer = ClientPreferences.serializer(), + ) ?: ClientPreferences.DEFAULT, + ), + ) + + private val _defaultAccount = MutableStateFlow( + settings.decodeValue( + key = DEFAULT_ACCOUNT, + serializer = DefaultAccount.serializer(), + defaultValue = settings.decodeValueOrNull( + key = DEFAULT_ACCOUNT, + serializer = DefaultAccount.serializer(), + ) ?: DefaultAccount.DEFAULT, + ), + ) + + val token = _userInfo.map { + it.base64EncodedAuthenticationKey + } + val userInfo = _userInfo.map(UserInfoPreferences::toUserInfo) + + val clientInfo = _clientInfo.map(ClientPreferences::toClientInfo) + + val clientId = _clientInfo.map { it.id } + + val defaultAccount = _defaultAccount.map { it.takeIf { it.accountId != 0L } } + + suspend fun updateClientInfo(client: Client) { + withContext(dispatcher) { + settings.putClientPreference(client.toClientPreferences()) + _clientInfo.value = client.toClientPreferences() + } + } + + suspend fun updateUserInfo(userInfo: UserInfo) { + withContext(dispatcher) { + settings.putUserInfoPreference(userInfo.toUserInfoPreferences()) + _userInfo.value = userInfo.toUserInfoPreferences() + } + } + + suspend fun updateClientProfile(client: UpdatedClient) { + withContext(dispatcher) { + val updatedClient = _clientInfo.value.copy( + firstname = client.firstname, + lastname = client.lastname, + displayName = client.firstname + " " + client.lastname, + emailAddress = client.emailAddress, + mobileNo = client.mobileNo, + externalId = client.externalId, + ) + + settings.putClientPreference(updatedClient) + _clientInfo.value = updatedClient + } + } + + suspend fun updateToken(token: String) { + withContext(dispatcher) { + settings.putUserInfoPreference( + UserInfoPreferences.DEFAULT.copy( + base64EncodedAuthenticationKey = token, + ), + ) + _userInfo.value = UserInfoPreferences.DEFAULT.copy( + base64EncodedAuthenticationKey = token, + ) + } + } + + fun updateDefaultAccount(account: DefaultAccount) { + settings.putDefaultAccount(account) + + _defaultAccount.value = account + } + + fun updateAuthToken(token: String) { + settings.putString(AUTH_TOKEN, token) + } + + fun getAuthToken(): String? { + return settings.getString(AUTH_TOKEN, "").ifEmpty { null } + } + + suspend fun clearInfo() { + withContext(dispatcher) { + settings.clear() + } + } + + companion object { + const val AUTH_TOKEN = "authToken" + const val DEFAULT_ACCOUNT = "default_account" + } +} + +private fun Settings.putClientPreference(preference: ClientPreferences) { + encodeValue( + key = CLIENT_INFO_KEY, + serializer = ClientPreferences.serializer(), + value = preference, + ) +} + +private fun Settings.putUserInfoPreference(preference: UserInfoPreferences) { + encodeValue( + key = USER_INFO_KEY, + serializer = UserInfoPreferences.serializer(), + value = preference, + ) +} + +private fun Settings.putDefaultAccount(account: DefaultAccount) { + encodeValue( + key = DEFAULT_ACCOUNT, + serializer = DefaultAccount.serializer(), + value = account, + ) +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt new file mode 100644 index 00000000000..ad807598375 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.datastore + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.StateFlow +import org.mifospay.core.common.DataState +import org.mifospay.core.model.account.DefaultAccount +import org.mifospay.core.model.client.Client +import org.mifospay.core.model.client.UpdatedClient +import org.mifospay.core.model.user.UserInfo + +interface UserPreferencesRepository { + val userInfo: Flow + + val token: StateFlow + + val client: StateFlow + + val clientId: StateFlow + + val authToken: String? + + val defaultAccount: StateFlow + + val defaultAccountId: StateFlow + + suspend fun updateToken(token: String): DataState + + suspend fun updateUserInfo(user: UserInfo): DataState + + suspend fun updateClientInfo(client: Client): DataState + + suspend fun updateClientProfile(client: UpdatedClient): DataState + + suspend fun updateDefaultAccount(account: DefaultAccount): DataState + + suspend fun logOut(): Unit +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt new file mode 100644 index 00000000000..c0647b171ef --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt @@ -0,0 +1,127 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.datastore + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn +import org.mifospay.core.common.DataState +import org.mifospay.core.model.account.DefaultAccount +import org.mifospay.core.model.client.Client +import org.mifospay.core.model.client.UpdatedClient +import org.mifospay.core.model.user.UserInfo + +class UserPreferencesRepositoryImpl( + private val preferenceManager: UserPreferencesDataSource, + private val ioDispatcher: CoroutineDispatcher, + unconfinedDispatcher: CoroutineDispatcher, +) : UserPreferencesRepository { + private val unconfinedScope = CoroutineScope(unconfinedDispatcher) + + override val userInfo: Flow + get() = preferenceManager.userInfo.flowOn(ioDispatcher) + + override val token: StateFlow + get() = preferenceManager.token.stateIn( + scope = unconfinedScope, + initialValue = null, + started = SharingStarted.Eagerly, + ) + + override val client: StateFlow + get() = preferenceManager.clientInfo.stateIn( + scope = unconfinedScope, + initialValue = null, + started = SharingStarted.Eagerly, + ) + + override val clientId: StateFlow + get() = preferenceManager.clientId.stateIn( + scope = unconfinedScope, + initialValue = null, + started = SharingStarted.Eagerly, + ) + + override val authToken: String? + get() = preferenceManager.getAuthToken() + + override val defaultAccount: StateFlow + get() = preferenceManager.defaultAccount.stateIn( + scope = unconfinedScope, + initialValue = null, + started = SharingStarted.Eagerly, + ) + + override val defaultAccountId: StateFlow + get() = preferenceManager.defaultAccount + .map { it?.accountId }.stateIn( + scope = unconfinedScope, + initialValue = null, + started = SharingStarted.Eagerly, + ) + + override suspend fun updateDefaultAccount(account: DefaultAccount): DataState { + return try { + val result = preferenceManager.updateDefaultAccount(account) + + DataState.Success(result) + } catch (e: Exception) { + DataState.Error(e) + } + } + + override suspend fun updateToken(token: String): DataState { + return try { + val result = preferenceManager.updateAuthToken(token) + + DataState.Success(result) + } catch (e: Exception) { + DataState.Error(e) + } + } + + override suspend fun updateClientInfo(client: Client): DataState { + return try { + val result = preferenceManager.updateClientInfo(client) + + DataState.Success(result) + } catch (e: Exception) { + DataState.Error(e) + } + } + + override suspend fun updateClientProfile(client: UpdatedClient): DataState { + return try { + val result = preferenceManager.updateClientProfile(client) + DataState.Success(result) + } catch (e: Exception) { + DataState.Error(e) + } + } + + override suspend fun updateUserInfo(user: UserInfo): DataState { + return try { + val result = preferenceManager.updateUserInfo(user) + + DataState.Success(result) + } catch (e: Exception) { + DataState.Error(e) + } + } + + override suspend fun logOut() { + preferenceManager.clearInfo() + } +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt new file mode 100644 index 00000000000..3e05a9f553a --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore.di + +import com.russhwolf.settings.Settings +import org.koin.core.qualifier.named +import org.koin.dsl.module +import org.mifos.core.datastore.MifosDispatchers +import org.mifos.core.datastore.UserPreferencesDataSource +import org.mifospay.core.datastore.UserPreferencesRepository +import org.mifospay.core.datastore.UserPreferencesRepositoryImpl + + +val PreferencesModule = module { + factory { Settings() } + // Use the IO dispatcher name - MifosDispatchers.IO.name + factory { UserPreferencesDataSource(get(), get(named(MifosDispatchers.IO.name))) } + + single { + UserPreferencesRepositoryImpl( + preferenceManager = get(), + ioDispatcher = get(named(MifosDispatchers.IO.name)), + unconfinedDispatcher = get(named(MifosDispatchers.Unconfined.name)), + ) + } +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt new file mode 100644 index 00000000000..5d1a3acf747 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +import org.mifos.core.datastore.Parcelable +import org.mifos.core.datastore.Parcelize + +@Parcelize +data class Client( + val id: Long, + val accountNo: String, + val externalId: String, + val active: Boolean, + val activationDate: List, + val firstname: String, + val lastname: String, + val displayName: String, + val mobileNo: String, + val emailAddress: String, + val dateOfBirth: List, + val isStaff: Boolean, + val officeId: Long, + val officeName: String, + val savingsProductName: String, + val timeline: ClientTimeline = ClientTimeline(), + val status: ClientStatus = ClientStatus(), + val legalForm: ClientStatus = ClientStatus(), +) : Parcelable diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt new file mode 100644 index 00000000000..56f05ed22a1 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore.model + +import kotlinx.serialization.Serializable + +@Serializable +data class ClientPreferences( + val id: Long, + val accountNo: String, + val externalId: String, + val active: Boolean, + val activationDate: List, + val firstname: String, + val lastname: String, + val displayName: String, + val mobileNo: String, + val emailAddress: String, + val dateOfBirth: List, + val isStaff: Boolean, + val officeId: Long, + val officeName: String, + val savingsProductName: String, +) { + companion object { + val DEFAULT = ClientPreferences( + id = 0L, + accountNo = "", + externalId = "", + active = false, + activationDate = emptyList(), + firstname = "", + lastname = "", + displayName = "", + mobileNo = "", + emailAddress = "", + dateOfBirth = emptyList(), + isStaff = false, + officeId = 0, + officeName = "", + savingsProductName = "", + ) + } +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt new file mode 100644 index 00000000000..cc535a86b24 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +import kotlinx.serialization.Serializable +import org.mifos.core.datastore.Parcelize + +@Serializable +@Parcelize +data class DefaultAccount( + val accountId: Long, + val accountNo: String, +) : Parcelable { + companion object { + val DEFAULT = DefaultAccount( + accountId = 0, + accountNo = "", + ) + } +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt new file mode 100644 index 00000000000..89c9ef1c03b --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore.model + +import kotlinx.serialization.Serializable + +@Serializable +data class RolePreferences( + val id: String, + val name: String, + val description: String, + val disabled: Boolean, +) { + companion object { + val DEFAULT = RolePreferences( + id = "", + name = "", + description = "", + disabled = false, + ) + } +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt new file mode 100644 index 00000000000..4f24a3231ed --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +import org.mifospay.core.datastore.Parcelable +import org.mifospay.core.datastore.Parcelize + +@Parcelize +data class UpdatedClient( + val firstname: String, + val lastname: String, + val externalId: String, + val mobileNo: String, + val emailAddress: String, +) : Parcelable diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt new file mode 100644 index 00000000000..ffd80ad9971 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore.model + +import kotlinx.serialization.Serializable + +@Serializable +data class UserInfoPreferences( + val username: String, + val userId: Long, + val base64EncodedAuthenticationKey: String, + val authenticated: Boolean, + val officeId: Int, + val officeName: String, + val roles: List, + val permissions: List, + val clients: List, + val shouldRenewPassword: Boolean, + val isTwoFactorAuthenticationRequired: Boolean, +) { + companion object { + val DEFAULT = UserInfoPreferences( + username = "", + userId = 0, + base64EncodedAuthenticationKey = "", + authenticated = false, + officeId = 0, + officeName = "", + roles = emptyList(), + permissions = emptyList(), + clients = emptyList(), + shouldRenewPassword = false, + isTwoFactorAuthenticationRequired = false, + ) + } +} From 1a1e7171503f49d14b09544bc07179a0d1d80e46 Mon Sep 17 00:00:00 2001 From: kapmaurya Date: Tue, 21 Jan 2025 23:20:43 +0530 Subject: [PATCH 02/13] commit message --- .../com.mifos.room.db.MifosDatabase/1.json | 45 ++++++++++++++++++ core/datastore/build.gradle.kts | 34 +++++++------- .../org.mifos.core.datastore/DataState.kt | 39 +++++++++++++++ .../PreferencesMapper.kt | 5 +- .../org.mifos.core.datastore/RoleInfo.kt | 2 +- .../org.mifos.core.datastore/UserInfo.kt | 2 +- .../UserPreferencesDataSource.kt | 4 +- .../UserPreferencesRepository.kt | 12 ++--- .../UserPreferencesRepositoryImpl.kt | 12 ++--- .../di/PreferenceModule.kt | 4 +- .../org.mifos.core.datastore/model/Client.kt | 10 ++-- .../model/DefaultAccount.kt | 10 +--- .../model/UpdatedClient.kt | 5 +- .../Parcelize.desktop.kt | 46 ++++++++++++++++++ .../org.mifos.core.datastore/Parcelize.js.kt | 46 ++++++++++++++++++ .../Parcelize.android.kt | 47 +++++++++++++++++++ .../Parcelize.native.kt | 46 ++++++++++++++++++ .../Parcelize.wasmJs.kt | 46 ++++++++++++++++++ gradle/libs.versions.toml | 2 +- 19 files changed, 359 insertions(+), 58 deletions(-) create mode 100644 core/database/schemas/com.mifos.room.db.MifosDatabase/1.json create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt create mode 100644 core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt create mode 100644 core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt create mode 100644 core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt create mode 100644 core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt create mode 100644 core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt diff --git a/core/database/schemas/com.mifos.room.db.MifosDatabase/1.json b/core/database/schemas/com.mifos.room.db.MifosDatabase/1.json new file mode 100644 index 00000000000..0e84f2baf5e --- /dev/null +++ b/core/database/schemas/com.mifos.room.db.MifosDatabase/1.json @@ -0,0 +1,45 @@ +{ + "formatVersion": 1, + "database": { + "version": 1, + "identityHash": "52a9a8b64b78975c74e557a9c0411c25", + "entities": [ + { + "tableName": "ColumnValue", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER, `value` TEXT, `score` INTEGER, `registeredTableName` TEXT, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER" + }, + { + "fieldPath": "value", + "columnName": "value", + "affinity": "TEXT" + }, + { + "fieldPath": "score", + "columnName": "score", + "affinity": "INTEGER" + }, + { + "fieldPath": "registeredTableName", + "columnName": "registeredTableName", + "affinity": "TEXT" + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + } + } + ], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '52a9a8b64b78975c74e557a9c0411c25')" + ] + } +} \ No newline at end of file diff --git a/core/datastore/build.gradle.kts b/core/datastore/build.gradle.kts index f7bd49852b0..9938055e088 100644 --- a/core/datastore/build.gradle.kts +++ b/core/datastore/build.gradle.kts @@ -8,9 +8,9 @@ * See https://github.com/openMF/android-client/blob/master/LICENSE.md */ plugins { - alias(libs.plugins.mifos.android.library) - alias(libs.plugins.mifos.android.library.jacoco) - alias(libs.plugins.mifos.android.hilt) + alias(libs.plugins.mifos.kmp.library) + id(libs.plugins.kotlin.parcelize.get().pluginId) + id("kotlinx-serialization") } android { @@ -19,22 +19,20 @@ android { defaultConfig { consumerProguardFiles("consumer-proguard-rules.pro") } - testOptions { - unitTests { - isReturnDefaultValues = true - } - } + } dependencies { - api(projects.core.model) - api(projects.core.common) - - api(libs.converter.gson) - - // fineract sdk dependencies - api(libs.mifos.android.sdk.arch) - - // sdk client - api(libs.fineract.client) + kotlin { + sourceSets { + commonMain.dependencies { + implementation(libs.multiplatform.settings) + implementation(libs.multiplatform.settings.serialization) + implementation(libs.multiplatform.settings.coroutines) + implementation(libs.kotlinx.coroutines.core) + implementation(libs.kotlinx.serialization.core) + // implementation(projects.core.common) + } + } + } } \ No newline at end of file diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt new file mode 100644 index 00000000000..048e2487cf5 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.onStart + +sealed class DataState { + abstract val data: T? + + data object Loading : DataState() { + override val data: Nothing? get() = null + } + + data class Success( + override val data: T, + ) : DataState() + + data class Error( + val exception: Throwable, + override val data: T? = null, + ) : DataState() { + val message = exception.message.toString() + } +} + +fun Flow.asDataStateFlow(): Flow> = + map> { DataState.Success(it) } + .onStart { emit(DataState.Loading) } + .catch { emit(DataState.Error(it, null)) } diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt index 775e03a7e31..9599cf7a610 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt @@ -12,9 +12,8 @@ package org.mifos.core.datastore import org.mifos.core.datastore.model.ClientPreferences import org.mifos.core.datastore.model.RolePreferences import org.mifos.core.datastore.model.UserInfoPreferences -import org.mifos.core.model.client.Client -import org.mifos.core.model.user.RoleInfo -import org.mifos.core.model.user.UserInfo + + fun ClientPreferences.toClientInfo(): Client { return Client( diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt index 89e9025cef6..0c7b2c1ef6b 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt @@ -17,4 +17,4 @@ data class RoleInfo( val name: String, val description: String, val disabled: Boolean, -) : Parcelable +) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt index 7a03a94a1c7..1056b52673f 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt @@ -24,4 +24,4 @@ data class UserInfo( val clients: List, val shouldRenewPassword: Boolean, val isTwoFactorAuthenticationRequired: Boolean, -) : Parcelable +) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt index cf107862b08..68d58ef0d17 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt @@ -24,9 +24,9 @@ import kotlinx.serialization.ExperimentalSerializationApi import org.mifos.core.datastore.UserPreferencesDataSource.Companion.DEFAULT_ACCOUNT import org.mifos.core.datastore.model.ClientPreferences import org.mifos.core.datastore.model.UserInfoPreferences -//import org.mifos.core.datastore.model.Client +import org.mifos.core.datastore.Client //import org.mifos.core.datastore.model.UpdatedClient -import org.mifos.core.model.user.UserInfo +import org.mifos.core.datastore.UserInfo private const val USER_INFO_KEY = "userInfo" private const val CLIENT_INFO_KEY = "clientInfo" diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt index ad807598375..0ab0b08d342 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt @@ -7,15 +7,15 @@ * * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md */ -package org.mifospay.core.datastore +package org.mifos.core.datastore import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow -import org.mifospay.core.common.DataState -import org.mifospay.core.model.account.DefaultAccount -import org.mifospay.core.model.client.Client -import org.mifospay.core.model.client.UpdatedClient -import org.mifospay.core.model.user.UserInfo +//import org.mifos.core.datastore +//import org.mifospay.core.model.account.DefaultAccount +//import org.mifospay.core.model.client.Client +//import org.mifospay.core.model.client.UpdatedClient +//import org.mifospay.core.model.user.UserInfo interface UserPreferencesRepository { val userInfo: Flow diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt index c0647b171ef..06ed4f79c01 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt @@ -7,7 +7,7 @@ * * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md */ -package org.mifospay.core.datastore +package org.mifos.core.datastore import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope @@ -17,11 +17,11 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn -import org.mifospay.core.common.DataState -import org.mifospay.core.model.account.DefaultAccount -import org.mifospay.core.model.client.Client -import org.mifospay.core.model.client.UpdatedClient -import org.mifospay.core.model.user.UserInfo +//import org.mifospay.core.common.DataState +//import org.mifospay.core.model.account.DefaultAccount +//import org.mifospay.core.model.client.Client +//import org.mifospay.core.model.client.UpdatedClient +//import org.mifospay.core.model.user.UserInfo class UserPreferencesRepositoryImpl( private val preferenceManager: UserPreferencesDataSource, diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt index 3e05a9f553a..cac8fc70f5b 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt @@ -14,8 +14,8 @@ import org.koin.core.qualifier.named import org.koin.dsl.module import org.mifos.core.datastore.MifosDispatchers import org.mifos.core.datastore.UserPreferencesDataSource -import org.mifospay.core.datastore.UserPreferencesRepository -import org.mifospay.core.datastore.UserPreferencesRepositoryImpl +import org.mifos.core.datastore.UserPreferencesRepository +import org.mifos.core.datastore.UserPreferencesRepositoryImpl val PreferencesModule = module { diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt index 5d1a3acf747..fb9364f025b 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt @@ -9,8 +9,7 @@ */ package org.mifos.core.datastore -import org.mifos.core.datastore.Parcelable -import org.mifos.core.datastore.Parcelize + @Parcelize data class Client( @@ -28,8 +27,5 @@ data class Client( val isStaff: Boolean, val officeId: Long, val officeName: String, - val savingsProductName: String, - val timeline: ClientTimeline = ClientTimeline(), - val status: ClientStatus = ClientStatus(), - val legalForm: ClientStatus = ClientStatus(), -) : Parcelable + val savingsProductName: String +) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt index cc535a86b24..7bdaa566652 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt @@ -17,11 +17,5 @@ import org.mifos.core.datastore.Parcelize data class DefaultAccount( val accountId: Long, val accountNo: String, -) : Parcelable { - companion object { - val DEFAULT = DefaultAccount( - accountId = 0, - accountNo = "", - ) - } -} +) + diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt index 4f24a3231ed..7514fc6d300 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt @@ -9,8 +9,7 @@ */ package org.mifos.core.datastore -import org.mifospay.core.datastore.Parcelable -import org.mifospay.core.datastore.Parcelize + @Parcelize data class UpdatedClient( @@ -19,4 +18,4 @@ data class UpdatedClient( val externalId: String, val mobileNo: String, val emailAddress: String, -) : Parcelable +) diff --git a/core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt b/core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt new file mode 100644 index 00000000000..505c69125c0 --- /dev/null +++ b/core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +//actual interface Parcelable +//actual annotation class IgnoredOnParcel +actual annotation class Parcelize +actual interface Parceler

{ + actual fun create(parcel: Parcel): P + actual fun P.write(parcel: Parcel, flags: Int) +} + +actual annotation class TypeParceler> + +actual class Parcel { + actual fun readString(): String? = null + actual fun readByte(): Byte = 1 + + actual fun readInt(): Int = 1 + + actual fun readFloat(): Float = 1f + + actual fun readDouble(): Double = 1.0 + + actual fun writeByte(value: Byte) { + } + + actual fun writeInt(value: Int) { + } + + actual fun writeFloat(value: Float) { + } + + actual fun writeDouble(value: Double) { + } + + actual fun writeString(value: String?) { + } +} diff --git a/core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt b/core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt new file mode 100644 index 00000000000..505c69125c0 --- /dev/null +++ b/core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +//actual interface Parcelable +//actual annotation class IgnoredOnParcel +actual annotation class Parcelize +actual interface Parceler

{ + actual fun create(parcel: Parcel): P + actual fun P.write(parcel: Parcel, flags: Int) +} + +actual annotation class TypeParceler> + +actual class Parcel { + actual fun readString(): String? = null + actual fun readByte(): Byte = 1 + + actual fun readInt(): Int = 1 + + actual fun readFloat(): Float = 1f + + actual fun readDouble(): Double = 1.0 + + actual fun writeByte(value: Byte) { + } + + actual fun writeInt(value: Int) { + } + + actual fun writeFloat(value: Float) { + } + + actual fun writeDouble(value: Double) { + } + + actual fun writeString(value: String?) { + } +} diff --git a/core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt b/core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt new file mode 100644 index 00000000000..51d01bd51df --- /dev/null +++ b/core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt @@ -0,0 +1,47 @@ +package org.mifos.core.datastore + +actual interface Parceler

{ + actual fun create(parcel: Parcel): P + actual fun P.write(parcel: Parcel, flags: Int) + +} + +actual annotation class TypeParceler> actual constructor() +actual annotation class Parcelize actual constructor() +actual class Parcel { + actual fun readByte(): Byte { + TODO("Not yet implemented") + } + + actual fun readInt(): Int { + TODO("Not yet implemented") + } + + actual fun readFloat(): Float { + TODO("Not yet implemented") + } + + actual fun readDouble(): Double { + TODO("Not yet implemented") + } + + actual fun readString(): String? { + TODO("Not yet implemented") + } + + actual fun writeByte(value: Byte) { + } + + actual fun writeInt(value: Int) { + } + + actual fun writeFloat(value: Float) { + } + + actual fun writeDouble(value: Double) { + } + + actual fun writeString(value: String?) { + } + +} \ No newline at end of file diff --git a/core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt b/core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt new file mode 100644 index 00000000000..505c69125c0 --- /dev/null +++ b/core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +//actual interface Parcelable +//actual annotation class IgnoredOnParcel +actual annotation class Parcelize +actual interface Parceler

{ + actual fun create(parcel: Parcel): P + actual fun P.write(parcel: Parcel, flags: Int) +} + +actual annotation class TypeParceler> + +actual class Parcel { + actual fun readString(): String? = null + actual fun readByte(): Byte = 1 + + actual fun readInt(): Int = 1 + + actual fun readFloat(): Float = 1f + + actual fun readDouble(): Double = 1.0 + + actual fun writeByte(value: Byte) { + } + + actual fun writeInt(value: Int) { + } + + actual fun writeFloat(value: Float) { + } + + actual fun writeDouble(value: Double) { + } + + actual fun writeString(value: String?) { + } +} diff --git a/core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt b/core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt new file mode 100644 index 00000000000..505c69125c0 --- /dev/null +++ b/core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +//actual interface Parcelable +//actual annotation class IgnoredOnParcel +actual annotation class Parcelize +actual interface Parceler

{ + actual fun create(parcel: Parcel): P + actual fun P.write(parcel: Parcel, flags: Int) +} + +actual annotation class TypeParceler> + +actual class Parcel { + actual fun readString(): String? = null + actual fun readByte(): Byte = 1 + + actual fun readInt(): Int = 1 + + actual fun readFloat(): Float = 1f + + actual fun readDouble(): Double = 1.0 + + actual fun writeByte(value: Byte) { + } + + actual fun writeInt(value: Int) { + } + + actual fun writeFloat(value: Float) { + } + + actual fun writeDouble(value: Double) { + } + + actual fun writeString(value: String?) { + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 67ab31e3b3b..d32c073d1e9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,7 +7,7 @@ androidDesugarJdkLibs = "2.1.4" androidIconifyMaterial = "2.2.2" androidJob = "1.2.6" androidMapsUtils = "0.4.2" -androidGradlePlugin = "8.8.0" +androidGradlePlugin = "8.7.2" androidTools = "31.8.0" androidxActivity = "1.9.3" androidxAppCompat = "1.7.0" From c3070456dbcecd4b4dbf547aeda5d714a2cb750c Mon Sep 17 00:00:00 2001 From: kapmaurya Date: Thu, 30 Jan 2025 17:39:48 +0530 Subject: [PATCH 03/13] datastore-migration-kmpl --- core/datastore/build.gradle.kts | 2 +- .../org.mifos.core.datastore/DataState.kt | 39 --- .../MifosDispatchers.kt | 26 -- .../org.mifos.core.datastore/Parcelize.kt | 39 --- .../PreferencesMapper.kt | 106 -------- .../org.mifos.core.datastore/RoleInfo.kt | 20 -- .../org.mifos.core.datastore/UserInfo.kt | 27 -- .../UserPreferencesDataSource.kt | 243 +++++++----------- .../UserPreferencesRepository.kt | 33 +-- .../UserPreferencesRepositoryImpl.kt | 106 +------- .../di/PreferenceModule.kt | 7 +- .../org.mifos.core.datastore/model/Client.kt | 31 --- .../model/ClientPreferences.kt | 51 ---- .../model/DefaultAccount.kt | 21 -- .../model/RolePreferences.kt | 29 --- .../model/UpdatedClient.kt | 21 -- .../org.mifos.core.datastore/model/User.kt | 19 ++ .../model/UserInfoPreferences.kt | 43 ---- .../Parcelize.desktop.kt | 46 ---- .../org.mifos.core.datastore/Parcelize.js.kt | 46 ---- .../com/mifos/core/datastore/PrefManager.kt | 172 ++++++------- .../Parcelize.android.kt | 47 ---- .../Parcelize.native.kt | 46 ---- .../Parcelize.wasmJs.kt | 46 ---- 24 files changed, 222 insertions(+), 1044 deletions(-) delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/User.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt delete mode 100644 core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt delete mode 100644 core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt delete mode 100644 core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt delete mode 100644 core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt delete mode 100644 core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt diff --git a/core/datastore/build.gradle.kts b/core/datastore/build.gradle.kts index 9938055e088..8965b1842da 100644 --- a/core/datastore/build.gradle.kts +++ b/core/datastore/build.gradle.kts @@ -9,7 +9,7 @@ */ plugins { alias(libs.plugins.mifos.kmp.library) - id(libs.plugins.kotlin.parcelize.get().pluginId) + //id(libs.plugins.kotlin.parcelize.get().pluginId) id("kotlinx-serialization") } diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt deleted file mode 100644 index 048e2487cf5..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.catch -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.onStart - -sealed class DataState { - abstract val data: T? - - data object Loading : DataState() { - override val data: Nothing? get() = null - } - - data class Success( - override val data: T, - ) : DataState() - - data class Error( - val exception: Throwable, - override val data: T? = null, - ) : DataState() { - val message = exception.message.toString() - } -} - -fun Flow.asDataStateFlow(): Flow> = - map> { DataState.Success(it) } - .onStart { emit(DataState.Loading) } - .catch { emit(DataState.Error(it, null)) } diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt deleted file mode 100644 index 65c5fa6872d..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -import org.koin.core.annotation.Qualifier - -@Qualifier -@Retention(AnnotationRetention.RUNTIME) -annotation class Dispatcher(val mifosDispatcher: MifosDispatchers) - -enum class MifosDispatchers { - Default, - IO, - Unconfined, -} - -@Qualifier -@Retention(AnnotationRetention.RUNTIME) -annotation class ApplicationScope diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt deleted file mode 100644 index a5c53c24d83..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -expect annotation class Parcelize() - -//expect annotation class IgnoredOnParcel() - -expect interface Parceler

{ - fun create(parcel: Parcel): P - - fun P.write(parcel: Parcel, flags: Int) -} - -expect annotation class TypeParceler>() - -expect class Parcel { - fun readByte(): Byte - fun readInt(): Int - - fun readFloat(): Float - fun readDouble(): Double - fun readString(): String? - - fun writeByte(value: Byte) - fun writeInt(value: Int) - - fun writeFloat(value: Float) - - fun writeDouble(value: Double) - fun writeString(value: String?) -} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt deleted file mode 100644 index 9599cf7a610..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -import org.mifos.core.datastore.model.ClientPreferences -import org.mifos.core.datastore.model.RolePreferences -import org.mifos.core.datastore.model.UserInfoPreferences - - - -fun ClientPreferences.toClientInfo(): Client { - return Client( - id = id, - accountNo = accountNo, - externalId = externalId, - active = active, - activationDate = activationDate, - firstname = firstname, - lastname = lastname, - displayName = displayName, - mobileNo = mobileNo, - emailAddress = emailAddress, - dateOfBirth = dateOfBirth, - isStaff = isStaff, - officeId = officeId, - officeName = officeName, - savingsProductName = savingsProductName, - ) -} - -fun Client.toClientPreferences(): ClientPreferences { - return ClientPreferences( - id = id, - accountNo = accountNo, - externalId = externalId, - active = active, - activationDate = activationDate, - firstname = firstname, - lastname = lastname, - displayName = displayName, - mobileNo = mobileNo, - emailAddress = emailAddress, - dateOfBirth = dateOfBirth, - isStaff = isStaff, - officeId = officeId, - officeName = officeName, - savingsProductName = savingsProductName, - ) -} - -fun RolePreferences.toRoleInfo(): RoleInfo { - return RoleInfo( - id = id, - name = name, - description = description, - disabled = disabled, - ) -} - -fun RoleInfo.toRolePreferences(): RolePreferences { - return RolePreferences( - id = id, - name = name, - description = description, - disabled = disabled, - ) -} - -fun UserInfoPreferences.toUserInfo(): UserInfo { - return UserInfo( - username = username, - userId = userId, - base64EncodedAuthenticationKey = base64EncodedAuthenticationKey, - authenticated = authenticated, - officeId = officeId, - officeName = officeName, - roles = roles.map { it.toRoleInfo() }, - permissions = permissions, - clients = clients, - shouldRenewPassword = shouldRenewPassword, - isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired, - ) -} - -fun UserInfo.toUserInfoPreferences(): UserInfoPreferences { - return UserInfoPreferences( - username = username, - userId = userId, - base64EncodedAuthenticationKey = base64EncodedAuthenticationKey, - authenticated = authenticated, - officeId = officeId, - officeName = officeName, - roles = roles.map { it.toRolePreferences() }, - permissions = permissions, - clients = clients, - shouldRenewPassword = shouldRenewPassword, - isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired, - ) -} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt deleted file mode 100644 index 0c7b2c1ef6b..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - - - -@Parcelize -data class RoleInfo( - val id: String, - val name: String, - val description: String, - val disabled: Boolean, -) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt deleted file mode 100644 index 1056b52673f..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - - - -@Parcelize -data class UserInfo( - val username: String, - val userId: Long, - val base64EncodedAuthenticationKey: String, - val authenticated: Boolean, - val officeId: Int, - val officeName: String, - val roles: List, - val permissions: List, - val clients: List, - val shouldRenewPassword: Boolean, - val isTwoFactorAuthenticationRequired: Boolean, -) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt index 68d58ef0d17..653f6e0580c 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt @@ -1,174 +1,127 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -@file:OptIn(ExperimentalSerializationApi::class, ExperimentalSettingsApi::class) - +///* +// * Copyright 2024 Mifos Initiative +// * +// * This Source Code Form is subject to the terms of the Mozilla Public +// * License, v. 2.0. If a copy of the MPL was not distributed with this +// * file, You can obtain one at https://mozilla.org/MPL/2.0/. +// * +// * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md +// */ +//@file:OptIn(ExperimentalSerializationApi::class, ExperimentalSettingsApi::class) +// package org.mifos.core.datastore +// +//import com.russhwolf.settings.ExperimentalSettingsApi +//import com.russhwolf.settings.Settings +//import com.russhwolf.settings.serialization.decodeValue +//import com.russhwolf.settings.serialization.decodeValueOrNull +//import com.russhwolf.settings.serialization.encodeValue +//import kotlinx.coroutines.CoroutineDispatcher +// +//import kotlinx.coroutines.flow.MutableStateFlow +//import kotlinx.coroutines.flow.map +//import kotlinx.coroutines.withContext +//import kotlinx.serialization.ExperimentalSerializationApi +// +// +//private const val USER_INFO_KEY = "userInfo" +// +// +//@OptIn(ExperimentalSerializationApi::class) +//class UserPreferencesDataSource( +// private val settings: Settings, +// private val dispatcher: CoroutineDispatcher, +//) { +// private val _userInfo = MutableStateFlow( +// settings.decodeValue( +// key = USER_INFO_KEY, +// serializer = UserInfoPreferences.serializer(), +// defaultValue = settings.decodeValueOrNull( +// key = USER_INFO_KEY, +// serializer = UserInfoPreferences.serializer(), +// ) ?: UserInfoPreferences.DEFAULT, +// ), +// ) +// +// +// val userInfo = _userInfo.map(UserInfoPreferences::toUserInfo) +// +// suspend fun updateUserInfo(userInfo: UserInfo) { +// withContext(dispatcher) { +// settings.putUserInfoPreference(userInfo.toUserInfoPreferences()) +// _userInfo.value = userInfo.toUserInfoPreferences() +// } +// } +// +// +// +// +// suspend fun clearInfo() { +// withContext(dispatcher) { +// settings.clear() +// } +// } +// +// +//} +// +// +// +//private fun Settings.putUserInfoPreference(preference: UserInfoPreferences) { +// encodeValue( +// key = USER_INFO_KEY, +// serializer = UserInfoPreferences.serializer(), +// value = preference, +// ) +//} +// +// -import com.russhwolf.settings.ExperimentalSettingsApi -import com.russhwolf.settings.Settings import com.russhwolf.settings.serialization.decodeValue import com.russhwolf.settings.serialization.decodeValueOrNull +import kotlinx.coroutines.withContext +import com.russhwolf.settings.ExperimentalSettingsApi +import com.russhwolf.settings.Settings import com.russhwolf.settings.serialization.encodeValue import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.withContext import kotlinx.serialization.ExperimentalSerializationApi -import org.mifos.core.datastore.UserPreferencesDataSource.Companion.DEFAULT_ACCOUNT -import org.mifos.core.datastore.model.ClientPreferences -import org.mifos.core.datastore.model.UserInfoPreferences -import org.mifos.core.datastore.Client -//import org.mifos.core.datastore.model.UpdatedClient -import org.mifos.core.datastore.UserInfo - -private const val USER_INFO_KEY = "userInfo" -private const val CLIENT_INFO_KEY = "clientInfo" +import org.mifos.core.datastore.model.UserData -@OptIn(ExperimentalSerializationApi::class) +private const val USER_DATA = "userData" class UserPreferencesDataSource( private val settings: Settings, private val dispatcher: CoroutineDispatcher, ) { + @OptIn(ExperimentalSerializationApi::class, ExperimentalSettingsApi::class) private val _userInfo = MutableStateFlow( settings.decodeValue( - key = USER_INFO_KEY, - serializer = UserInfoPreferences.serializer(), + key = USER_DATA, + serializer = UserData.serializer(), defaultValue = settings.decodeValueOrNull( - key = USER_INFO_KEY, - serializer = UserInfoPreferences.serializer(), - ) ?: UserInfoPreferences.DEFAULT, + key = USER_DATA, + serializer = UserData.serializer(), + ) ?: UserData.DEFAULT, ), ) - - private val _clientInfo = MutableStateFlow( - settings.decodeValue( - key = CLIENT_INFO_KEY, - serializer = ClientPreferences.serializer(), - defaultValue = settings.decodeValueOrNull( - key = CLIENT_INFO_KEY, - serializer = ClientPreferences.serializer(), - ) ?: ClientPreferences.DEFAULT, - ), - ) - - private val _defaultAccount = MutableStateFlow( - settings.decodeValue( - key = DEFAULT_ACCOUNT, - serializer = DefaultAccount.serializer(), - defaultValue = settings.decodeValueOrNull( - key = DEFAULT_ACCOUNT, - serializer = DefaultAccount.serializer(), - ) ?: DefaultAccount.DEFAULT, - ), - ) - - val token = _userInfo.map { - it.base64EncodedAuthenticationKey - } - val userInfo = _userInfo.map(UserInfoPreferences::toUserInfo) - - val clientInfo = _clientInfo.map(ClientPreferences::toClientInfo) - - val clientId = _clientInfo.map { it.id } - - val defaultAccount = _defaultAccount.map { it.takeIf { it.accountId != 0L } } - - suspend fun updateClientInfo(client: Client) { + val userInfo = _userInfo + suspend fun updateUserInfo(user: UserData) { withContext(dispatcher) { - settings.putClientPreference(client.toClientPreferences()) - _clientInfo.value = client.toClientPreferences() + settings.putUserPreference(user) + _userInfo.value = user } } - - suspend fun updateUserInfo(userInfo: UserInfo) { - withContext(dispatcher) { - settings.putUserInfoPreference(userInfo.toUserInfoPreferences()) - _userInfo.value = userInfo.toUserInfoPreferences() - } - } - - suspend fun updateClientProfile(client: UpdatedClient) { - withContext(dispatcher) { - val updatedClient = _clientInfo.value.copy( - firstname = client.firstname, - lastname = client.lastname, - displayName = client.firstname + " " + client.lastname, - emailAddress = client.emailAddress, - mobileNo = client.mobileNo, - externalId = client.externalId, - ) - - settings.putClientPreference(updatedClient) - _clientInfo.value = updatedClient - } - } - - suspend fun updateToken(token: String) { - withContext(dispatcher) { - settings.putUserInfoPreference( - UserInfoPreferences.DEFAULT.copy( - base64EncodedAuthenticationKey = token, - ), - ) - _userInfo.value = UserInfoPreferences.DEFAULT.copy( - base64EncodedAuthenticationKey = token, - ) - } - } - - fun updateDefaultAccount(account: DefaultAccount) { - settings.putDefaultAccount(account) - - _defaultAccount.value = account - } - - fun updateAuthToken(token: String) { - settings.putString(AUTH_TOKEN, token) - } - - fun getAuthToken(): String? { - return settings.getString(AUTH_TOKEN, "").ifEmpty { null } - } - suspend fun clearInfo() { withContext(dispatcher) { settings.clear() } } - - companion object { - const val AUTH_TOKEN = "authToken" - const val DEFAULT_ACCOUNT = "default_account" - } -} - -private fun Settings.putClientPreference(preference: ClientPreferences) { - encodeValue( - key = CLIENT_INFO_KEY, - serializer = ClientPreferences.serializer(), - value = preference, - ) } - -private fun Settings.putUserInfoPreference(preference: UserInfoPreferences) { +@OptIn(ExperimentalSerializationApi::class, ExperimentalSettingsApi::class) +private fun Settings.putUserPreference(user: UserData) { encodeValue( - key = USER_INFO_KEY, - serializer = UserInfoPreferences.serializer(), - value = preference, + key = USER_DATA, + serializer = UserData.serializer(), + value = user, ) -} - -private fun Settings.putDefaultAccount(account: DefaultAccount) { - encodeValue( - key = DEFAULT_ACCOUNT, - serializer = DefaultAccount.serializer(), - value = account, - ) -} +} \ No newline at end of file diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt index 0ab0b08d342..1a76e1ab832 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt @@ -10,37 +10,12 @@ package org.mifos.core.datastore import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.StateFlow -//import org.mifos.core.datastore -//import org.mifospay.core.model.account.DefaultAccount -//import org.mifospay.core.model.client.Client -//import org.mifospay.core.model.client.UpdatedClient -//import org.mifospay.core.model.user.UserInfo +import org.mifos.core.datastore.model.UserData -interface UserPreferencesRepository { - val userInfo: Flow - - val token: StateFlow - - val client: StateFlow - - val clientId: StateFlow - - val authToken: String? - - val defaultAccount: StateFlow - val defaultAccountId: StateFlow - - suspend fun updateToken(token: String): DataState - - suspend fun updateUserInfo(user: UserInfo): DataState - - suspend fun updateClientInfo(client: Client): DataState - - suspend fun updateClientProfile(client: UpdatedClient): DataState - - suspend fun updateDefaultAccount(account: DefaultAccount): DataState +interface UserPreferencesRepository { + val userInfo: Flow + suspend fun updateUser(user: UserData): Result suspend fun logOut(): Unit } diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt index 06ed4f79c01..e1de6eafaa5 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt @@ -9,19 +9,11 @@ */ package org.mifos.core.datastore + import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.flowOn -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.stateIn -//import org.mifospay.core.common.DataState -//import org.mifospay.core.model.account.DefaultAccount -//import org.mifospay.core.model.client.Client -//import org.mifospay.core.model.client.UpdatedClient -//import org.mifospay.core.model.user.UserInfo +import org.mifos.core.datastore.model.UserData class UserPreferencesRepositoryImpl( private val preferenceManager: UserPreferencesDataSource, @@ -29,99 +21,17 @@ class UserPreferencesRepositoryImpl( unconfinedDispatcher: CoroutineDispatcher, ) : UserPreferencesRepository { private val unconfinedScope = CoroutineScope(unconfinedDispatcher) - - override val userInfo: Flow - get() = preferenceManager.userInfo.flowOn(ioDispatcher) - - override val token: StateFlow - get() = preferenceManager.token.stateIn( - scope = unconfinedScope, - initialValue = null, - started = SharingStarted.Eagerly, - ) - - override val client: StateFlow - get() = preferenceManager.clientInfo.stateIn( - scope = unconfinedScope, - initialValue = null, - started = SharingStarted.Eagerly, - ) - - override val clientId: StateFlow - get() = preferenceManager.clientId.stateIn( - scope = unconfinedScope, - initialValue = null, - started = SharingStarted.Eagerly, - ) - - override val authToken: String? - get() = preferenceManager.getAuthToken() - - override val defaultAccount: StateFlow - get() = preferenceManager.defaultAccount.stateIn( - scope = unconfinedScope, - initialValue = null, - started = SharingStarted.Eagerly, - ) - - override val defaultAccountId: StateFlow - get() = preferenceManager.defaultAccount - .map { it?.accountId }.stateIn( - scope = unconfinedScope, - initialValue = null, - started = SharingStarted.Eagerly, - ) - - override suspend fun updateDefaultAccount(account: DefaultAccount): DataState { - return try { - val result = preferenceManager.updateDefaultAccount(account) - - DataState.Success(result) - } catch (e: Exception) { - DataState.Error(e) - } - } - - override suspend fun updateToken(token: String): DataState { - return try { - val result = preferenceManager.updateAuthToken(token) - - DataState.Success(result) - } catch (e: Exception) { - DataState.Error(e) - } - } - - override suspend fun updateClientInfo(client: Client): DataState { - return try { - val result = preferenceManager.updateClientInfo(client) - - DataState.Success(result) - } catch (e: Exception) { - DataState.Error(e) - } - } - - override suspend fun updateClientProfile(client: UpdatedClient): DataState { - return try { - val result = preferenceManager.updateClientProfile(client) - DataState.Success(result) - } catch (e: Exception) { - DataState.Error(e) - } - } - - override suspend fun updateUserInfo(user: UserInfo): DataState { + override val userInfo: Flow + get() = preferenceManager.userInfo + override suspend fun updateUser(user: UserData): Result { return try { val result = preferenceManager.updateUserInfo(user) - - DataState.Success(result) + Result.success(result) } catch (e: Exception) { - DataState.Error(e) + Result.failure(e) } } - override suspend fun logOut() { preferenceManager.clearInfo() } -} +} \ No newline at end of file diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt index cac8fc70f5b..0a97634f518 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt @@ -12,7 +12,6 @@ package org.mifos.core.datastore.di import com.russhwolf.settings.Settings import org.koin.core.qualifier.named import org.koin.dsl.module -import org.mifos.core.datastore.MifosDispatchers import org.mifos.core.datastore.UserPreferencesDataSource import org.mifos.core.datastore.UserPreferencesRepository import org.mifos.core.datastore.UserPreferencesRepositoryImpl @@ -31,3 +30,9 @@ val PreferencesModule = module { ) } } + +enum class MifosDispatchers { + Default, + IO, + Unconfined, +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt deleted file mode 100644 index fb9364f025b..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - - - -@Parcelize -data class Client( - val id: Long, - val accountNo: String, - val externalId: String, - val active: Boolean, - val activationDate: List, - val firstname: String, - val lastname: String, - val displayName: String, - val mobileNo: String, - val emailAddress: String, - val dateOfBirth: List, - val isStaff: Boolean, - val officeId: Long, - val officeName: String, - val savingsProductName: String -) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt deleted file mode 100644 index 56f05ed22a1..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore.model - -import kotlinx.serialization.Serializable - -@Serializable -data class ClientPreferences( - val id: Long, - val accountNo: String, - val externalId: String, - val active: Boolean, - val activationDate: List, - val firstname: String, - val lastname: String, - val displayName: String, - val mobileNo: String, - val emailAddress: String, - val dateOfBirth: List, - val isStaff: Boolean, - val officeId: Long, - val officeName: String, - val savingsProductName: String, -) { - companion object { - val DEFAULT = ClientPreferences( - id = 0L, - accountNo = "", - externalId = "", - active = false, - activationDate = emptyList(), - firstname = "", - lastname = "", - displayName = "", - mobileNo = "", - emailAddress = "", - dateOfBirth = emptyList(), - isStaff = false, - officeId = 0, - officeName = "", - savingsProductName = "", - ) - } -} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt deleted file mode 100644 index 7bdaa566652..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -import kotlinx.serialization.Serializable -import org.mifos.core.datastore.Parcelize - -@Serializable -@Parcelize -data class DefaultAccount( - val accountId: Long, - val accountNo: String, -) - diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt deleted file mode 100644 index 89c9ef1c03b..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore.model - -import kotlinx.serialization.Serializable - -@Serializable -data class RolePreferences( - val id: String, - val name: String, - val description: String, - val disabled: Boolean, -) { - companion object { - val DEFAULT = RolePreferences( - id = "", - name = "", - description = "", - disabled = false, - ) - } -} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt deleted file mode 100644 index 7514fc6d300..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - - - -@Parcelize -data class UpdatedClient( - val firstname: String, - val lastname: String, - val externalId: String, - val mobileNo: String, - val emailAddress: String, -) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/User.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/User.kt new file mode 100644 index 00000000000..20cbc03746d --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/User.kt @@ -0,0 +1,19 @@ +package org.mifos.core.datastore.model + +import kotlinx.serialization.Serializable +@Serializable +data class UserData( + val userId: Long, + val userName: String, + val clientId: Long, + val isAuthenticated: Boolean +) { + companion object { + val DEFAULT = UserData( + userId = -1, + userName = "", + clientId = -1, + isAuthenticated = false, + ) + } +} \ No newline at end of file diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt deleted file mode 100644 index ffd80ad9971..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore.model - -import kotlinx.serialization.Serializable - -@Serializable -data class UserInfoPreferences( - val username: String, - val userId: Long, - val base64EncodedAuthenticationKey: String, - val authenticated: Boolean, - val officeId: Int, - val officeName: String, - val roles: List, - val permissions: List, - val clients: List, - val shouldRenewPassword: Boolean, - val isTwoFactorAuthenticationRequired: Boolean, -) { - companion object { - val DEFAULT = UserInfoPreferences( - username = "", - userId = 0, - base64EncodedAuthenticationKey = "", - authenticated = false, - officeId = 0, - officeName = "", - roles = emptyList(), - permissions = emptyList(), - clients = emptyList(), - shouldRenewPassword = false, - isTwoFactorAuthenticationRequired = false, - ) - } -} diff --git a/core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt b/core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt deleted file mode 100644 index 505c69125c0..00000000000 --- a/core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -//actual interface Parcelable -//actual annotation class IgnoredOnParcel -actual annotation class Parcelize -actual interface Parceler

{ - actual fun create(parcel: Parcel): P - actual fun P.write(parcel: Parcel, flags: Int) -} - -actual annotation class TypeParceler> - -actual class Parcel { - actual fun readString(): String? = null - actual fun readByte(): Byte = 1 - - actual fun readInt(): Int = 1 - - actual fun readFloat(): Float = 1f - - actual fun readDouble(): Double = 1.0 - - actual fun writeByte(value: Byte) { - } - - actual fun writeInt(value: Int) { - } - - actual fun writeFloat(value: Float) { - } - - actual fun writeDouble(value: Double) { - } - - actual fun writeString(value: String?) { - } -} diff --git a/core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt b/core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt deleted file mode 100644 index 505c69125c0..00000000000 --- a/core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -//actual interface Parcelable -//actual annotation class IgnoredOnParcel -actual annotation class Parcelize -actual interface Parceler

{ - actual fun create(parcel: Parcel): P - actual fun P.write(parcel: Parcel, flags: Int) -} - -actual annotation class TypeParceler> - -actual class Parcel { - actual fun readString(): String? = null - actual fun readByte(): Byte = 1 - - actual fun readInt(): Int = 1 - - actual fun readFloat(): Float = 1f - - actual fun readDouble(): Double = 1.0 - - actual fun writeByte(value: Byte) { - } - - actual fun writeInt(value: Int) { - } - - actual fun writeFloat(value: Float) { - } - - actual fun writeDouble(value: Double) { - } - - actual fun writeString(value: String?) { - } -} diff --git a/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt b/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt index 1a8e8b1d746..ca77c5a931f 100644 --- a/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt +++ b/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt @@ -9,89 +9,89 @@ */ package com.mifos.core.datastore -import android.content.Context -import android.content.SharedPreferences -import android.preference.PreferenceManager -import com.mifos.core.common.BuildConfig -import com.mifos.core.common.model.user.User -import com.mifos.core.common.utils.Constants -import com.mifos.core.common.utils.asServerConfig -import com.mifos.core.model.ServerConfig -import dagger.hilt.android.qualifiers.ApplicationContext -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flow -import org.mifos.core.sharedpreference.Key -import org.mifos.core.sharedpreference.UserPreferences -import org.openapitools.client.models.PostAuthenticationResponse -import javax.inject.Inject - -/** - * Created by Aditya Gupta on 19/08/23. - */ -const val USER_DETAILS = "user_details" -const val AUTH_USERNAME = "auth_username" -const val AUTH_PASSWORD = "auth_password" - -class PrefManager @Inject constructor( - @ApplicationContext context: Context, -) : UserPreferences() { - - private val serverConfigKey = Key.Custom("SERVER_CONFIG_KEY") - - override val preference: SharedPreferences = - PreferenceManager.getDefaultSharedPreferences(context) - - override fun getUser(): User { - return gson.fromJson(preference.getString(USER_DETAILS, ""), User::class.java) - } - - override fun saveUser(user: User) { - preference.edit().putString(USER_DETAILS, gson.toJson(user)).apply() - } - - // Created this to store userDetails - fun savePostAuthenticationResponse(user: PostAuthenticationResponse) { - preference.edit().putString(USER_DETAILS, gson.toJson(user)).apply() - } - - fun setPermissionDeniedStatus(permissionDeniedStatus: String, status: Boolean) { - preference.edit().putBoolean(permissionDeniedStatus, status).apply() - } - - fun getPermissionDeniedStatus(permissionDeniedStatus: String): Boolean { - return preference.getBoolean(permissionDeniedStatus, true) - } - - var userStatus: Boolean - get() = preference.getBoolean(Constants.SERVICE_STATUS, false) - set(status) { - preference.edit().putBoolean(Constants.SERVICE_STATUS, status).apply() - } - - var usernamePassword: Pair - get() = Pair( - preference.getString(AUTH_USERNAME, "")!!, - preference.getString(AUTH_PASSWORD, "")!!, - ) - set(value) { - preference.edit().putString(AUTH_USERNAME, value.first).apply() - preference.edit().putString(AUTH_PASSWORD, value.second).apply() - } - - val getServerConfig: ServerConfig = - preference.getString(serverConfigKey.value, null)?.let { - gson.fromJson(it, ServerConfig::class.java) - } ?: BuildConfig.DEMO_SERVER_CONFIG.asServerConfig() - - fun updateServerConfig(config: ServerConfig?) { - this.put(serverConfigKey, config) - } - - fun getStringValue(key: String): Flow = flow { - emit(preference.getString(key, "")) - } - - fun setStringValue(key: String, value: String) { - preference.edit().putString(key, value).apply() - } -} +//import android.content.Context +//import android.content.SharedPreferences +//import android.preference.PreferenceManager +//import com.mifos.core.common.BuildConfig +//import com.mifos.core.common.model.user.User +//import com.mifos.core.common.utils.Constants +//import com.mifos.core.common.utils.asServerConfig +//import com.mifos.core.model.ServerConfig +//import dagger.hilt.android.qualifiers.ApplicationContext +//import kotlinx.coroutines.flow.Flow +//import kotlinx.coroutines.flow.flow +//import org.mifos.core.sharedpreference.Key +//import org.mifos.core.sharedpreference.UserPreferences +//import org.openapitools.client.models.PostAuthenticationResponse +//import javax.inject.Inject +// +///** +// * Created by Aditya Gupta on 19/08/23. +// */ +//const val USER_DETAILS = "user_details" +//const val AUTH_USERNAME = "auth_username" +//const val AUTH_PASSWORD = "auth_password" +// +//class PrefManager @Inject constructor( +// @ApplicationContext context: Context, +//) : UserPreferences() { +// +// private val serverConfigKey = Key.Custom("SERVER_CONFIG_KEY") +// +// override val preference: SharedPreferences = +// PreferenceManager.getDefaultSharedPreferences(context) +// +// override fun getUser(): User { +// return gson.fromJson(preference.getString(USER_DETAILS, ""), User::class.java) +// } +// +// override fun saveUser(user: User) { +// preference.edit().putString(USER_DETAILS, gson.toJson(user)).apply() +// } +// +// // Created this to store userDetails +// fun savePostAuthenticationResponse(user: PostAuthenticationResponse) { +// preference.edit().putString(USER_DETAILS, gson.toJson(user)).apply() +// } +// +// fun setPermissionDeniedStatus(permissionDeniedStatus: String, status: Boolean) { +// preference.edit().putBoolean(permissionDeniedStatus, status).apply() +// } +// +// fun getPermissionDeniedStatus(permissionDeniedStatus: String): Boolean { +// return preference.getBoolean(permissionDeniedStatus, true) +// } +// +// var userStatus: Boolean +// get() = preference.getBoolean(Constants.SERVICE_STATUS, false) +// set(status) { +// preference.edit().putBoolean(Constants.SERVICE_STATUS, status).apply() +// } +// +// var usernamePassword: Pair +// get() = Pair( +// preference.getString(AUTH_USERNAME, "")!!, +// preference.getString(AUTH_PASSWORD, "")!!, +// ) +// set(value) { +// preference.edit().putString(AUTH_USERNAME, value.first).apply() +// preference.edit().putString(AUTH_PASSWORD, value.second).apply() +// } +// +// val getServerConfig: ServerConfig = +// preference.getString(serverConfigKey.value, null)?.let { +// gson.fromJson(it, ServerConfig::class.java) +// } ?: BuildConfig.DEMO_SERVER_CONFIG.asServerConfig() +// +// fun updateServerConfig(config: ServerConfig?) { +// this.put(serverConfigKey, config) +// } +// +// fun getStringValue(key: String): Flow = flow { +// emit(preference.getString(key, "")) +// } +// +// fun setStringValue(key: String, value: String) { +// preference.edit().putString(key, value).apply() +// } +//} diff --git a/core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt b/core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt deleted file mode 100644 index 51d01bd51df..00000000000 --- a/core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt +++ /dev/null @@ -1,47 +0,0 @@ -package org.mifos.core.datastore - -actual interface Parceler

{ - actual fun create(parcel: Parcel): P - actual fun P.write(parcel: Parcel, flags: Int) - -} - -actual annotation class TypeParceler> actual constructor() -actual annotation class Parcelize actual constructor() -actual class Parcel { - actual fun readByte(): Byte { - TODO("Not yet implemented") - } - - actual fun readInt(): Int { - TODO("Not yet implemented") - } - - actual fun readFloat(): Float { - TODO("Not yet implemented") - } - - actual fun readDouble(): Double { - TODO("Not yet implemented") - } - - actual fun readString(): String? { - TODO("Not yet implemented") - } - - actual fun writeByte(value: Byte) { - } - - actual fun writeInt(value: Int) { - } - - actual fun writeFloat(value: Float) { - } - - actual fun writeDouble(value: Double) { - } - - actual fun writeString(value: String?) { - } - -} \ No newline at end of file diff --git a/core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt b/core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt deleted file mode 100644 index 505c69125c0..00000000000 --- a/core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -//actual interface Parcelable -//actual annotation class IgnoredOnParcel -actual annotation class Parcelize -actual interface Parceler

{ - actual fun create(parcel: Parcel): P - actual fun P.write(parcel: Parcel, flags: Int) -} - -actual annotation class TypeParceler> - -actual class Parcel { - actual fun readString(): String? = null - actual fun readByte(): Byte = 1 - - actual fun readInt(): Int = 1 - - actual fun readFloat(): Float = 1f - - actual fun readDouble(): Double = 1.0 - - actual fun writeByte(value: Byte) { - } - - actual fun writeInt(value: Int) { - } - - actual fun writeFloat(value: Float) { - } - - actual fun writeDouble(value: Double) { - } - - actual fun writeString(value: String?) { - } -} diff --git a/core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt b/core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt deleted file mode 100644 index 505c69125c0..00000000000 --- a/core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -//actual interface Parcelable -//actual annotation class IgnoredOnParcel -actual annotation class Parcelize -actual interface Parceler

{ - actual fun create(parcel: Parcel): P - actual fun P.write(parcel: Parcel, flags: Int) -} - -actual annotation class TypeParceler> - -actual class Parcel { - actual fun readString(): String? = null - actual fun readByte(): Byte = 1 - - actual fun readInt(): Int = 1 - - actual fun readFloat(): Float = 1f - - actual fun readDouble(): Double = 1.0 - - actual fun writeByte(value: Byte) { - } - - actual fun writeInt(value: Int) { - } - - actual fun writeFloat(value: Float) { - } - - actual fun writeDouble(value: Double) { - } - - actual fun writeString(value: String?) { - } -} From 8d092611db4ff7cf57ba2148d37bbfc59836f214 Mon Sep 17 00:00:00 2001 From: kapmaurya Date: Mon, 20 Jan 2025 20:54:53 +0530 Subject: [PATCH 04/13] datastore-migration-kmpl --- .../MifosDispatchers.kt | 26 +++ .../org.mifos.core.datastore/Parcelize.kt | 39 ++++ .../PreferencesMapper.kt | 107 +++++++++++ .../org.mifos.core.datastore/RoleInfo.kt | 20 ++ .../org.mifos.core.datastore/UserInfo.kt | 27 +++ .../UserPreferencesDataSource.kt | 174 ++++++++++++++++++ .../UserPreferencesRepository.kt | 46 +++++ .../UserPreferencesRepositoryImpl.kt | 127 +++++++++++++ .../di/PreferenceModule.kt | 33 ++++ .../org.mifos.core.datastore/model/Client.kt | 35 ++++ .../model/ClientPreferences.kt | 51 +++++ .../model/DefaultAccount.kt | 27 +++ .../model/RolePreferences.kt | 29 +++ .../model/UpdatedClient.kt | 22 +++ .../model/UserInfoPreferences.kt | 43 +++++ 15 files changed, 806 insertions(+) create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt new file mode 100644 index 00000000000..65c5fa6872d --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +import org.koin.core.annotation.Qualifier + +@Qualifier +@Retention(AnnotationRetention.RUNTIME) +annotation class Dispatcher(val mifosDispatcher: MifosDispatchers) + +enum class MifosDispatchers { + Default, + IO, + Unconfined, +} + +@Qualifier +@Retention(AnnotationRetention.RUNTIME) +annotation class ApplicationScope diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt new file mode 100644 index 00000000000..a5c53c24d83 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +expect annotation class Parcelize() + +//expect annotation class IgnoredOnParcel() + +expect interface Parceler

{ + fun create(parcel: Parcel): P + + fun P.write(parcel: Parcel, flags: Int) +} + +expect annotation class TypeParceler>() + +expect class Parcel { + fun readByte(): Byte + fun readInt(): Int + + fun readFloat(): Float + fun readDouble(): Double + fun readString(): String? + + fun writeByte(value: Byte) + fun writeInt(value: Int) + + fun writeFloat(value: Float) + + fun writeDouble(value: Double) + fun writeString(value: String?) +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt new file mode 100644 index 00000000000..775e03a7e31 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt @@ -0,0 +1,107 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +import org.mifos.core.datastore.model.ClientPreferences +import org.mifos.core.datastore.model.RolePreferences +import org.mifos.core.datastore.model.UserInfoPreferences +import org.mifos.core.model.client.Client +import org.mifos.core.model.user.RoleInfo +import org.mifos.core.model.user.UserInfo + +fun ClientPreferences.toClientInfo(): Client { + return Client( + id = id, + accountNo = accountNo, + externalId = externalId, + active = active, + activationDate = activationDate, + firstname = firstname, + lastname = lastname, + displayName = displayName, + mobileNo = mobileNo, + emailAddress = emailAddress, + dateOfBirth = dateOfBirth, + isStaff = isStaff, + officeId = officeId, + officeName = officeName, + savingsProductName = savingsProductName, + ) +} + +fun Client.toClientPreferences(): ClientPreferences { + return ClientPreferences( + id = id, + accountNo = accountNo, + externalId = externalId, + active = active, + activationDate = activationDate, + firstname = firstname, + lastname = lastname, + displayName = displayName, + mobileNo = mobileNo, + emailAddress = emailAddress, + dateOfBirth = dateOfBirth, + isStaff = isStaff, + officeId = officeId, + officeName = officeName, + savingsProductName = savingsProductName, + ) +} + +fun RolePreferences.toRoleInfo(): RoleInfo { + return RoleInfo( + id = id, + name = name, + description = description, + disabled = disabled, + ) +} + +fun RoleInfo.toRolePreferences(): RolePreferences { + return RolePreferences( + id = id, + name = name, + description = description, + disabled = disabled, + ) +} + +fun UserInfoPreferences.toUserInfo(): UserInfo { + return UserInfo( + username = username, + userId = userId, + base64EncodedAuthenticationKey = base64EncodedAuthenticationKey, + authenticated = authenticated, + officeId = officeId, + officeName = officeName, + roles = roles.map { it.toRoleInfo() }, + permissions = permissions, + clients = clients, + shouldRenewPassword = shouldRenewPassword, + isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired, + ) +} + +fun UserInfo.toUserInfoPreferences(): UserInfoPreferences { + return UserInfoPreferences( + username = username, + userId = userId, + base64EncodedAuthenticationKey = base64EncodedAuthenticationKey, + authenticated = authenticated, + officeId = officeId, + officeName = officeName, + roles = roles.map { it.toRolePreferences() }, + permissions = permissions, + clients = clients, + shouldRenewPassword = shouldRenewPassword, + isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired, + ) +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt new file mode 100644 index 00000000000..89e9025cef6 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt @@ -0,0 +1,20 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + + + +@Parcelize +data class RoleInfo( + val id: String, + val name: String, + val description: String, + val disabled: Boolean, +) : Parcelable diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt new file mode 100644 index 00000000000..7a03a94a1c7 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + + + +@Parcelize +data class UserInfo( + val username: String, + val userId: Long, + val base64EncodedAuthenticationKey: String, + val authenticated: Boolean, + val officeId: Int, + val officeName: String, + val roles: List, + val permissions: List, + val clients: List, + val shouldRenewPassword: Boolean, + val isTwoFactorAuthenticationRequired: Boolean, +) : Parcelable diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt new file mode 100644 index 00000000000..cf107862b08 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt @@ -0,0 +1,174 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +@file:OptIn(ExperimentalSerializationApi::class, ExperimentalSettingsApi::class) + +package org.mifos.core.datastore + +import com.russhwolf.settings.ExperimentalSettingsApi +import com.russhwolf.settings.Settings +import com.russhwolf.settings.serialization.decodeValue +import com.russhwolf.settings.serialization.decodeValueOrNull +import com.russhwolf.settings.serialization.encodeValue +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.withContext +import kotlinx.serialization.ExperimentalSerializationApi +import org.mifos.core.datastore.UserPreferencesDataSource.Companion.DEFAULT_ACCOUNT +import org.mifos.core.datastore.model.ClientPreferences +import org.mifos.core.datastore.model.UserInfoPreferences +//import org.mifos.core.datastore.model.Client +//import org.mifos.core.datastore.model.UpdatedClient +import org.mifos.core.model.user.UserInfo + +private const val USER_INFO_KEY = "userInfo" +private const val CLIENT_INFO_KEY = "clientInfo" + +@OptIn(ExperimentalSerializationApi::class) +class UserPreferencesDataSource( + private val settings: Settings, + private val dispatcher: CoroutineDispatcher, +) { + private val _userInfo = MutableStateFlow( + settings.decodeValue( + key = USER_INFO_KEY, + serializer = UserInfoPreferences.serializer(), + defaultValue = settings.decodeValueOrNull( + key = USER_INFO_KEY, + serializer = UserInfoPreferences.serializer(), + ) ?: UserInfoPreferences.DEFAULT, + ), + ) + + private val _clientInfo = MutableStateFlow( + settings.decodeValue( + key = CLIENT_INFO_KEY, + serializer = ClientPreferences.serializer(), + defaultValue = settings.decodeValueOrNull( + key = CLIENT_INFO_KEY, + serializer = ClientPreferences.serializer(), + ) ?: ClientPreferences.DEFAULT, + ), + ) + + private val _defaultAccount = MutableStateFlow( + settings.decodeValue( + key = DEFAULT_ACCOUNT, + serializer = DefaultAccount.serializer(), + defaultValue = settings.decodeValueOrNull( + key = DEFAULT_ACCOUNT, + serializer = DefaultAccount.serializer(), + ) ?: DefaultAccount.DEFAULT, + ), + ) + + val token = _userInfo.map { + it.base64EncodedAuthenticationKey + } + val userInfo = _userInfo.map(UserInfoPreferences::toUserInfo) + + val clientInfo = _clientInfo.map(ClientPreferences::toClientInfo) + + val clientId = _clientInfo.map { it.id } + + val defaultAccount = _defaultAccount.map { it.takeIf { it.accountId != 0L } } + + suspend fun updateClientInfo(client: Client) { + withContext(dispatcher) { + settings.putClientPreference(client.toClientPreferences()) + _clientInfo.value = client.toClientPreferences() + } + } + + suspend fun updateUserInfo(userInfo: UserInfo) { + withContext(dispatcher) { + settings.putUserInfoPreference(userInfo.toUserInfoPreferences()) + _userInfo.value = userInfo.toUserInfoPreferences() + } + } + + suspend fun updateClientProfile(client: UpdatedClient) { + withContext(dispatcher) { + val updatedClient = _clientInfo.value.copy( + firstname = client.firstname, + lastname = client.lastname, + displayName = client.firstname + " " + client.lastname, + emailAddress = client.emailAddress, + mobileNo = client.mobileNo, + externalId = client.externalId, + ) + + settings.putClientPreference(updatedClient) + _clientInfo.value = updatedClient + } + } + + suspend fun updateToken(token: String) { + withContext(dispatcher) { + settings.putUserInfoPreference( + UserInfoPreferences.DEFAULT.copy( + base64EncodedAuthenticationKey = token, + ), + ) + _userInfo.value = UserInfoPreferences.DEFAULT.copy( + base64EncodedAuthenticationKey = token, + ) + } + } + + fun updateDefaultAccount(account: DefaultAccount) { + settings.putDefaultAccount(account) + + _defaultAccount.value = account + } + + fun updateAuthToken(token: String) { + settings.putString(AUTH_TOKEN, token) + } + + fun getAuthToken(): String? { + return settings.getString(AUTH_TOKEN, "").ifEmpty { null } + } + + suspend fun clearInfo() { + withContext(dispatcher) { + settings.clear() + } + } + + companion object { + const val AUTH_TOKEN = "authToken" + const val DEFAULT_ACCOUNT = "default_account" + } +} + +private fun Settings.putClientPreference(preference: ClientPreferences) { + encodeValue( + key = CLIENT_INFO_KEY, + serializer = ClientPreferences.serializer(), + value = preference, + ) +} + +private fun Settings.putUserInfoPreference(preference: UserInfoPreferences) { + encodeValue( + key = USER_INFO_KEY, + serializer = UserInfoPreferences.serializer(), + value = preference, + ) +} + +private fun Settings.putDefaultAccount(account: DefaultAccount) { + encodeValue( + key = DEFAULT_ACCOUNT, + serializer = DefaultAccount.serializer(), + value = account, + ) +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt new file mode 100644 index 00000000000..ad807598375 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.datastore + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.StateFlow +import org.mifospay.core.common.DataState +import org.mifospay.core.model.account.DefaultAccount +import org.mifospay.core.model.client.Client +import org.mifospay.core.model.client.UpdatedClient +import org.mifospay.core.model.user.UserInfo + +interface UserPreferencesRepository { + val userInfo: Flow + + val token: StateFlow + + val client: StateFlow + + val clientId: StateFlow + + val authToken: String? + + val defaultAccount: StateFlow + + val defaultAccountId: StateFlow + + suspend fun updateToken(token: String): DataState + + suspend fun updateUserInfo(user: UserInfo): DataState + + suspend fun updateClientInfo(client: Client): DataState + + suspend fun updateClientProfile(client: UpdatedClient): DataState + + suspend fun updateDefaultAccount(account: DefaultAccount): DataState + + suspend fun logOut(): Unit +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt new file mode 100644 index 00000000000..c0647b171ef --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt @@ -0,0 +1,127 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.datastore + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn +import org.mifospay.core.common.DataState +import org.mifospay.core.model.account.DefaultAccount +import org.mifospay.core.model.client.Client +import org.mifospay.core.model.client.UpdatedClient +import org.mifospay.core.model.user.UserInfo + +class UserPreferencesRepositoryImpl( + private val preferenceManager: UserPreferencesDataSource, + private val ioDispatcher: CoroutineDispatcher, + unconfinedDispatcher: CoroutineDispatcher, +) : UserPreferencesRepository { + private val unconfinedScope = CoroutineScope(unconfinedDispatcher) + + override val userInfo: Flow + get() = preferenceManager.userInfo.flowOn(ioDispatcher) + + override val token: StateFlow + get() = preferenceManager.token.stateIn( + scope = unconfinedScope, + initialValue = null, + started = SharingStarted.Eagerly, + ) + + override val client: StateFlow + get() = preferenceManager.clientInfo.stateIn( + scope = unconfinedScope, + initialValue = null, + started = SharingStarted.Eagerly, + ) + + override val clientId: StateFlow + get() = preferenceManager.clientId.stateIn( + scope = unconfinedScope, + initialValue = null, + started = SharingStarted.Eagerly, + ) + + override val authToken: String? + get() = preferenceManager.getAuthToken() + + override val defaultAccount: StateFlow + get() = preferenceManager.defaultAccount.stateIn( + scope = unconfinedScope, + initialValue = null, + started = SharingStarted.Eagerly, + ) + + override val defaultAccountId: StateFlow + get() = preferenceManager.defaultAccount + .map { it?.accountId }.stateIn( + scope = unconfinedScope, + initialValue = null, + started = SharingStarted.Eagerly, + ) + + override suspend fun updateDefaultAccount(account: DefaultAccount): DataState { + return try { + val result = preferenceManager.updateDefaultAccount(account) + + DataState.Success(result) + } catch (e: Exception) { + DataState.Error(e) + } + } + + override suspend fun updateToken(token: String): DataState { + return try { + val result = preferenceManager.updateAuthToken(token) + + DataState.Success(result) + } catch (e: Exception) { + DataState.Error(e) + } + } + + override suspend fun updateClientInfo(client: Client): DataState { + return try { + val result = preferenceManager.updateClientInfo(client) + + DataState.Success(result) + } catch (e: Exception) { + DataState.Error(e) + } + } + + override suspend fun updateClientProfile(client: UpdatedClient): DataState { + return try { + val result = preferenceManager.updateClientProfile(client) + DataState.Success(result) + } catch (e: Exception) { + DataState.Error(e) + } + } + + override suspend fun updateUserInfo(user: UserInfo): DataState { + return try { + val result = preferenceManager.updateUserInfo(user) + + DataState.Success(result) + } catch (e: Exception) { + DataState.Error(e) + } + } + + override suspend fun logOut() { + preferenceManager.clearInfo() + } +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt new file mode 100644 index 00000000000..3e05a9f553a --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore.di + +import com.russhwolf.settings.Settings +import org.koin.core.qualifier.named +import org.koin.dsl.module +import org.mifos.core.datastore.MifosDispatchers +import org.mifos.core.datastore.UserPreferencesDataSource +import org.mifospay.core.datastore.UserPreferencesRepository +import org.mifospay.core.datastore.UserPreferencesRepositoryImpl + + +val PreferencesModule = module { + factory { Settings() } + // Use the IO dispatcher name - MifosDispatchers.IO.name + factory { UserPreferencesDataSource(get(), get(named(MifosDispatchers.IO.name))) } + + single { + UserPreferencesRepositoryImpl( + preferenceManager = get(), + ioDispatcher = get(named(MifosDispatchers.IO.name)), + unconfinedDispatcher = get(named(MifosDispatchers.Unconfined.name)), + ) + } +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt new file mode 100644 index 00000000000..5d1a3acf747 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +import org.mifos.core.datastore.Parcelable +import org.mifos.core.datastore.Parcelize + +@Parcelize +data class Client( + val id: Long, + val accountNo: String, + val externalId: String, + val active: Boolean, + val activationDate: List, + val firstname: String, + val lastname: String, + val displayName: String, + val mobileNo: String, + val emailAddress: String, + val dateOfBirth: List, + val isStaff: Boolean, + val officeId: Long, + val officeName: String, + val savingsProductName: String, + val timeline: ClientTimeline = ClientTimeline(), + val status: ClientStatus = ClientStatus(), + val legalForm: ClientStatus = ClientStatus(), +) : Parcelable diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt new file mode 100644 index 00000000000..56f05ed22a1 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt @@ -0,0 +1,51 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore.model + +import kotlinx.serialization.Serializable + +@Serializable +data class ClientPreferences( + val id: Long, + val accountNo: String, + val externalId: String, + val active: Boolean, + val activationDate: List, + val firstname: String, + val lastname: String, + val displayName: String, + val mobileNo: String, + val emailAddress: String, + val dateOfBirth: List, + val isStaff: Boolean, + val officeId: Long, + val officeName: String, + val savingsProductName: String, +) { + companion object { + val DEFAULT = ClientPreferences( + id = 0L, + accountNo = "", + externalId = "", + active = false, + activationDate = emptyList(), + firstname = "", + lastname = "", + displayName = "", + mobileNo = "", + emailAddress = "", + dateOfBirth = emptyList(), + isStaff = false, + officeId = 0, + officeName = "", + savingsProductName = "", + ) + } +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt new file mode 100644 index 00000000000..cc535a86b24 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt @@ -0,0 +1,27 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +import kotlinx.serialization.Serializable +import org.mifos.core.datastore.Parcelize + +@Serializable +@Parcelize +data class DefaultAccount( + val accountId: Long, + val accountNo: String, +) : Parcelable { + companion object { + val DEFAULT = DefaultAccount( + accountId = 0, + accountNo = "", + ) + } +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt new file mode 100644 index 00000000000..89c9ef1c03b --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore.model + +import kotlinx.serialization.Serializable + +@Serializable +data class RolePreferences( + val id: String, + val name: String, + val description: String, + val disabled: Boolean, +) { + companion object { + val DEFAULT = RolePreferences( + id = "", + name = "", + description = "", + disabled = false, + ) + } +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt new file mode 100644 index 00000000000..4f24a3231ed --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +import org.mifospay.core.datastore.Parcelable +import org.mifospay.core.datastore.Parcelize + +@Parcelize +data class UpdatedClient( + val firstname: String, + val lastname: String, + val externalId: String, + val mobileNo: String, + val emailAddress: String, +) : Parcelable diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt new file mode 100644 index 00000000000..ffd80ad9971 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore.model + +import kotlinx.serialization.Serializable + +@Serializable +data class UserInfoPreferences( + val username: String, + val userId: Long, + val base64EncodedAuthenticationKey: String, + val authenticated: Boolean, + val officeId: Int, + val officeName: String, + val roles: List, + val permissions: List, + val clients: List, + val shouldRenewPassword: Boolean, + val isTwoFactorAuthenticationRequired: Boolean, +) { + companion object { + val DEFAULT = UserInfoPreferences( + username = "", + userId = 0, + base64EncodedAuthenticationKey = "", + authenticated = false, + officeId = 0, + officeName = "", + roles = emptyList(), + permissions = emptyList(), + clients = emptyList(), + shouldRenewPassword = false, + isTwoFactorAuthenticationRequired = false, + ) + } +} From 8d330e5352706901508fa6753bbbf49735ce6000 Mon Sep 17 00:00:00 2001 From: kapmaurya Date: Tue, 21 Jan 2025 23:20:43 +0530 Subject: [PATCH 05/13] commit message --- .../com.mifos.room.db.MifosDatabase/1.json | 45 ++++++++++++++++++ core/datastore/build.gradle.kts | 34 +++++++------- .../org.mifos.core.datastore/DataState.kt | 39 +++++++++++++++ .../PreferencesMapper.kt | 5 +- .../org.mifos.core.datastore/RoleInfo.kt | 2 +- .../org.mifos.core.datastore/UserInfo.kt | 2 +- .../UserPreferencesDataSource.kt | 4 +- .../UserPreferencesRepository.kt | 12 ++--- .../UserPreferencesRepositoryImpl.kt | 12 ++--- .../di/PreferenceModule.kt | 4 +- .../org.mifos.core.datastore/model/Client.kt | 10 ++-- .../model/DefaultAccount.kt | 10 +--- .../model/UpdatedClient.kt | 5 +- .../Parcelize.desktop.kt | 46 ++++++++++++++++++ .../org.mifos.core.datastore/Parcelize.js.kt | 46 ++++++++++++++++++ .../Parcelize.android.kt | 47 +++++++++++++++++++ .../Parcelize.native.kt | 46 ++++++++++++++++++ .../Parcelize.wasmJs.kt | 46 ++++++++++++++++++ gradle/libs.versions.toml | 2 +- 19 files changed, 359 insertions(+), 58 deletions(-) create mode 100644 core/database/schemas/com.mifos.room.db.MifosDatabase/1.json create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt create mode 100644 core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt create mode 100644 core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt create mode 100644 core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt create mode 100644 core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt create mode 100644 core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt diff --git a/core/database/schemas/com.mifos.room.db.MifosDatabase/1.json b/core/database/schemas/com.mifos.room.db.MifosDatabase/1.json new file mode 100644 index 00000000000..0e84f2baf5e --- /dev/null +++ b/core/database/schemas/com.mifos.room.db.MifosDatabase/1.json @@ -0,0 +1,45 @@ +{ + "formatVersion": 1, + "database": { + "version": 1, + "identityHash": "52a9a8b64b78975c74e557a9c0411c25", + "entities": [ + { + "tableName": "ColumnValue", + "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER, `value` TEXT, `score` INTEGER, `registeredTableName` TEXT, PRIMARY KEY(`id`))", + "fields": [ + { + "fieldPath": "id", + "columnName": "id", + "affinity": "INTEGER" + }, + { + "fieldPath": "value", + "columnName": "value", + "affinity": "TEXT" + }, + { + "fieldPath": "score", + "columnName": "score", + "affinity": "INTEGER" + }, + { + "fieldPath": "registeredTableName", + "columnName": "registeredTableName", + "affinity": "TEXT" + } + ], + "primaryKey": { + "autoGenerate": false, + "columnNames": [ + "id" + ] + } + } + ], + "setupQueries": [ + "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", + "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '52a9a8b64b78975c74e557a9c0411c25')" + ] + } +} \ No newline at end of file diff --git a/core/datastore/build.gradle.kts b/core/datastore/build.gradle.kts index f7bd49852b0..9938055e088 100644 --- a/core/datastore/build.gradle.kts +++ b/core/datastore/build.gradle.kts @@ -8,9 +8,9 @@ * See https://github.com/openMF/android-client/blob/master/LICENSE.md */ plugins { - alias(libs.plugins.mifos.android.library) - alias(libs.plugins.mifos.android.library.jacoco) - alias(libs.plugins.mifos.android.hilt) + alias(libs.plugins.mifos.kmp.library) + id(libs.plugins.kotlin.parcelize.get().pluginId) + id("kotlinx-serialization") } android { @@ -19,22 +19,20 @@ android { defaultConfig { consumerProguardFiles("consumer-proguard-rules.pro") } - testOptions { - unitTests { - isReturnDefaultValues = true - } - } + } dependencies { - api(projects.core.model) - api(projects.core.common) - - api(libs.converter.gson) - - // fineract sdk dependencies - api(libs.mifos.android.sdk.arch) - - // sdk client - api(libs.fineract.client) + kotlin { + sourceSets { + commonMain.dependencies { + implementation(libs.multiplatform.settings) + implementation(libs.multiplatform.settings.serialization) + implementation(libs.multiplatform.settings.coroutines) + implementation(libs.kotlinx.coroutines.core) + implementation(libs.kotlinx.serialization.core) + // implementation(projects.core.common) + } + } + } } \ No newline at end of file diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt new file mode 100644 index 00000000000..048e2487cf5 --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.onStart + +sealed class DataState { + abstract val data: T? + + data object Loading : DataState() { + override val data: Nothing? get() = null + } + + data class Success( + override val data: T, + ) : DataState() + + data class Error( + val exception: Throwable, + override val data: T? = null, + ) : DataState() { + val message = exception.message.toString() + } +} + +fun Flow.asDataStateFlow(): Flow> = + map> { DataState.Success(it) } + .onStart { emit(DataState.Loading) } + .catch { emit(DataState.Error(it, null)) } diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt index 775e03a7e31..9599cf7a610 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt @@ -12,9 +12,8 @@ package org.mifos.core.datastore import org.mifos.core.datastore.model.ClientPreferences import org.mifos.core.datastore.model.RolePreferences import org.mifos.core.datastore.model.UserInfoPreferences -import org.mifos.core.model.client.Client -import org.mifos.core.model.user.RoleInfo -import org.mifos.core.model.user.UserInfo + + fun ClientPreferences.toClientInfo(): Client { return Client( diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt index 89e9025cef6..0c7b2c1ef6b 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt @@ -17,4 +17,4 @@ data class RoleInfo( val name: String, val description: String, val disabled: Boolean, -) : Parcelable +) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt index 7a03a94a1c7..1056b52673f 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt @@ -24,4 +24,4 @@ data class UserInfo( val clients: List, val shouldRenewPassword: Boolean, val isTwoFactorAuthenticationRequired: Boolean, -) : Parcelable +) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt index cf107862b08..68d58ef0d17 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt @@ -24,9 +24,9 @@ import kotlinx.serialization.ExperimentalSerializationApi import org.mifos.core.datastore.UserPreferencesDataSource.Companion.DEFAULT_ACCOUNT import org.mifos.core.datastore.model.ClientPreferences import org.mifos.core.datastore.model.UserInfoPreferences -//import org.mifos.core.datastore.model.Client +import org.mifos.core.datastore.Client //import org.mifos.core.datastore.model.UpdatedClient -import org.mifos.core.model.user.UserInfo +import org.mifos.core.datastore.UserInfo private const val USER_INFO_KEY = "userInfo" private const val CLIENT_INFO_KEY = "clientInfo" diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt index ad807598375..0ab0b08d342 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt @@ -7,15 +7,15 @@ * * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md */ -package org.mifospay.core.datastore +package org.mifos.core.datastore import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow -import org.mifospay.core.common.DataState -import org.mifospay.core.model.account.DefaultAccount -import org.mifospay.core.model.client.Client -import org.mifospay.core.model.client.UpdatedClient -import org.mifospay.core.model.user.UserInfo +//import org.mifos.core.datastore +//import org.mifospay.core.model.account.DefaultAccount +//import org.mifospay.core.model.client.Client +//import org.mifospay.core.model.client.UpdatedClient +//import org.mifospay.core.model.user.UserInfo interface UserPreferencesRepository { val userInfo: Flow diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt index c0647b171ef..06ed4f79c01 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt @@ -7,7 +7,7 @@ * * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md */ -package org.mifospay.core.datastore +package org.mifos.core.datastore import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope @@ -17,11 +17,11 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn -import org.mifospay.core.common.DataState -import org.mifospay.core.model.account.DefaultAccount -import org.mifospay.core.model.client.Client -import org.mifospay.core.model.client.UpdatedClient -import org.mifospay.core.model.user.UserInfo +//import org.mifospay.core.common.DataState +//import org.mifospay.core.model.account.DefaultAccount +//import org.mifospay.core.model.client.Client +//import org.mifospay.core.model.client.UpdatedClient +//import org.mifospay.core.model.user.UserInfo class UserPreferencesRepositoryImpl( private val preferenceManager: UserPreferencesDataSource, diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt index 3e05a9f553a..cac8fc70f5b 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt @@ -14,8 +14,8 @@ import org.koin.core.qualifier.named import org.koin.dsl.module import org.mifos.core.datastore.MifosDispatchers import org.mifos.core.datastore.UserPreferencesDataSource -import org.mifospay.core.datastore.UserPreferencesRepository -import org.mifospay.core.datastore.UserPreferencesRepositoryImpl +import org.mifos.core.datastore.UserPreferencesRepository +import org.mifos.core.datastore.UserPreferencesRepositoryImpl val PreferencesModule = module { diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt index 5d1a3acf747..fb9364f025b 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt @@ -9,8 +9,7 @@ */ package org.mifos.core.datastore -import org.mifos.core.datastore.Parcelable -import org.mifos.core.datastore.Parcelize + @Parcelize data class Client( @@ -28,8 +27,5 @@ data class Client( val isStaff: Boolean, val officeId: Long, val officeName: String, - val savingsProductName: String, - val timeline: ClientTimeline = ClientTimeline(), - val status: ClientStatus = ClientStatus(), - val legalForm: ClientStatus = ClientStatus(), -) : Parcelable + val savingsProductName: String +) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt index cc535a86b24..7bdaa566652 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt @@ -17,11 +17,5 @@ import org.mifos.core.datastore.Parcelize data class DefaultAccount( val accountId: Long, val accountNo: String, -) : Parcelable { - companion object { - val DEFAULT = DefaultAccount( - accountId = 0, - accountNo = "", - ) - } -} +) + diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt index 4f24a3231ed..7514fc6d300 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt @@ -9,8 +9,7 @@ */ package org.mifos.core.datastore -import org.mifospay.core.datastore.Parcelable -import org.mifospay.core.datastore.Parcelize + @Parcelize data class UpdatedClient( @@ -19,4 +18,4 @@ data class UpdatedClient( val externalId: String, val mobileNo: String, val emailAddress: String, -) : Parcelable +) diff --git a/core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt b/core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt new file mode 100644 index 00000000000..505c69125c0 --- /dev/null +++ b/core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +//actual interface Parcelable +//actual annotation class IgnoredOnParcel +actual annotation class Parcelize +actual interface Parceler

{ + actual fun create(parcel: Parcel): P + actual fun P.write(parcel: Parcel, flags: Int) +} + +actual annotation class TypeParceler> + +actual class Parcel { + actual fun readString(): String? = null + actual fun readByte(): Byte = 1 + + actual fun readInt(): Int = 1 + + actual fun readFloat(): Float = 1f + + actual fun readDouble(): Double = 1.0 + + actual fun writeByte(value: Byte) { + } + + actual fun writeInt(value: Int) { + } + + actual fun writeFloat(value: Float) { + } + + actual fun writeDouble(value: Double) { + } + + actual fun writeString(value: String?) { + } +} diff --git a/core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt b/core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt new file mode 100644 index 00000000000..505c69125c0 --- /dev/null +++ b/core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +//actual interface Parcelable +//actual annotation class IgnoredOnParcel +actual annotation class Parcelize +actual interface Parceler

{ + actual fun create(parcel: Parcel): P + actual fun P.write(parcel: Parcel, flags: Int) +} + +actual annotation class TypeParceler> + +actual class Parcel { + actual fun readString(): String? = null + actual fun readByte(): Byte = 1 + + actual fun readInt(): Int = 1 + + actual fun readFloat(): Float = 1f + + actual fun readDouble(): Double = 1.0 + + actual fun writeByte(value: Byte) { + } + + actual fun writeInt(value: Int) { + } + + actual fun writeFloat(value: Float) { + } + + actual fun writeDouble(value: Double) { + } + + actual fun writeString(value: String?) { + } +} diff --git a/core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt b/core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt new file mode 100644 index 00000000000..51d01bd51df --- /dev/null +++ b/core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt @@ -0,0 +1,47 @@ +package org.mifos.core.datastore + +actual interface Parceler

{ + actual fun create(parcel: Parcel): P + actual fun P.write(parcel: Parcel, flags: Int) + +} + +actual annotation class TypeParceler> actual constructor() +actual annotation class Parcelize actual constructor() +actual class Parcel { + actual fun readByte(): Byte { + TODO("Not yet implemented") + } + + actual fun readInt(): Int { + TODO("Not yet implemented") + } + + actual fun readFloat(): Float { + TODO("Not yet implemented") + } + + actual fun readDouble(): Double { + TODO("Not yet implemented") + } + + actual fun readString(): String? { + TODO("Not yet implemented") + } + + actual fun writeByte(value: Byte) { + } + + actual fun writeInt(value: Int) { + } + + actual fun writeFloat(value: Float) { + } + + actual fun writeDouble(value: Double) { + } + + actual fun writeString(value: String?) { + } + +} \ No newline at end of file diff --git a/core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt b/core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt new file mode 100644 index 00000000000..505c69125c0 --- /dev/null +++ b/core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +//actual interface Parcelable +//actual annotation class IgnoredOnParcel +actual annotation class Parcelize +actual interface Parceler

{ + actual fun create(parcel: Parcel): P + actual fun P.write(parcel: Parcel, flags: Int) +} + +actual annotation class TypeParceler> + +actual class Parcel { + actual fun readString(): String? = null + actual fun readByte(): Byte = 1 + + actual fun readInt(): Int = 1 + + actual fun readFloat(): Float = 1f + + actual fun readDouble(): Double = 1.0 + + actual fun writeByte(value: Byte) { + } + + actual fun writeInt(value: Int) { + } + + actual fun writeFloat(value: Float) { + } + + actual fun writeDouble(value: Double) { + } + + actual fun writeString(value: String?) { + } +} diff --git a/core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt b/core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt new file mode 100644 index 00000000000..505c69125c0 --- /dev/null +++ b/core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifos.core.datastore + +//actual interface Parcelable +//actual annotation class IgnoredOnParcel +actual annotation class Parcelize +actual interface Parceler

{ + actual fun create(parcel: Parcel): P + actual fun P.write(parcel: Parcel, flags: Int) +} + +actual annotation class TypeParceler> + +actual class Parcel { + actual fun readString(): String? = null + actual fun readByte(): Byte = 1 + + actual fun readInt(): Int = 1 + + actual fun readFloat(): Float = 1f + + actual fun readDouble(): Double = 1.0 + + actual fun writeByte(value: Byte) { + } + + actual fun writeInt(value: Int) { + } + + actual fun writeFloat(value: Float) { + } + + actual fun writeDouble(value: Double) { + } + + actual fun writeString(value: String?) { + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 67ab31e3b3b..d32c073d1e9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,7 +7,7 @@ androidDesugarJdkLibs = "2.1.4" androidIconifyMaterial = "2.2.2" androidJob = "1.2.6" androidMapsUtils = "0.4.2" -androidGradlePlugin = "8.8.0" +androidGradlePlugin = "8.7.2" androidTools = "31.8.0" androidxActivity = "1.9.3" androidxAppCompat = "1.7.0" From 8e864ad764ac0ab6661b7f4ce5cbe5922bd16aff Mon Sep 17 00:00:00 2001 From: kapmaurya Date: Thu, 30 Jan 2025 17:39:48 +0530 Subject: [PATCH 06/13] datastore-migration-kmpl --- core/datastore/build.gradle.kts | 2 +- .../org.mifos.core.datastore/DataState.kt | 39 --- .../MifosDispatchers.kt | 26 -- .../org.mifos.core.datastore/Parcelize.kt | 39 --- .../PreferencesMapper.kt | 106 -------- .../org.mifos.core.datastore/RoleInfo.kt | 20 -- .../org.mifos.core.datastore/UserInfo.kt | 27 -- .../UserPreferencesDataSource.kt | 243 +++++++----------- .../UserPreferencesRepository.kt | 33 +-- .../UserPreferencesRepositoryImpl.kt | 106 +------- .../di/PreferenceModule.kt | 7 +- .../org.mifos.core.datastore/model/Client.kt | 31 --- .../model/ClientPreferences.kt | 51 ---- .../model/DefaultAccount.kt | 21 -- .../model/RolePreferences.kt | 29 --- .../model/UpdatedClient.kt | 21 -- .../org.mifos.core.datastore/model/User.kt | 19 ++ .../model/UserInfoPreferences.kt | 43 ---- .../Parcelize.desktop.kt | 46 ---- .../org.mifos.core.datastore/Parcelize.js.kt | 46 ---- .../com/mifos/core/datastore/PrefManager.kt | 172 ++++++------- .../Parcelize.android.kt | 47 ---- .../Parcelize.native.kt | 46 ---- .../Parcelize.wasmJs.kt | 46 ---- 24 files changed, 222 insertions(+), 1044 deletions(-) delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt create mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/User.kt delete mode 100644 core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt delete mode 100644 core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt delete mode 100644 core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt delete mode 100644 core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt delete mode 100644 core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt delete mode 100644 core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt diff --git a/core/datastore/build.gradle.kts b/core/datastore/build.gradle.kts index 9938055e088..8965b1842da 100644 --- a/core/datastore/build.gradle.kts +++ b/core/datastore/build.gradle.kts @@ -9,7 +9,7 @@ */ plugins { alias(libs.plugins.mifos.kmp.library) - id(libs.plugins.kotlin.parcelize.get().pluginId) + //id(libs.plugins.kotlin.parcelize.get().pluginId) id("kotlinx-serialization") } diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt deleted file mode 100644 index 048e2487cf5..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/DataState.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.catch -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.onStart - -sealed class DataState { - abstract val data: T? - - data object Loading : DataState() { - override val data: Nothing? get() = null - } - - data class Success( - override val data: T, - ) : DataState() - - data class Error( - val exception: Throwable, - override val data: T? = null, - ) : DataState() { - val message = exception.message.toString() - } -} - -fun Flow.asDataStateFlow(): Flow> = - map> { DataState.Success(it) } - .onStart { emit(DataState.Loading) } - .catch { emit(DataState.Error(it, null)) } diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt deleted file mode 100644 index 65c5fa6872d..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/MifosDispatchers.kt +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -import org.koin.core.annotation.Qualifier - -@Qualifier -@Retention(AnnotationRetention.RUNTIME) -annotation class Dispatcher(val mifosDispatcher: MifosDispatchers) - -enum class MifosDispatchers { - Default, - IO, - Unconfined, -} - -@Qualifier -@Retention(AnnotationRetention.RUNTIME) -annotation class ApplicationScope diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt deleted file mode 100644 index a5c53c24d83..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/Parcelize.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -expect annotation class Parcelize() - -//expect annotation class IgnoredOnParcel() - -expect interface Parceler

{ - fun create(parcel: Parcel): P - - fun P.write(parcel: Parcel, flags: Int) -} - -expect annotation class TypeParceler>() - -expect class Parcel { - fun readByte(): Byte - fun readInt(): Int - - fun readFloat(): Float - fun readDouble(): Double - fun readString(): String? - - fun writeByte(value: Byte) - fun writeInt(value: Int) - - fun writeFloat(value: Float) - - fun writeDouble(value: Double) - fun writeString(value: String?) -} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt deleted file mode 100644 index 9599cf7a610..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/PreferencesMapper.kt +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -import org.mifos.core.datastore.model.ClientPreferences -import org.mifos.core.datastore.model.RolePreferences -import org.mifos.core.datastore.model.UserInfoPreferences - - - -fun ClientPreferences.toClientInfo(): Client { - return Client( - id = id, - accountNo = accountNo, - externalId = externalId, - active = active, - activationDate = activationDate, - firstname = firstname, - lastname = lastname, - displayName = displayName, - mobileNo = mobileNo, - emailAddress = emailAddress, - dateOfBirth = dateOfBirth, - isStaff = isStaff, - officeId = officeId, - officeName = officeName, - savingsProductName = savingsProductName, - ) -} - -fun Client.toClientPreferences(): ClientPreferences { - return ClientPreferences( - id = id, - accountNo = accountNo, - externalId = externalId, - active = active, - activationDate = activationDate, - firstname = firstname, - lastname = lastname, - displayName = displayName, - mobileNo = mobileNo, - emailAddress = emailAddress, - dateOfBirth = dateOfBirth, - isStaff = isStaff, - officeId = officeId, - officeName = officeName, - savingsProductName = savingsProductName, - ) -} - -fun RolePreferences.toRoleInfo(): RoleInfo { - return RoleInfo( - id = id, - name = name, - description = description, - disabled = disabled, - ) -} - -fun RoleInfo.toRolePreferences(): RolePreferences { - return RolePreferences( - id = id, - name = name, - description = description, - disabled = disabled, - ) -} - -fun UserInfoPreferences.toUserInfo(): UserInfo { - return UserInfo( - username = username, - userId = userId, - base64EncodedAuthenticationKey = base64EncodedAuthenticationKey, - authenticated = authenticated, - officeId = officeId, - officeName = officeName, - roles = roles.map { it.toRoleInfo() }, - permissions = permissions, - clients = clients, - shouldRenewPassword = shouldRenewPassword, - isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired, - ) -} - -fun UserInfo.toUserInfoPreferences(): UserInfoPreferences { - return UserInfoPreferences( - username = username, - userId = userId, - base64EncodedAuthenticationKey = base64EncodedAuthenticationKey, - authenticated = authenticated, - officeId = officeId, - officeName = officeName, - roles = roles.map { it.toRolePreferences() }, - permissions = permissions, - clients = clients, - shouldRenewPassword = shouldRenewPassword, - isTwoFactorAuthenticationRequired = isTwoFactorAuthenticationRequired, - ) -} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt deleted file mode 100644 index 0c7b2c1ef6b..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/RoleInfo.kt +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - - - -@Parcelize -data class RoleInfo( - val id: String, - val name: String, - val description: String, - val disabled: Boolean, -) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt deleted file mode 100644 index 1056b52673f..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserInfo.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - - - -@Parcelize -data class UserInfo( - val username: String, - val userId: Long, - val base64EncodedAuthenticationKey: String, - val authenticated: Boolean, - val officeId: Int, - val officeName: String, - val roles: List, - val permissions: List, - val clients: List, - val shouldRenewPassword: Boolean, - val isTwoFactorAuthenticationRequired: Boolean, -) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt index 68d58ef0d17..653f6e0580c 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt @@ -1,174 +1,127 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -@file:OptIn(ExperimentalSerializationApi::class, ExperimentalSettingsApi::class) - +///* +// * Copyright 2024 Mifos Initiative +// * +// * This Source Code Form is subject to the terms of the Mozilla Public +// * License, v. 2.0. If a copy of the MPL was not distributed with this +// * file, You can obtain one at https://mozilla.org/MPL/2.0/. +// * +// * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md +// */ +//@file:OptIn(ExperimentalSerializationApi::class, ExperimentalSettingsApi::class) +// package org.mifos.core.datastore +// +//import com.russhwolf.settings.ExperimentalSettingsApi +//import com.russhwolf.settings.Settings +//import com.russhwolf.settings.serialization.decodeValue +//import com.russhwolf.settings.serialization.decodeValueOrNull +//import com.russhwolf.settings.serialization.encodeValue +//import kotlinx.coroutines.CoroutineDispatcher +// +//import kotlinx.coroutines.flow.MutableStateFlow +//import kotlinx.coroutines.flow.map +//import kotlinx.coroutines.withContext +//import kotlinx.serialization.ExperimentalSerializationApi +// +// +//private const val USER_INFO_KEY = "userInfo" +// +// +//@OptIn(ExperimentalSerializationApi::class) +//class UserPreferencesDataSource( +// private val settings: Settings, +// private val dispatcher: CoroutineDispatcher, +//) { +// private val _userInfo = MutableStateFlow( +// settings.decodeValue( +// key = USER_INFO_KEY, +// serializer = UserInfoPreferences.serializer(), +// defaultValue = settings.decodeValueOrNull( +// key = USER_INFO_KEY, +// serializer = UserInfoPreferences.serializer(), +// ) ?: UserInfoPreferences.DEFAULT, +// ), +// ) +// +// +// val userInfo = _userInfo.map(UserInfoPreferences::toUserInfo) +// +// suspend fun updateUserInfo(userInfo: UserInfo) { +// withContext(dispatcher) { +// settings.putUserInfoPreference(userInfo.toUserInfoPreferences()) +// _userInfo.value = userInfo.toUserInfoPreferences() +// } +// } +// +// +// +// +// suspend fun clearInfo() { +// withContext(dispatcher) { +// settings.clear() +// } +// } +// +// +//} +// +// +// +//private fun Settings.putUserInfoPreference(preference: UserInfoPreferences) { +// encodeValue( +// key = USER_INFO_KEY, +// serializer = UserInfoPreferences.serializer(), +// value = preference, +// ) +//} +// +// -import com.russhwolf.settings.ExperimentalSettingsApi -import com.russhwolf.settings.Settings import com.russhwolf.settings.serialization.decodeValue import com.russhwolf.settings.serialization.decodeValueOrNull +import kotlinx.coroutines.withContext +import com.russhwolf.settings.ExperimentalSettingsApi +import com.russhwolf.settings.Settings import com.russhwolf.settings.serialization.encodeValue import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.withContext import kotlinx.serialization.ExperimentalSerializationApi -import org.mifos.core.datastore.UserPreferencesDataSource.Companion.DEFAULT_ACCOUNT -import org.mifos.core.datastore.model.ClientPreferences -import org.mifos.core.datastore.model.UserInfoPreferences -import org.mifos.core.datastore.Client -//import org.mifos.core.datastore.model.UpdatedClient -import org.mifos.core.datastore.UserInfo - -private const val USER_INFO_KEY = "userInfo" -private const val CLIENT_INFO_KEY = "clientInfo" +import org.mifos.core.datastore.model.UserData -@OptIn(ExperimentalSerializationApi::class) +private const val USER_DATA = "userData" class UserPreferencesDataSource( private val settings: Settings, private val dispatcher: CoroutineDispatcher, ) { + @OptIn(ExperimentalSerializationApi::class, ExperimentalSettingsApi::class) private val _userInfo = MutableStateFlow( settings.decodeValue( - key = USER_INFO_KEY, - serializer = UserInfoPreferences.serializer(), + key = USER_DATA, + serializer = UserData.serializer(), defaultValue = settings.decodeValueOrNull( - key = USER_INFO_KEY, - serializer = UserInfoPreferences.serializer(), - ) ?: UserInfoPreferences.DEFAULT, + key = USER_DATA, + serializer = UserData.serializer(), + ) ?: UserData.DEFAULT, ), ) - - private val _clientInfo = MutableStateFlow( - settings.decodeValue( - key = CLIENT_INFO_KEY, - serializer = ClientPreferences.serializer(), - defaultValue = settings.decodeValueOrNull( - key = CLIENT_INFO_KEY, - serializer = ClientPreferences.serializer(), - ) ?: ClientPreferences.DEFAULT, - ), - ) - - private val _defaultAccount = MutableStateFlow( - settings.decodeValue( - key = DEFAULT_ACCOUNT, - serializer = DefaultAccount.serializer(), - defaultValue = settings.decodeValueOrNull( - key = DEFAULT_ACCOUNT, - serializer = DefaultAccount.serializer(), - ) ?: DefaultAccount.DEFAULT, - ), - ) - - val token = _userInfo.map { - it.base64EncodedAuthenticationKey - } - val userInfo = _userInfo.map(UserInfoPreferences::toUserInfo) - - val clientInfo = _clientInfo.map(ClientPreferences::toClientInfo) - - val clientId = _clientInfo.map { it.id } - - val defaultAccount = _defaultAccount.map { it.takeIf { it.accountId != 0L } } - - suspend fun updateClientInfo(client: Client) { + val userInfo = _userInfo + suspend fun updateUserInfo(user: UserData) { withContext(dispatcher) { - settings.putClientPreference(client.toClientPreferences()) - _clientInfo.value = client.toClientPreferences() + settings.putUserPreference(user) + _userInfo.value = user } } - - suspend fun updateUserInfo(userInfo: UserInfo) { - withContext(dispatcher) { - settings.putUserInfoPreference(userInfo.toUserInfoPreferences()) - _userInfo.value = userInfo.toUserInfoPreferences() - } - } - - suspend fun updateClientProfile(client: UpdatedClient) { - withContext(dispatcher) { - val updatedClient = _clientInfo.value.copy( - firstname = client.firstname, - lastname = client.lastname, - displayName = client.firstname + " " + client.lastname, - emailAddress = client.emailAddress, - mobileNo = client.mobileNo, - externalId = client.externalId, - ) - - settings.putClientPreference(updatedClient) - _clientInfo.value = updatedClient - } - } - - suspend fun updateToken(token: String) { - withContext(dispatcher) { - settings.putUserInfoPreference( - UserInfoPreferences.DEFAULT.copy( - base64EncodedAuthenticationKey = token, - ), - ) - _userInfo.value = UserInfoPreferences.DEFAULT.copy( - base64EncodedAuthenticationKey = token, - ) - } - } - - fun updateDefaultAccount(account: DefaultAccount) { - settings.putDefaultAccount(account) - - _defaultAccount.value = account - } - - fun updateAuthToken(token: String) { - settings.putString(AUTH_TOKEN, token) - } - - fun getAuthToken(): String? { - return settings.getString(AUTH_TOKEN, "").ifEmpty { null } - } - suspend fun clearInfo() { withContext(dispatcher) { settings.clear() } } - - companion object { - const val AUTH_TOKEN = "authToken" - const val DEFAULT_ACCOUNT = "default_account" - } -} - -private fun Settings.putClientPreference(preference: ClientPreferences) { - encodeValue( - key = CLIENT_INFO_KEY, - serializer = ClientPreferences.serializer(), - value = preference, - ) } - -private fun Settings.putUserInfoPreference(preference: UserInfoPreferences) { +@OptIn(ExperimentalSerializationApi::class, ExperimentalSettingsApi::class) +private fun Settings.putUserPreference(user: UserData) { encodeValue( - key = USER_INFO_KEY, - serializer = UserInfoPreferences.serializer(), - value = preference, + key = USER_DATA, + serializer = UserData.serializer(), + value = user, ) -} - -private fun Settings.putDefaultAccount(account: DefaultAccount) { - encodeValue( - key = DEFAULT_ACCOUNT, - serializer = DefaultAccount.serializer(), - value = account, - ) -} +} \ No newline at end of file diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt index 0ab0b08d342..1a76e1ab832 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepository.kt @@ -10,37 +10,12 @@ package org.mifos.core.datastore import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.StateFlow -//import org.mifos.core.datastore -//import org.mifospay.core.model.account.DefaultAccount -//import org.mifospay.core.model.client.Client -//import org.mifospay.core.model.client.UpdatedClient -//import org.mifospay.core.model.user.UserInfo +import org.mifos.core.datastore.model.UserData -interface UserPreferencesRepository { - val userInfo: Flow - - val token: StateFlow - - val client: StateFlow - - val clientId: StateFlow - - val authToken: String? - - val defaultAccount: StateFlow - val defaultAccountId: StateFlow - - suspend fun updateToken(token: String): DataState - - suspend fun updateUserInfo(user: UserInfo): DataState - - suspend fun updateClientInfo(client: Client): DataState - - suspend fun updateClientProfile(client: UpdatedClient): DataState - - suspend fun updateDefaultAccount(account: DefaultAccount): DataState +interface UserPreferencesRepository { + val userInfo: Flow + suspend fun updateUser(user: UserData): Result suspend fun logOut(): Unit } diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt index 06ed4f79c01..e1de6eafaa5 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesRepositoryImpl.kt @@ -9,19 +9,11 @@ */ package org.mifos.core.datastore + import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.flowOn -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.stateIn -//import org.mifospay.core.common.DataState -//import org.mifospay.core.model.account.DefaultAccount -//import org.mifospay.core.model.client.Client -//import org.mifospay.core.model.client.UpdatedClient -//import org.mifospay.core.model.user.UserInfo +import org.mifos.core.datastore.model.UserData class UserPreferencesRepositoryImpl( private val preferenceManager: UserPreferencesDataSource, @@ -29,99 +21,17 @@ class UserPreferencesRepositoryImpl( unconfinedDispatcher: CoroutineDispatcher, ) : UserPreferencesRepository { private val unconfinedScope = CoroutineScope(unconfinedDispatcher) - - override val userInfo: Flow - get() = preferenceManager.userInfo.flowOn(ioDispatcher) - - override val token: StateFlow - get() = preferenceManager.token.stateIn( - scope = unconfinedScope, - initialValue = null, - started = SharingStarted.Eagerly, - ) - - override val client: StateFlow - get() = preferenceManager.clientInfo.stateIn( - scope = unconfinedScope, - initialValue = null, - started = SharingStarted.Eagerly, - ) - - override val clientId: StateFlow - get() = preferenceManager.clientId.stateIn( - scope = unconfinedScope, - initialValue = null, - started = SharingStarted.Eagerly, - ) - - override val authToken: String? - get() = preferenceManager.getAuthToken() - - override val defaultAccount: StateFlow - get() = preferenceManager.defaultAccount.stateIn( - scope = unconfinedScope, - initialValue = null, - started = SharingStarted.Eagerly, - ) - - override val defaultAccountId: StateFlow - get() = preferenceManager.defaultAccount - .map { it?.accountId }.stateIn( - scope = unconfinedScope, - initialValue = null, - started = SharingStarted.Eagerly, - ) - - override suspend fun updateDefaultAccount(account: DefaultAccount): DataState { - return try { - val result = preferenceManager.updateDefaultAccount(account) - - DataState.Success(result) - } catch (e: Exception) { - DataState.Error(e) - } - } - - override suspend fun updateToken(token: String): DataState { - return try { - val result = preferenceManager.updateAuthToken(token) - - DataState.Success(result) - } catch (e: Exception) { - DataState.Error(e) - } - } - - override suspend fun updateClientInfo(client: Client): DataState { - return try { - val result = preferenceManager.updateClientInfo(client) - - DataState.Success(result) - } catch (e: Exception) { - DataState.Error(e) - } - } - - override suspend fun updateClientProfile(client: UpdatedClient): DataState { - return try { - val result = preferenceManager.updateClientProfile(client) - DataState.Success(result) - } catch (e: Exception) { - DataState.Error(e) - } - } - - override suspend fun updateUserInfo(user: UserInfo): DataState { + override val userInfo: Flow + get() = preferenceManager.userInfo + override suspend fun updateUser(user: UserData): Result { return try { val result = preferenceManager.updateUserInfo(user) - - DataState.Success(result) + Result.success(result) } catch (e: Exception) { - DataState.Error(e) + Result.failure(e) } } - override suspend fun logOut() { preferenceManager.clearInfo() } -} +} \ No newline at end of file diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt index cac8fc70f5b..0a97634f518 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/di/PreferenceModule.kt @@ -12,7 +12,6 @@ package org.mifos.core.datastore.di import com.russhwolf.settings.Settings import org.koin.core.qualifier.named import org.koin.dsl.module -import org.mifos.core.datastore.MifosDispatchers import org.mifos.core.datastore.UserPreferencesDataSource import org.mifos.core.datastore.UserPreferencesRepository import org.mifos.core.datastore.UserPreferencesRepositoryImpl @@ -31,3 +30,9 @@ val PreferencesModule = module { ) } } + +enum class MifosDispatchers { + Default, + IO, + Unconfined, +} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt deleted file mode 100644 index fb9364f025b..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/Client.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - - - -@Parcelize -data class Client( - val id: Long, - val accountNo: String, - val externalId: String, - val active: Boolean, - val activationDate: List, - val firstname: String, - val lastname: String, - val displayName: String, - val mobileNo: String, - val emailAddress: String, - val dateOfBirth: List, - val isStaff: Boolean, - val officeId: Long, - val officeName: String, - val savingsProductName: String -) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt deleted file mode 100644 index 56f05ed22a1..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/ClientPreferences.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore.model - -import kotlinx.serialization.Serializable - -@Serializable -data class ClientPreferences( - val id: Long, - val accountNo: String, - val externalId: String, - val active: Boolean, - val activationDate: List, - val firstname: String, - val lastname: String, - val displayName: String, - val mobileNo: String, - val emailAddress: String, - val dateOfBirth: List, - val isStaff: Boolean, - val officeId: Long, - val officeName: String, - val savingsProductName: String, -) { - companion object { - val DEFAULT = ClientPreferences( - id = 0L, - accountNo = "", - externalId = "", - active = false, - activationDate = emptyList(), - firstname = "", - lastname = "", - displayName = "", - mobileNo = "", - emailAddress = "", - dateOfBirth = emptyList(), - isStaff = false, - officeId = 0, - officeName = "", - savingsProductName = "", - ) - } -} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt deleted file mode 100644 index 7bdaa566652..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/DefaultAccount.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -import kotlinx.serialization.Serializable -import org.mifos.core.datastore.Parcelize - -@Serializable -@Parcelize -data class DefaultAccount( - val accountId: Long, - val accountNo: String, -) - diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt deleted file mode 100644 index 89c9ef1c03b..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/RolePreferences.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore.model - -import kotlinx.serialization.Serializable - -@Serializable -data class RolePreferences( - val id: String, - val name: String, - val description: String, - val disabled: Boolean, -) { - companion object { - val DEFAULT = RolePreferences( - id = "", - name = "", - description = "", - disabled = false, - ) - } -} diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt deleted file mode 100644 index 7514fc6d300..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UpdatedClient.kt +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - - - -@Parcelize -data class UpdatedClient( - val firstname: String, - val lastname: String, - val externalId: String, - val mobileNo: String, - val emailAddress: String, -) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/User.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/User.kt new file mode 100644 index 00000000000..20cbc03746d --- /dev/null +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/User.kt @@ -0,0 +1,19 @@ +package org.mifos.core.datastore.model + +import kotlinx.serialization.Serializable +@Serializable +data class UserData( + val userId: Long, + val userName: String, + val clientId: Long, + val isAuthenticated: Boolean +) { + companion object { + val DEFAULT = UserData( + userId = -1, + userName = "", + clientId = -1, + isAuthenticated = false, + ) + } +} \ No newline at end of file diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt deleted file mode 100644 index ffd80ad9971..00000000000 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/model/UserInfoPreferences.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore.model - -import kotlinx.serialization.Serializable - -@Serializable -data class UserInfoPreferences( - val username: String, - val userId: Long, - val base64EncodedAuthenticationKey: String, - val authenticated: Boolean, - val officeId: Int, - val officeName: String, - val roles: List, - val permissions: List, - val clients: List, - val shouldRenewPassword: Boolean, - val isTwoFactorAuthenticationRequired: Boolean, -) { - companion object { - val DEFAULT = UserInfoPreferences( - username = "", - userId = 0, - base64EncodedAuthenticationKey = "", - authenticated = false, - officeId = 0, - officeName = "", - roles = emptyList(), - permissions = emptyList(), - clients = emptyList(), - shouldRenewPassword = false, - isTwoFactorAuthenticationRequired = false, - ) - } -} diff --git a/core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt b/core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt deleted file mode 100644 index 505c69125c0..00000000000 --- a/core/datastore/src/desktopMain/kotlin/org.mifos.core.datastore/Parcelize.desktop.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -//actual interface Parcelable -//actual annotation class IgnoredOnParcel -actual annotation class Parcelize -actual interface Parceler

{ - actual fun create(parcel: Parcel): P - actual fun P.write(parcel: Parcel, flags: Int) -} - -actual annotation class TypeParceler> - -actual class Parcel { - actual fun readString(): String? = null - actual fun readByte(): Byte = 1 - - actual fun readInt(): Int = 1 - - actual fun readFloat(): Float = 1f - - actual fun readDouble(): Double = 1.0 - - actual fun writeByte(value: Byte) { - } - - actual fun writeInt(value: Int) { - } - - actual fun writeFloat(value: Float) { - } - - actual fun writeDouble(value: Double) { - } - - actual fun writeString(value: String?) { - } -} diff --git a/core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt b/core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt deleted file mode 100644 index 505c69125c0..00000000000 --- a/core/datastore/src/jsMain/kotlin/org.mifos.core.datastore/Parcelize.js.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -//actual interface Parcelable -//actual annotation class IgnoredOnParcel -actual annotation class Parcelize -actual interface Parceler

{ - actual fun create(parcel: Parcel): P - actual fun P.write(parcel: Parcel, flags: Int) -} - -actual annotation class TypeParceler> - -actual class Parcel { - actual fun readString(): String? = null - actual fun readByte(): Byte = 1 - - actual fun readInt(): Int = 1 - - actual fun readFloat(): Float = 1f - - actual fun readDouble(): Double = 1.0 - - actual fun writeByte(value: Byte) { - } - - actual fun writeInt(value: Int) { - } - - actual fun writeFloat(value: Float) { - } - - actual fun writeDouble(value: Double) { - } - - actual fun writeString(value: String?) { - } -} diff --git a/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt b/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt index 1a8e8b1d746..ca77c5a931f 100644 --- a/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt +++ b/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt @@ -9,89 +9,89 @@ */ package com.mifos.core.datastore -import android.content.Context -import android.content.SharedPreferences -import android.preference.PreferenceManager -import com.mifos.core.common.BuildConfig -import com.mifos.core.common.model.user.User -import com.mifos.core.common.utils.Constants -import com.mifos.core.common.utils.asServerConfig -import com.mifos.core.model.ServerConfig -import dagger.hilt.android.qualifiers.ApplicationContext -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flow -import org.mifos.core.sharedpreference.Key -import org.mifos.core.sharedpreference.UserPreferences -import org.openapitools.client.models.PostAuthenticationResponse -import javax.inject.Inject - -/** - * Created by Aditya Gupta on 19/08/23. - */ -const val USER_DETAILS = "user_details" -const val AUTH_USERNAME = "auth_username" -const val AUTH_PASSWORD = "auth_password" - -class PrefManager @Inject constructor( - @ApplicationContext context: Context, -) : UserPreferences() { - - private val serverConfigKey = Key.Custom("SERVER_CONFIG_KEY") - - override val preference: SharedPreferences = - PreferenceManager.getDefaultSharedPreferences(context) - - override fun getUser(): User { - return gson.fromJson(preference.getString(USER_DETAILS, ""), User::class.java) - } - - override fun saveUser(user: User) { - preference.edit().putString(USER_DETAILS, gson.toJson(user)).apply() - } - - // Created this to store userDetails - fun savePostAuthenticationResponse(user: PostAuthenticationResponse) { - preference.edit().putString(USER_DETAILS, gson.toJson(user)).apply() - } - - fun setPermissionDeniedStatus(permissionDeniedStatus: String, status: Boolean) { - preference.edit().putBoolean(permissionDeniedStatus, status).apply() - } - - fun getPermissionDeniedStatus(permissionDeniedStatus: String): Boolean { - return preference.getBoolean(permissionDeniedStatus, true) - } - - var userStatus: Boolean - get() = preference.getBoolean(Constants.SERVICE_STATUS, false) - set(status) { - preference.edit().putBoolean(Constants.SERVICE_STATUS, status).apply() - } - - var usernamePassword: Pair - get() = Pair( - preference.getString(AUTH_USERNAME, "")!!, - preference.getString(AUTH_PASSWORD, "")!!, - ) - set(value) { - preference.edit().putString(AUTH_USERNAME, value.first).apply() - preference.edit().putString(AUTH_PASSWORD, value.second).apply() - } - - val getServerConfig: ServerConfig = - preference.getString(serverConfigKey.value, null)?.let { - gson.fromJson(it, ServerConfig::class.java) - } ?: BuildConfig.DEMO_SERVER_CONFIG.asServerConfig() - - fun updateServerConfig(config: ServerConfig?) { - this.put(serverConfigKey, config) - } - - fun getStringValue(key: String): Flow = flow { - emit(preference.getString(key, "")) - } - - fun setStringValue(key: String, value: String) { - preference.edit().putString(key, value).apply() - } -} +//import android.content.Context +//import android.content.SharedPreferences +//import android.preference.PreferenceManager +//import com.mifos.core.common.BuildConfig +//import com.mifos.core.common.model.user.User +//import com.mifos.core.common.utils.Constants +//import com.mifos.core.common.utils.asServerConfig +//import com.mifos.core.model.ServerConfig +//import dagger.hilt.android.qualifiers.ApplicationContext +//import kotlinx.coroutines.flow.Flow +//import kotlinx.coroutines.flow.flow +//import org.mifos.core.sharedpreference.Key +//import org.mifos.core.sharedpreference.UserPreferences +//import org.openapitools.client.models.PostAuthenticationResponse +//import javax.inject.Inject +// +///** +// * Created by Aditya Gupta on 19/08/23. +// */ +//const val USER_DETAILS = "user_details" +//const val AUTH_USERNAME = "auth_username" +//const val AUTH_PASSWORD = "auth_password" +// +//class PrefManager @Inject constructor( +// @ApplicationContext context: Context, +//) : UserPreferences() { +// +// private val serverConfigKey = Key.Custom("SERVER_CONFIG_KEY") +// +// override val preference: SharedPreferences = +// PreferenceManager.getDefaultSharedPreferences(context) +// +// override fun getUser(): User { +// return gson.fromJson(preference.getString(USER_DETAILS, ""), User::class.java) +// } +// +// override fun saveUser(user: User) { +// preference.edit().putString(USER_DETAILS, gson.toJson(user)).apply() +// } +// +// // Created this to store userDetails +// fun savePostAuthenticationResponse(user: PostAuthenticationResponse) { +// preference.edit().putString(USER_DETAILS, gson.toJson(user)).apply() +// } +// +// fun setPermissionDeniedStatus(permissionDeniedStatus: String, status: Boolean) { +// preference.edit().putBoolean(permissionDeniedStatus, status).apply() +// } +// +// fun getPermissionDeniedStatus(permissionDeniedStatus: String): Boolean { +// return preference.getBoolean(permissionDeniedStatus, true) +// } +// +// var userStatus: Boolean +// get() = preference.getBoolean(Constants.SERVICE_STATUS, false) +// set(status) { +// preference.edit().putBoolean(Constants.SERVICE_STATUS, status).apply() +// } +// +// var usernamePassword: Pair +// get() = Pair( +// preference.getString(AUTH_USERNAME, "")!!, +// preference.getString(AUTH_PASSWORD, "")!!, +// ) +// set(value) { +// preference.edit().putString(AUTH_USERNAME, value.first).apply() +// preference.edit().putString(AUTH_PASSWORD, value.second).apply() +// } +// +// val getServerConfig: ServerConfig = +// preference.getString(serverConfigKey.value, null)?.let { +// gson.fromJson(it, ServerConfig::class.java) +// } ?: BuildConfig.DEMO_SERVER_CONFIG.asServerConfig() +// +// fun updateServerConfig(config: ServerConfig?) { +// this.put(serverConfigKey, config) +// } +// +// fun getStringValue(key: String): Flow = flow { +// emit(preference.getString(key, "")) +// } +// +// fun setStringValue(key: String, value: String) { +// preference.edit().putString(key, value).apply() +// } +//} diff --git a/core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt b/core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt deleted file mode 100644 index 51d01bd51df..00000000000 --- a/core/datastore/src/main/java/org.mifos.core.datastore/Parcelize.android.kt +++ /dev/null @@ -1,47 +0,0 @@ -package org.mifos.core.datastore - -actual interface Parceler

{ - actual fun create(parcel: Parcel): P - actual fun P.write(parcel: Parcel, flags: Int) - -} - -actual annotation class TypeParceler> actual constructor() -actual annotation class Parcelize actual constructor() -actual class Parcel { - actual fun readByte(): Byte { - TODO("Not yet implemented") - } - - actual fun readInt(): Int { - TODO("Not yet implemented") - } - - actual fun readFloat(): Float { - TODO("Not yet implemented") - } - - actual fun readDouble(): Double { - TODO("Not yet implemented") - } - - actual fun readString(): String? { - TODO("Not yet implemented") - } - - actual fun writeByte(value: Byte) { - } - - actual fun writeInt(value: Int) { - } - - actual fun writeFloat(value: Float) { - } - - actual fun writeDouble(value: Double) { - } - - actual fun writeString(value: String?) { - } - -} \ No newline at end of file diff --git a/core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt b/core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt deleted file mode 100644 index 505c69125c0..00000000000 --- a/core/datastore/src/nativeMain/kotlin/org.mifos.core.datastore/Parcelize.native.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -//actual interface Parcelable -//actual annotation class IgnoredOnParcel -actual annotation class Parcelize -actual interface Parceler

{ - actual fun create(parcel: Parcel): P - actual fun P.write(parcel: Parcel, flags: Int) -} - -actual annotation class TypeParceler> - -actual class Parcel { - actual fun readString(): String? = null - actual fun readByte(): Byte = 1 - - actual fun readInt(): Int = 1 - - actual fun readFloat(): Float = 1f - - actual fun readDouble(): Double = 1.0 - - actual fun writeByte(value: Byte) { - } - - actual fun writeInt(value: Int) { - } - - actual fun writeFloat(value: Float) { - } - - actual fun writeDouble(value: Double) { - } - - actual fun writeString(value: String?) { - } -} diff --git a/core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt b/core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt deleted file mode 100644 index 505c69125c0..00000000000 --- a/core/datastore/src/wasmJsMain/kotlin/org.mifos.core.datastore/Parcelize.wasmJs.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifos.core.datastore - -//actual interface Parcelable -//actual annotation class IgnoredOnParcel -actual annotation class Parcelize -actual interface Parceler

{ - actual fun create(parcel: Parcel): P - actual fun P.write(parcel: Parcel, flags: Int) -} - -actual annotation class TypeParceler> - -actual class Parcel { - actual fun readString(): String? = null - actual fun readByte(): Byte = 1 - - actual fun readInt(): Int = 1 - - actual fun readFloat(): Float = 1f - - actual fun readDouble(): Double = 1.0 - - actual fun writeByte(value: Byte) { - } - - actual fun writeInt(value: Int) { - } - - actual fun writeFloat(value: Float) { - } - - actual fun writeDouble(value: Double) { - } - - actual fun writeString(value: String?) { - } -} From e4f4fff84b7c53a574cef21f2ebca1b397e57ff2 Mon Sep 17 00:00:00 2001 From: kapmaurya Date: Fri, 31 Jan 2025 16:55:04 +0530 Subject: [PATCH 07/13] datastore-migration-kmpl --- core/datastore/src/commonMain/PrefManager.kt | 10 ++ .../UserPreferencesDataSource.kt | 66 ------------- .../com/mifos/core/datastore/PrefManager.kt | 97 ------------------- 3 files changed, 10 insertions(+), 163 deletions(-) create mode 100644 core/datastore/src/commonMain/PrefManager.kt delete mode 100644 core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt diff --git a/core/datastore/src/commonMain/PrefManager.kt b/core/datastore/src/commonMain/PrefManager.kt new file mode 100644 index 00000000000..41a9304a4f1 --- /dev/null +++ b/core/datastore/src/commonMain/PrefManager.kt @@ -0,0 +1,10 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.core.datastore diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt index 653f6e0580c..b1014cc99a6 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt @@ -10,72 +10,6 @@ //@file:OptIn(ExperimentalSerializationApi::class, ExperimentalSettingsApi::class) // package org.mifos.core.datastore -// -//import com.russhwolf.settings.ExperimentalSettingsApi -//import com.russhwolf.settings.Settings -//import com.russhwolf.settings.serialization.decodeValue -//import com.russhwolf.settings.serialization.decodeValueOrNull -//import com.russhwolf.settings.serialization.encodeValue -//import kotlinx.coroutines.CoroutineDispatcher -// -//import kotlinx.coroutines.flow.MutableStateFlow -//import kotlinx.coroutines.flow.map -//import kotlinx.coroutines.withContext -//import kotlinx.serialization.ExperimentalSerializationApi -// -// -//private const val USER_INFO_KEY = "userInfo" -// -// -//@OptIn(ExperimentalSerializationApi::class) -//class UserPreferencesDataSource( -// private val settings: Settings, -// private val dispatcher: CoroutineDispatcher, -//) { -// private val _userInfo = MutableStateFlow( -// settings.decodeValue( -// key = USER_INFO_KEY, -// serializer = UserInfoPreferences.serializer(), -// defaultValue = settings.decodeValueOrNull( -// key = USER_INFO_KEY, -// serializer = UserInfoPreferences.serializer(), -// ) ?: UserInfoPreferences.DEFAULT, -// ), -// ) -// -// -// val userInfo = _userInfo.map(UserInfoPreferences::toUserInfo) -// -// suspend fun updateUserInfo(userInfo: UserInfo) { -// withContext(dispatcher) { -// settings.putUserInfoPreference(userInfo.toUserInfoPreferences()) -// _userInfo.value = userInfo.toUserInfoPreferences() -// } -// } -// -// -// -// -// suspend fun clearInfo() { -// withContext(dispatcher) { -// settings.clear() -// } -// } -// -// -//} -// -// -// -//private fun Settings.putUserInfoPreference(preference: UserInfoPreferences) { -// encodeValue( -// key = USER_INFO_KEY, -// serializer = UserInfoPreferences.serializer(), -// value = preference, -// ) -//} -// -// import com.russhwolf.settings.serialization.decodeValue import com.russhwolf.settings.serialization.decodeValueOrNull diff --git a/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt b/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt deleted file mode 100644 index ca77c5a931f..00000000000 --- a/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2024 Mifos Initiative - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. - * - * See https://github.com/openMF/android-client/blob/master/LICENSE.md - */ -package com.mifos.core.datastore - -//import android.content.Context -//import android.content.SharedPreferences -//import android.preference.PreferenceManager -//import com.mifos.core.common.BuildConfig -//import com.mifos.core.common.model.user.User -//import com.mifos.core.common.utils.Constants -//import com.mifos.core.common.utils.asServerConfig -//import com.mifos.core.model.ServerConfig -//import dagger.hilt.android.qualifiers.ApplicationContext -//import kotlinx.coroutines.flow.Flow -//import kotlinx.coroutines.flow.flow -//import org.mifos.core.sharedpreference.Key -//import org.mifos.core.sharedpreference.UserPreferences -//import org.openapitools.client.models.PostAuthenticationResponse -//import javax.inject.Inject -// -///** -// * Created by Aditya Gupta on 19/08/23. -// */ -//const val USER_DETAILS = "user_details" -//const val AUTH_USERNAME = "auth_username" -//const val AUTH_PASSWORD = "auth_password" -// -//class PrefManager @Inject constructor( -// @ApplicationContext context: Context, -//) : UserPreferences() { -// -// private val serverConfigKey = Key.Custom("SERVER_CONFIG_KEY") -// -// override val preference: SharedPreferences = -// PreferenceManager.getDefaultSharedPreferences(context) -// -// override fun getUser(): User { -// return gson.fromJson(preference.getString(USER_DETAILS, ""), User::class.java) -// } -// -// override fun saveUser(user: User) { -// preference.edit().putString(USER_DETAILS, gson.toJson(user)).apply() -// } -// -// // Created this to store userDetails -// fun savePostAuthenticationResponse(user: PostAuthenticationResponse) { -// preference.edit().putString(USER_DETAILS, gson.toJson(user)).apply() -// } -// -// fun setPermissionDeniedStatus(permissionDeniedStatus: String, status: Boolean) { -// preference.edit().putBoolean(permissionDeniedStatus, status).apply() -// } -// -// fun getPermissionDeniedStatus(permissionDeniedStatus: String): Boolean { -// return preference.getBoolean(permissionDeniedStatus, true) -// } -// -// var userStatus: Boolean -// get() = preference.getBoolean(Constants.SERVICE_STATUS, false) -// set(status) { -// preference.edit().putBoolean(Constants.SERVICE_STATUS, status).apply() -// } -// -// var usernamePassword: Pair -// get() = Pair( -// preference.getString(AUTH_USERNAME, "")!!, -// preference.getString(AUTH_PASSWORD, "")!!, -// ) -// set(value) { -// preference.edit().putString(AUTH_USERNAME, value.first).apply() -// preference.edit().putString(AUTH_PASSWORD, value.second).apply() -// } -// -// val getServerConfig: ServerConfig = -// preference.getString(serverConfigKey.value, null)?.let { -// gson.fromJson(it, ServerConfig::class.java) -// } ?: BuildConfig.DEMO_SERVER_CONFIG.asServerConfig() -// -// fun updateServerConfig(config: ServerConfig?) { -// this.put(serverConfigKey, config) -// } -// -// fun getStringValue(key: String): Flow = flow { -// emit(preference.getString(key, "")) -// } -// -// fun setStringValue(key: String, value: String) { -// preference.edit().putString(key, value).apply() -// } -//} From 1c268ca1393ce9e588aa6bd4d8bf5503011a120e Mon Sep 17 00:00:00 2001 From: kapmaurya Date: Fri, 31 Jan 2025 17:15:04 +0530 Subject: [PATCH 08/13] datastore-migration-kmpl --- .../mifos/room/basemodel/MifosBaseModel.kt | 21 ++ .../accounts/loans/ActualDisbursementDate.kt | 29 +++ .../entities/accounts/loans/LoanAccount.kt | 69 ++++++ .../accounts/loans/LoanRepaymentRequest.kt | 68 ++++++ .../room/entities/accounts/loans/LoanType.kt | 26 +++ .../accounts/loans/LoanWithAssociations.kt | 198 ++++++++++++++++++ .../room/entities/accounts/loans/Status.kt | 50 +++++ .../room/entities/accounts/loans/Summary.kt | 124 +++++++++++ .../room/entities/accounts/loans/Timeline.kt | 83 ++++++++ .../entities/accounts/savings/Currency.kt | 38 ++++ .../entities/accounts/savings/DepositType.kt | 45 ++++ .../accounts/savings/SavingsAccount.kt | 75 +++++++ .../SavingsAccountTransactionRequest.kt | 67 ++++++ .../savings/SavingsAccountWithAssociations.kt | 125 +++++++++++ .../savings/SavingsTransactionDate.kt | 29 +++ .../room/entities/accounts/savings/Status.kt | 44 ++++ .../room/entities/accounts/savings/Summary.kt | 39 ++++ .../entities/accounts/savings/Transaction.kt | 75 +++++++ .../accounts/savings/TransactionType.kt | 59 ++++++ .../room/entities/center/CenterPayload.kt | 46 ++++ .../entities/client/ChargeCalculationType.kt | 33 +++ .../room/entities/client/ChargeTimeType.kt | 30 +++ .../com/mifos/room/entities/client/Charges.kt | 134 ++++++++++++ .../com/mifos/room/entities/client/Client.kt | 128 +++++++++++ .../mifos/room/entities/client/ClientDate.kt | 37 ++++ .../room/entities/client/ClientPayload.kt | 86 ++++++++ .../mifos/room/entities/client/Currency.kt | 42 ++++ .../com/mifos/room/entities/client/Status.kt | 39 ++++ .../com/mifos/room/entities/group/Center.kt | 80 +++++++ .../mifos/room/entities/group/CenterDate.kt | 37 ++++ .../com/mifos/room/entities/group/Group.kt | 90 ++++++++ .../mifos/room/entities/group/GroupDate.kt | 37 ++++ .../mifos/room/entities/group/GroupPayload.kt | 53 +++++ .../room/entities/noncore/ColumnHeader.kt | 52 +++++ .../mifos/room/entities/noncore/DataTable.kt | 31 +++ .../room/entities/noncore/DataTablePayload.kt | 41 ++++ .../com/mifos/room/entities/noncore/Note.kt | 48 +++++ .../room/entities/organisation/Office.kt | 50 +++++ .../organisation/OfficeOpeningDate.kt | 33 +++ .../mifos/room/entities/organisation/Staff.kt | 48 +++++ .../room/entities/survey/ComponentDatas.kt | 36 ++++ .../room/entities/survey/QuestionDatas.kt | 54 +++++ .../room/entities/survey/ResponseDatas.kt | 37 ++++ .../com/mifos/room/entities/survey/Survey.kt | 46 ++++ .../templates/clients/ClientsTemplate.kt | 67 ++++++ .../templates/clients/InterestType.kt | 30 +++ .../templates/clients/OfficeOptions.kt | 35 ++++ .../entities/templates/clients/Options.kt | 82 ++++++++ .../templates/clients/SavingProductOptions.kt | 33 +++ .../templates/clients/StaffOptions.kt | 48 +++++ .../templates/loans/LoanRepaymentTemplate.kt | 54 +++++ .../SavingsAccountTransactionTemplate.kt | 42 ++++ .../utils/typeconverters/DueDateConverter.kt | 26 +++ .../typeconverters/ServerTypesConverters.kt | 25 +++ .../com/mifos/core/datastore/PrefManager.kt | 97 +++++++++ 55 files changed, 3151 insertions(+) create mode 100644 core/database/src/main/java/com/mifos/room/basemodel/MifosBaseModel.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/loans/ActualDisbursementDate.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanAccount.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanRepaymentRequest.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanType.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanWithAssociations.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/loans/Status.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/loans/Summary.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/loans/Timeline.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/savings/Currency.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/savings/DepositType.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsAccount.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsAccountTransactionRequest.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsAccountWithAssociations.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsTransactionDate.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/savings/Status.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/savings/Summary.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/savings/Transaction.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/accounts/savings/TransactionType.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/center/CenterPayload.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/client/ChargeCalculationType.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/client/ChargeTimeType.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/client/Charges.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/client/Client.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/client/ClientDate.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/client/ClientPayload.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/client/Currency.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/client/Status.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/group/Center.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/group/CenterDate.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/group/Group.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/group/GroupDate.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/group/GroupPayload.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/noncore/ColumnHeader.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/noncore/DataTable.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/noncore/DataTablePayload.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/noncore/Note.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/organisation/Office.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/organisation/OfficeOpeningDate.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/organisation/Staff.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/survey/ComponentDatas.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/survey/QuestionDatas.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/survey/ResponseDatas.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/survey/Survey.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/templates/clients/ClientsTemplate.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/templates/clients/InterestType.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/templates/clients/OfficeOptions.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/templates/clients/Options.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/templates/clients/SavingProductOptions.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/templates/clients/StaffOptions.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/templates/loans/LoanRepaymentTemplate.kt create mode 100644 core/database/src/main/java/com/mifos/room/entities/templates/savings/SavingsAccountTransactionTemplate.kt create mode 100644 core/database/src/main/java/com/mifos/room/utils/typeconverters/DueDateConverter.kt create mode 100644 core/database/src/main/java/com/mifos/room/utils/typeconverters/ServerTypesConverters.kt create mode 100644 core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt diff --git a/core/database/src/main/java/com/mifos/room/basemodel/MifosBaseModel.kt b/core/database/src/main/java/com/mifos/room/basemodel/MifosBaseModel.kt new file mode 100644 index 00000000000..b730ab47bb2 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/basemodel/MifosBaseModel.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.basemodel + +import kotlinx.serialization.Serializable +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json + +@Serializable +open class MifosBaseModel { + override fun toString(): String { + return Json.encodeToString(this) + } +} diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/loans/ActualDisbursementDate.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/ActualDisbursementDate.kt new file mode 100644 index 00000000000..80d26995f89 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/ActualDisbursementDate.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.loans + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity +data class ActualDisbursementDate( + @PrimaryKey + var loanId: Int? = null, + + @ColumnInfo(name = "year") + var year: Int? = null, + + @ColumnInfo(name = "month") + var month: Int? = null, + + @ColumnInfo(name = "date") + var date: Int? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanAccount.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanAccount.kt new file mode 100644 index 00000000000..c51c60b92bb --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanAccount.kt @@ -0,0 +1,69 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.loans + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.PrimaryKey + +@Entity( + foreignKeys = [ + ForeignKey( + entity = Status::class, + parentColumns = ["id"], + childColumns = ["status"], + onDelete = ForeignKey.CASCADE, + ), + ForeignKey( + entity = LoanType::class, + parentColumns = ["id"], + childColumns = ["loanType"], + onDelete = ForeignKey.CASCADE, + ), + ], +) +data class LoanAccount( + @PrimaryKey + var id: Int? = null, + + @ColumnInfo(name = "clientId") + var clientId: Long = 0, + + @ColumnInfo(name = "groupId") + var groupId: Long = 0, + + @ColumnInfo(name = "centerId") + var centerId: Long = 0, + + @ColumnInfo(name = "accountNo") + var accountNo: String? = null, + + @ColumnInfo(name = "externalId") + var externalId: String? = null, + + @ColumnInfo(name = "productId") + var productId: Int? = null, + + @ColumnInfo(name = "productName") + var productName: String? = null, + + @ColumnInfo(name = "status", index = true) + var status: Status? = null, + + @ColumnInfo(name = "loanType", index = true) + var loanType: LoanType? = null, + + @ColumnInfo(name = "loanCycle") + var loanCycle: Int? = null, + + @ColumnInfo(name = "inArrears") + var inArrears: Boolean? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanRepaymentRequest.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanRepaymentRequest.kt new file mode 100644 index 00000000000..74989552424 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanRepaymentRequest.kt @@ -0,0 +1,68 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.loans + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity +data class LoanRepaymentRequest( + +// TODO(check this out) +// @PrimaryKey(autoGenerate = true) +// var id: Int = 0, + + @ColumnInfo(name = "timeStamp") + @PrimaryKey + @Transient + var timeStamp: Long = 0, + + @ColumnInfo(name = "loanId") + @Transient + var loanId: Int? = null, + + @ColumnInfo(name = "errorMessage") + @Transient + var errorMessage: String? = null, + + @ColumnInfo(name = "dateFormat") + var dateFormat: String? = null, + + @ColumnInfo(name = "locale") + var locale: String? = null, + + @ColumnInfo(name = "transactionDate") + var transactionDate: String? = null, + + @ColumnInfo(name = "transactionAmount") + var transactionAmount: String? = null, + + @ColumnInfo(name = "paymentTypeId") + var paymentTypeId: String? = null, + + @ColumnInfo(name = "note") + var note: String? = null, + + @ColumnInfo(name = "accountNumber") + var accountNumber: String? = null, + + @ColumnInfo(name = "checkNumber") + var checkNumber: String? = null, + + @ColumnInfo(name = "routingCode") + var routingCode: String? = null, + + @ColumnInfo(name = "receiptNumber") + var receiptNumber: String? = null, + + @ColumnInfo(name = "bankNumber") + var bankNumber: String? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanType.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanType.kt new file mode 100644 index 00000000000..726a590d6da --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanType.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.loans + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "LoanAccountLoanType") +data class LoanType( + @PrimaryKey + var id: Int? = null, + + @ColumnInfo("code") + var code: String? = null, + + @ColumnInfo("value") + var value: String? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanWithAssociations.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanWithAssociations.kt new file mode 100644 index 00000000000..1c39acae611 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/LoanWithAssociations.kt @@ -0,0 +1,198 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.loans + +import androidx.room.ColumnInfo +import androidx.room.Embedded +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.PrimaryKey +import com.mifos.core.objects.account.loan.AmortizationType +import com.mifos.core.objects.account.loan.Currency +import com.mifos.core.objects.account.loan.InterestCalculationPeriodType +import com.mifos.core.objects.account.loan.InterestRateFrequencyType +import com.mifos.core.objects.account.loan.InterestType +import com.mifos.core.objects.account.loan.RepaymentFrequencyType +import com.mifos.core.objects.account.loan.RepaymentSchedule +import com.mifos.core.objects.account.loan.TermPeriodFrequencyType +import com.mifos.core.objects.account.loan.Transaction + +@Entity( + tableName = "LoanWithAssociations", + foreignKeys = [ + ForeignKey( + entity = Status::class, + parentColumns = ["id"], + childColumns = ["status"], + onDelete = ForeignKey.CASCADE, + ), + ForeignKey( + entity = Timeline::class, + parentColumns = ["loanId"], + childColumns = ["timeline"], + onDelete = ForeignKey.CASCADE, + ), + ForeignKey( + entity = Summary::class, + parentColumns = ["savings"], + childColumns = ["summary"], + onDelete = ForeignKey.CASCADE, + ), + ], +) +// @TypeConverters( +// AmortizationTypeConverter::class, +// CurrencyTypeConverter::class, +// InterestCalculationPeriodTypeConverter::class, +// InterestRateFrequencyTypeConverter::class, +// InterestTypeConverter::class, +// LoanTypeConverter::class, +// RepaymentFrequencyTypeConverter::class, +// RepaymentScheduleTypeConverter::class, +// TermPeriodFrequencyTypeConverter::class, +// TimelineTypeConverter::class, +// TransactionListConverter::class, +// ) +data class LoanWithAssociations( + @PrimaryKey + var id: Int = 0, + + @ColumnInfo(name = "accountNo") + var accountNo: String = "", + + @ColumnInfo(name = "status", index = true) + var status: Status = Status(), + + @ColumnInfo(name = "clientId") + var clientId: Int = 0, + + @ColumnInfo(name = "clientName") + var clientName: String = "", + + @ColumnInfo(name = "clientOfficeId") + var clientOfficeId: Int = 0, + + @ColumnInfo(name = "loanProductId") + var loanProductId: Int = 0, + + @ColumnInfo(name = "loanProductName") + var loanProductName: String = "", + + @ColumnInfo(name = "loanProductDescription") + var loanProductDescription: String = "", + + @ColumnInfo(name = "fundId") + var fundId: Int = 0, + + @ColumnInfo(name = "fundName") + var fundName: String = "", + + @ColumnInfo(name = "loanPurposeId") + var loanPurposeId: Int = 0, + + @ColumnInfo(name = "loanPurposeName") + var loanPurposeName: String = "", + + @ColumnInfo(name = "loanOfficerId") + var loanOfficerId: Int = 0, + + @ColumnInfo(name = "loanOfficerName") + var loanOfficerName: String = "", + + @Embedded + var loanType: LoanType = LoanType(), + + @Embedded + var currency: Currency = Currency(), + + @ColumnInfo(name = "principal") + var principal: Double = 0.0, + + @ColumnInfo(name = "approvedPrincipal") + var approvedPrincipal: Double = 0.0, + + @ColumnInfo(name = "termFrequency") + var termFrequency: Int = 0, + + @Embedded + var termPeriodFrequencyType: TermPeriodFrequencyType = TermPeriodFrequencyType(), + + @ColumnInfo(name = "numberOfRepayments") + var numberOfRepayments: Int = 0, + + @ColumnInfo(name = "repaymentEvery") + var repaymentEvery: Int = 0, + + @Embedded + var repaymentFrequencyType: RepaymentFrequencyType = RepaymentFrequencyType(), + + @ColumnInfo(name = "interestRatePerPeriod") + var interestRatePerPeriod: Double = 0.0, + + @Embedded + var interestRateFrequencyType: InterestRateFrequencyType = InterestRateFrequencyType(), + + @ColumnInfo(name = "annualInterestRate") + var annualInterestRate: Double = 0.0, + + @Embedded + var amortizationType: AmortizationType = AmortizationType(), + + @Embedded + var interestType: InterestType = InterestType(), + + @Embedded + var interestCalculationPeriodType: InterestCalculationPeriodType = InterestCalculationPeriodType(), + + @ColumnInfo(name = "transactionProcessingStrategyId") + var transactionProcessingStrategyId: Int = 0, + + @ColumnInfo(name = "transactionProcessingStrategyName") + var transactionProcessingStrategyName: String = "", + + @ColumnInfo(name = "syncDisbursementWithMeeting") + var syncDisbursementWithMeeting: Boolean = false, + + @ColumnInfo(name = "timeline", index = true) + var timeline: Timeline = Timeline(), + + @ColumnInfo(name = "summary", index = true) + var summary: Summary = Summary(), + + @Embedded + var repaymentSchedule: RepaymentSchedule = RepaymentSchedule(), + + @ColumnInfo(name = "transactions") + var transactions: List = ArrayList(), + + @ColumnInfo(name = "feeChargesAtDisbursementCharged") + var feeChargesAtDisbursementCharged: Double = 0.0, + + @ColumnInfo(name = "totalOverpaid") + var totalOverpaid: Double = 0.0, + + @ColumnInfo(name = "loanCounter") + var loanCounter: Int = 0, + + @ColumnInfo(name = "loanProductCounter") + var loanProductCounter: Int = 0, + + @ColumnInfo(name = "multiDisburseLoan") + var multiDisburseLoan: Boolean = false, + + @ColumnInfo(name = "canDisburse") + var canDisburse: Boolean = false, + + @ColumnInfo(name = "inArrears") + var inArrears: Boolean = false, + + @ColumnInfo(name = "isNPA") + var isNPA: Boolean = false, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/loans/Status.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/Status.kt new file mode 100644 index 00000000000..f6d427df461 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/Status.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.loans + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "LoanStatus") +data class Status( + @PrimaryKey + var id: Int? = null, + + @ColumnInfo(name = "code") + var code: String? = null, + + @ColumnInfo(name = "value") + var value: String? = null, + + @ColumnInfo(name = "pendingApproval") + var pendingApproval: Boolean? = null, + + @ColumnInfo(name = "waitingForDisbursal") + var waitingForDisbursal: Boolean? = null, + + @ColumnInfo(name = "active") + var active: Boolean? = null, + + @ColumnInfo(name = "closedObligationsMet") + var closedObligationsMet: Boolean? = null, + + @ColumnInfo(name = "closedWrittenOff") + var closedWrittenOff: Boolean? = null, + + @ColumnInfo(name = "closedRescheduled") + var closedRescheduled: Boolean? = null, + + @ColumnInfo(name = "closed") + var closed: Boolean? = null, + + @ColumnInfo(name = "overpaid") + var overpaid: Boolean? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/loans/Summary.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/Summary.kt new file mode 100644 index 00000000000..9db95a472b9 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/Summary.kt @@ -0,0 +1,124 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.loans + +import androidx.room.ColumnInfo +import androidx.room.Embedded +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.mifos.core.objects.account.loan.Currency + +@Entity(tableName = "LoansAccountSummary") +data class Summary( + @PrimaryKey + var loanId: Int? = null, + + @Embedded + var currency: Currency? = null, + + @ColumnInfo(name = "principalDisbursed") + var principalDisbursed: Double? = null, + + @ColumnInfo(name = "principalPaid") + var principalPaid: Double? = null, + + @ColumnInfo(name = "principalWrittenOff") + var principalWrittenOff: Double? = null, + + @ColumnInfo(name = "principalOutstanding") + var principalOutstanding: Double? = null, + + @ColumnInfo(name = "principalOverdue") + var principalOverdue: Double? = null, + + @ColumnInfo(name = "interestCharged") + var interestCharged: Double? = null, + + @ColumnInfo(name = "interestPaid") + var interestPaid: Double? = null, + + @ColumnInfo(name = "interestWaived") + var interestWaived: Double? = null, + + @ColumnInfo(name = "interestWrittenOff") + var interestWrittenOff: Double? = null, + + @ColumnInfo(name = "interestOutstanding") + var interestOutstanding: Double? = null, + + @ColumnInfo(name = "interestOverdue") + var interestOverdue: Double? = null, + + @ColumnInfo(name = "feeChargesCharged") + var feeChargesCharged: Double? = null, + + @ColumnInfo(name = "feeChargesDueAtDisbursementCharged") + var feeChargesDueAtDisbursementCharged: Double? = null, + + @ColumnInfo(name = "feeChargesPaid") + var feeChargesPaid: Double? = null, + + @ColumnInfo(name = "feeChargesWaived") + var feeChargesWaived: Double? = null, + + @ColumnInfo(name = "feeChargesWrittenOff") + var feeChargesWrittenOff: Double? = null, + + @ColumnInfo(name = "feeChargesOutstanding") + var feeChargesOutstanding: Double? = null, + + @ColumnInfo(name = "feeChargesOverdue") + var feeChargesOverdue: Double? = null, + + @ColumnInfo(name = "penaltyChargesCharged") + var penaltyChargesCharged: Double? = null, + + @ColumnInfo(name = "penaltyChargesPaid") + var penaltyChargesPaid: Double? = null, + + @ColumnInfo(name = "penaltyChargesWaived") + var penaltyChargesWaived: Double? = null, + + @ColumnInfo(name = "penaltyChargesWrittenOff") + var penaltyChargesWrittenOff: Double? = null, + + @ColumnInfo(name = "penaltyChargesOutstanding") + var penaltyChargesOutstanding: Double? = null, + + @ColumnInfo(name = "penaltyChargesOverdue") + var penaltyChargesOverdue: Double? = null, + + @ColumnInfo(name = "totalExpectedRepayment") + var totalExpectedRepayment: Double? = null, + + @ColumnInfo(name = "totalRepayment") + var totalRepayment: Double? = null, + + @ColumnInfo(name = "totalExpectedCostOfLoan") + var totalExpectedCostOfLoan: Double? = null, + + @ColumnInfo(name = "totalCostOfLoan") + var totalCostOfLoan: Double? = null, + + @ColumnInfo(name = "totalWaived") + var totalWaived: Double? = null, + + @ColumnInfo(name = "totalWrittenOff") + var totalWrittenOff: Double? = null, + + @ColumnInfo(name = "totalOutstanding") + var totalOutstanding: Double? = null, + + @ColumnInfo(name = "totalOverdue") + var totalOverdue: Double? = null, + + @ColumnInfo(name = "overdueSinceDate") + var overdueSinceDate: List? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/loans/Timeline.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/Timeline.kt new file mode 100644 index 00000000000..b5a90b89202 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/loans/Timeline.kt @@ -0,0 +1,83 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.loans + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.PrimaryKey +import kotlinx.serialization.Transient + +@Entity( + tableName = "Timeline", + foreignKeys = [ + ForeignKey( + entity = ActualDisbursementDate::class, + parentColumns = ["loanId"], + childColumns = ["actualDisburseDate"], + onDelete = ForeignKey.CASCADE, + ), + ], +) +data class Timeline( + @PrimaryKey + @Transient + var loanId: Int? = null, + + @ColumnInfo(name = "submittedOnDate") + var submittedOnDate: List? = null, + + @ColumnInfo(name = "submittedByUsername") + var submittedByUsername: String? = null, + + @ColumnInfo(name = "submittedByFirstname") + var submittedByFirstname: String? = null, + + @ColumnInfo(name = "submittedByLastname") + var submittedByLastname: String? = null, + + @ColumnInfo(name = "approvedOnDate") + var approvedOnDate: List? = null, + + @ColumnInfo(name = "approvedByUsername") + var approvedByUsername: String? = null, + + @ColumnInfo(name = "approvedByFirstname") + var approvedByFirstname: String? = null, + + @ColumnInfo(name = "approvedByLastname") + var approvedByLastname: String? = null, + + @ColumnInfo(name = "expectedDisbursementDate") + var expectedDisbursementDate: List? = null, + +// todo check if its int + @ColumnInfo(name = "actualDisburseDate", index = true) + @Transient + var actualDisburseDate: ActualDisbursementDate? = null, + + @ColumnInfo(name = "actualDisbursementDate") + var actualDisbursementDate: List? = null, + + @ColumnInfo(name = "disbursedByUsername") + var disbursedByUsername: String? = null, + + @ColumnInfo(name = "disbursedByFirstname") + var disbursedByFirstname: String? = null, + + @ColumnInfo(name = "disbursedByLastname") + var disbursedByLastname: String? = null, + + @ColumnInfo(name = "closedOnDate") + var closedOnDate: List? = null, + + @ColumnInfo(name = "expectedMaturityDate") + var expectedMaturityDate: List? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/savings/Currency.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/Currency.kt new file mode 100644 index 00000000000..c8a1b445beb --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/Currency.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.savings + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "SavingAccountCurrency") +data class Currency( + @PrimaryKey + var code: String? = null, + + @ColumnInfo(name = "name") + var name: String? = null, + + @ColumnInfo(name = "decimalPlaces") + var decimalPlaces: Int? = null, + + @ColumnInfo(name = "inMultiplesOf") + var inMultiplesOf: Int? = null, + + @ColumnInfo(name = "displaySymbol") + var displaySymbol: String? = null, + + @ColumnInfo(name = "nameCode") + var nameCode: String? = null, + + @ColumnInfo(name = "displayLabel") + var displayLabel: String? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/savings/DepositType.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/DepositType.kt new file mode 100644 index 00000000000..f6924732c09 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/DepositType.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.savings + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.mifos.room.basemodel.APIEndPoint + +@Entity(tableName = "SavingAccountDepositType") +data class DepositType( + @PrimaryKey + var id: Int? = null, + + @ColumnInfo(name = "code") + var code: String? = null, + + @ColumnInfo(name = "value") + var value: String? = null, +) + +enum class ServerTypes(val id: Int, val code: String, val endpoint: String) { + SAVINGS(100, "depositAccountType.savingsDeposit", APIEndPoint.SAVINGS_ACCOUNTS), + FIXED(200, "depositAccountType.fixedDeposit", APIEndPoint.SAVINGS_ACCOUNTS), + RECURRING(300, "depositAccountType.recurringDeposit", APIEndPoint.RECURRING_ACCOUNTS), + ; + + companion object { + fun fromId(id: Int): ServerTypes { + for (type in entries) { + if (type.id == id) { + return type + } + } + return SAVINGS + } + } +} diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsAccount.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsAccount.kt new file mode 100644 index 00000000000..1a47321d5b3 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsAccount.kt @@ -0,0 +1,75 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.savings + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.PrimaryKey + +@Entity( + tableName = "SavingsAccount", + foreignKeys = [ + ForeignKey( + entity = Status::class, + parentColumns = ["id"], + childColumns = ["status"], + onDelete = ForeignKey.CASCADE, + ), + ForeignKey( + entity = Currency::class, + parentColumns = ["code"], + childColumns = ["currency"], + onDelete = ForeignKey.CASCADE, + ), + ForeignKey( + entity = DepositType::class, + parentColumns = ["id"], + childColumns = ["depositType"], + onDelete = ForeignKey.CASCADE, + ), + ], +) +data class SavingsAccount( + @PrimaryKey + var id: Int? = null, + + @ColumnInfo(name = "clientId") + @Transient + var clientId: Long = 0, + + @ColumnInfo(name = "groupId") + @Transient + var groupId: Long = 0, + + @ColumnInfo(name = "centerId") + var centerId: Long = 0, + + @ColumnInfo(name = "accountNo") + var accountNo: String? = null, + + @ColumnInfo(name = "productId") + var productId: Int? = null, + + @ColumnInfo(name = "productName") + var productName: String? = null, + + @ColumnInfo(name = "status", index = true) + var status: Status? = null, + + @ColumnInfo(name = "currency", index = true) + var currency: Currency? = null, + + @ColumnInfo(name = "accountBalance") + var accountBalance: Double? = null, + + @ColumnInfo(name = "depositType", index = true) + var depositType: DepositType? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsAccountTransactionRequest.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsAccountTransactionRequest.kt new file mode 100644 index 00000000000..9da0a1a15a9 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsAccountTransactionRequest.kt @@ -0,0 +1,67 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.savings + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "SavingsAccountTransactionRequest") +data class SavingsAccountTransactionRequest( + + @Transient + @PrimaryKey + var savingAccountId: Int? = null, + + @ColumnInfo(name = "savingsAccountType") + @Transient + var savingsAccountType: String? = null, + + @ColumnInfo(name = "transactionType") + @Transient + var transactionType: String? = null, + + @ColumnInfo(name = "dateFormat") + var dateFormat: String? = null, + + @ColumnInfo(name = "locale") + var locale: String? = null, + + @ColumnInfo(name = "transactionDate") + var transactionDate: String? = null, + + @ColumnInfo(name = "transactionAmount") + var transactionAmount: String? = null, + + @ColumnInfo(name = "paymentTypeId") + var paymentTypeId: String? = null, + + @ColumnInfo(name = "note") + var note: String? = null, + + @ColumnInfo(name = "accountNumber") + var accountNumber: String? = null, + + @ColumnInfo(name = "checkNumber") + var checkNumber: String? = null, + + @ColumnInfo(name = "routingCode") + var routingCode: String? = null, + + @ColumnInfo(name = "receiptNumber") + var receiptNumber: String? = null, + + @ColumnInfo(name = "bankNumber") + var bankNumber: String? = null, + + @ColumnInfo(name = "errorMessage") + @Transient + var errorMessage: String? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsAccountWithAssociations.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsAccountWithAssociations.kt new file mode 100644 index 00000000000..4686996860c --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsAccountWithAssociations.kt @@ -0,0 +1,125 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.savings + +import androidx.room.ColumnInfo +import androidx.room.Embedded +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.PrimaryKey +import com.mifos.core.objects.account.saving.InterestCalculationDaysInYearType +import com.mifos.core.objects.account.saving.InterestCalculationType +import com.mifos.core.objects.account.saving.InterestCompoundingPeriodType +import com.mifos.core.objects.account.saving.InterestPostingPeriodType +import com.mifos.core.objects.account.saving.LockinPeriodFrequencyType +import com.mifos.core.objects.account.saving.Timeline + +@Entity( + tableName = "SavingsAccountWithAssociations", + foreignKeys = [ + ForeignKey( + entity = Status::class, + parentColumns = ["id"], + childColumns = ["status"], + onDelete = ForeignKey.CASCADE, + ), + ForeignKey( + entity = Summary::class, + parentColumns = ["loanId"], + childColumns = ["summary"], + onDelete = ForeignKey.CASCADE, + ), + ], +) +data class SavingsAccountWithAssociations( + @PrimaryKey + var id: Int? = null, + + @ColumnInfo(name = "accountNo") + var accountNo: Int? = null, + + @ColumnInfo(name = "clientId") + var clientId: Int? = null, + + @ColumnInfo(name = "clientName") + var clientName: String? = null, + + @ColumnInfo(name = "savingsProductId") + var savingsProductId: Int? = null, + + @ColumnInfo(name = "savingsProductName") + var savingsProductName: String? = null, + + @ColumnInfo(name = "fieldOfficerId") + var fieldOfficerId: Int? = null, + + @ColumnInfo(name = "status", index = true) + var status: Status? = null, + + @Embedded + var timeline: Timeline? = null, + + @Embedded + var currency: Currency? = null, + + @ColumnInfo(name = "nominalAnnualInterestRate") + var nominalAnnualInterestRate: Double? = null, + + @ColumnInfo(name = "interestCompoundingPeriodType") + var interestCompoundingPeriodType: InterestCompoundingPeriodType? = null, + + @ColumnInfo(name = "interestPostingPeriodType") + var interestPostingPeriodType: InterestPostingPeriodType? = null, + + @ColumnInfo(name = "interestCalculationType") + var interestCalculationType: InterestCalculationType? = null, + + @ColumnInfo(name = "interestCalculationDaysInYearType") + var interestCalculationDaysInYearType: InterestCalculationDaysInYearType? = null, + + @ColumnInfo(name = "minRequiredOpeningBalance") + var minRequiredOpeningBalance: Double? = null, + + @ColumnInfo(name = "lockinPeriodFrequency") + var lockinPeriodFrequency: Int? = null, + + @ColumnInfo(name = "lockinPeriodFrequencyType") + var lockinPeriodFrequencyType: LockinPeriodFrequencyType? = null, + + @ColumnInfo(name = "withdrawalFeeForTransfers") + var withdrawalFeeForTransfers: Boolean? = null, + + @ColumnInfo(name = "allowOverdraft") + var allowOverdraft: Boolean? = null, + + @ColumnInfo(name = "enforceMinRequiredBalance") + var enforceMinRequiredBalance: Boolean? = null, + + @ColumnInfo(name = "withHoldTax") + var withHoldTax: Boolean? = null, + + @ColumnInfo(name = "lastActiveTransactionDate") + var lastActiveTransactionDate: List = ArrayList(), + + @ColumnInfo(name = "dormancyTrackingActive") + var dormancyTrackingActive: Boolean? = null, + + @ColumnInfo(name = "overdraftLimit") + var overdraftLimit: Int? = null, + + @ColumnInfo(name = "summary", index = true) + var summary: Summary? = null, + + @ColumnInfo(name = "transactions") + var transactions: List = ArrayList(), + + @ColumnInfo(name = "charges") + var charges: List = ArrayList(), +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsTransactionDate.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsTransactionDate.kt new file mode 100644 index 00000000000..693b256ffa5 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/SavingsTransactionDate.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.savings + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "SavingsTransactionDate") +data class SavingsTransactionDate( + @PrimaryKey + var transactionId: Int? = null, + + @ColumnInfo("year") + var year: Int? = null, + + @ColumnInfo("month") + var month: Int? = null, + + @ColumnInfo("day") + var day: Int? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/savings/Status.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/Status.kt new file mode 100644 index 00000000000..8a952db559c --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/Status.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.savings + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "SavingsAccountStatus") +data class Status( + @PrimaryKey + var id: Int? = null, + + @ColumnInfo(name = "code") + var code: String? = null, + + @ColumnInfo(name = "value") + var value: String? = null, + + @ColumnInfo(name = "submittedAndPendingApproval") + var submittedAndPendingApproval: Boolean? = null, + + @ColumnInfo(name = "approved") + var approved: Boolean? = null, + + @ColumnInfo(name = "rejected") + var rejected: Boolean? = null, + + @ColumnInfo(name = "withdrawnByApplicant") + var withdrawnByApplicant: Boolean? = null, + + @ColumnInfo(name = "active") + var active: Boolean? = null, + + @ColumnInfo(name = "closed") + var closed: Boolean? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/savings/Summary.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/Summary.kt new file mode 100644 index 00000000000..a0fe83ba907 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/Summary.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.savings + +import androidx.room.ColumnInfo +import androidx.room.Embedded +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.serialization.Transient + +@Entity(tableName = "SavingsAccountSummary") +// @TypeConverters(CurrencyTypeConverter::class) +data class Summary( + @PrimaryKey + @Transient + var savingsId: Int? = null, + + @Embedded + var currency: Currency? = null, + + @ColumnInfo(name = "totalDeposits") + var totalDeposits: Double? = null, + + @ColumnInfo(name = "accountBalance") + var accountBalance: Double? = null, + + @ColumnInfo(name = "totalWithdrawals") + var totalWithdrawals: Double? = null, + + @ColumnInfo(name = "totalInterestEarned") + var totalInterestEarned: Double? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/savings/Transaction.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/Transaction.kt new file mode 100644 index 00000000000..35d9e366de6 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/Transaction.kt @@ -0,0 +1,75 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.savings + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.PrimaryKey + +@Entity( + tableName = "Transaction", + foreignKeys = [ + ForeignKey( + entity = TransactionType::class, + parentColumns = ["id"], + childColumns = ["transactionType"], + onDelete = ForeignKey.CASCADE, + ), + ForeignKey( + entity = SavingsTransactionDate::class, + parentColumns = ["transactionId"], + childColumns = ["savingsTransactionDate"], + onDelete = ForeignKey.CASCADE, + ), + ForeignKey( + entity = Currency::class, + parentColumns = ["code"], + childColumns = ["currency"], + onDelete = ForeignKey.CASCADE, + ), + ], +) +// @TypeConverters(NullableIntegerListConverter::class, CurrencyTypeConverter::class) +data class Transaction( + @PrimaryKey + var id: Int? = null, + + @ColumnInfo(name = "savingsAccountId") + var savingsAccountId: Int? = null, + + @ColumnInfo(name = "transactionType", index = true) + var transactionType: TransactionType? = null, + + @ColumnInfo(name = "accountId") + var accountId: Int? = null, + + @ColumnInfo(name = "accountNo") + var accountNo: String? = null, + + @ColumnInfo(name = "savingsTransactionDate") + @Transient + var savingsTransactionDate: SavingsTransactionDate? = null, + + @ColumnInfo(name = "date") + var date: List = ArrayList(), + + @ColumnInfo(name = "currency", index = true) + var currency: Currency? = null, + + @ColumnInfo(name = "amount") + var amount: Double? = null, + + @ColumnInfo(name = "runningBalance") + var runningBalance: Double? = null, + + @ColumnInfo(name = "reversed") + var reversed: Boolean? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/accounts/savings/TransactionType.kt b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/TransactionType.kt new file mode 100644 index 00000000000..09b342d794d --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/accounts/savings/TransactionType.kt @@ -0,0 +1,59 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.accounts.savings + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "TransactionType") +data class TransactionType( + @PrimaryKey + var id: Int? = null, + + @ColumnInfo(name = "code") + var code: String? = null, + + @ColumnInfo(name = "value") + var value: String? = null, + + @ColumnInfo(name = "deposit") + var deposit: Boolean? = null, + + @ColumnInfo(name = "withdrawal") + var withdrawal: Boolean? = null, + + @ColumnInfo(name = "interestPosting") + var interestPosting: Boolean? = null, + + @ColumnInfo(name = "feeDeduction") + var feeDeduction: Boolean? = null, + + @ColumnInfo(name = "initiateTransfer") + var initiateTransfer: Boolean? = null, + + @ColumnInfo(name = "approveTransfer") + var approveTransfer: Boolean? = null, + + @ColumnInfo(name = "withdrawTransfer") + var withdrawTransfer: Boolean? = null, + + @ColumnInfo(name = "rejectTransfer") + var rejectTransfer: Boolean? = null, + + @ColumnInfo(name = "overdraftInterest") + var overdraftInterest: Boolean? = null, + + @ColumnInfo(name = "writtenoff") + var writtenoff: Boolean? = null, + + @ColumnInfo(name = "overdraftFee") + var overdraftFee: Boolean? = null, +) diff --git a/core/database/src/main/java/com/mifos/room/entities/center/CenterPayload.kt b/core/database/src/main/java/com/mifos/room/entities/center/CenterPayload.kt new file mode 100644 index 00000000000..42880410cbc --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/center/CenterPayload.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.center + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "CenterPayload") +data class CenterPayload( + @PrimaryKey(autoGenerate = true) + @Transient + var id: Int = 0, + + @ColumnInfo(name = "errorMessage") + @Transient + var errorMessage: String? = null, + + @ColumnInfo(name = "dateFormat") + var dateFormat: String? = null, + + @ColumnInfo(name = "locale") + var locale: String? = null, + + @ColumnInfo(name = "name") + var name: String? = null, + + @ColumnInfo(name = "officeId") + var officeId: Int? = null, + + @ColumnInfo(name = "active") + var active: Boolean = false, + + @ColumnInfo(name = "activationDate") + var activationDate: String? = null, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/client/ChargeCalculationType.kt b/core/database/src/main/java/com/mifos/room/entities/client/ChargeCalculationType.kt new file mode 100644 index 00000000000..cfeedff91af --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/client/ChargeCalculationType.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.client + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "ChargeCalculationType") +data class ChargeCalculationType( + @JvmField + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int? = null, + + @ColumnInfo(name = "code") + @JvmField + var code: String? = null, + + @ColumnInfo(name = "value") + @JvmField + var value: String? = null, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/client/ChargeTimeType.kt b/core/database/src/main/java/com/mifos/room/entities/client/ChargeTimeType.kt new file mode 100644 index 00000000000..114a1e91f42 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/client/ChargeTimeType.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.client + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity +data class ChargeTimeType( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int? = null, + + @ColumnInfo(name = "code") + var code: String? = null, + + @ColumnInfo(name = "value") + var value: String? = null, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/client/Charges.kt b/core/database/src/main/java/com/mifos/room/entities/client/Charges.kt new file mode 100644 index 00000000000..bfd576f8eb3 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/client/Charges.kt @@ -0,0 +1,134 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.client + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize +import kotlinx.serialization.json.Json + +/** + * Created by nellyk on 2/15/2016. + */ +/* + * This project is licensed under the open source MPL V2. + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +@Parcelize +@Entity( + tableName = "Charges", + foreignKeys = [ + ForeignKey( + entity = ChargeTimeType::class, + parentColumns = ["id"], + childColumns = ["chargeTimeType"], + onDelete = ForeignKey.CASCADE, + ), + ForeignKey( + entity = ClientDate::class, + parentColumns = ["clientId"], + childColumns = ["chargeDueDate"], + onDelete = ForeignKey.CASCADE, + ), + ForeignKey( + entity = ChargeCalculationType::class, + parentColumns = ["id"], + childColumns = ["chargeCalculationType"], + onDelete = ForeignKey.CASCADE, + ), + ForeignKey( + entity = Currency::class, + parentColumns = ["code"], + childColumns = ["currency"], + onDelete = ForeignKey.CASCADE, + ), + ], +) +data class Charges( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int? = null, + + @ColumnInfo(name = "clientId") + var clientId: Int? = null, + + @ColumnInfo(name = "loanId") + var loanId: Int? = null, + + @ColumnInfo(name = "chargeId") + var chargeId: Int? = null, + + @ColumnInfo(name = "name") + var name: String? = null, + + @ColumnInfo(name = "chargeTimeType") + var chargeTimeType: ChargeTimeType? = null, + + @ColumnInfo(name = "chargeDueDateId") + var chargeDueDate: ClientDate? = null, + + @ColumnInfo(name = "dueDate") + var dueDate: String? = null, + + @ColumnInfo(name = "chargeCalculationType") + var chargeCalculationType: ChargeCalculationType? = null, + + @ColumnInfo(name = "currency") + var currency: Currency? = null, + + @ColumnInfo(name = "amount") + var amount: Double? = null, + + @ColumnInfo(name = "amountPaid") + var amountPaid: Double? = null, + + @ColumnInfo(name = "amountWaived") + var amountWaived: Double? = null, + + @ColumnInfo(name = "amountWrittenOff") + var amountWrittenOff: Double? = null, + + @ColumnInfo(name = "amountOutstanding") + var amountOutstanding: Double? = null, + + @ColumnInfo(name = "penalty") + var penalty: Boolean? = null, + + @ColumnInfo(name = "active") + var active: Boolean? = null, + + @ColumnInfo(name = "paid") + var paid: Boolean? = null, + + @ColumnInfo(name = "waived") + var waived: Boolean? = null, +) : Parcelable { + + val formattedDueDate: String + get() { + val pattern = "%s-%s-%s" + + val dueDateList = try { + dueDate?.let { Json.decodeFromString>(it) } + } catch (e: kotlinx.serialization.SerializationException) { + emptyList() + } + + if (dueDateList != null) { + if (dueDateList.size > 2) { + return String.format(pattern, dueDateList[0], dueDateList[1], dueDateList[2]) + } + } + return "No Due Date" + } +} diff --git a/core/database/src/main/java/com/mifos/room/entities/client/Client.kt b/core/database/src/main/java/com/mifos/room/entities/client/Client.kt new file mode 100644 index 00000000000..91e9607ce70 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/client/Client.kt @@ -0,0 +1,128 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.client + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.PrimaryKey +import com.mifos.core.entity.group.Group +import com.mifos.room.entities.Timeline +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity( + tableName = "Client", + foreignKeys = [ + ForeignKey( + entity = Status::class, + parentColumns = ["id"], + childColumns = ["status"], + onDelete = ForeignKey.CASCADE, + ), + ForeignKey( + entity = ClientDate::class, + parentColumns = ["clientId"], + childColumns = ["clientDate"], + onDelete = ForeignKey.CASCADE, + ), + ], +) +data class Client( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int = 0, + + @ColumnInfo(name = "groupId") + @Transient + var groupId: Int? = 0, + + @ColumnInfo(name = "accountNo") + var accountNo: String? = null, + + @ColumnInfo(name = "clientId") + var clientId: Int? = null, + + @ColumnInfo(name = "status") + var status: Status? = null, + + @ColumnInfo(name = "sync") + @Transient + var sync: Boolean = false, + + @ColumnInfo(name = "active") + var active: Boolean = false, + + @ColumnInfo(name = "clientDate") + var clientDate: ClientDate? = null, + + @ColumnInfo(name = "activationDate") + var activationDate: List = ArrayList(), + + @ColumnInfo(name = "dobDate") + var dobDate: List = ArrayList(), + + @ColumnInfo(name = "groups") + var groups: List = ArrayList(), + + @ColumnInfo(name = "mobileNo") + var mobileNo: String? = null, + + @ColumnInfo(name = "firstname") + var firstname: String? = null, + + @ColumnInfo(name = "middlename") + var middlename: String? = null, + + @ColumnInfo(name = "lastname") + var lastname: String? = null, + + @ColumnInfo(name = "displayName") + var displayName: String? = null, + + @ColumnInfo(name = "officeId") + var officeId: Int = 0, + + @ColumnInfo(name = "officeName") + var officeName: String? = null, + + @ColumnInfo(name = "staffId") + var staffId: Int = 0, + + @ColumnInfo(name = "staffName") + var staffName: String? = null, + + @ColumnInfo(name = "timeline") + var timeline: Timeline? = null, + + @ColumnInfo(name = "fullname") + var fullname: String? = null, + + @ColumnInfo(name = "imageId") + var imageId: Int = 0, + + @ColumnInfo(name = "imagePresent") + var imagePresent: Boolean = false, + + @ColumnInfo(name = "externalId") + var externalId: String? = null, +) : Parcelable { + + val groupNames: String + get() { + var groupNames = "" + if (groups.isEmpty()) return "" + for (group in groups) { + groupNames += group!!.name + ", " + } + return groupNames.substring(0, groupNames.length - 2) + } +} diff --git a/core/database/src/main/java/com/mifos/room/entities/client/ClientDate.kt b/core/database/src/main/java/com/mifos/room/entities/client/ClientDate.kt new file mode 100644 index 00000000000..2985ae97516 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/client/ClientDate.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.client + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity( + tableName = "ClientDate", + primaryKeys = ["clientId", "chargeId"], +) +data class ClientDate( + @ColumnInfo(name = "clientId") + var clientId: Long = 0, + + @ColumnInfo(name = "chargeId") + var chargeId: Long = 0, + + @ColumnInfo(name = "day") + var day: Int = 0, + + @ColumnInfo(name = "month") + var month: Int = 0, + + @ColumnInfo(name = "year") + var year: Int = 0, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/client/ClientPayload.kt b/core/database/src/main/java/com/mifos/room/entities/client/ClientPayload.kt new file mode 100644 index 00000000000..1ac74db066d --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/client/ClientPayload.kt @@ -0,0 +1,86 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.client + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "ClientPayload") +data class ClientPayload( + @PrimaryKey(autoGenerate = true) + @ColumnInfo(name = "id") + var id: Int? = null, + + @ColumnInfo(name = "clientCreationTime") + @Transient + var clientCreationTime: Long? = null, + + @ColumnInfo(name = "errorMessage") + @Transient + var errorMessage: String? = null, + + @ColumnInfo(name = "firstname") + var firstname: String? = null, + + @ColumnInfo(name = "lastname") + var lastname: String? = null, + + @ColumnInfo(name = "middlename") + var middlename: String? = null, + + @ColumnInfo(name = "officeId") + var officeId: Int? = null, + + @ColumnInfo(name = "staffId") + var staffId: Int? = null, + + @ColumnInfo(name = "genderId") + var genderId: Int? = null, + + @ColumnInfo(name = "active") + var active: Boolean? = null, + + @ColumnInfo(name = "activationDate") + var activationDate: String? = null, + + @ColumnInfo(name = "submittedOnDate") + var submittedOnDate: String? = null, + + @ColumnInfo(name = "dateOfBirth") + var dateOfBirth: String? = null, + + @ColumnInfo(name = "mobileNo") + var mobileNo: String? = null, + + @ColumnInfo(name = "externalId") + var externalId: String? = null, + + @ColumnInfo(name = "clientTypeId") + var clientTypeId: Int? = null, + + @ColumnInfo(name = "clientClassificationId") + var clientClassificationId: Int? = null, + + @ColumnInfo(name = "address") + var address: String? = null, + + @ColumnInfo(name = "dateFormat") + var dateFormat: String? = "dd MMMM YYYY", + + @ColumnInfo(name = "locale") + var locale: String? = "en", + + @ColumnInfo(name = "datatables") + var datatables: String? = null, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/client/Currency.kt b/core/database/src/main/java/com/mifos/room/entities/client/Currency.kt new file mode 100644 index 00000000000..6778c951d91 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/client/Currency.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.client + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "ClientChargeCurrency") +data class Currency( + @PrimaryKey + @ColumnInfo(name = "code") + var code: String? = null, + + @ColumnInfo(name = "name") + var name: String? = null, + + @ColumnInfo(name = "decimalPlaces") + var decimalPlaces: Int? = null, + + @ColumnInfo(name = "inMultiplesOf") + var inMultiplesOf: Int? = null, + + @ColumnInfo(name = "displaySymbol") + var displaySymbol: String? = null, + + @ColumnInfo(name = "nameCode") + var nameCode: String? = null, + + @ColumnInfo(name = "displayLabel") + var displayLabel: String? = null, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/client/Status.kt b/core/database/src/main/java/com/mifos/room/entities/client/Status.kt new file mode 100644 index 00000000000..0da6cc23185 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/client/Status.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.client + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "Status") +data class Status( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int = 0, + + @ColumnInfo(name = "code") + var code: String? = null, + + @ColumnInfo(name = "value") + var value: String? = null, +) : Parcelable { + + companion object { + const val STATUS_ACTIVE = "Active" + + fun isActive(value: String): Boolean { + return value == STATUS_ACTIVE + } + } +} diff --git a/core/database/src/main/java/com/mifos/room/entities/group/Center.kt b/core/database/src/main/java/com/mifos/room/entities/group/Center.kt new file mode 100644 index 00000000000..b66afc76897 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/group/Center.kt @@ -0,0 +1,80 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.group + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.PrimaryKey +import com.mifos.room.entities.client.Status +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity( + tableName = "Center", + foreignKeys = [ + ForeignKey( + entity = CenterDate::class, + parentColumns = ["centerId"], + childColumns = ["centerDate"], + onDelete = ForeignKey.CASCADE, + ), + ], +) +data class Center( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int? = null, + + @ColumnInfo(name = "sync") + @Transient + var sync: Boolean = false, + + @ColumnInfo(name = "accountNo") + var accountNo: String? = null, + + @ColumnInfo(name = "name") + var name: String? = null, + + @ColumnInfo(name = "officeId") + var officeId: Int? = null, + + @ColumnInfo(name = "officeName") + var officeName: String? = null, + + @ColumnInfo(name = "staffId") + var staffId: Int? = null, + + @ColumnInfo(name = "staffName") + var staffName: String? = null, + + @ColumnInfo(name = "hierarchy") + var hierarchy: String? = null, + + @ColumnInfo(name = "status") + var status: Status? = null, + + @ColumnInfo(name = "active") + var active: Boolean? = null, + + @ColumnInfo(name = "centerDate") + @Transient + var centerDate: CenterDate? = null, + + @ColumnInfo(name = "activationDate") + var activationDate: String? = null, + + @ColumnInfo(name = "timeline") + var timeline: String? = null, + + @ColumnInfo(name = "externalId") + var externalId: String? = null, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/group/CenterDate.kt b/core/database/src/main/java/com/mifos/room/entities/group/CenterDate.kt new file mode 100644 index 00000000000..b74cb4b31ba --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/group/CenterDate.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.group + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity( + tableName = "CenterDate", + primaryKeys = ["centerId", "chargeId"], +) +data class CenterDate( + @ColumnInfo(name = "centerId") + var centerId: Long = 0, + + @ColumnInfo(name = "chargeId") + var chargeId: Long = 0, + + @ColumnInfo(name = "day") + var day: Int = 0, + + @ColumnInfo(name = "month") + var month: Int = 0, + + @ColumnInfo(name = "year") + var year: Int = 0, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/group/Group.kt b/core/database/src/main/java/com/mifos/room/entities/group/Group.kt new file mode 100644 index 00000000000..0ac0729e30e --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/group/Group.kt @@ -0,0 +1,90 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.group + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.PrimaryKey +import com.mifos.room.entities.Timeline +import com.mifos.room.entities.client.Status +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity( + tableName = "Group", + foreignKeys = [ + ForeignKey( + entity = GroupDate::class, + parentColumns = ["groupId"], + childColumns = ["groupDate"], + onDelete = ForeignKey.CASCADE, + ), + ], +) +data class Group( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int? = null, + + @ColumnInfo(name = "accountNo") + var accountNo: String? = null, + + @ColumnInfo(name = "sync") + @Transient + var sync: Boolean = false, + + @ColumnInfo(name = "name") + var name: String? = null, + + @ColumnInfo(name = "status") + var status: Status? = null, + + @ColumnInfo(name = "active") + var active: Boolean? = null, + + @ColumnInfo(name = "groupDate") + @Transient + var groupDate: GroupDate? = null, + + @ColumnInfo(name = "activationDate") + var activationDate: List = ArrayList(), + + @ColumnInfo(name = "officeId") + var officeId: Int? = null, + + @ColumnInfo(name = "officeName") + var officeName: String? = null, + + @ColumnInfo(name = "centerId") + var centerId: Int? = 0, + + @ColumnInfo(name = "centerName") + var centerName: String? = null, + + @ColumnInfo(name = "staffId") + var staffId: Int? = null, + + @ColumnInfo(name = "staffName") + var staffName: String? = null, + + @ColumnInfo(name = "hierarchy") + var hierarchy: String? = null, + + @ColumnInfo(name = "groupLevel") + var groupLevel: Int = 0, + + @ColumnInfo(name = "timeline") + var timeline: Timeline? = null, + + @ColumnInfo(name = "externalId") + var externalId: String? = null, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/group/GroupDate.kt b/core/database/src/main/java/com/mifos/room/entities/group/GroupDate.kt new file mode 100644 index 00000000000..7d3b9498fde --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/group/GroupDate.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.group + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity( + tableName = "GroupDate", + primaryKeys = ["groupId", "chargeId"], +) +data class GroupDate( + @ColumnInfo(name = "groupId") + var groupId: Long = 0, + + @ColumnInfo(name = "chargeId") + var chargeId: Long = 0, + + @ColumnInfo(name = "day") + var day: Int = 0, + + @ColumnInfo(name = "month") + var month: Int = 0, + + @ColumnInfo(name = "year") + var year: Int = 0, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/group/GroupPayload.kt b/core/database/src/main/java/com/mifos/room/entities/group/GroupPayload.kt new file mode 100644 index 00000000000..638313b1848 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/group/GroupPayload.kt @@ -0,0 +1,53 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.group + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "GroupPayload") +data class GroupPayload( + @PrimaryKey(autoGenerate = true) + @ColumnInfo(name = "id") + @Transient + var id: Int = 0, + + @ColumnInfo(name = "errorMessage") + @Transient + var errorMessage: String? = null, + + @ColumnInfo(name = "officeId") + var officeId: Int = 0, + + @ColumnInfo(name = "active") + var active: Boolean = false, + + @ColumnInfo(name = "activationDate") + var activationDate: String? = null, + + @ColumnInfo(name = "submittedOnDate") + var submittedOnDate: String? = null, + + @ColumnInfo(name = "externalId") + var externalId: String? = null, + + @ColumnInfo(name = "name") + var name: String? = null, + + @ColumnInfo(name = "locale") + var locale: String? = null, + + @ColumnInfo(name = "dateFormat") + var dateFormat: String? = null, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/noncore/ColumnHeader.kt b/core/database/src/main/java/com/mifos/room/entities/noncore/ColumnHeader.kt new file mode 100644 index 00000000000..6cb425271bd --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/noncore/ColumnHeader.kt @@ -0,0 +1,52 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.noncore + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.mifos.core.entity.noncore.ColumnValue +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "ColumnHeader") +data class ColumnHeader( + @PrimaryKey(autoGenerate = true) + @ColumnInfo(name = "id") + var id: Int? = null, + + @ColumnInfo(name = "columnCode") + var columnCode: String? = null, + + @ColumnInfo(name = "columnDisplayType") + var columnDisplayType: String? = null, + + @ColumnInfo(name = "columnLength") + var columnLength: Int? = null, + + @ColumnInfo(name = "dataTableColumnName") + var dataTableColumnName: String? = null, + + @ColumnInfo(name = "columnType") + var columnType: String? = null, + + @ColumnInfo(name = "columnNullable") + var columnNullable: Boolean? = null, + + @ColumnInfo(name = "columnPrimaryKey") + var columnPrimaryKey: Boolean? = null, + + @ColumnInfo(name = "registeredTableName") + var registeredTableName: String? = null, + + @ColumnInfo(name = "columnValues") + var columnValues: List = ArrayList(), +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/noncore/DataTable.kt b/core/database/src/main/java/com/mifos/room/entities/noncore/DataTable.kt new file mode 100644 index 00000000000..24676aa9628 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/noncore/DataTable.kt @@ -0,0 +1,31 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.noncore + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.mifos.core.entity.noncore.ColumnHeader +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity("DataTable") +data class DataTable( + @ColumnInfo("applicationTableName") + var applicationTableName: String? = null, + + @ColumnInfo("columnHeaderData") + var columnHeaderData: List = ArrayList(), + + @PrimaryKey + @ColumnInfo("registeredTableName") + var registeredTableName: String? = null, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/noncore/DataTablePayload.kt b/core/database/src/main/java/com/mifos/room/entities/noncore/DataTablePayload.kt new file mode 100644 index 00000000000..fa85a1640e8 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/noncore/DataTablePayload.kt @@ -0,0 +1,41 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.noncore + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize +import kotlinx.parcelize.RawValue + +@Parcelize +@Entity(tableName = "DataTablePayload") +data class DataTablePayload( + + @PrimaryKey(autoGenerate = true) + @Transient + @ColumnInfo(name = "id") + var id: Int? = null, + + @ColumnInfo(name = "clientCreationTime") + @Transient + var clientCreationTime: Long? = null, + + @ColumnInfo(name = "dataTableString") + @Transient + var dataTableString: String? = null, + + @ColumnInfo(name = "registeredTableName") + var registeredTableName: String? = null, + + @ColumnInfo(name = "data") + var data: HashMap? = null, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/noncore/Note.kt b/core/database/src/main/java/com/mifos/room/entities/noncore/Note.kt new file mode 100644 index 00000000000..6b04a19eee4 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/noncore/Note.kt @@ -0,0 +1,48 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.noncore + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "Note") +data class Note( + @PrimaryKey(autoGenerate = true) + @ColumnInfo(name = "id") + var id: Int? = null, + + @ColumnInfo(name = "clientId") + var clientId: Int? = null, + + @ColumnInfo(name = "noteContent") + var noteContent: String? = null, + + @ColumnInfo(name = "createdById") + var createdById: Int? = null, + + @ColumnInfo(name = "createdByUsername") + var createdByUsername: String? = null, + + @ColumnInfo(name = "createdOn") + var createdOn: Long = 0, + + @ColumnInfo(name = "updatedById") + var updatedById: Int? = null, + + @ColumnInfo(name = "updatedByUsername") + var updatedByUsername: String? = null, + + @ColumnInfo(name = "updatedOn") + var updatedOn: Long = 0, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/organisation/Office.kt b/core/database/src/main/java/com/mifos/room/entities/organisation/Office.kt new file mode 100644 index 00000000000..1b13a63b22d --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/organisation/Office.kt @@ -0,0 +1,50 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.organisation + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.ForeignKey +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity( + tableName = "Office", + foreignKeys = [ + ForeignKey( + entity = OfficeOpeningDate::class, + parentColumns = ["officeId"], + childColumns = ["officeOpeningDate"], + onDelete = ForeignKey.CASCADE, + ), + ], +) +data class Office( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int? = null, + + @ColumnInfo(name = "externalId") + var externalId: String? = null, + + @ColumnInfo(name = "name") + var name: String? = null, + + @ColumnInfo(name = "nameDecorated") + var nameDecorated: String? = null, + + @ColumnInfo(name = "officeOpeningDate") + var officeOpeningDate: Int? = null, + + @ColumnInfo(name = "openingDate") + var openingDate: List = ArrayList(), +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/organisation/OfficeOpeningDate.kt b/core/database/src/main/java/com/mifos/room/entities/organisation/OfficeOpeningDate.kt new file mode 100644 index 00000000000..562d0efe603 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/organisation/OfficeOpeningDate.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.organisation + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "OfficeOpeningDate") +data class OfficeOpeningDate( + @PrimaryKey + @ColumnInfo(name = "officeId") + var officeId: Int? = null, + + @ColumnInfo(name = "year") + var year: Int? = null, + + @ColumnInfo(name = "month") + var month: Int? = null, + + @ColumnInfo(name = "day") + var day: Int? = null, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/organisation/Staff.kt b/core/database/src/main/java/com/mifos/room/entities/organisation/Staff.kt new file mode 100644 index 00000000000..b30af01f058 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/organisation/Staff.kt @@ -0,0 +1,48 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.organisation + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "Staff") +data class Staff( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int? = null, + + @ColumnInfo(name = "firstname") + var firstname: String? = null, + + @ColumnInfo(name = "lastname") + var lastname: String? = null, + + @ColumnInfo(name = "mobileNo") + var mobileNo: String? = null, + + @ColumnInfo(name = "displayName") + var displayName: String? = null, + + @ColumnInfo(name = "officeId") + var officeId: Int? = null, + + @ColumnInfo(name = "officeName") + var officeName: String? = null, + + @ColumnInfo(name = "isLoanOfficer") + var isLoanOfficer: Boolean? = null, + + @ColumnInfo(name = "isActive") + var isActive: Boolean? = null, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/survey/ComponentDatas.kt b/core/database/src/main/java/com/mifos/room/entities/survey/ComponentDatas.kt new file mode 100644 index 00000000000..15518921941 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/survey/ComponentDatas.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.survey + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "ComponentDatas") +data class ComponentDatas( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int? = null, + + @ColumnInfo(name = "key") + var key: String? = null, + + @ColumnInfo(name = "text") + var text: String? = null, + + @ColumnInfo(name = "description") + var description: String? = null, + + @ColumnInfo(name = "sequenceNo") + var sequenceNo: Int = 0, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/survey/QuestionDatas.kt b/core/database/src/main/java/com/mifos/room/entities/survey/QuestionDatas.kt new file mode 100644 index 00000000000..0221e7018c0 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/survey/QuestionDatas.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.survey + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.mifos.core.entity.survey.ResponseDatas +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "QuestionDatas") +data class QuestionDatas( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int = 0, + + @ColumnInfo(name = "surveyId") + @Transient + var surveyId: Int = 0, + + @ColumnInfo(name = "componentKey") + var componentKey: String? = null, + + @ColumnInfo(name = "key") + var key: String? = null, + + @ColumnInfo(name = "text") + var text: String? = null, + + @ColumnInfo(name = "description") + var description: String? = null, + + @ColumnInfo(name = "sequenceNo") + var sequenceNo: Int = 0, + + @ColumnInfo(name = "responseDatas") + var responseDatas: List = ArrayList(), +) : Parcelable { + + var questionId: Int + get() = id + set(id) { + this.id = id + } +} diff --git a/core/database/src/main/java/com/mifos/room/entities/survey/ResponseDatas.kt b/core/database/src/main/java/com/mifos/room/entities/survey/ResponseDatas.kt new file mode 100644 index 00000000000..4c64b3a95cd --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/survey/ResponseDatas.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.survey + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "ResponseDatas") +data class ResponseDatas( + @PrimaryKey + @ColumnInfo(name = "responseId") + var responseId: Int = 0, + + @ColumnInfo(name = "questionId") + @Transient + var questionId: Int = 0, + + @ColumnInfo(name = "text") + var text: String? = null, + + @ColumnInfo(name = "sequenceNo") + var sequenceNo: Int = 0, + + @ColumnInfo(name = "value") + var value: Int = 0, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/survey/Survey.kt b/core/database/src/main/java/com/mifos/room/entities/survey/Survey.kt new file mode 100644 index 00000000000..b1e40d93d39 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/survey/Survey.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.survey + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "Survey") +data class Survey( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int = 0, + + @ColumnInfo(name = "key") + var key: String? = null, + + @ColumnInfo(name = "name") + var name: String? = null, + + @ColumnInfo(name = "description") + var description: String? = null, + + @ColumnInfo(name = "isSync") + @Transient + var isSync: Boolean = false, + + @ColumnInfo(name = "countryCode") + var countryCode: String? = null, + + @ColumnInfo(name = "questionDatas") + var questionDatas: List = ArrayList(), + + @ColumnInfo(name = "componentDatas") + var componentDatas: List = ArrayList(), +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/templates/clients/ClientsTemplate.kt b/core/database/src/main/java/com/mifos/room/entities/templates/clients/ClientsTemplate.kt new file mode 100644 index 00000000000..45d520ebbe9 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/templates/clients/ClientsTemplate.kt @@ -0,0 +1,67 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.templates.clients + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.mifos.room.entities.noncore.DataTable +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "ClientsTemplate") +data class ClientsTemplate( + @ColumnInfo(name = "activationDate") + var activationDate: IntArray = intArrayOf(), + + @PrimaryKey + @ColumnInfo(name = "officeId") + var officeId: Int = 0, + + @ColumnInfo(name = "officeOptions") + var officeOptions: List = ArrayList(), + + @ColumnInfo(name = "staffOptions") + var staffOptions: List = ArrayList(), + + @ColumnInfo(name = "savingProductOptions") + var savingProductOptions: List = ArrayList(), + + @ColumnInfo(name = "genderOptions") + var genderOptions: List = ArrayList(), + + @ColumnInfo(name = "clientTypeOptions") + var clientTypeOptions: List = ArrayList(), + + @ColumnInfo(name = "clientClassificationOptions") + var clientClassificationOptions: List = ArrayList(), + + @ColumnInfo(name = "clientLegalFormOptions") + var clientLegalFormOptions: List = ArrayList(), + + @ColumnInfo(name = "dataTables") + var dataTables: List = ArrayList(), +) : Parcelable { + + override fun toString(): String { + return "ClientsTemplate{" + + "activationDate=" + activationDate.contentToString() + + ", officeId=" + officeId + + ", officeOptions=" + officeOptions + + ", staffOptions=" + staffOptions + + ", savingProductOptions=" + savingProductOptions + + ", genderOptions=" + genderOptions + + ", clientTypeOptions=" + clientTypeOptions + + ", clientClassificationOptions=" + clientClassificationOptions + + ", clientLegalFormOptions=" + clientLegalFormOptions + + '}' + } +} diff --git a/core/database/src/main/java/com/mifos/room/entities/templates/clients/InterestType.kt b/core/database/src/main/java/com/mifos/room/entities/templates/clients/InterestType.kt new file mode 100644 index 00000000000..44ef94d7d8f --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/templates/clients/InterestType.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.templates.clients + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "ClientTemplateInterest") +data class InterestType( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int = 0, + + @ColumnInfo(name = "code") + var code: String = "", + + @ColumnInfo(name = "value") + var value: String = "", +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/templates/clients/OfficeOptions.kt b/core/database/src/main/java/com/mifos/room/entities/templates/clients/OfficeOptions.kt new file mode 100644 index 00000000000..941f710d58e --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/templates/clients/OfficeOptions.kt @@ -0,0 +1,35 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.templates.clients + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "ClientTemplateOfficeOptions") +data class OfficeOptions( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int = 0, + + @ColumnInfo(name = "name") + val name: String = "", + + @ColumnInfo(name = "nameDecorated") + val nameDecorated: String = "", +) : Parcelable { + + override fun toString(): String { + return "OfficeOptions{id=$id, name='$name', nameDecorated='$nameDecorated'}" + } +} diff --git a/core/database/src/main/java/com/mifos/room/entities/templates/clients/Options.kt b/core/database/src/main/java/com/mifos/room/entities/templates/clients/Options.kt new file mode 100644 index 00000000000..0218a985fec --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/templates/clients/Options.kt @@ -0,0 +1,82 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.templates.clients + +import android.os.Parcel +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.google.gson.annotations.SerializedName +import kotlinx.parcelize.Parceler +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "ClientTemplateOptions") +class Options() : Parcelable { + + @ColumnInfo(name = "optionType") + var optionType: String? = null + + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int = 0 + + @ColumnInfo(name = "name") + var name: String = "" + + @ColumnInfo(name = "position") + var position: Int = 0 + + @ColumnInfo(name = "description") + var description: String? = null + + @SerializedName("isActive") + @ColumnInfo(name = "activeStatus") + var activeStatus: Boolean = false + + // Getter for activeStatus property + fun isActiveStatus(): Boolean { + return activeStatus + } + + constructor(parcel: Parcel) : this() { + id = parcel.readInt() + name = parcel.readString()!! + position = parcel.readInt() + description = parcel.readString() + activeStatus = parcel.readByte() != 0.toByte() + } + + companion object : Parceler { + + override fun Options.write(parcel: Parcel, flags: Int) { + parcel.writeInt(id) + parcel.writeString(name) + parcel.writeInt(position) + parcel.writeString(description) + parcel.writeByte(if (activeStatus) 1 else 0) + } + + override fun create(parcel: Parcel): Options { + return Options(parcel) + } + } + + override fun toString(): String { + return "Options{" + + "id=" + id + + ", name='" + name + '\'' + + ", position=" + position + + ", description='" + description + '\'' + + ", activeStatus=" + activeStatus + + '}' + } +} diff --git a/core/database/src/main/java/com/mifos/room/entities/templates/clients/SavingProductOptions.kt b/core/database/src/main/java/com/mifos/room/entities/templates/clients/SavingProductOptions.kt new file mode 100644 index 00000000000..44f7156b08c --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/templates/clients/SavingProductOptions.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.templates.clients + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "ClientTemplateSavingProductsOptions") +data class SavingProductOptions( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int = 0, + + @ColumnInfo(name = "name") + val name: String = "", + + @ColumnInfo(name = "withdrawalFeeForTransfers") + val withdrawalFeeForTransfers: Boolean = false, + + @ColumnInfo(name = "allowOverdraft") + val allowOverdraft: Boolean = false, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/templates/clients/StaffOptions.kt b/core/database/src/main/java/com/mifos/room/entities/templates/clients/StaffOptions.kt new file mode 100644 index 00000000000..a69ec7090d5 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/templates/clients/StaffOptions.kt @@ -0,0 +1,48 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.templates.clients + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.google.gson.annotations.SerializedName +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "ClientTemplateStaffOptions") +data class StaffOptions( + @PrimaryKey + @ColumnInfo(name = "id") + var id: Int = 0, + + @ColumnInfo(name = "firstname") + val firstname: String = "", + + @ColumnInfo(name = "lastname") + val lastname: String = "", + + @ColumnInfo(name = "displayName") + val displayName: String = "", + + @ColumnInfo(name = "officeId") + val officeId: Int = 0, + + @ColumnInfo(name = "officeName") + val officeName: String = "", + + @SerializedName("isLoanOfficer") + @ColumnInfo(name = "isLoanOfficer") + var isLoanOfficer: Boolean = false, + + @SerializedName("isActive") + @ColumnInfo(name = "isActive") + var isActive: Boolean = false, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/templates/loans/LoanRepaymentTemplate.kt b/core/database/src/main/java/com/mifos/room/entities/templates/loans/LoanRepaymentTemplate.kt new file mode 100644 index 00000000000..5fb57c9b083 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/templates/loans/LoanRepaymentTemplate.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.templates.loans + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.mifos.core.objects.template.loan.Currency +import com.mifos.core.objects.template.loan.Type +import com.mifos.room.entities.PaymentTypeOption +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "LoanRepaymentTemplate") +data class LoanRepaymentTemplate( + @PrimaryKey(autoGenerate = true) + @ColumnInfo(name = "loanId") + var loanId: Int? = null, + + @ColumnInfo(name = "type") + var type: Type? = null, + + @ColumnInfo(name = "date") + var date: MutableList? = null, + + @ColumnInfo(name = "currency") + var currency: Currency? = null, + + @ColumnInfo(name = "amount") + var amount: Double? = null, + + @ColumnInfo(name = "principalPortion") + var principalPortion: Double? = null, + + @ColumnInfo(name = "interestPortion") + var interestPortion: Double? = null, + + @ColumnInfo(name = "feeChargesPortion") + var feeChargesPortion: Double? = null, + + @ColumnInfo(name = "penaltyChargesPortion") + var penaltyChargesPortion: Double? = null, + + @ColumnInfo(name = "paymentTypeOptions") + var paymentTypeOptions: MutableList? = null, +) : Parcelable diff --git a/core/database/src/main/java/com/mifos/room/entities/templates/savings/SavingsAccountTransactionTemplate.kt b/core/database/src/main/java/com/mifos/room/entities/templates/savings/SavingsAccountTransactionTemplate.kt new file mode 100644 index 00000000000..22bd87dd0ca --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/entities/templates/savings/SavingsAccountTransactionTemplate.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.entities.templates.savings + +import android.os.Parcelable +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey +import com.mifos.room.entities.PaymentTypeOption +import kotlinx.parcelize.Parcelize + +@Parcelize +@Entity(tableName = "SavingsAccountTransactionTemplate") +data class SavingsAccountTransactionTemplate( + @PrimaryKey + @ColumnInfo(name = "accountId") + var accountId: Int? = null, + + @ColumnInfo(name = "accountNo") + var accountNo: String? = null, + + @ColumnInfo(name = "date") + var date: List = ArrayList(), + + @ColumnInfo(name = "reversed") + var reversed: Boolean? = null, + + @ColumnInfo(name = "paymentTypeOptions") + var paymentTypeOptions: List = ArrayList(), +) : Parcelable { + + fun isReversed(): Boolean? { + return reversed + } +} diff --git a/core/database/src/main/java/com/mifos/room/utils/typeconverters/DueDateConverter.kt b/core/database/src/main/java/com/mifos/room/utils/typeconverters/DueDateConverter.kt new file mode 100644 index 00000000000..475df707a19 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/utils/typeconverters/DueDateConverter.kt @@ -0,0 +1,26 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.utils.typeconverters + +import androidx.room.TypeConverter +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json + +class DueDateConverter { + @TypeConverter + fun fromListToString(dueDate: List): String { + return Json.encodeToString(dueDate) + } + + @TypeConverter + fun fromStringToList(dueDateString: String): List { + return Json.decodeFromString(dueDateString) + } +} diff --git a/core/database/src/main/java/com/mifos/room/utils/typeconverters/ServerTypesConverters.kt b/core/database/src/main/java/com/mifos/room/utils/typeconverters/ServerTypesConverters.kt new file mode 100644 index 00000000000..598d39ccf64 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/utils/typeconverters/ServerTypesConverters.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.utils.typeconverters + +import androidx.room.TypeConverter +import com.mifos.room.entities.accounts.savings.ServerTypes + +class ServerTypesConverters { + @TypeConverter + fun toServerTypes(id: Int?): ServerTypes? { + return id?.let { ServerTypes.fromId(it) } + } + + @TypeConverter + fun fromServerTypes(serverTypes: ServerTypes?): Int? { + return serverTypes?.id + } +} diff --git a/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt b/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt new file mode 100644 index 00000000000..ca77c5a931f --- /dev/null +++ b/core/datastore/src/main/java/com/mifos/core/datastore/PrefManager.kt @@ -0,0 +1,97 @@ +/* + * Copyright 2024 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.core.datastore + +//import android.content.Context +//import android.content.SharedPreferences +//import android.preference.PreferenceManager +//import com.mifos.core.common.BuildConfig +//import com.mifos.core.common.model.user.User +//import com.mifos.core.common.utils.Constants +//import com.mifos.core.common.utils.asServerConfig +//import com.mifos.core.model.ServerConfig +//import dagger.hilt.android.qualifiers.ApplicationContext +//import kotlinx.coroutines.flow.Flow +//import kotlinx.coroutines.flow.flow +//import org.mifos.core.sharedpreference.Key +//import org.mifos.core.sharedpreference.UserPreferences +//import org.openapitools.client.models.PostAuthenticationResponse +//import javax.inject.Inject +// +///** +// * Created by Aditya Gupta on 19/08/23. +// */ +//const val USER_DETAILS = "user_details" +//const val AUTH_USERNAME = "auth_username" +//const val AUTH_PASSWORD = "auth_password" +// +//class PrefManager @Inject constructor( +// @ApplicationContext context: Context, +//) : UserPreferences() { +// +// private val serverConfigKey = Key.Custom("SERVER_CONFIG_KEY") +// +// override val preference: SharedPreferences = +// PreferenceManager.getDefaultSharedPreferences(context) +// +// override fun getUser(): User { +// return gson.fromJson(preference.getString(USER_DETAILS, ""), User::class.java) +// } +// +// override fun saveUser(user: User) { +// preference.edit().putString(USER_DETAILS, gson.toJson(user)).apply() +// } +// +// // Created this to store userDetails +// fun savePostAuthenticationResponse(user: PostAuthenticationResponse) { +// preference.edit().putString(USER_DETAILS, gson.toJson(user)).apply() +// } +// +// fun setPermissionDeniedStatus(permissionDeniedStatus: String, status: Boolean) { +// preference.edit().putBoolean(permissionDeniedStatus, status).apply() +// } +// +// fun getPermissionDeniedStatus(permissionDeniedStatus: String): Boolean { +// return preference.getBoolean(permissionDeniedStatus, true) +// } +// +// var userStatus: Boolean +// get() = preference.getBoolean(Constants.SERVICE_STATUS, false) +// set(status) { +// preference.edit().putBoolean(Constants.SERVICE_STATUS, status).apply() +// } +// +// var usernamePassword: Pair +// get() = Pair( +// preference.getString(AUTH_USERNAME, "")!!, +// preference.getString(AUTH_PASSWORD, "")!!, +// ) +// set(value) { +// preference.edit().putString(AUTH_USERNAME, value.first).apply() +// preference.edit().putString(AUTH_PASSWORD, value.second).apply() +// } +// +// val getServerConfig: ServerConfig = +// preference.getString(serverConfigKey.value, null)?.let { +// gson.fromJson(it, ServerConfig::class.java) +// } ?: BuildConfig.DEMO_SERVER_CONFIG.asServerConfig() +// +// fun updateServerConfig(config: ServerConfig?) { +// this.put(serverConfigKey, config) +// } +// +// fun getStringValue(key: String): Flow = flow { +// emit(preference.getString(key, "")) +// } +// +// fun setStringValue(key: String, value: String) { +// preference.edit().putString(key, value).apply() +// } +//} From e7fed678b62c8a795e85c7286f8ce6b7618c3e4d Mon Sep 17 00:00:00 2001 From: kapmaurya Date: Fri, 31 Jan 2025 17:18:14 +0530 Subject: [PATCH 09/13] datastore-migration-kmpl --- .../kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt index b1014cc99a6..e70c80e6190 100644 --- a/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt +++ b/core/datastore/src/commonMain/kotlin/org.mifos.core.datastore/UserPreferencesDataSource.kt @@ -11,6 +11,7 @@ // package org.mifos.core.datastore + import com.russhwolf.settings.serialization.decodeValue import com.russhwolf.settings.serialization.decodeValueOrNull import kotlinx.coroutines.withContext From b1ed2cd580c1fb28a0160c3ceb575c453513d511 Mon Sep 17 00:00:00 2001 From: kapmaurya Date: Wed, 5 Feb 2025 20:34:40 +0530 Subject: [PATCH 10/13] datastore-migration-kmpl --- .../com.mifos.room.db.MifosDatabase/1.json | 45 ---------- core/datastore/src/commonMain/PrefManager.kt | 87 +++++++++++++++++++ 2 files changed, 87 insertions(+), 45 deletions(-) delete mode 100644 core/database/schemas/com.mifos.room.db.MifosDatabase/1.json diff --git a/core/database/schemas/com.mifos.room.db.MifosDatabase/1.json b/core/database/schemas/com.mifos.room.db.MifosDatabase/1.json deleted file mode 100644 index 0e84f2baf5e..00000000000 --- a/core/database/schemas/com.mifos.room.db.MifosDatabase/1.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "formatVersion": 1, - "database": { - "version": 1, - "identityHash": "52a9a8b64b78975c74e557a9c0411c25", - "entities": [ - { - "tableName": "ColumnValue", - "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER, `value` TEXT, `score` INTEGER, `registeredTableName` TEXT, PRIMARY KEY(`id`))", - "fields": [ - { - "fieldPath": "id", - "columnName": "id", - "affinity": "INTEGER" - }, - { - "fieldPath": "value", - "columnName": "value", - "affinity": "TEXT" - }, - { - "fieldPath": "score", - "columnName": "score", - "affinity": "INTEGER" - }, - { - "fieldPath": "registeredTableName", - "columnName": "registeredTableName", - "affinity": "TEXT" - } - ], - "primaryKey": { - "autoGenerate": false, - "columnNames": [ - "id" - ] - } - } - ], - "setupQueries": [ - "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)", - "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '52a9a8b64b78975c74e557a9c0411c25')" - ] - } -} \ No newline at end of file diff --git a/core/datastore/src/commonMain/PrefManager.kt b/core/datastore/src/commonMain/PrefManager.kt index 41a9304a4f1..95ed0031e80 100644 --- a/core/datastore/src/commonMain/PrefManager.kt +++ b/core/datastore/src/commonMain/PrefManager.kt @@ -8,3 +8,90 @@ * See https://github.com/openMF/android-client/blob/master/LICENSE.md */ package com.mifos.core.datastore + +//import android.content.Context +//import android.content.SharedPreferences +//import android.preference.PreferenceManager +//import com.mifos.core.common.BuildConfig +//import com.mifos.core.common.model.user.User +//import com.mifos.core.common.utils.Constants +//import com.mifos.core.common.utils.asServerConfig +//import com.mifos.core.model.ServerConfig +//import dagger.hilt.android.qualifiers.ApplicationContext +//import kotlinx.coroutines.flow.Flow +//import kotlinx.coroutines.flow.flow +//import org.mifos.core.sharedpreference.Key +//import org.mifos.core.sharedpreference.UserPreferences +//import org.openapitools.client.models.PostAuthenticationResponse +//import javax.inject.Inject +// +///** +// * Created by Aditya Gupta on 19/08/23. +// */ +//const val USER_DETAILS = "user_details" +//const val AUTH_USERNAME = "auth_username" +//const val AUTH_PASSWORD = "auth_password" +// +//class PrefManager @Inject constructor( +// @ApplicationContext context: Context, +//) : UserPreferences() { +// +// private val serverConfigKey = Key.Custom("SERVER_CONFIG_KEY") +// +// override val preference: SharedPreferences = +// PreferenceManager.getDefaultSharedPreferences(context) +// +// override fun getUser(): User { +// return gson.fromJson(preference.getString(USER_DETAILS, ""), User::class.java) +// } +// +// override fun saveUser(user: User) { +// preference.edit().putString(USER_DETAILS, gson.toJson(user)).apply() +// } +// +// // Created this to store userDetails +// fun savePostAuthenticationResponse(user: PostAuthenticationResponse) { +// preference.edit().putString(USER_DETAILS, gson.toJson(user)).apply() +// } +// +// fun setPermissionDeniedStatus(permissionDeniedStatus: String, status: Boolean) { +// preference.edit().putBoolean(permissionDeniedStatus, status).apply() +// } +// +// fun getPermissionDeniedStatus(permissionDeniedStatus: String): Boolean { +// return preference.getBoolean(permissionDeniedStatus, true) +// } +// +// var userStatus: Boolean +// get() = preference.getBoolean(Constants.SERVICE_STATUS, false) +// set(status) { +// preference.edit().putBoolean(Constants.SERVICE_STATUS, status).apply() +// } +// +// var usernamePassword: Pair +// get() = Pair( +// preference.getString(AUTH_USERNAME, "")!!, +// preference.getString(AUTH_PASSWORD, "")!!, +// ) +// set(value) { +// preference.edit().putString(AUTH_USERNAME, value.first).apply() +// preference.edit().putString(AUTH_PASSWORD, value.second).apply() +// } +// +// val getServerConfig: ServerConfig = +// preference.getString(serverConfigKey.value, null)?.let { +// gson.fromJson(it, ServerConfig::class.java) +// } ?: BuildConfig.DEMO_SERVER_CONFIG.asServerConfig() +// +// fun updateServerConfig(config: ServerConfig?) { +// this.put(serverConfigKey, config) +// } +// +// fun getStringValue(key: String): Flow = flow { +// emit(preference.getString(key, "")) +// } +// +// fun setStringValue(key: String, value: String) { +// preference.edit().putString(key, value).apply() +// } +//} \ No newline at end of file From 8cf47c15a0f56e91fc62ce67f81c30bfa5209037 Mon Sep 17 00:00:00 2001 From: kapmaurya Date: Wed, 5 Feb 2025 20:45:18 +0530 Subject: [PATCH 11/13] datastore-migration-kmpl --- core/datastore/build.gradle.kts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/datastore/build.gradle.kts b/core/datastore/build.gradle.kts index 8965b1842da..cb0dc91dd4a 100644 --- a/core/datastore/build.gradle.kts +++ b/core/datastore/build.gradle.kts @@ -10,7 +10,8 @@ plugins { alias(libs.plugins.mifos.kmp.library) //id(libs.plugins.kotlin.parcelize.get().pluginId) - id("kotlinx-serialization") +// id("kotlinx-serialization") + alias(libs.plugins.kotlin.serialization) } android { From c7acb3a077eb57508edd3d622421b60fa957d80d Mon Sep 17 00:00:00 2001 From: kapmaurya Date: Fri, 7 Feb 2025 15:36:00 +0530 Subject: [PATCH 12/13] datastore-migration-kmpl --- core/datastore/src/commonMain/PrefManager.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/datastore/src/commonMain/PrefManager.kt b/core/datastore/src/commonMain/PrefManager.kt index 95ed0031e80..989aff7e8af 100644 --- a/core/datastore/src/commonMain/PrefManager.kt +++ b/core/datastore/src/commonMain/PrefManager.kt @@ -87,9 +87,7 @@ package com.mifos.core.datastore // this.put(serverConfigKey, config) // } // -// fun getStringValue(key: String): Flow = flow { -// emit(preference.getString(key, "")) -// } + // // fun setStringValue(key: String, value: String) { // preference.edit().putString(key, value).apply() From 90e9a3cb2778e59da17675b3c217b171b503276e Mon Sep 17 00:00:00 2001 From: kapmaurya Date: Fri, 7 Feb 2025 15:40:41 +0530 Subject: [PATCH 13/13] datastore-migration-kmpl --- core/datastore/src/commonMain/PrefManager.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/datastore/src/commonMain/PrefManager.kt b/core/datastore/src/commonMain/PrefManager.kt index 989aff7e8af..7c1a5e0d23e 100644 --- a/core/datastore/src/commonMain/PrefManager.kt +++ b/core/datastore/src/commonMain/PrefManager.kt @@ -67,7 +67,7 @@ package com.mifos.core.datastore // set(status) { // preference.edit().putBoolean(Constants.SERVICE_STATUS, status).apply() // } -// + // var usernamePassword: Pair // get() = Pair( // preference.getString(AUTH_USERNAME, "")!!,