Skip to content

Commit

Permalink
Match AbstractEvent entities API with iOS tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
mscwilson committed Jan 26, 2024
1 parent c51096d commit 5c45695
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class AbstractEventTest {
@Test
fun testAddsEntitiesUsingAllAPIs() {
val event = ScreenView("screen")
val entity = SelfDescribingJson("schema3", "data3")

event.entities.add(SelfDescribingJson("schema1", "data1"))
event.customContexts.add(SelfDescribingJson("schema2", "data2"))
event.entities(listOf(SelfDescribingJson("schema3", "data3")))
event.contexts(listOf(SelfDescribingJson("schema4", "data4")))
event.contexts(listOf(SelfDescribingJson("schema2", "data2")))
event.entities(listOf(entity))

Assert.assertEquals(4, event.entities.count())
Assert.assertEquals(4, event.contexts.count())
Assert.assertEquals(4, event.customContexts.count())
Assert.assertEquals(1, event.entities.count())
Assert.assertEquals(1, event.contexts.count())
Assert.assertTrue(event.entities.contains(entity))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,27 @@ import java.util.*
* - "True" timestamp: user-defined custom event timestamp
*/
abstract class AbstractEvent : Event {
/** List of custom contexts associated with the event. */
@Deprecated("Old nomenclature.", ReplaceWith("entities"))
@JvmField
val customContexts: MutableList<SelfDescribingJson> = LinkedList()
private var _entities: MutableList<SelfDescribingJson> = LinkedList()
/**
* @return the custom context entities associated with the event.
*/
override var entities: MutableList<SelfDescribingJson>
get() {
if (isProcessing) {
entitiesForProcessing?.let {
return (_entities + it).toMutableList()
}
}
return _entities
}
set(value) {
_entities = value
}

@Deprecated("Old nomenclature", ReplaceWith("entities"))
override var contexts: List<SelfDescribingJson>
get() = entities
set(value) { entities = value.toMutableList()}

/**
* @return the optional "true" (custom) event timestamp
Expand All @@ -38,15 +55,15 @@ abstract class AbstractEvent : Event {

// Builder methods

/** Adds a list of context entities to the existing ones. */
fun entities(entities: List<SelfDescribingJson>?): AbstractEvent {
entities?.let { customContexts.addAll(entities) }
/** Replace the context entities attached to the event with a new list of entities. */
fun entities(entities: List<SelfDescribingJson>): AbstractEvent {
this.entities = entities.toMutableList()
return this
}

/** Adds a list of context entities to the existing ones. */
/** Replace the context entities attached to the event with a new list of entities. */
@Deprecated("Old nomenclature.", ReplaceWith("entities()"))
fun contexts(contexts: List<SelfDescribingJson>?): AbstractEvent {
fun contexts(contexts: List<SelfDescribingJson>): AbstractEvent {
return entities(contexts)
}

Expand All @@ -56,24 +73,6 @@ abstract class AbstractEvent : Event {
return this
}

// Public methods

/**
* @return the event custom context entities
*/
override val entities: MutableList<SelfDescribingJson>
get() {
if (isProcessing) {
entitiesForProcessing?.let {
return (customContexts + it).toMutableList()
}
}
return customContexts
}

@Deprecated("Old nomenclature", ReplaceWith("entities"))
override val contexts: List<SelfDescribingJson>
get() = entities

private var isProcessing = false
override fun beginProcessing(tracker: Tracker) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ConsentGranted(expiry: String, documentId: String, documentVersion: String
override fun beginProcessing(tracker: Tracker) {
for (document in documents) {
val context = SelfDescribingJson(document.schema, document.dataPayload)
customContexts.add(context) // TODO: Only the user should modify the public customContexts property
entities.add(context)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class ConsentWithdrawn(all: Boolean, documentId: String, documentVersion: String
override fun beginProcessing(tracker: Tracker) {
for (document in documents) {
val context = SelfDescribingJson(document.schema, document.dataPayload)
customContexts.add(context) // TODO: Only the user should modify the public customContexts property
entities.add(context)
}
}
}

0 comments on commit 5c45695

Please sign in to comment.