From 23ce30b9e25fe6e292e6bca016a57d1175db62ac Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 11 May 2022 17:11:54 +0530 Subject: [PATCH 01/10] :potted_plant: setting proxy, live_preview --- pom.xml | 15 +- .../java/com/contentstack/sdk/APIService.java | 1 - src/main/java/com/contentstack/sdk/Asset.java | 2 + .../com/contentstack/sdk/AssetLibrary.java | 2 + .../contentstack/sdk/CSBackgroundTask.java | 43 +- .../contentstack/sdk/CSConnectionPool.java | 18 + .../contentstack/sdk/CSConnectionRequest.java | 5 +- .../contentstack/sdk/CSHttpConnection.java | 11 +- .../java/com/contentstack/sdk/Config.java | 70 +- .../com/contentstack/sdk/ContentType.java | 41 +- src/main/java/com/contentstack/sdk/Entry.java | 564 ++++++------ src/main/java/com/contentstack/sdk/Group.java | 217 ++--- src/main/java/com/contentstack/sdk/Query.java | 833 +++++++++--------- src/main/java/com/contentstack/sdk/Stack.java | 387 ++++---- .../java/com/contentstack/sdk/TestConfig.java | 51 ++ 15 files changed, 1241 insertions(+), 1019 deletions(-) create mode 100644 src/main/java/com/contentstack/sdk/CSConnectionPool.java create mode 100644 src/test/java/com/contentstack/sdk/TestConfig.java diff --git a/pom.xml b/pom.xml index 506d259b..c1a62eb3 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.contentstack.sdk java - 1.9.0-SNAPSHOT + 1.9.0 jar contentstack-java Java SDK for Contentstack Content Delivery API @@ -146,6 +146,13 @@ ${loggin.version} compile + + com.squareup.retrofit2 + converter-jackson + 2.9.0 + compile + + org.projectlombok lombok @@ -366,9 +373,9 @@ - - - + + + src/main/java/com/contentstack/sdk/Group.class src/main/java/com/contentstack/sdk/FetchAssetsCallback.class diff --git a/src/main/java/com/contentstack/sdk/APIService.java b/src/main/java/com/contentstack/sdk/APIService.java index ac52a03c..b8dd35cd 100644 --- a/src/main/java/com/contentstack/sdk/APIService.java +++ b/src/main/java/com/contentstack/sdk/APIService.java @@ -9,7 +9,6 @@ import java.util.LinkedHashMap; public interface APIService { - @GET Call getRequest(@Url String url, @HeaderMap LinkedHashMap headers); } diff --git a/src/main/java/com/contentstack/sdk/Asset.java b/src/main/java/com/contentstack/sdk/Asset.java index 9c3e2ac8..ee5b51a3 100644 --- a/src/main/java/com/contentstack/sdk/Asset.java +++ b/src/main/java/com/contentstack/sdk/Asset.java @@ -2,6 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.json.JSONObject; +import retrofit2.Retrofit; import java.util.Calendar; import java.util.HashMap; @@ -28,6 +29,7 @@ public class Asset { protected String[] tagsArray = null; protected LinkedHashMap headers; protected Stack stackInstance; + protected Retrofit retrofit; protected Asset() { this.headers = new LinkedHashMap<>(); diff --git a/src/main/java/com/contentstack/sdk/AssetLibrary.java b/src/main/java/com/contentstack/sdk/AssetLibrary.java index 1b95b513..5b4dfd6b 100644 --- a/src/main/java/com/contentstack/sdk/AssetLibrary.java +++ b/src/main/java/com/contentstack/sdk/AssetLibrary.java @@ -2,6 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.json.JSONObject; +import retrofit2.Retrofit; import java.util.*; import java.util.logging.Logger; @@ -19,6 +20,7 @@ public class AssetLibrary implements INotifyClass { protected LinkedHashMap headers; protected FetchAssetsCallback callback; protected int count; + protected Retrofit retrofit; protected AssetLibrary() { this.urlQueries = new JSONObject(); diff --git a/src/main/java/com/contentstack/sdk/CSBackgroundTask.java b/src/main/java/com/contentstack/sdk/CSBackgroundTask.java index ad5cdd51..6a5b358c 100644 --- a/src/main/java/com/contentstack/sdk/CSBackgroundTask.java +++ b/src/main/java/com/contentstack/sdk/CSBackgroundTask.java @@ -1,6 +1,7 @@ package com.contentstack.sdk; import org.jetbrains.annotations.NotNull; +import retrofit2.Retrofit; import java.util.HashMap; import java.util.LinkedHashMap; @@ -9,71 +10,79 @@ class CSBackgroundTask { + protected APIService service; + protected CSBackgroundTask() { } protected CSBackgroundTask(Stack stackInstance, String controller, String url, HashMap headers, - HashMap urlParams, String requestInfo, ResultCallBack callback) { + HashMap urlParams, String requestInfo, ResultCallBack callback) { checkHeader(headers); String completeUrl = stackInstance.config.getEndpoint() + url; CSConnectionRequest csConnectionRequest = new CSConnectionRequest(stackInstance); csConnectionRequest.setStackInstance(stackInstance); csConnectionRequest.setURLQueries(urlParams); - csConnectionRequest.setParams(completeUrl, headers, controller, requestInfo, callback); + this.service = stackInstance.service; + csConnectionRequest.setParams(completeUrl, headers, controller, requestInfo, callback, this.service); } protected CSBackgroundTask(Query queryInstance, Stack stackInstance, String controller, String url, - LinkedHashMap headers, HashMap urlQueries, String requestInfo, - ResultCallBack callback) { + LinkedHashMap headers, HashMap urlQueries, String requestInfo, + ResultCallBack callback) { checkHeader(headers); String completeUrl = stackInstance.config.getEndpoint() + url; CSConnectionRequest csConnectionRequest = new CSConnectionRequest(queryInstance); csConnectionRequest.setQueryInstance(queryInstance); csConnectionRequest.setURLQueries(urlQueries); - csConnectionRequest.setParams(completeUrl, headers, controller, requestInfo, callback); + this.service = stackInstance.service; + csConnectionRequest.setParams(completeUrl, headers, controller, requestInfo, callback, this.service); } protected CSBackgroundTask(Entry entryInstance, Stack stackInstance, String controller, String url, - LinkedHashMap headers, HashMap urlQueries, String requestInfo, - ResultCallBack callBack) { + LinkedHashMap headers, HashMap urlQueries, String requestInfo, + ResultCallBack callBack) { checkHeader(headers); String completeUrl = stackInstance.config.getEndpoint() + url; CSConnectionRequest csConnectionRequest = new CSConnectionRequest(entryInstance); csConnectionRequest.setURLQueries(urlQueries); - csConnectionRequest.setParams(completeUrl, headers, controller, requestInfo, callBack); + this.service = stackInstance.service; + csConnectionRequest.setParams(completeUrl, headers, controller, requestInfo, callBack, this.service); } protected CSBackgroundTask(AssetLibrary assetLibrary, Stack stackInstance, String controller, String url, - LinkedHashMap headers, HashMap urlQueries, String requestInfo, - ResultCallBack callback) { + LinkedHashMap headers, HashMap urlQueries, String requestInfo, + ResultCallBack callback) { checkHeader(headers); String completeUrl = stackInstance.config.getEndpoint() + url; CSConnectionRequest csConnectionRequest = new CSConnectionRequest(assetLibrary); csConnectionRequest.setURLQueries(urlQueries); - csConnectionRequest.setParams(completeUrl, headers, controller, requestInfo, callback); + this.service = stackInstance.service; + csConnectionRequest.setParams(completeUrl, headers, controller, requestInfo, callback, this.service); } protected CSBackgroundTask(Asset asset, Stack stackInstance, String controller, String url, - LinkedHashMap headers, HashMap urlQueries, String requestInfo, - ResultCallBack callback) { + LinkedHashMap headers, HashMap urlQueries, String requestInfo, + ResultCallBack callback) { checkHeader(headers); String completeUrl = stackInstance.config.getEndpoint() + url; CSConnectionRequest csConnectionRequest = new CSConnectionRequest(asset); csConnectionRequest.setURLQueries(urlQueries); - csConnectionRequest.setParams(completeUrl, headers, controller, requestInfo, callback); + this.service = stackInstance.service; + csConnectionRequest.setParams(completeUrl, headers, controller, requestInfo, callback, this.service); } protected CSBackgroundTask(ContentType contentType, Stack stackInstance, String controller, String url, - HashMap headers, HashMap urlParams, String requestInfo, - ResultCallBack callback) { + HashMap headers, HashMap urlParams, String requestInfo, + ResultCallBack callback) { checkHeader(headers); String completeUrl = stackInstance.config.getEndpoint() + url; CSConnectionRequest csConnectionRequest = new CSConnectionRequest(contentType); csConnectionRequest.setURLQueries(urlParams); - csConnectionRequest.setParams(completeUrl, headers, controller, requestInfo, callback); + this.service = stackInstance.service; + csConnectionRequest.setParams(completeUrl, headers, controller, requestInfo, callback, this.service); } protected void checkHeader(@NotNull Map headers) { diff --git a/src/main/java/com/contentstack/sdk/CSConnectionPool.java b/src/main/java/com/contentstack/sdk/CSConnectionPool.java new file mode 100644 index 00000000..46685433 --- /dev/null +++ b/src/main/java/com/contentstack/sdk/CSConnectionPool.java @@ -0,0 +1,18 @@ +package com.contentstack.sdk; + +import okhttp3.ConnectionPool; + +import java.util.concurrent.TimeUnit; + + +public class CSConnectionPool { + + ConnectionPool create() { + return new ConnectionPool(); + } + + ConnectionPool create(int maxIdleConnections, long keepAliveDuration, TimeUnit timeUnit) { + return new ConnectionPool(maxIdleConnections, keepAliveDuration, timeUnit); + } + +} diff --git a/src/main/java/com/contentstack/sdk/CSConnectionRequest.java b/src/main/java/com/contentstack/sdk/CSConnectionRequest.java index 74146e5b..5f932bf2 100644 --- a/src/main/java/com/contentstack/sdk/CSConnectionRequest.java +++ b/src/main/java/com/contentstack/sdk/CSConnectionRequest.java @@ -1,6 +1,7 @@ package com.contentstack.sdk; import org.json.JSONObject; +import retrofit2.Retrofit; import java.util.HashMap; import java.util.LinkedHashMap; @@ -19,7 +20,7 @@ class CSConnectionRequest implements IRequestModelHTTP { private ResultCallBack resultCallBack; private INotifyClass notifyClass; private AssetLibrary assetLibrary; - + private APIService service; private Entry entryInstance; private Asset assetInstance; private Stack stackInstance; @@ -73,6 +74,7 @@ public void setParams(Object... objects) { if (objects[4] != null) { resultCallBack = (ResultCallBack) objects[4]; } + this.service = (APIService) objects[5]; sendRequest(); } @@ -83,6 +85,7 @@ public void sendRequest() { connection.setHeaders(header); connection.setInfo(requestInfo); connection.setEndpoint(this.endpoint); + connection.setAPIService(this.service); connection.setCallBackObject(resultCallBack); if (urlQueries != null && urlQueries.size() > 0) { connection.setFormParams(urlQueries); diff --git a/src/main/java/com/contentstack/sdk/CSHttpConnection.java b/src/main/java/com/contentstack/sdk/CSHttpConnection.java index 8380995c..297043be 100644 --- a/src/main/java/com/contentstack/sdk/CSHttpConnection.java +++ b/src/main/java/com/contentstack/sdk/CSHttpConnection.java @@ -28,6 +28,7 @@ public class CSHttpConnection implements IURLRequestHTTP { private String controller; private LinkedHashMap headers; private String info; + private APIService service; private String endpoint; private ResultCallBack callBackObject; private JSONObject responseJSON; @@ -182,11 +183,11 @@ public void send() { } private void getService(String requestUrl) throws IOException { - Retrofit retrofit = new Retrofit.Builder().baseUrl(this.endpoint).build(); - APIService service = retrofit.create(APIService.class); +// Retrofit retrofit = new Retrofit.Builder().baseUrl(this.endpoint).build(); +// APIService service = retrofit.create(APIService.class); this.headers.put(X_USER_AGENT, CLIENT_USER_AGENT); this.headers.put(CONTENT_TYPE, APPLICATION_JSON); - Response response = service.getRequest(requestUrl, this.headers).execute(); + Response response = this.service.getRequest(requestUrl, this.headers).execute(); if (response.isSuccessful()) { assert response.body() != null; String resp = response.body().string(); @@ -212,4 +213,8 @@ void setError(String errResp) { protected void setEndpoint(@NotNull String endpoint) { this.endpoint = endpoint; } + + public void setAPIService(APIService service) { + this.service = service; + } } \ No newline at end of file diff --git a/src/main/java/com/contentstack/sdk/Config.java b/src/main/java/com/contentstack/sdk/Config.java index a7976cc4..8f843f8f 100644 --- a/src/main/java/com/contentstack/sdk/Config.java +++ b/src/main/java/com/contentstack/sdk/Config.java @@ -1,7 +1,12 @@ package com.contentstack.sdk; +import okhttp3.ConnectionPool; import org.jetbrains.annotations.NotNull; +import java.net.Proxy; +import java.util.concurrent.TimeUnit; + + /** * The type Config. enables optional parameters while passing from stack */ @@ -18,6 +23,8 @@ public class Config { protected ContentstackRegion region = ContentstackRegion.US; protected String managementToken; protected String branch; + protected Proxy proxy = null; + protected ConnectionPool connectionPool = new ConnectionPool(); public String getBranch() { return branch; @@ -27,6 +34,51 @@ public void setBranch(String branch) { this.branch = branch; } + + /** + * Proxy can be set like below. + * + * @param proxy + * Proxy setting, typically a type (http, socks) and a socket address. A Proxy is an immutable object + *

Example:

+ * + * java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyHost", "proxyPort")); + * java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("sl.theproxyvpn.io", 80)); Config + * config = new Config() config.setProxy(proxy) + * + */ + public void setProxy(Proxy proxy) { + this.proxy = proxy; + } + + /** + * Returns the Proxy instance + * + * @return Proxy + */ + public Proxy getProxy() { + return this.proxy; + } + + + /** + * Manages reuse of HTTP and HTTP/2 connections for reduced network latency. HTTP requests that * share the same + * {@link okhttp3.Address} may share a {@link okhttp3.Connection}. This class implements the policy * of which + * connections to keep open for future use. + * + * @param maxIdleConnections + * the maxIdleConnections default value is 5 + * @param keepAliveDuration + * the keepAliveDuration default value is 5 + * @param timeUnit + * the timeUnit default value is TimeUnit.MINUTES + * @return ConnectionPool + */ + public ConnectionPool connectionPool(int maxIdleConnections, long keepAliveDuration, TimeUnit timeUnit) { + this.connectionPool = new ConnectionPool(maxIdleConnections, keepAliveDuration, timeUnit); + return this.connectionPool; + } + /** * Gets region. * @@ -39,7 +91,8 @@ public ContentstackRegion getRegion() { /** * Sets region. * - * @param region the region + * @param region + * the region * @return the region */ public ContentstackRegion setRegion(ContentstackRegion region) { @@ -68,7 +121,8 @@ public String getHost() { /** * Sets host. * - * @param hostName the host name + * @param hostName + * the host name */ public void setHost(String hostName) { if (hostName != null && !hostName.isEmpty()) { @@ -88,7 +142,8 @@ public String getVersion() { /** * Enable live preview config. * - * @param enableLivePreview to enable live preview + * @param enableLivePreview + * to enable live preview * @return the config */ public Config enableLivePreview(boolean enableLivePreview) { @@ -99,7 +154,8 @@ public Config enableLivePreview(boolean enableLivePreview) { /** * Sets live preview host. * - * @param livePreviewHost the live preview host + * @param livePreviewHost + * the live preview host * @return the live preview host */ public Config setLivePreviewHost(@NotNull String livePreviewHost) { @@ -110,7 +166,8 @@ public Config setLivePreviewHost(@NotNull String livePreviewHost) { /** * Sets management token. * - * @param managementToken the management token + * @param managementToken + * the management token * @return the management token */ public Config setManagementToken(@NotNull String managementToken) { @@ -119,8 +176,7 @@ public Config setManagementToken(@NotNull String managementToken) { } /** - * The enum Contentstack region. for now contentstack supports - * [US, EU, AZURE_NA] + * The enum Contentstack region. for now contentstack supports [US, EU, AZURE_NA] */ public enum ContentstackRegion { US, EU, AZURE_NA diff --git a/src/main/java/com/contentstack/sdk/ContentType.java b/src/main/java/com/contentstack/sdk/ContentType.java index 6780b1f0..86556c71 100644 --- a/src/main/java/com/contentstack/sdk/ContentType.java +++ b/src/main/java/com/contentstack/sdk/ContentType.java @@ -2,6 +2,7 @@ import org.jetbrains.annotations.NotNull; import org.json.JSONObject; +import retrofit2.Retrofit; import java.util.HashMap; import java.util.Iterator; @@ -34,8 +35,10 @@ protected void setStackInstance(Stack stack) { /** * Sets header on {@link Stack}. * - * @param headerKey the header key - * @param headerValue the header value + * @param headerKey + * the header key + * @param headerValue + * the header value */ public void setHeader(String headerKey, String headerValue) { if (!headerKey.isEmpty() && !headerValue.isEmpty()) { @@ -46,7 +49,8 @@ public void setHeader(String headerKey, String headerValue) { /** * Remove header from {@link Stack} * - * @param headerKey the header key + * @param headerKey + * the header key */ public void removeHeader(String headerKey) { if (!headerKey.isEmpty()) { @@ -55,12 +59,12 @@ public void removeHeader(String headerKey) { } /** - * An entry is the actual piece of content created using one of the defined - * content types. + * An entry is the actual piece of content created using one of the defined content types. *

* The Get a single entry request fetches a particular entry of a content type. * - * @param entryUid the entry unique ID of the entry that you want to fetch. + * @param entryUid + * the entry unique ID of the entry that you want to fetch. * @return the {@link Entry} entry. */ public Entry entry(String entryUid) { @@ -78,10 +82,9 @@ protected Entry entry() { } /** - * Query. The Get all entries request fetches the list of all the entries of a - * particular content type. It returns the content of each entry in JSON format. - * You need to specify the environment and locale of which you want to get the - * entries. + * Query. The Get all entries request fetches the list of all the entries of a particular content type. It returns + * the content of each entry in JSON format. You need to specify the environment and locale of which you want to get + * the entries. * *

* If an entry is not published in a specific locale, make use of the @@ -92,12 +95,10 @@ protected Entry entry() { * language itself, this parameter would not be applicable. * *

- * To include the publishing details in the response, make use of the - * include_publish_details=true parameter. This will return the publishing - * details of the entry in every environment along with the version number that - * is published in each of the environments. You can add other Queries to extend - * the functionality of this API call. Add a query parameter named query and - * provide your query (in JSON format) as the value. + * To include the publishing details in the response, make use of the include_publish_details=true parameter. This + * will return the publishing details of the entry in every environment along with the version number that is + * published in each of the environments. You can add other Queries to extend the functionality of this API call. + * Add a query parameter named query and provide your query (in JSON format) as the value. * * @return the {@link Query} */ @@ -111,8 +112,10 @@ public Query query() { /** * Fetch. * - * @param params the params - * @param callback the callback + * @param params + * the params + * @param callback + * the callback */ public void fetch(@NotNull JSONObject params, final ContentTypesCallback callback) { String urlString = "content_types/" + contentTypeUid; @@ -134,7 +137,7 @@ public void fetch(@NotNull JSONObject params, final ContentTypesCallback callbac } private void fetchContentTypes(String urlString, JSONObject params, HashMap headers, - ContentTypesCallback callback) { + ContentTypesCallback callback) { if (callback != null) { HashMap urlParams = getUrlParams(params); new CSBackgroundTask(this, stackInstance, Constants.FETCHCONTENTTYPES, urlString, headers, urlParams, diff --git a/src/main/java/com/contentstack/sdk/Entry.java b/src/main/java/com/contentstack/sdk/Entry.java index a2d85b4c..e65b7ca3 100644 --- a/src/main/java/com/contentstack/sdk/Entry.java +++ b/src/main/java/com/contentstack/sdk/Entry.java @@ -3,6 +3,7 @@ import org.jetbrains.annotations.NotNull; import org.json.JSONArray; import org.json.JSONObject; +import retrofit2.Retrofit; import java.util.*; import java.util.logging.Logger; @@ -30,6 +31,7 @@ public class Entry { protected JSONObject onlyJsonObject; protected JSONObject exceptJsonObject; protected String rteContent = null; + protected Retrofit retrofit; protected Entry() throws IllegalAccessException { throw new IllegalAccessException("Can Not Access Private Modifier"); @@ -61,16 +63,18 @@ public Entry configure(JSONObject jsonObject) { /** * Set headers. * - * @param key custom_header_key - * @param value custom_header_value
- *
- * Example :
- * - *

-     *              Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
-     *              Entry entry = stack.contentType("form_name").entry("entry_uid");
-     *              entry.setHeader("custom_header_key", "custom_header_value");
-     *              
+ * @param key + * custom_header_key + * @param value + * custom_header_value
+ *
+ * Example :
+ * + *
+     *                                      Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+     *                                      Entry entry = stack.contentType("form_name").entry("entry_uid");
+     *                                      entry.setHeader("custom_header_key", "custom_header_value");
+     *                                      
*/ public void setHeader(String key, String value) { @@ -82,15 +86,16 @@ public void setHeader(String key, String value) { /** * Remove header key. * - * @param key custom_header_key
- *
- * Example :
- * - *
-     *            Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
-     *            Entry entry = stack.contentType("form_name").entry("entry_uid");
-     *            entry.removeHeader("custom_header_key");
-     *            
+ * @param key + * custom_header_key
+ *
+ * Example :
+ * + *
+     *                                    Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+     *                                    Entry entry = stack.contentType("form_name").entry("entry_uid");
+     *                                    entry.removeHeader("custom_header_key");
+     *                                    
*/ public void removeHeader(String key) { @@ -103,10 +108,10 @@ public void removeHeader(String key) { * Get title string * * @return String @title
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         String title = entry.getTitle();
      *         
*/ @@ -119,10 +124,10 @@ public String getTitle() { * Get url string * * @return String @url
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         String url = entry.getURL();
      *         
*/ @@ -135,10 +140,10 @@ public String getURL() { * Get tags. * * @return String @tags
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         String[] tags = entry.getURL();
      *         
*/ @@ -155,10 +160,10 @@ protected void setTags(String[] tags) { * Get contentType name. * * @return String @contentTypeName
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         String contentType = entry.getFileType();
      *         
*/ @@ -171,10 +176,10 @@ public String getContentType() { * Get uid. * * @return String @uid
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         String uid = entry.getUid();
      *         
*/ @@ -192,12 +197,13 @@ public String getLocale() { } /** - * @param locale {@link String} + * @param locale + * {@link String} * @return Entry
- *
- * Example :
+ *
+ * Example :
* - *
+     * 
      *         Entry entry = entry.setLanguage();
      *         
*/ @@ -216,10 +222,10 @@ public Map getOwner() { * Get entry representation in json * * @return JSONObject @resultJson
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         JSONObject json = entry.toJSON();
      *         
*/ @@ -231,14 +237,14 @@ public JSONObject toJSON() { /** * Get object value for key. * - * @param key field_uid as key.
- *
- * Example :
- * - *
-     *            Object obj = entry.get("key");
-     *            
+ * @param key + * field_uid as key.
+ *
+ * Example :
* + *
+     *                                    Object obj = entry.get("key");
+     *                                    
* @return Object @resultJson */ public Object get(@NotNull String key) { @@ -248,14 +254,14 @@ public Object get(@NotNull String key) { /** * Get string value for key. * - * @param key field_uid as key.
- *
- * Example :
- * - *
-     *            String value = entry.getString("key");
-     *            
+ * @param key + * field_uid as key.
+ *
+ * Example :
* + *
+     *                                    String value = entry.getString("key");
+     *                                    
* @return String @getString */ @@ -270,14 +276,14 @@ public String getString(@NotNull String key) { /** * Get boolean value for key. * - * @param key field_uid as key.
- *
- * Example :
- * - *
-     *            Boolean value = entry.getBoolean("key");
-     *            
+ * @param key + * field_uid as key.
+ *
+ * Example :
* + *
+     *                                    Boolean value = entry.getBoolean("key");
+     *                                    
* @return boolean @getBoolean */ @@ -292,14 +298,14 @@ public Boolean getBoolean(@NotNull String key) { /** * Get {@link JSONArray} value for key * - * @param key field_uid as key.
- *
- * Example :
- * - *
-     *            JSONArray value = entry.getJSONArray("key");
-     *            
+ * @param key + * field_uid as key.
+ *
+ * Example :
* + *
+     *                                    JSONArray value = entry.getJSONArray("key");
+     *                                    
* @return JSONArray @getJSONArray */ @@ -314,14 +320,14 @@ public JSONArray getJSONArray(@NotNull String key) { /** * Get {@link JSONObject} value for key * - * @param key field_uid as key.
- *
- * Example :
- * - *
-     *            JSONObject value = entry.getJSONObject("key");
-     *            
+ * @param key + * field_uid as key.
+ *
+ * Example :
* + *
+     *                                    JSONObject value = entry.getJSONObject("key");
+     *                                    
* @return JSONObject @getJSONObject */ public JSONObject getJSONObject(@NotNull String key) { @@ -335,14 +341,14 @@ public JSONObject getJSONObject(@NotNull String key) { /** * Get {@link JSONObject} value for key * - * @param key field_uid as key.
- *
- * Example :
- * - *
-     *            JSONObject value = entry.getJSONObject("key");
-     *            
+ * @param key + * field_uid as key.
+ *
+ * Example :
* + *
+     *                                    JSONObject value = entry.getJSONObject("key");
+     *                                    
* @return Number @getNumber */ @@ -357,14 +363,14 @@ public Number getNumber(@NotNull String key) { /** * Get integer value for key * - * @param key field_uid as key.
- *
- * Example :
- * - *
-     *            int value = entry.getInt("key");
-     *            
+ * @param key + * field_uid as key.
+ *
+ * Example :
* + *
+     *                                    int value = entry.getInt("key");
+     *                                    
* @return int @getInt */ @@ -379,12 +385,13 @@ public int getInt(@NotNull String key) { /** * Get integer value for key * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return float @getFloat
- *
- * Example :
+ *
+ * Example :
* - *
+     * 
      *         float value = entry.getFloat("key");
      *         
*/ @@ -400,12 +407,13 @@ public float getFloat(@NotNull String key) { /** * Get double value for key * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return double @getDouble
- *
- * Example :
+ *
+ * Example :
* - *
+     * 
      *         double value = entry.getDouble("key");
      *         
*/ @@ -421,14 +429,14 @@ public double getDouble(@NotNull String key) { /** * Get long value for key * - * @param key field_uid as key.
- *
- * Example :
- * - *
-     *            long value = entry.getLong("key");
-     *            
+ * @param key + * field_uid as key.
+ *
+ * Example :
* + *
+     *                                    long value = entry.getLong("key");
+     *                                    
* @return long @getLong */ @@ -443,16 +451,16 @@ public long getLong(@NotNull String key) { /** * Get short value for key * - * @param key field_uid as key. + * @param key + * field_uid as key. * - *
- *
- * Example :
- * - *
-     *            short value = entry.getShort("key");
-     *            
+ *
+ *
+ * Example :
* + *
+     *                                    short value = entry.getShort("key");
+     *                                    
* @return short @getShort */ public short getShort(@NotNull String key) { @@ -466,14 +474,14 @@ public short getShort(@NotNull String key) { /** * Get {@link Calendar} value for key * - * @param key field_uid as key.
- *
- * Example :
- * - *
-     *            Calendar value = entry.getDate("key");
-     *            
+ * @param key + * field_uid as key.
+ *
+ * Example :
* + *
+     *                                    Calendar value = entry.getDate("key");
+     *                                    
* @return Calendar @getDate */ @@ -491,10 +499,10 @@ public Calendar getDate(@NotNull String key) { * Get {@link Calendar} value of creation time of entry. * * @return Calendar @getCreateAt
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         Calendar createdAt = entry.getCreateAt("key");
      *         
*/ @@ -513,10 +521,10 @@ public Calendar getCreateAt() { * Get uid who created this entry. * * @return String @getCreatedBy
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         String createdBy_uid = entry.getCreatedBy();
      *         
*/ @@ -528,10 +536,10 @@ public String getCreatedBy() { * Get {@link Calendar} value of updating time of entry. * * @return Calendar @getUpdateAt
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         Calendar updatedAt = entry.getUpdateAt("key");
      *         
*/ @@ -550,10 +558,10 @@ public Calendar getUpdateAt() { * Get uid who updated this entry. * * @return String @getString
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         String updatedBy_uid = entry.getUpdatedBy();
      *         
*/ @@ -566,11 +574,11 @@ public String getUpdatedBy() { * * @return Calendar * - *
- *
- * Example :
- * - *
+     * 
+ *
+ * Example :
+ * + *
      *         Calendar updatedAt = entry.getUpdateAt("key");
      *         
*/ @@ -589,10 +597,10 @@ public Calendar getDeleteAt() { * Get uid who deleted this entry. * * @return String
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         String deletedBy_uid = entry.getDeletedBy();
      *         
*/ @@ -603,12 +611,13 @@ public String getDeletedBy() { /** * Get an asset from the entry * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return Asset
- *
- * Example :
+ *
+ * Example :
* - *
+     * 
      *         Asset asset = entry.getAsset("key");
      *         
*/ @@ -621,7 +630,7 @@ public Asset getAsset(String key) { * Get an assets from the entry. This works with multiple true fields
*
* Example :
- * + * *
      * {
      *     @code
@@ -629,7 +638,8 @@ public Asset getAsset(String key) {
      * }
      * 
* - * @param key This is the String key + * @param key + * This is the String key * @return ArrayList This returns list of Assets. */ @@ -647,17 +657,15 @@ public List getAssets(String key) { } /** + * @param key + * field_uid as key.
+ *
+ * Example :
* - * @param key field_uid as key.
- *
- * Example :
- * - *
-     *             Group innerGroup = entry.getGroup("key");
-     *             return null
-     *            
- * - * + *
+     *                                     Group innerGroup = entry.getGroup("key");
+     *                                     return null
+     *                                    
* @return {@link Group} */ public Group getGroup(String key) { @@ -672,12 +680,13 @@ public Group getGroup(String key) { *

* Note :- This will work when group is multiple true. * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return list of group from entry
- *
- * Example :
- * - *

+     * 
+ * Example :
+ * + *
      *         Group innerGroup = entry.getGroups("key");
      *         
*/ @@ -697,15 +706,16 @@ public List getGroups(String key) { /** * Get value for the given reference key. * - * @param refKey key of a reference field. - * @param refContentType class uid. - * @return {@link ArrayList} of {@link Entry} instances. Also specified - * contentType value will be set as class uid for all {@link Entry} - * instance.
- *
- * Example :
- * - *
+     * @param refKey
+     *         key of a reference field.
+     * @param refContentType
+     *         class uid.
+     * @return {@link ArrayList} of {@link Entry} instances. Also specified contentType value will be set as class uid
+     * for all {@link Entry} instance. 
+ *
+ * Example :
+ * + *
      *          {@code
      *          Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentType_name").query();
@@ -752,15 +762,15 @@ public ArrayList getAllEntries(String refKey, String refContentType) {
     }
 
     /**
-     * Specifies list of field uids that would be 'excluded' from the
-     * response.
+     * Specifies list of field uids that would be 'excluded' from the response.
      *
-     * @param fieldUid field uid which get 'excluded' from the response.
+     * @param fieldUid
+     *         field uid which get 'excluded' from the response.
      * @return {@link Entry} object, so you can chain this call. 
- *
- * Example :
+ *
+ * Example :
* - *
+     * 
      *          Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *          Entry entry = stack.contentType("form_name").entry("entry_uid");
* entry.except(new String[]{"name", "description"}); @@ -782,12 +792,13 @@ public Entry except(@NotNull String[] fieldUid) { /** * Add a constraint that requires a particular reference key details. * - * @param referenceField key that to be constrained. + * @param referenceField + * key that to be constrained. * @return {@link Entry} object, so you can chain this call.
- *
- * Example :
+ *
+ * Example :
* - *
+     * 
      *          Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *          Entry entry = stack.contentType("form_name").entry("entry_uid");
* entry.includeReference("referenceUid"); @@ -807,13 +818,14 @@ public Entry includeReference(@NotNull String referenceField) { /** * Add a constraint that requires a particular reference key details. * - * @param referenceFields array key that to be constrained. + * @param referenceFields + * array key that to be constrained. * @return {@link Entry} object, so you can chain this call.
- *
- * Example :
- * - *
-    *           Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+     * 
+ * Example :
+ * + *
+     *           Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *          Entry entry = stack.contentType("form_name").entry("entry_uid");
* entry.includeReference(new String[]{"referenceUid_A", "referenceUid_B"}); *
@@ -832,16 +844,15 @@ public Entry includeReference(@NotNull String[] referenceFields) { } /** - * Specifies an array of 'only' keys in BASE object that would be - * 'included' in the response. + * Specifies an array of 'only' keys in BASE object that would be 'included' in the response. * - * @param fieldUid Array of the 'only' reference keys to be included in - * response. + * @param fieldUid + * Array of the 'only' reference keys to be included in response. * @return {@link Entry} object, so you can chain this call.
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *          Entry entry = stack.contentType("form_name").entry("entry_uid");
* entry.only(new String[]{"name", "description"}); @@ -860,18 +871,18 @@ public Entry only(String[] fieldUid) { } /** - * Specifies an array of 'only' keys that would be 'included' in - * the response. + * Specifies an array of 'only' keys that would be 'included' in the response. * - * @param fieldUid Array of the 'only' reference keys to be - * included in response. - * @param referenceFieldUid Key who has reference to some other class object.. + * @param fieldUid + * Array of the 'only' reference keys to be included in response. + * @param referenceFieldUid + * Key who has reference to some other class object.. * @return {@link Entry} object, so you can chain this call.
- *
- * Example :
- * - *
-                Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+     * 
+ * Example :
+ * + *
+     * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *          Entry entry = stack.contentType("form_name").entry("entry_uid");
* ArrayList<String> array = new ArrayList<String>(); * array.add("description"); @@ -894,19 +905,19 @@ public Entry onlyWithReferenceUid(@NotNull ArrayList fieldUid, @NotNull } /** - * Specifies an array of 'except' keys that would be 'excluded' - * in the response. + * Specifies an array of 'except' keys that would be 'excluded' in the response. * - * @param fieldUid Array of the 'except' reference keys to be - * excluded in response. - * @param referenceFieldUid Key who has reference to some other class object. + * @param fieldUid + * Array of the 'except' reference keys to be excluded in response. + * @param referenceFieldUid + * Key who has reference to some other class object. * @return {@link Entry} object, so you can chain this call. * - *
- *
- * Example :
- * - *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *          Entry entry = stack.contentType("form_name").entry("entry_uid");
* ArrayList<String> array = new ArrayList<String>(); @@ -929,22 +940,22 @@ public Entry exceptWithReferenceUid(@NotNull ArrayList fieldUid, @NotNul /** * Fetches the latest version of the entries from Contentstack.com content stack * - * @param callback {@link EntryResultCallBack} object to notify the application - * when the request has completed.
- *
- * Example :
- * - *
-     *                 {@code
-     *                 Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
-     *                 Entry entry = stack.contentType("form_name").entry("entry_uid");
- * entry.fetch(new EntryResultCallBack() {
- * @Override - * public void onCompletion(ResponseType responseType, Error error) { - * }
- * });
- * } - *
+ * @param callback + * {@link EntryResultCallBack} object to notify the application when the request has completed.
+ *
+ * Example :
+ * + *
+     *                                         {@code
+     *                                         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+     *                                         Entry entry = stack.contentType("form_name").entry("entry_uid");
+ * entry.fetch(new EntryResultCallBack() {
+ * @Override + * public void onCompletion(ResponseType responseType, Error error) { + * }
+ * });
+ * } + *
*/ public void fetch(EntryResultCallBack callback) { @@ -985,7 +996,9 @@ private void checkLivePreview(LinkedHashMap headers, JSONObject if (configInstance.livePreviewHash == null || configInstance.livePreviewHash.isEmpty()) { configInstance.livePreviewHash = "init"; } - headers.put("live_preview", configInstance.livePreviewHash); + //headers.put("live_preview", configInstance.livePreviewHash); + urlQueries.put("live_preview", configInstance.livePreviewHash); + urlQueries.put("content_type_uid", contentTypeUid); headers.put("authorization", configInstance.managementToken); urlQueries.remove(ENVIRONMENT); } @@ -1047,15 +1060,17 @@ private void throwException(String errorMsg, Exception e, EntryResultCallBack ca /** * This method adds key and value to an Entry. * - * @param key The key as string which needs to be added to an Entry - * @param value The value as string which needs to be added to an Entry + * @param key + * The key as string which needs to be added to an Entry + * @param value + * The value as string which needs to be added to an Entry * @return {@link Entry} * - *
- *
- * Example :
- * - *
+     * 
+ *
+ * Example :
+ * + *
      *         {@code
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         final Entry entry = stack.contentType("user").entry("entryUid"); 
@@ -1075,15 +1090,14 @@ public Entry addParam(@NotNull String key, @NotNull String value) { } /** - * This method also includes the content type UIDs of the referenced entries - * returned in the response + * This method also includes the content type UIDs of the referenced entries returned in the response * * @return {@link Entry} * - *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *          {@code
      *          Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *          final Entry entry = stack.contentType("user").entry("entryUid"); 
@@ -1105,10 +1119,10 @@ public Entry includeReferenceContentTypeUID() { * Include Content Type of all returned objects along with objects themselves. * * @return {@link Entry} object, so you can chain this call.
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         final Entry entry = stack.contentType("user").entry("entryUid");
      *         entry.includeContentType();
@@ -1122,14 +1136,13 @@ public Entry includeContentType() {
     }
 
     /**
-     * Retrieve the published content of the fallback locale if an entry is not
-     * localized in specified locale
+     * Retrieve the published content of the fallback locale if an entry is not localized in specified locale
      *
      * @return {@link Entry} object, so you can chain this call. 
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         final Entry entry = stack.contentType("user").entry("entryUid");
      *         entry.includeFallback();
@@ -1141,19 +1154,18 @@ public Entry includeFallback() {
     }
 
     /**
-     * includeEmbeddedItems instance of Entry Include Embedded Objects (Entries and
-     * Assets) along with entry/entries details.
+ * includeEmbeddedItems instance of Entry Include Embedded Objects (Entries and Assets) along with entry/entries + * details.
* * @return {@link Entry} object, so you can chain this call.
- *
- * Example :
+ *
+ * Example :
* - *
+     * 
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         final Entry entry = stack.contentType("user").entry("entryUid");
      *         entry.includeEmbeddedItems();
      *         
- * */ public Entry includeEmbeddedItems() { params.put("include_embedded_items[]", "BASE"); @@ -1164,12 +1176,12 @@ public Entry includeEmbeddedItems() { * Includes Branch in the entry response * * @return {@link Entry} object, so you can chain this call. - * - *
- *
- * Example :
* - *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         final Entry entry = stack.contentType("user").entry("entryUid");
      *         entry.includeBranch();
diff --git a/src/main/java/com/contentstack/sdk/Group.java b/src/main/java/com/contentstack/sdk/Group.java
index b1d3da42..a2bd7495 100644
--- a/src/main/java/com/contentstack/sdk/Group.java
+++ b/src/main/java/com/contentstack/sdk/Group.java
@@ -2,6 +2,7 @@
 
 import org.json.JSONArray;
 import org.json.JSONObject;
+import retrofit2.Retrofit;
 
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -13,8 +14,10 @@ public class Group {
     protected static final Logger logger = Logger.getLogger(Group.class.getSimpleName());
     private final JSONObject resultJson;
     private final Stack stackInstance;
+    protected APIService service;
 
     protected Group(Stack stack, JSONObject jsonObject) {
+        this.service = stack.service;
         resultJson = jsonObject;
         stackInstance = stack;
     }
@@ -23,10 +26,10 @@ protected Group(Stack stack, JSONObject jsonObject) {
      * Get group representation in json
      *
      * @return JSONObject 
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         JSONObject json = group.toJSON();
      *         
*/ @@ -37,12 +40,13 @@ public JSONObject toJSON() { /** * Get object value for key. * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return JSONObject
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         Object obj = group.get("key");
      *         
*/ @@ -57,12 +61,13 @@ public Object get(String key) { /** * Get string value for key. * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return String
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         String value = group.getString("key");
      *         
*/ @@ -77,12 +82,13 @@ public String getString(String key) { /** * Get boolean value for key. * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return boolean true or false
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         Boolean value = group.getBoolean("key");
      *         
*/ @@ -97,12 +103,13 @@ public Boolean getBoolean(String key) { /** * Get {@link JSONArray} value for key * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return JSONArray
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         JSONArray value = group.getJSONArray("key");
      *         
*/ @@ -117,12 +124,13 @@ public JSONArray getJSONArray(String key) { /** * Get {@link JSONObject} value for key * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return JSONObject
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         JSONObject value = group.getJSONObject("key");
      *         
*/ @@ -137,12 +145,13 @@ public JSONObject getJSONObject(String key) { /** * Get {@link JSONObject} value for key * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return Number
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         JSONObject value = group.getJSONObject("key");
      *         
*/ @@ -157,12 +166,13 @@ public Number getNumber(String key) { /** * Get integer value for key * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return int
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         int value = group.getInt("key");
      *         
*/ @@ -177,12 +187,13 @@ public int getInt(String key) { /** * Get integer value for key * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return float
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         float value = group.getFloat("key");
      *         
*/ @@ -197,12 +208,13 @@ public float getFloat(String key) { /** * Get double value for key * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return double
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         double value = group.getDouble("key");
      *         
*/ @@ -217,12 +229,13 @@ public double getDouble(String key) { /** * Get long value for key * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return long
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         long value = group.getLong("key");
      *         
*/ @@ -237,12 +250,13 @@ public long getLong(String key) { /** * Get short value for key * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return short
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         short value = group.getShort("key");
      *         
*/ @@ -257,12 +271,13 @@ public short getShort(String key) { /** * Get {@link Calendar} value for key * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return {@link java.util.Date}
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         Calendar value = group.getDate("key");
      *         
*/ @@ -280,12 +295,13 @@ public Calendar getDate(String key) { /** * Get an asset from the group * - * @param key field_uid as key. + * @param key + * field_uid as key. * @return Asset object
- *
- * Example :
- * - *
+     * 
+ * Example :
+ * + *
      *         Asset asset = group.getAsset("key");
      *         
*/ @@ -297,14 +313,15 @@ public Asset getAsset(String key) { /** * Get an assets from the group. This works with multiple true fields * - * @param key field_uid as key.
- *
- * Example :
- * - *
-     *              {@code List asset = group.getAssets("key"); }
-     *              @return ArrayList of {@link Asset}
-     *            
+ * @param key + * field_uid as key.
+ *
+ * Example :
+ * + *
+     *                      {@code List asset = group.getAssets("key"); }
+     *                      @return ArrayList of {@link Asset}
+     *                    
*/ public List getAssets(String key) { List assets = new ArrayList<>(); @@ -321,15 +338,15 @@ public List getAssets(String key) { /** * Get a group from the group. * - * @param key field_uid as key.
- *
- * Example :
- * - *
-     *              Group innerGroup = group.getGroup("key");            @return Group
-     *         object
-     *            
- * + * @param key + * field_uid as key.
+ *
+ * Example :
+ * + *
+     *                      Group innerGroup = group.getGroup("key");            @return Group
+     *                 object
+     *                    
* @return the group */ public Group getGroup(String key) { @@ -344,14 +361,15 @@ public Group getGroup(String key) { *

* Note :- This will work when group is multiple true. * - * @param key field_uid as key.
- *
- * Example :
- * - *

-     *              Group innerGroup = group.getGroups("key");
-     *         @return List of {@link Group}
-     *            
+ * @param key + * field_uid as key.
+ *
+ * Example :
+ * + *
+     *                      Group innerGroup = group.getGroups("key");
+     *                 @return List of {@link Group}
+     *                    
*/ public List getGroups(String key) { List groupList = new ArrayList<>(); @@ -369,11 +387,12 @@ public List getGroups(String key) { /** * Get value for the given reference key. * - * @param refKey key of a reference field. - * @param refContentType class uid. - * @return {@link ArrayList} of {@link Entry} instances. Also specified - * contentType value will be set as class uid for all {@link Entry} - * instance. + * @param refKey + * key of a reference field. + * @param refContentType + * class uid. + * @return {@link ArrayList} of {@link Entry} instances. Also specified contentType value will be set as class uid + * for all {@link Entry} instance. */ public ArrayList getAllEntries(String refKey, String refContentType) { ArrayList entryContainer = new ArrayList<>(); diff --git a/src/main/java/com/contentstack/sdk/Query.java b/src/main/java/com/contentstack/sdk/Query.java index dcb7d13d..819e1d3a 100644 --- a/src/main/java/com/contentstack/sdk/Query.java +++ b/src/main/java/com/contentstack/sdk/Query.java @@ -3,6 +3,7 @@ import org.jetbrains.annotations.NotNull; import org.json.JSONArray; import org.json.JSONObject; +import retrofit2.Retrofit; import java.util.*; import java.util.logging.Logger; @@ -10,8 +11,8 @@ import static com.contentstack.sdk.Constants.*; /** - * Contentstack provides certain queries that you can use to fetch filtered - * results. You can use queries for Entries and Assets API requests. + * Contentstack provides certain queries that you can use to fetch filtered results. You can use queries for Entries and + * Assets API requests. */ public class Query implements INotifyClass { @@ -30,7 +31,6 @@ public class Query implements INotifyClass { protected JSONArray objectUidForExcept = null; protected JSONArray objectUidForOnly = null; private boolean isJsonProper = true; - private String errorString; private JSONObject onlyJsonObject; private JSONObject exceptJsonObject; @@ -48,22 +48,23 @@ protected void setContentTypeInstance(ContentType contentTypeInstance) { } /** - * To set headers for Built.io Contentstack rest calls.
- * Scope is limited to this object and followed classes. - * - * @param key header name. - * @param value header value against given header name.
- * - * - *
- *
- * Example :
- * - *
-     *              Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
-     *              Query csQuery = stack.contentType("contentTypeUid").query();
- * csQuery.setHeader("custom_key", "custom_value"); - *
+ * To set headers for Built.io Contentstack rest calls.
Scope is limited to this object and followed classes. + * + * @param key + * header name. + * @param value + * header value against given header name.
+ * + * + *
+ *
+ * Example :
+ * + *
+     *                              Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+     *                              Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.setHeader("custom_key", "custom_value"); + *
*/ public void setHeader(@NotNull String key, @NotNull String value) { if (!key.isEmpty() && !value.isEmpty()) { @@ -74,17 +75,18 @@ public void setHeader(@NotNull String key, @NotNull String value) { /** * Remove header key @param key custom_header_key * - * @param key {@link String}
- * - *
- *
- * Example :
- * - *
-     *            Stack stack = Contentstack..stack( "apiKey", "deliveryToken", "environment");
-     *            Query csQuery = stack.contentType("contentTypeUid").query();
- * csQuery.removeHeader("custom_key"); - *
+ * @param key + * {@link String}
+ * + *
+ *
+ * Example :
+ * + *
+     *                            Stack stack = Contentstack..stack( "apiKey", "deliveryToken", "environment");
+     *                            Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.removeHeader("custom_key"); + *
*/ public void removeHeader(@NotNull String key) { if (!key.isEmpty()) { @@ -97,21 +99,22 @@ public String getContentType() { } /** - * Add a constraint to fetch all entries that contains given value against - * specified key + * Add a constraint to fetch all entries that contains given value against specified key * - * @param key field uid. - * @param value field value which get 'included' from the response. + * @param key + * field uid. + * @param value + * field value which get 'included' from the response. * @return {@link Query} object, so you can chain this call. - *

- * Note : for group field provide key in a - * "key.groupFieldUid" format.
- * - *
- *
- * Example :
- * - *

+     * 

+ * Note : for group field provide key in a + * "key.groupFieldUid" format.
+ * + *
+ *
+ * Example :
+ * + *

      *          Stack stack = Contentstack..stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
      *          csQuery.where("uid", "entry_uid");
@@ -126,15 +129,17 @@ public Query where(@NotNull String key, Object value) {
     /**
      * Add a custom query against specified key.
      *
-     * @param key   key.
-     * @param value value.
+     * @param key
+     *         key.
+     * @param value
+     *         value.
      * @return {@link Query} object, so you can chain this call.
      *
-     *         
- *
- * Example :
- * - *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack..stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
      *          csQuery.addQuery("query_param_key", "query_param_value");
@@ -150,14 +155,15 @@ public Query addQuery(@NotNull String key, String value) {
     /**
      * Remove provided query key from custom query if exist.
      *
-     * @param key Query name to remove.
+     * @param key
+     *         Query name to remove.
      * @return {@linkplain Query} object, so you can chain this call. 
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *         projectQuery.removeQuery("Query_Key");
      *         
*/ @@ -171,15 +177,15 @@ public Query removeQuery(@NotNull String key) { /** * Combines all the queries together using AND operator * - * @param queryObjects list of {@link Query} instances on which AND query - * executes. + * @param queryObjects + * list of {@link Query} instances on which AND query executes. * @return {@link Query} object, so you can chain this call. * - *
- *
- * Example ;
- * - *
+     * 
+ *
+ * Example ;
+ * + *
      *          Stack stack = Contentstack..stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
      *
@@ -209,15 +215,15 @@ public Query and(@NotNull ArrayList queryObjects) {
     /**
      * Add a constraint to fetch all entries which satisfy  any  queries.
      *
-     * @param queryObjects list of {@link Query} instances on which OR query
-     *                     executes.
+     * @param queryObjects
+     *         list of {@link Query} instances on which OR query executes.
      * @return {@link Query} object, so you can chain this call.
      *
-     *         
- *
- * Example :
- * - *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
      *
@@ -251,18 +257,19 @@ public Query or(ArrayList queryObjects) {
     }
 
     /**
-     * Add a constraint to the query that requires a particular key entry to be less
-     * than the provided value.
+     * Add a constraint to the query that requires a particular key entry to be less than the provided value.
      *
-     * @param key   the key to be constrained.
-     * @param value the value that provides an upper bound.
+     * @param key
+     *         the key to be constrained.
+     * @param value
+     *         the value that provides an upper bound.
      * @return {@link Query} object, so you can chain this call. 
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.lessThan("due_date", "2013-06-25T00:00:00+05:30");
@@ -283,18 +290,20 @@ public Query lessThan(@NotNull String key, @NotNull Object value) {
     }
 
     /**
-     * Add a constraint to the query that requires a particular key entry to be less
-     * than or equal to the provided value.
+     * Add a constraint to the query that requires a particular key entry to be less than or equal to the provided
+     * value.
      *
-     * @param key   The key to be constrained
-     * @param value The value that must be equalled.
+     * @param key
+     *         The key to be constrained
+     * @param value
+     *         The value that must be equalled.
      * @return {@link Query} object, so you can chain this call.
      *
-     *         
- *
- * Example :
- * - *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.lessThanOrEqualTo("due_date", "2013-06-25T00:00:00+05:30");
@@ -315,18 +324,19 @@ public Query lessThanOrEqualTo(@NotNull String key, Object value) {
     }
 
     /**
-     * Add a constraint to the query that requires a particular key entry to be
-     * greater than the provided value.
+     * Add a constraint to the query that requires a particular key entry to be greater than the provided value.
      *
-     * @param key   The key to be constrained.
-     * @param value The value that provides an lower bound.
+     * @param key
+     *         The key to be constrained.
+     * @param value
+     *         The value that provides an lower bound.
      * @return {@link Query} object, so you can chain this call.
      *
-     *         
- *
- * Example :
- * - *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.greaterThan("due_date", "2013-06-25T00:00:00+05:30");
@@ -347,18 +357,20 @@ public Query greaterThan(@NotNull String key, Object value) {
     }
 
     /**
-     * Add a constraint to the query that requires a particular key entry to be
-     * greater than or equal to the provided value.
+     * Add a constraint to the query that requires a particular key entry to be greater than or equal to the provided
+     * value.
      *
-     * @param key   The key to be constrained.
-     * @param value The value that provides an lower bound.
+     * @param key
+     *         The key to be constrained.
+     * @param value
+     *         The value that provides an lower bound.
      * @return {@link Query} object, so you can chain this call.
      *
-     *         
- *
- * Example :
- * - *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.greaterThanOrEqualTo("due_date", "2013-06-25T00:00:00+05:30");
@@ -379,18 +391,19 @@ public Query greaterThanOrEqualTo(String key, Object value) {
     }
 
     /**
-     * Add a constraint to the query that requires a particular key's entry to
-     * be not equal to the provided value.
+     * Add a constraint to the query that requires a particular key's entry to be not equal to the provided value.
      *
-     * @param key   The key to be constrained.
-     * @param value The object that must not be equaled.
+     * @param key
+     *         The key to be constrained.
+     * @param value
+     *         The object that must not be equaled.
      * @return {@link Query} object, so you can chain this call.
      *
-     *         
- *
- * Example ;
- * - *
+     * 
+ *
+ * Example ;
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.notEqualTo("due_date", "2013-06-25T00:00:00+05:30");
@@ -411,18 +424,19 @@ public Query notEqualTo(@NotNull String key, Object value) {
     }
 
     /**
-     * Add a constraint to the query that requires a particular key's entry to
-     * be contained in the provided array.
+     * Add a constraint to the query that requires a particular key's entry to be contained in the provided array.
      *
-     * @param key    The key to be constrained.
-     * @param values The possible values for the key's object.
+     * @param key
+     *         The key to be constrained.
+     * @param values
+     *         The possible values for the key's object.
      * @return {@link Query} object, so you can chain this call. 
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.containedIn("severity", new Object[] { "Show Stopper", "Critical" });
@@ -448,19 +462,21 @@ public Query containedIn(@NotNull String key, Object[] values) {
     }
 
     /**
-     * Add a constraint to the query that requires a particular key entry's
-     * value not be contained in the provided array.
+     * Add a constraint to the query that requires a particular key entry's value not be contained in the provided
+     * array.
      *
-     * @param key    The key to be constrained.
-     * @param values The list of values the key object should not be.
+     * @param key
+     *         The key to be constrained.
+     * @param values
+     *         The list of values the key object should not be.
      * @return {@link Query} object, so you can chain this call.
      *
-     * 
-     *         
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.notContainedIn("severity", new Object[] { "Show Stopper", "Critical" });
@@ -488,14 +504,15 @@ public Query notContainedIn(@NotNull String key, Object[] values) {
     /**
      * Add a constraint that requires, a specified key exists in response.
      *
-     * @param key The key to be constrained.
+     * @param key
+     *         The key to be constrained.
      * @return {@link Query} object, so you can chain this call.
      *
-     *         
- *
- * Example :
- * - *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.exists("status");
@@ -518,15 +535,16 @@ public Query exists(@NotNull String key) {
     /**
      * Add a constraint that requires, a specified key does not exists in response.
      *
-     * @param key The key to be constrained.
+     * @param key
+     *         The key to be constrained.
      * @return {@link Query} object, so you can chain this call. 
- * - * - *
- *
- * Example :
- * - *
+     *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.notExists("status");
@@ -550,14 +568,15 @@ public Query notExists(@NotNull String key) {
     /**
      * Add a constraint that requires a particular reference key details.
      *
-     * @param key key that to be constrained.
+     * @param key
+     *         key that to be constrained.
      * @return {@link Query} object, so you can chain this call.
      *
-     *         
- *
- * Example :
- * - *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.includeReference("for_bug");
@@ -574,14 +593,15 @@ public Query includeReference(String key) {
     /**
      * Include tags with which to search entries.
      *
-     * @param tags Comma separated array of tags with which to search entries.
+     * @param tags
+     *         Comma separated array of tags with which to search entries.
      * @return {@link Query} object, so you can chain this call. 
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.tags(new String[] { "tag1", "tag2" });
@@ -598,17 +618,18 @@ public Query tags(@NotNull String[] tags) {
     }
 
     /**
-     * Sort the results in ascending order with the given key. 
- * Sort the returned entries in ascending order of the provided key. + * Sort the results in ascending order with the given key.
Sort the returned entries in ascending order of the + * provided key. * - * @param key The key to order by. + * @param key + * The key to order by. * @return {@link Query} object, so you can chain this call.
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.ascending("name");
@@ -621,17 +642,18 @@ public Query ascending(@NotNull String key) {
     }
 
     /**
-     * Sort the results in descending order with the given key. 
- * Sort the returned entries in descending order of the provided key. + * Sort the results in descending order with the given key.
Sort the returned entries in descending order of + * the provided key. * - * @param key The key to order by. + * @param key + * The key to order by. * @return {@link Query} object, so you can chain this call.
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.descending("name");
@@ -643,18 +665,18 @@ public Query descending(@NotNull String key) {
     }
 
     /**
-     * Specifies list of field uids that would be 'excluded' from the
-     * response.
+     * Specifies list of field uids that would be 'excluded' from the response.
      *
-     * @param fieldUid field uid which get 'excluded' from the response.
+     * @param fieldUid
+     *         field uid which get 'excluded' from the response.
      * @return {@link Query} object, so you can chain this call.
      *
-     * 
-     *         
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* ArrayList<String> array = new ArrayList<String>(); @@ -676,17 +698,17 @@ public Query except(@NotNull ArrayList fieldUid) { } /** - * Specifies list of field uids that would be 'excluded' from the - * response. + * Specifies list of field uids that would be 'excluded' from the response. * - * @param fieldIds field uid which get 'excluded' from the response. + * @param fieldIds + * field uid which get 'excluded' from the response. * @return {@link Query} object, so you can chain this call.
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.except(new String[]{"name", "description"}); @@ -705,18 +727,17 @@ public Query except(@NotNull String[] fieldIds) { } /** - * Specifies an array of 'only' keys in BASE object that would be - * 'included' in the response. + * Specifies an array of 'only' keys in BASE object that would be 'included' in the response. * - * @param fieldUid Array of the 'only' reference keys to be included in - * response. + * @param fieldUid + * Array of the 'only' reference keys to be included in response. * @return {@link Query} object, so you can chain this call.
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.only(new String[]{"name"}); @@ -735,20 +756,20 @@ public Query only(@NotNull String[] fieldUid) { } /** - * Specifies an array of 'only' keys that would be 'included' in - * the response. + * Specifies an array of 'only' keys that would be 'included' in the response. * - * @param fieldUid Array of the 'only' reference keys to be - * included in response. - * @param referenceFieldUid Key who has reference to some other class object. + * @param fieldUid + * Array of the 'only' reference keys to be included in response. + * @param referenceFieldUid + * Key who has reference to some other class object. * @return {@link Query} object, so you can chain this call.
- * - * - *
- *
- * Example :
- * - *
+     *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* ArrayList<String> array = new ArrayList<String>(); @@ -774,19 +795,19 @@ public Query onlyWithReferenceUid(@NotNull ArrayList fieldUid, @NotNull } /** - * Specifies an array of 'except' keys that would be 'excluded' - * in the response. + * Specifies an array of 'except' keys that would be 'excluded' in the response. * - * @param fieldUid Array of the 'except' reference keys to be - * excluded in response. - * @param referenceFieldUid Key who has reference to some other class object. + * @param fieldUid + * Array of the 'except' reference keys to be excluded in response. + * @param referenceFieldUid + * Key who has reference to some other class object. * @return {@link Query} object, so you can chain this call.
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* ArrayList<String> array = new ArrayList<String>(); @@ -814,15 +835,14 @@ public Query exceptWithReferenceUid(@NotNull ArrayList fieldUid, @NotNul /** * Retrieve only count of entries in result. * - * @return {@link Query} object, so you can chain this call. Note :- - * Call {@link QueryResult#getCount()} method in the success to get - * count of objects.
- * - *
- *
- * Example :
- * - *
+     * @return {@link Query} object, so you can chain this call. Note :-  Call {@link QueryResult#getCount()}
+     * method in the success to get count of objects. 
+ * + *
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.count(); @@ -836,15 +856,14 @@ public Query count() { /** * Retrieve count and data of objects in result * - * @return {@link Query} object, so you can chain this call. Note :- - * Call {@link QueryResult#getCount()} method in the success to get - * count of objects.
- * - *
- *
- * Example :
- * - *
+     * @return {@link Query} object, so you can chain this call. Note :-  Call {@link QueryResult#getCount()}
+     * method in the success to get count of objects. 
+ * + *
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.includeCount(); @@ -859,12 +878,12 @@ public Query includeCount() { * Include Content Type of all returned objects along with objects themselves. * * @return {@link Query} object, so you can chain this call.
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.includeContentType(); @@ -883,12 +902,12 @@ public Query includeContentType() { * Include object owner's profile in the objects data. * * @return {@linkplain Query} object, so you can chain this call.
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.includeOwner(); @@ -902,18 +921,18 @@ public Query includeOwner() { /** * The number of objects to skip before returning any. * - * @param number No of objects to skip from returned objects + * @param number + * No of objects to skip from returned objects * @return {@link Query} object, so you can chain this call. - *

- * Note: The skip parameter can be used for pagination, - * "skip" specifies the number of objects to skip in the - * response.
- * - *
- *
- * Example :
- * - *

+     * 

+ * Note: The skip parameter can be used for pagination, + * "skip" specifies the number of objects to skip in the response.
+ * + *
+ *
+ * Example :
+ * + *

      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.skip(2); @@ -927,18 +946,18 @@ public Query skip(int number) { /** * A limit on the number of objects to return. * - * @param number No of objects to limit. + * @param number + * No of objects to limit. * @return {@link Query} object, so you can chain this call. - *

- * Note: The limit parameter can be used for pagination, " - * limit" specifies the number of objects to limit to in the - * response.
- * - *
- *
- * Example :
- * - *

+     * 

+ * Note: The limit parameter can be used for pagination, " + * limit" specifies the number of objects to limit to in the response.
+ * + *
+ *
+ * Example :
+ * + *

      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.limit(2); @@ -950,18 +969,20 @@ public Query limit(int number) { } /** - * Add a regular expression constraint for finding string values that match the - * provided regular expression. This may be slow for large data sets. + * Add a regular expression constraint for finding string values that match the provided regular expression. This + * may be slow for large data sets. * - * @param key The key to be constrained. - * @param regex The regular expression pattern to match. + * @param key + * The key to be constrained. + * @param regex + * The regular expression pattern to match. * @return {@link Query} object, so you can chain this call.
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.regex("name", "^browser"); @@ -983,28 +1004,31 @@ public Query regex(@NotNull String key, @NotNull String regex) { } /** - * Add a regular expression constraint for finding string values that match the - * provided regular expression. This may be slow for large data sets. - * - * @param key The key to be constrained. - * @param regex The regular expression pattern to match - * @param modifiers Any of the following supported Regular expression modifiers. - *

- * use i for case-insensitive matching. - *

- *

- * use m for making dot match newlines. - *

- *

- * use x for ignoring whitespace in regex - *

+ * Add a regular expression constraint for finding string values that match the provided regular expression. This + * may be slow for large data sets. + * + * @param key + * The key to be constrained. + * @param regex + * The regular expression pattern to match + * @param modifiers + * Any of the following supported Regular expression modifiers. + *

+ * use i for case-insensitive matching. + *

+ *

+ * use m for making dot match newlines. + *

+ *

+ * use x for ignoring whitespace in regex + *

* @return {@link Query} object, so you can chain this call.
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.regex("name", "^browser", "i"); @@ -1038,13 +1062,14 @@ public Query regex(@NotNull String key, @NotNull String regex, String modifiers) /** * set Language using locale code. * - * @param locale {@link String} value + * @param locale + * {@link String} value * @return {@link Query} object, so you can chain this call
- *
- *
- * Example :
- * - *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.locale("en-us"); @@ -1058,14 +1083,15 @@ public Query locale(@NotNull String locale) { /** * This method provides only the entries matching the specified value. * - * @param value value used to match or compare + * @param value + * value used to match or compare * @return {@link Query} object, so you can chain this call.
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.search("header"); @@ -1082,16 +1108,16 @@ public Query search(@NotNull String value) { /** * Execute a Query and Caches its result (Optional) * - * @param callback {@link QueryResultsCallBack} object to notify the application - * when the request has completed. + * @param callback + * {@link QueryResultsCallBack} object to notify the application when the request has completed. * @return {@linkplain Query} object, so you can chain this call.
- * - * - *
- *
- * Example :
- * - *
+     *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.find(new QueryResultsCallBack() {
@@ -1121,15 +1147,15 @@ public Query find(QueryResultsCallBack callback) { /** * Execute a Query and Caches its result (Optional) * - * @param callBack {@link QueryResultsCallBack} object to notify the application - * when the request has completed. + * @param callBack + * {@link QueryResultsCallBack} object to notify the application when the request has completed. * @return {@linkplain Query} object, so you can chain this call.
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.findOne(new QueryResultsCallBack() {
@@ -1227,14 +1253,16 @@ private void includeLivePreview() { if (configInstance.livePreviewHash == null || configInstance.livePreviewHash.isEmpty()) { configInstance.livePreviewHash = "init"; } - this.headers.put("live_preview", configInstance.livePreviewHash); + //this.headers.put("live_preview", configInstance.livePreviewHash); + urlQueries.put("live_preview", configInstance.livePreviewHash); + urlQueries.put("content_type_uid", contentTypeUid); this.headers.put("authorization", configInstance.managementToken); } } // fetch from network. private void fetchFromNetwork(String urlString, JSONObject jsonMain, ResultCallBack callback, - SingleQueryResultCallback resultCallback) { + SingleQueryResultCallback resultCallback) { LinkedHashMap urlParams = getUrlParams(jsonMain); if (resultCallback != null) { new CSBackgroundTask(this, contentTypeInstance.stackInstance, Constants.SINGLEQUERYOBJECT, urlString, @@ -1305,15 +1333,17 @@ public void getResultObject(List objects, JSONObject jsonObject, boolean /** * This method adds key and value to an Entry. Parameters: * - * @param paramKey: The key as string which needs to be added to the Query - * @param paramValue: The value as string which needs to be added to the Query + * @param paramKey: + * The key as string which needs to be added to the Query + * @param paramValue: + * The value as string which needs to be added to the Query * @return - Query * - *
- *
- * Example :
- * - *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.addParam("key", "some_value");
@@ -1330,16 +1360,15 @@ public Query addParam(@NotNull String paramKey, @NotNull String paramValue) {
     }
 
     /**
-     * This method also includes the content type UIDs of the referenced entries
-     * returned in the response
+     * This method also includes the content type UIDs of the referenced entries returned in the response
      *
      * @return {@link Query} 
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *          Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
      *          Query csQuery = stack.contentType("contentTypeUid").query();
* csQuery.includeReferenceContentTypUid(); @@ -1356,18 +1385,20 @@ public Query includeReferenceContentTypUid() { } /** - * Get entries having values based on referenced fields. This query retrieves - * all entries that satisfy the query conditions made on referenced fields. + * Get entries having values based on referenced fields. This query retrieves all entries that satisfy the query + * conditions made on referenced fields. * - * @param key The key to be constrained - * @param queryObject {@link Query} object, so you can chain this call + * @param key + * The key to be constrained + * @param queryObject + * {@link Query} object, so you can chain this call * @return {@link Query} object, so you can chain this call
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.whereIn("due_date", csQuery);
@@ -1381,19 +1412,20 @@ public Query whereIn(@NotNull String key, Query queryObject) {
     }
 
     /**
-     * Get entries having values based on referenced fields. This query works the
-     * opposite of $in_query and retrieves all entries that does not satisfy query
-     * conditions made on referenced fields.
+     * Get entries having values based on referenced fields. This query works the opposite of $in_query and retrieves
+     * all entries that does not satisfy query conditions made on referenced fields.
      *
-     * @param key         The key to be constrained
-     * @param queryObject {@link Query} object, so you can chain this call
+     * @param key
+     *         The key to be constrained
+     * @param queryObject
+     *         {@link Query} object, so you can chain this call
      * @return {@link Query} object, so you can chain this call
      *
-     *         
- *
- * Example :
- * - *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.whereNotIn("due_date", csQuery);
@@ -1407,16 +1439,15 @@ public Query whereNotIn(@NotNull String key, Query queryObject) {
     }
 
     /**
-     * Retrieve the published content of the fallback locale if an entry is not
-     * localized in specified locale
+     * Retrieve the published content of the fallback locale if an entry is not localized in specified locale
      *
      * @return {@link Query} object, so you can chain this call. 
- * - *
- *
- * Example :
- * - *
+     *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", environment);
      *         Query csQuery = stack.contentType("contentTypeUid").query();
      *         csQuery.includeFallback();
@@ -1429,15 +1460,13 @@ public Query includeFallback() {
 
     /**
      * @return {@link Query} object, so you can chain this call. 
- * - * * @return {@link Query} - * - *
- *
- * Example :
* - *
+     * 
+ *
+ * Example :
+ * + *
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", environment);
      *         Query query = stack.contentType("contentTypeUid").query();
      *         query.includeEmbeddedObjects()
@@ -1453,11 +1482,11 @@ public Query includeEmbeddedItems() {
      *
      * @return {@link Query} object, so you can chain this call. 
* - *
- *
- * Example :
+ *
+ *
+ * Example :
* - *
+     * 
      *         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
      *         Query query = stack.contentType("contentTypeUid").query();
      *         entry.includeBranch();
diff --git a/src/main/java/com/contentstack/sdk/Stack.java b/src/main/java/com/contentstack/sdk/Stack.java
index c5bd51ab..0ab98d41 100644
--- a/src/main/java/com/contentstack/sdk/Stack.java
+++ b/src/main/java/com/contentstack/sdk/Stack.java
@@ -1,8 +1,13 @@
 package com.contentstack.sdk;
 
+import okhttp3.ConnectionPool;
+import okhttp3.OkHttpClient;
 import org.jetbrains.annotations.NotNull;
 import org.json.JSONObject;
+import retrofit2.Retrofit;
+import retrofit2.converter.jackson.JacksonConverterFactory;
 
+import java.net.Proxy;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -12,9 +17,8 @@
 import static com.contentstack.sdk.Constants.*;
 
 /**
- * A stack is a repository or a container that holds all the content/assets of
- * your site. It allows multiple users to create, edit, approve, and publish
- * their content within a single space.
+ * A stack is a repository or a container that holds all the content/assets of your site. It allows multiple users to
+ * create, edit, approve, and publish their content within a single space.
  */
 public class Stack {
 
@@ -22,6 +26,7 @@ public class Stack {
     protected LinkedHashMap headers;
     protected Config config;
     protected String contentType;
+    protected APIService service;
     protected String apiKey;
     protected JSONObject syncParams = null;
 
@@ -54,11 +59,30 @@ protected void setConfig(Config config) {
         }
 
         includeLivePreview();
-        // Set the endpoint
         String endpoint = config.scheme + config.host;
         this.config.setEndpoint(endpoint);
+
+        client(endpoint);
+    }
+
+    //Setting a global client with the connection pool configuration solved the issue
+    private void client(String endpoint) {
+        Proxy proxy = this.config.getProxy();
+        ConnectionPool pool = this.config.connectionPool;
+        OkHttpClient client = new OkHttpClient.Builder()
+                .proxy(proxy)
+                .connectionPool(pool)
+                .build();
+
+        Retrofit retrofit = new Retrofit.Builder().baseUrl(endpoint)
+                .client(client)
+                .addConverterFactory(JacksonConverterFactory.create())
+                .build();
+
+        this.service = retrofit.create(APIService.class);
     }
 
+
     private void includeLivePreview() {
         try {
             if (config.enableLivePreview) {
@@ -78,28 +102,26 @@ private void includeLivePreview() {
     }
 
     /**
-     * Live Preview lets content managers preview entry content across multiple
-     * channels before saving or publishing it to a live website. You can edit an
-     * entry and preview the content changes side by side in real-time.
+     * Live Preview lets content managers preview entry content across multiple channels before saving or publishing it
+     * to a live website. You can edit an entry and preview the content changes side by side in real-time.
      * 

* Note: To be able to preview entry content, developers need to first - * configure Live Preview for the frontend website and then enable it from the - * stack settings section in Contentstack. You can set up the base URL and - * environment across which you want to preview content. + * configure Live Preview for the frontend website and then enable it from the stack settings section in + * Contentstack. You can set up the base URL and environment across which you want to preview content. *

* - * @param query the query of type {@link HashMap} + * @param query + * the query of type {@link HashMap} * @return stack - *

- * Example - * - * - * stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); - *

- * HashMap queryMap = new HashMap(); - *

- * stack.livePreviewQuery(queryMap) - * + *

+ * Example + *

+ *

+ * stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); + *

+ * HashMap queryMap = new HashMap(); + *

+ * stack.livePreviewQuery(queryMap) */ public Stack livePreviewQuery(Map query) { if (this.config.enableLivePreview) { @@ -110,51 +132,44 @@ public Stack livePreviewQuery(Map query) { } /** - * Content type defines the structure or schema of a page or a section of your - * web or mobile property. To create content for your application, you are - * required to first create a content type, and then create entries using the + * Content type defines the structure or schema of a page or a section of your web or mobile property. To create + * content for your application, you are required to first create a content type, and then create entries using the * content type. * - * @param contentTypeUid Enter the unique ID of the content type of which you - * want to retrieve the entries. The UID is often based on - * the title of the content type and it is unique across a - * stack. + * @param contentTypeUid + * Enter the unique ID of the content type of which you want to retrieve the entries. The UID is often based + * on the title of the content type and it is unique across a stack. * @return the {@link ContentType} - *

- * Example + *

+ * Example * - *

+     * 
      *  Stack stack = contentstack.Stack("apiKey",
      * "deliveryToken", "environment"); ContentType contentType = stack.contentType("contentTypeUid")
      *         
*/ public ContentType contentType(String contentTypeUid) { - this.contentType = contentTypeUid; // set contentTypeUid for stack instance + this.contentType = contentTypeUid; ContentType ct = new ContentType(contentTypeUid); ct.setStackInstance(this); return ct; } /** - * Assets refer to all the media files (images, videos, PDFs, audio files, and - * so on) uploaded in your Contentstack repository for future use. These files - * can be attached and used in multiple entries. - *

- * The Get a single asset request fetches the latest version of a specific asset - * of a particular stack. + * Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack + * repository for future use. These files can be attached and used in multiple entries. + *

+ * The Get a single asset request fetches the latest version of a specific asset of a particular stack. *

* - * @param uid uid of {@link Asset} - * @return {@link Asset} instance Tip: If no version is mentioned, the - * request will retrieve the latest published version of the asset. To - * retrieve a specific version, use the version parameter, keep the - * environment parameter blank, and use the management token instead of - * the delivery token. - *

- * Example Stack stack = contentstack.Stack("apiKey", - * "deliveryToken", "environment"); Asset asset = - * stack.asset("assetUid"); - * + * @param uid + * uid of {@link Asset} + * @return {@link Asset} instance Tip: If no version is mentioned, the request will retrieve the latest + * published version of the asset. To retrieve a specific version, use the version parameter, keep the environment + * parameter blank, and use the management token instead of the delivery token. + *

+ * Example Stack stack = contentstack.Stack("apiKey", + * "deliveryToken", "environment"); Asset asset = stack.asset("assetUid"); */ public Asset asset(@NotNull String uid) { Asset asset = new Asset(uid); @@ -169,14 +184,14 @@ protected Asset asset() { } /** - * The Get all assets request fetches the list of all the assets of a particular - * stack. It returns the content of each asset in JSON format. + * The Get all assets request fetches the list of all the assets of a particular stack. It returns the content of + * each asset in JSON format. * * @return {@link AssetLibrary} asset library - *

- * Example + *

+ * Example * - *

+     * 
      *         Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
      *         AssetLibrary assets = stack.assetLibrary();
      *         
@@ -218,9 +233,10 @@ public String getDeliveryToken() { /** * Removes Header by key * - * @param headerKey of the header - *

- * Example: stack.removeHeader("delivery_token"); + * @param headerKey + * of the header + *

+ * Example: stack.removeHeader("delivery_token"); */ public void removeHeader(String headerKey) { headers.remove(headerKey); @@ -229,8 +245,10 @@ public void removeHeader(String headerKey) { /** * Adds header to the stack * - * @param headerKey the header key - * @param headerValue the header value + * @param headerKey + * the header key + * @param headerValue + * the header value */ public void setHeader(@NotNull String headerKey, @NotNull String headerValue) { if (!headerKey.isEmpty() && !headerValue.isEmpty()) { @@ -239,13 +257,14 @@ public void setHeader(@NotNull String headerKey, @NotNull String headerValue) { } /** - * Image transform string. This document is a detailed reference to Contentstack - * Image Delivery API and covers the parameters that you can add to the URL to - * retrieve, manipulate (or convert) image files and display it to your web or - * mobile properties. - * - * @param imageUrl the image url - * @param parameters the parameters {@link LinkedHashMap} + * Image transform string. This document is a detailed reference to Contentstack Image Delivery API and covers the + * parameters that you can add to the URL to retrieve, manipulate (or convert) image files and display it to your + * web or mobile properties. + * + * @param imageUrl + * the image url + * @param parameters + * the parameters {@link LinkedHashMap} * @return the string */ public String imageTransform(@NotNull String imageUrl, @NotNull Map parameters) { @@ -266,13 +285,14 @@ protected String getQueryParam(Map params) { } /** - * The Get all content types call returns comprehensive information of all the - * content types available in a particular stack in your account.. - * - * @param params query parameters - * @param callback ContentTypesCallback This call returns comprehensive - * information of all the content types available in a - * particular stack in your account. + * The Get all content types call returns comprehensive information of all the content types available in a + * particular stack in your account.. + * + * @param params + * query parameters + * @param callback + * ContentTypesCallback This call returns comprehensive information of all the content types available in a + * particular stack in your account. */ public void getContentTypes(@NotNull JSONObject params, final ContentTypesCallback callback) { Iterator keys = params.keys(); @@ -289,13 +309,12 @@ public void getContentTypes(@NotNull JSONObject params, final ContentTypesCallba } /** - * The Sync request performs a complete sync of your app data. It returns all - * the published entries and assets of the specified stack in response. The - * response also contains a sync token, which you need to store, since this + * The Sync request performs a complete sync of your app data. It returns all the published entries and assets of + * the specified stack in response. The response also contains a sync token, which you need to store, since this * token is used to get subsequent delta * - * @param syncCallBack returns callback for sync result. - * + * @param syncCallBack + * returns callback for sync result. */ public void sync(SyncResultCallBack syncCallBack) { syncParams = new JSONObject(); @@ -306,25 +325,19 @@ public void sync(SyncResultCallBack syncCallBack) { /** * Sync pagination token. * - * @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.
- *
- * Example :
- * + * @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.
+ *
+ * Example :
*/ public void syncPaginationToken(@NotNull String paginationToken, SyncResultCallBack syncCallBack) { this.sync(null); @@ -335,21 +348,20 @@ public void syncPaginationToken(@NotNull String paginationToken, SyncResultCallB /** * Sync token. * - * @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. The - * sync token fetches only the content that was added after - * your last sync, and the details of the content that was - * deleted or updated.
- *
- * Example :
- * - *

-     *                     stack.syncToken(sync_token, new SyncResultCallBack()                                                                                                                                                                                                               ){ }
-     *                     
+ * @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. + * The sync token fetches only the content that was added after your last sync, and the details of the + * content that was deleted or updated.
+ *
+ * Example :
+ * + *

+     *                                                                                                                                                                                     stack.syncToken(sync_token, new SyncResultCallBack()                                                                                                                                                                                                               ){ }
+     *                                                                                                                                                                                     
*/ public void syncToken(String syncToken, SyncResultCallBack syncCallBack) { this.sync(null); @@ -360,21 +372,22 @@ public void syncToken(String syncToken, SyncResultCallBack syncCallBack) { /** * Sync from date. * - * @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 and specify - * the start date as its value.
- *
- * Example :
+ * @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 + * and specify the start date as its value.
+ *
+ * Example :
* - *

-     *                     final Date start_date = sdf.parse("2018-10-07"); 

- * stack.syncFromDate(start_date, SyncResultCallBack()) { + *

+     *                                                                                                                                                                                     final Date start_date = sdf.parse("2018-10-07"); 

+ * stack.syncFromDate(start_date, SyncResultCallBack()) { * - * } - *

+ * } + *
*/ public void syncFromDate(@NotNull Date fromDate, SyncResultCallBack syncCallBack) { String newFromDate = convertUTCToISO(fromDate); @@ -393,20 +406,18 @@ protected String convertUTCToISO(Date date) { /** * Sync 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 : - *

- * stack.syncContentType(String content_type, new - * SyncResultCallBack()){ } - * + * @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 : + *

+ * stack.syncContentType(String content_type, new SyncResultCallBack()){ } */ public void syncContentType(@NotNull String contentType, SyncResultCallBack syncCallBack) { this.sync(null); @@ -417,19 +428,16 @@ public void syncContentType(@NotNull String contentType, SyncResultCallBack sync /** * Sync locale. * - * @param localeCode Select the required locale code. - * @param syncCallBack Returns callback for sync result. - *

- * You can also initialize sync with entries of only - * specific locales. To do this, use syncLocale and specify - * the locale code as its value. However, if you do this, - * the subsequent syncs will only include the entries of the - * specified locales.
- *
- * Example :
- * - * - * + * @param localeCode + * Select the required locale code. + * @param syncCallBack + * Returns callback for sync result. + *

+ * You can also initialize sync with entries of only specific locales. To do this, use syncLocale and + * specify the locale code as its value. However, if you do this, the subsequent syncs will only include the + * entries of the specified locales.
+ *
+ * Example :
*/ public void syncLocale(String localeCode, SyncResultCallBack syncCallBack) { this.sync(null); @@ -440,27 +448,25 @@ public void syncLocale(String localeCode, SyncResultCallBack syncCallBack) { /** * Sync publish type. * - * @param publishType 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.) - * @param syncCallBack returns callback for sync result. - *

- * 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. - *
- *
- * Example :
- * - *

-     *                     stackInstance.syncPublishType(Stack.PublishType.entry_published, new SyncResultCallBack()) { }
-     *                     
+ * @param publishType + * 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.) + * @param syncCallBack + * returns callback for sync result. + *

+ * 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. + *
+ *
+ * Example :
+ * + *

+     *                                                                                                                                                                                     stackInstance.syncPublishType(Stack.PublishType.entry_published, new SyncResultCallBack()) { }
+     *                                                                                                                                                                                     
*/ public void syncPublishType(PublishType publishType, SyncResultCallBack syncCallBack) { this.sync(null); @@ -471,21 +477,22 @@ public void syncPublishType(PublishType publishType, SyncResultCallBack syncCall /** * Sync. * - * @param contentType your content type id - * @param fromDate start date - * @param localeCode language as language code - * @param publishType type as PublishType - * @param syncCallBack Callback - *

- * You can also initialize sync with entries that satisfy - * multiple parameters. To do this, use syncWith and specify - * the parameters. However, if you do this, the subsequent - * syncs will only include the entries of the specified - * parameters
- *
- * Example :
- * - * + * @param contentType + * your content type id + * @param fromDate + * start date + * @param localeCode + * language as language code + * @param publishType + * type as PublishType + * @param syncCallBack + * Callback + *

+ * You can also initialize sync with entries that satisfy multiple parameters. To do this, use syncWith and + * specify the parameters. However, if you do this, the subsequent syncs will only include the entries of + * the specified parameters
+ *
+ * Example :
*/ public void sync( String contentType, Date fromDate, String localeCode, PublishType publishType, SyncResultCallBack syncCallBack) { @@ -506,7 +513,7 @@ private void requestSync(final SyncResultCallBack callback) { } private void fetchContentTypes(String urlString, JSONObject contentTypeParam, HashMap headers, - ContentTypesCallback callback) { + ContentTypesCallback callback) { if (callback != null) { HashMap queryParam = getUrlParams(contentTypeParam); String requestInfo = REQUEST_CONTROLLER.CONTENTTYPES.toString(); @@ -516,7 +523,7 @@ private void fetchContentTypes(String urlString, JSONObject contentTypeParam, Ha } private void fetchFromNetwork(String urlString, JSONObject urlQueries, HashMap headers, - SyncResultCallBack callback) { + SyncResultCallBack callback) { if (callback != null) { HashMap urlParams = getUrlParams(urlQueries); String requestInfo = REQUEST_CONTROLLER.SYNC.toString(); diff --git a/src/test/java/com/contentstack/sdk/TestConfig.java b/src/test/java/com/contentstack/sdk/TestConfig.java new file mode 100644 index 00000000..c3768770 --- /dev/null +++ b/src/test/java/com/contentstack/sdk/TestConfig.java @@ -0,0 +1,51 @@ +package com.contentstack.sdk; + +import okhttp3.ConnectionPool; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.util.HashMap; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * The type Config testcase. + */ +public class TestConfig { + + private static final Logger logger = Logger.getLogger(TestConfig.class.getName()); + private static Config config; + + + @BeforeAll + public static void setUp() { + logger.setLevel(Level.FINE); + config = new Config(); + } + + + @Test + void testNullProxy() { + Assertions.assertNotNull(config.getProxy()); + } + + @Test + void testsSetProxy() { + java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("sl.thefakevpn.io", 80)); + config.setProxy(proxy); + Proxy newProxy = config.getProxy(); + Assertions.assertNotNull(newProxy.address().toString()); + } + + @Test + void testsConnectionPool() { + ConnectionPool pool = config.connectionPool; + pool.connectionCount(); + pool.idleConnectionCount();; + Assertions.assertNotNull(pool); + } + +} From e6fc87f4a3dc09c7e24a6ca17f2a6eb64ac8c4d9 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 11 May 2022 17:27:36 +0530 Subject: [PATCH 02/10] :maple_leaf: removed unsed imports --- .../com/contentstack/sdk/CSBackgroundTask.java | 2 -- .../contentstack/sdk/CSConnectionRequest.java | 3 +-- .../com/contentstack/sdk/CSHttpConnection.java | 9 --------- .../java/com/contentstack/sdk/ContentType.java | 1 - src/main/java/com/contentstack/sdk/Group.java | 1 - src/main/java/com/contentstack/sdk/Query.java | 17 ++++++++--------- 6 files changed, 9 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/contentstack/sdk/CSBackgroundTask.java b/src/main/java/com/contentstack/sdk/CSBackgroundTask.java index 6a5b358c..b8ec7165 100644 --- a/src/main/java/com/contentstack/sdk/CSBackgroundTask.java +++ b/src/main/java/com/contentstack/sdk/CSBackgroundTask.java @@ -1,8 +1,6 @@ package com.contentstack.sdk; import org.jetbrains.annotations.NotNull; -import retrofit2.Retrofit; - import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; diff --git a/src/main/java/com/contentstack/sdk/CSConnectionRequest.java b/src/main/java/com/contentstack/sdk/CSConnectionRequest.java index 5f932bf2..4e96b47e 100644 --- a/src/main/java/com/contentstack/sdk/CSConnectionRequest.java +++ b/src/main/java/com/contentstack/sdk/CSConnectionRequest.java @@ -1,7 +1,6 @@ package com.contentstack.sdk; import org.json.JSONObject; -import retrofit2.Retrofit; import java.util.HashMap; import java.util.LinkedHashMap; @@ -84,7 +83,7 @@ public void sendRequest() { connection.setController(controller); connection.setHeaders(header); connection.setInfo(requestInfo); - connection.setEndpoint(this.endpoint); + //connection.setEndpoint(this.endpoint); connection.setAPIService(this.service); connection.setCallBackObject(resultCallBack); if (urlQueries != null && urlQueries.size() > 0) { diff --git a/src/main/java/com/contentstack/sdk/CSHttpConnection.java b/src/main/java/com/contentstack/sdk/CSHttpConnection.java index 297043be..74a072d3 100644 --- a/src/main/java/com/contentstack/sdk/CSHttpConnection.java +++ b/src/main/java/com/contentstack/sdk/CSHttpConnection.java @@ -1,12 +1,10 @@ package com.contentstack.sdk; import okhttp3.ResponseBody; -import org.jetbrains.annotations.NotNull; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import retrofit2.Response; -import retrofit2.Retrofit; import java.io.IOException; import java.io.UnsupportedEncodingException; @@ -29,7 +27,6 @@ public class CSHttpConnection implements IURLRequestHTTP { private LinkedHashMap headers; private String info; private APIService service; - private String endpoint; private ResultCallBack callBackObject; private JSONObject responseJSON; private HashMap formParams; @@ -183,8 +180,6 @@ public void send() { } private void getService(String requestUrl) throws IOException { -// Retrofit retrofit = new Retrofit.Builder().baseUrl(this.endpoint).build(); -// APIService service = retrofit.create(APIService.class); this.headers.put(X_USER_AGENT, CLIENT_USER_AGENT); this.headers.put(CONTENT_TYPE, APPLICATION_JSON); Response response = this.service.getRequest(requestUrl, this.headers).execute(); @@ -210,10 +205,6 @@ void setError(String errResp) { connectionRequest.onRequestFailed(responseJSON, errCode, callBackObject); } - protected void setEndpoint(@NotNull String endpoint) { - this.endpoint = endpoint; - } - public void setAPIService(APIService service) { this.service = service; } diff --git a/src/main/java/com/contentstack/sdk/ContentType.java b/src/main/java/com/contentstack/sdk/ContentType.java index 86556c71..ab320028 100644 --- a/src/main/java/com/contentstack/sdk/ContentType.java +++ b/src/main/java/com/contentstack/sdk/ContentType.java @@ -2,7 +2,6 @@ import org.jetbrains.annotations.NotNull; import org.json.JSONObject; -import retrofit2.Retrofit; import java.util.HashMap; import java.util.Iterator; diff --git a/src/main/java/com/contentstack/sdk/Group.java b/src/main/java/com/contentstack/sdk/Group.java index a2bd7495..e5a07ce7 100644 --- a/src/main/java/com/contentstack/sdk/Group.java +++ b/src/main/java/com/contentstack/sdk/Group.java @@ -2,7 +2,6 @@ import org.json.JSONArray; import org.json.JSONObject; -import retrofit2.Retrofit; import java.util.ArrayList; import java.util.Calendar; diff --git a/src/main/java/com/contentstack/sdk/Query.java b/src/main/java/com/contentstack/sdk/Query.java index 819e1d3a..e1408eb1 100644 --- a/src/main/java/com/contentstack/sdk/Query.java +++ b/src/main/java/com/contentstack/sdk/Query.java @@ -3,7 +3,6 @@ import org.jetbrains.annotations.NotNull; import org.json.JSONArray; import org.json.JSONObject; -import retrofit2.Retrofit; import java.util.*; import java.util.logging.Logger; @@ -61,10 +60,10 @@ protected void setContentTypeInstance(ContentType contentTypeInstance) { * Example :
* *

-     *                              Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
-     *                              Query csQuery = stack.contentType("contentTypeUid").query();
- * csQuery.setHeader("custom_key", "custom_value"); - *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment"); + * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.setHeader("custom_key", "custom_value"); + *
*/ public void setHeader(@NotNull String key, @NotNull String value) { if (!key.isEmpty() && !value.isEmpty()) { @@ -83,10 +82,10 @@ public void setHeader(@NotNull String key, @NotNull String value) { * Example :
* *
-     *                            Stack stack = Contentstack..stack( "apiKey", "deliveryToken", "environment");
-     *                            Query csQuery = stack.contentType("contentTypeUid").query();
- * csQuery.removeHeader("custom_key"); - *
+ * Stack stack = Contentstack..stack( "apiKey", "deliveryToken", "environment"); + * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.removeHeader("custom_key"); + *
*/ public void removeHeader(@NotNull String key) { if (!key.isEmpty()) { From 3c5bf7c58ba26df174f6c9a002f4d83180bd1280 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 11 May 2022 17:42:01 +0530 Subject: [PATCH 03/10] :mega: logger improved --- .../contentstack/sdk/CSBackgroundTask.java | 4 +- .../contentstack/sdk/CSHttpConnection.java | 3 +- .../java/com/contentstack/sdk/Constants.java | 3 +- .../com/contentstack/sdk/EntriesModel.java | 3 +- src/main/java/com/contentstack/sdk/Entry.java | 95 ++++++++++--------- src/main/java/com/contentstack/sdk/Group.java | 7 +- src/main/java/com/contentstack/sdk/Query.java | 5 +- .../com/contentstack/sdk/QueryResult.java | 3 +- 8 files changed, 66 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/contentstack/sdk/CSBackgroundTask.java b/src/main/java/com/contentstack/sdk/CSBackgroundTask.java index b8ec7165..7f1aba0e 100644 --- a/src/main/java/com/contentstack/sdk/CSBackgroundTask.java +++ b/src/main/java/com/contentstack/sdk/CSBackgroundTask.java @@ -1,9 +1,11 @@ package com.contentstack.sdk; import org.jetbrains.annotations.NotNull; + import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import java.util.logging.Level; import java.util.logging.Logger; class CSBackgroundTask { @@ -89,7 +91,7 @@ protected void checkHeader(@NotNull Map headers) { try { throw new IllegalAccessException("CSBackgroundTask Header Exception"); } catch (IllegalAccessException e) { - logger.severe(e.getLocalizedMessage()); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); } } } diff --git a/src/main/java/com/contentstack/sdk/CSHttpConnection.java b/src/main/java/com/contentstack/sdk/CSHttpConnection.java index 74a072d3..65216388 100644 --- a/src/main/java/com/contentstack/sdk/CSHttpConnection.java +++ b/src/main/java/com/contentstack/sdk/CSHttpConnection.java @@ -14,6 +14,7 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; +import java.util.logging.Level; import java.util.logging.Logger; import static com.contentstack.sdk.Constants.*; @@ -175,7 +176,7 @@ public void send() { try { getService(url); } catch (IOException | JSONException e) { - logger.severe(e.getLocalizedMessage()); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); } } diff --git a/src/main/java/com/contentstack/sdk/Constants.java b/src/main/java/com/contentstack/sdk/Constants.java index 64347585..7ce2c39e 100644 --- a/src/main/java/com/contentstack/sdk/Constants.java +++ b/src/main/java/com/contentstack/sdk/Constants.java @@ -6,6 +6,7 @@ import java.util.Calendar; import java.util.Date; import java.util.TimeZone; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -89,7 +90,7 @@ public static Calendar parseDate(String date, TimeZone timeZone) { try { return parseDate(date, formatString, timeZone); } catch (ParseException e) { - logger.warning(e.getLocalizedMessage()); + logger.log(Level.WARNING, e.getLocalizedMessage(), e); } } return null; diff --git a/src/main/java/com/contentstack/sdk/EntriesModel.java b/src/main/java/com/contentstack/sdk/EntriesModel.java index 32d39b9e..45cc9cfd 100644 --- a/src/main/java/com/contentstack/sdk/EntriesModel.java +++ b/src/main/java/com/contentstack/sdk/EntriesModel.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.logging.Level; import java.util.logging.Logger; class EntriesModel { @@ -31,7 +32,7 @@ protected EntriesModel(JSONObject responseJSON) { } } catch (Exception e) { Logger logger = Logger.getLogger(EntriesModel.class.getSimpleName()); - logger.severe(e.getLocalizedMessage()); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); } } diff --git a/src/main/java/com/contentstack/sdk/Entry.java b/src/main/java/com/contentstack/sdk/Entry.java index e65b7ca3..4cc367d5 100644 --- a/src/main/java/com/contentstack/sdk/Entry.java +++ b/src/main/java/com/contentstack/sdk/Entry.java @@ -6,6 +6,7 @@ import retrofit2.Retrofit; import java.util.*; +import java.util.logging.Level; import java.util.logging.Logger; import static com.contentstack.sdk.Constants.ENVIRONMENT; @@ -71,10 +72,10 @@ public Entry configure(JSONObject jsonObject) { * Example :
* *
-     *                                      Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
-     *                                      Entry entry = stack.contentType("form_name").entry("entry_uid");
-     *                                      entry.setHeader("custom_header_key", "custom_header_value");
-     *                                      
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment"); + * Entry entry = stack.contentType("form_name").entry("entry_uid"); + * entry.setHeader("custom_header_key", "custom_header_value"); + *
*/ public void setHeader(String key, String value) { @@ -92,10 +93,10 @@ public void setHeader(String key, String value) { * Example :
* *
-     *                                    Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
-     *                                    Entry entry = stack.contentType("form_name").entry("entry_uid");
-     *                                    entry.removeHeader("custom_header_key");
-     *                                    
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment"); + * Entry entry = stack.contentType("form_name").entry("entry_uid"); + * entry.removeHeader("custom_header_key"); + *
*/ public void removeHeader(String key) { @@ -243,8 +244,8 @@ public JSONObject toJSON() { * Example :
* *
-     *                                    Object obj = entry.get("key");
-     *                                    
+ * Object obj = entry.get("key"); + *
* @return Object @resultJson */ public Object get(@NotNull String key) { @@ -260,8 +261,8 @@ public Object get(@NotNull String key) { * Example :
* *
-     *                                    String value = entry.getString("key");
-     *                                    
+ * String value = entry.getString("key"); + *
* @return String @getString */ @@ -282,8 +283,8 @@ public String getString(@NotNull String key) { * Example :
* *
-     *                                    Boolean value = entry.getBoolean("key");
-     *                                    
+ * Boolean value = entry.getBoolean("key"); + *
* @return boolean @getBoolean */ @@ -304,8 +305,8 @@ public Boolean getBoolean(@NotNull String key) { * Example :
* *
-     *                                    JSONArray value = entry.getJSONArray("key");
-     *                                    
+ * JSONArray value = entry.getJSONArray("key"); + *
* @return JSONArray @getJSONArray */ @@ -326,8 +327,8 @@ public JSONArray getJSONArray(@NotNull String key) { * Example :
* *
-     *                                    JSONObject value = entry.getJSONObject("key");
-     *                                    
+ * JSONObject value = entry.getJSONObject("key"); + *
* @return JSONObject @getJSONObject */ public JSONObject getJSONObject(@NotNull String key) { @@ -347,8 +348,8 @@ public JSONObject getJSONObject(@NotNull String key) { * Example :
* *
-     *                                    JSONObject value = entry.getJSONObject("key");
-     *                                    
+ * JSONObject value = entry.getJSONObject("key"); + *
* @return Number @getNumber */ @@ -369,8 +370,8 @@ public Number getNumber(@NotNull String key) { * Example :
* *
-     *                                    int value = entry.getInt("key");
-     *                                    
+ * int value = entry.getInt("key"); + *
* @return int @getInt */ @@ -435,8 +436,8 @@ public double getDouble(@NotNull String key) { * Example :
* *
-     *                                    long value = entry.getLong("key");
-     *                                    
+ * long value = entry.getLong("key"); + *
* @return long @getLong */ @@ -459,8 +460,8 @@ public long getLong(@NotNull String key) { * Example :
* *
-     *                                    short value = entry.getShort("key");
-     *                                    
+ * short value = entry.getShort("key"); + *
* @return short @getShort */ public short getShort(@NotNull String key) { @@ -480,8 +481,8 @@ public short getShort(@NotNull String key) { * Example :
* *
-     *                                    Calendar value = entry.getDate("key");
-     *                                    
+ * Calendar value = entry.getDate("key"); + *
* @return Calendar @getDate */ @@ -490,7 +491,7 @@ public Calendar getDate(@NotNull String key) { String value = getString(key); return Constants.parseDate(value, null); } catch (Exception e) { - logger.severe(e.getLocalizedMessage()); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); } return null; } @@ -512,7 +513,7 @@ public Calendar getCreateAt() { String value = getString("created_at"); return Constants.parseDate(value, null); } catch (Exception e) { - logger.severe(e.getLocalizedMessage()); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); } return null; } @@ -549,7 +550,7 @@ public Calendar getUpdateAt() { String value = getString("updated_at"); return Constants.parseDate(value, null); } catch (Exception e) { - logger.severe(e.getLocalizedMessage()); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); } return null; } @@ -588,7 +589,7 @@ public Calendar getDeleteAt() { String value = getString("deleted_at"); return Constants.parseDate(value, null); } catch (Exception e) { - logger.severe(e.getLocalizedMessage()); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); } return null; } @@ -663,9 +664,9 @@ public List getAssets(String key) { * Example :
* *
-     *                                     Group innerGroup = entry.getGroup("key");
-     *                                     return null
-     *                                    
+ * Group innerGroup = entry.getGroup("key"); + * return null + *
* @return {@link Group} */ public Group getGroup(String key) { @@ -749,7 +750,7 @@ public ArrayList getAllEntries(String refKey, String refContentType) { entryInstance = contentType.stackInstance.contentType(refContentType).entry(); } catch (Exception e) { entryInstance = new Entry(refContentType); - logger.severe(e.getLocalizedMessage()); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); } entryInstance.setUid(model.uid); entryInstance.resultJson = model.jsonObject; @@ -946,16 +947,16 @@ public Entry exceptWithReferenceUid(@NotNull ArrayList fieldUid, @NotNul * Example :
* *
-     *                                         {@code
-     *                                         Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
-     *                                         Entry entry = stack.contentType("form_name").entry("entry_uid");
- * entry.fetch(new EntryResultCallBack() {
- * @Override - * public void onCompletion(ResponseType responseType, Error error) { - * }
- * });
- * } - *
+ * {@code + * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment"); + * Entry entry = stack.contentType("form_name").entry("entry_uid");
+ * entry.fetch(new EntryResultCallBack() {
+ * @Override + * public void onCompletion(ResponseType responseType, Error error) { + * }
+ * });
+ * } + *
*/ public void fetch(EntryResultCallBack callback) { @@ -963,7 +964,7 @@ public void fetch(EntryResultCallBack callback) { try { throw new IllegalAccessException("Entry Uid is required"); } catch (IllegalAccessException e) { - logger.severe(e.getLocalizedMessage()); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); } } String urlString = "content_types/" + contentTypeUid + "/entries/" + uid; diff --git a/src/main/java/com/contentstack/sdk/Group.java b/src/main/java/com/contentstack/sdk/Group.java index e5a07ce7..132c47df 100644 --- a/src/main/java/com/contentstack/sdk/Group.java +++ b/src/main/java/com/contentstack/sdk/Group.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.List; +import java.util.logging.Level; import java.util.logging.Logger; public class Group { @@ -286,7 +287,7 @@ public Calendar getDate(String key) { String value = getString(key); return Constants.parseDate(value, null); } catch (Exception e) { - logger.severe(e.getLocalizedMessage()); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); } return null; } @@ -407,7 +408,7 @@ public ArrayList getAllEntries(String refKey, String refContentType) { entryInstance = stackInstance.contentType(refContentType).entry(); } catch (Exception e) { entryInstance = new Entry(refContentType); - logger.severe(e.getLocalizedMessage()); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); } entryInstance.setUid(model.uid); entryInstance.resultJson = model.jsonObject; @@ -418,7 +419,7 @@ public ArrayList getAllEntries(String refKey, String refContentType) { } } } catch (Exception e) { - logger.severe(e.getLocalizedMessage()); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); return entryContainer; } return entryContainer; diff --git a/src/main/java/com/contentstack/sdk/Query.java b/src/main/java/com/contentstack/sdk/Query.java index e1408eb1..ffda5510 100644 --- a/src/main/java/com/contentstack/sdk/Query.java +++ b/src/main/java/com/contentstack/sdk/Query.java @@ -5,6 +5,7 @@ import org.json.JSONObject; import java.util.*; +import java.util.logging.Level; import java.util.logging.Logger; import static com.contentstack.sdk.Constants.*; @@ -1195,7 +1196,7 @@ private void throwException(String queryName, String messageString, Exception e) errorHashMap.put(queryName, e.getLocalizedMessage()); } errorHashMap.put("detail", messageString); - logger.warning(messageString); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); } protected void setQueryJson() { @@ -1235,7 +1236,7 @@ protected void execQuery(SingleQueryResultCallback callBack, QueryResultsCallBac mainJSON.put(QUERY, urlQueries); fetchFromNetwork(urlString, mainJSON, callback, callBack); } catch (Exception e) { - logger.severe(e.getLocalizedMessage()); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); throwException("find", Constants.QUERY_EXCEPTION, e); } diff --git a/src/main/java/com/contentstack/sdk/QueryResult.java b/src/main/java/com/contentstack/sdk/QueryResult.java index c9c88b33..a4b006fa 100644 --- a/src/main/java/com/contentstack/sdk/QueryResult.java +++ b/src/main/java/com/contentstack/sdk/QueryResult.java @@ -4,6 +4,7 @@ import org.json.JSONObject; import java.util.List; +import java.util.logging.Level; import java.util.logging.Logger; public class QueryResult { @@ -108,7 +109,7 @@ protected void setJSON(JSONObject jsonobject, List objectList) { } } catch (Exception e) { - logger.severe(e.getLocalizedMessage()); + logger.log(Level.SEVERE, e.getLocalizedMessage(), e); } } From 07bd915bc48c223e75b35689d1dacc7a280d7d33 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 12 May 2022 11:50:48 +0530 Subject: [PATCH 04/10] :sparkles: v1.10.0 release --- CHANGELOG.md | 130 ++++++++++-------- LICENSE | 2 +- pom.xml | 6 +- .../contentstack/sdk/CSConnectionRequest.java | 1 - .../java/com/contentstack/sdk/Config.java | 5 +- .../java/com/contentstack/sdk/Constants.java | 21 +-- 6 files changed, 95 insertions(+), 70 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e530dfc1..fe4f1954 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,25 @@ # CHANGELOG +## Version 1.10.0 + +### Date: 16-May-2022 + +- High increase in memory consumption & thread count when updated to the 1.9.0 version +- Setting Proxy in config [#52](https://github.com/contentstack/contentstack-java/issues/52) +- Adding query parameter for the Live Preview +- Enhancement in logger for the different class ( Suggested through a pull request ) [#51](https://github.com/contentstack/contentstack-java/pull/51) + +--- + +## Version 1.9.0 + +### Date: 16-Mar-2022 + +- Entry uid bug fixed #45 +- Static logger implemented #43 +- Scope based dependencies + +--- ## Version 1.8.1 @@ -9,7 +29,7 @@ - Static logger implemented #43 - Scope based dependencies ------------------------------------------------- +--- ## Version 1.8.0 @@ -22,7 +42,7 @@ - Removed deprecated code/Non-working code marked deprecated - Few breaking changes added. ------------------------------------------------- +--- ## Version 1.7.0 @@ -32,16 +52,16 @@ - Bug #32 issue resolved removed e.printStackTrace() - Instead stacktrace used logger.error() ------------------------------------------------- +--- ## Version 1.6.0 ### Date: 05-APR-2021 - **Query** : query.includeEmbeddedItems() method support added -- **Entry** : entry.includeEmbeddedItems() method support added +- **Entry** : entry.includeEmbeddedItems() method support added ------------------------------------------------- +--- ## Version 1.5.7 @@ -49,7 +69,7 @@ Document updated ------------------------------------------------- +--- ## Version 1.5.6 @@ -60,7 +80,7 @@ Document updated New Features: • None ------------------------------------------------- +--- ## Version 1.5.5 @@ -81,7 +101,7 @@ Language Enum: New Features: • None ------------------------------------------------- +--- ## Version 1.5.4 @@ -94,15 +114,15 @@ New Features: • [Asset] - Publish fallback method added, includeDimension method added • [Assets] - Publish fallback method added ------------------------------------------------- +--- ## Version 1.5.3 ### Date: 28-July-2020 -- **Build Issue** Build update issue fixed +- **Build Issue** Build update issue fixed ------------------------------------------------- +--- ## Version 1.5.2 @@ -112,15 +132,15 @@ New Features: - **Query** : Query.locale() documentation - **CSHttpConnection** : StandardCharsets.UTF_8 Support Added ------------------------------------------------- +--- ## Version 1.5.1 ### Date: 13-Jan-2020 -- **Dependency Vulnerability** Java Github reported vulnerable issue on dependency logj +- **Dependency Vulnerability** Java Github reported vulnerable issue on dependency logj ------------------------------------------------- +--- ## Version 1.5.0 @@ -131,7 +151,7 @@ New Features: - **Query**: Updated support of whereIn(String KEY, Query queryObject) - **Query**: Updated support of whereNotIn(String KEY, Query queryObject) ------------------------------------------------- +--- ## Version 1.4.2 @@ -139,7 +159,7 @@ New Features: - **Config** - Added support for Region in Config. ------------------------------------------------- +--- ## Version 1.4.1 @@ -148,7 +168,7 @@ New Features: - **Query** - Added support for whereIn(String key) and whereNotIn(String key) methods - **CSAppConstants** - Removed google internet connection check from CSAppConstants ------------------------------------------------- +--- ## Version 1.4.0 @@ -162,7 +182,7 @@ New Features: - **Query** - Added method for locale in Query. - **Query** - Removed deprecated method for includeSchema in Query ------------------------------------------------- +--- ## Version 1.3.3 @@ -170,7 +190,7 @@ New Features: - **HOTFIX**: Override response hot-fix ------------------------------------------------- +--- ## Version 1.3.2 @@ -179,7 +199,7 @@ New Features: - **Code Improvement** Removed println - **Code Improvement** Added support for Logger ------------------------------------------------- +--- ## Version 1.3.1 @@ -188,69 +208,69 @@ New Features: - **Change**: include reference bug fixed - **Added testcase** report for v1.3.1 ------------------------------------------------- +--- + +## Version 1.3.0 -## Version 1.3.0 +### Date: Apr-12-2019 -### Date: Apr-12-2019 +Change: Added support of below methods in SDK + + ``` + getContentTypes() in Stack class + fetch in ContentType class + ``` - Change: Added support of below methods in SDK - - ``` - getContentTypes() in Stack class - fetch in ContentType class - ``` - Below two support from the Config class has been removed permanently -- public void setSSL(boolean isSSL)setSSL() -- public boolean isSSL() - ------------------------------------------------- +- public void setSSL(boolean isSSL)setSSL() +- public boolean isSSL() + +--- ## Version 1.2.1 ### Date: 14-Mar-2019 - Note: Bug Fixes and code clean up: - + Date: 20-Feb-2019 Maven integration -Folder structure modified. - ------------------------------------------------- +Folder structure modified. + +--- ## Version 1.2.0 -### Date: 15-Dec-2017 +### Date: 15-Dec-2017 - New Features: ``` - Entry- added method ‘addParam’ - Query- added method 'addParam' + Entry- added method ‘addParam’ + Query- added method 'addParam' Asset- added method 'addParam' - ``` + ``` + +--- ------------------------------------------------- - ## Version 1.1.0 -### Date: 10-Nov-2017 +### Date: 10-Nov-2017 - New Features: - ``` - Stack- added method 'ImageTransform' - Query- added method 'includeContentType' - QueryResult- added method 'contentType' ``` + Stack- added method 'ImageTransform' + Query- added method 'includeContentType' + QueryResult- added method 'contentType' + ``` + +--- ------------------------------------------------- - -### API deprecation +### API deprecation -- Query -- Deprecated method 'includeSchema' +- Query +- Deprecated method 'includeSchema' ------------------------------------------------- +--- diff --git a/LICENSE b/LICENSE index f6c01cdb..0e7d6f3b 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2012 - 2021 Contentstack +Copyright (c) 2012 - 2022 Contentstack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/pom.xml b/pom.xml index c1a62eb3..94d909e7 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.contentstack.sdk java - 1.9.0 + 1.10.0 jar contentstack-java Java SDK for Contentstack Content Delivery API @@ -13,8 +13,8 @@ - 1.9.0-SNAPSHOT - 1.9.0 + 1.10.0-SNAPSHOT + 1.10.0 1.8 1.8 UTF-8 diff --git a/src/main/java/com/contentstack/sdk/CSConnectionRequest.java b/src/main/java/com/contentstack/sdk/CSConnectionRequest.java index 4e96b47e..3bbd3f7f 100644 --- a/src/main/java/com/contentstack/sdk/CSConnectionRequest.java +++ b/src/main/java/com/contentstack/sdk/CSConnectionRequest.java @@ -83,7 +83,6 @@ public void sendRequest() { connection.setController(controller); connection.setHeaders(header); connection.setInfo(requestInfo); - //connection.setEndpoint(this.endpoint); connection.setAPIService(this.service); connection.setCallBackObject(resultCallBack); if (urlQueries != null && urlQueries.size() > 0) { diff --git a/src/main/java/com/contentstack/sdk/Config.java b/src/main/java/com/contentstack/sdk/Config.java index 8f843f8f..eeb99854 100644 --- a/src/main/java/com/contentstack/sdk/Config.java +++ b/src/main/java/com/contentstack/sdk/Config.java @@ -43,8 +43,9 @@ public void setBranch(String branch) { *

Example:

* * java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyHost", "proxyPort")); - * java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("sl.theproxyvpn.io", 80)); Config - * config = new Config() config.setProxy(proxy) + * java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("sl.theproxyvpn.io", 80)); + * Config config = new Config(); + * config.setProxy(proxy); * */ public void setProxy(Proxy proxy) { diff --git a/src/main/java/com/contentstack/sdk/Constants.java b/src/main/java/com/contentstack/sdk/Constants.java index 7ce2c39e..984aeba9 100644 --- a/src/main/java/com/contentstack/sdk/Constants.java +++ b/src/main/java/com/contentstack/sdk/Constants.java @@ -15,7 +15,7 @@ public class Constants { private static final Logger logger = Logger.getLogger(Constants.class.getSimpleName()); - protected static final String SDK_VERSION = "1.9.0"; + protected static final String SDK_VERSION = "1.10.0"; protected static final String ENVIRONMENT = "environment"; protected static final String CONTENT_TYPE_UID = "content_type_uid"; protected static final String SYNCHRONISATION = "stacks/sync"; @@ -37,7 +37,6 @@ public class Constants { protected static final String OPTIONS = "$options"; - protected Constants() { logger.warning("Not Allowed"); } @@ -68,8 +67,10 @@ public enum REQUEST_CONTROLLER { /** * Parse date calendar. * - * @param date the date - * @param timeZone the time zone + * @param date + * the date + * @param timeZone + * the time zone * @return the calendar */ public static Calendar parseDate(String date, TimeZone timeZone) { @@ -99,11 +100,15 @@ public static Calendar parseDate(String date, TimeZone timeZone) { /** * Parse date calendar. * - * @param date the date - * @param dateFormat the date format - * @param timeZone the time zone + * @param date + * the date + * @param dateFormat + * the date format + * @param timeZone + * the time zone * @return the calendar - * @throws ParseException the parse exception + * @throws ParseException + * the parse exception */ public static Calendar parseDate(String date, String dateFormat, TimeZone timeZone) throws ParseException { Calendar cal = Calendar.getInstance(); From 17419922ab88336088842c946d3fcddd2bb98ea0 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 12 May 2022 11:59:35 +0530 Subject: [PATCH 05/10] :lock: security file added --- SECURITY.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 00000000..88da02e6 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,27 @@ +# Security + +Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations. + +If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below. + +## Reporting Security Issues + +**Please do not report security vulnerabilities through public GitHub issues.** + +Send email to [security@contentstack.com](mailto:security@contentstack.com). + +You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. + +Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: + +- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) +- Full paths of source file(s) related to the manifestation of the issue +- The location of the affected source code (tag/branch/commit or direct URL) +- Any special configuration required to reproduce the issue +- Step-by-step instructions to reproduce the issue +- Proof-of-concept or exploit code (if possible) +- Impact of the issue, including how an attacker might exploit the issue + +This information will help us triage your report more quickly. + +[https://www.contentstack.com/trust/](https://www.contentstack.com/trust/) From ac83f52b4bf3b9390cefdd153e02b308e6121f0c Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 12 May 2022 12:05:09 +0530 Subject: [PATCH 06/10] :feather: maven snapshot --- pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 94d909e7..1394ac14 100644 --- a/pom.xml +++ b/pom.xml @@ -1,11 +1,10 @@ - + 4.0.0 com.contentstack.sdk java - 1.10.0 + 1.10.0-SNAPSHOT jar contentstack-java Java SDK for Contentstack Content Delivery API From e4cee127bf5865e3bbf51df779b530c6cd1d0722 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 12 May 2022 12:10:00 +0530 Subject: [PATCH 07/10] :feather: removed commented properties --- pom.xml | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/pom.xml b/pom.xml index 1394ac14..c073cc89 100644 --- a/pom.xml +++ b/pom.xml @@ -192,20 +192,6 @@ # time-consuming stuff mvn surefire-report:report site -DgenerateReports=false --> - - - - - - - - - - - - - - org.apache.maven.plugins maven-source-plugin @@ -322,25 +308,6 @@ deploy - - - - - - - - - - - - - - - - - - - org.jacoco jacoco-maven-plugin @@ -372,9 +339,6 @@ - - - src/main/java/com/contentstack/sdk/Group.class src/main/java/com/contentstack/sdk/FetchAssetsCallback.class From 744329579a534fa4d215865cacacc9632082c3a7 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 18 May 2022 10:53:28 +0530 Subject: [PATCH 08/10] pom.xml updated :lock: --- pom.xml | 10 +++++----- src/test/java/com/contentstack/sdk/TestConfig.java | 1 - 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index c073cc89..ecc3ca45 100644 --- a/pom.xml +++ b/pom.xml @@ -20,13 +20,13 @@ 2.22.0 2.2.1 3.3.2 - 5.2.2 - 3.1.3 + 2.2.3 + 3.1.4 2.9.0 2.9.0 4.9.3 0.8.5 - 1.18.22 + 1.18.24 5.8.2 5.8.0-M1 5.8.2 @@ -37,7 +37,7 @@ 3.8.1 1.6.7 2.5.3 - 20211205 + 20220320 0.8.7 2.5.3 1.6.7 @@ -117,7 +117,7 @@ io.github.cdimascio - java-dotenv + dotenv-java ${dotenv-source.version} runtime diff --git a/src/test/java/com/contentstack/sdk/TestConfig.java b/src/test/java/com/contentstack/sdk/TestConfig.java index c3768770..62e66907 100644 --- a/src/test/java/com/contentstack/sdk/TestConfig.java +++ b/src/test/java/com/contentstack/sdk/TestConfig.java @@ -7,7 +7,6 @@ import java.net.InetSocketAddress; import java.net.Proxy; -import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; From 63379edbbbf660c9207fc9b7b8188c6da4a327eb Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Fri, 20 May 2022 17:07:22 +0530 Subject: [PATCH 09/10] pom.xml updated :lock: --- pom.xml | 6 ------ src/main/java/com/contentstack/sdk/Stack.java | 2 -- 2 files changed, 8 deletions(-) diff --git a/pom.xml b/pom.xml index ecc3ca45..139a6156 100644 --- a/pom.xml +++ b/pom.xml @@ -145,12 +145,6 @@ ${loggin.version} compile - - com.squareup.retrofit2 - converter-jackson - 2.9.0 - compile - org.projectlombok diff --git a/src/main/java/com/contentstack/sdk/Stack.java b/src/main/java/com/contentstack/sdk/Stack.java index 0ab98d41..3c32b446 100644 --- a/src/main/java/com/contentstack/sdk/Stack.java +++ b/src/main/java/com/contentstack/sdk/Stack.java @@ -5,7 +5,6 @@ import org.jetbrains.annotations.NotNull; import org.json.JSONObject; import retrofit2.Retrofit; -import retrofit2.converter.jackson.JacksonConverterFactory; import java.net.Proxy; import java.text.DateFormat; @@ -76,7 +75,6 @@ private void client(String endpoint) { Retrofit retrofit = new Retrofit.Builder().baseUrl(endpoint) .client(client) - .addConverterFactory(JacksonConverterFactory.create()) .build(); this.service = retrofit.create(APIService.class); From 0952831b74ea71fb338fc9a054aecb65c20e2217 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 1 Jun 2022 12:51:51 +0530 Subject: [PATCH 10/10] :lady_beetle: pom and version --- pom.xml | 2 +- .../contentstack/sdk/CSHttpConnection.java | 3 +- .../java/com/contentstack/sdk/Constants.java | 16 ++++------ .../contentstack/sdk/TestAssetLibrary.java | 1 - .../com/contentstack/sdk/TestContentType.java | 4 +-- .../java/com/contentstack/sdk/TestEntry.java | 2 +- .../java/com/contentstack/sdk/TestQuery.java | 31 ++++++------------- 7 files changed, 21 insertions(+), 38 deletions(-) diff --git a/pom.xml b/pom.xml index 139a6156..9cf6d252 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ 0.8.7 2.5.3 1.6.7 - 1.1.0 + 1.1.1
diff --git a/src/main/java/com/contentstack/sdk/CSHttpConnection.java b/src/main/java/com/contentstack/sdk/CSHttpConnection.java index 65216388..0636fe16 100644 --- a/src/main/java/com/contentstack/sdk/CSHttpConnection.java +++ b/src/main/java/com/contentstack/sdk/CSHttpConnection.java @@ -181,7 +181,8 @@ public void send() { } private void getService(String requestUrl) throws IOException { - this.headers.put(X_USER_AGENT, CLIENT_USER_AGENT); + this.headers.put(X_USER_AGENT_KEY, "contentstack-java/" + SDK_VERSION); + this.headers.put(USER_AGENT_KEY, USER_AGENT); this.headers.put(CONTENT_TYPE, APPLICATION_JSON); Response response = this.service.getRequest(requestUrl, this.headers).execute(); if (response.isSuccessful()) { diff --git a/src/main/java/com/contentstack/sdk/Constants.java b/src/main/java/com/contentstack/sdk/Constants.java index 984aeba9..fa64ae5f 100644 --- a/src/main/java/com/contentstack/sdk/Constants.java +++ b/src/main/java/com/contentstack/sdk/Constants.java @@ -2,10 +2,7 @@ import java.text.ParseException; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.TimeZone; +import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -24,11 +21,12 @@ public class Constants { protected static final String ERROR_MESSAGE = "error_message"; protected static final String ERRORS = "errors"; // User-Agents - protected static final String X_USER_AGENT = "X-User-Agent"; + protected static final String X_USER_AGENT_KEY = "X-User-Agent"; + protected static final String USER_AGENT_KEY = "User-Agent"; + protected static final String USER_AGENT = userAgent(); protected static final String CONTENT_TYPE = "Content-Type"; protected static final String APPLICATION_JSON = "application/json"; - protected static final String CLIENT_USER_AGENT = userAgent(); - // Query + protected static final String QUERY = "query"; protected static final String EXCEPT = "except"; protected static final String EXISTS = "$exists"; @@ -58,10 +56,7 @@ public enum REQUEST_CONTROLLER { public static final String FETCHSYNC = "getSync"; public static final String FETCHCONTENTTYPES = "getContentTypes"; - // ERROR MESSAGE BLOCK - public static final String JSON_NOT_PROPER = "Please provide valid JSON."; public static final String CONTENT_TYPE_NAME = "Please set contentType name."; - public static final String HEADER_IS_MISSING_TO_PROCESS_THE_DATA = "Header is missing to process the data"; public static final String QUERY_EXCEPTION = "Please provide valid params."; /** @@ -137,4 +132,5 @@ protected static String userAgent() { agentStr = agentStr + "/" + SDK_VERSION; return agentStr; } + } diff --git a/src/test/java/com/contentstack/sdk/TestAssetLibrary.java b/src/test/java/com/contentstack/sdk/TestAssetLibrary.java index de23631f..8de98f16 100644 --- a/src/test/java/com/contentstack/sdk/TestAssetLibrary.java +++ b/src/test/java/com/contentstack/sdk/TestAssetLibrary.java @@ -42,7 +42,6 @@ public void onCompletion(ResponseType responseType, List assets, Error er Assertions.assertTrue(model.getCreatedBy().startsWith("blt")); assertEquals("gregory", model.getUpdateAt().getCalendarType()); Assertions.assertTrue(model.getUpdatedBy().startsWith("sys")); - Assertions.assertNull(model.getDeleteAt()); assertEquals("", model.getDeletedBy()); logger.info("passed..."); } diff --git a/src/test/java/com/contentstack/sdk/TestContentType.java b/src/test/java/com/contentstack/sdk/TestContentType.java index b1e8c8ff..b80e95a5 100644 --- a/src/test/java/com/contentstack/sdk/TestContentType.java +++ b/src/test/java/com/contentstack/sdk/TestContentType.java @@ -69,7 +69,7 @@ void testEntryInstance() { Entry entry = contentType.entry("just-fake-it"); Assertions.assertEquals("product", entry.getContentType()); Assertions.assertEquals("just-fake-it", entry.uid); - Assertions.assertEquals(5, entry.headers.size()); + Assertions.assertEquals(6, entry.headers.size()); logger.info("passed..."); } @@ -78,7 +78,7 @@ void testQueryInstance() { ContentType contentType = stack.contentType("product"); Query query = contentType.query(); Assertions.assertEquals("product", query.getContentType()); - Assertions.assertEquals(5, query.headers.size()); + Assertions.assertEquals(6, query.headers.size()); logger.info("passed..."); } diff --git a/src/test/java/com/contentstack/sdk/TestEntry.java b/src/test/java/com/contentstack/sdk/TestEntry.java index 5d9148f7..c95662d6 100644 --- a/src/test/java/com/contentstack/sdk/TestEntry.java +++ b/src/test/java/com/contentstack/sdk/TestEntry.java @@ -84,7 +84,7 @@ public void onCompletion(ResponseType responseType, Error error) { @Test @Order(4) void entryCalling() { - Assertions.assertEquals(5, entry.headers.size()); + Assertions.assertEquals(6, entry.headers.size()); logger.info("passed..."); } diff --git a/src/test/java/com/contentstack/sdk/TestQuery.java b/src/test/java/com/contentstack/sdk/TestQuery.java index b259e82c..03de7fa5 100644 --- a/src/test/java/com/contentstack/sdk/TestQuery.java +++ b/src/test/java/com/contentstack/sdk/TestQuery.java @@ -133,7 +133,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err @Test @Order(5) void testNotContainedInField() { - String[] containArray = new String[] { "Roti Maker", "kids dress" }; + String[] containArray = new String[]{"Roti Maker", "kids dress"}; query.notContainedIn("title", containArray); query.find(new QueryResultsCallBack() { @Override @@ -151,7 +151,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err @Test @Order(6) void testContainedInField() { - String[] containArray = new String[] { "Roti Maker", "kids dress" }; + String[] containArray = new String[]{"Roti Maker", "kids dress"}; query.containedIn("title", containArray); query.find(new QueryResultsCallBack() { @Override @@ -262,7 +262,7 @@ void testEntriesWithOr() { query.lessThan("price", 90); Query subQuery = ct.query(); - subQuery.containedIn("discount", new Integer[] { 20, 45 }); + subQuery.containedIn("discount", new Integer[]{20, 45}); ArrayList array = new ArrayList<>(); array.add(query); @@ -294,7 +294,7 @@ void testEntriesWithAnd() { query.lessThan("price", 90); Query subQuery = ct.query(); - subQuery.containedIn("discount", new Integer[] { 20, 45 }); + subQuery.containedIn("discount", new Integer[]{20, 45}); ArrayList array = new ArrayList<>(); array.add(query); @@ -404,7 +404,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err String previous = entries.get(i).getTitle(); // get first string String next = entries.get(i + 1).getTitle(); // get second string if (previous.compareTo(next) < 0) { // compare both if less than Zero then Ascending else - // descending + // descending Assertions.assertTrue(true); } else { Assertions.fail("expected descending, found ascending"); @@ -430,7 +430,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err String previous = entries.get(i).getTitle(); // get first string String next = entries.get(i + 1).getTitle(); // get second string if (previous.compareTo(next) < 0) { // compare both if less than Zero then Ascending else - // descending + // descending Assertions.fail("expected descending, found ascending"); } else { Assertions.assertTrue(true); @@ -480,7 +480,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err @Test @Order(22) void testOnly() { - query.only(new String[] { "price" }); + query.only(new String[]{"price"}); query.find(new QueryResultsCallBack() { @Override public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) { @@ -497,7 +497,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err @Test @Order(23) void testExcept() { - query.except(new String[] { "price" }); + query.except(new String[]{"price"}); query.find(new QueryResultsCallBack() { @Override public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) { @@ -583,7 +583,7 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err @Test @Order(28) void testTags() { - query.tags(new String[] { "pink" }); + query.tags(new String[]{"pink"}); query.find(new QueryResultsCallBack() { @Override public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) { @@ -877,17 +877,4 @@ public void onCompletion(ResponseType responseType, QueryResult queryresult, Err logger.info("passed..."); } - // @Test @Order(53) - // void testIncludeBranchAPI() throws IllegalAccessException { - // Dotenv dotenv = Dotenv.load(); - // String apiKey = dotenv.get("apiKey"); - // String deliveryToken = dotenv.get("deliveryToken"); - // String env = dotenv.get("env"); - // Config config = new Config(); - // config.setHost("development"); - // Stack stack = Contentstack.stack(apiKey, deliveryToken, env, config); - // query = stack.contentType("menu").query(); - // query.includeBranch().find(null); - // } - } \ No newline at end of file