Skip to content

Commit 3177b8a

Browse files
committed
convert core model java class into kotilin data class
1 parent 86ddb7f commit 3177b8a

File tree

142 files changed

+2458
-7203
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+2458
-7203
lines changed

core/data/src/main/java/org/mifos/mobilewallet/core/data/fineract/entity/mapper/AccountMapper.java

-48
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.mifos.mobilewallet.core.data.fineract.entity.mapper
2+
3+
import com.mifos.mobilewallet.model.entity.accounts.savings.SavingAccount
4+
import com.mifos.mobilewallet.model.entity.client.ClientAccounts
5+
import com.mifos.mobilewallet.model.domain.Account
6+
import javax.inject.Inject
7+
8+
class AccountMapper @Inject constructor(private val currencyMapper: CurrencyMapper) {
9+
10+
fun transform(clientAccounts: ClientAccounts?): List<Account> {
11+
val accountList = mutableListOf<Account>()
12+
13+
if (clientAccounts != null && clientAccounts.savingsAccounts != null
14+
&& clientAccounts.savingsAccounts.isNotEmpty()) {
15+
16+
for (savingAccount in clientAccounts.savingsAccounts) {
17+
val account = Account().apply {
18+
name = savingAccount.productName
19+
number = savingAccount.accountNo
20+
id = savingAccount.id
21+
balance = savingAccount.accountBalance
22+
currency = currencyMapper.transform(savingAccount.currency)
23+
productId = savingAccount.productId.toLong()
24+
}
25+
26+
accountList.add(account)
27+
}
28+
}
29+
return accountList
30+
}
31+
}

core/data/src/main/java/org/mifos/mobilewallet/core/data/fineract/entity/mapper/ClientDetailsMapper.java

-59
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.mifos.mobilewallet.core.data.fineract.entity.mapper
2+
3+
import com.mifos.mobilewallet.model.entity.client.Client
4+
import javax.inject.Inject
5+
6+
/**
7+
* Created by naman on 10/7/17.
8+
*/
9+
class ClientDetailsMapper @Inject constructor() {
10+
fun transformList(clients: List<Client?>?): List<com.mifos.mobilewallet.model.domain.client.Client> {
11+
val clientList: MutableList<com.mifos.mobilewallet.model.domain.client.Client> = ArrayList()
12+
if (clients != null && clients.size != 0) {
13+
for (client in clients) {
14+
clientList.add(transform(client))
15+
}
16+
}
17+
return clientList
18+
}
19+
20+
fun transform(client: Client?): com.mifos.mobilewallet.model.domain.client.Client {
21+
val clientDetails = com.mifos.mobilewallet.model.domain.client.Client()
22+
if (client != null) {
23+
clientDetails.name = client.displayName
24+
clientDetails.clientId = client.id.toLong()
25+
clientDetails.externalId = client.externalId
26+
clientDetails.mobileNo = client.mobileNo
27+
}
28+
return clientDetails
29+
}
30+
}

core/data/src/main/java/org/mifos/mobilewallet/core/data/fineract/entity/mapper/CurrencyMapper.java

-26
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.mifos.mobilewallet.core.data.fineract.entity.mapper
2+
3+
import com.mifos.mobilewallet.model.entity.accounts.savings.Currency
4+
import javax.inject.Inject
5+
6+
/**
7+
* Created by naman on 17/8/17.
8+
*/
9+
class CurrencyMapper @Inject internal constructor() {
10+
fun transform(savingsCurrency: Currency): com.mifos.mobilewallet.model.domain.Currency {
11+
val currency: com.mifos.mobilewallet.model.domain.Currency =
12+
com.mifos.mobilewallet.model.domain.Currency()
13+
currency.code = savingsCurrency.code
14+
currency.displayLabel = savingsCurrency.displayLabel
15+
currency.displaySymbol = savingsCurrency.displaySymbol
16+
return currency
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.mifos.mobilewallet.core.data.fineract.entity.mapper
2+
3+
import org.mifos.mobilewallet.core.base.UseCase
4+
import org.mifos.mobilewallet.core.data.fineract.entity.mapper.AccountMapper
5+
import org.mifos.mobilewallet.core.data.fineract.repository.FineractRepository
6+
import org.mifos.mobilewallet.core.utils.Constants
7+
import com.mifos.mobilewallet.model.domain.Account
8+
import com.mifos.mobilewallet.model.entity.client.ClientAccounts
9+
import rx.Subscriber
10+
import rx.android.schedulers.AndroidSchedulers
11+
import rx.schedulers.Schedulers
12+
13+
import javax.inject.Inject
14+
15+
class FetchAccount @Inject constructor(
16+
private val fineractRepository: FineractRepository,
17+
private val accountMapper: AccountMapper
18+
) : UseCase<FetchAccount.RequestValues, FetchAccount.ResponseValue>() {
19+
20+
override fun executeUseCase(requestValues: RequestValues) {
21+
fineractRepository.getSelfAccounts(requestValues.clientId)
22+
.observeOn(AndroidSchedulers.mainThread())
23+
.subscribeOn(Schedulers.io())
24+
.subscribe(object : Subscriber<ClientAccounts>() {
25+
override fun onCompleted() {}
26+
27+
override fun onError(e: Throwable) {
28+
useCaseCallback.onError(Constants.ERROR_FETCHING_ACCOUNTS)
29+
}
30+
31+
override fun onNext(clientAccounts: ClientAccounts) {
32+
val accounts: List<Account> = accountMapper.transform(clientAccounts)
33+
if (accounts.isNotEmpty()) {
34+
var walletAccount: Account? = null
35+
for (account in accounts) {
36+
if (account.productId.toInt() == Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) {
37+
walletAccount = account
38+
break
39+
}
40+
}
41+
if (walletAccount != null) {
42+
useCaseCallback.onSuccess(ResponseValue(walletAccount))
43+
} else {
44+
useCaseCallback.onError(Constants.NO_ACCOUNT_FOUND)
45+
}
46+
} else {
47+
useCaseCallback.onError(Constants.ERROR_FETCHING_ACCOUNT)
48+
}
49+
}
50+
})
51+
}
52+
53+
class RequestValues(val clientId: Long) : UseCase.RequestValues
54+
55+
class ResponseValue(val account: Account) : UseCase.ResponseValue
56+
}

core/data/src/main/java/org/mifos/mobilewallet/core/data/fineract/entity/mapper/SearchedEntitiesMapper.java

-43
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.mifos.mobilewallet.core.data.fineract.entity.mapper
2+
3+
import com.mifos.mobilewallet.model.domain.SearchResult
4+
import com.mifos.mobilewallet.model.entity.SearchedEntity
5+
import javax.inject.Inject
6+
7+
/**
8+
* Created by naman on 19/8/17.
9+
*/
10+
class SearchedEntitiesMapper @Inject internal constructor() {
11+
fun transformList(searchedEntities: List<SearchedEntity>?): List<SearchResult> {
12+
val searchResults: MutableList<SearchResult> = ArrayList()
13+
if (searchedEntities != null && searchedEntities.size != 0) {
14+
for (entity in searchedEntities) {
15+
searchResults.add(transform(entity))
16+
}
17+
}
18+
return searchResults
19+
}
20+
21+
fun transform(searchedEntity: SearchedEntity): SearchResult {
22+
val searchResult = SearchResult()
23+
searchResult.resultId = searchedEntity.entityId
24+
searchResult.resultName = searchedEntity.entityName
25+
searchResult.resultType = searchedEntity.entityType
26+
return searchResult
27+
}
28+
}

0 commit comments

Comments
 (0)