Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove PageMessage and PAGE event type #455

Open
wants to merge 1 commit into
base: feat/android
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.rudderstack.models.AliasMessage
import com.rudderstack.models.GroupMessage
import com.rudderstack.models.IdentifyMessage
import com.rudderstack.models.Message
import com.rudderstack.models.PageMessage
import com.rudderstack.models.ScreenMessage
import com.rudderstack.models.TrackMessage
import com.rudderstack.rudderjsonadapter.JsonAdapter
Expand All @@ -45,21 +44,24 @@ import com.rudderstack.rudderjsonadapter.RudderTypeAdapter
RudderField(RudderField.Type.INTEGER, MessageEntity.ColumnNames.status),
]
)
internal class MessageEntity(val message: Message,
private val jsonAdapter: JsonAdapter,
private val updatedAt: Long? = null) : Entity {
internal class MessageEntity(
val message: Message,
private val jsonAdapter: JsonAdapter,
private val updatedAt: Long? = null
) : Entity {
object ColumnNames {
internal const val messageId = "id"
internal const val message = "message"
internal const val updatedAt = "updated"
internal const val type = "type"
internal const val status = "status"
}

val status: Int
get() = _status
private var _status: Int = STATUS_NEW

fun maskWithDmtStatus(dmtStatus: Int){
fun maskWithDmtStatus(dmtStatus: Int) {
_status = _status.maskWith(dmtStatus)
}

Expand All @@ -71,7 +73,7 @@ internal class MessageEntity(val message: Message,
jsonAdapter.writeToJson(message, RudderTypeAdapter<Message> {})
?.replace("'", BACKLASHES_INVERTED_COMMA)
)
it.put(ColumnNames.updatedAt, updatedAt?: System.currentTimeMillis())
it.put(ColumnNames.updatedAt, updatedAt ?: System.currentTimeMillis())
it.put(ColumnNames.type, message.getType().value)
it.put(ColumnNames.status, _status)
}
Expand All @@ -95,7 +97,7 @@ internal class MessageEntity(val message: Message,
return MessageEntity(
message ?: return null,
jsonAdapter
).also {entity ->
).also { entity ->
status?.let {
entity.maskWithDmtStatus(it)
}
Expand All @@ -107,11 +109,10 @@ internal class MessageEntity(val message: Message,
Message.EventType.ALIAS.value -> AliasMessage::class.java
Message.EventType.GROUP.value -> GroupMessage::class.java
Message.EventType.IDENTIFY.value -> IdentifyMessage::class.java
Message.EventType.PAGE.value -> PageMessage::class.java
Message.EventType.SCREEN.value -> ScreenMessage::class.java
Message.EventType.TRACK.value -> TrackMessage::class.java
else -> Message::class.java
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import org.robolectric.annotation.Config

abstract class MessageEntityTest {
abstract val jsonAdapter: JsonAdapter

@Test
fun testGenerateContentValuesForTrack() {
val testMessage = TrackMessage.create(
Expand All @@ -42,19 +43,21 @@ abstract class MessageEntityTest {
val regainedEntity = MessageEntity.create(contentValues.keySet().associateWith {
contentValues.getAsString(it)
}, jsonAdapter)
MatcherAssert.assertThat(regainedEntity?.message, Matchers.allOf(
Matchers.notNullValue(),
Matchers.instanceOf(TrackMessage::class.java),
Matchers.hasProperty("eventName", Matchers.equalTo("testEvent")),
Matchers.hasProperty("anonymousId", Matchers.equalTo("testAnonymousId")),
Matchers.hasProperty("userId", Matchers.equalTo("testUserId")),
Matchers.hasProperty("properties", Matchers.hasEntry("testKey", "testValue")),
Matchers.hasProperty("messageId", Matchers.equalTo(testMessage.messageId)),
Matchers.hasProperty("context", Matchers.equalTo(testMessage.context)),
Matchers.hasProperty("destinationProps", Matchers.equalTo(testMessage.destinationProps)),

))
MatcherAssert.assertThat(
regainedEntity?.message, Matchers.allOf(
Matchers.notNullValue(),
Matchers.instanceOf(TrackMessage::class.java),
Matchers.hasProperty("eventName", Matchers.equalTo("testEvent")),
Matchers.hasProperty("anonymousId", Matchers.equalTo("testAnonymousId")),
Matchers.hasProperty("userId", Matchers.equalTo("testUserId")),
Matchers.hasProperty("properties", Matchers.hasEntry("testKey", "testValue")),
Matchers.hasProperty("messageId", Matchers.equalTo(testMessage.messageId)),
Matchers.hasProperty("context", Matchers.equalTo(testMessage.context)),
Matchers.hasProperty("destinationProps", Matchers.equalTo(testMessage.destinationProps)),
)
)
}

@Test
fun testGenerateContentValuesForGroup() {
val testMessage = GroupMessage.create(
Expand All @@ -75,20 +78,23 @@ Matchers.hasProperty("destinationProps", Matchers.equalTo(testMessage.destinatio
val regainedEntity = MessageEntity.create(contentValues.keySet().associateWith {
contentValues.getAsString(it)
}, jsonAdapter)
MatcherAssert.assertThat(regainedEntity?.message, Matchers.allOf(
Matchers.notNullValue(),
Matchers.instanceOf(GroupMessage::class.java),
Matchers.hasProperty("groupId", Matchers.equalTo(testMessage.groupId)),
Matchers.hasProperty("anonymousId", Matchers.equalTo(testMessage.anonymousId)),
Matchers.hasProperty("userId", Matchers.equalTo(testMessage.userId)),
Matchers.hasProperty("traits", Matchers.hasEntry("testKey", "testValue")),
Matchers.hasProperty("messageId", Matchers.equalTo(testMessage.messageId)),
Matchers.hasProperty("context", Matchers.equalTo(testMessage.context)),
Matchers.hasProperty("destinationProps", Matchers.equalTo(testMessage.destinationProps)),
MatcherAssert.assertThat(
regainedEntity?.message, Matchers.allOf(
Matchers.notNullValue(),
Matchers.instanceOf(GroupMessage::class.java),
Matchers.hasProperty("groupId", Matchers.equalTo(testMessage.groupId)),
Matchers.hasProperty("anonymousId", Matchers.equalTo(testMessage.anonymousId)),
Matchers.hasProperty("userId", Matchers.equalTo(testMessage.userId)),
Matchers.hasProperty("traits", Matchers.hasEntry("testKey", "testValue")),
Matchers.hasProperty("messageId", Matchers.equalTo(testMessage.messageId)),
Matchers.hasProperty("context", Matchers.equalTo(testMessage.context)),
Matchers.hasProperty("destinationProps", Matchers.equalTo(testMessage.destinationProps)),

))
)
)
}
@Test

@Test
fun testGenerateContentValuesForIdentify() {
val testMessage = IdentifyMessage.create(
"testAnonymousId",
Expand All @@ -106,19 +112,22 @@ Matchers.hasProperty("destinationProps", Matchers.equalTo(testMessage.destinatio
val regainedEntity = MessageEntity.create(contentValues.keySet().associateWith {
contentValues.getAsString(it)
}, jsonAdapter)
MatcherAssert.assertThat(regainedEntity?.message, Matchers.allOf(
Matchers.notNullValue(),
Matchers.instanceOf(IdentifyMessage::class.java),
Matchers.hasProperty("anonymousId", Matchers.equalTo(testMessage.anonymousId)),
Matchers.hasProperty("userId", Matchers.equalTo(testMessage.userId)),
Matchers.hasProperty("properties", Matchers.hasEntry("testKey", "testValue")),
Matchers.hasProperty("messageId", Matchers.equalTo(testMessage.messageId)),
Matchers.hasProperty("context", Matchers.equalTo(testMessage.context)),
Matchers.hasProperty("destinationProps", Matchers.equalTo(testMessage.destinationProps)),
MatcherAssert.assertThat(
regainedEntity?.message, Matchers.allOf(
Matchers.notNullValue(),
Matchers.instanceOf(IdentifyMessage::class.java),
Matchers.hasProperty("anonymousId", Matchers.equalTo(testMessage.anonymousId)),
Matchers.hasProperty("userId", Matchers.equalTo(testMessage.userId)),
Matchers.hasProperty("properties", Matchers.hasEntry("testKey", "testValue")),
Matchers.hasProperty("messageId", Matchers.equalTo(testMessage.messageId)),
Matchers.hasProperty("context", Matchers.equalTo(testMessage.context)),
Matchers.hasProperty("destinationProps", Matchers.equalTo(testMessage.destinationProps)),

))
)
)
}
@Test

@Test
fun testGenerateContentValuesForScreen() {
val testMessage = ScreenMessage.create(
RudderUtils.timeStamp,
Expand All @@ -138,17 +147,18 @@ Matchers.hasProperty("destinationProps", Matchers.equalTo(testMessage.destinatio
val regainedEntity = MessageEntity.create(contentValues.keySet().associateWith {
contentValues.getAsString(it)
}, jsonAdapter)
MatcherAssert.assertThat(regainedEntity?.message, Matchers.allOf(
Matchers.notNullValue(),
Matchers.instanceOf(ScreenMessage::class.java),
Matchers.hasProperty("anonymousId", Matchers.equalTo(testMessage.anonymousId)),
Matchers.hasProperty("userId", Matchers.equalTo(testMessage.userId)),
Matchers.hasProperty("properties", Matchers.hasEntry("testKey", "testValue")),
Matchers.hasProperty("messageId", Matchers.equalTo(testMessage.messageId)),
Matchers.hasProperty("context", Matchers.equalTo(testMessage.context)),
Matchers.hasProperty("destinationProps", Matchers.equalTo(testMessage.destinationProps)),

))
MatcherAssert.assertThat(
regainedEntity?.message, Matchers.allOf(
Matchers.notNullValue(),
Matchers.instanceOf(ScreenMessage::class.java),
Matchers.hasProperty("anonymousId", Matchers.equalTo(testMessage.anonymousId)),
Matchers.hasProperty("userId", Matchers.equalTo(testMessage.userId)),
Matchers.hasProperty("properties", Matchers.hasEntry("testKey", "testValue")),
Matchers.hasProperty("messageId", Matchers.equalTo(testMessage.messageId)),
Matchers.hasProperty("context", Matchers.equalTo(testMessage.context)),
Matchers.hasProperty("destinationProps", Matchers.equalTo(testMessage.destinationProps)),
)
)
}

@Test
Expand All @@ -169,6 +179,7 @@ Matchers.hasProperty("destinationProps", Matchers.equalTo(testMessage.destinatio
MatcherAssert.assertThat(primaryKeyValues, Matchers.arrayContaining(testMessage.messageId))
}
}

@RunWith(AndroidJUnit4::class)
@Config(sdk = [29])
class GsonEntityTest : MessageEntityTest() {
Expand All @@ -183,13 +194,6 @@ class JacksonEntityTest : MessageEntityTest() {
get() = JacksonAdapter()
}

/*@RunWith(AndroidJUnit4::class)
@Config(sdk = [29])
class MoshiEntityTest : MessageEntityTest() {
override val jsonAdapter: JsonAdapter
get() = MoshiAdapter()
}*/

@RunWith(Suite::class)
@Suite.SuiteClasses(
GsonEntityTest::class, JacksonEntityTest::class,
Expand Down
110 changes: 1 addition & 109 deletions models/src/main/java/com/rudderstack/models/Message.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import java.util.Locale
import java.util.UUID

typealias MessageContext = Map<String, Any?>
typealias PageProperties = Map<String, Any>
typealias ScreenProperties = Map<String, Any>
typealias TrackProperties = Map<String, Any>
typealias IdentifyTraits = Map<String, Any?>
Expand Down Expand Up @@ -119,7 +118,7 @@ sealed class Message(
@SerializedName("sentAt")
@JsonProperty("sentAt")
@Json(name = "sentAt")
var sentAt: String?= null
var sentAt: String? = null
open fun copy(
context: MessageContext? = this.context,
anonymousId: String? = this.anonymousId,
Expand Down Expand Up @@ -153,17 +152,6 @@ sealed class Message(
properties,
)

is PageMessage -> copy(
context,
anonymousId,
userId,
timestamp,
destinationProps,
name,
properties,
category,
)

is ScreenMessage -> copy(
context,
anonymousId,
Expand Down Expand Up @@ -198,11 +186,6 @@ sealed class Message(
@Json(name = "group")
GROUP("group"),

@SerializedName("page")
@JsonProperty("page")
@Json(name = "page")
PAGE("page"),

@SerializedName("screen")
@JsonProperty("screen")
@Json(name = "screen")
Expand All @@ -222,7 +205,6 @@ sealed class Message(
fun fromValue(value: String) = when (value.lowercase()) {
"alias" -> EventType.ALIAS
"group" -> EventType.GROUP
"page" -> EventType.PAGE
"screen" -> EventType.SCREEN
"track" -> EventType.TRACK
"identify" -> EventType.IDENTIFY
Expand Down Expand Up @@ -419,94 +401,6 @@ class GroupMessage internal constructor(
}
}

class PageMessage internal constructor(

@JsonProperty("context") @Json(name = "context") context: MessageContext? = null,
@JsonProperty("anonymousId") @Json(name = "anonymousId") anonymousId: String?,
@JsonProperty("userId") @Json(name = "userId") userId: String? = null,
@JsonProperty("originalTimestamp") @Json(name = "originalTimestamp") timestamp: String,

@JsonProperty("destinationProps") @Json(name = "destinationProps") destinationProps: MessageDestinationProps? = null,
/** @return Name of the event tracked */

@SerializedName("event") @get:JsonProperty("event") @field:JsonProperty("event") @param:JsonProperty(
"event"
) @Json(name = "event") var name: String? = null,

/**
* Get the properties back as set to the event Always convert objects to
* it's json equivalent before setting it as values
*
* @return Map of String-Object
*/

@SerializedName("properties") @JsonProperty("properties") @Json(name = "properties") val properties: PageProperties? = null,

@SerializedName("category") @JsonProperty("category") @Json(name = "category") val category: String? = null,
@JsonProperty("not_applicable", required = false) // work-around to ignore value param
// jackson serialisation
_messageId: String? = null,
) : Message(
EventType.PAGE,
context,
anonymousId,
userId,
timestamp,
destinationProps,
_messageId,
) {
companion object {
@JvmStatic
fun create(
anonymousId: String? = null,
userId: String? = null,
timestamp: String,
destinationProps: MessageDestinationProps? = null,
name: String? = null,
properties: PageProperties? = null,
category: String? = null,
traits: Map<String, Any?>? = null,
externalIds: List<Map<String, String>>? = null,
customContextMap: Map<String, Any>? = null,
_messageId: String? = null,
) = PageMessage(
createContext(traits, externalIds, customContextMap),
anonymousId, userId, timestamp, destinationProps, name, properties,
category, _messageId,
)
}

fun copy(
context: MessageContext? = this.context,
anonymousId: String? = this.anonymousId,
userId: String? = this.userId,
timestamp: String = this.timestamp,
destinationProps: MessageDestinationProps? = this.destinationProps,
name: String? = this.name,
properties: PageProperties? = this.properties,
category: String? = this.category,

) = PageMessage(
context, anonymousId, userId, timestamp, destinationProps, name, properties,
category, _messageId = this.messageId,
)

override fun toString(): String {
return "${super.toString()}, " + "name = $name, " + "properties = $properties, " + "category = $category"
}

override fun equals(other: Any?): Boolean {
return super.equals(other) && other is PageMessage && other.name == name && other.properties == properties && other.category == category
}

override fun hashCode(): Int {
var result = name?.hashCode() ?: 0
result = 31 * result + (properties?.hashCode() ?: 0)
result = 31 * result + (category?.hashCode() ?: 0)
return result
}
}

class ScreenMessage internal constructor(

@JsonProperty("context") @Json(name = "context") context: MessageContext? = null,
Expand Down Expand Up @@ -783,8 +677,6 @@ class IdentifyMessage internal constructor(
fun TrackProperties(vararg keyPropertyPair: Pair<String, Any>): TrackProperties =
mapOf(*keyPropertyPair)

// fun PageProperties(vararg keyPropertyPair: Pair<String, Any>) : PageProperties = mapOf(*keyPropertyPair)

fun ScreenProperties(vararg keyPropertyPair: Pair<String, Any>): ScreenProperties =
mapOf(*keyPropertyPair)

Expand Down
Loading