forked from openMF/mifos-mobile-cn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d10098d
commit b5d2115
Showing
87 changed files
with
4,065 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
app/src/main/kotlin/org/mifos/mobile/cn/data/datamanager/DataManagerCustomer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.mifos.mobile.cn.data.datamanager | ||
|
||
import io.reactivex.Completable | ||
import io.reactivex.Observable | ||
import okhttp3.MultipartBody | ||
import org.mifos.mobile.cn.data.models.customer.Command | ||
import org.mifos.mobile.cn.data.models.customer.Customer | ||
import org.mifos.mobile.cn.data.models.customer.identification.Identification | ||
import org.mifos.mobile.cn.data.models.customer.identification.ScanCard | ||
|
||
import org.mifos.mobile.cn.data.datamanager.contracts.ManagerCustomer | ||
import org.mifos.mobile.cn.data.local.DatabaseHelperCustomer | ||
import javax.inject.Inject | ||
|
||
|
||
class DataManagerCustomer @Inject constructor(databaseHelperCustomer: DatabaseHelperCustomer) : ManagerCustomer { | ||
var databaseHelperCustomer: DatabaseHelperCustomer = databaseHelperCustomer | ||
|
||
|
||
override fun fetchCustomer(identifier: String): Observable<Customer> { | ||
return databaseHelperCustomer.fetchCustomer(identifier) | ||
|
||
} | ||
|
||
override fun updateCustomer(customerIdentifier: String, customer: Customer?): Completable? { | ||
return null | ||
} | ||
|
||
|
||
|
||
override fun customerCommand(identifier: String, command: Command): Completable? { | ||
return null | ||
} | ||
|
||
override fun fetchCustomerCommands(customerIdentifier: String): Observable<MutableList<Command>>? { | ||
return null | ||
} | ||
|
||
override fun fetchIdentifications(customerIdentifier: String): Observable<MutableList<Identification>>? { | ||
return null | ||
} | ||
|
||
override fun createIdentificationCard(identifier: String, identification: Identification): Completable? { | ||
return null | ||
} | ||
|
||
override fun updateIdentificationCard(customerIdentifier: String, identificationNumber: String, identification: Identification?): Completable? { | ||
return null | ||
} | ||
|
||
override fun fetchIdentificationScanCards(customerIdentifier: String, identificationNumber: String): Observable<MutableList<ScanCard>>? { | ||
return null | ||
} | ||
|
||
override fun uploadIdentificationCardScan(customerIdentifier: String, identificationNumber: String, scanIdentifier: String, description: String, file: MultipartBody.Part): Completable? { | ||
return null | ||
} | ||
|
||
override fun deleteIdentificationCardScan(customerIdentifier: String, identificationNumber: String, scanIdentifier: String): Completable? { | ||
return null | ||
} | ||
|
||
override fun deleteIdentificationCard(customerIdentifier: String, identificationnumber: String): Completable? { | ||
return null | ||
} | ||
|
||
override fun uploadCustomerPortrait(customerIdentifier: String, file: MultipartBody.Part): Completable? { | ||
return null | ||
} | ||
|
||
override fun deleteCustomerPortrait(customerIdentifier: String): Completable? { | ||
return null | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
app/src/main/kotlin/org/mifos/mobile/cn/data/datamanager/contracts/ManagerCustomer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.mifos.mobile.cn.data.datamanager.contracts; | ||
|
||
import org.mifos.mobile.cn.data.models.customer.Command; | ||
import org.mifos.mobile.cn.data.models.customer.Customer; | ||
import org.mifos.mobile.cn.data.models.customer.identification.Identification; | ||
import org.mifos.mobile.cn.data.models.customer.identification.ScanCard; | ||
|
||
import java.util.List; | ||
|
||
import io.reactivex.Completable; | ||
import io.reactivex.Observable; | ||
import okhttp3.MultipartBody; | ||
|
||
public interface ManagerCustomer { | ||
|
||
|
||
|
||
Observable<Customer> fetchCustomer(String identifier); | ||
|
||
Completable updateCustomer(String customerIdentifier, Customer customer); | ||
|
||
|
||
|
||
|
||
|
||
Completable customerCommand(String identifier, Command command); | ||
|
||
Observable<List<Command>> fetchCustomerCommands(String customerIdentifier); | ||
|
||
Observable<List<Identification>> fetchIdentifications(String customerIdentifier); | ||
|
||
Completable createIdentificationCard(String identifier, Identification identification); | ||
|
||
Completable updateIdentificationCard(String customerIdentifier, String identificationNumber, | ||
Identification identification); | ||
|
||
Observable<List<ScanCard>> fetchIdentificationScanCards(String customerIdentifier, | ||
String identificationNumber); | ||
|
||
Completable uploadIdentificationCardScan(String customerIdentifier, String identificationNumber, | ||
String scanIdentifier, String description, | ||
MultipartBody.Part file); | ||
|
||
Completable deleteIdentificationCardScan(String customerIdentifier, String identificationNumber, | ||
String scanIdentifier); | ||
|
||
Completable deleteIdentificationCard(String customerIdentifier, String identificationnumber); | ||
|
||
Completable uploadCustomerPortrait(String customerIdentifier, MultipartBody.Part file); | ||
|
||
Completable deleteCustomerPortrait(String customerIdentifier); | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/kotlin/org/mifos/mobile/cn/data/local/DatabaseHelperCustomer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.mifos.mobile.cn.data.local | ||
|
||
import com.raizlabs.android.dbflow.sql.language.SQLite.select | ||
import org.mifos.mobile.cn.data.models.customer.Customer | ||
import org.mifos.mobile.cn.data.models.customer.Customer_Table | ||
|
||
import javax.inject.Inject | ||
|
||
|
||
class DatabaseHelperCustomer @Inject constructor(){ | ||
|
||
fun fetchCustomer(identifier: String): io.reactivex.Observable<Customer> { | ||
return io.reactivex.Observable.defer { | ||
var customer = select() | ||
.from(Customer::class.java) | ||
.where(Customer_Table.identifier.eq(identifier)) | ||
.querySingle() | ||
if (customer == null) | ||
customer = Customer() | ||
//else it will throw exception and will not go in the flatMap | ||
io.reactivex.Observable.just(customer!!) | ||
} | ||
|
||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/kotlin/org/mifos/mobile/cn/data/models/customer/Address.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.mifos.mobile.cn.data.models.customer | ||
|
||
import android.os.Parcelable | ||
import com.google.gson.annotations.SerializedName | ||
import com.raizlabs.android.dbflow.annotation.ConflictAction | ||
import com.raizlabs.android.dbflow.annotation.PrimaryKey | ||
import com.raizlabs.android.dbflow.annotation.Table | ||
import com.raizlabs.android.dbflow.structure.BaseModel | ||
import kotlinx.android.parcel.Parcelize | ||
import org.mifos.mobile.cn.local.MifosCnDatabase | ||
|
||
@Parcelize | ||
@Table(name = "Address", database = MifosCnDatabase::class, allFields = true, insertConflict = | ||
ConflictAction.REPLACE) | ||
data class Address( | ||
@PrimaryKey | ||
@SerializedName("street") var street: String? = null, | ||
@PrimaryKey | ||
@SerializedName("city") var city: String? = null, | ||
@PrimaryKey | ||
@SerializedName("region") var region: String? = null, | ||
@SerializedName("postalCode") var postalCode: String? = null, | ||
@SerializedName("countryCode") var countryCode: String? = null, | ||
@SerializedName("country") var country: String? = null | ||
) : BaseModel(), Parcelable |
28 changes: 28 additions & 0 deletions
28
app/src/main/kotlin/org/mifos/mobile/cn/data/models/customer/Command.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.mifos.mobile.cn.data.models.customer | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class Command( | ||
@SerializedName("action") var action: Action? = null, | ||
@SerializedName("comment") var comment: String? = null, | ||
@SerializedName("createdOn") var createdOn: String? = null, | ||
@SerializedName("createdBy") var createdBy: String? = null | ||
) { | ||
enum class Action { | ||
|
||
@SerializedName("ACTIVATE") | ||
ACTIVATE, | ||
|
||
@SerializedName("LOCK") | ||
LOCK, | ||
|
||
@SerializedName("UNLOCK") | ||
UNLOCK, | ||
|
||
@SerializedName("CLOSE") | ||
CLOSE, | ||
|
||
@SerializedName("REOPEN") | ||
REOPEN | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
app/src/main/kotlin/org/mifos/mobile/cn/data/models/customer/ContactDetail.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.mifos.mobile.cn.data.models.customer | ||
|
||
import android.os.Parcelable | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import com.raizlabs.android.dbflow.annotation.ConflictAction | ||
import com.raizlabs.android.dbflow.annotation.ForeignKey | ||
import com.raizlabs.android.dbflow.annotation.PrimaryKey | ||
import com.raizlabs.android.dbflow.annotation.Table | ||
import com.raizlabs.android.dbflow.structure.BaseModel | ||
import kotlinx.android.parcel.Parcelize | ||
import org.mifos.mobile.cn.local.MifosCnDatabase | ||
|
||
@Parcelize | ||
@Table(name = "ContactDetail", database = MifosCnDatabase::class, allFields = true, insertConflict = | ||
ConflictAction.REPLACE, useBooleanGetterSetters = false) | ||
data class ContactDetail( | ||
@SerializedName("type") var type: Type? = null, | ||
@SerializedName("value") var value: String? = null, | ||
@SerializedName("preferenceLevel") var preferenceLevel: Int? = null, | ||
@SerializedName("validated") var validated: Boolean? = null, | ||
@SerializedName("group") var group: Group? = null | ||
) : BaseModel(), Parcelable { | ||
|
||
@PrimaryKey | ||
@ForeignKey(stubbedRelationship = true) var customer: Customer? = null | ||
|
||
enum class Type { | ||
@SerializedName("EMAIL") | ||
EMAIL, | ||
|
||
@SerializedName("PHONE") | ||
PHONE, | ||
|
||
@SerializedName("MOBILE") | ||
MOBILE | ||
} | ||
|
||
enum class Group { | ||
|
||
@SerializedName("BUSINESS") | ||
BUSINESS, | ||
|
||
@SerializedName("PRIVATE") | ||
PRIVATE | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/kotlin/org/mifos/mobile/cn/data/models/customer/Country.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.mifos.mobile.cn.data.models.customer | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
/** | ||
* @author Rajan Maurya | ||
* On 26/07/17. | ||
*/ | ||
|
||
data class Country( | ||
@SerializedName("translations") var translations: Translations, | ||
@SerializedName("name") var name: String, | ||
@SerializedName("alpha2Code") var alphaCode: String | ||
) |
84 changes: 84 additions & 0 deletions
84
app/src/main/kotlin/org/mifos/mobile/cn/data/models/customer/Customer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package org.mifos.mobile.cn.data.models.customer | ||
|
||
import android.os.Parcelable | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import com.raizlabs.android.dbflow.annotation.* | ||
import com.raizlabs.android.dbflow.sql.language.SQLite.select | ||
import com.raizlabs.android.dbflow.structure.BaseModel | ||
import kotlinx.android.parcel.Parcelize | ||
import org.mifos.mobile.cn.data.models.customer.ContactDetail_Table | ||
import org.mifos.mobile.cn.local.MifosCnDatabase | ||
|
||
@Parcelize | ||
@Table(database = MifosCnDatabase::class, useBooleanGetterSetters = false) | ||
data class Customer( | ||
@PrimaryKey | ||
@Column var identifier: String? = null, | ||
@Column var type: String? = null, | ||
@Column var givenName: String? = null, | ||
@Column var middleName: String? = null, | ||
@Column var surname: String? = null, | ||
@ForeignKey(saveForeignKeyModel = true) | ||
@Column var dateOfBirth: DateOfBirth? = null, | ||
@Column var member: Boolean? = null, | ||
@Column var accountBeneficiary: String? = null, | ||
@Column var referenceCustomer: String? = null, | ||
@Column var assignedOffice: String? = null, | ||
@Column var assignedEmployee: String? = null, | ||
@ForeignKey(saveForeignKeyModel = true) | ||
@Column var address: Address? = null, | ||
var contactDetails: List<ContactDetail>? = null, | ||
@Column var currentState: State? = null, | ||
@Column var createdBy: String? = null, | ||
@Column var createdOn: String? = null, | ||
@Column var lastModifiedBy: String? = null, | ||
@Column var lastModifiedOn: String? = null | ||
) : BaseModel(), Parcelable { | ||
|
||
var isUpdate: Boolean? = null | ||
|
||
@OneToMany(methods = arrayOf(OneToMany.Method.ALL), variableName = "contactDetails") | ||
fun getContactDetail() : List<ContactDetail>? { | ||
contactDetails = select() | ||
.from(ContactDetail::class.java) | ||
.where(ContactDetail_Table.customer_identifier.eq(identifier)) | ||
.queryList() | ||
return contactDetails | ||
} | ||
|
||
enum class Type { | ||
|
||
@SerializedName("PERSON") | ||
PERSON, | ||
|
||
@SerializedName("BUSINESS") | ||
BUSINESS | ||
} | ||
|
||
enum class State { | ||
|
||
@SerializedName("PENDING") | ||
PENDING, | ||
|
||
@SerializedName("ACTIVE") | ||
ACTIVE, | ||
|
||
@SerializedName("LOCKED") | ||
LOCKED, | ||
|
||
@SerializedName("CLOSED") | ||
CLOSED | ||
} | ||
|
||
override fun save(): Boolean { | ||
val res = super.save() | ||
if (contactDetails != null) { | ||
contactDetails!!.forEach { | ||
it.customer = this | ||
it.save() | ||
} | ||
} | ||
return res | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/kotlin/org/mifos/mobile/cn/data/models/customer/CustomerPage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.mifos.mobile.cn.data.models.customer | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class CustomerPage( | ||
@SerializedName("customers") var customers: List<Customer>? = null, | ||
@SerializedName("totalPages") var totalPages: Int? = null, | ||
@SerializedName("totalElements") var totalElements: Long? = null | ||
) |
Oops, something went wrong.