From c7e1b4e067903e12027f433fdc767b64f07a7f53 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Thu, 27 Jun 2024 15:59:51 +0530 Subject: [PATCH 1/4] feat : variants implementation and testcases --- contentstack/build.gradle | 12 +++---- .../com/contentstack/sdk/EntryTestCase.java | 25 +++++++++++++ .../main/java/com/contentstack/sdk/Entry.java | 36 +++++++++++++++++++ 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/contentstack/build.gradle b/contentstack/build.gradle index 878f55f8..f15adf45 100755 --- a/contentstack/build.gradle +++ b/contentstack/build.gradle @@ -118,12 +118,12 @@ android { testCoverageEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - buildConfigField "String", "host", localProperties['host'] - buildConfigField "String", "APIKey", localProperties['APIKey'] - buildConfigField "String", "deliveryToken", localProperties['deliveryToken'] - buildConfigField "String", "environment", localProperties['environment'] - buildConfigField "String", "contentTypeUID", localProperties['contentType'] - buildConfigField "String", "assetUID", localProperties['assetUid'] + buildConfigField "String", "host", localProperties['host'] + buildConfigField "String", "APIKey", localProperties['APIKey'] + buildConfigField "String", "deliveryToken", localProperties['deliveryToken'] + buildConfigField "String", "environment", localProperties['environment'] + buildConfigField "String", "contentTypeUID", localProperties['contentType'] + buildConfigField "String", "assetUID", localProperties['assetUid'] } release { minifyEnabled false diff --git a/contentstack/src/androidTest/java/com/contentstack/sdk/EntryTestCase.java b/contentstack/src/androidTest/java/com/contentstack/sdk/EntryTestCase.java index b9b40beb..a2c4661c 100644 --- a/contentstack/src/androidTest/java/com/contentstack/sdk/EntryTestCase.java +++ b/contentstack/src/androidTest/java/com/contentstack/sdk/EntryTestCase.java @@ -27,6 +27,9 @@ public class EntryTestCase { private static final String CONTENT_TYPE_UID = BuildConfig.contentTypeUID; private static CountDownLatch latch; private static Stack stack; + private static String variantUID = BuildConfig.variantUID; + private static String variantEntryUID = BuildConfig.variantEntryUID; + private static String[] variantsUID = BuildConfig.variantsUID; @BeforeClass @@ -319,4 +322,26 @@ public void onCompletion(ResponseType responseType, Error error) { latch.await(); } + @Test + public void VariantsTestSingleUid(){ + final Entry entry = stack.contentType("author").entry(variantEntryUID).variants(variantUID); + entry.fetch(new EntryResultCallBack() { + @Override + public void onCompletion(ResponseType responseType, Error error) { + assertEquals(variantUID, entry.getHeaders().get("x-cs-variant-uid")); + System.out.println(entry.toJSON()); + } + }); + } + @Test + public void VariantsTestArray(){ + final Entry entry = stack.contentType("author").entry(variantEntryUID).variants(variantsUID); + entry.fetch(new EntryResultCallBack() { + @Override + public void onCompletion(ResponseType responseType, Error error) { + System.out.println(entry.toJSON()); + } + }); + } + } \ No newline at end of file diff --git a/contentstack/src/main/java/com/contentstack/sdk/Entry.java b/contentstack/src/main/java/com/contentstack/sdk/Entry.java index f315392c..dd0e6696 100755 --- a/contentstack/src/main/java/com/contentstack/sdk/Entry.java +++ b/contentstack/src/main/java/com/contentstack/sdk/Entry.java @@ -1494,4 +1494,40 @@ public Entry includeMetadata() { } return this; } + /** + * method variants + * memberof Entry + * description The variant header will be added to client + * returns {Entry} + * example + * import contentstack from '@contentstack/delivery-sdk' + * + * Stack stack = contentstack.Stack("apiKey", "deliveryToken", + * "environment"); + * Entry entry = + * stack.contentType("user").entry("entry_uid").variant("variant_uid").fetch(); + */ + public Entry variants(String variants){ + if (variants != null && variants.length() > 0) { + this.localHeader.put("x-cs-variant-uid", variants.trim()); + } + return this; + + } + public Entry variants(String[] variants){ + if (variants != null && variants.length > 0) { + List variantList = new ArrayList<>(); + for (String variant : variants) { + if(variant != null && !variant.trim().isEmpty()) + variantList.add(variant.trim()); + } + if(!variantList.isEmpty()){ + this.localHeader.put("x-cs-variant-uid", String.join(", ", variantList)); + } + } + return this; + } + public ArrayMap getHeaders() { + return localHeader; + } } From 5b2dc75b74101fe1ce5a3d35e79f3204271142ce Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Tue, 20 Aug 2024 15:21:40 +0530 Subject: [PATCH 2/4] chore: version bump done need to add changelog --- contentstack/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contentstack/build.gradle b/contentstack/build.gradle index f15adf45..ca63fb19 100755 --- a/contentstack/build.gradle +++ b/contentstack/build.gradle @@ -10,7 +10,7 @@ android.buildFeatures.buildConfig true mavenPublishing { publishToMavenCentral(SonatypeHost.DEFAULT) signAllPublications() - coordinates("com.contentstack.sdk", "android", "3.16.0") + coordinates("com.contentstack.sdk", "android", "4.0.0") pom { name = "contentstack-android" From 56eb5a98d05cfce735a7e796703c3d3c5fba50dc Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Wed, 11 Sep 2024 17:53:22 +0530 Subject: [PATCH 3/4] chore: buildconfig contains variant properties --- contentstack/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/contentstack/build.gradle b/contentstack/build.gradle index ca63fb19..a225af9d 100755 --- a/contentstack/build.gradle +++ b/contentstack/build.gradle @@ -112,6 +112,8 @@ android { def localProperties = new Properties() localProperties.load(new FileInputStream(rootProject.file("local.properties"))) + def variantsArray = localProperties['variantsUID']?.split(",")?.collect { it.trim() } + def variantsAsArrayString = 'new String[] {' + variantsArray.collect { "\"$it\"" }.join(", ") + '}' buildTypes { debug { debuggable true @@ -124,6 +126,9 @@ android { buildConfigField "String", "environment", localProperties['environment'] buildConfigField "String", "contentTypeUID", localProperties['contentType'] buildConfigField "String", "assetUID", localProperties['assetUid'] + buildConfigField "String", "variantUID", localProperties['variantUID'] + buildConfigField "String", "variantEntryUID", localProperties['variantEntryUID'] + buildConfigField "String[]", "variantsUID", variantsAsArrayString } release { minifyEnabled false From d547e50c7ffb84a79cf9acdad38db46eaf82fab7 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Thu, 12 Sep 2024 11:49:06 +0530 Subject: [PATCH 4/4] fix: sca-scan workflow --- contentstack/build.gradle | 24 +++++++++++-------- .../com/contentstack/sdk/EntryTestCase.java | 4 ++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/contentstack/build.gradle b/contentstack/build.gradle index a225af9d..eaccd3e0 100755 --- a/contentstack/build.gradle +++ b/contentstack/build.gradle @@ -112,22 +112,26 @@ android { def localProperties = new Properties() localProperties.load(new FileInputStream(rootProject.file("local.properties"))) - def variantsArray = localProperties['variantsUID']?.split(",")?.collect { it.trim() } - def variantsAsArrayString = 'new String[] {' + variantsArray.collect { "\"$it\"" }.join(", ") + '}' + def getPropertyOrEmpty = { key -> + def value = localProperties.getProperty(key) + return value != null ? "$value" : "\"\"" + } + def variantsArray = localProperties.getProperty('variantsUID')?.split(",")?.collect { it.trim() } + def variantsAsArrayString = variantsArray ? 'new String[] {' + variantsArray.collect { "\"$it\"" }.join(", ") + '}' : "new String[0]" buildTypes { debug { debuggable true testCoverageEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - buildConfigField "String", "host", localProperties['host'] - buildConfigField "String", "APIKey", localProperties['APIKey'] - buildConfigField "String", "deliveryToken", localProperties['deliveryToken'] - buildConfigField "String", "environment", localProperties['environment'] - buildConfigField "String", "contentTypeUID", localProperties['contentType'] - buildConfigField "String", "assetUID", localProperties['assetUid'] - buildConfigField "String", "variantUID", localProperties['variantUID'] - buildConfigField "String", "variantEntryUID", localProperties['variantEntryUID'] + buildConfigField "String", "host", getPropertyOrEmpty('host') + buildConfigField "String", "APIKey", getPropertyOrEmpty('APIKey') + buildConfigField "String", "deliveryToken", getPropertyOrEmpty('deliveryToken') + buildConfigField "String", "environment", getPropertyOrEmpty('environment') + buildConfigField "String", "contentTypeUID", getPropertyOrEmpty('contentType') + buildConfigField "String", "assetUID", getPropertyOrEmpty('assetUid') + buildConfigField "String", "variantUID", getPropertyOrEmpty('variantUID') + buildConfigField "String", "variantEntryUID", getPropertyOrEmpty('variantEntryUID') buildConfigField "String[]", "variantsUID", variantsAsArrayString } release { diff --git a/contentstack/src/androidTest/java/com/contentstack/sdk/EntryTestCase.java b/contentstack/src/androidTest/java/com/contentstack/sdk/EntryTestCase.java index a2c4661c..7a78dad4 100644 --- a/contentstack/src/androidTest/java/com/contentstack/sdk/EntryTestCase.java +++ b/contentstack/src/androidTest/java/com/contentstack/sdk/EntryTestCase.java @@ -324,7 +324,7 @@ public void onCompletion(ResponseType responseType, Error error) { @Test public void VariantsTestSingleUid(){ - final Entry entry = stack.contentType("author").entry(variantEntryUID).variants(variantUID); + final Entry entry = stack.contentType("product").entry(variantEntryUID).variants(variantUID); entry.fetch(new EntryResultCallBack() { @Override public void onCompletion(ResponseType responseType, Error error) { @@ -335,7 +335,7 @@ public void onCompletion(ResponseType responseType, Error error) { } @Test public void VariantsTestArray(){ - final Entry entry = stack.contentType("author").entry(variantEntryUID).variants(variantsUID); + final Entry entry = stack.contentType("product").entry(variantEntryUID).variants(variantsUID); entry.fetch(new EntryResultCallBack() { @Override public void onCompletion(ResponseType responseType, Error error) {