Skip to content

Commit

Permalink
function to match an action
Browse files Browse the repository at this point in the history
  • Loading branch information
e-marchand committed Jan 5, 2024
1 parent c650214 commit 7473aee
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.qmobile.qmobiledatastore.dao
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.qmobile.qmobiledatastore.data.RoomData
import com.qmobile.qmobiledatastore.data.RoomEntity
import org.json.JSONArray
import org.json.JSONObject
import java.util.Date
Expand Down Expand Up @@ -39,6 +40,16 @@ data class ActionTask(
fun isSuccess(): Boolean = this.status == Status.SUCCESS
fun isErrorServer(): Boolean = this.status == Status.ERROR_SERVER

@Suppress("UNCHECKED_CAST")
fun match(actionName: String, tableName: String, primaryKey: Any?): Boolean {
if (actionName != this.actionInfo.actionName) return false
if (tableName != this.actionInfo.tableName) return false

val contextMap: Map<String, Any>? = actionContent?.get("context") as? Map<String, Any>
val entityMap: Map<String, Any>? = contextMap?.get("entity") as? Map<String, Any>
return (primaryKey == entityMap?.get("primaryKey"))
}

fun getNbParameters(): Int {
return this.actionInfo.allParameters?.let {
JSONArray(it).length()
Expand Down

0 comments on commit 7473aee

Please sign in to comment.