From 5cced41a2716b540590313fef1f5578b608278e9 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Mon, 12 Aug 2024 13:47:43 +0530 Subject: [PATCH 1/3] feat: fetch asset by query implementation and test cases --- .../com/contentstack/sdk/AssetTestCase.java | 75 +++++++++++++++++++ .../com/contentstack/sdk/AssetLibrary.java | 15 ++++ 2 files changed, 90 insertions(+) diff --git a/contentstack/src/androidTest/java/com/contentstack/sdk/AssetTestCase.java b/contentstack/src/androidTest/java/com/contentstack/sdk/AssetTestCase.java index 7137b885..3f46ad7f 100644 --- a/contentstack/src/androidTest/java/com/contentstack/sdk/AssetTestCase.java +++ b/contentstack/src/androidTest/java/com/contentstack/sdk/AssetTestCase.java @@ -9,9 +9,11 @@ import org.junit.runners.MethodSorters; import java.util.List; +import java.util.concurrent.CountDownLatch; import static junit.framework.Assert.assertTrue; import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.assertNotNull; import androidx.test.InstrumentationRegistry; import androidx.test.core.app.ApplicationProvider; @@ -22,6 +24,8 @@ public class AssetTestCase { private final String TAG = AssetTestCase.class.getSimpleName(); private static String assetUid = BuildConfig.assetUID; private static Stack stack; + private static CountDownLatch latch; + @BeforeClass public static void oneTimeSetUp() throws Exception { @@ -191,4 +195,75 @@ public void test_GCP_NA() throws Exception { stack = Contentstack.stack(appContext, DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config); } + @Test + public void test_I_fetch_asset_by_title() { + final AssetLibrary assetLibrary = stack.assetLibrary().where("title", "iot-icon.png"); + assetLibrary.fetchAll(new FetchAssetsCallback() { + @Override + public void onCompletion(ResponseType responseType, List assets, Error error) { + if (error == null) { + for (Asset asset : assets) { + Log.d("RESULT:", "resp" + asset.json); + } + } + } + }); + } + + @Test + public void test_J_fetch_asset_by_tags() { + final AssetLibrary assetLibrary = stack.assetLibrary().where("tags","tag1"); + assetLibrary.fetchAll(new FetchAssetsCallback() { + @Override + public void onCompletion(ResponseType responseType, List assets, Error error) { + if (error == null) { + for( Asset asset : assets){ + Log.d("RESULT:", "resp" + asset.json); + } + assertTrue(assets.size()>0); + } + } + }); + } + + @Test + public void test_K_fetch_asset_by_description() { + final AssetLibrary assetLibrary= stack.assetLibrary().where("description","Page1"); + assetLibrary.fetchAll(new FetchAssetsCallback() { + @Override + public void onCompletion(ResponseType responseType, List assets, Error error) { + for(Asset asset : assets){ + Log.d("RESULT:", "resp" + asset.toJSON()); + } + assertTrue(assets.size()>0); + } + }); + } + + @Test + public void test_L_fetch_asset_invalid() { + final AssetLibrary assetLibrary = stack.assetLibrary().where("title",null); + assetLibrary.fetchAll(new FetchAssetsCallback() { + @Override + public void onCompletion(ResponseType responseType, List assets, Error error) { + Log.e("RESULT:", "ERROR:"+ error.errorMessage); + } + }); + + } + + @Test + public void test_M_fetch_asset_empty_title() { + final AssetLibrary assetLibrary = stack.assetLibrary().where("title",""); + assetLibrary.fetchAll(new FetchAssetsCallback() { + @Override + public void onCompletion(ResponseType responseType, List assets, Error error) { + for(Asset asset : assets){ + Log.d("RESULT:", "resp: " + asset.toJSON()); + } + assertEquals(0, assets.size()); + } + }); + } + } diff --git a/contentstack/src/main/java/com/contentstack/sdk/AssetLibrary.java b/contentstack/src/main/java/com/contentstack/sdk/AssetLibrary.java index 48a081d8..973a3c08 100644 --- a/contentstack/src/main/java/com/contentstack/sdk/AssetLibrary.java +++ b/contentstack/src/main/java/com/contentstack/sdk/AssetLibrary.java @@ -452,5 +452,20 @@ public AssetLibrary includeMetadata() { } return this; } + public AssetLibrary where(String key, String value) { + if (value != null) { + try { + JSONObject queryParams = new JSONObject(); + queryParams.put(key, value); + urlQueries.put("query", queryParams); + } catch (JSONException e) { + Log.e(TAG, "JSON error: " + e.getLocalizedMessage()); + } + } else { + Log.e(TAG, "Value for key '" + key + "' is null. Skipping addition to query."); + } + return this; + } + } From e9ec7f132441d20abb847fa780c6d2d0f759bf07 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Tue, 13 Aug 2024 10:50:49 +0530 Subject: [PATCH 2/3] chore: version bump --- CHANGELOG.md | 8 ++++++++ contentstack/build.gradle | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca4d346a..b5d2e1c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # CHANGELOG +## Version 3.16.1 + +### Date: 21-August-2024 + +- Fetch Asset by query + +--- + ## Version 3.16.0 ### Date: 31-July-2024 diff --git a/contentstack/build.gradle b/contentstack/build.gradle index 878f55f8..68257fdc 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", "3.16.1") pom { name = "contentstack-android" From c61e0a3544cc385cd6524ef6aa1aa61e9c015d24 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Tue, 20 Aug 2024 12:29:05 +0530 Subject: [PATCH 3/3] fix: SRE issue --- .../src/main/java/com/contentstack/sdk/SDKUtil.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/contentstack/src/main/java/com/contentstack/sdk/SDKUtil.java b/contentstack/src/main/java/com/contentstack/sdk/SDKUtil.java index 72cf092f..8220aa46 100755 --- a/contentstack/src/main/java/com/contentstack/sdk/SDKUtil.java +++ b/contentstack/src/main/java/com/contentstack/sdk/SDKUtil.java @@ -150,12 +150,9 @@ public String getSHAFromString(String value) { // Create Hex String // deepcode ignore ApiMigration: StringBuffer hexString = new StringBuffer(); - for (int i = 0; i < messageDigest.length; i++) { - String hex = Integer.toHexString(0xFF & messageDigest[i]); - if (hex.length() == 1) { - hexString.append('0'); - } - hexString.append(hex); + for (byte b : messageDigest) { + // Format each byte as two-digit hexadecimal + hexString.append(String.format("%02X", b)); } return hexString.toString();