headers);
- public void setController(String controller);
+ JSONObject getResponse();
- public String getController();
+ String getInfo();
- public void setCallBackObject(ResultCallBack builtResultCallBackObject);
+ void setInfo(String info);
- public ResultCallBack getCallBackObject();
+ String getController();
- public void setTreatDuplicateKeysAsArrayItems(boolean treatDuplicateKeysAsArrayItems);
+ void setController(String controller);
- public boolean getTreatDuplicateKeysAsArrayItems();
+ ResultCallBack getCallBackObject();
+ void setCallBackObject(ResultCallBack builtResultCallBackObject);
}
diff --git a/src/main/java/com/contentstack/sdk/Language.java b/src/main/java/com/contentstack/sdk/Language.java
deleted file mode 100644
index 4efee11b..00000000
--- a/src/main/java/com/contentstack/sdk/Language.java
+++ /dev/null
@@ -1,286 +0,0 @@
-package com.contentstack.sdk;
-
-
-/**
- * Language
- * @deprecated
- * This Enum is no longer acceptable to apply language.
- * Use {@link Entry entry.setLocale("en-us")} instead.
- */
-@Deprecated
-public enum Language {
-
- AFRIKAANS_SOUTH_AFRICA,
-
- ALBANIAN_ALBANIA,
-
- ARABIC_ALGERIA,
-
- ARABIC_BAHRAIN,
-
- ARABIC_EGYPT,
-
- ARABIC_IRAQ,
-
- ARABIC_JORDAN,
-
- ARABIC_KUWAIT,
-
- ARABIC_LEBANON,
-
- ARABIC_LIBYA,
-
- ARABIC_MOROCCO,
-
- ARABIC_OMAN,
-
- ARABIC_QATAR,
-
- ARABIC_SAUDI_ARABIA,
-
- ARABIC_SYRIA,
-
- ARABIC_TUNISIA,
-
- ARABIC_UNITED_ARAB_EMIRATES,
-
- ARABIC_YEMEN,
-
- ARMENIAN_ARMENIA,
-
- AZERI_CYRILLIC_ARMENIA,
-
- AZERI_LATIN_AZERBAIJAN,
-
- BASQUE_BASQUE,
-
- BELARUSIAN_BELARUS,
-
- BULGARIAN_BULGARIA,
-
- CATALAN_CATALAN,
-
- CHINESE_CHINA,
-
- CHINESE_HONG_KONG_SAR,
-
- CHINESE_MACUS_SAR,
-
- CHINESE_SINGAPORE,
-
- CHINESE_TAIWAN,
-
- CHINESE_SIMPLIFIED,
-
- CHINESE_TRADITIONAL,
-
- CROATIAN_CROATIA,
-
- CZECH_CZECH_REPUBLIC,
-
- DANISH_DENMARK,
-
- DHIVEHI_MALDIVES,
-
- DUTCH_BELGIUM,
-
- DUTCH_NETHERLANDS,
-
- ENGLISH_AUSTRALIA,
-
- ENGLISH_BELIZE,
-
- ENGLISH_CANADA,
-
- ENGLISH_CARIBBEAN,
-
- ENGLISH_IRELAND,
-
- ENGLISH_JAMAICA,
-
- ENGLISH_NEW_ZEALAND,
-
- ENGLISH_PHILIPPINES,
-
- ENGLISH_SOUTH_AFRICA,
-
- ENGLISH_TRINIDAD_AND_TOBAGO,
-
- ENGLISH_UNITED_KINGDOM,
-
- ENGLISH_UNITED_STATES,
-
- ENGLISH_ZIMBABWE,
-
- ESTONIAN_ESTONIA,
-
- FAROESE_FAROE_ISLANDS,
-
- FARSI_IRAN,
-
- FINNISH_FINLAND,
-
- FRENCH_BELGIUM,
-
- FRENCH_CANADA,
-
- FRENCH_FRANCE,
-
- FRENCH_LUXEMBOURG,
-
- FRENCH_MONACO,
-
- FRENCH_SWITZERLAND,
-
- GALICIAN_GALICIAN,
-
- GEORGIAN_GEORGIA,
-
- GERMAN_AUSTRIA,
-
- GERMAN_GERMANY,
-
- GERMAN_LIENCHTENSTEIN,
-
- GERMAN_LUXEMBOURG,
-
- GERMAN_SWITZERLAND,
-
- GREEK_GREECE,
-
- GUJARATI_INDIA,
-
- HEBREW_ISRAEL,
-
- HINDI_INDIA,
-
- HUNGARIAN_HUNGARY,
-
- ICELANDIC_ICELAND,
-
- INDONESIAN_INDONESIA,
-
- ITALIAN_ITALY,
-
- ITALIAN_SWITZERLAND,
-
- JAPANESE_JAPAN,
-
- KANNADA_INDIA,
-
- KAZAKH_KAZAKHSTAN,
-
- KONKANI_INDIA,
-
- KOREAN_KOREA,
-
- KYRGYZ_KAZAKHSTAN,
-
- LATVIAN_LATVIA,
-
- LITHUANIAN_LITHUANIA,
-
- MACEDONIAN_FYROM,
-
- MALAY_BRUNEI,
-
- MALAY_MALAYSIA,
-
- MARATHI_INDIA,
-
- MONGOLIAN_MONGOLIA,
-
- NORWEGIAN_BOKMAL_NORWAY,
-
- NORWEGIAN_NYNORSK_NORWAY,
-
- POLISH_POLAND,
-
- PORTUGUESE_BRAZIL,
-
- PORTUGUESE_PORTUGAL,
-
- PUNJABI_INDIA,
-
- ROMANIAN_ROMANIA,
-
- RUSSIAN_RUSSIA,
-
- SANSKRIT_INDIA,
-
- SERBIAN_CYRILLIC_SERBIA,
-
- SERBIAN_LATIN_SERBIA,
-
- SLOVAK_SLOVAKIA,
-
- SLOVENIAN_SLOVENIAN,
-
- SPANISH_ARGENTINA,
-
- SPANISH_BOLIVIA,
-
- SPANISH_CHILE,
-
- SPANISH_COLOMBIA,
-
- SPANISH_COSTA_RICA,
-
- SPANISH_DOMINICAN_REPUBLIC,
-
- SPANISH_ECUADOR,
-
- SPANISH_ELSALVADOR,
-
- SPANISH_GUATEMALA,
-
- SPANISH_HONDURAS,
-
- SPANISH_MEXICO,
-
- SPANISH_NICARAGUA,
-
- SPANISH_PANAMA,
-
- SPANISH_PARAGUAY,
-
- SPANISH_PERU,
-
- SPANISH_PUERTO_RICO,
-
- SPANISH_SPAIN,
-
- SPANISH_URUGUAY,
-
- SPANISH_VENEZUELA,
-
- SWAHILI_KENYA,
-
- SWEDISH_FINLAND,
-
- SWEDISH_SWEDEN,
-
- SYRIAC_SYRIA,
-
- TAMIL_INDIA,
-
- TATAR_RUSSIA,
-
- TELUGU_INDIA,
-
- THAI_THAILAND,
-
- TURKISH_TURKEY,
-
- UKRAINIAN_UKRAINE,
-
- URDU_PAKISTAN,
-
- UZBEK_CYRILLIC_UZBEKISTAN,
-
- UZBEK_LATIN_UZEBEKISTAN,
-
- VIETNAMESE_VIETNAM;
-
-}
-
diff --git a/src/main/java/com/contentstack/sdk/LanguageCode.java b/src/main/java/com/contentstack/sdk/LanguageCode.java
deleted file mode 100644
index 426ba2ef..00000000
--- a/src/main/java/com/contentstack/sdk/LanguageCode.java
+++ /dev/null
@@ -1,284 +0,0 @@
-package com.contentstack.sdk;
-
-/**
- * LanguageCode
- * @deprecated
- * This Enum is no longer acceptable to apply {@link LanguageCode}.
- *
Use {@link Entry entry.setLocale("en-us")} instead.
- */
-@Deprecated
-enum LanguageCode {
-
- af_za,
-
- sq_al,
-
- ar_dz,
-
- ar_bh,
-
- ar_eg,
-
- ar_iq,
-
- ar_jo,
-
- ar_kw,
-
- ar_lb,
-
- ar_ly,
-
- ar_ma,
-
- ar_om,
-
- ar_qa,
-
- ar_sa,
-
- ar_sy,
-
- ar_tn,
-
- ar_ae,
-
- ar_ye,
-
- hy_am,
-
- cy_az_az,
-
- lt_az_az,
-
- eu_es,
-
- be_by,
-
- bg_bg,
-
- ca_es,
-
- zh_cn,
-
- zh_hk,
-
- zh_mo,
-
- zh_sg,
-
- zh_tw,
-
- zh_chs,
-
- zh_cht,
-
- hr_hr,
-
- cs_cz,
-
- da_dk,
-
- div_mv,
-
- nl_be,
-
- nl_nl,
-
- en_au,
-
- en_bz,
-
- en_ca,
-
- en_cb,
-
- en_ie,
-
- en_jm,
-
- en_nz,
-
- en_ph,
-
- en_za,
-
- en_tt,
-
- en_gb,
-
- en_us,
-
- en_zw,
-
- et_ee,
-
- fo_fo,
-
- fa_ir,
-
- fi_fi,
-
- fr_be,
-
- fr_ca,
-
- fr_fr,
-
- fr_lu,
-
- fr_mc,
-
- fr_ch,
-
- gl_es,
-
- ka_ge,
-
- de_at,
-
- de_de,
-
- de_li,
-
- de_lu,
-
- de_ch,
-
- el_gr,
-
- gu_in,
-
- he_il,
-
- hi_in,
-
- hu_hu,
-
- is_is,
-
- id_id,
-
- it_it,
-
- it_ch,
-
- ja_jp,
-
- kn_in,
-
- kk_kz,
-
- kok_in,
-
- ko_kr,
-
- ky_kz,
-
- lv_lv,
-
- lt_lt,
-
- mk_mk,
-
- ms_bn,
-
- ms_my,
-
- mr_in,
-
- mn_mn,
-
- nb_no,
-
- nn_no,
-
- pl_pl,
-
- pt_br,
-
- pt_pt,
-
- pa_in,
-
- ro_ro,
-
- ru_ru,
-
- sa_in,
-
- cy_sr_sp,
-
- lt_sr_sp,
-
- sk_sk,
-
- sl_si,
-
- es_ar,
-
- es_bo,
-
- es_cl,
-
- es_co,
-
- es_cr,
-
- es_do,
-
- es_ec,
-
- es_sv,
-
- es_gt,
-
- es_hn,
-
- es_mx,
-
- es_ni,
-
- es_pa,
-
- es_py,
-
- es_pe,
-
- es_pr,
-
- es_es,
-
- es_uy,
-
- es_ve,
-
- sw_ke,
-
- sv_fi,
-
- sv_se,
-
- syr_sy,
-
- ta_in,
-
- tt_ru,
-
- te_in,
-
- th_th,
-
- tr_tr,
-
- uk_ua,
-
- ur_pk,
-
- cy_uz_uz,
-
- lt_uz_uz,
-
- vi_vn;
-
-}
diff --git a/src/main/java/com/contentstack/sdk/Query.java b/src/main/java/com/contentstack/sdk/Query.java
index 5309e8a8..e6345d67 100644
--- a/src/main/java/com/contentstack/sdk/Query.java
+++ b/src/main/java/com/contentstack/sdk/Query.java
@@ -1,46 +1,42 @@
package com.contentstack.sdk;
-import com.contentstack.sdk.utility.CSAppConstants;
-import com.contentstack.sdk.utility.CSController;
+
+import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
-import org.json.JSONException;
import org.json.JSONObject;
+
import java.util.*;
import java.util.logging.Logger;
+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 {
private static final Logger logger = Logger.getLogger(Query.class.getSimpleName());
protected ContentType contentTypeInstance = null;
- protected LinkedHashMap formHeader = null;
- private JSONObject mainJSON = null;
- private String formName = null;
- protected JSONObject urlQueries = null;
- private LinkedHashMap localHeader = null;
- private QueryResultsCallBack queryResultCallback;
- private SingleQueryResultCallback singleQueryResultCallback;
- private JSONObject queryValueJSON = null;
- private JSONObject queryValue = null;
- private JSONArray objectUidForInclude = null;
- private JSONArray objectUidForExcept = null;
- private JSONArray objectUidForOnly = null;
+ protected LinkedHashMap headers = null;
+ protected JSONObject urlQueries;
+ protected JSONObject mainJSON;
+ protected String contentTypeUid;
+ protected QueryResultsCallBack queryResultCallback;
+ protected SingleQueryResultCallback singleQueryResultCallback;
+ protected JSONObject queryValueJSON;
+ protected JSONObject queryValue;
+ protected JSONArray objectUidForInclude = null;
+ protected JSONArray objectUidForExcept = null;
+ protected JSONArray objectUidForOnly = null;
private boolean isJsonProper = true;
private String errorString;
- private HashMap errorHashMap;
private JSONObject onlyJsonObject;
private JSONObject exceptJsonObject;
-
protected Query(String formName) {
- this.formName = formName;
- this.localHeader = new LinkedHashMap<>();
+ this.contentTypeUid = formName;
this.urlQueries = new JSONObject();
this.queryValue = new JSONObject();
this.queryValueJSON = new JSONObject();
@@ -51,81 +47,82 @@ protected void setContentTypeInstance(ContentType contentTypeInstance) {
this.contentTypeInstance = contentTypeInstance;
}
-
/**
- * To set headers for Built.io Contentstack rest calls.
- *
+ * 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_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.setHeader("custom_key", "custom_value");
- *
+ * @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(String key, String value) {
+ public void setHeader(@NotNull String key, @NotNull String value) {
if (!key.isEmpty() && !value.isEmpty()) {
- localHeader.put(key, value);
+ this.headers.put(key, value);
}
}
-
/**
* Remove header key @param key custom_header_key
*
- * @param key {@link String}
- * Example :
- *
- * Stack stack = Contentstack..stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").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(String key) {
+ public void removeHeader(@NotNull String key) {
if (!key.isEmpty()) {
- localHeader.remove(key);
+ this.headers.remove(key);
}
}
public String getContentType() {
- return contentTypeInstance.contentTypeName;
+ return contentTypeInstance.contentTypeUid;
}
-
/**
- * 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.
* @return {@link Query} object, so you can chain this call.
- *
- * Note : for group field provide key in a "key.groupFieldUid" format.
- * Example :
- *
- * Stack stack = Contentstack..stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.where("uid", "bltf4fbsample851db");
- *
+ *
+ * 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");
+ *
*/
- public Query where(String key, Object value) {
- try {
- if (key != null && value != null) {
- queryValueJSON.put(key, value);
- } else {
- throwException("where", CSAppConstants.ErrorMessage_QueryFilterException, null);
- }
- } catch (Exception e) {
- throwException("where", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
-
+ public Query where(@NotNull String key, Object value) {
+ queryValueJSON.put(key, value);
return this;
}
-
/**
* Add a custom query against specified key.
*
@@ -133,379 +130,323 @@ public Query where(String key, Object value) {
* @param value value.
* @return {@link Query} object, so you can chain this call.
*
- * Example :
- *
- * Stack stack = Contentstack..stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.addQuery("query_param_key", "query_param_value");
- *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack..stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.addQuery("query_param_key", "query_param_value");
+ *
*/
- public Query addQuery(String key, String value) {
- try {
- if (key != null && value != null) {
-
- urlQueries.put(key, value);
- } else {
- throwException("and", CSAppConstants.ErrorMessage_QueryFilterException, null);
- }
- } catch (Exception e) {
- throwException("and", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ public Query addQuery(@NotNull String key, String value) {
+ if (value != null) {
+ urlQueries.put(key, value);
}
return this;
}
-
/**
* Remove provided query key from custom query if exist.
*
* @param key Query name to remove.
- * @return {@linkplain Query} object, so you can chain this call.
- * Example :
- *
- * projectQuery.removeQuery("Query_Key");
- *
+ * @return {@linkplain Query} object, so you can chain this call.
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * projectQuery.removeQuery("Query_Key");
+ *
*/
- public Query removeQuery(String key) {
- try {
- if (urlQueries.has(key)) {
- urlQueries.remove(key);
- }
- } catch (Exception e) {
- throwException("and", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ public Query removeQuery(@NotNull String key) {
+ if (urlQueries.has(key)) {
+ urlQueries.remove(key);
}
return this;
}
-
/**
* 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 ;
- *
- * Stack stack = Contentstack..stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- *
- * Query query = projectClass.query();
- * query.where('username','something');
- *
- * Query subQuery = projectClass.query();
- * subQuery.where('email_address','something@email.com');
- *
- * ArrayList<Query> array = new ArrayList<Query>();
- * array.add(query);
- * array.add(subQuery);
- * projectQuery.and(array);
- *
+ *
+ *
+ * Example ;
+ *
+ *
+ * Stack stack = Contentstack..stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ *
+ * Query query = projectClass.query();
+ * query.where('username','something');
+ *
+ * Query subQuery = projectClass.query();
+ * subQuery.where('email_address','something@email.com');
+ *
+ * ArrayList<Query> array = new ArrayList<Query>();
+ * array.add(query);
+ * array.add(subQuery);
+ * projectQuery.and(array);
+ *
*/
- public Query and(ArrayList queryObjects) {
- if (queryObjects != null && queryObjects.size() > 0) {
- try {
- JSONArray orValueJson = new JSONArray();
- int count = queryObjects.size();
-
- for (int i = 0; i < count; i++) {
- orValueJson.put(queryObjects.get(i).queryValueJSON);
- }
- queryValueJSON.put("$and", orValueJson);
-
- } catch (Exception e) {
- throwException("and", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
+ public Query and(@NotNull ArrayList queryObjects) {
+ if (!queryObjects.isEmpty()) {
+ JSONArray orValueJson = new JSONArray();
+ queryObjects.forEach(obj -> orValueJson.put(obj.queryValueJSON));
+ queryValueJSON.put("$and", orValueJson);
} else {
- throwException("and", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ throwException("and", "Can not process with blank query objects", null);
}
-
return this;
}
-
/**
* 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 :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- *
- * Query query = projectClass.query();
- * query.where('username','something');
- *
- * Query subQuery = projectClass.query();
- * subQuery.where('email_address','something@email.com');
- *
- * ArrayList<Query> array = new ArrayList<Query>();
- * array.add(query);
- * array.add(subQuery);
- * csQuery.or(array);
- *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ *
+ * Query query = projectClass.query();
+ * query.where('username','something');
+ *
+ * Query subQuery = projectClass.query();
+ * subQuery.where('email_address','something@email.com');
+ *
+ * ArrayList<Query> array = new ArrayList<Query>();
+ * array.add(query);
+ * array.add(subQuery);
+ * csQuery.or(array);
+ *
*/
public Query or(ArrayList queryObjects) {
- if (queryObjects != null && queryObjects.size() > 0) {
+ if (queryObjects != null && !queryObjects.isEmpty()) {
try {
JSONArray orValueJson = new JSONArray();
- int count = queryObjects.size();
-
- for (int i = 0; i < count; i++) {
- orValueJson.put(queryObjects.get(i).queryValueJSON);
+ for (Query queryObject : queryObjects) {
+ orValueJson.put(queryObject.queryValueJSON);
}
-
queryValueJSON.put("$or", orValueJson);
} catch (Exception e) {
- throwException("or", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ throwException("or", Constants.QUERY_EXCEPTION, e);
}
- } else {
- throwException("or", CSAppConstants.ErrorMessage_QueryFilterException, null);
}
return this;
}
-
/**
- * 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.
- * @return {@link Query} object, so you can chain this call.
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.lessThan("due_date", "2013-06-25T00:00:00+05:30");
- *
+ * @return {@link Query} object, so you can chain this call.
+ *
+ *
+ *
+ * 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");
+ *
*/
- public Query lessThan(String key, Object value) {
- if (key != null && value != null) {
- try {
- if (queryValueJSON.isNull(key)) {
- if (queryValue.length() > 0) {
- queryValue = new JSONObject();
- }
- queryValue.put("$lt", value);
- queryValueJSON.put(key, queryValue);
- } else if (queryValueJSON.has(key)) {
- queryValue.put("$lt", value);
- queryValueJSON.put(key, queryValue);
- }
- } catch (Exception e) {
- throwException("lessThan", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ public Query lessThan(@NotNull String key, @NotNull Object value) {
+ if (queryValueJSON.isNull(key)) {
+ if (queryValue.length() > 0) {
+ queryValue = new JSONObject();
}
- } else {
- throwException("lessThan", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ queryValue.put("$lt", value);
+ queryValueJSON.put(key, queryValue);
+ } else if (queryValueJSON.has(key)) {
+ queryValue.put("$lt", value);
+ queryValueJSON.put(key, queryValue);
}
-
return this;
}
-
/**
- * 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.
* @return {@link Query} object, so you can chain this call.
*
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.lessThanOrEqualTo("due_date", "2013-06-25T00:00:00+05:30");
- *
+ *
+ *
+ * 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");
+ *
*/
- public Query lessThanOrEqualTo(String key, Object value) {
-
- if (key != null && value != null) {
-
- try {
- if (queryValueJSON.isNull(key)) {
- if (queryValue.length() > 0) {
- queryValue = new JSONObject();
- }
- queryValue.put("$lte", value);
- queryValueJSON.put(key, queryValue);
- } else if (queryValueJSON.has(key)) {
- queryValue.put("$lte", value);
- queryValueJSON.put(key, queryValue);
- }
- } catch (Exception e) {
- throwException("lessThanOrEqualTo", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ public Query lessThanOrEqualTo(@NotNull String key, Object value) {
+ if (queryValueJSON.isNull(key)) {
+ if (queryValue.length() > 0) {
+ queryValue = new JSONObject();
}
- } else {
- throwException("lessThanOrEqualTo", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ queryValue.put("$lte", value);
+ queryValueJSON.put(key, queryValue);
+ } else if (queryValueJSON.has(key)) {
+ queryValue.put("$lte", value);
+ queryValueJSON.put(key, queryValue);
}
return this;
}
-
/**
- * 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.
* @return {@link Query} object, so you can chain this call.
*
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.greaterThan("due_date", "2013-06-25T00:00:00+05:30");
- *
+ *
+ *
+ * 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");
+ *
*/
- public Query greaterThan(String key, Object value) {
-
- if (key != null && value != null) {
- try {
- if (queryValueJSON.isNull(key)) {
- if (queryValue.length() > 0) {
- queryValue = new JSONObject();
- }
- queryValue.put("$gt", value);
- queryValueJSON.put(key, queryValue);
- } else if (queryValueJSON.has(key)) {
- queryValue.put("$gt", value);
- queryValueJSON.put(key, queryValue);
- }
- } catch (Exception e) {
- throwException("greaterThan", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ public Query greaterThan(@NotNull String key, Object value) {
+ if (queryValueJSON.isNull(key)) {
+ if (queryValue.length() > 0) {
+ queryValue = new JSONObject();
}
- } else {
- throwException("greaterThan", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ queryValue.put("$gt", value);
+ queryValueJSON.put(key, queryValue);
+ } else if (queryValueJSON.has(key)) {
+ queryValue.put("$gt", value);
+ queryValueJSON.put(key, queryValue);
}
return this;
}
-
/**
- * 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.
* @return {@link Query} object, so you can chain this call.
*
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.greaterThanOrEqualTo("due_date", "2013-06-25T00:00:00+05:30");
- *
+ *
+ *
+ * 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");
+ *
*/
public Query greaterThanOrEqualTo(String key, Object value) {
-
- if (key != null && value != null) {
- try {
- if (queryValueJSON.isNull(key)) {
- if (queryValue.length() > 0) {
- queryValue = new JSONObject();
- }
- queryValue.put("$gte", value);
- queryValueJSON.put(key, queryValue);
- } else if (queryValueJSON.has(key)) {
- queryValue.put("$gte", value);
- queryValueJSON.put(key, queryValue);
- }
- } catch (Exception e) {
- throwException("greaterThanOrEqualTo", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ if (queryValueJSON.isNull(key)) {
+ if (queryValue.length() > 0) {
+ queryValue = new JSONObject();
}
- } else {
- throwException("greaterThanOrEqualTo", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ queryValue.put("$gte", value);
+ queryValueJSON.put(key, queryValue);
+ } else if (queryValueJSON.has(key)) {
+ queryValue.put("$gte", value);
+ queryValueJSON.put(key, queryValue);
}
return this;
}
-
/**
- * 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.
* @return {@link Query} object, so you can chain this call.
*
- * Example ;
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.notEqualTo("due_date", "2013-06-25T00:00:00+05:30");
- *
+ *
+ *
+ * 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");
+ *
*/
- public Query notEqualTo(String key, Object value) {
-
- if (key != null && value != null) {
-
- try {
- if (queryValueJSON.isNull(key)) {
- if (queryValue.length() > 0) {
- queryValue = new JSONObject();
- }
- queryValue.put("$ne", value);
- queryValueJSON.put(key, queryValue);
- } else if (queryValueJSON.has(key)) {
- queryValue.put("$ne", value);
- queryValueJSON.put(key, queryValue);
- }
- } catch (Exception e) {
- throwException("notEqualTo", null, e);
+ public Query notEqualTo(@NotNull String key, Object value) {
+ if (queryValueJSON.isNull(key)) {
+ if (queryValue.length() > 0) {
+ queryValue = new JSONObject();
}
-
- } else {
- throwException("notEqualTo", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ queryValue.put("$ne", value);
+ queryValueJSON.put(key, queryValue);
+ } else if (queryValueJSON.has(key)) {
+ queryValue.put("$ne", value);
+ queryValueJSON.put(key, queryValue);
}
-
return this;
}
-
/**
- * 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.
- * @return {@link Query} object, so you can chain this call.
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.containedIn("severity", new Object[]{"Show Stopper", "Critical"});
- *
+ * @return {@link Query} object, so you can chain this call.
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.containedIn("severity", new Object[] { "Show Stopper", "Critical" });
+ *
*/
- public Query containedIn(String key, Object[] values) {
-
- if (key != null && values != null) {
- try {
- JSONArray valuesArray = new JSONArray();
- int length = values.length;
- for (int i = 0; i < length; i++) {
- valuesArray.put(values[i]);
- }
- if (queryValueJSON.isNull(key)) {
- if (queryValue.length() > 0) {
- queryValue = new JSONObject();
- }
- queryValue.put("$in", valuesArray);
- queryValueJSON.put(key, queryValue);
- } else if (queryValueJSON.has(key)) {
- queryValue.put("$in", valuesArray);
- queryValueJSON.put(key, queryValue);
- }
- } catch (Exception e) {
- throwException("containedIn", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ public Query containedIn(@NotNull String key, Object[] values) {
+ JSONArray valuesArray = new JSONArray();
+ int length = values.length;
+ for (int i = 0; i < length; i++) {
+ valuesArray.put(values[i]);
+ }
+ if (queryValueJSON.isNull(key)) {
+ if (queryValue.length() > 0) {
+ queryValue = new JSONObject();
}
- } else {
- throwException("containedIn", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ queryValue.put("$in", valuesArray);
+ queryValueJSON.put(key, queryValue);
+ } else if (queryValueJSON.has(key)) {
+ queryValue.put("$in", valuesArray);
+ queryValueJSON.put(key, queryValue);
}
-
return this;
}
-
/**
* Add a constraint to the query that requires a particular key entry's
* value not be contained in the provided array.
@@ -514,131 +455,113 @@ public Query containedIn(String key, Object[] values) {
* @param values The list of values the key object should not be.
* @return {@link Query} object, so you can chain this call.
*
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.notContainedIn("severity", new Object[]{"Show Stopper", "Critical"});
- *
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.notContainedIn("severity", new Object[] { "Show Stopper", "Critical" });
+ *
*/
- public Query notContainedIn(String key, Object[] values) {
-
- if (key != null && values != null) {
- try {
- JSONArray valuesArray = new JSONArray();
- int length = values.length;
- for (int i = 0; i < length; i++) {
- valuesArray.put(values[i]);
- }
- if (queryValueJSON.isNull(key)) {
- if (queryValue.length() > 0) {
- queryValue = new JSONObject();
- }
- queryValue.put("$nin", valuesArray);
- queryValueJSON.put(key, queryValue);
- } else if (queryValueJSON.has(key)) {
- queryValue.put("$nin", valuesArray);
- queryValueJSON.put(key, queryValue);
- }
- } catch (Exception e) {
- throwException("containedIn", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ public Query notContainedIn(@NotNull String key, Object[] values) {
+ JSONArray valuesArray = new JSONArray();
+ int length = values.length;
+ for (int i = 0; i < length; i++) {
+ valuesArray.put(values[i]);
+ }
+ if (queryValueJSON.isNull(key)) {
+ if (queryValue.length() > 0) {
+ queryValue = new JSONObject();
}
- } else {
- throwException("containedIn", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ queryValue.put("$nin", valuesArray);
+ queryValueJSON.put(key, queryValue);
+ } else if (queryValueJSON.has(key)) {
+ queryValue.put("$nin", valuesArray);
+ queryValueJSON.put(key, queryValue);
}
-
return this;
}
-
/**
* Add a constraint that requires, a specified key exists in response.
*
* @param key The key to be constrained.
* @return {@link Query} object, so you can chain this call.
*
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.exists("status");
- *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.exists("status");
+ *
*/
- public Query exists(String key) {
-
- if (key != null) {
- try {
- if (queryValueJSON.isNull(key)) {
- if (queryValue.length() > 0) {
- queryValue = new JSONObject();
- }
- queryValue.put("$exists", true);
- queryValueJSON.put(key, queryValue);
- } else if (queryValueJSON.has(key)) {
- queryValue.put("$exists", true);
- queryValueJSON.put(key, queryValue);
- }
- } catch (Exception e) {
- throwException("exists", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ public Query exists(@NotNull String key) {
+ if (queryValueJSON.isNull(key)) {
+ if (queryValue.length() > 0) {
+ queryValue = new JSONObject();
}
- } else {
- throwException("exists", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ queryValue.put(EXISTS, true);
+ queryValueJSON.put(key, queryValue);
+ } else if (queryValueJSON.has(key)) {
+ queryValue.put(EXISTS, true);
+ queryValueJSON.put(key, queryValue);
}
return this;
}
-
/**
* Add a constraint that requires, a specified key does not exists in response.
*
* @param key The key to be constrained.
- * @return {@link Query} object, so you can chain this call.
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.notExists("status");
- *
+ * @return {@link Query} object, so you can chain this call.
+ *
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.notExists("status");
+ *
*/
- public Query notExists(String key) {
-
- if (key != null) {
- try {
-
- if (queryValueJSON.isNull(key)) {
- if (queryValue.length() > 0) {
- queryValue = new JSONObject();
- }
- queryValue.put("$exists", false);
- queryValueJSON.put(key, queryValue);
- } else if (queryValueJSON.has(key)) {
-
- queryValue.put("$exists", false);
- queryValueJSON.put(key, queryValue);
- }
- } catch (Exception e) {
- throwException("notExists", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ public Query notExists(@NotNull String key) {
+ if (queryValueJSON.isNull(key)) {
+ if (queryValue.length() > 0) {
+ queryValue = new JSONObject();
}
- } else {
- throwException("notExists", CSAppConstants.ErrorMessage_QueryFilterException, null);
- }
+ queryValue.put(EXISTS, false);
+ queryValueJSON.put(key, queryValue);
+ } else if (queryValueJSON.has(key)) {
+ queryValue.put(EXISTS, false);
+ queryValueJSON.put(key, queryValue);
+ }
return this;
}
-
/**
* Add a constraint that requires a particular reference key details.
*
* @param key key that to be constrained.
* @return {@link Query} object, so you can chain this call.
*
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.includeReference("for_bug");
- *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.includeReference("for_bug");
+ *
*/
public Query includeReference(String key) {
if (objectUidForInclude == null) {
@@ -648,891 +571,697 @@ public Query includeReference(String key) {
return this;
}
-
/**
* Include 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 :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.tags(new String[]{"tag1","tag2"});
- *
+ * @return {@link Query} object, so you can chain this call.
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.tags(new String[] { "tag1", "tag2" });
+ *
*/
- public Query tags(String[] tags) {
- try {
- if (tags != null) {
-
- String tagsvalue = null;
- int count = tags.length;
- for (int i = 0; i < count; i++) {
- tagsvalue = tagsvalue + "," + tags[i];
- }
- urlQueries.put("tags", tagsvalue);
- } else {
- throwException("tags", CSAppConstants.ErrorMessage_QueryFilterException, null);
- }
- } catch (Exception e) {
- throwException("tags", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ public Query tags(@NotNull String[] tags) {
+ String tagsvalue = null;
+ int count = tags.length;
+ for (int i = 0; i < count; i++) {
+ tagsvalue = tagsvalue + "," + tags[i];
}
+ urlQueries.put("tags", tagsvalue);
return this;
}
-
/**
- * Sort the results in ascending order with the given 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.
- * @return {@link Query} object, so you can chain this call.
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.ascending("name");
- *
+ * @return {@link Query} object, so you can chain this call.
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.ascending("name");
+ *
*/
-
- public Query ascending(String key) {
- if (key != null) {
- try {
- urlQueries.put("asc", key);
- } catch (Exception e) {
- throwException("ascending", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
- } else {
- throwException("ascending", CSAppConstants.ErrorMessage_QueryFilterException, null);
- }
+ public Query ascending(@NotNull String key) {
+ urlQueries.put("asc", key);
return this;
}
-
/**
- * Sort the results in descending order with the given 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.
- * @return {@link Query} object, so you can chain this call.
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.descending("name");
- *
+ * @return {@link Query} object, so you can chain this call.
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.descending("name");
+ *
*/
- public Query descending(String key) {
- if (key != null) {
- try {
- urlQueries.put("desc", key);
- } catch (Exception e) {
- throwException("descending", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
- } else {
- throwException("descending", CSAppConstants.ErrorMessage_QueryFilterException, null);
- }
+ public Query descending(@NotNull String key) {
+ urlQueries.put("desc", key);
return this;
}
-
/**
- * 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 :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * ArrayList<String> array = new ArrayList<String>();
- * array.add("name");
- * array.add("description");
- * csQuery.except(array);
- *
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * ArrayList<String> array = new ArrayList<String>();
+ * array.add("name");
+ * array.add("description");
+ * csQuery.except(array);
+ *
*/
- public Query except(ArrayList fieldUid) {
- try {
- if (fieldUid != null && fieldUid.size() > 0) {
- if (objectUidForExcept == null) {
- objectUidForExcept = new JSONArray();
- }
- int count = fieldUid.size();
- for (int i = 0; i < count; i++) {
- objectUidForExcept.put(fieldUid.get(i));
- }
- } else {
- throwException("except", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ public Query except(@NotNull ArrayList fieldUid) {
+ if (!fieldUid.isEmpty()) {
+ if (objectUidForExcept == null) {
+ objectUidForExcept = new JSONArray();
+ }
+ for (String s : fieldUid) {
+ objectUidForExcept.put(s);
}
- } catch (Exception e) {
- throwException("except", CSAppConstants.ErrorMessage_QueryFilterException, e);
}
return this;
}
-
/**
- * Specifies list of field uids that would be 'excluded' from the response.
- *
- * @param fieldUids field uid which get 'excluded' from the response.
- * @return {@link Query} object, so you can chain this call.
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.except(new String[]{"name", "description"});
- *
+ * Specifies list of field uids that would be '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 :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.except(new String[]{"name", "description"});
+ *
*/
- public Query except(String[] fieldUids) {
- try {
- if (fieldUids != null && fieldUids.length > 0) {
- if (objectUidForExcept == null) {
- objectUidForExcept = new JSONArray();
- }
- int count = fieldUids.length;
- for (int i = 0; i < count; i++) {
- objectUidForExcept.put(fieldUids[i]);
- }
- } else {
- throwException("except", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ public Query except(@NotNull String[] fieldIds) {
+ if (fieldIds.length > 0) {
+ if (objectUidForExcept == null) {
+ objectUidForExcept = new JSONArray();
+ }
+ for (String fieldId : fieldIds) {
+ objectUidForExcept.put(fieldId);
}
- } catch (Exception e) {
- throwException("except", CSAppConstants.ErrorMessage_QueryFilterException, e);
}
return this;
}
-
/**
- * 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.
- * @return {@link Query} object, so you can chain this call.
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.only(new String[]{"name"});
- *
+ * 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.
+ * @return {@link Query} object, so you can chain this call.
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.only(new String[]{"name"});
+ *
*/
- public Query only(String[] fieldUid) {
- try {
- if (fieldUid != null && fieldUid.length > 0) {
- if (objectUidForOnly == null) {
- objectUidForOnly = new JSONArray();
- }
- int count = fieldUid.length;
- for (int i = 0; i < count; i++) {
- objectUidForOnly.put(fieldUid[i]);
- }
- } else {
- throwException("only", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ public Query only(@NotNull String[] fieldUid) {
+ if (fieldUid.length > 0) {
+ if (objectUidForOnly == null) {
+ objectUidForOnly = new JSONArray();
+ }
+ for (String s : fieldUid) {
+ objectUidForOnly.put(s);
}
- } catch (Exception e) {
- throwException("only", CSAppConstants.ErrorMessage_QueryFilterException, e);
}
return this;
}
-
/**
- * 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 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 :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * ArrayList<String> array = new ArrayList<String>();
- * array.add("description");
- * array.add("name");
- * csQuery.onlyWithReferenceUid(array, "for_bug");
- *
+ * @return {@link Query} object, so you can chain this call.
+ *
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * ArrayList<String> array = new ArrayList<String>();
+ * array.add("description");
+ * array.add("name");
+ * csQuery.onlyWithReferenceUid(array, "for_bug");
+ *
*/
- public Query onlyWithReferenceUid(ArrayList fieldUid, String referenceFieldUid) {
- try {
- if (fieldUid != null && referenceFieldUid != null) {
- if (onlyJsonObject == null) {
- onlyJsonObject = new JSONObject();
- }
- JSONArray fieldValueArray = new JSONArray();
- int count = fieldUid.size();
- for (int i = 0; i < count; i++) {
- fieldValueArray.put(fieldUid.get(i));
- }
-
- onlyJsonObject.put(referenceFieldUid, fieldValueArray);
- if (objectUidForInclude == null) {
- objectUidForInclude = new JSONArray();
- }
- objectUidForInclude.put(referenceFieldUid);
-
- } else {
- throwException("onlyWithReferenceUid", CSAppConstants.ErrorMessage_QueryFilterException, null);
- }
- } catch (Exception e) {
- throwException("onlyWithReferenceUid", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ public Query onlyWithReferenceUid(@NotNull ArrayList fieldUid, @NotNull String referenceFieldUid) {
+ if (onlyJsonObject == null) {
+ onlyJsonObject = new JSONObject();
+ }
+ JSONArray fieldValueArray = new JSONArray();
+ for (String s : fieldUid) {
+ fieldValueArray.put(s);
+ }
+ onlyJsonObject.put(referenceFieldUid, fieldValueArray);
+ if (objectUidForInclude == null) {
+ objectUidForInclude = new JSONArray();
}
+ objectUidForInclude.put(referenceFieldUid);
return this;
}
-
/**
- * 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 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 :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * ArrayList<String> array = new ArrayList<String>();
- * array.add("description");
- * array.add("name");
- * csQuery.exceptWithReferenceUid(array, "for_bug");
- *
+ * @return {@link Query} object, so you can chain this call.
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * ArrayList<String> array = new ArrayList<String>();
+ * array.add("description");
+ * array.add("name");
+ * csQuery.exceptWithReferenceUid(array, "for_bug");
+ *
*/
- public Query exceptWithReferenceUid(ArrayList fieldUid, String referenceFieldUid) {
- try {
- if (fieldUid != null && referenceFieldUid != null) {
- if (exceptJsonObject == null) {
- exceptJsonObject = new JSONObject();
- }
- JSONArray fieldValueArray = new JSONArray();
- int count = fieldUid.size();
- for (int i = 0; i < count; i++) {
- fieldValueArray.put(fieldUid.get(i));
- }
- exceptJsonObject.put(referenceFieldUid, fieldValueArray);
- if (objectUidForInclude == null) {
- objectUidForInclude = new JSONArray();
- }
- objectUidForInclude.put(referenceFieldUid);
- } else {
- throwException("exceptWithReferenceUid", CSAppConstants.ErrorMessage_QueryFilterException, null);
- }
- } catch (Exception e) {
- throwException("exceptWithReferenceUid", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ public Query exceptWithReferenceUid(@NotNull ArrayList fieldUid, @NotNull String referenceFieldUid) {
+ if (exceptJsonObject == null) {
+ exceptJsonObject = new JSONObject();
}
+ JSONArray fieldValueArray = new JSONArray();
+ for (String s : fieldUid) {
+ fieldValueArray.put(s);
+ }
+ exceptJsonObject.put(referenceFieldUid, fieldValueArray);
+ if (objectUidForInclude == null) {
+ objectUidForInclude = new JSONArray();
+ }
+ objectUidForInclude.put(referenceFieldUid);
return this;
}
-
/**
* 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 :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.count();
- *
+ * @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();
+ *
*/
public Query count() {
- try {
- urlQueries.put("count", "true");
- } catch (Exception e) {
- throwException("count", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
+ urlQueries.put("count", "true");
return this;
}
-
/**
* 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 :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.includeCount();
- *
+ * @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();
+ *
*/
public Query includeCount() {
- try {
- urlQueries.put("include_count", "true");
- } catch (Exception e) {
- throwException("includeCount", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
+ urlQueries.put("include_count", "true");
return this;
}
-
/**
* Include Content Type of all returned objects along with objects themselves.
*
- * @return {@link Query} object, so you can chain this call.
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.includeContentType();
- *
+ * @return {@link Query} object, so you can chain this call.
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.includeContentType();
+ *
*/
public Query includeContentType() {
- try {
- if (urlQueries.has("include_schema")) {
- urlQueries.remove("include_schema");
- }
- urlQueries.put("include_content_type", true);
- urlQueries.put("include_global_field_schema", true);
- } catch (Exception e) {
- throwException("include_content_type", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ if (urlQueries.has("include_schema")) {
+ urlQueries.remove("include_schema");
}
+ urlQueries.put("include_content_type", true);
+ urlQueries.put("include_global_field_schema", true);
return this;
}
-
/**
* Include object owner's profile in the objects data.
*
- * @return {@linkplain Query} object, so you can chain this call.
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.includeOwner();
- *
+ * @return {@linkplain Query} object, so you can chain this call.
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.includeOwner();
+ *
*/
public Query includeOwner() {
- try {
- urlQueries.put("include_owner", true);
- } catch (Exception e) {
- throwException("includeUser", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
+ urlQueries.put("include_owner", true);
return this;
}
-
- /**
- * Fetches all the objects before specified uid.
- *
- * @param uid uid before which objects should be returned.
- * @return {@link Query} object, so you can chain this call.
- *
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("content_type").query();
- * //'blt0ae4df463e93f6f5' is dummy uid
- * csQuery.beforeUid("blt0ae4df463e93f6f5");
- *
- */
- private Query beforeUid(String uid) {
- if (uid != null) {
- try {
- urlQueries.put("before_uid", uid);
- } catch (Exception e) {
- throwException("beforeUid", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
- } else {
- throwException("beforeUid", CSAppConstants.ErrorMessage_QueryFilterException, null);
- }
- return this;
- }
-
-
- /**
- * Fetches all the objects after specified uid.
- *
- * @param uid uid after which objects should be returned.
- * @return {@link Query} object, so you can chain this call.
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * //'blt0ae4df463e93f6f5' is dummy uid
- * csQuery.afterUid("blt0ae4df463e93f6f5");
- *
- */
- private Query afterUid(String uid) {
- if (uid != null) {
- try {
- urlQueries.put("after_uid", uid);
- } catch (Exception e) {
- throwException("afterUid", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
- } else {
- throwException("afterUid", CSAppConstants.ErrorMessage_QueryFilterException, null);
- }
- return this;
- }
-
-
/**
* The number of objects to skip before returning any.
*
* @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 :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.skip(2);
- *
+ *
+ * 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);
+ *
*/
public Query skip(int number) {
- try {
- urlQueries.put("skip", number);
- } catch (Exception e) {
- throwException("skip", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
+ urlQueries.put("skip", number);
return this;
}
-
/**
* A limit on the number of objects to return.
*
* @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 :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.limit(2);
- *
+ *
+ * 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);
+ *
*/
public Query limit(int number) {
- try {
- urlQueries.put("limit", number);
- } catch (Exception e) {
- throwException("limit", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
+ urlQueries.put(LIMIT, number);
return this;
}
-
/**
- * 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.
- * @return {@link Query} object, so you can chain this call.
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.regex("name", "^browser");
- *
+ * @return {@link Query} object, so you can chain this call.
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.regex("name", "^browser");
+ *
*/
- public Query regex(String key, String regex) {
-
- if (key != null && regex != null) {
- try {
- if (queryValueJSON.isNull(key)) {
-
- if (queryValue.length() > 0) {
- queryValue = new JSONObject();
- }
- queryValue.put("$regex", regex);
- queryValueJSON.put(key, queryValue);
- } else if (queryValueJSON.has(key)) {
- queryValue.put("$regex", regex);
- queryValueJSON.put(key, queryValue);
- }
- } catch (Exception e) {
- throwException("matches", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ public Query regex(@NotNull String key, @NotNull String regex) {
+ if (queryValueJSON.isNull(key)) {
+ if (!queryValue.isEmpty()) {
+ queryValue = new JSONObject();
}
- } else {
- throwException("matches", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ queryValue.put(REGEX, regex);
+ queryValueJSON.put(key, queryValue);
+ } else if (queryValueJSON.has(key)) {
+ queryValue.put(REGEX, regex);
+ queryValueJSON.put(key, queryValue);
}
return this;
}
-
/**
- * 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 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 :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.regex("name", "^browser", "i");
- *
+ *
+ * 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 :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.regex("name", "^browser", "i");
+ *
*/
-
- public Query regex(String key, String regex, String modifiers) {
- if (key != null && regex != null) {
-
- try {
- if (queryValueJSON.isNull(key)) {
-
- if (queryValue.length() > 0) {
- queryValue = new JSONObject();
- }
- queryValue.put("$regex", regex);
- if (modifiers != null) {
- queryValue.put("$options", modifiers);
- }
- queryValueJSON.put(key, queryValue);
- } else if (queryValueJSON.has(key)) {
- queryValue.put("$regex", regex);
- if (modifiers != null) {
- queryValue.put("$options", modifiers);
- }
- queryValueJSON.put(key, queryValue);
+ public Query regex(@NotNull String key, @NotNull String regex, String modifiers) {
+ try {
+ if (queryValueJSON.isNull(key)) {
+ if (queryValue.length() > 0) {
+ queryValue = new JSONObject();
}
- } catch (Exception e) {
- throwException("matches", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
- } else {
- throwException("matches", CSAppConstants.ErrorMessage_QueryFilterException, null);
- }
- return this;
- }
-
-
- /**
- * Set {@link Language} instance.
- *
- * @param language {@link Language} value
- * @return {@link Query} object, so you can chain this call
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.language(Language.ENGLISH_UNITED_STATES);
- *
- */
- @Deprecated
- public Query language(Language language) {
-
- if (language != null) {
- try {
- Language languageName = Language.valueOf(language.name());
- int localeValue = languageName.ordinal();
- LanguageCode[] languageCodeValues = LanguageCode.values();
- String localeCode = languageCodeValues[localeValue].name();
- localeCode = localeCode.replace("_", "-");
-
- if (urlQueries != null) {
- urlQueries.put("locale", localeCode);
+ queryValue.put(REGEX, regex);
+ if (modifiers != null) {
+ queryValue.put(OPTIONS, modifiers);
}
-
- } catch (Exception e) {
- throwException("language", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ queryValueJSON.put(key, queryValue);
+ } else if (queryValueJSON.has(key)) {
+ queryValue.put(REGEX, regex);
+ if (modifiers != null) {
+ queryValue.put(OPTIONS, modifiers);
+ }
+ queryValueJSON.put(key, queryValue);
}
- } else {
- throwException("language", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ } catch (Exception e) {
+ throwException(OPTIONS, Constants.QUERY_EXCEPTION, e);
}
-
return this;
}
-
/**
- * Set {@link Language} instance.
+ * set Language using locale code.
*
* @param locale {@link String} value
- * @return {@link Query} object, so you can chain this call
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.locale("en-us");
- *
+ * @return {@link Query} object, so you can chain this call
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.locale("en-us");
+ *
*/
- public Query locale(String locale) {
-
- if (locale != null && urlQueries != null) {
- try {
- urlQueries.put("locale", locale);
- } catch (JSONException e) {
- logger.severe(e.getLocalizedMessage());
- }
- }
-
+ public Query locale(@NotNull String locale) {
+ urlQueries.put("locale", locale);
return this;
}
-
/**
* This method provides only the entries matching the specified value.
*
* @param value value used to match or compare
- * @return {@link Query} object, so you can chain this call.
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.search("header");
- *
+ * @return {@link Query} object, so you can chain this call.
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.search("header");
+ *
*/
- public Query search(String value) {
-
- if (value != null) {
- try {
- if (urlQueries.isNull(value)) {
- urlQueries.put("typeahead", value);
- }
- } catch (Exception e) {
- throwException("value", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
- } else {
- throwException("value", CSAppConstants.ErrorMessage_QueryFilterException, null);
+ public Query search(@NotNull String value) {
+ if (urlQueries.isNull(value)) {
+ urlQueries.put("typeahead", value);
}
-
return this;
}
-
/**
* Execute a Query and Caches its result (Optional)
*
- * @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 :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.find(new QueryResultsCallBack() {
- * @Override
+ * @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 :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.find(new QueryResultsCallBack() {
+ * @Override
* public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
- * }
+ * }
* });
- *
+ *
*/
public Query find(QueryResultsCallBack callback) {
-
Error error = null;
- try {
- if (isJsonProper) {
- if (!formName.isEmpty()) {
- execQuery(null, callback, false);
- } else {
- throwException("find", CSAppConstants.ErrorMessage_FormName, null);
- error = new Error();
- error.setErrorMessage(errorString);
- }
+ if (isJsonProper) {
+ if (!contentTypeUid.isEmpty()) {
+ execQuery(null, callback);
} else {
+ throwException("find", Constants.CONTENT_TYPE_NAME, null);
error = new Error();
error.setErrorMessage(errorString);
}
- } catch (Exception e) {
- logger.severe(e.getLocalizedMessage());
- throwException("find", CSAppConstants.ErrorMessage_JsonNotProper, null);
+ } else {
error = new Error();
error.setErrorMessage(errorString);
}
-
- if (error != null && callback != null) {
- callback.onRequestFail(ResponseType.UNKNOWN, error);
- }
return this;
}
-
/**
* Execute a Query and Caches its result (Optional)
*
- * @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 :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.findOne(new QueryResultsCallBack() {
- * @Override
+ * @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 :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.findOne(new QueryResultsCallBack() {
+ * @Override
* public void onCompletion(ResponseType responseType, ENTRY entry, Error error) {
*
* }
* });
- *
+ *
*/
public Query findOne(SingleQueryResultCallback callBack) {
- Error error = null;
- try {
- if (isJsonProper) {
- if (!formName.isEmpty()) {
-
- int limit = -1;
- if (urlQueries != null && urlQueries.has("limit")) {
- limit = (int) urlQueries.get("limit");
- }
- urlQueries.put("limit", 1);
-
- execQuery(callBack, null, false);
+ if (isJsonProper) {
+ if (!contentTypeUid.isEmpty()) {
+ int limit = -1;
+ if (urlQueries != null && urlQueries.has(LIMIT)) {
+ limit = (int) urlQueries.get(LIMIT);
+ }
+ if (urlQueries != null) {
+ urlQueries.put(LIMIT, 1);
+ execQuery(callBack, null);
if (limit != -1) {
- urlQueries.put("limit", limit);
+ urlQueries.put(LIMIT, limit);
}
-
- } else {
-
- throwException("find", CSAppConstants.ErrorMessage_FormName, null);
- error = new Error();
- error.setErrorMessage(errorString);
}
} else {
-
- error = new Error();
- error.setErrorMessage(errorString);
+ throwException("find", Constants.CONTENT_TYPE_NAME, null);
}
- } catch (Exception e) {
-
- throwException("find", CSAppConstants.ErrorMessage_JsonNotProper, null);
- error = new Error();
- error.setErrorMessage(errorString);
}
-
- if (error != null && callBack != null) {
- callBack.onRequestFail(ResponseType.UNKNOWN, error);
- }
-
return this;
}
-
private void throwException(String queryName, String messageString, Exception e) {
+ HashMap errorHashMap = new HashMap<>();
isJsonProper = false;
errorString = messageString;
- errorHashMap = new HashMap();
if (e != null) {
- errorHashMap.put(queryName, e.toString());
+ errorHashMap.put(queryName, e.getLocalizedMessage());
}
+ errorHashMap.put("detail", messageString);
+ logger.warning(messageString);
}
-
- protected void setQueryJson(QueryResultsCallBack callback) {
- try {
-
- if (queryValueJSON != null && queryValueJSON.length() > 0) {
- urlQueries.put("query", queryValueJSON);
- }
-
- if (objectUidForExcept != null && objectUidForExcept.length() > 0) {
- //JSONObject exceptValueJson = new JSONObject();
- //exceptValueJson.put("BASE", objectUidForExcept);
- urlQueries.put("except[BASE][]", objectUidForExcept);
- objectUidForExcept = null;
-
- }
-
- if (objectUidForOnly != null && objectUidForOnly.length() > 0) {
- //JSONObject onlyValueJson = new JSONObject();
- //onlyValueJson.put("BASE", objectUidForOnly);
- urlQueries.put("only[BASE][]", objectUidForOnly);
- objectUidForOnly = null;
-
- }
-
- if (onlyJsonObject != null && onlyJsonObject.length() > 0) {
- urlQueries.put("only", onlyJsonObject);
- onlyJsonObject = null;
- }
-
- if (exceptJsonObject != null && exceptJsonObject.length() > 0) {
- urlQueries.put("except", exceptJsonObject);
- exceptJsonObject = null;
- }
-
- if (objectUidForInclude != null && objectUidForInclude.length() > 0) {
- urlQueries.put("include[]", objectUidForInclude);
- objectUidForInclude = null;
- }
-
- } catch (Exception e) {
- throwException("find", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ protected void setQueryJson() {
+ if (queryValueJSON != null && queryValueJSON.length() > 0) {
+ urlQueries.put(QUERY, queryValueJSON);
+ }
+ if (objectUidForExcept != null && objectUidForExcept.length() > 0) {
+ urlQueries.put("except[BASE][]", objectUidForExcept);
+ objectUidForExcept = null;
+ }
+ if (objectUidForOnly != null && objectUidForOnly.length() > 0) {
+ urlQueries.put("only[BASE][]", objectUidForOnly);
+ objectUidForOnly = null;
+ }
+ if (onlyJsonObject != null && onlyJsonObject.length() > 0) {
+ urlQueries.put("only", onlyJsonObject);
+ onlyJsonObject = null;
+ }
+ if (exceptJsonObject != null && exceptJsonObject.length() > 0) {
+ urlQueries.put(EXCEPT, exceptJsonObject);
+ exceptJsonObject = null;
+ }
+ if (objectUidForInclude != null && objectUidForInclude.length() > 0) {
+ urlQueries.put("include[]", objectUidForInclude);
+ objectUidForInclude = null;
}
}
-
- protected void execQuery(SingleQueryResultCallback callBack, QueryResultsCallBack callback, boolean isFromLocal) {
+ protected void execQuery(SingleQueryResultCallback callBack, QueryResultsCallBack callback) {
try {
-
- String URL = "/" + contentTypeInstance.stackInstance.VERSION + "/content_types/" + formName + "/entries";
+ String urlString = "content_types/" + contentTypeUid + "/entries";
queryResultCallback = callback;
singleQueryResultCallback = callBack;
- setQueryJson(callback);
- LinkedHashMap headers = getHeader(localHeader);
- if (headers.size() < 1) {
- throwException("find", CSAppConstants.ErrorMessage_CalledDefaultMethod, null);
- } else {
- if (headers.containsKey("environment")) {
- urlQueries.put("environment", headers.get("environment"));
- }
- mainJSON.put("query", urlQueries);
- mainJSON.put("_method", CSAppConstants.RequestMethod.GET.toString());
- fetchFromNetwork(URL, headers, mainJSON, callback, callBack);
- }
-
-
+ setQueryJson();
+ urlQueries.put(Constants.ENVIRONMENT, this.headers.get(Constants.ENVIRONMENT));
+ includeLivePreview();
+ mainJSON.put(QUERY, urlQueries);
+ fetchFromNetwork(urlString, mainJSON, callback, callBack);
} catch (Exception e) {
logger.severe(e.getLocalizedMessage());
- throwException("find", CSAppConstants.ErrorMessage_QueryFilterException, e);
+ throwException("find", Constants.QUERY_EXCEPTION, e);
}
}
+ private void includeLivePreview() {
+ Config configInstance = contentTypeInstance.stackInstance.config;
+ if (configInstance.enableLivePreview
+ && configInstance.livePreviewContentType.equalsIgnoreCase(contentTypeUid)) {
+ configInstance.setHost(configInstance.livePreviewHost); // Check host and replace with new host
+ this.headers.remove("access_token");
+ urlQueries.remove(Constants.ENVIRONMENT);
+ this.headers.remove(Constants.ENVIRONMENT);
+ if (configInstance.livePreviewHash == null || configInstance.livePreviewHash.isEmpty()) {
+ configInstance.livePreviewHash = "init";
+ }
+ this.headers.put("live_preview", configInstance.livePreviewHash);
+ this.headers.put("authorization", configInstance.managementToken);
+ }
+ }
- //fetch from network.
- private void fetchFromNetwork(String URL, LinkedHashMap headers, JSONObject jsonMain, ResultCallBack callback, SingleQueryResultCallback resultCallback) {
+ // fetch from network.
+ private void fetchFromNetwork(String urlString, JSONObject jsonMain, ResultCallBack callback,
+ SingleQueryResultCallback resultCallback) {
LinkedHashMap urlParams = getUrlParams(jsonMain);
if (resultCallback != null) {
- new CSBackgroundTask(this, contentTypeInstance.stackInstance, CSController.SINGLEQUERYOBJECT, URL, headers, urlParams, new JSONObject(), CSAppConstants.callController.QUERY.toString(), CSAppConstants.RequestMethod.GET, resultCallback);
+ new CSBackgroundTask(this, contentTypeInstance.stackInstance, Constants.SINGLEQUERYOBJECT, urlString,
+ this.headers, urlParams, Constants.REQUEST_CONTROLLER.QUERY.toString(), resultCallback);
} else {
- new CSBackgroundTask(this, contentTypeInstance.stackInstance, CSController.QUERYOBJECT, URL, headers, urlParams, new JSONObject(), CSAppConstants.callController.QUERY.toString(), CSAppConstants.RequestMethod.GET, callback);
+ new CSBackgroundTask(this, contentTypeInstance.stackInstance, Constants.QUERYOBJECT, urlString,
+ this.headers, urlParams, Constants.REQUEST_CONTROLLER.QUERY.toString(), callback);
}
}
-
private LinkedHashMap getUrlParams(JSONObject jsonMain) {
-
- JSONObject queryJSON = jsonMain.optJSONObject("query");
LinkedHashMap hashMap = new LinkedHashMap<>();
+ JSONObject queryJSON = jsonMain.optJSONObject(QUERY);
if (queryJSON != null && queryJSON.length() > 0) {
Iterator iter = queryJSON.keys();
while (iter.hasNext()) {
String key = iter.next();
- try {
- Object value = queryJSON.opt(key);
- hashMap.put(key, value);
- } catch (Exception e) {
- logger.severe(e.getLocalizedMessage());
- }
+ Object value = queryJSON.opt(key);
+ hashMap.put(key, value);
}
- return hashMap;
}
-
- return null;
+ return hashMap;
}
-
@Override
public void getResult(Object object, String controller) {
-
+ // It would not be called.
}
@Override
@@ -1542,30 +1271,22 @@ public void getResultObject(List objects, JSONObject jsonObject, boolean
for (int i = 0; i < countObject; i++) {
Entry entry = null;
try {
- entry = contentTypeInstance.stackInstance.contentType(formName).entry(((EntryModel) objects.get(i)).entryUid);
+ entry = contentTypeInstance.stackInstance.contentType(contentTypeUid)
+ .entry(((EntryModel) objects.get(i)).uid);
} catch (Exception e) {
- entry = new Entry(formName);
+ entry = new Entry(contentTypeUid);
}
- entry.setUid(((EntryModel) objects.get(i)).entryUid);
+ entry.setUid(((EntryModel) objects.get(i)).uid);
entry.resultJson = ((EntryModel) objects.get(i)).jsonObject;
- entry.ownerEmailId = ((EntryModel) objects.get(i)).ownerEmailId;
- entry.ownerUid = ((EntryModel) objects.get(i)).ownerUid;
entry.title = ((EntryModel) objects.get(i)).title;
entry.url = ((EntryModel) objects.get(i)).url;
-
- if (((EntryModel) objects.get(i)).ownerMap != null) {
- entry.owner = new HashMap<>(((EntryModel) objects.get(i)).ownerMap);
- }
- if (((EntryModel) objects.get(i))._metadata != null) {
- entry._metadata = new HashMap<>(((EntryModel) objects.get(i))._metadata);
- }
entry.setTags(((EntryModel) objects.get(i)).tags);
objectList.add(entry);
}
if (isSingleEntry) {
Entry entry = contentTypeInstance.entry();
- if (objectList != null && objectList.size() > 0) {
+ if (!objectList.isEmpty()) {
entry = objectList.get(0);
}
if (singleQueryResultCallback != null) {
@@ -1581,166 +1302,125 @@ public void getResultObject(List objects, JSONObject jsonObject, boolean
}
-
- private LinkedHashMap getHeader(LinkedHashMap localHeader) {
- LinkedHashMap mainHeader = formHeader;
- LinkedHashMap classHeaders = new LinkedHashMap<>();
-
- if (localHeader != null && localHeader.size() > 0) {
- if (mainHeader != null && mainHeader.size() > 0) {
- for (Map.Entry entry : localHeader.entrySet()) {
- String key = entry.getKey();
- classHeaders.put(key, entry.getValue());
- }
-
- for (Map.Entry entry : mainHeader.entrySet()) {
- String key = entry.getKey();
- if (!classHeaders.containsKey(key)) {
- classHeaders.put(key, entry.getValue());
- }
- }
- return classHeaders;
- } else {
- return localHeader;
- }
-
- } else {
- return formHeader;
- }
- }
-
-
/**
- * This method adds key and value to an Entry.
- * Parameters:
+ * This method adds key and value to an Entry. Parameters:
*
- * @param key: The key as string which needs to be added to the Query
- * @param value: 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 :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.addParam("key", "some_value");
- * csQuery.findOne(new QueryResultsCallBack() {
- * @Override
- * public void onCompletion(ResponseType responseType, ENTRY entry, Error error) {
- * }
- * });
- *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.addParam("key", "some_value");
+ * csQuery.findOne(new QueryResultsCallBack() {
+ * @Override
+ * public void onCompletion(ResponseType responseType, ENTRY entry, Error error) {
+ * }
+ * });
+ *
*/
- public Query addParam(String key, String value) {
- try {
- if (key != null) {
- urlQueries.put(key, value == null ? JSONObject.NULL : value);
- } else {
- throwException("and", CSAppConstants.ErrorMessage_QueryFilterException, null);
- }
- } catch (Exception e) {
- throwException("and", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
+ public Query addParam(@NotNull String paramKey, @NotNull String paramValue) {
+ urlQueries.put(paramKey, paramValue);
return this;
}
-
/**
- * This method also includes the content type UIDs of the referenced entries returned in the response
- * @return {@link Query}
- * Example :
- *
- * //'blt5d4sample2633b' is a dummy Stack API key
- * //'blt6d0240b5sample254090d' is dummy access token.
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.includeReferenceContentTypUid();
- * csQuery.findOne(new QueryResultsCallBack() {
+ * This method also includes the content type UIDs of the referenced entries
+ * returned in the response
+ *
+ * @return {@link Query}
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.includeReferenceContentTypUid();
+ * csQuery.findOne(new QueryResultsCallBack() {
* @Override
* public void onCompletion(ResponseType responseType, ENTRY entry, Error error) {
* }
* });
- *
+ *
*/
public Query includeReferenceContentTypUid() {
- try {
- urlQueries.put("include_reference_content_type_uid", "true");
- } catch (JSONException e) {
- logger.severe(e.getLocalizedMessage());
- }
+ urlQueries.put("include_reference_content_type_uid", "true");
return this;
}
-
/**
- * 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 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 :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.whereIn("due_date", csQuery);
- *
+ * @return {@link Query} object, so you can chain this call
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.whereIn("due_date", csQuery);
+ *
*/
- public Query whereIn(String key, Query queryObject) {
- if (key != null) {
- try {
- JSONObject inQueryObj = new JSONObject();
- inQueryObj.put("$in_query", queryObject.queryValueJSON.toString());
- queryValueJSON.put(key, inQueryObj);
- } catch (Exception e) {
- throwException("in_query", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
- } else {
- throwException("in_query", CSAppConstants.ErrorMessage_QueryFilterException, null);
- }
+ public Query whereIn(@NotNull String key, Query queryObject) {
+ JSONObject inQueryObj = new JSONObject();
+ inQueryObj.put("$in_query", queryObject.queryValueJSON.toString());
+ queryValueJSON.put(key, inQueryObj);
return this;
}
-
/**
- * 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
* @return {@link Query} object, so you can chain this call
*
- * Example :
- *
- * Stack stack = Contentstack.stack( "APIKey", "deliveryToken", "environment_name");
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.whereNotIn("due_date", csQuery);
- *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.whereNotIn("due_date", csQuery);
+ *
*/
- public Query whereNotIn(String key, Query queryObject) {
-
- if (key != null) {
- try {
- JSONObject inQueryObj = new JSONObject();
- inQueryObj.put("$nin_query", queryObject.queryValueJSON.toString());
- queryValueJSON.put(key, inQueryObj);
- } catch (Exception e) {
- throwException("nin_query", CSAppConstants.ErrorMessage_QueryFilterException, e);
- }
- } else {
- throwException("nin_query", CSAppConstants.ErrorMessage_QueryFilterException, null);
- }
+ public Query whereNotIn(@NotNull String key, Query queryObject) {
+ JSONObject inQueryObj = new JSONObject();
+ inQueryObj.put("$nin_query", queryObject.queryValueJSON.toString());
+ queryValueJSON.put(key, inQueryObj);
return this;
}
-
/**
- * 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 :
- *
- * Stack stack = Contentstack.stack( "ApiKey", "deliveryToken", environment_name);
- * Query csQuery = stack.contentType("contentType_name").query();
- * csQuery.includeFallback();
- *
+ * 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 :
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", environment);
+ * Query csQuery = stack.contentType("contentTypeUid").query();
+ * csQuery.includeFallback();
+ *
*/
public Query includeFallback() {
urlQueries.put("include_fallback", true);
@@ -1748,17 +1428,44 @@ public Query includeFallback() {
}
/**
- * includeEmbeddedItems instance of Query
- * Include Embedded Objects (Entries and Assets) along with entry/entries details.
- * Stack stack = Contentstack.stack( "ApiKey", "deliveryToken", "environment");
- * final Query query = stack.contentType("user").query();
- * query = query.includeEmbeddedObjects()
+ * @return {@link Query} object, so you can chain this call.
+ *
+ *
* @return {@link Query}
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", environment);
+ * Query query = stack.contentType("contentTypeUid").query();
+ * query.includeEmbeddedObjects()
+ *
*/
public Query includeEmbeddedItems() {
urlQueries.put("include_embedded_items[]", "BASE");
return this;
}
-}
+ /**
+ * Includes Branch in the entry response
+ *
+ * @return {@link Query} object, so you can chain this call.
+ *
+ *
+ *
+ * Example :
+ *
+ *
+ * Stack stack = Contentstack.stack("apiKey", "deliveryToken", "environment");
+ * Query query = stack.contentType("contentTypeUid").query();
+ * entry.includeBranch();
+ *
+ */
+ public Query includeBranch() {
+ urlQueries.put("include_branch", true);
+ return this;
+ }
+}
diff --git a/src/main/java/com/contentstack/sdk/QueryResult.java b/src/main/java/com/contentstack/sdk/QueryResult.java
index c7c06def..0cf50919 100644
--- a/src/main/java/com/contentstack/sdk/QueryResult.java
+++ b/src/main/java/com/contentstack/sdk/QueryResult.java
@@ -6,96 +6,90 @@
import java.util.List;
import java.util.logging.Logger;
-/**
- * It results the query response
- */
-
public class QueryResult {
-
- private static final Logger logger = Logger.getLogger(QueryResult.class.getSimpleName());
+ private final Logger logger = Logger.getLogger(QueryResult.class.getSimpleName());
protected JSONObject receiveJson;
protected JSONArray schemaArray;
protected JSONObject contentObject;
protected int count;
protected List resultObjects;
-
/**
- * @return List of {@link Entry} objects list.
- * Example :
- *
+ * @return List of {@link Entry} objects list.
+ *
+ * Example :
+ *
+ *
* List<Entry> list = queryResultObject.getResultObjects();
- *
+ *
*/
public List getResultObjects() {
return resultObjects;
}
-
/**
* Returns count of objects available.
- * Note :
- * To retrieve this data, {@link Query#includeCount()} or {@link Query#count()}
- * should be added in {@link Query} while querying.
+ * Note : To retrieve this data, {@link Query#includeCount()} or
+ * {@link Query#count()} should be added in {@link Query} while querying.
*
- * @return int count
- * Example :
- *
+ * @return int count
+ *
+ * Example :
+ *
+ *
* int count = queryResultObject.getCount();
- *
+ *
*/
public int getCount() {
return count;
}
-
/**
* Returns class's schema if call to fetch schema executed successfully.
*
- * @return JSONArray schema Array
- * Example :
- *
+ * @return JSONArray schema Array
+ *
+ * Example :
+ *
+ *
* JSONArray schemaArray = queryResultObject.getSchema();
- *
+ *
*/
public JSONArray getSchema() {
return schemaArray;
}
-
/**
- * Returns class's content type if call to fetch contentType executed successfully.
+ * Returns class's content type if call to fetch contentType executed
+ * successfully.
*
- * @return JSONObject contentObject
- * Example :
- *
+ * @return JSONObject contentObject
+ *
+ * Example :
+ *
+ *
* JSONObject contentObject = queryResultObject.getContentType();
- *
+ *
*/
public JSONObject getContentType() {
return contentObject;
}
-
protected void setJSON(JSONObject jsonobject, List objectList) {
receiveJson = jsonobject;
resultObjects = objectList;
-
try {
if (receiveJson != null) {
if (receiveJson.has("schema")) {
-
- JSONArray jsonarray = new JSONArray();
- jsonarray = receiveJson.getJSONArray("schema");
+ JSONArray jsonarray = receiveJson.getJSONArray("schema");
if (jsonarray != null) {
schemaArray = jsonarray;
}
}
if (receiveJson.has("content_type")) {
-
JSONObject jsonObject = receiveJson.getJSONObject("content_type");
if (jsonObject != null) {
contentObject = jsonObject;
@@ -106,7 +100,7 @@ protected void setJSON(JSONObject jsonobject, List objectList) {
count = receiveJson.optInt("count");
}
- if (count <= 0) {
+ if (count == 0) {
if (receiveJson.has("entries")) {
count = receiveJson.optInt("entries");
}
@@ -118,5 +112,4 @@ protected void setJSON(JSONObject jsonobject, List objectList) {
}
}
-
}
diff --git a/src/main/java/com/contentstack/sdk/QueryResultsCallBack.java b/src/main/java/com/contentstack/sdk/QueryResultsCallBack.java
index 22599622..5d8c3ac1 100644
--- a/src/main/java/com/contentstack/sdk/QueryResultsCallBack.java
+++ b/src/main/java/com/contentstack/sdk/QueryResultsCallBack.java
@@ -1,7 +1,6 @@
package com.contentstack.sdk;
-
-public abstract class QueryResultsCallBack extends ResultCallBack {
+public abstract class QueryResultsCallBack implements ResultCallBack {
public abstract void onCompletion(ResponseType responseType, QueryResult queryresult, Error error);
@@ -10,14 +9,8 @@ void onRequestFinish(ResponseType responseType, QueryResult queryResultObject) {
}
@Override
- void onRequestFail(ResponseType responseType, Error error) {
+ public void onRequestFail(ResponseType responseType, Error error) {
onCompletion(responseType, null, error);
}
- @Override
- public void always() {
-
- }
-
-
}
diff --git a/src/main/java/com/contentstack/sdk/ResultCallBack.java b/src/main/java/com/contentstack/sdk/ResultCallBack.java
index 50c14ad8..189fbbb7 100644
--- a/src/main/java/com/contentstack/sdk/ResultCallBack.java
+++ b/src/main/java/com/contentstack/sdk/ResultCallBack.java
@@ -1,8 +1,5 @@
package com.contentstack.sdk;
-public abstract class ResultCallBack {
-
- abstract void onRequestFail(ResponseType responseType, Error error);
-
- public abstract void always();
-}
+public interface ResultCallBack {
+ void onRequestFail(ResponseType responseType, Error error);
+}
\ No newline at end of file
diff --git a/src/main/java/com/contentstack/sdk/SingleQueryResultCallback.java b/src/main/java/com/contentstack/sdk/SingleQueryResultCallback.java
index 3587e80e..14bb4cc1 100644
--- a/src/main/java/com/contentstack/sdk/SingleQueryResultCallback.java
+++ b/src/main/java/com/contentstack/sdk/SingleQueryResultCallback.java
@@ -1,6 +1,6 @@
package com.contentstack.sdk;
-public abstract class SingleQueryResultCallback extends ResultCallBack {
+public abstract class SingleQueryResultCallback implements ResultCallBack {
public abstract void onCompletion(ResponseType responseType, Entry entry, Error error);
@@ -9,15 +9,8 @@ void onRequestFinish(ResponseType responseType, Entry entry) {
}
@Override
- void onRequestFail(ResponseType responseType, Error error) {
+ public void onRequestFail(ResponseType responseType, Error error) {
onCompletion(responseType, null, error);
}
- @Override
- public void always() {
-
- }
-
-
}
-
diff --git a/src/main/java/com/contentstack/sdk/Stack.java b/src/main/java/com/contentstack/sdk/Stack.java
index fdc9e2f8..1fd5e871 100644
--- a/src/main/java/com/contentstack/sdk/Stack.java
+++ b/src/main/java/com/contentstack/sdk/Stack.java
@@ -1,723 +1,542 @@
package com.contentstack.sdk;
-import com.contentstack.sdk.utility.CSAppConstants;
-import com.contentstack.sdk.utility.CSController;
-import org.json.JSONException;
+
+import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.Logger;
+import java.util.stream.Collectors;
+
+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 {
- private static final Logger logger = Logger.getLogger(Stack.class.getSimpleName());
- private String stackApiKey = null;
- protected LinkedHashMap localHeader = null;
- private String imageTransformationUrl;
- private LinkedHashMap imageParams = new LinkedHashMap<>();
-
- protected String URLSCHEMA = "https://";
- protected String URL = "cdn.contentstack.io";
- protected String VERSION = "v3";
+ private final Logger logger = Logger.getLogger(Stack.class.getSimpleName());
+ protected LinkedHashMap headers;
protected Config config;
- protected String SYNC_KEY = "sync";
- protected String content_type;
-
- private JSONObject syncParams = null;
- protected String sync_token = null;
- protected String pagination_token = null;
protected String contentType;
- protected String localeCode ;
- protected PublishType publishType;
- protected String start_from_date;
- private SyncResultCallBack syncCallBack;
- protected HashMap headerGroup_app;
-
- private Stack(){ }
-
-
- public static enum PublishType
- {
- entry_published,
- entry_unpublished ,
- entry_deleted ,
- asset_published ,
- asset_unpublished ,
- asset_deleted ,
- content_type_deleted
- }
+ protected String apiKey;
+ protected JSONObject syncParams = null;
-
- protected Stack(String stackApiKey) {
- this.stackApiKey = stackApiKey;
- this.localHeader = new LinkedHashMap<>();
+ protected Stack() throws IllegalAccessException {
+ throw new IllegalAccessException("Can Not Access Private Modifier");
}
- protected void setConfig(Config config){
- this.config = config;
- URLSCHEMA = config.URLSCHEMA;
- URL = config.URL;
- VERSION = config.VERSION;
-
- if(!config.environment.isEmpty()){
- setHeader("environment", config.environment);
- }
+ protected Stack(@NotNull String apiKey) {
+ this.apiKey = apiKey;
+ this.headers = new LinkedHashMap<>();
+ }
- if (!config.region.name().isEmpty()){
+ protected void setConfig(Config config) {
+ this.config = config;
+ String urlDomain = config.host;
+ if (!config.region.name().isEmpty()) {
String region = config.region.name().toLowerCase();
- if (!region.equalsIgnoreCase("us")){
- if(URL.equalsIgnoreCase("cdn.contentstack.io")) {
- URL = "cdn.contentstack.com";
+ if (!region.equalsIgnoreCase("us")) {
+ if (urlDomain.equalsIgnoreCase("cdn.contentstack.io")) {
+ urlDomain = "cdn.contentstack.com";
}
- URL = region+"-"+URL;
+ config.host = region + "-" + urlDomain;
}
}
+ includeLivePreview();
+ // Set the endpoint
+ String endpoint = config.scheme + config.host;
+ this.config.setEndpoint(endpoint);
}
+ private void includeLivePreview() {
+ try {
+ if (config.enableLivePreview) {
+ if (config.managementToken == null || config.managementToken.isEmpty()) {
+ throw new IllegalAccessException("managementToken is required");
+ }
+ if (config.livePreviewHost == null || config.livePreviewHost.isEmpty()) {
+ throw new IllegalAccessException("host is required");
+ }
+ config.host = config.livePreviewHost;
+ }
+ } catch (Exception e) {
+ String info = "To enable live preview, managementToken and host are required";
+ logger.warning(info);
+ throw new IllegalArgumentException(e.getLocalizedMessage());
+ }
+ }
- public ContentType contentType(String contentTypeName){
- this.content_type = contentType;
- ContentType contentType = new ContentType(contentTypeName);
- contentType.setStackInstance(this);
- return contentType;
+ /**
+ * 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.
+ *
+ *
+ * @param query the query of type {@link HashMap}
+ * @return stack
+ *
+ * Example
+ *
+ *
+ * stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
+ *
+ * HashMap queryMap = new HashMap();
+ *
+ * stack.livePreviewQuery(queryMap)
+ *
+ */
+ public Stack livePreviewQuery(Map query) {
+ if (this.config.enableLivePreview) {
+ config.livePreviewHash = query.get("live_preview");
+ config.livePreviewContentType = query.get(CONTENT_TYPE_UID);
+ }
+ return this;
}
+ /**
+ * 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.
+ * @return the {@link ContentType}
+ *
+ * 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
+ ContentType ct = new ContentType(contentTypeUid);
+ ct.setStackInstance(this);
+ return ct;
+ }
/**
- * Takes asset uid as a parameter and returns @{@link Asset} instance
+ * 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 Asset instance
+ * @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(String uid){
+ public Asset asset(@NotNull String uid) {
Asset asset = new Asset(uid);
asset.setStackInstance(this);
return asset;
}
-
-
- protected Asset asset(){
+ protected Asset asset() {
Asset asset = new Asset();
asset.setStackInstance(this);
return asset;
}
/**
- * assetLibrary returns AssetLibrary instance
- * @return AssetLibrary
+ * 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
+ *
+ *
+ * Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
+ * AssetLibrary assets = stack.assetLibrary();
+ *
*/
- public AssetLibrary assetLibrary(){
+ public AssetLibrary assetLibrary() {
AssetLibrary library = new AssetLibrary();
library.setStackInstance(this);
return library;
}
-
/**
* Returns apiKey of particular stack
- * @return stack api key
+ *
+ * @return {@link Stack} apiKey
*/
- public String getApplicationKey(){ return stackApiKey;}
-
+ public String getApplicationKey() {
+ return apiKey;
+ }
/**
- * Returns accessToken of particular stack
- * @return access token of particular stack
+ * @deprecated accessToken of particular stack
+ *
+ * @return {@link Stack} accessToken
*/
- public String getAccessToken(){ return localHeader != null ? (String)localHeader.get("access_token") : null;};
-
+ @Deprecated
+ public String getAccessToken() {
+ return (String) headers.get("access_token");
+ }
/**
- * Removes Header by key
- * @param key header key
- * Example :
- * stack.removeHeader("delivery_token");
- *
- *
+ * Returns deliveryToken of particular stack
+ *
+ * @return deliveryToken delivery token
*/
- public void removeHeader(String key){
- if(!key.isEmpty()){
- localHeader.remove(key);
- }
+ public String getDeliveryToken() {
+ return (String) headers.get("access_token");
}
-
/**
- * Adds header to the stack by key and value
- * @param key header key
- * @param value header value
- *
- * Example
- * stack.setHeader("delivery_token","blt843748744");
- *
+ * Removes Header by key
+ *
+ * @param headerKey of the header
+ *
+ * Example: stack.removeHeader("delivery_token");
*/
- public void setHeader(String key, String value) {
- if (!key.isEmpty() && !value.isEmpty()) {
- localHeader.put(key, value);
- }
+ public void removeHeader(String headerKey) {
+ headers.remove(headerKey);
}
-
-
/**
- * @param image_url
- * on which we want to manipulate.
- * @param parameters
- * It is an second parameter in which we want to place different manipulation key and value in array form
- * @return String
- *
- * ImageTransform function is define for image manipulation with different
- * parameters in second parameter in array form
- *
- * Example :
- *
- * //'blt5d4sample2633b' is a dummy Stack API key
- * //'blt6d0240b5sample254090d' is dummy access token.
- * Stack stack = Contentstack.stack("blt5d4sample2633b", "blt6d0240b5sample254090d", "stag", false);
- * // resize the image by specifying width and height
- * LinkedHashMap imageParams = new LinkedHashMap();
- * imageParams.put("width", 100);
- * imageParams.put("height",100);
- * imageUrl = Stack.ImageTransform(image_url, parameters);
- * stack.ImageTransform(image_url, parameters);
- *
+ * Adds header to the stack
*
+ * @param headerKey the header key
+ * @param headerValue the header value
*/
- public String ImageTransform(String image_url, LinkedHashMap parameters) {
- imageTransformationUrl = image_url;
- imageParams = parameters;
- return getImageUrl();
- }
-
-
-
- private String getImageUrl() {
-
- if (imageParams == null || imageParams.size() == 0) {
- return imageTransformationUrl;
+ public void setHeader(@NotNull String headerKey, @NotNull String headerValue) {
+ if (!headerKey.isEmpty() && !headerValue.isEmpty()) {
+ headers.put(headerKey, headerValue);
}
-
- imageParams.forEach((key, value) -> {
-
- try {
- final String encodedKey = URLEncoder.encode(key.toString(), "UTF-8");
- final String encodedValue = URLEncoder.encode(value.toString(), "UTF-8");
- if (!imageTransformationUrl.contains("?")) {
- imageTransformationUrl += "?" + encodedKey + "=" + encodedValue;
- } else {
- imageTransformationUrl += "&" + encodedKey + "=" + encodedValue;
- }
-
- } catch (UnsupportedEncodingException e) {
- logger.severe(e.getLocalizedMessage());
- }
- });
-
- return imageTransformationUrl;
}
-
-
-
-
-
/**
- * @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.
- *
- * Example :
- *
- *
- * JSONObject params = new JSONObject();
- * params.put("include_snippet_schema", true);
- * params.put("limit", 3);
- * stack.getContentTypes(new ContentTypesCallback() {
- * public void onCompletion(ContentTypesModel contentTypesModel, Error error) {
- * if (error == null){
- * // do your stuff.
- * }
- * }
- * });
- *
+ * 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 void getContentTypes(JSONObject params, final ContentTypesCallback callback) {
-
- try {
- String URL = "/" + this.VERSION + "/content_types";
- HashMap headers = getHeader(localHeader);
- if (params == null){ params = new JSONObject(); }
-
- Iterator keys = params.keys();
- while(keys.hasNext()) {
- // loop to get the dynamic key
- String key = (String)keys.next();
- // get the value of the dynamic key
- Object value = params.opt(key);
- // do something here with the value...
- params.put(key, value);
- }
-
- if (headers.containsKey("environment")) {
- params.put("environment", headers.get("environment"));
- params.put("include_count", true);
- }
-
- fetchContentTypes(URL, params, headers, callback );
-
- }catch (Exception e){
-
- Error error = new Error();
- error.setErrorMessage(CSAppConstants.ErrorMessage_JsonNotProper);
- callback.onRequestFail(ResponseType.UNKNOWN, error);
+ public String imageTransform(@NotNull String imageUrl, @NotNull Map parameters) {
+ if (parameters.size() == 0) {
+ return imageUrl;
+ }
+ String query = getQueryParam(parameters);
+ if (imageUrl.contains("?")) {
+ imageUrl += "&" + query;
+ } else {
+ imageUrl += "?" + query;
}
+ return imageUrl;
}
-
-
-
-
+ protected String getQueryParam(Map params) {
+ return params.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()).collect(Collectors.joining("&"));
+ }
/**
- * @param syncCallBack returns callback for sync result.
- * 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 updates later.
- *
- * Example :
- *
+ * The Get all content types call returns comprehensive information of all the
+ * content types available in a particular stack in your account..
*
- * stack.sync(SyncResultCallBack syncCallBack){ }
- *
- *
+ * @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 sync(SyncResultCallBack syncCallBack){
-
- if (syncParams == null){
- syncParams = new JSONObject();
+ public void getContentTypes(@NotNull JSONObject params, final ContentTypesCallback callback) {
+ Iterator keys = params.keys();
+ while (keys.hasNext()) {
+ String key = keys.next();
+ Object value = params.opt(key);
+ params.put(key, value);
}
- try {
- syncParams.put("init", true);
- } catch (JSONException e) {
- logger.severe(e.getLocalizedMessage());
+ if (this.headers.containsKey(ENVIRONMENT)) {
+ params.put(ENVIRONMENT, this.headers.get(ENVIRONMENT));
+ params.put("include_count", true);
}
-
- this.requestSync(syncCallBack);
-
+ fetchContentTypes("content_types", params, this.headers, callback);
}
-
-
/**
+ * 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 pagination_token If the response is paginated, use the pagination token under this parameter.
- * @param syncCallBack returns callback for sync result
- *
- * If the result of the initial sync (or subsequent sync) contains more than 100 records,
- * the response would be paginated. It provides pagination token in the response. However,
- * you do not have to use the pagination token manually to get the next batch,
- * the SDK does that automatically until the sync is complete.
- * Pagination token can be used in case you want to fetch only selected batches.
- * It is especially useful if the sync process is interrupted midway (due to network issues, etc.).
- * In such cases, this token can be used to restart the sync process from where it was interrupted.
- *
- * Example :
- *
- *
- * // dummy pagination_token = "blt7f35951d259183fba680e1";
- * stack.syncPaginationToken(pagination_token, new SyncResultCallBack()) {}
- *
+ * @param syncCallBack returns callback for sync result.
*
- *
*/
- public void syncPaginationToken(String pagination_token, SyncResultCallBack syncCallBack){
- this.pagination_token = pagination_token;
- if (syncParams == null){
- syncParams = new JSONObject();
- }
-
- try {
- syncParams.put("init", true);
- syncParams.put("pagination_token", pagination_token);
- } catch (JSONException e) {
- logger.severe(e.getLocalizedMessage());
- }
-
+ public void sync(SyncResultCallBack syncCallBack) {
+ syncParams = new JSONObject();
+ syncParams.put("init", true);
this.requestSync(syncCallBack);
}
-
-
-
/**
- * @param sync_token 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.
- *
+ * 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 :
*
- * Example :
- *
- *
- * //dummy sync_token = "blt28937206743728463";
- * stack.syncToken(sync_token, new SyncResultCallBack() ){ }
- *
- *
*/
- public void syncToken(String sync_token, SyncResultCallBack syncCallBack){
-
- this.sync_token = sync_token;
- if (syncParams == null){
- syncParams = new JSONObject();
- }
- try {
- syncParams.put("init", true);
- syncParams.put("sync_token", sync_token);
- } catch (JSONException e) {
- logger.severe(e.getLocalizedMessage());
- }
-
+ public void syncPaginationToken(@NotNull String paginationToken, SyncResultCallBack syncCallBack) {
+ this.sync(null);
+ syncParams.put("pagination_token", paginationToken);
this.requestSync(syncCallBack);
}
-
-
-
-
-
-
-
/**
- * @param from_date 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 :
- *
- *
- * // dummy date final Date start_date = sdf.parse("2018-10-07");
- * stack.syncFromDate(start_date, new SyncResultCallBack()) { }
+ * 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() ){ }
+ *
*/
- public void syncFromDate(Date from_date, SyncResultCallBack syncCallBack){
- start_from_date = convertUTCToISO(from_date);
- if (syncParams == null){
- syncParams = new JSONObject();
- }
-
- try {
- syncParams.put("init", true);
- syncParams.put("start_from", start_from_date);
- } catch (JSONException e) {
- logger.severe(e.getLocalizedMessage());
- }
+ public void syncToken(String syncToken, SyncResultCallBack syncCallBack) {
+ this.sync(null);
+ syncParams.put("sync_token", syncToken);
this.requestSync(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 :
+ *
+ *
+ * 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);
+ this.sync(null);
+ syncParams.put("start_from", newFromDate);
+ this.requestSync(syncCallBack);
+ }
-
-
- private String convertUTCToISO(Date date) {
-
+ protected String convertUTCToISO(Date date) {
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
dateFormat.setTimeZone(tz);
return dateFormat.format(date);
}
-
-
/**
+ * Sync content type.
*
- * @param content_type Provide uid of your content_type
+ * @param contentType Provide uid of your content_type
* @param syncCallBack Returns callback for sync result.
- *
- * You can also initialize sync with entries of only specific content_type.
- * To do this, use syncContentType and specify the content type uid as its value.
- * However, if you do this, the subsequent syncs will only include the entries of the specified content_type.
- *
- * Example :
- *
- *
- * // dummy content_type like "session"
- * stack.syncContentType(String content_type, new SyncResultCallBack()){ }
- *
- *
+ *
+ * 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(String content_type, SyncResultCallBack syncCallBack){
-
- this.contentType = content_type;
- if (syncParams == null){
- syncParams = new JSONObject();
- }
- try {
- syncParams.put("init", true);
- syncParams.put("content_type_uid", contentType);
- } catch (JSONException e) {
- logger.severe(e.getLocalizedMessage());
- }
-
+ public void syncContentType(@NotNull String contentType, SyncResultCallBack syncCallBack) {
+ this.sync(null);
+ syncParams.put(CONTENT_TYPE_UID, contentType);
this.requestSync(syncCallBack);
}
-
-
-
-
/**
- * @param language Select the required locale from the Language class.
- * @param syncCallBack Returns callback for sync result.
+ * Sync locale.
*
- * 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.
+ * @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 :
*
- * Example :
- *
*
- * // dummy language- Language.ENGLISH_UNITED_STATES
- * stackInstance.syncLocale(Language.ENGLISH_UNITED_STATES, new SyncResultCallBack() ) { }
*
- *
*/
- public void syncLocale(Language language, SyncResultCallBack syncCallBack) {
- this.localeCode = getLanguageCode(language);
-
- if (syncParams == null) {
- syncParams = new JSONObject();
- }
- try {
- syncParams.put("init", true);
- syncParams.put("locale", localeCode);
- } catch (JSONException e) {
- logger.severe(e.getLocalizedMessage());
- }
-
-
+ public void syncLocale(String localeCode, SyncResultCallBack syncCallBack) {
+ this.sync(null);
+ syncParams.put("locale", localeCode);
this.requestSync(syncCallBack);
}
-
-
- private String getLanguageCode(Language language){
-
- String localeCode = null;
- if (language != null) {
-
- Language languageName = Language.valueOf(language.name());
- int localeValue = languageName.ordinal();
- LanguageCode[] languageCodeValues = LanguageCode.values();
- localeCode = languageCodeValues[localeValue].name();
- localeCode = localeCode.replace("_", "-");
- }
-
- return localeCode;
- }
-
-
-
-
-
/**
- *
- * @param type - Use the type parameter to get a specific type of content
- like ( asset_published, entry_published, asset_unpublished, asset_deleted, entry_unpublished, entry_deleted, content_type_deleted.)
- *
- *
+ * 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()) { }
- *
- *
+ *
+ * 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 type, SyncResultCallBack syncCallBack){
- this.publishType = type;
- if (syncParams == null){ syncParams = new JSONObject(); }
-
- try {
- syncParams.put("init", true);
- syncParams.put("type", publishType);
- } catch (JSONException e) {
- logger.severe(e.getLocalizedMessage());
- }
-
+ public void syncPublishType(PublishType publishType, SyncResultCallBack syncCallBack) {
+ this.sync(null);
+ syncParams.put("type", publishType.name());
this.requestSync(syncCallBack);
}
-
-
/**
+ * Sync.
*
- * @param contentType your content type id
- * @param from_date start date
- * @param language language as {@link Language}
- * @param type type as PublishType
+ * @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 :
- *
- *
- * stackInstance.sync(String contentType, Date from_date, Language language, PublishType type, SyncResultCallBack syncCallBack) { }
+ *
+ * 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 from_date, Language language, PublishType type, SyncResultCallBack syncCallBack){
- start_from_date = convertUTCToISO(from_date);
- this.contentType = contentType;
- this.publishType = type;
- this.localeCode = getLanguageCode(language);
-
- if (syncParams == null){
- syncParams = new JSONObject();
- }
- try {
- syncParams.put("init", true);
- syncParams.put("start_from", this.start_from_date);
- syncParams.put("content_type_uid", this.contentType);
- syncParams.put("type", publishType);
- syncParams.put("locale", this.localeCode);
- } catch (JSONException e) {
- logger.severe(e.getLocalizedMessage());
- }
-
+ public void sync(String contentType, Date fromDate, String localeCode, PublishType publishType,
+ SyncResultCallBack syncCallBack) {
+ String newDate = convertUTCToISO(fromDate);
+ this.sync(null);
+ syncParams.put("start_from", newDate);
+ syncParams.put("content_type_uid", contentType);
+ syncParams.put("type", publishType.name());
+ syncParams.put("locale", localeCode);
this.requestSync(syncCallBack);
}
-
-
-
-
- private void requestSync(final SyncResultCallBack callback){
-
- try {
-
- String URL = "/" + this.VERSION + "/stacks/" + SYNC_KEY;
- HashMap headers = getHeader(localHeader);
-
- JSONObject urlQueries = new JSONObject();
- if (headers.containsKey("environment")) {
- syncParams.put("environment", headers.get("environment"));
- }
-
- urlQueries = syncParams;
- fetchFromNetwork(URL, syncParams, headers, callback );
-
-
- }catch (Exception e){
-
- Error error = new Error();
- error.setErrorMessage(CSAppConstants.ErrorMessage_JsonNotProper);
- callback.onRequestFail(ResponseType.UNKNOWN, error);
+ private void requestSync(final SyncResultCallBack callback) {
+ if (this.headers.containsKey(ENVIRONMENT)) {
+ syncParams.put(ENVIRONMENT, this.headers.get(ENVIRONMENT));
}
-
+ fetchFromNetwork(SYNCHRONISATION, syncParams, this.headers, callback);
}
-
-
- private void fetchContentTypes(String urlString, JSONObject content_type_param, HashMap headers, ContentTypesCallback callback) {
-
- if(callback != null) {
-
- HashMap urlParams = getUrlParams(content_type_param);
- new CSBackgroundTask(this, CSController.FETCHCONTENTTYPES, urlString, headers, urlParams, new JSONObject(), CSAppConstants.callController.CONTENTTYPES.toString(), false, CSAppConstants.RequestMethod.GET, callback);
+ private void fetchContentTypes(String urlString, JSONObject contentTypeParam, HashMap headers,
+ ContentTypesCallback callback) {
+ if (callback != null) {
+ HashMap queryParam = getUrlParams(contentTypeParam);
+ String requestInfo = REQUEST_CONTROLLER.CONTENTTYPES.toString();
+ new CSBackgroundTask(this, Constants.FETCHCONTENTTYPES, urlString, headers, queryParam, requestInfo,
+ callback);
}
}
-
- private void fetchFromNetwork(String urlString, JSONObject urlQueries, HashMap headers, SyncResultCallBack callback) {
-
- if(callback != null) {
-
+ private void fetchFromNetwork(String urlString, JSONObject urlQueries, HashMap headers,
+ SyncResultCallBack callback) {
+ if (callback != null) {
HashMap urlParams = getUrlParams(urlQueries);
- new CSBackgroundTask(this, CSController.FETCHSYNC, urlString, headers, urlParams, new JSONObject(), CSAppConstants.callController.SYNC.toString(), false, CSAppConstants.RequestMethod.GET, callback);
+ String requestInfo = REQUEST_CONTROLLER.SYNC.toString();
+ new CSBackgroundTask(this, Constants.FETCHSYNC, urlString, headers, urlParams, requestInfo, callback);
}
}
-
- private HashMap getUrlParams(JSONObject urlQueriesJSON) {
-
+ private HashMap getUrlParams(JSONObject jsonQuery) {
HashMap hashMap = new HashMap<>();
-
- if(urlQueriesJSON != null && urlQueriesJSON.length() > 0){
- Iterator iter = urlQueriesJSON.keys();
- while (iter.hasNext()) {
- String key = iter.next();
- try {
- Object value = urlQueriesJSON.opt(key);
- hashMap.put(key, value);
- } catch (Exception e) {
- logger.severe(e.getLocalizedMessage());
- }
+ if (jsonQuery != null && jsonQuery.length() > 0) {
+ Iterator iteString = jsonQuery.keys();
+ while (iteString.hasNext()) {
+ String key = iteString.next();
+ Object value = jsonQuery.opt(key);
+ hashMap.put(key, value);
}
-
- return hashMap;
}
-
- return null;
+ return hashMap;
}
-
- private HashMap getHeader(HashMap localHeader) {
-
- HashMap mainHeader = headerGroup_app;
- HashMap classHeaders = new HashMap<>();
-
- if(localHeader != null && localHeader.size() > 0){
- if(mainHeader != null && mainHeader.size() > 0) {
- for (Map.Entry entry : localHeader.entrySet()) {
- String key = entry.getKey();
- classHeaders.put(key, entry.getValue());
- }
-
- for (Map.Entry