diff --git a/CHANGELOG.md b/CHANGELOG.md
index 992967b9..e6b37207 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,18 @@
# CHANGELOG
+## Version 3.12.0
+
+### Date: 02-May-2023
+
+- Added support for include metadata in asset, entry and query class
+- Added support of Region for Azure-EU
+- General code and API document improvements
+- Breaking changes : PublishType Enums are updated to all CAPS
+- Kotlin support removed due to build issue
+- EntryModel publish_details parsing issue fixed #30
+
+---
+
## Version 3.11.0
### Date: 08-Feb-2023
@@ -131,15 +144,8 @@ Below two support from the Config class has been removed permanently
Change:
- Removed support for unsafe (HTTP) request.
-- Below two breaking changes from Config class has been deprecated
-
-```java
-@Deprecated
-public void setSSL(boolean isSSL)setSSL()
-
-@Deprecated
-public boolean isSSL()
-```
+- Deprecated setSSL(boolean isSSL)setSSL() from config class
+- Deprecated isSSL() from config class
---
@@ -172,11 +178,11 @@ Added below function support for sync in Stack class
New Features:
- Entry
- - added method ‘addParam’
+ - added method ‘addParam’
- Query
- - added method 'addParam'
+ - added method 'addParam'
- Asset
- - added method ‘addParam'
+ - added method ‘addParam'
---
@@ -187,21 +193,21 @@ New Features:
New Features:
- Stack
- - added method 'ImageTransform'
+ - added method 'ImageTransform'
- Query
- - added method 'includeContentType'
+ - added method 'includeContentType'
- QueryResult
- - added method 'content_type'
+ - added method 'content_type'
- API Modifications:
- - None
+ - None
API deprecation:
- Query
- - Deprecated method 'includeSchema'
+ - Deprecated method 'includeSchema'
- Bug Fixes:
- - None
+ - None
---
@@ -210,18 +216,18 @@ API deprecation:
### Date: 28-July-2017
- New Features:
- - None
+ - None
- API Modifications:
- - None
+ - None
API deprecation:
None
- Bug Fixes:
- - Cache Policy bug fixed.
- - Cache Policy timeout increased.
+ - Cache Policy bug fixed.
+ - Cache Policy timeout increased.
---
@@ -234,15 +240,18 @@ New Features:
- None
API Modifications:
- - None
+
+- None
API deprecation:
- - Asset
+
+- Asset
1] Removed getPublishDetails() method. Entry 1] Removed getPublishDetails() method.
Bug Fixes:
- - None.
+
+- None.
---
@@ -251,10 +260,12 @@ Bug Fixes:
### Date: 17-May-2017
New Features:
- - None
+
+- None
API Modifications:
- - None
+
+- None
API deprecation:
@@ -275,16 +286,16 @@ New Features:
Added new class Group
Entry
- 1] Added getAllEntries(String refKey, String refContentType) method.
- 2] Added getGroups(String key) method.
- 3] Added getGroup(String key) method.
+1] Added getAllEntries(String refKey, String refContentType) method.
+2] Added getGroups(String key) method.
+3] Added getGroup(String key) method.
Asset
- 1] Added setCachePolicy(CachePolicy policy) method.
- 2] Added getTags() method.
+1] Added setCachePolicy(CachePolicy policy) method.
+2] Added getTags() method.
AssetLibrary
- 1] Added setCachePolicy(CachePolicy policy) method.
+1] Added setCachePolicy(CachePolicy policy) method.
API Modifications:
@@ -320,7 +331,7 @@ environment, Config config) method.
Stack 1] Added asset() method. 2] Added assetLibrary() method.
Entry
- 1] Added getPublishDetails() method.
+1] Added getPublishDetails() method.
API Modifications:
@@ -332,20 +343,20 @@ Conetntstack 1] Removed stack(Context context, String stackApiKey, String access
environment, boolean isEnvironmentUid) method.
Stack
- 1] Removed setVersion(String version) method.
- 2] Removed setURL(String hostName, boolean isSSL) method.
- 3] Removed setEnvironment(String environment, boolean isEnvironmentUid) method.
- 4] Removed isEnvironmentUid() method.
- 5] Removed getEnvironment() method.
- 6] Removed getVersion() method.
- 7] Removed getURL() method
+1] Removed setVersion(String version) method.
+2] Removed setURL(String hostName, boolean isSSL) method.
+3] Removed setEnvironment(String environment, boolean isEnvironmentUid) method.
+4] Removed isEnvironmentUid() method.
+5] Removed getEnvironment() method.
+6] Removed getVersion() method.
+7] Removed getURL() method
Entry
- 1] Removed getMetadata() method.
+1] Removed getMetadata() method.
Query
- 1] Removed afterUid() method.
- 2] Removed beforeUid() method.
+1] Removed afterUid() method.
+2] Removed beforeUid() method.
Bug Fixes:
@@ -379,17 +390,20 @@ Fixed API calls issue for Android 7.0 Nougat.
### Date: 22-September-2016
New Features:
- - None
-API Modifications:
- - None
+
+- None
+ API Modifications:
+- None
API deprecation:
- - None
+
+- None
Bug Fixes:
- - Query 1] Fixed search method issue causing improper result.
- - Entry 1] Fixed includeReference method issue causing improper result. 2] Fixed fetch method which
-now return response as per environment.
+
+- Query 1] Fixed search method issue causing improper result.
+- Entry 1] Fixed includeReference method issue causing improper result. 2] Fixed fetch method which
+ now return response as per environment.
---
diff --git a/build.gradle b/build.gradle
index 0e84797f..4fffe10f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,7 +1,5 @@
buildscript {
-
- ext.jacocoVersion = '0.8.8'
-
+ ext.jacoco_version = '0.8.8'
repositories {
maven { url "https://plugins.gradle.org/m2/" }
google()
@@ -9,16 +7,15 @@ buildscript {
}
dependencies {
- classpath 'com.android.tools.build:gradle:7.0.4' //4.1.3
+ classpath "com.android.tools.build:gradle:7.2.2" //7.0.4
classpath 'io.github.gradle-nexus:publish-plugin:1.1.0'
- // NOTE: Do not place your application dependencies here
- classpath "org.jacoco:org.jacoco.core:$jacocoVersion"
+ classpath "org.jacoco:org.jacoco.core:$jacoco_version"
}
}
apply plugin: 'io.github.gradle-nexus.publish-plugin'
apply from: "${rootDir}/scripts/publish-root.gradle"
-task clean(type: Delete) {
+tasks.register('clean', Delete) {
delete rootProject.buildDir
}
\ No newline at end of file
diff --git a/contentstack/build.gradle b/contentstack/build.gradle
index 4077cbf1..c91cacea 100755
--- a/contentstack/build.gradle
+++ b/contentstack/build.gradle
@@ -1,61 +1,22 @@
apply plugin: 'com.android.library'
apply plugin: 'jacoco'
-ext {
- PUBLISH_GROUP_ID = 'com.contentstack.sdk'
- PUBLISH_ARTIFACT_ID = 'android'
- PUBLISH_VERSION = '3.11.0'
- PUBLISH_DESCRIPTION = 'The Content Delivery SDK is used to retrieve content from your Contentstack account and deliver it to your web or mobile properties.'
- PUBLISH_URL = 'https://github.com/contentstack/contentstack-android'
- PUBLISH_LICENSE_NAME = 'MIT License'
- PUBLISH_LICENSE_URL = 'https://github.com/contentstack/contentstack-android/blob/master/LICENSE'
- PUBLISH_DEVELOPER_ID = 'ishaileshmishra'
- PUBLISH_DEVELOPER_NAME = 'Shailesh Mishra'
- PUBLISH_DEVELOPER_EMAIL = 'shailesh.mishra@contentstack.com'
- PUBLISH_SCM_CONNECTION = 'scm:git@github.com:contentstack/contentstack-android'
- PUBLISH_SCM_DEVELOPER_CONNECTION = 'scm:git@github.com:contentstack/contentstack-android'
- PUBLISH_SCM_URL = 'https://github.com/contentstack/contentstack-android/tree/master'
-}
-
apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"
-def localProperties = new Properties()
-localProperties.load(new FileInputStream(rootProject.file("local.properties")))
-
android {
- compileSdkVersion 33
compileSdk 33
- buildToolsVersion '30.0.2'
-
defaultConfig {
- minSdkVersion 19
+ minSdk 19
+ targetSdk 33
versionCode 1
- versionName "1.0.0"
+ versionName "1.0"
+ multiDexEnabled true
+ vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
- debug {
- debuggable true
- testCoverageEnabled true
- buildConfigField "String", "host", localProperties['host']
- buildConfigField "String", "APIKey", localProperties['APIKey']
- buildConfigField "String", "deliveryToken", localProperties['deliveryToken']
- buildConfigField "String", "environment", localProperties['env']
- buildConfigField "String", "contentTypeUID", localProperties['contentType']
- buildConfigField "String", "assetUID", localProperties['assetUid']
- }
-
- release {
- minifyEnabled false
- 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['env']
- buildConfigField "String", "contentTypeUID", localProperties['contentType']
- buildConfigField "String", "assetUID", localProperties['assetUid']
- proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
- }
+ def localProperties = new Properties()
+ localProperties.load(new FileInputStream(rootProject.file("local.properties")))
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
@@ -74,12 +35,14 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
- //testImplementation 'junit:junit:5.9.2'
- // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api
- testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.2'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.android.volley:volley:1.2.1'
- androidTestImplementation 'androidx.test:core:1.5.0'
- androidTestImplementation "androidx.test:runner:1.5.2"
- androidTestImplementation "androidx.test:rules:1.5.0"
+ implementation 'androidx.test:core:1.5.0'
+ testImplementation 'junit:junit:4.13.2'
+ androidTestImplementation 'androidx.test.ext:junit:1.1.5'
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
+}
+java {
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
}
\ No newline at end of file
diff --git a/contentstack/src/androidTest/java/com/contentstack/sdk/AssetTestCase.java b/contentstack/src/androidTest/java/com/contentstack/sdk/AssetTestCase.java
deleted file mode 100644
index fb82ca09..00000000
--- a/contentstack/src/androidTest/java/com/contentstack/sdk/AssetTestCase.java
+++ /dev/null
@@ -1,180 +0,0 @@
-package com.contentstack.sdk;
-
-import static junit.framework.Assert.assertTrue;
-import static junit.framework.TestCase.assertEquals;
-
-import android.content.Context;
-import android.util.Log;
-
-import androidx.test.core.app.ApplicationProvider;
-
-import org.junit.BeforeClass;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-import java.util.List;
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class AssetTestCase {
-
- private final String TAG = AssetTestCase.class.getSimpleName();
- private static String assetUid = BuildConfig.assetUID;
- private static Stack stack;
-
- @BeforeClass
- public static void oneTimeSetUp() throws Exception {
- Context context = ApplicationProvider.getApplicationContext();
-
- Config config = new Config();
- String DEFAULT_API_KEY = BuildConfig.APIKey;
- String DEFAULT_DELIVERY_TOKEN = BuildConfig.deliveryToken;
- String DEFAULT_ENV = BuildConfig.environment;
- String DEFAULT_HOST = BuildConfig.host;
- config.setHost(DEFAULT_HOST);
- stack = Contentstack.stack(context, DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config);
- }
-
-
- @Test()
- public void test_A_getAllAssetsToSetAssetUID() {
- final AssetLibrary assetLibrary = stack.assetLibrary();
- assetLibrary.fetchAll(new FetchAssetsCallback() {
- @Override
- public void onCompletion(ResponseType responseType, List assets, Error error) {
- if (error == null) {
- Log.d(TAG, "response: " + assets.get(0).getAssetUid());
- assetUid = assets.get(0).getAssetUid();
- Log.e(assetUid, assetUid);
- }
- }
- });
-
- }
-
- @Test
- public void test_B_VerifyAssetUID() {
-
- final Asset asset = stack.asset(assetUid);
- asset.fetch(new FetchResultCallback() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- // Success Block.
- Log.d(TAG, "response: " + asset.getAssetUid());
- assertEquals(assetUid, asset.getAssetUid());
- }
- }
- });
- }
-
- @Test
- public void test_C_Asset_fetch() {
- final Asset asset = stack.asset(assetUid);
- asset.fetch(new FetchResultCallback() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- assertEquals(BuildConfig.assetUID, asset.getAssetUid());
- assertEquals("image/jpeg", asset.getFileType());
- assertEquals("phoenix2.jpg", asset.getFileName());
- assertEquals("482141", asset.getFileSize());
- } else {
- assertEquals(105, error.getErrorCode());
- }
- }
- });
- }
-
- @Test
- public void test_D_AssetLibrary_fetch() {
- final AssetLibrary assetLibrary = stack.assetLibrary();
- assetLibrary.fetchAll(new FetchAssetsCallback() {
- @Override
- public void onCompletion(ResponseType responseType, List assets, Error error) {
- if (error == null) {
- assets.forEach(asset -> {
- Log.d(TAG, "----Test--Asset-D--Success----" + asset.toJSON());
- Log.d(TAG, "----Test--Asset-D--Success----" + asset.getFileType());
- Log.d(TAG, "----Test--Asset-D--Success----" + asset.getCreatedBy());
- Log.d(TAG, "----Test--Asset-D--Success----" + asset.getUpdatedBy());
- Log.d(TAG, "----Test--Asset-D--Success----" + asset.getFileName());
- Log.d(TAG, "----Test--Asset-D--Success----" + asset.getFileSize());
- Log.d(TAG, "----Test--Asset-D--Success----" + asset.getAssetUid());
- Log.d(TAG, "----Test--Asset-D--Success----" + asset.getUrl());
- });
- }
- }
- });
- }
-
- @Test
- public void test_E_AssetLibrary_includeCount_fetch() {
- final AssetLibrary assetLibrary = stack.assetLibrary();
- assetLibrary.includeCount();
- assetLibrary.fetchAll(new FetchAssetsCallback() {
- @Override
- public void onCompletion(ResponseType responseType, List assets, Error error) {
- if (error == null) {
- assertEquals(16, assetLibrary.getCount());
- }
- }
- });
- }
-
- @Test
- public void test_F_AssetLibrary_includeRelativeUrl_fetch() {
- final AssetLibrary assetLibrary = stack.assetLibrary();
- assetLibrary.includeRelativeUrl();
- assetLibrary.fetchAll(new FetchAssetsCallback() {
- public void onCompletion(ResponseType responseType, List assets, Error error) {
- if (error == null) {
- assertTrue(assets.get(0).getUrl().contains("phoenix2.jpg"));
- }
- }
- });
- }
-
- @Test
- public void test_G_Include_Dimension() {
- final Asset asset = stack.asset(assetUid);
- asset.includeDimension().fetch(new FetchResultCallback() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- Log.d(TAG, asset.getAssetUid());
- assertEquals(assetUid, asset.getAssetUid());
- }
- }
- });
- }
-
-
- @Test
- public void test_H_include_fallback() {
- final Asset asset = stack.asset(assetUid);
- asset.includeFallback().fetch(new FetchResultCallback() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- Log.d(TAG, asset.getAssetUid());
- assertEquals(assetUid, asset.getAssetUid());
- }
- }
- });
- }
-
- @Test
- public void test_AZURE_NA() throws Exception {
- Config config = new Config();
- String DEFAULT_API_KEY = BuildConfig.APIKey;
- String DEFAULT_DELIVERY_TOKEN = BuildConfig.deliveryToken;
- String DEFAULT_ENV = BuildConfig.environment;
- String DEFAULT_HOST = BuildConfig.host;
- config.setHost(DEFAULT_HOST);
- config.setRegion(Config.ContentstackRegion.AZURE_NA);
- Context appContext = ApplicationProvider.getApplicationContext();
- stack = Contentstack.stack(appContext, DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config);
- }
-
-}
diff --git a/contentstack/src/androidTest/java/com/contentstack/sdk/EntryTestCase.java b/contentstack/src/androidTest/java/com/contentstack/sdk/EntryTestCase.java
deleted file mode 100644
index dc1fb492..00000000
--- a/contentstack/src/androidTest/java/com/contentstack/sdk/EntryTestCase.java
+++ /dev/null
@@ -1,334 +0,0 @@
-package com.contentstack.sdk;
-
-import android.content.Context;
-import android.util.Log;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.junit.*;
-import org.junit.runners.MethodSorters;
-
-import java.util.ArrayList;
-import java.util.concurrent.CountDownLatch;
-
-import static junit.framework.TestCase.*;
-
-import androidx.test.core.app.ApplicationProvider;
-
-
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class EntryTestCase {
-
- private final static String TAG = EntryTestCase.class.getSimpleName();
- private static String entryUID;
- private static final String CONTENT_TYPE_UID = BuildConfig.contentTypeUID;
- private static CountDownLatch latch;
- private static Stack stack;
-
-
- @BeforeClass
- public static void oneTimeSetUp() throws Exception {
- Context appContext = ApplicationProvider.getApplicationContext();
- Config config = new Config();
- String DEFAULT_HOST = BuildConfig.host;
- config.setHost(DEFAULT_HOST);
- stack = Contentstack.stack(appContext, BuildConfig.APIKey, BuildConfig.deliveryToken, BuildConfig.environment, config);
-
- latch = new CountDownLatch(1);
- Log.d(TAG, "test started...");
- }
-
- @AfterClass
- public static void oneTimeTearDown() {
- // one-time cleanup code
- Log.d(TAG, "When all the test cases of class finishes...");
- Log.d(TAG, "Total testcase: " + latch.getCount());
- }
-
- /**
- * Sets up the test fixture.
- * (Called before every test case method.)
- */
- @Before
- public void setUp() {
- latch = new CountDownLatch(1);
- }
-
-
- /**
- * Tears down the test fixture.
- * (Called after every test case method.)
- */
- @After
- public void tearDown() {
- Log.d(TAG, "Runs after every testcase completes.");
- latch.countDown();
- }
-
-
- @Test
- public void testCustomHeader() {
- final Query query = stack.contentType(CONTENT_TYPE_UID).query();
- query.setHeader("customHeaderKey", "customHeaderValue");
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- entryUID = queryresult.getResultObjects().get(15).getUid();
- }
- }
- });
- }
-
- @Test
- public void test_01_findAllEntries() {
- final Query query = stack.contentType(CONTENT_TYPE_UID).query();
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- entryUID = queryresult.getResultObjects().get(15).getUid();
- }
- }
- });
- }
-
- @Test
- public void test_02_only_fetch() {
- final Entry entry = stack.contentType(CONTENT_TYPE_UID).entry(entryUID);
- entry.only(new String[]{"price"});
- entry.fetch(new EntryResultCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- assertEquals(786, entry.toJSON().opt("price"));
- }
- }
- });
- }
-
- @Test
- public void test_03_except_fetch() {
- final Entry entry = stack.contentType(CONTENT_TYPE_UID).entry(entryUID);
- entry.except(new String[]{"title"});
- entry.fetch(new EntryResultCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- Log.e(TAG, entry.toJSON().optString("title"));
- } else {
- Log.e(TAG, error.getErrorMessage());
- }
- }
- });
- }
-
- @Test
- public void test_04_includeReference_fetch() {
- final Entry entry = stack.contentType(CONTENT_TYPE_UID).entry(entryUID);
- entry.includeReference("category");
- entry.fetch(new EntryResultCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- JSONArray categoryArray = entry.getJSONArray("category");
-
- try {
- for (int index = 0; index < categoryArray.length(); index++) {
- JSONObject array = (JSONObject) categoryArray.get(index);
- assertTrue(array.toString().contains("_content_type_uid"));
- }
- } catch (Exception e) {
- Log.e(TAG, e.getLocalizedMessage());
- }
-
- }
- }
- });
- }
-
- @Test
- public void test_05_includeReferenceOnly_fetch() {
- final Entry entry = stack.contentType(CONTENT_TYPE_UID).entry(entryUID);
- ArrayList strings = new ArrayList<>();
- strings.add("title");
- strings.add("orange");
- strings.add("mango");
- entry.onlyWithReferenceUid(strings, "category");
- entry.fetch(new EntryResultCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- assertEquals("laptop", entry.toJSON().optString("title"));
- }
- }
- });
-
- }
-
-
- @Test
- public void test_06_includeReferenceExcept_fetch() throws InterruptedException {
- final Entry entry = stack.contentType(CONTENT_TYPE_UID).entry(entryUID);
- ArrayList strings = new ArrayList<>();
- strings.add("color");
- strings.add("price_in_usd");
- entry.exceptWithReferenceUid(strings, "category");
- entry.fetch(new EntryResultCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- latch.countDown();
- } else {
- latch.countDown();
- }
-
- }
- });
- latch.await();
-
- }
-
-
- @Test
- public void test_07_getMarkdown_fetch() throws InterruptedException {
-
- final Entry entry = stack.contentType("user").entry(entryUID);
- entry.fetch(new EntryResultCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- latch.countDown();
- } else {
- latch.countDown();
- }
- }
- });
- latch.await();
- }
-
-
- @Test
- public void test_08_get() throws InterruptedException {
- final Entry entry = stack.contentType("user").entry(entryUID);
- entry.fetch(new EntryResultCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- latch.countDown();
- } else {
- latch.countDown();
- }
- }
- });
- latch.await();
- }
-
-
- @Test
- public void test_09_getParam() throws InterruptedException {
- final Entry entry = stack.contentType("user").entry(entryUID);
- entry.addParam("include_dimensions", "true");
- entry.fetch(new EntryResultCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- latch.countDown();
- } else {
- latch.countDown();
- }
- }
- });
- latch.await();
- }
-
-
- @Test
- public void test_10_IncludeReferenceContentTypeUID() throws InterruptedException {
- final Entry entry = stack.contentType("user").entry(entryUID);
- entry.includeReferenceContentTypeUID();
- entry.fetch(new EntryResultCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- JSONObject jsonResult = entry.toJSON();
- try {
- JSONArray cartList = (JSONArray) jsonResult.get("cart");
- Object whatTYPE = cartList.get(0);
- if (whatTYPE instanceof JSONObject) {
- assertTrue(true);
- }
- } catch (JSONException e) {
- Log.e(TAG, e.getLocalizedMessage());
- }
- latch.countDown();
- } else {
- latch.countDown();
- }
- }
- });
- latch.await();
-
- }
-
-
- @Test
- public void test_11_Locale() throws InterruptedException {
- final Entry entry = stack.contentType("user").entry(entryUID);
- entry.fetch(new EntryResultCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- String checkResp = entry.getLocale();
- Log.e(TAG, checkResp);
- latch.countDown();
- } else {
- latch.countDown();
- }
-
- }
- });
- latch.await();
- }
-
- @Test
- public void test_12_entry_except() throws InterruptedException {
- final Entry entry = stack.contentType("user").entry(entryUID);
- String[] allValues = {"color", "price_in_usd"};
- entry.except(allValues);
- entry.fetch(new EntryResultCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- String checkResp = entry.getLocale();
- Log.d(TAG, checkResp);
- latch.countDown();
- } else {
- latch.countDown();
- }
- }
- });
- latch.await();
- }
-
- @Test
- public void test_13_entry_include_embedded_items_unit_test() throws InterruptedException {
-
- final Entry entry = stack.contentType("user").entry(entryUID);
- entry.includeEmbeddedItems().fetch(new EntryResultCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, Error error) {
- if (error == null) {
- String checkResp = entry.getLocale();
- Log.d(TAG, checkResp);
- }
- boolean hasEmbeddedItemKey = entry.otherPostJSON.has("include_embedded_items[]");
- Assert.assertTrue(hasEmbeddedItemKey);
- latch.countDown();
- }
- });
- latch.await();
- }
-
-}
diff --git a/contentstack/src/androidTest/java/com/contentstack/sdk/ExampleInstrumentedTest.java b/contentstack/src/androidTest/java/com/contentstack/sdk/ExampleInstrumentedTest.java
new file mode 100644
index 00000000..b6c7c4e9
--- /dev/null
+++ b/contentstack/src/androidTest/java/com/contentstack/sdk/ExampleInstrumentedTest.java
@@ -0,0 +1,75 @@
+package com.contentstack.sdk;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import android.content.Context;
+
+import androidx.test.core.app.ApplicationProvider;
+import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Date;
+
+
+@RunWith(AndroidJUnit4ClassRunner.class)
+public class ExampleInstrumentedTest {
+
+ static final String apiKey = BuildConfig.APIKey;
+ static final String deliveryToken = BuildConfig.deliveryToken;
+ static final String environment = BuildConfig.environment;
+ static Stack stack = null;
+
+
+ @Test
+ public void useAppContext() throws Exception {
+ Context ctx = ApplicationProvider.getApplicationContext();
+ stack = Contentstack.stack(ctx, apiKey, deliveryToken, environment);
+ assertEquals("com.contentstack.sdk.test", ctx.getPackageName().toLowerCase());
+ }
+
+ @Test
+ public void testAPINotNull() {
+ assertNotNull(apiKey);
+ }
+
+ @Test
+ public void testDeliveryTokenNotNull() {
+ assertNotNull(deliveryToken);
+ }
+
+ @Test
+ public void testEnvironmentNotNull() {
+ assertNotNull(environment);
+ }
+
+ @Test
+ public void initSDK() {
+ stack.sync(null);
+ assertNotNull(stack.syncParams);
+ }
+
+ @Test
+ public void syncLocale() {
+ stack.syncLocale("ar-eu", new SyncResultCallBack() {
+ @Override
+ public void onCompletion(SyncStack syncStack, Error error) {
+
+ }
+ });
+ assertNotNull(stack.syncParams);
+ }
+
+
+ @Test
+ public void syncSDKWIthAllParams() {
+ stack.sync("content_type", new Date(), "en-us", Stack.PublishType.ENTRY_PUBLISHED, new SyncResultCallBack() {
+ @Override
+ public void onCompletion(SyncStack syncStack, Error error) {
+
+ }
+ });
+ assertNotNull(stack.syncParams);
+ }
+}
\ No newline at end of file
diff --git a/contentstack/src/androidTest/java/com/contentstack/sdk/QueryTestCase.java b/contentstack/src/androidTest/java/com/contentstack/sdk/QueryTestCase.java
deleted file mode 100644
index d5217610..00000000
--- a/contentstack/src/androidTest/java/com/contentstack/sdk/QueryTestCase.java
+++ /dev/null
@@ -1,654 +0,0 @@
-package com.contentstack.sdk;
-
-import android.content.Context;
-import android.util.Log;
-
-import org.json.JSONArray;
-import org.json.JSONObject;
-import org.junit.*;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import static junit.framework.TestCase.assertEquals;
-
-import androidx.test.core.app.ApplicationProvider;
-
-
-public class QueryTestCase {
-
- private static final String TAG = AssetTestCase.class.getSimpleName();
- private static Stack stack;
- private static Query query;
- private static final String contentTypeUID = BuildConfig.contentTypeUID;
-
- @BeforeClass
- public static void oneTimeSetUp() throws Exception {
- Context appContext = ApplicationProvider.getApplicationContext();
- Config config = new Config();
- String DEFAULT_API_KEY = BuildConfig.APIKey;
- String DEFAULT_DELIVERY_TOKEN = BuildConfig.deliveryToken;
- String DEFAULT_ENV = BuildConfig.environment;
- String DEFAULT_HOST = BuildConfig.host;
- config.setHost(DEFAULT_HOST);
- stack = Contentstack.stack(appContext, DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config);
- query = stack.contentType(contentTypeUID).query();
- }
-
-
- /**
- * Sets up the test fixture.
- * (Called before every test case method.)
- */
- @Before
- public void setUp() {
- query = stack.contentType(contentTypeUID).query();
- }
-
-
- @Test
- public void test_01_fetchAllEntries() {
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List listOfEntries = queryresult.getResultObjects();
- }
- }
- });
- }
-
- @Test()
- public void test_03_fetchSingleNonExistingEntry() {
- Query query = stack.contentType("categories").query();
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List listOfEntries = queryresult.getResultObjects();
- }
- }
- });
- }
-
- @Test
- public void test_04_fetchEntryWithIncludeReference() {
- query.includeReference("category");
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List listOfEntries = queryresult.getResultObjects();
- }
- }
- });
- }
-
-
- @Test
- public void test_05_fetchEntryNotContainedInField() {
- String[] containArray = new String[]{"Roti Maker", "kids dress"};
- query.notContainedIn("title", containArray);
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
-
- if (error == null) {
- List entries = queryresult.getResultObjects();
- int price = entries.get(0).toJSON().optInt("price");
- assertEquals(45, price);
- }
- }
- });
- }
-
-
- @Test
- public void test_07_fetchEntryNotEqualToField() {
- query.notEqualTo("title", "yellow t shirt");
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- entries.forEach(entry -> Log.i(TAG, entry.getString("title")));
- }
- }
- });
- }
-
-
- @Test
- public void test_08_fetchEntryGreaterThanEqualToField() {
- query.greaterThanOrEqualTo("price", 90);
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- entries.forEach(entry -> {
- //og.i(TAG,entry.getString("price"));
- });
- }
- }
- });
- }
-
-
- @Test
- public void test_09_fetchEntryGreaterThanField() {
- query.greaterThan("price", 90);
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- entries.forEach(entry -> {
- //Log.i(TAG,entry.getString("price");
- });
- }
- }
- });
- }
-
-
- @Test
- public void test_10_fetchEntryLessThanEqualField() {
- query.lessThanOrEqualTo("price", 90);
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- int price = entries.get(0).toJSON().optInt("price");
- assertEquals(45, price);
- }
- }
- });
- }
-
-
- @Test
- public void test_11_fetchEntryLessThanField() {
- query.lessThan("price", "90");
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List resp = queryresult.getResultObjects();
- resp.forEach(entry -> {
- Log.i(TAG, "Is price less than 90..? " + entry.get("price"));
- });
- }
- }
- });
- }
-
-
- @Test
- public void test_12_fetchEntriesWithOr() {
-
- ContentType ct = stack.contentType(contentTypeUID);
- Query orQuery = ct.query();
-
- Query query = ct.query();
- query.lessThan("price", 90);
-
- Query subQuery = ct.query();
- subQuery.containedIn("discount", new Integer[]{20, 45});
-
- ArrayList array = new ArrayList();
- array.add(query);
- array.add(subQuery);
- orQuery.or(array);
-
- orQuery.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List listOfEntries = queryresult.getResultObjects();
- }
- }
- });
- }
-
-
- @Test
- public void test_13_fetchEntriesWithAnd() {
-
- ContentType ct = stack.contentType(contentTypeUID);
- Query orQuery = ct.query();
-
- Query query = ct.query();
- query.lessThan("price", 90);
-
- Query subQuery = ct.query();
- subQuery.containedIn("discount", new Integer[]{20, 45});
-
- ArrayList array = new ArrayList();
- array.add(query);
- array.add(subQuery);
-
- orQuery.and(array);
- orQuery.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List listOfEntries = queryresult.getResultObjects();
- }
- }
- });
- }
-
-
- @Test
- public void test_14_addQuery() {
- query.addQuery("limit", "8");
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List listOfEntries = queryresult.getResultObjects();
- }
- }
- });
- }
-
-
- @Test
- public void test_15_removeQueryFromQuery() {
- query.addQuery("limit", "8");
- query.removeQuery("limit");
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List listOfEntries = queryresult.getResultObjects();
- }
- }
- });
- }
-
-
- @Test
- public void test_16_includeSchema() {
- query.includeContentType();
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- JSONObject contentTypeObj = queryresult.getContentType();
- }
- }
- });
- }
-
-
- @Test
- public void test_17_search() {
- query.search("dress");
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- for (Entry entry : entries) {
- JSONObject jsonObject = entry.toJSON();
- Iterator iter = jsonObject.keys();
- while (iter.hasNext()) {
- String key = iter.next();
- try {
- Object value = jsonObject.opt(key);
- if (value instanceof String && ((String) value).contains("dress"))
- Log.i(TAG, value.toString());
- } catch (Exception e) {
- Log.i(TAG, "----------------setQueryJson" + e.toString());
- }
- }
- }
- }
- }
- });
- }
-
-
- @Test
- public void test_18_ascending() {
- query.ascending("title");
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- for (Entry entry : entries) {
- Log.i(TAG, entry.getString("title"));
- }
- }
- }
- });
- }
-
-
- @Test
- public void test_19_descending() {
- query.descending("title");
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- for (Entry entry : entries) {
- Log.i(TAG, entry.getString("title"));
- }
- }
- }
- });
- }
-
-
- @Test
- public void test_20_limit() {
- query.limit(3);
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- for (Entry entry : entries) {
- Log.i(TAG, " entry = [" + entry.getString("title") + "]");
- }
- }
- }
- });
- }
-
-
- @Test
- public void test_21_skip() {
- query.skip(3);
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- }
- }
- });
- }
-
-
- @Test
- public void test_22_only() {
- query.only(new String[]{"price"});
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- }
- }
- });
- }
-
-
- @Test
- public void test_23_except() {
- query.locale("en-eu");
- query.except(new String[]{"price", "chutiya"});
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- }
- }
- });
- }
-
-
- @Test
- public void test_24_count() {
- query.count();
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- int count = queryresult.getCount();
- }
- }
- });
- }
-
-
- @Test
- public void test_25_regex() {
- query.regex("title", "lap*", "i");
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- }
- }
- });
- }
-
-
- @Test
- public void test_26_exist() {
- query.exists("title");
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- }
- }
- });
- }
-
-
- @Test
- public void test_27_notExist() {
- query.notExists("price1");
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- int entryCount = queryresult.getCount();
- }
- }
- });
-
-
- }
-
-
- @Test
- public void test_28_tags() {
- query.tags(new String[]{"pink"});
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- }
- }
- });
-
-
- }
-
-
- @Test
- public void test_29_language() {
- query.language(Language.ENGLISH_UNITED_KINGDOM);
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- }
- }
- });
-
-
- }
-
-
- @Test
- public void test_33_findOne() {
- query.includeCount();
- query.where("in_stock", true);
- query.findOne(new SingleQueryResultCallback() {
- @Override
- public void onCompletion(ResponseType responseType, Entry entry, Error error) {
- if (error == null) {
- System.out.println("entry: " + entry);
- }
- }
- });
- }
-
-
- @Test
- public void test_34_complexFind() {
- query.notEqualTo("title", "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.*************************************Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.*************************************Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.*************************************Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.*************************************Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.************************************Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.************************************Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.************************************Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.************************************Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.************************************Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.************************************Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.************************************Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.************************************Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.*******");
- query.includeCount();
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- List entries = queryresult.getResultObjects();
- }
- }
- });
- }
-
-
- @Test
- public void test_35_includeSchema() {
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- JSONArray result;
- if (error == null) {
- result = queryresult.getSchema();
- }
- }
- });
- }
-
-
- @Test
- public void test_36_includeContentType() {
- query.includeContentType();
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- JSONObject entries = queryresult.getContentType();
- }
- }
- });
- }
-
-
- @Test
- public void test_38_include_content_type() {
- query.includeContentType();
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- JSONObject result;
- if (error == null) {
- result = queryresult.getContentType();
- }
- }
- });
- }
-
-
- @Test
- public void test_39_include_content_type() {
- query.includeContentType();
- query.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- JSONObject entries = queryresult.getContentType();
- }
- }
- });
- }
-
-
- @Test
- public void test_40_WithoutIncludeFallback() {
- Query fallbackQuery = stack.contentType("categories").query();
- fallbackQuery.locale("hi-in");
- fallbackQuery.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- assertEquals(0, queryresult.getResultObjects().size());
- fallbackQuery.includeFallback().locale("hi-in");
- fallbackQuery.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- assertEquals(0, queryresult.getResultObjects().size());
- }
- });
- }
- }
- });
- }
-
- @Test
- public void test_40_WithIncludeFallback() {
- Query fallbackQuery = stack.contentType("categories").query();
- fallbackQuery.locale("hi-in");
- fallbackQuery.find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- assertEquals(0, queryresult.getResultObjects().size());
- }
- }
- });
- }
-
-
- @Test
- public void test_41_entry_include_embedded_items_unit_test() {
-
- final Query query = stack.contentType("user").query();
- query.includeEmbeddedItems().find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- Entry checkResp = queryresult.getResultObjects().get(0);
- Log.d(TAG, checkResp.toString());
- }
- }
- });
- }
-
-
- @Test
- public void query_include_embedded_items_unit_test() throws Exception {
- final Query query = stack.contentType("testembededobjects").query();
- query.includeEmbeddedItems().find(new QueryResultsCallBack() {
- @Override
- public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
- if (error == null) {
- Entry checkResp = queryresult.getResultObjects().get(0);
- Log.d(TAG, queryresult.getResultObjects().toString());
- }
- }
- });
- }
-
-
-}
\ No newline at end of file
diff --git a/contentstack/src/androidTest/java/com/contentstack/sdk/TransformTestcase.java b/contentstack/src/androidTest/java/com/contentstack/sdk/TransformTestcase.java
deleted file mode 100644
index 7e60cfcb..00000000
--- a/contentstack/src/androidTest/java/com/contentstack/sdk/TransformTestcase.java
+++ /dev/null
@@ -1,240 +0,0 @@
-package com.contentstack.sdk;
-
-import android.content.Context;
-import android.util.Log;
-
-import androidx.test.core.app.ApplicationProvider;
-
-import org.junit.*;
-
-import java.util.LinkedHashMap;
-import java.util.concurrent.CountDownLatch;
-
-
-/**
- *
- */
-public class TransformTestcase {
-
- static final String TAG = TransformTestcase.class.getSimpleName();
- private static CountDownLatch latch;
- private static Stack stack;
- private final LinkedHashMap imageParams = new LinkedHashMap<>();
- private final String IMAGE_URL = "https://images.contentstack.io/v3/assets/download";
-
-
- @BeforeClass
- public static void oneTimeSetUp() throws Exception {
- Context appContext = ApplicationProvider.getApplicationContext();
-
- Config config = new Config();
- String DEFAULT_API_KEY = BuildConfig.APIKey;
- String DEFAULT_DELIVERY_TOKEN = BuildConfig.deliveryToken;
- String DEFAULT_ENV = BuildConfig.environment;
- String DEFAULT_HOST = BuildConfig.host;
- config.setHost(DEFAULT_HOST);
- stack = Contentstack.stack(appContext, DEFAULT_API_KEY, DEFAULT_DELIVERY_TOKEN, DEFAULT_ENV, config);
-
- latch = new CountDownLatch(1);
- }
-
- @Before
- public void setUp() {
- latch = new CountDownLatch(1);
- }
-
-
- @Test
- public void test_00_fetchAllImageTransformation() {
-
- imageParams.put("auto", "webp");
- imageParams.put("quality", 200);
- imageParams.put("width", 100);
- imageParams.put("height", 50);
- imageParams.put("format", "png");
- imageParams.put("crop", "3:5");
- imageParams.put("trim", "20,20,20,20");
- imageParams.put("disable", "upscale");
- imageParams.put("pad", "10,10,10,10");
- imageParams.put("bg-color", "#FFFFFF");
- imageParams.put("dpr", 20);
- imageParams.put("canvas", "3:5");
- imageParams.put("orient", "l");
-
- String image_url = stack.ImageTransform(IMAGE_URL, imageParams);
- int counter = 0;
- if (image_url.contains("?")) {
- String[] imgKeys = image_url.split("\\?");
- String rightUrl = imgKeys[1];
- String[] getAllPairs = rightUrl.split("\\&");
- counter = 0;
- if (imageParams.size() > 0) {
- for (int i = 0; i < imageParams.size(); i++) {
- String keyValueParis = getAllPairs[i];
- Log.i(TAG, "pairs:--> " + keyValueParis);
- ++counter;
- }
- }
- } else {
- try {
- latch.await();
- } catch (Exception e) {
- Log.i(TAG, "---------------||" + e.toString());
- }
- }
-
- if (counter == imageParams.size()) {
- latch.countDown();
- Log.i(TAG, "Testcases Passed");
- } else {
- Log.i(TAG, "Testcases Failed");
- try {
- latch.await();
- } catch (Exception e) {
- Log.i(TAG, "---------------||" + e.toString());
- }
- }
- }
-
-
- @Test
- public void test_01_fetchAllImageTransformation() {
-
- imageParams.put("auto", "webp");
- imageParams.put("quality", 200);
- imageParams.put("width", 100);
- imageParams.put("height", 50);
- imageParams.put("format", "png");
- imageParams.put("crop", "3:5");
-
- String image_url = stack.ImageTransform(IMAGE_URL, imageParams);
- int counter = 0;
- /* check url contains "?" */
- if (image_url.contains("?")) {
- String[] imgKeys = image_url.split("\\?");
- String rightUrl = imgKeys[1];
- String[] getAllPairs = rightUrl.split("\\&");
- counter = 0;
- if (imageParams.size() > 0) {
- for (int i = 0; i < imageParams.size(); i++) {
- String keyValueParis = getAllPairs[i];
- Log.i(TAG, "pairs:--> " + keyValueParis);
- ++counter;
- }
- }
- } else {
- Log.i(TAG, "Testcases Failed");
- try {
- latch.await();
- } catch (Exception e) {
- Log.i(TAG, "---------------||" + e.toString());
- }
- }
-
- if (counter == imageParams.size()) {
- latch.countDown();
- Log.i(TAG, "Testcases Passed");
- } else {
- Log.i(TAG, "Testcases Failed");
- try {
- latch.await();
- } catch (Exception e) {
- Log.i(TAG, "---------------||" + e.toString());
- }
- }
- }
-
-
- @Test
- public void test_02_fetchAllImageTransformation() {
- imageParams.put("trim", "20,20,20,20");
- imageParams.put("disable", "upscale");
- imageParams.put("pad", "10,10,10,10");
- imageParams.put("bg-color", "#FFFFFF");
- imageParams.put("dpr", 20);
- imageParams.put("canvas", "3:5");
- imageParams.put("orient", "l");
- String image_url = stack.ImageTransform(IMAGE_URL, imageParams);
- int counter = 0;
- /* check url contains "?" */
- if (!image_url.equalsIgnoreCase("") && image_url.contains("?")) {
- String[] imgKeys = image_url.split("\\?");
- String rightUrl = imgKeys[1];
- String[] getAllPairs = rightUrl.split("\\&");
- counter = 0;
- if (imageParams.size() > 0) {
- for (int i = 0; i < imageParams.size(); i++) {
- String keyValueParis = getAllPairs[i];
- Log.i(TAG, "pairs:--> " + keyValueParis);
- ++counter;
- }
- }
- } else {
- Log.i(TAG, "Testcases Failed");
- try {
- latch.await();
- } catch (Exception e) {
- Log.i(TAG, "---------------||" + e.toString());
- }
- }
-
- if (counter == imageParams.size()) {
- latch.countDown();
- Log.i(TAG, "Testcases Passed");
- } else {
- Log.i(TAG, "Testcases Failed");
- try {
- latch.await();
- } catch (Exception e) {
- Log.i(TAG, "---------------||" + e.toString());
- }
- }
- }
-
-
- @Test
- public void test_03_fetchAllImageTransformation() {
-
-
- imageParams.put("trim", "20,20,20,20");
- imageParams.put("disable", "upscale");
- imageParams.put("canvas", "3:5");
- imageParams.put("orient", "l");
-
- String image_url = stack.ImageTransform(IMAGE_URL, imageParams);
- int counter = 0;
- /* check url contains "?" */
- if (image_url.contains("?")) {
- String[] imgKeys = image_url.split("\\?");
- String rightUrl = imgKeys[1];
- String[] getAllPairs = rightUrl.split("\\&");
- counter = 0;
- if (imageParams.size() > 0) {
- for (int i = 0; i < imageParams.size(); i++) {
- String keyValueParis = getAllPairs[i];
- Log.i(TAG, "pairs:--> " + keyValueParis);
- ++counter;
- }
- }
- } else {
- Log.i(TAG, "Testcases Failed");
- try {
- latch.await();
- } catch (Exception e) {
- Log.i(TAG, "---------------||" + e.toString());
- }
- }
-
- if (counter == imageParams.size()) {
- latch.countDown();
- Log.i(TAG, "Testcases Passed");
- } else {
- Log.i(TAG, "Testcases Failed");
- try {
- latch.await();
- } catch (Exception e) {
- Log.i(TAG, "---------------||" + e.toString());
- }
- }
- }
-}
diff --git a/contentstack/src/azure-eu/java/AzureEUTest.java b/contentstack/src/azure-eu/java/AzureEUTest.java
new file mode 100644
index 00000000..00821f86
--- /dev/null
+++ b/contentstack/src/azure-eu/java/AzureEUTest.java
@@ -0,0 +1,20 @@
+package com.contentstack.sdk;
+
+import static org.junit.Assert.assertEquals;
+
+import android.content.Context;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+ @Test
+ public void useAppContext() {
+ Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ assertEquals("com.shaileshmishra.myapplication", appContext.getPackageName());
+ }
+}
\ No newline at end of file
diff --git a/contentstack/src/azure-na/java/AzureNATest.java b/contentstack/src/azure-na/java/AzureNATest.java
new file mode 100644
index 00000000..00821f86
--- /dev/null
+++ b/contentstack/src/azure-na/java/AzureNATest.java
@@ -0,0 +1,20 @@
+package com.contentstack.sdk;
+
+import static org.junit.Assert.assertEquals;
+
+import android.content.Context;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+ @Test
+ public void useAppContext() {
+ Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ assertEquals("com.shaileshmishra.myapplication", appContext.getPackageName());
+ }
+}
\ No newline at end of file
diff --git a/contentstack/src/eu/java/EUInstrumentedTest.java b/contentstack/src/eu/java/EUInstrumentedTest.java
new file mode 100644
index 00000000..00821f86
--- /dev/null
+++ b/contentstack/src/eu/java/EUInstrumentedTest.java
@@ -0,0 +1,20 @@
+package com.contentstack.sdk;
+
+import static org.junit.Assert.assertEquals;
+
+import android.content.Context;
+
+import androidx.test.ext.junit.runners.AndroidJUnit4;
+import androidx.test.platform.app.InstrumentationRegistry;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+public class ExampleInstrumentedTest {
+ @Test
+ public void useAppContext() {
+ Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
+ assertEquals("com.shaileshmishra.myapplication", appContext.getPackageName());
+ }
+}
\ No newline at end of file
diff --git a/contentstack/src/main/AndroidManifest.xml b/contentstack/src/main/AndroidManifest.xml
index 62a04f3d..d94c12f5 100755
--- a/contentstack/src/main/AndroidManifest.xml
+++ b/contentstack/src/main/AndroidManifest.xml
@@ -23,6 +23,13 @@
+
+
+
-
+
\ No newline at end of file
diff --git a/contentstack/src/main/java/com/contentstack/sdk/Asset.java b/contentstack/src/main/java/com/contentstack/sdk/Asset.java
index 26c2173f..828e609d 100755
--- a/contentstack/src/main/java/com/contentstack/sdk/Asset.java
+++ b/contentstack/src/main/java/com/contentstack/sdk/Asset.java
@@ -4,11 +4,6 @@
import android.util.ArrayMap;
import android.util.Log;
-import com.contentstack.sdk.utilities.CSAppConstants;
-import com.contentstack.sdk.utilities.CSAppUtils;
-import com.contentstack.sdk.utilities.CSController;
-import com.contentstack.sdk.utilities.ContentstackUtil;
-
import org.json.JSONException;
import org.json.JSONObject;
@@ -17,15 +12,16 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.Objects;
/**
- * Asset class to fetch files details on Conentstack server.
+ * Asset class to fetch files details on Contentstack server.
*
* @author contentstack.com
*/
public class Asset {
- private final static String TAG = "Asset";
+ private final static String TAG = Asset.class.getSimpleName();
protected String assetUid = null;
protected String contentType = null;
protected String fileSize = null;
@@ -34,28 +30,26 @@ public class Asset {
protected JSONObject json = null;
protected String[] tagsArray = null;
JSONObject urlQueries = new JSONObject();
- protected ArrayMap headerGroup_app;
- protected ArrayMap headerGroup_local;
+ protected ArrayMap headerGroupApp;
+ protected ArrayMap headerGroupLocal;
protected Stack stackInstance;
private CachePolicy cachePolicyForCall = CachePolicy.IGNORE_CACHE;
-
- private final long maxCacheTimeForCall = 0;
- private final long defaultCacheTimeInterval = 0;
+ private final long MAX_CACHE_TIME_FOR_CALL = 0;
protected Asset() {
- this.headerGroup_local = new ArrayMap<>();
- this.headerGroup_app = new ArrayMap<>();
+ this.headerGroupLocal = new ArrayMap<>();
+ this.headerGroupApp = new ArrayMap<>();
}
protected Asset(String assetUid) {
this.assetUid = assetUid;
- this.headerGroup_local = new ArrayMap<>();
- this.headerGroup_app = new ArrayMap<>();
+ this.headerGroupLocal = new ArrayMap<>();
+ this.headerGroupApp = new ArrayMap<>();
}
protected void setStackInstance(Stack stack) {
this.stackInstance = stack;
- this.headerGroup_app = stack.localHeader;
+ this.headerGroupApp = stack.localHeader;
}
/**
@@ -64,28 +58,26 @@ protected void setStackInstance(Stack stack) {
*
* @param jsonObject json object of particular file attached in the built object.
*
- * {@link Asset} can be generate using of data filled {@link Entry} and {@link #configure(JSONObject)}.
- *
+ * {@link Asset} can be generate using of data filled {@link Entry}
+ * and {@link #configure(JSONObject)}.
*
*/
public void sync(SyncResultCallBack syncCallBack) {
-
- if (syncParams == null) {
- syncParams = new JSONObject();
- }
try {
- syncParams.put("init", true);
+ this.syncParams = new JSONObject();
+ this.syncParams.put("init", true);
} catch (JSONException e) {
- Log.e(TAG, e.getLocalizedMessage());
+ Log.e(TAG, Objects.requireNonNull(e.getLocalizedMessage()));
}
-
this.requestSync(syncCallBack);
-
}
-
/**
- * @param pagination_token If the response is paginated, use the pagination token under this parameter.
- * @param syncCallBack returns callback for sync result
- *
- * If the result of the initial sync (or subsequent sync) contains more than 100 records,
- * the response would be paginated. It provides pagination token in the response. However,
- * you do not have to use the pagination token manually to get the next batch,
- * the SDK does that automatically until the sync is complete.
- * Pagination token can be used in case you want to fetch only selected batches.
- * It is especially useful if the sync process is interrupted midway (due to network issues, etc.).
- * In such cases, this token can be used to restart the sync process from where it was interrupted.
- *
- *
Example :
- *
- * stack.syncPaginationToken(pagination_token, new SyncResultCallBack()) {}
- *
+ * @param paginationToken If the response is paginated, use the pagination token under this parameter.
+ * @param syncCallBack returns callback for sync result
+ *
+ * If the result of the initial sync (or subsequent sync) contains more than 100 records,
+ * the response would be paginated. It provides pagination token in the response. However,
+ * you do not have to use the pagination token manually to get the next batch,
+ * the SDK does that automatically until the sync is complete.
+ * Pagination token can be used in case you want to fetch only selected batches.
+ * It is especially useful if the sync process is interrupted midway (due to network issues, etc.).
+ * In such cases, this token can be used to restart the sync process from where it was interrupted.
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+ * stack.syncPaginationToken(pagination_token, new SyncResultCallBack()) {}
+ *
+ *
*/
- public void syncPaginationToken(String pagination_token, SyncResultCallBack syncCallBack) {
- this.pagination_token = pagination_token;
- if (syncParams == null) {
- syncParams = new JSONObject();
- }
-
+ public void syncPaginationToken(String paginationToken, SyncResultCallBack syncCallBack) {
try {
- syncParams.put("init", true);
- syncParams.put("pagination_token", pagination_token);
+ this.syncParams = new JSONObject();
+ this.syncParams.put("pagination_token", paginationToken);
} catch (JSONException e) {
- Log.e(TAG, e.getLocalizedMessage());
+ Log.e(TAG, Objects.requireNonNull(e.getLocalizedMessage()));
}
-
this.requestSync(syncCallBack);
}
-
/**
- * @param sync_token Use the sync token that you received in the previous/initial sync under this parameter.
+ * @param syncToken Use the sync token that you received in the previous/initial sync under this parameter.
* @param syncCallBack returns callback for sync result
*
* You can use the sync token (that you receive after initial sync) to get the updated content next time.
@@ -442,29 +402,20 @@ public void syncPaginationToken(String pagination_token, SyncResultCallBack sync
* and the details of the content that was deleted or updated.
*
+ *
*/
- public void syncToken(String sync_token, SyncResultCallBack syncCallBack) {
-
- this.sync_token = sync_token;
- if (syncParams == null) {
- syncParams = new JSONObject();
- }
+ public void syncToken(String syncToken, SyncResultCallBack syncCallBack) {
try {
- syncParams.put("init", true);
- syncParams.put("sync_token", sync_token);
+ this.syncParams = new JSONObject();
+ this.syncParams.put("sync_token", syncToken);
} catch (JSONException e) {
- Log.e(TAG, e.getLocalizedMessage());
+ Log.e(TAG, Objects.requireNonNull(e.getLocalizedMessage()));
}
-
this.requestSync(syncCallBack);
}
-
/**
- * @param from_date Enter the start date for initial sync.
+ * @param fromDate Enter the start date for initial sync.
* @param syncCallBack Returns callback for sync result.
*
* You can also initialize sync with entries published after a specific date. To do this, use syncWithDate
@@ -472,67 +423,49 @@ public void syncToken(String sync_token, SyncResultCallBack syncCallBack) {
*
*
Example :
*
- * stack.syncFromDate(start_date, new SyncResultCallBack()) { }
- *
+ * stack.syncFromDate(start_date, new SyncResultCallBack()) { }
+ *
*/
- public void syncFromDate(Date from_date, SyncResultCallBack syncCallBack) {
- startFromDate = convertUTCToISO(from_date);
- if (syncParams == null) {
- syncParams = new JSONObject();
- }
-
+ public void syncFromDate(Date fromDate, SyncResultCallBack syncCallBack) {
+ String startFromDate = convertUTCToISO(fromDate);
try {
- syncParams.put("init", true);
- syncParams.put("start_from", startFromDate);
+ this.syncParams = new JSONObject();
+ this.syncParams.put("init", true);
+ this.syncParams.put("start_from", startFromDate);
} catch (JSONException e) {
- Log.e(TAG, e.getLocalizedMessage());
+ Log.e(TAG, Objects.requireNonNull(e.getLocalizedMessage()));
}
this.requestSync(syncCallBack);
}
-
- private String convertUTCToISO(Date date) {
-
- TimeZone tz = TimeZone.getTimeZone("UTC");
- DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
- dateFormat.setTimeZone(tz);
- return dateFormat.format(date);
- }
-
-
/**
- * @param content_type Provide uid of your content_type
+ * @param contentType Provide uid of your content_type
* @param syncCallBack Returns callback for sync result.
*
* You can also initialize sync with entries of only specific content_type.
* To do this, use syncContentType and specify the content type uid as its value.
* However, if you do this, the subsequent syncs will only include the entries of the specified content_type.
- *
- *
Example :
- *
- *
- * // dummy content_type like "session"
- * stack.syncContentType(String content_type, new SyncResultCallBack()){ }
- *
- *
+ *
*/
- public void syncContentType(String content_type, SyncResultCallBack syncCallBack) {
-
- this.contentType = content_type;
- if (syncParams == null) {
- syncParams = new JSONObject();
- }
+ public void syncContentType(String contentType, SyncResultCallBack syncCallBack) {
try {
- syncParams.put("init", true);
- syncParams.put("content_type_uid", contentType);
+ this.syncParams = new JSONObject();
+ this.syncParams.put("init", true);
+ this.syncParams.put("content_type_uid", contentType);
} catch (JSONException e) {
- Log.e(TAG, e.getLocalizedMessage());
+ Log.e(TAG, Objects.requireNonNull(e.getLocalizedMessage()));
}
-
this.requestSync(syncCallBack);
}
+ private String convertUTCToISO(Date date) {
+ TimeZone tz = TimeZone.getTimeZone("UTC");
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
+ dateFormat.setTimeZone(tz);
+ return dateFormat.format(date);
+ }
+
/**
* @param language Select the required locale from the Language class.
* @param syncCallBack Returns callback for sync result.
@@ -542,22 +475,17 @@ public void syncContentType(String content_type, SyncResultCallBack syncCallBack
*
*/
public void syncLocale(Language language, SyncResultCallBack syncCallBack) {
- this.localeCode = getLanguageCode(language);
-
- if (syncParams == null) {
- syncParams = new JSONObject();
- }
+ String localeCode = getLanguageCode(language);
try {
- syncParams.put("init", true);
- syncParams.put("locale", localeCode);
+ this.syncParams = new JSONObject();
+ this.syncParams.put("init", true);
+ this.syncParams.put("locale", localeCode);
} catch (JSONException e) {
- Log.e(TAG, e.getLocalizedMessage());
+ Log.e(TAG, Objects.requireNonNull(e.getLocalizedMessage()));
}
-
this.requestSync(syncCallBack);
}
-
/**
* @param localeCode Provide locale code
* @param syncCallBack Returns callback for sync result.
@@ -567,33 +495,17 @@ public void syncLocale(Language language, SyncResultCallBack syncCallBack) {
*
*/
public void syncLocale(@NotNull String localeCode, SyncResultCallBack syncCallBack) {
- if (syncParams == null) {
- syncParams = new JSONObject();
- }
try {
- syncParams.put("init", true);
- syncParams.put("locale", localeCode);
+ this.syncParams = new JSONObject();
+ this.syncParams.put("init", true);
+ this.syncParams.put("locale", localeCode);
} catch (JSONException e) {
- Log.e(TAG, e.getLocalizedMessage());
+ Log.e(TAG, Objects.requireNonNull(e.getLocalizedMessage()));
}
this.requestSync(syncCallBack);
}
-
- private String getLanguageCode(Language language) {
- String localeCode = null;
- if (language != null) {
- Language languageName = Language.valueOf(language.name());
- int localeValue = languageName.ordinal();
- LanguageCode[] languageCodeValues = LanguageCode.values();
- localeCode = languageCodeValues[localeValue].name();
- localeCode = localeCode.replace("_", "-");
- }
- return localeCode;
- }
-
-
/**
* @param type - Use the type parameter to get a specific type of content
* like ( asset_published, entry_published, asset_unpublished, asset_deleted, entry_unpublished, entry_deleted, content_type_deleted.)
@@ -602,32 +514,39 @@ private String getLanguageCode(Language language) {
* Use the type parameter to get a specific type of content. You can pass one of the following values:
* asset_published, entry_published, asset_unpublished, asset_deleted, entry_unpublished, entry_deleted, content_type_deleted.
* If you do not specify any value, it will bring all published entries and published assets.
+ *