|
|
|
@ -17,13 +17,11 @@ import java.util.* |
|
|
|
* It contains a list of [FilterElement] describing the complete query to launch |
|
|
|
* It contains a list of [FilterElement] describing the complete query to launch |
|
|
|
* The [Filter] is working closely with a [Filterable] interface providing the entity we want the query being launched on |
|
|
|
* The [Filter] is working closely with a [Filterable] interface providing the entity we want the query being launched on |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
open class Filter() : RealmObject() { |
|
|
|
open class Filter(entity:Filterable) : RealmObject() { |
|
|
|
|
|
|
|
|
|
|
|
constructor(entity:Filterable) : this() { |
|
|
|
constructor() : this(entity = Session) |
|
|
|
this.entityType = FilterableClass.filterableClass(entity = entity).ordinal |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var entityType : Int? = null |
|
|
|
private var entityType : Int? = FilterableClass.filterableClass(entity = entity).ordinal |
|
|
|
private val filterableClass : FilterableClass? |
|
|
|
private val filterableClass : FilterableClass? |
|
|
|
get() { |
|
|
|
get() { |
|
|
|
entityType?.let { |
|
|
|
entityType?.let { |
|
|
|
@ -49,17 +47,26 @@ open class Filter() : RealmObject() { |
|
|
|
get() { |
|
|
|
get() { |
|
|
|
return when (this) { |
|
|
|
return when (this) { |
|
|
|
SESSION -> Session::class.java |
|
|
|
SESSION -> Session::class.java |
|
|
|
else -> throw FilterUnhandledEntityException("this entity is not filterable") |
|
|
|
// else -> throw FilterUnhandledEntityException("this entity is not filterable") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val filterable : Filterable |
|
|
|
|
|
|
|
get() { |
|
|
|
|
|
|
|
return when (this) { |
|
|
|
|
|
|
|
SESSION -> Session.Companion |
|
|
|
|
|
|
|
// else -> throw FilterUnhandledEntityException("this entity is not filterable") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
@TestOnly |
|
|
|
@TestOnly |
|
|
|
fun queryOn(realm: Realm, entity: Filterable, queries:List<QueryType>): RealmResults<*> { |
|
|
|
fun queryOn(realm: Realm, entity: Filterable, queries:List<QueryType>): RealmResults<*> { |
|
|
|
var realmQuery : RealmQuery<out RealmObject> = realm.where(FilterableClass.filterableClass(entity).relatedEntity) |
|
|
|
val realmEntity : Class < out RealmObject > = FilterableClass.filterableClass(entity).relatedEntity |
|
|
|
|
|
|
|
var realmQuery : RealmQuery<out RealmObject> = realm.where(realmEntity) |
|
|
|
queries.forEach { |
|
|
|
queries.forEach { |
|
|
|
realmQuery = (it.filter(realmQuery, entity)) |
|
|
|
realmQuery = (it.filter(realmQuery, entity)) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -123,13 +130,14 @@ open class Filter() : RealmObject() { |
|
|
|
return filterElementRow.contains(filtered) |
|
|
|
return filterElementRow.contains(filtered) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun queryOn(entity: Filterable) : RealmResults<*> { |
|
|
|
fun results(): RealmResults<*> { |
|
|
|
val realmEntity : Class < out RealmObject > = filterableClass?.relatedEntity ?: throw FilterMissingEntityException("this filter has no entity initialized") |
|
|
|
val filterableClass : FilterableClass = this.filterableClass ?: throw FilterMissingEntityException("this filter has no entity initialized") |
|
|
|
|
|
|
|
val realmEntity : Class < out RealmObject > = filterableClass.relatedEntity |
|
|
|
var realmQuery : RealmQuery<out RealmObject> = realm.where(realmEntity) |
|
|
|
var realmQuery : RealmQuery<out RealmObject> = realm.where(realmEntity) |
|
|
|
this.filterElements.map { |
|
|
|
this.filterElements.map { |
|
|
|
it.queryType |
|
|
|
it.queryType |
|
|
|
}.forEach { |
|
|
|
}.forEach { |
|
|
|
realmQuery = (it.filter(realmQuery, entity)) |
|
|
|
realmQuery = (it.filter(realmQuery, filterableClass.filterable)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return realmQuery.findAll() |
|
|
|
return realmQuery.findAll() |
|
|
|
|