openMF / mifos-mobile

Repository for the Mifos Mobile Banking App for clients
https://openmf.github.io/mobileapps.github.io/
Mozilla Public License 2.0
270 stars 674 forks source link

Bug: MifosNotification_Table is not available #2549

Closed MuindiStephen closed 5 months ago

MuindiStephen commented 5 months ago

Database helper class calls MifosNotification_Table class which is not available in package import org.mifos.mobile.models.notification.MifosNotification_Table

MuindiStephen commented 5 months ago

@PratyushSingh07 This issue is fixed. My code is working perfect!

MuindiStephen commented 5 months ago

This is what I was having previously

@Singleton
class DatabaseHelper @Inject constructor() {
    fun syncCharges(charges: Page<Charge>?): Page<Charge>? {
        if (charges != null) {
            for (charge in charges.pageItems)
                charge.save()
        }
        return charges
    }

    fun clientCharges(): Page<Charge?> {
        val charges = SQLite.select()
            .from(Charge::class.java)
            .queryList()
        val chargePage = Page<Charge?>()
        chargePage.pageItems = charges
        return chargePage
    }

    fun notifications(): List<MifosNotification> {
        deleteOldNotifications()
        val notifications = SQLite.select()
            .from(MifosNotification::class.java)
            .queryList()
        Collections.sort(notifications, NotificationComparator())
        return notifications
    }

    fun unreadNotificationsCount(): Int {
        deleteOldNotifications()
        return SQLite.select()
            .from(MifosNotification::class.java)
            .where(MifosNotification.isRead().eq(false))
            .queryList().size
    }

    private fun deleteOldNotifications() {
        Observable.defer<Void> {
            val thirtyDaysInSeconds: Long = 2592000
            val thirtyDaysFromCurrentTimeInSeconds = System.currentTimeMillis() / 1000 -
                    thirtyDaysInSeconds
            SQLite.delete(MifosNotification::class.java)
                .where(MifosNotification_Table.timeStamp.lessThan(thirtyDaysFromCurrentTimeInSeconds * 1000))
                .execute()
            null
        }
    }
}

instead of


@Singleton
class DatabaseHelper @Inject constructor() {
    fun syncCharges(charges: Page<Charge>?): Page<Charge>? {
        if (charges != null) {
            for (charge in charges.pageItems)
                charge.save()
        }
        return charges
    }

    fun clientCharges(): Page<Charge?> {
        val charges = SQLite.select()
            .from(Charge::class.java)
            .queryList()
        val chargePage = Page<Charge?>()
        chargePage.pageItems = charges
        return chargePage
    }

    fun notifications(): List<MifosNotification> {
        deleteOldNotifications()
        val notifications = SQLite.select()
            .from(MifosNotification::class.java)
            .queryList()
        Collections.sort(notifications, NotificationComparator())
        return notifications
    }

    fun unreadNotificationsCount(): Int {
        deleteOldNotifications()
        return SQLite.select()
            .from(MifosNotification::class.java)
            .where(MifosNotification_Table.read.eq(false))
            .queryList().size
    }

    private fun deleteOldNotifications() {
        Observable.defer<Void> {
            val thirtyDaysInSeconds: Long = 2592000
            val thirtyDaysFromCurrentTimeInSeconds = System.currentTimeMillis() / 1000 -
                    thirtyDaysInSeconds
            SQLite.delete(MifosNotification::class.java)
                .where(MifosNotification_Table.timeStamp.lessThan(thirtyDaysFromCurrentTimeInSeconds * 1000))
                .execute()
            null
        }
    }
}