Skip to content

Commit

Permalink
Fs3 369 slug (#8)
Browse files Browse the repository at this point in the history
### [3.0.3 (Latest version)]
* Added campaign slug information in FlagMetadata
  • Loading branch information
raf-abtasty authored May 30, 2022
1 parent 743cbd6 commit 68fdbef
Show file tree
Hide file tree
Showing 15 changed files with 64 additions and 30 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ android {
minSdkVersion 16
}
}
namespace 'com.abtasty.flagshipqa'
}

dependencies {
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abtasty.flagshipqa">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET"/>

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ buildscript {
if (flagship_version_name != null)
rootProject.ext.flagship_version_name = flagship_version_name
else
rootProject.ext.flagship_version_name = "3.0.2"
rootProject.ext.flagship_version_name = "3.0.3"

if (flagship_version_code != null)
rootProject.ext.flagship_version_code = flagship_version_code
Expand Down Expand Up @@ -63,7 +63,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0'
classpath 'com.android.tools.build:gradle:7.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.24.18"
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.16"
Expand Down
15 changes: 8 additions & 7 deletions flagship/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ apply from: 'jacoco.gradle'

android {
publishNonDefault true
compileSdkVersion 31
compileSdkVersion 32

defaultConfig {
// multiDexEnabled true
minSdkVersion 16
compileSdkVersion 31
targetSdkVersion 31
compileSdkVersion 32
targetSdkVersion 32

kapt {
arguments {
Expand Down Expand Up @@ -74,6 +74,7 @@ android {
resValue("string", "variant", "compat")
}
}
namespace 'com.abtasty.flagship'
}

configurations {
Expand All @@ -87,22 +88,22 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'androidx.test:core:1.4.0'
testImplementation 'org.robolectric:robolectric:4.6'
testImplementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
testImplementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testCompatImplementation 'org.conscrypt:conscrypt-openjdk-uber:2.5.1'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2"
implementation 'androidx.room:room-runtime:2.4.1'
implementation 'androidx.room:room-runtime:2.4.2'

commonImplementation 'com.squareup.okhttp3:okhttp:4.9.3'

//keep this old version for compat
compatImplementation 'com.squareup.okhttp3:okhttp:3.12.12'
compatImplementation 'org.conscrypt:conscrypt-android:2.5.1'

annotationProcessor("androidx.room:room-compiler:2.4.1")
kapt 'androidx.room:room-compiler:2.4.1'
annotationProcessor("androidx.room:room-compiler:2.4.2")
kapt 'androidx.room:room-compiler:2.4.2'
}


Expand Down
3 changes: 1 addition & 2 deletions flagship/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.abtasty.flagship" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class VisitorCacheHelper: CacheHelper() {
campaignJSON.getString("variationId"),
campaignJSON.getBoolean("isReference"),
flagJSON.get(k),
campaignJSON.getString("type")
campaignJSON.getString("type"),
campaignJSON.optString("slug", "")
)
visitorDelegate.modifications[k] = modification
}
Expand Down Expand Up @@ -102,6 +103,7 @@ class VisitorCacheHelper: CacheHelper() {
.put("variationId", m.value.variationId)
.put("isReference", m.value.isReference)
.put("type", m.value.campaignType)
.put("slug", m.value.slug)
.put("activated", visitorDelegateDTO.activatedVariations.contains(m.value.variationId))
.put("flags", JSONObject().put(m.value.key, m.value.value ?: JSONObject.NULL))
)
Expand Down
5 changes: 3 additions & 2 deletions flagship/src/main/java/com/abtasty/flagship/model/Campaign.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,20 @@ data class Campaign(val id: String, val type: String = "", val variationGroups:
return try {
val id = campaignObject.getString("id")
val type = campaignObject.optString("type") ?: ""
val slug = if (campaignObject.isNull("slug")) "" else campaignObject.optString("slug", "")
val variationGroups: LinkedList<VariationGroup?> = LinkedList()
val variationGroupArray = campaignObject.optJSONArray("variationGroups")
variationGroupArray?.let {
//bucketing
for (variationGroupsObj in variationGroupArray) {
val variationGroup: VariationGroup? =
VariationGroup.parse(id, type, variationGroupsObj, true)
VariationGroup.parse(id, type, slug, variationGroupsObj, true)
variationGroup?.let { variationGroups.add(variationGroup) }
}
} ?: run {
//api
val variationGroup: VariationGroup? =
VariationGroup.parse(id, type, campaignObject, false)
VariationGroup.parse(id, type, slug, campaignObject, false)
variationGroup?.let { variationGroups.add(variationGroup) }
}
Campaign(id, type, variationGroups)
Expand Down
25 changes: 23 additions & 2 deletions flagship/src/main/java/com/abtasty/flagship/model/FlagMetadata.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,30 @@ import org.json.JSONObject
* This class contains the flag campaign information.
*/
data class FlagMetadata(
/**
* Flag use case id.
*/
val campaignId: String = "",
/**
* Flag use case variation group id.
*/
val variationGroupId: String = "",
/**
* Flag use case variation id.
*/
val variationId: String = "",
/**
* Is flag from the reference variation.
*/
val isReference: Boolean = false,
val campaignType: String = ""
/**
* Flag use case type
*/
val campaignType: String = "",
/**
* Flag use case custom slug
*/
val slug: String = ""
) {

companion object {
Expand All @@ -23,7 +42,8 @@ data class FlagMetadata(
modification.variationGroupId,
modification.variationId,
modification.isReference,
modification.campaignType
modification.campaignType,
modification.slug
)
}
}
Expand All @@ -48,5 +68,6 @@ data class FlagMetadata(
.put("variationId", variationId)
.put("isReference", isReference)
.put("campaignType", campaignType)
.put("slug", slug)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.abtasty.flagship.model

data class Modification(val key: String, val campaignId: String, val variationGroupId: String,
val variationId: String, val isReference: Boolean, val value: Any?, val campaignType : String) {
data class Modification(
val key: String, val campaignId: String, val variationGroupId: String,
val variationId: String, val isReference: Boolean, val value: Any?, val campaignType: String,
val slug: String
) {

override fun toString(): String {
return "Modification(key='$key', campaignId='$campaignId', variationGroupId='$variationGroupId'," +
" variationId='$variationId', isReference=$isReference, value=$value)"
" variationId='$variationId', isReference=$isReference, value=$value, slug=$slug)"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ data class Modifications(

companion object {

fun parse(campaignId: String, campaignType : String, variationGroupId: String, variationId: String, isReference: Boolean, modificationsObj: JSONObject): Modifications? {
fun parse(campaignId: String, campaignType : String, slug: String, variationGroupId: String, variationId: String, isReference: Boolean, modificationsObj: JSONObject): Modifications? {
return try {
val type = modificationsObj.getString("type")
val values: HashMap<String, Modification> = HashMap()
val valueObj = modificationsObj.getJSONObject("value")
for (key in valueObj.keys()) {
val value = if (valueObj.isNull(key)) null else valueObj[key]
if (value is Boolean || value is Number || value is String || value is JSONObject || value is JSONArray || value == null)
values[key] = Modification(key, campaignId, variationGroupId, variationId, isReference, value, campaignType)
values[key] = Modification(key, campaignId, variationGroupId, variationId, isReference, value, campaignType, slug)
else
FlagshipLogManager.log(FlagshipLogManager.Tag.PARSING, LogManager.Level.ERROR, FlagshipConstants.Errors.PARSING_MODIFICATION_ERROR)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ data class Variation(val campaignId : String, val variationGroupId : String, val

companion object {

fun parse(bucketingMode : Boolean, campaignId: String, campaignType: String, variationGroupId: String, variationObj: JSONObject): Variation? {
fun parse(bucketingMode : Boolean, campaignId: String, campaignType: String, slug: String, variationGroupId: String, variationObj: JSONObject): Variation? {
return try {
val variationId = variationObj.getString("id")
val isReference = variationObj.optBoolean("reference", false)
val modifications: Modifications? = Modifications.parse(campaignId, campaignType, variationGroupId,
val modifications: Modifications? = Modifications.parse(campaignId, campaignType, slug, variationGroupId,
variationId, isReference, variationObj.getJSONObject("modifications"))
val allocation = variationObj.optInt("allocation", if (bucketingMode) 0 else 100)
//In Api mode always 100%, in bucketing mode the variations at 0% are loaded just to check if it matches one in cache at selection time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ data class VariationGroup(val campaignId: String, val variationGroupId: String,
}

companion object {
fun parse(campaignId: String, campaignType: String, variationGroupsObj: JSONObject, bucketing: Boolean): VariationGroup? {
fun parse(campaignId: String, campaignType: String, slug: String, variationGroupsObj: JSONObject, bucketing: Boolean): VariationGroup? {
return try {
val variationGroupId =
variationGroupsObj.getString(if (bucketing) "id" else "variationGroupId")
Expand All @@ -55,15 +55,15 @@ data class VariationGroup(val campaignId: String, val variationGroupId: String,
if (!bucketing) {
// api
variationGroupsObj.optJSONObject("variation")?.let { variationObj ->
Variation.parse(bucketing, campaignId, campaignType, variationGroupId, variationObj)?.let { variation ->
Variation.parse(bucketing, campaignId, campaignType, slug, variationGroupId, variationObj)?.let { variation ->
variations[variation.variationId] = variation
}
}
} else {
//bucketing
variationGroupsObj.optJSONArray("variations")?.let { variationArr ->
for (variationObj in variationArr) {
Variation.parse(bucketing, campaignId, campaignType, variationGroupId, variationObj)?.let { variation ->
Variation.parse(bucketing, campaignId, campaignType, slug, variationGroupId, variationObj)?.let { variation ->
variations[variation.variationId] = variation
}
}
Expand Down
1 change: 1 addition & 0 deletions flagship/src/test/assets/bucketing_response_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
{
"id": "brjjpk7734cg0sl5llll",
"type": "ab",
"slug": "campaignSlug",
"variationGroups": [
{
"id": "brjjpk7734cg0sl5mmmm",
Expand Down
8 changes: 7 additions & 1 deletion flagship/src/test/java/com/abtasty/flagship/FlagshipTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ class FlagshipTests {
assertEquals(false, rank_plus.metadata().isReference)
assertEquals("ab", rank_plus.metadata().campaignType)
assertEquals(true, rank_plus.metadata().exists())
assertEquals(5, rank_plus.metadata().toJson().length())
assertEquals(6, rank_plus.metadata().toJson().length())

val do_not_exists = visitor.getFlag("do_not_exists", "a")
assertEquals("a", do_not_exists.value( false))
Expand All @@ -1508,6 +1508,12 @@ class FlagshipTests {
Thread.sleep(1500)
assertEquals(6, activateLatch.count)

//testing slug

assertEquals("", visitor.getFlag("visitorIdColor", "#00000000").metadata().slug)
assertEquals("campaignSlug", visitor.getFlag("rank_plus", "#00000000").metadata().slug)
assertEquals("", visitor.getFlag("eflzjefl", "#00000000").metadata().slug)

// System.out.println("=> " + visitor.getFlag("rank_plus", null).value(true))

}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip

0 comments on commit 68fdbef

Please sign in to comment.