From 0cbcb2f8e6dea41c1db91e988cfacfb0e2f52972 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 13 Dec 2023 18:49:09 +0530 Subject: [PATCH 01/10] v1.12.3 - Taxonomy query support - Early Access Feature Support --- .../java/com/contentstack/sdk/APIService.java | 10 +- .../java/com/contentstack/sdk/Config.java | 3 +- .../java/com/contentstack/sdk/Constants.java | 2 + src/main/java/com/contentstack/sdk/Query.java | 218 ++++++---------- src/main/java/com/contentstack/sdk/Stack.java | 236 ++++++++---------- .../java/com/contentstack/sdk/Taxonomy.java | 125 ++++++++++ .../contentstack/sdk/TaxonomyCallback.java | 28 +++ .../com/contentstack/sdk/Credentials.java | 4 +- .../com/contentstack/sdk/TaxonomyTest.java | 73 ++++++ .../java/com/contentstack/sdk/TestAsset.java | 4 +- 10 files changed, 431 insertions(+), 272 deletions(-) create mode 100644 src/main/java/com/contentstack/sdk/Taxonomy.java create mode 100644 src/main/java/com/contentstack/sdk/TaxonomyCallback.java create mode 100644 src/test/java/com/contentstack/sdk/TaxonomyTest.java diff --git a/src/main/java/com/contentstack/sdk/APIService.java b/src/main/java/com/contentstack/sdk/APIService.java index a537f0d8..e178b7af 100644 --- a/src/main/java/com/contentstack/sdk/APIService.java +++ b/src/main/java/com/contentstack/sdk/APIService.java @@ -4,9 +4,11 @@ import retrofit2.Call; import retrofit2.http.GET; import retrofit2.http.HeaderMap; +import retrofit2.http.QueryMap; import retrofit2.http.Url; import java.util.LinkedHashMap; +import java.util.Map; /** * @author Shailesh Mishra @@ -15,5 +17,11 @@ */ public interface APIService { @GET - Call getRequest(@Url String url, @HeaderMap LinkedHashMap headers); + Call getRequest( + @Url String url, @HeaderMap LinkedHashMap headers); + + @GET("v3/taxonomies/entries") + Call getTaxonomy( + @HeaderMap Map headers, + @QueryMap(encoded = true) Map query); } diff --git a/src/main/java/com/contentstack/sdk/Config.java b/src/main/java/com/contentstack/sdk/Config.java index 7522eebc..495d0153 100644 --- a/src/main/java/com/contentstack/sdk/Config.java +++ b/src/main/java/com/contentstack/sdk/Config.java @@ -168,7 +168,8 @@ public enum ContentstackRegion { /** - * The configuration for the contentstack that contains support for Early Access Feature + * To initialize the SDK with the latest features offered in the early access phase, + * include the early access parameter as shown in the following code: * * @param earlyAccessFeatures The list of Early Access Features * {@code diff --git a/src/main/java/com/contentstack/sdk/Constants.java b/src/main/java/com/contentstack/sdk/Constants.java index 24917225..6a31923d 100644 --- a/src/main/java/com/contentstack/sdk/Constants.java +++ b/src/main/java/com/contentstack/sdk/Constants.java @@ -26,6 +26,8 @@ public class Constants { protected static final String CONTENT_TYPE_UID = "content_type_uid"; protected static final String ENTRY_UID = "entry_uid"; protected static final String LIVE_PREVIEW = "live_preview"; + + protected static final String TaxonomyPath = "/taxonomies/entries?query"; protected static final String SYNCHRONISATION = "stacks/sync"; // Errors protected static final String ERROR_CODE = "error_code"; diff --git a/src/main/java/com/contentstack/sdk/Query.java b/src/main/java/com/contentstack/sdk/Query.java index ce2c63ea..9522b626 100644 --- a/src/main/java/com/contentstack/sdk/Query.java +++ b/src/main/java/com/contentstack/sdk/Query.java @@ -63,21 +63,21 @@ protected void setContentTypeInstance(ContentType contentTypeInstance) { /** * To set headers for Built.io Contentstack rest calls.
Scope is limited to this object and followed classes. * - * @param key - * header name. - * @param value - * header value against given header name.
- * - *
- *
- * Example :
- *

- * tack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment"); Query query = - * stack.contentType("contentTypeUid").query(); query.setHeader("custom_key", "custom_value"); - * Example :
- *

- * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment"); Query csQuery = - * stack.contentType("contentTypeUid").query(); csQuery.setHeader("custom_key", "custom_value"); + * @param key header name. + * @param value header value against given header name.
+ * + *
+ *
+ * Example :
+ *

+     *                                            Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment");
+     *                                            
+ * Query query = stack.contentType("contentTypeUid").query(); query.setHeader("custom_key", "custom_value"); + *
+ * Stack stack = Contentstack.stack( "apiKey", "deliveryToken", "environment"); + *
+ * Query csQuery = stack.contentType("contentTypeUid").query();
csQuery.setHeader("custom_key", "custom_value"); + *
*/ public Query setHeader(@NotNull String key, @NotNull String value) { if (!key.isEmpty() && !value.isEmpty()) { @@ -89,12 +89,11 @@ public Query setHeader(@NotNull String key, @NotNull String value) { /** * Remove header key @param key custom_header_key * - * @param key - * {@link String} - * Example :
- *

- * Stack stack = Contentstack..stack( "apiKey", "deliveryToken", "environment"); Query csQuery = - * stack.contentType("contentTypeUid").query();
csQuery.removeHeader("custom_key"); + * @param key {@link String} + * Example :
+ *

+ * Stack stack = Contentstack..stack( "apiKey", "deliveryToken", "environment"); Query csQuery = + * stack.contentType("contentTypeUid").query();
csQuery.removeHeader("custom_key"); */ public Query removeHeader(@NotNull String key) { if (!key.isEmpty()) { @@ -110,10 +109,8 @@ public String getContentType() { /** * Add a constraint to fetch all entries that contains given value against specified key * - * @param key - * field uid. - * @param value - * field value which get 'included' from the response. + * @param key field uid. + * @param value field value which get 'included' from the response. * @return {@link Query} object, so you can chain this call. *

* Note : for group field provide key in a @@ -138,10 +135,8 @@ public Query where(@NotNull String key, Object value) { /** * Add a custom query against specified key. * - * @param key - * key. - * @param value - * value. + * @param key key. + * @param value value. * @return {@link Query} object, so you can chain this call. * *
@@ -164,8 +159,7 @@ public Query addQuery(@NotNull String key, String value) { /** * Remove provided query key from custom query if existed. * - * @param key - * Query name to remove. + * @param key Query name to remove. * @return {@linkplain Query} object, so you can chain this call.
* *
@@ -186,8 +180,7 @@ public Query removeQuery(@NotNull String key) { /** * Combines all the queries together using AND operator * - * @param queryObjects - * list of {@link Query} instances on which AND query executes. + * @param queryObjects list of {@link Query} instances on which AND query executes. * @return {@link Query} object, so you can chain this call. * *
@@ -221,8 +214,7 @@ public Query and(@NotNull List queryObjects) { /** * Add a constraint to fetch all entries which satisfy any queries. * - * @param queryObjects - * list of {@link Query} instances on which OR query executes. + * @param queryObjects list of {@link Query} instances on which OR query executes. * @return {@link Query} object, so you can chain this call. * *
@@ -262,10 +254,8 @@ public Query or(List queryObjects) { /** * Add a constraint to the query that requires a particular key entry to be less than the provided value. * - * @param key - * the key to be constrained. - * @param value - * the value that provides an upper bound. + * @param key the key to be constrained. + * @param value the value that provides an upper bound. * @return {@link Query} object, so you can chain this call.
* *
@@ -280,7 +270,7 @@ public Query or(List queryObjects) { */ public Query lessThan(@NotNull String key, @NotNull Object value) { if (queryValueJSON.isNull(key)) { - if (queryValue.length() > 0) { + if (!queryValue.isEmpty()) { queryValue = new JSONObject(); } queryValue.put("$lt", value); @@ -296,10 +286,8 @@ public Query lessThan(@NotNull String key, @NotNull Object value) { * Add a constraint to the query that requires a particular key entry to be less than or equal to the provided * value. * - * @param key - * The key to be constrained - * @param value - * The value that must be equalled. + * @param key The key to be constrained + * @param value The value that must be equalled. * @return {@link Query} object, so you can chain this call. * *
@@ -314,7 +302,7 @@ public Query lessThan(@NotNull String key, @NotNull Object value) { */ public Query lessThanOrEqualTo(@NotNull String key, Object value) { if (queryValueJSON.isNull(key)) { - if (queryValue.length() > 0) { + if (!queryValue.isEmpty()) { queryValue = new JSONObject(); } queryValue.put("$lte", value); @@ -329,10 +317,8 @@ public Query lessThanOrEqualTo(@NotNull String key, Object value) { /** * Add a constraint to the query that requires a particular key entry to be greater than the provided value. * - * @param key - * The key to be constrained. - * @param value - * The value that provides a lower bound. + * @param key The key to be constrained. + * @param value The value that provides a lower bound. * @return {@link Query} object, so you can chain this call. * *
@@ -347,7 +333,7 @@ public Query lessThanOrEqualTo(@NotNull String key, Object value) { */ public Query greaterThan(@NotNull String key, Object value) { if (queryValueJSON.isNull(key)) { - if (queryValue.length() > 0) { + if (!queryValue.isEmpty()) { queryValue = new JSONObject(); } queryValue.put("$gt", value); @@ -363,10 +349,8 @@ public Query greaterThan(@NotNull String key, Object value) { * Add a constraint to the query that requires a particular key entry to be greater than or equal to the provided * value. * - * @param key - * The key to be constrained. - * @param value - * The value that provides a lower bound. + * @param key The key to be constrained. + * @param value The value that provides a lower bound. * @return {@link Query} object, so you can chain this call. * *
@@ -396,10 +380,8 @@ public Query greaterThanOrEqualTo(String key, Object value) { /** * Add a constraint to the query that requires a particular key's entry to be not equal to the provided value. * - * @param key - * The key to be constrained. - * @param value - * The object that must not be equaled. + * @param key The key to be constrained. + * @param value The object that must not be equaled. * @return {@link Query} object, so you can chain this call. * *
@@ -429,10 +411,8 @@ public Query notEqualTo(@NotNull String key, Object value) { /** * Add a constraint to the query that requires a particular key's entry to be contained in the provided array. * - * @param key - * The key to be constrained. - * @param values - * The possible values for the key's object. + * @param key The key to be constrained. + * @param values The possible values for the key's object. * @return {@link Query} object, so you can chain this call.
* *
@@ -467,10 +447,8 @@ public Query containedIn(@NotNull String key, Object[] values) { * Add a constraint to the query that requires a particular key entry's value not be contained in the provided * array. * - * @param key - * The key to be constrained. - * @param values - * The list of values the key object should not be. + * @param key The key to be constrained. + * @param values The list of values the key object should not be. * @return {@link Query} object, so you can chain this call. * *
@@ -504,8 +482,7 @@ public Query notContainedIn(@NotNull String key, Object[] values) { /** * Add a constraint that requires, a specified key exists in response. * - * @param key - * The key to be constrained. + * @param key The key to be constrained. * @return {@link Query} object, so you can chain this call. * *
@@ -535,8 +512,7 @@ public Query exists(@NotNull String key) { /** * Add a constraint that requires, a specified key does not exist in response. * - * @param key - * The key to be constrained. + * @param key The key to be constrained. * @return {@link Query} object, so you can chain this call.
* * @@ -568,8 +544,7 @@ public Query notExists(@NotNull String key) { /** * Add a constraint that requires a particular reference key details. * - * @param key - * key that to be constrained. + * @param key key that to be constrained. * @return {@link Query} object, so you can chain this call. * *
@@ -593,8 +568,7 @@ public Query includeReference(String key) { /** * Include tags with which to search entries. * - * @param tags - * Comma separated array of tags with which to search entries. + * @param tags Comma separated array of tags with which to search entries. * @return {@link Query} object, so you can chain this call.
* *
@@ -617,8 +591,7 @@ public Query tags(@NotNull String[] tags) { * Sort the results in ascending order with the given key.
Sort the returned entries in ascending order of the * provided key. * - * @param key - * The key to order by. + * @param key The key to order by. * @return {@link Query} object, so you can chain this call.
* *
@@ -641,8 +614,7 @@ public Query ascending(@NotNull String key) { * Sort the results in descending order with the given key.
Sort the returned entries in descending order of * the provided key. * - * @param key - * The key to order by. + * @param key The key to order by. * @return {@link Query} object, so you can chain this call.
* *
@@ -663,8 +635,7 @@ public Query descending(@NotNull String key) { /** * Specifies list of field ids 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. * *
@@ -695,8 +666,7 @@ public Query except(@NotNull List fieldUid) { /** * Specifies list of field ids that would be 'excluded' from the response. * - * @param fieldIds - * field uid which get 'excluded' from the response. + * @param fieldIds field uid which get 'excluded' from the response. * @return {@link Query} object, so you can chain this call.
* *
@@ -724,8 +694,7 @@ public Query except(@NotNull String[] fieldIds) { /** * Specifies an array of 'only' keys in BASE object that would be 'included' in the response. * - * @param fieldUid - * Array of the 'only' reference keys to be included in response. + * @param fieldUid Array of the 'only' reference keys to be included in response. * @return {@link Query} object, so you can chain this call.
* *
@@ -753,10 +722,8 @@ public Query only(@NotNull String[] fieldUid) { /** * Specifies an array of 'only' keys that would be 'included' in the response. * - * @param fieldUid - * Array of the 'only' reference keys to be included in response. - * @param referenceFieldUid - * Key who has reference to some other class object. + * @param fieldUid Array of the 'only' reference keys to be included in response. + * @param referenceFieldUid Key who has reference to some other class object. * @return {@link Query} object, so you can chain this call.
* * @@ -792,10 +759,8 @@ public Query onlyWithReferenceUid(@NotNull List fieldUid, @NotNull Strin /** * Specifies an array of 'except' keys that would be 'excluded' in the response. * - * @param fieldUid - * Array of the 'except' reference keys to be excluded in response. - * @param referenceFieldUid - * Key who has reference to some other class object. + * @param fieldUid Array of the 'except' reference keys to be excluded in response. + * @param referenceFieldUid Key who has reference to some other class object. * @return {@link Query} object, so you can chain this call.
* *
@@ -897,8 +862,7 @@ public Query includeContentType() { /** * The number of objects to skip before returning any. * - * @param number - * No of objects to skip from returned objects + * @param number No of objects to skip from returned objects * @return {@link Query} object, so you can chain this call. *

* Note: The skip parameter can be used for pagination, @@ -922,8 +886,7 @@ public Query skip(int number) { /** * A limit on the number of objects to return. * - * @param number - * No of objects to limit. + * @param number No of objects to limit. * @return {@link Query} object, so you can chain this call. *

* Note: The limit parameter can be used for pagination, " @@ -948,10 +911,8 @@ public Query limit(int number) { * Add a regular expression constraint for finding string values that match the provided regular expression. This * may be slow for large data sets. * - * @param key - * The key to be constrained. - * @param regex - * The regular expression pattern to match. + * @param key The key to be constrained. + * @param regex The regular expression pattern to match. * @return {@link Query} object, so you can chain this call.
* *
@@ -983,21 +944,18 @@ public Query regex(@NotNull String key, @NotNull String regex) { * Add a regular expression constraint for finding string values that match the provided regular expression. This * may be slow for large data sets. * - * @param key - * The key to be constrained. - * @param regex - * The regular expression pattern to match - * @param modifiers - * Any of the following supported Regular expression modifiers. - *

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

- *

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

- *

- * use x for ignoring whitespace in regex - *

+ * @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.
* *
@@ -1038,8 +996,7 @@ public Query regex(@NotNull String key, @NotNull String regex, String modifiers) /** * set Language using locale code. * - * @param locale - * {@link String} value + * @param locale {@link String} value * @return {@link Query} object, so you can chain this call
*
*
@@ -1059,8 +1016,7 @@ public Query locale(@NotNull String locale) { /** * This method provides only the entries matching the specified value. * - * @param value - * value used to match or compare + * @param value value used to match or compare * @return {@link Query} object, so you can chain this call.
* *
@@ -1084,8 +1040,7 @@ public Query search(@NotNull String value) { /** * Execute a Query and Caches its result (Optional) * - * @param callback - * {@link QueryResultsCallBack} object to notify the application when the request has completed. + * @param callback {@link QueryResultsCallBack} object to notify the application when the request has completed. * @return {@linkplain Query} object, so you can chain this call.
* * @@ -1123,8 +1078,7 @@ public Query find(QueryResultsCallBack callback) { /** * Execute a Query and Caches its result (Optional) * - * @param callBack - * {@link QueryResultsCallBack} object to notify the application when the request has completed. + * @param callBack {@link QueryResultsCallBack} object to notify the application when the request has completed. * @return {@linkplain Query} object, so you can chain this call.
* *
@@ -1294,10 +1248,8 @@ public void getResultObject(List objects, JSONObject jsonObject, boolean /** * 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 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 * @return - Query * *
@@ -1349,10 +1301,8 @@ public Query includeReferenceContentTypUid() { * Get entries having values based on referenced fields. This query retrieves all entries that satisfy the query * conditions made on referenced fields. * - * @param key - * The key to be constrained - * @param queryObject - * {@link Query} object, so you can chain this call + * @param key The key to be constrained + * @param queryObject {@link Query} object, so you can chain this call * @return {@link Query} object, so you can chain this call
* *
@@ -1376,10 +1326,8 @@ public Query whereIn(@NotNull String key, Query queryObject) { * Get entries having values based on referenced fields. This query works the opposite of $in_query and retrieves * all entries that does not satisfy query conditions made on referenced fields. * - * @param key - * The key to be constrained - * @param queryObject - * {@link Query} object, so you can chain this call + * @param key The key to be constrained + * @param queryObject {@link Query} object, so you can chain this call * @return {@link Query} object, so you can chain this call * *
diff --git a/src/main/java/com/contentstack/sdk/Stack.java b/src/main/java/com/contentstack/sdk/Stack.java index a9a89449..73aaae64 100644 --- a/src/main/java/com/contentstack/sdk/Stack.java +++ b/src/main/java/com/contentstack/sdk/Stack.java @@ -105,8 +105,7 @@ private void includeLivePreview() { * Contentstack. You can set up the base URL and environment across which you want to preview content. *

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

* Example @@ -117,8 +116,7 @@ private void includeLivePreview() { *

* stack.livePreviewQuery(queryMap) *

- * @throws IOException - * IO Exception + * @throws IOException IO Exception */ public Stack livePreviewQuery(Map query) throws IOException { config.livePreviewHash = query.get(LIVE_PREVIEW); @@ -154,9 +152,8 @@ public Stack livePreviewQuery(Map query) throws IOException { * content for your application, you are required to first create a content type, and then create entries using the * content type. * - * @param contentTypeUid - * Enter the unique ID of the content type of which you want to retrieve the entries. The UID is often based - * on the title of the content type and it is unique across a stack. + * @param contentTypeUid Enter the unique ID of the content type of which you want to retrieve the entries. The UID is often based + * on the title of the content type, and it is unique across a stack. * @return the {@link ContentType} *

* Example @@ -179,8 +176,7 @@ public ContentType contentType(String contentTypeUid) { * The Get a single asset request fetches the latest version of a specific asset of a particular stack. *

* - * @param uid - * uid of {@link Asset} + * @param uid uid of {@link Asset} * @return {@link Asset} instance Tip: If no version is mentioned, the request will retrieve the latest * published version of the asset. To retrieve a specific version, use the version parameter, keep the environment * parameter blank, and use the management token instead of the delivery token. @@ -241,10 +237,9 @@ public String getDeliveryToken() { /** * Removes Header by key * - * @param headerKey - * of the header - *

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

+ * Example: stack.removeHeader("delivery_token"); */ public void removeHeader(String headerKey) { headers.remove(headerKey); @@ -253,10 +248,8 @@ public void removeHeader(String headerKey) { /** * Adds header to the stack * - * @param headerKey - * the header key - * @param headerValue - * the header value + * @param headerKey the header key + * @param headerValue the header value */ public void setHeader(@NotNull String headerKey, @NotNull String headerValue) { if (!headerKey.isEmpty() && !headerValue.isEmpty()) { @@ -269,10 +262,8 @@ public void setHeader(@NotNull String headerKey, @NotNull String headerValue) { * 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} + * @param imageUrl the image url + * @param parameters the parameters {@link LinkedHashMap} * @return the string */ public String imageTransform(@NotNull String imageUrl, @NotNull Map parameters) { @@ -296,11 +287,9 @@ protected String getQueryParam(Map params) { * The Get all content types call returns comprehensive information of all the content types available in a * particular stack in your account.. * - * @param params - * query parameters - * @param callback - * ContentTypesCallback This call returns comprehensive information of all the content types available in a - * particular stack in your account. + * @param params query parameters + * @param callback ContentTypesCallback This call returns comprehensive information of all the content types available in a + * particular stack in your account. */ public void getContentTypes(@NotNull JSONObject params, final ContentTypesCallback callback) { Iterator keys = params.keys(); @@ -321,8 +310,7 @@ public void getContentTypes(@NotNull JSONObject params, final ContentTypesCallba * the specified stack in response. The response also contains a sync token, which you need to store, since this * token is used to get subsequent delta * - * @param syncCallBack - * returns callback for sync result. + * @param syncCallBack returns callback for sync result. */ public void sync(SyncResultCallBack syncCallBack) { syncParams = new JSONObject(); @@ -333,21 +321,19 @@ public void sync(SyncResultCallBack syncCallBack) { /** * Sync pagination token. * - * @param paginationToken - * If the response is paginated, use the pagination token under this parameter. - * @param syncCallBack - * returns callback for sync result - *

- * If the result of the initial sync (or subsequent sync) contains more than 100 records, the response would - * be paginated. It provides pagination token in the response. However, you do not have to use the - * pagination token manually to get the next batch, the SDK does that automatically until the sync is - * complete. Pagination token can be used in case you want to fetch only selected batches. It is especially - * useful if the sync process is interrupted midway (due to network issues, etc.). In such cases, this token - * can be used to restart the sync process from where it was interrupted.
- *
- * Example :
- * Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); - * stack.syncPaginationToken("paginationToken) + * @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 :
+ * Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); + * stack.syncPaginationToken("paginationToken) */ public void syncPaginationToken(@NotNull String paginationToken, SyncResultCallBack syncCallBack) { syncParams = new JSONObject(); @@ -358,21 +344,19 @@ public void syncPaginationToken(@NotNull String paginationToken, SyncResultCallB /** * Sync token. * - * @param syncToken - * Use the sync token that you received in the previous/initial sync under this parameter. - * @param syncCallBack - * returns callback for sync result - *

- * You can use the sync token (that you receive after initial sync) to get the updated content next time. - * The sync token fetches only the content that was added after your last sync, and the details of the - * content that was deleted or updated.
- *
- * Example :
- *

-     *                                                                                                                                                                                                                                                                                             Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
-     *                                                                                                                                                                                                                                                                                             stack.syncToken("syncToken")
-     *                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     stack.syncToken(sync_token, new SyncResultCallBack()                                                                                                                                                                                                               ){ }
-     *                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
+ * @param syncToken Use the sync token that you received in the previous/initial sync under this parameter. + * @param syncCallBack returns callback for sync result + *

+ * You can use the sync token (that you receive after initial sync) to get the updated content next time. + * The sync token fetches only the content that was added after your last sync, and the details of the + * content that was deleted or updated.
+ *
+ * Example :
+ *

+     *                                                                                                                                                                                                                                                                                                                                                         Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
+     *                                                                                                                                                                                                                                                                                                                                                         stack.syncToken("syncToken")
+     *                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 stack.syncToken(sync_token, new SyncResultCallBack()                                                                                                                                                                                                               ){ }
+     *                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
*/ public void syncToken(String syncToken, SyncResultCallBack syncCallBack) { syncParams = new JSONObject(); @@ -383,17 +367,15 @@ public void syncToken(String syncToken, SyncResultCallBack syncCallBack) { /** * Sync from date. * - * @param fromDate - * Enter the start date for initial sync. - * @param syncCallBack - * Returns callback for sync result. - *

- * You can also initialize sync with entries published after a specific date. To do this, use syncWithDate - * and specify the start date as its value.
- *
- * Example :
- * Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); - * stack.syncFromDate("fromDate") + * @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 :
+ * Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); + * stack.syncFromDate("fromDate") */ public void syncFromDate(@NotNull Date fromDate, SyncResultCallBack syncCallBack) { String newFromDate = convertUTCToISO(fromDate); @@ -413,18 +395,16 @@ protected String convertUTCToISO(Date date) { /** * Sync content type. * - * @param contentType - * Provide uid of your content_type - * @param syncCallBack - * Returns callback for sync result. - *

- * You can also initialize sync with entries of only specific content_type. To do this, use syncContentType - * and specify the content type uid as its value. However, if you do this, the subsequent syncs will only - * include the entries of the specified content_type.
- *
- * Example : - *

- * stack.syncContentType(String content_type, new SyncResultCallBack()){ } + * @param contentType Provide uid of your content_type + * @param syncCallBack Returns callback for sync result. + *

+ * You can also initialize sync with entries of only specific content_type. To do this, use syncContentType + * and specify the content type uid as its value. However, if you do this, the subsequent syncs will only + * include the entries of the specified content_type.
+ *
+ * Example : + *

+ * stack.syncContentType(String content_type, new SyncResultCallBack()){ } */ public void syncContentType(@NotNull String contentType, SyncResultCallBack syncCallBack) { syncParams = new JSONObject(); @@ -436,18 +416,16 @@ public void syncContentType(@NotNull String contentType, SyncResultCallBack sync /** * Sync locale. * - * @param localeCode - * Select the required locale code. - * @param syncCallBack - * Returns callback for sync result. - *

- * You can also initialize sync with entries of only specific locales. To do this, use syncLocale and - * specify the locale code as its value. However, if you do this, the subsequent syncs will only include the - * entries of the specified locales.
- *
- * Example :
- * Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); stack.syncContentType(String - * content_type, new SyncResultCallBack()){ } + * @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 :
+ * Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); stack.syncContentType(String + * content_type, new SyncResultCallBack()){ } */ public void syncLocale(String localeCode, SyncResultCallBack syncCallBack) { syncParams = new JSONObject(); @@ -459,25 +437,23 @@ public void syncLocale(String localeCode, SyncResultCallBack syncCallBack) { /** * Sync publish type. * - * @param publishType - * Use the type parameter to get a specific type of content like - *

- * (asset_published, entry_published, asset_unpublished, asset_deleted, entry_unpublished, entry_deleted, - * content_type_deleted.) - * @param syncCallBack - * returns callback for sync result. - *

- * Use the type parameter to get a specific type of content. You can pass one of the following values: - * asset_published, entry_published, asset_unpublished, asset_deleted, entry_unpublished, entry_deleted, - * content_type_deleted. If you do not specify any value, it will bring all published entries and published - * assets. - *
- *
- * Example :
- * - * Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); * - * stack.syncPublishType(PublishType) - * + * @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 :
+ * + * Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment"); * + * stack.syncPublishType(PublishType) + * */ public void syncPublishType(PublishType publishType, SyncResultCallBack syncCallBack) { syncParams = new JSONObject(); @@ -489,22 +465,17 @@ public void syncPublishType(PublishType publishType, SyncResultCallBack syncCall /** * Sync. * - * @param contentType - * your content type id - * @param fromDate - * start date - * @param localeCode - * language as language code - * @param publishType - * type as PublishType - * @param syncCallBack - * Callback - *

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

+ * You can also initialize sync with entries that satisfy multiple parameters. To do this, use syncWith and + * specify the parameters. However, if you do this, the subsequent syncs will only include the entries of + * the specified parameters
+ *
+ * Example :
*/ public void sync(String contentType, Date fromDate, String localeCode, PublishType publishType, SyncResultCallBack syncCallBack) { @@ -547,7 +518,7 @@ private void fetchFromNetwork(String urlString, JSONObject urlQueries, private HashMap getUrlParams(JSONObject jsonQuery) { HashMap hashMap = new HashMap<>(); - if (jsonQuery != null && jsonQuery.length() > 0) { + if (jsonQuery != null && !jsonQuery.isEmpty()) { Iterator iteString = jsonQuery.keys(); while (iteString.hasNext()) { String key = iteString.next(); @@ -558,11 +529,16 @@ private HashMap getUrlParams(JSONObject jsonQuery) { return hashMap; } + + public Taxonomy taxonomy() { + return new Taxonomy(this.service,this.config, this.headers); + } + + /** * The enum Publish type. */ public enum PublishType { - //asset_deleted, asset_published, asset_unpublished, content_type_deleted, entry_deleted, entry_published, // Breaking change in v3.11.0 ASSET_DELETED, ASSET_PUBLISHED, diff --git a/src/main/java/com/contentstack/sdk/Taxonomy.java b/src/main/java/com/contentstack/sdk/Taxonomy.java new file mode 100644 index 00000000..68866b6c --- /dev/null +++ b/src/main/java/com/contentstack/sdk/Taxonomy.java @@ -0,0 +1,125 @@ +package com.contentstack.sdk; + +import okhttp3.Request; +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.Response; + +import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * The type Taxonomy. + * + * @author Shailesh Mishra
Taxonomy :

Taxonomy, currently in the Early Access Phase simplifies the process of organizing content in your system, making it effortless to find and retrieve information. + */ +public class Taxonomy { + + + protected LinkedHashMap headers; + protected APIService service; + protected HashMap query = new HashMap<>(); + protected Config config; + + /** + * Instantiates a new Taxonomy. + * + * @param service the service + * @param config the config + * @param headers the headers + */ + public Taxonomy(APIService service, Config config, LinkedHashMap headers) { + this.service = service; + this.headers = headers; + this.config = config; + } + + /** + * You can retrieve filtered entries using taxonomy through two different endpoints: + * + * @param queryParams the query parameters should be like below + *

    + *
  • IN Operator : Get all entries for a specific taxonomy that satisfy the given conditions provided in the '$in' query.
    Your query should be as follows:
    {"taxonomies.taxonomy_uid" : { "$in" : ["term_uid1" , "term_uid2" ] }}

  • OR Operator : Get all entries for a specific taxonomy that satisfy at least one of the given conditions provided in the “$or” query.
    Your query should be as follows:
    query={ $or: [ { "taxonomies.taxonomy_uid_1" : "term_uid1" }, { "taxonomies.taxonomy_uid_2" : "term_uid2" } ] } + *
  • + *
    + *
  • + * AND Operator :
    + * Get all entries for a specific taxonomy that satisfy all the conditions provided in the “$and” query.
    + *

    + * Your query should be as follows:
    + * + * { + * $and: [ + * { "taxonomies.taxonomy_uid_1" : "term_uid1" }, + * { "taxonomies.taxonomy_uid_2" : "term_uid2" } + * ] + * } + * + * + *

  • + *
    + * + *
  • + * Exists Operator :
    + * Get all entries for a specific taxonomy that if the value of the field, mentioned in the condition, exists.
    + *

    + * Your query should be as follows: + * + * {"taxonomies.taxonomy_uid" : { "$exists": true }} + * + *


  • + *
  • + * Equal and Below Operator :
    + * Get all entries for a specific taxonomy that match a specific term and all its descendant terms, requiring only the target term and a specified level.
    + *

    + * Your query should be as follows: + * + * { + * "taxonomies.taxonomy_uid" : { "$eq_below": "term_uid", "level" : 2}} + * + *

  • + * + * + *
+ * @return instance of {@link Taxonomy} + */ + public Taxonomy query(Map queryParams) { + query.putAll(queryParams); + return this; + } + + /** + * Make request call. + * + * @return the call + */ + Call makeRequest() { + HashMap map = new HashMap<>(); + map.put("query", query); + return this.service.getTaxonomy(this.headers, map); + } + + + /** + * Find. + * + * @param callback the callback + */ + public void find(TaxonomyCallback callback) { + try { + Response response = makeRequest().execute(); + if (response.isSuccessful()) { + callback.onResponse(response.body()); + } else { + Request request = makeRequest().request(); + callback.onFailure(request, response.errorBody()); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} + + diff --git a/src/main/java/com/contentstack/sdk/TaxonomyCallback.java b/src/main/java/com/contentstack/sdk/TaxonomyCallback.java new file mode 100644 index 00000000..3de08db1 --- /dev/null +++ b/src/main/java/com/contentstack/sdk/TaxonomyCallback.java @@ -0,0 +1,28 @@ +package com.contentstack.sdk; + +import okhttp3.Request; +import okhttp3.ResponseBody; + +public interface TaxonomyCallback { + + /** + * Called when the HTTP response was successfully returned by the remote server. The callback may + * proceed to read the response body. The response is still live until + * its response body is {@linkplain ResponseBody closed}. The recipient of the callback may + * consume the response body on another thread. + * + *

Note that transport-layer success (receiving a HTTP response code, headers and body) does + * not necessarily indicate application-layer success: {@code response} may still indicate an + * unhappy HTTP response code like 404 or 500. + */ + void onResponse(ResponseBody response); + + /** + * Called when the request could not be executed due to cancellation, a connectivity problem or + * timeout. Because networks can fail during an exchange, it is possible that the remote server + * accepted the request before the failure. + */ + void onFailure(Request request, ResponseBody errorMessage); + + +} \ No newline at end of file diff --git a/src/test/java/com/contentstack/sdk/Credentials.java b/src/test/java/com/contentstack/sdk/Credentials.java index 9b5bb2c5..33d6e556 100644 --- a/src/test/java/com/contentstack/sdk/Credentials.java +++ b/src/test/java/com/contentstack/sdk/Credentials.java @@ -15,7 +15,6 @@ private static String envChecker() { if (githubActions != null && githubActions.equals("true")) { System.out.println("Tests are running in GitHub Actions environment."); String mySecretKey = System.getenv("API_KEY"); - System.out.println("My Secret Key: " + mySecretKey); return "GitHub"; } else { System.out.println("Tests are running in a local environment."); @@ -65,13 +64,14 @@ private Credentials() throws AccessException { public static Stack getStack() { if (stack == null) { var envCheck = envChecker(); - System.out.println(envCheck); + System.out.println("idendified env file detected " + envCheck); synchronized (Credentials.class) { if (stack == null) { try { Config config = new Config(); config.setHost(HOST); stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENVIRONMENT, config); + System.out.println(stack); } catch (IllegalAccessException e) { throw new RuntimeException(e); } diff --git a/src/test/java/com/contentstack/sdk/TaxonomyTest.java b/src/test/java/com/contentstack/sdk/TaxonomyTest.java new file mode 100644 index 00000000..27b16972 --- /dev/null +++ b/src/test/java/com/contentstack/sdk/TaxonomyTest.java @@ -0,0 +1,73 @@ +package com.contentstack.sdk; + +import okhttp3.*; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.util.HashMap; + + +public class TaxonomyTest { + + private final Taxonomy taxonomy = Credentials.getStack().taxonomy(); + + @Test + void testInstance() { + Assertions.assertNotNull(taxonomy); + } + + @Test + void testInOperator() { + HashMap query = new HashMap<>(); + query.put("taxonomies.taxonomy_uid", new HashMap() {{ + put("$in", new String[]{"term_uid1", "term_uid2"}); + }}); + + taxonomy.query(query).find(new TaxonomyCallback() { + @Override + public void onFailure(Request request, ResponseBody errorMessage) { + System.out.println("Failing API call : "+errorMessage.toString()); + + } + + @Override + public void onResponse(Request request, ResponseBody response) { + System.out.println("Response : "+response.toString()); + + } + }); + } + + +// @Test +// void testTaxonomyIn() { +// String[] value = {"term_uid1", "term_uid2"}; // ["term_uid1" , "term_uid2" ] +// +// Request request = taxonomy.inOperator("taxonomies.taxonomy_uid", value).find().request(); +// taxonomy.find(new Callback() { +// @Override +// public void onResponse(Call call, Response response) { +// call.request().url(); +// } +// +// @Override +// public void onFailure(Call call, Throwable t) { +// +// } +// }); +// Assertions.assertEquals(3, request.headers().size()); +// Assertions.assertEquals("GET", request.method().toString(), "test method are being passed though payload"); +// Assertions.assertEquals("cdn.contentstack.io", request.url().host()); +// Assertions.assertNull(request.url().encodedFragment(), "We do not expect any fragment"); +// Assertions.assertEquals("/taxonomies/entries", request.url().encodedPath()); +// Assertions.assertEquals(2, Arrays.stream(request.url().encodedPathSegments().stream().toArray()).count()); +// Assertions.assertEquals("", request.url().query()); +// Assertions.assertEquals("", request.url().encodedQuery()); +// Assertions.assertEquals("", request.url().queryParameterNames()); +// Assertions.assertEquals("", request.url(), "test url are being passed though payload"); +// Assertions.assertEquals("", request.body().contentType().toString(), "test content type are being passed though payload"); +// } + + +} diff --git a/src/test/java/com/contentstack/sdk/TestAsset.java b/src/test/java/com/contentstack/sdk/TestAsset.java index 0991b583..accc173f 100644 --- a/src/test/java/com/contentstack/sdk/TestAsset.java +++ b/src/test/java/com/contentstack/sdk/TestAsset.java @@ -14,16 +14,14 @@ class TestAsset { private String assetUid; private final Stack stack = Credentials.getStack(); - private String envChecker() { + private void envChecker() { String githubActions = System.getenv("GITHUB_ACTIONS"); if (githubActions != null && githubActions.equals("true")) { System.out.println("Tests are running in GitHub Actions environment."); String mySecretKey = System.getenv("API_KEY"); System.out.println("My Secret Key: " + mySecretKey); - return "GitHub"; } else { System.out.println("Tests are running in a local environment."); - return "local"; } } From a046fa01ede993698f63e677fd036e3669bdc18b Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Wed, 13 Dec 2023 19:10:54 +0530 Subject: [PATCH 02/10] v1.12.3 - Taxonomy query support - Early Access Feature Support --- .../com/contentstack/sdk/TaxonomyTest.java | 76 +++++++++++-------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/src/test/java/com/contentstack/sdk/TaxonomyTest.java b/src/test/java/com/contentstack/sdk/TaxonomyTest.java index 27b16972..f059a5a1 100644 --- a/src/test/java/com/contentstack/sdk/TaxonomyTest.java +++ b/src/test/java/com/contentstack/sdk/TaxonomyTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.io.IOException; +import java.util.Arrays; import java.util.HashMap; @@ -32,7 +32,7 @@ public void onFailure(Request request, ResponseBody errorMessage) { } @Override - public void onResponse(Request request, ResponseBody response) { + public void onResponse(ResponseBody response) { System.out.println("Response : "+response.toString()); } @@ -40,34 +40,50 @@ public void onResponse(Request request, ResponseBody response) { } -// @Test -// void testTaxonomyIn() { -// String[] value = {"term_uid1", "term_uid2"}; // ["term_uid1" , "term_uid2" ] -// -// Request request = taxonomy.inOperator("taxonomies.taxonomy_uid", value).find().request(); -// taxonomy.find(new Callback() { -// @Override -// public void onResponse(Call call, Response response) { -// call.request().url(); -// } -// -// @Override -// public void onFailure(Call call, Throwable t) { -// -// } -// }); -// Assertions.assertEquals(3, request.headers().size()); -// Assertions.assertEquals("GET", request.method().toString(), "test method are being passed though payload"); -// Assertions.assertEquals("cdn.contentstack.io", request.url().host()); -// Assertions.assertNull(request.url().encodedFragment(), "We do not expect any fragment"); -// Assertions.assertEquals("/taxonomies/entries", request.url().encodedPath()); -// Assertions.assertEquals(2, Arrays.stream(request.url().encodedPathSegments().stream().toArray()).count()); -// Assertions.assertEquals("", request.url().query()); -// Assertions.assertEquals("", request.url().encodedQuery()); -// Assertions.assertEquals("", request.url().queryParameterNames()); -// Assertions.assertEquals("", request.url(), "test url are being passed though payload"); -// Assertions.assertEquals("", request.body().contentType().toString(), "test content type are being passed though payload"); -// } + @Test + void testUnitInOperator() { + HashMap query = new HashMap<>(); + query.put("taxonomies.taxonomy_uid", new HashMap() {{ + put("$in", new String[]{"term_uid1", "term_uid2"}); + }}); + + taxonomy.query(query); + Request req = taxonomy.makeRequest().request(); + Assertions.assertEquals(3, req.headers().size()); + Assertions.assertEquals("GET", req.method().toString(), "test method are being passed though payload"); + Assertions.assertEquals("cdn.contentstack.io", req.url().host()); + Assertions.assertNull(req.url().encodedFragment(), "We do not expect any fragment"); + Assertions.assertEquals("/v3/taxonomies/entries", req.url().encodedPath()); + Assertions.assertEquals(3, Arrays.stream(req.url().encodedPathSegments().stream().toArray()).count()); + Assertions.assertNotNull( req.url().query()); + Assertions.assertNotNull(req.url().encodedQuery()); + Assertions.assertEquals("[query]", req.url().queryParameterNames().toString()); + } + + @Test + void testUnitOrOperator() { + HashMap query = new HashMap<>(); + query.put("taxonomies.taxonomy_uid", new HashMap() {{ + put("$in", new String[]{"term_uid1", "term_uid2"}); + }}); + + taxonomy.query(query); + Request req = taxonomy.makeRequest().request(); + Assertions.assertEquals(3, req.headers().size()); + Assertions.assertEquals("GET", req.method().toString(), "test method are being passed though payload"); + Assertions.assertEquals("cdn.contentstack.io", req.url().host()); + Assertions.assertNull(req.url().encodedFragment(), "We do not expect any fragment"); + Assertions.assertEquals("/v3/taxonomies/entries", req.url().encodedPath()); + Assertions.assertEquals(3, Arrays.stream(req.url().encodedPathSegments().stream().toArray()).count()); + Assertions.assertNotNull( req.url().query()); + Assertions.assertNotNull(req.url().encodedQuery()); + Assertions.assertEquals("[query]", req.url().queryParameterNames().toString()); + } + + + + + } From fe28d6d8a7b4591557535404249ad68ebf04d88e Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 14 Dec 2023 00:03:18 +0530 Subject: [PATCH 03/10] v1.12.3 - Taxonomy query support - Early Access Feature Support --- .../java/com/contentstack/sdk/Taxonomy.java | 74 ++++++++++++++++++- .../com/contentstack/sdk/TaxonomyTest.java | 55 +++++++++----- 2 files changed, 111 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/contentstack/sdk/Taxonomy.java b/src/main/java/com/contentstack/sdk/Taxonomy.java index 68866b6c..708759cc 100644 --- a/src/main/java/com/contentstack/sdk/Taxonomy.java +++ b/src/main/java/com/contentstack/sdk/Taxonomy.java @@ -2,12 +2,14 @@ import okhttp3.Request; import okhttp3.ResponseBody; +import org.jetbrains.annotations.NotNull; import retrofit2.Call; import retrofit2.Response; import java.io.IOException; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; /** @@ -86,7 +88,75 @@ public Taxonomy(APIService service, Config config, LinkedHashMap * @return instance of {@link Taxonomy} */ public Taxonomy query(Map queryParams) { - query.putAll(queryParams); + this.query.putAll(queryParams); + return this; + } + + + /** + * Get all entries for a specific taxonomy that satisfy the given conditions provided in the query. + * + * @param key the key of the taxonomy to query + * @param listOfItems the list of taxonomy fields + * Example: If you want to retrieve entries with the color taxonomy applied and linked to the term red and/or yellow. + * + * String key = "taxonomies.taxonomy_uid"; + * String[] listOfItem = {"term_uid1", "term_uid2"}; + * taxonomy.in(key, listOfItem); + * taxonomy.query(query).find(new TaxonomyCallback() { + * @Override public void onFailure(Request request, ResponseBody errorMessage) { + * System.out.println("Failing API call : " + errorMessage.toString()); + *

+ * } + * @Override public void onResponse(ResponseBody response) { + * System.out.println("Response : " + response.toString()); + *

+ * } + * }); + * + */ + public Taxonomy in(@NotNull String key, @NotNull String[] listOfItems) { + HashMap param = new HashMap<>(); + param.put("$in", listOfItems); + this.query.put(key, param); + return this; + } + + + public Taxonomy or(@NotNull List> listOfItems) { + for (int i = 0; i < listOfItems.size(); i++) { + HashMap param = listOfItems.get(i); + + if (i > 0) { + this.query.put("$or", listOfItems.toArray()); + } + + this.query.put("$or", param); + } + + return this; + } + + + public Taxonomy and(@NotNull List> listOfItems) { + for (int i = 0; i < listOfItems.size(); i++) { + HashMap param = listOfItems.get(i); + + if (i > 0) { + this.query.put("$and", listOfItems.toArray()); + } + + this.query.put("$and", param); + } + + return this; + } + + + public Taxonomy exists(@NotNull String name, @NotNull Boolean value) { + HashMap param = new HashMap<>(); + param.put("$exists", value); + this.query.put(name, param); return this; } @@ -120,6 +190,8 @@ public void find(TaxonomyCallback callback) { throw new RuntimeException(e); } } + + } diff --git a/src/test/java/com/contentstack/sdk/TaxonomyTest.java b/src/test/java/com/contentstack/sdk/TaxonomyTest.java index f059a5a1..fec99319 100644 --- a/src/test/java/com/contentstack/sdk/TaxonomyTest.java +++ b/src/test/java/com/contentstack/sdk/TaxonomyTest.java @@ -1,20 +1,24 @@ package com.contentstack.sdk; -import okhttp3.*; +import okhttp3.Request; +import okhttp3.ResponseBody; +import org.json.JSONObject; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.List; public class TaxonomyTest { - private final Taxonomy taxonomy = Credentials.getStack().taxonomy(); + private final Stack stack = Credentials.getStack(); @Test void testInstance() { - Assertions.assertNotNull(taxonomy); + Assertions.assertNotNull(stack); } @Test @@ -24,16 +28,16 @@ void testInOperator() { put("$in", new String[]{"term_uid1", "term_uid2"}); }}); - taxonomy.query(query).find(new TaxonomyCallback() { + stack.taxonomy().query(query).find(new TaxonomyCallback() { @Override public void onFailure(Request request, ResponseBody errorMessage) { - System.out.println("Failing API call : "+errorMessage.toString()); + System.out.println("Failing API call : " + errorMessage.toString()); } @Override public void onResponse(ResponseBody response) { - System.out.println("Response : "+response.toString()); + System.out.println("Response : " + response.toString()); } }); @@ -46,7 +50,7 @@ void testUnitInOperator() { query.put("taxonomies.taxonomy_uid", new HashMap() {{ put("$in", new String[]{"term_uid1", "term_uid2"}); }}); - + Taxonomy taxonomy = stack.taxonomy(); taxonomy.query(query); Request req = taxonomy.makeRequest().request(); Assertions.assertEquals(3, req.headers().size()); @@ -55,19 +59,17 @@ void testUnitInOperator() { Assertions.assertNull(req.url().encodedFragment(), "We do not expect any fragment"); Assertions.assertEquals("/v3/taxonomies/entries", req.url().encodedPath()); Assertions.assertEquals(3, Arrays.stream(req.url().encodedPathSegments().stream().toArray()).count()); - Assertions.assertNotNull( req.url().query()); + Assertions.assertNotNull(req.url().query()); Assertions.assertNotNull(req.url().encodedQuery()); Assertions.assertEquals("[query]", req.url().queryParameterNames().toString()); } @Test - void testUnitOrOperator() { - HashMap query = new HashMap<>(); - query.put("taxonomies.taxonomy_uid", new HashMap() {{ - put("$in", new String[]{"term_uid1", "term_uid2"}); - }}); - - taxonomy.query(query); + void testUnitINOperator() { + Taxonomy taxonomy = stack.taxonomy(); + String key = "taxonomies.taxonomy_uid"; + String[] listOfItem = {"term_uid1", "term_uid2"}; + taxonomy.in(key, listOfItem); Request req = taxonomy.makeRequest().request(); Assertions.assertEquals(3, req.headers().size()); Assertions.assertEquals("GET", req.method().toString(), "test method are being passed though payload"); @@ -75,15 +77,34 @@ void testUnitOrOperator() { Assertions.assertNull(req.url().encodedFragment(), "We do not expect any fragment"); Assertions.assertEquals("/v3/taxonomies/entries", req.url().encodedPath()); Assertions.assertEquals(3, Arrays.stream(req.url().encodedPathSegments().stream().toArray()).count()); - Assertions.assertNotNull( req.url().query()); + Assertions.assertNotNull(req.url().query()); Assertions.assertNotNull(req.url().encodedQuery()); Assertions.assertEquals("[query]", req.url().queryParameterNames().toString()); } + @Test + void testUnitOr() { + Taxonomy taxonomy = stack.taxonomy(); + List> listOfItems = new ArrayList<>(); + HashMap items = new HashMap<>(); + items.put("taxonomies.taxonomy_uid_1", "term_uid1"); + items.put("taxonomies.taxonomy_uid_2", "term_uid2"); + listOfItems.add(items); - + taxonomy.or(listOfItems); + Request req = taxonomy.makeRequest().request(); + Assertions.assertEquals(3, req.headers().size()); + Assertions.assertEquals("GET", req.method().toString(), "test method are being passed though payload"); + Assertions.assertEquals("cdn.contentstack.io", req.url().host()); + Assertions.assertNull(req.url().encodedFragment(), "We do not expect any fragment"); + Assertions.assertEquals("/v3/taxonomies/entries", req.url().encodedPath()); + Assertions.assertEquals(3, Arrays.stream(req.url().encodedPathSegments().stream().toArray()).count()); + Assertions.assertNotNull(req.url().query()); + Assertions.assertNotNull(req.url().encodedQuery()); + Assertions.assertEquals("[query]", req.url().queryParameterNames().toString()); + } } From f521de83783cb716c7da4868df3aec7e4ad30293 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Thu, 14 Dec 2023 19:04:30 +0530 Subject: [PATCH 04/10] v1.12.3 - Taxonomy query support - Early Access Feature Support --- .../java/com/contentstack/sdk/APIService.java | 2 +- .../java/com/contentstack/sdk/Taxonomy.java | 309 +++++++++++++----- .../com/contentstack/sdk/Credentials.java | 1 - .../com/contentstack/sdk/TaxonomyTest.java | 139 ++++---- 4 files changed, 297 insertions(+), 154 deletions(-) diff --git a/src/main/java/com/contentstack/sdk/APIService.java b/src/main/java/com/contentstack/sdk/APIService.java index e178b7af..a14af8e5 100644 --- a/src/main/java/com/contentstack/sdk/APIService.java +++ b/src/main/java/com/contentstack/sdk/APIService.java @@ -23,5 +23,5 @@ Call getRequest( @GET("v3/taxonomies/entries") Call getTaxonomy( @HeaderMap Map headers, - @QueryMap(encoded = true) Map query); + @QueryMap Map query); } diff --git a/src/main/java/com/contentstack/sdk/Taxonomy.java b/src/main/java/com/contentstack/sdk/Taxonomy.java index 708759cc..207607f9 100644 --- a/src/main/java/com/contentstack/sdk/Taxonomy.java +++ b/src/main/java/com/contentstack/sdk/Taxonomy.java @@ -7,10 +7,8 @@ import retrofit2.Response; import java.io.IOException; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; /** * The type Taxonomy. @@ -38,134 +36,265 @@ public Taxonomy(APIService service, Config config, LinkedHashMap this.config = config; } + /** - * You can retrieve filtered entries using taxonomy through two different endpoints: - * - * @param queryParams the query parameters should be like below - *

    - *
  • IN Operator : Get all entries for a specific taxonomy that satisfy the given conditions provided in the '$in' query.
    Your query should be as follows:
    {"taxonomies.taxonomy_uid" : { "$in" : ["term_uid1" , "term_uid2" ] }}

  • OR Operator : Get all entries for a specific taxonomy that satisfy at least one of the given conditions provided in the “$or” query.
    Your query should be as follows:
    query={ $or: [ { "taxonomies.taxonomy_uid_1" : "term_uid1" }, { "taxonomies.taxonomy_uid_2" : "term_uid2" } ] } - *
  • - *
    - *
  • - * AND Operator :
    - * Get all entries for a specific taxonomy that satisfy all the conditions provided in the “$and” query.
    - *

    - * Your query should be as follows:
    - * - * { - * $and: [ - * { "taxonomies.taxonomy_uid_1" : "term_uid1" }, - * { "taxonomies.taxonomy_uid_2" : "term_uid2" } - * ] - * } - * - * - *

  • - *
    - * - *
  • - * Exists Operator :
    - * Get all entries for a specific taxonomy that if the value of the field, mentioned in the condition, exists.
    - *

    - * Your query should be as follows: - * - * {"taxonomies.taxonomy_uid" : { "$exists": true }} - * - *


  • - *
  • - * Equal and Below Operator :
    - * Get all entries for a specific taxonomy that match a specific term and all its descendant terms, requiring only the target term and a specified level.
    - *

    - * Your query should be as follows: - * - * { - * "taxonomies.taxonomy_uid" : { "$eq_below": "term_uid", "level" : 2}} - * - *

  • - * - * - *
- * @return instance of {@link Taxonomy} + * Get all entries for a specific taxonomy that satisfy the given conditions provided in the '$in' query. + * Your query should be as follows: + *

+ *

+     * {"taxonomies.taxonomy_uid" : { "$in" : ["term_uid1" , "term_uid2" ] }}
+     * 
+ *

+ * Example: If you want to retrieve entries with the color taxonomy applied and linked to the term red and/or yellow. + *

+ *

+     * {"taxonomies.color" : { "$in" : ["red" , "yellow" ] }}
+     * 
+ * + * @param taxonomy the key of the taxonomy to query + * @param listOfItems the list of taxonomy fields + * @return an instance of the Taxonomy with the specified conditions added to the query */ - public Taxonomy query(Map queryParams) { - this.query.putAll(queryParams); + public Taxonomy in(String taxonomy, String[] listOfItems) { + String formattedValues = Arrays.stream(listOfItems).map(value -> "\"" + value.trim() + "\"").collect(Collectors.joining(" , ")); + + String stringify = "{ \"$in\" : [" + formattedValues + "] }}"; + this.query.put(taxonomy, stringify); return this; } /** - * Get all entries for a specific taxonomy that satisfy the given conditions provided in the query. - * - * @param key the key of the taxonomy to query - * @param listOfItems the list of taxonomy fields - * Example: If you want to retrieve entries with the color taxonomy applied and linked to the term red and/or yellow. - * - * String key = "taxonomies.taxonomy_uid"; - * String[] listOfItem = {"term_uid1", "term_uid2"}; - * taxonomy.in(key, listOfItem); - * taxonomy.query(query).find(new TaxonomyCallback() { - * @Override public void onFailure(Request request, ResponseBody errorMessage) { - * System.out.println("Failing API call : " + errorMessage.toString()); + * OR Operator : *

- * } - * @Override public void onResponse(ResponseBody response) { - * System.out.println("Response : " + response.toString()); + * Get all entries for a specific taxonomy that satisfy at least one of the given conditions provided in the “$or” query. *

- * } - * }); - * + * Your query should be as follows: + *

+ *

+     *
+     * { $or: [
+     * { "taxonomies.taxonomy_uid_1" : "term_uid1" },
+     * { "taxonomies.taxonomy_uid_2" : "term_uid2" }
+     * ]}
+     *
+     * 
+ * Example: If you want to retrieve entries with either the color or size taxonomy applied and linked to the terms yellow and small, respectively. + *
+ *
+     *
+     * {$or: [
+     * { "taxonomies.color" : "yellow" },
+     * { "taxonomies.size" : "small" }
+     * ]}
+     *
+     *
+     * 
+ * + * @param listOfItems + * @return */ - public Taxonomy in(@NotNull String key, @NotNull String[] listOfItems) { - HashMap param = new HashMap<>(); - param.put("$in", listOfItems); - this.query.put(key, param); - return this; - } - - public Taxonomy or(@NotNull List> listOfItems) { for (int i = 0; i < listOfItems.size(); i++) { HashMap param = listOfItems.get(i); - if (i > 0) { this.query.put("$or", listOfItems.toArray()); } - this.query.put("$or", param); } - return this; } + /** + * AND Operator : + *

+ * Get all entries for a specific taxonomy that satisfy all the conditions provided in the “$and” query. + *

+ * Your query should be as follows: + * + *

+     * {
+     * $and: [
+     * { "taxonomies.taxonomy_uid_1" : "term_uid1" },
+     * { "taxonomies.taxonomy_uid_2" : "term_uid2" }
+     * ]
+     * }
+     * 
+ * Example: If you want to retrieve entries with the color and computers taxonomies applied and linked to the terms red and laptop, respectively. + * + *
+     * {
+     * $and: [
+     * { "taxonomies.color" : "red" },
+     * { "taxonomies.computers" : "laptop" }
+     * ]
+     * }
+     * 
+ * + * @param listOfItems the list of items to that you want to include in the query string + * @return instance of the Taxonomy + */ public Taxonomy and(@NotNull List> listOfItems) { for (int i = 0; i < listOfItems.size(); i++) { HashMap param = listOfItems.get(i); - if (i > 0) { this.query.put("$and", listOfItems.toArray()); } - this.query.put("$and", param); } - return this; } - public Taxonomy exists(@NotNull String name, @NotNull Boolean value) { + /** + * Exists Operator : + *

+ * Get all entries for a specific taxonomy that if the value of the field, mentioned in the condition, exists. + *

+ * Your query should be as follows: + *

+     * {"taxonomies.taxonomy_uid" : { "$exists": true }}
+     * 
+ * Example: If you want to retrieve entries with the color taxonomy applied. + *
+     * {"taxonomies.color" : { "$exists": true }}
+     * 
+ * + * @param taxonomy the taxonomy + * @param value the value of the field + * @return instance of Taxonomy + */ + public Taxonomy exists(@NotNull String taxonomy, @NotNull Boolean value) { HashMap param = new HashMap<>(); param.put("$exists", value); - this.query.put(name, param); + this.query.put(taxonomy, param); return this; } + + /** + * Equal and Below Operator : + *

+ * Get all entries for a specific taxonomy that match a specific term and all its descendant terms, requiring only the target term and a specified level. + *

+ * Note: If you don't specify the level, the default behavior is to retrieve terms up to level 10. + * + *

{"taxonomies.taxonomy_uid" : { "$eq_below": "term_uid", "level" : 2}}
+ * + * Example: If you want to retrieve all entries with terms nested under blue, such as navy blue and sky blue, while also matching entries with the target term blue. + * + *
{"taxonomies.color" : { "$eq_below": "blue" }}
+ * + * @param taxonomy the taxonomy + * @param termsUid the term uid + * @return instance of Taxonomy + */ + public Taxonomy equalAndBelow(@NotNull String taxonomy, @NotNull String termsUid) { + HashMap param = new HashMap<>(); + param.put("$eq_below", termsUid); + this.query.put(taxonomy, param); + return this; + } + + /** + * Note: If you don't specify the level, the default behavior is to retrieve terms up to level 10. + * + * @param taxonomy the taxonomy + * @param termsUid the terms + * @param level the level to retrieve terms up to mentioned level + * @return instance of Taxonomy + */ + public Taxonomy equalAndBelowWithLevel(@NotNull String taxonomy, @NotNull String termsUid, @NotNull int level) { + Map innerMap = new HashMap<>(); + innerMap.put("$eq_below", termsUid + ", level: " + level); + this.query.put(taxonomy, innerMap); + return this; + } + + + /** + * Below Operator + *
+ *

+ * Get all entries for a specific taxonomy that match all of their descendant terms by specifying only the target term and a specific level. + *
+ * Note: If you don't specify the level, the default behavior is to retrieve terms up to level 10. + *
+ *

{"taxonomies.taxonomy_uid" : { "$below": "term_uid", "level" : 2}}
+ * + * Example: If you want to retrieve all entries containing terms nested under blue, such as navy blue and sky blue, but exclude entries that solely have the target term blue. + * + *
{"taxonomies.color" : { "$below": "blue" }}
+ * + * @param taxonomy the taxonomy + * @param termsUid the terms uid + * @return instance of Taxonomy + */ + public Taxonomy below(@NotNull String taxonomy, @NotNull String termsUid) { + HashMap param = new HashMap<>(); + param.put("$below", termsUid); + this.query.put(taxonomy, param); + return this; + } + + + /** + * Equal and Above Operator : + *

+ * Get all entries for a specific taxonomy that match a specific term and all its ancestor terms, requiring only the target term and a specified level. + * + * Note: If you don't specify the level, the default behavior is to retrieve terms up to level 10. + *

+ *

{"taxonomies.taxonomy_uid": { "$eq_above": "term_uid", "level": 2 }}
+ *

+ * Example: If you want to obtain all entries that include the term led and its parent term tv. + *

+ *

{"taxonomies.appliances": { "$eq_above": "led"}}
+ * + * @param taxonomy the taxonomy + * @param termUid the term uid + * @return instance of Taxonomy + */ + public Taxonomy equalAbove(@NotNull String taxonomy, @NotNull String termUid) { + Map innerMap = new HashMap<>(); + innerMap.put("$eq_above", termUid); + this.query.put(taxonomy, innerMap); + return this; + } + + + /** + * Above Operator : + *

+ * Get all entries for a specific taxonomy that match only the parent term(s) of a specified target term, excluding the target term itself. You can also specify a specific level. + *

+ * Note: If you don't specify the level, the default behavior is to retrieve terms up to level 10. + * + *

{ "taxonomies.taxonomy_uid": { "$above": "term_uid", "level": 2 }}
+ *

+ * Example: If you wish to match entries with the term tv but exclude the target term led. + * + *

{"taxonomies.appliances": { "$above": "led" }}
+ * + * @param taxonomy the taxonomy + * @param termUid the term uid + * @return instance of {@link Taxonomy} + */ + public Taxonomy above(@NotNull String taxonomy, @NotNull String termUid) { + Map innerMap = new HashMap<>(); + innerMap.put("$above", termUid); + this.query.put(taxonomy, innerMap); + return this; + } + + /** - * Make request call. + * To verify the payload * - * @return the call + * @return instance of Call */ - Call makeRequest() { + protected Call makeRequest() { HashMap map = new HashMap<>(); map.put("query", query); return this.service.getTaxonomy(this.headers, map); diff --git a/src/test/java/com/contentstack/sdk/Credentials.java b/src/test/java/com/contentstack/sdk/Credentials.java index 33d6e556..7a01db0f 100644 --- a/src/test/java/com/contentstack/sdk/Credentials.java +++ b/src/test/java/com/contentstack/sdk/Credentials.java @@ -71,7 +71,6 @@ public static Stack getStack() { Config config = new Config(); config.setHost(HOST); stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENVIRONMENT, config); - System.out.println(stack); } catch (IllegalAccessException e) { throw new RuntimeException(e); } diff --git a/src/test/java/com/contentstack/sdk/TaxonomyTest.java b/src/test/java/com/contentstack/sdk/TaxonomyTest.java index fec99319..91d5f5d6 100644 --- a/src/test/java/com/contentstack/sdk/TaxonomyTest.java +++ b/src/test/java/com/contentstack/sdk/TaxonomyTest.java @@ -1,13 +1,14 @@ package com.contentstack.sdk; +import okhttp3.HttpUrl; import okhttp3.Request; -import okhttp3.ResponseBody; -import org.json.JSONObject; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -22,88 +23,102 @@ void testInstance() { } @Test - void testInOperator() { - HashMap query = new HashMap<>(); - query.put("taxonomies.taxonomy_uid", new HashMap() {{ - put("$in", new String[]{"term_uid1", "term_uid2"}); - }}); - - stack.taxonomy().query(query).find(new TaxonomyCallback() { - @Override - public void onFailure(Request request, ResponseBody errorMessage) { - System.out.println("Failing API call : " + errorMessage.toString()); - - } - - @Override - public void onResponse(ResponseBody response) { - System.out.println("Response : " + response.toString()); - - } - }); - } - - - @Test - void testUnitInOperator() { - HashMap query = new HashMap<>(); - query.put("taxonomies.taxonomy_uid", new HashMap() {{ - put("$in", new String[]{"term_uid1", "term_uid2"}); - }}); + void operationIn() { Taxonomy taxonomy = stack.taxonomy(); - taxonomy.query(query); - Request req = taxonomy.makeRequest().request(); + String[] listOfItem = {"red", "yellow"}; + Request req = taxonomy.in("taxonomies.color", listOfItem).makeRequest().request(); + Assertions.assertEquals(3, req.headers().size()); - Assertions.assertEquals("GET", req.method().toString(), "test method are being passed though payload"); + Assertions.assertEquals("GET", req.method()); Assertions.assertEquals("cdn.contentstack.io", req.url().host()); - Assertions.assertNull(req.url().encodedFragment(), "We do not expect any fragment"); Assertions.assertEquals("/v3/taxonomies/entries", req.url().encodedPath()); - Assertions.assertEquals(3, Arrays.stream(req.url().encodedPathSegments().stream().toArray()).count()); - Assertions.assertNotNull(req.url().query()); - Assertions.assertNotNull(req.url().encodedQuery()); Assertions.assertEquals("[query]", req.url().queryParameterNames().toString()); } + @Test - void testUnitINOperator() { + void operationOr() { Taxonomy taxonomy = stack.taxonomy(); - String key = "taxonomies.taxonomy_uid"; - String[] listOfItem = {"term_uid1", "term_uid2"}; - taxonomy.in(key, listOfItem); + + List> listOfItems = new ArrayList<>(); + HashMap items = new HashMap<>(); + items.put("taxonomies.taxonomy_uid_1", "term_uid1"); + items.put("taxonomies.taxonomy_uid_2", "term_uid2"); + listOfItems.add(items); + taxonomy.or(listOfItems); Request req = taxonomy.makeRequest().request(); - Assertions.assertEquals(3, req.headers().size()); - Assertions.assertEquals("GET", req.method().toString(), "test method are being passed though payload"); - Assertions.assertEquals("cdn.contentstack.io", req.url().host()); - Assertions.assertNull(req.url().encodedFragment(), "We do not expect any fragment"); - Assertions.assertEquals("/v3/taxonomies/entries", req.url().encodedPath()); - Assertions.assertEquals(3, Arrays.stream(req.url().encodedPathSegments().stream().toArray()).count()); - Assertions.assertNotNull(req.url().query()); - Assertions.assertNotNull(req.url().encodedQuery()); + Assertions.assertEquals("[query]", req.url().queryParameterNames().toString()); + } + public static String decodeUrl(HttpUrl encodedUrl) { + String decodedUrl = null; + try { + decodedUrl = URLDecoder.decode(encodedUrl.toString(), StandardCharsets.UTF_8.toString()); + return decodedUrl; + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); // Handle the exception according to your requirements + } + return decodedUrl; + } @Test - void testUnitOr() { + void operatorAnd() { Taxonomy taxonomy = stack.taxonomy(); - List> listOfItems = new ArrayList<>(); HashMap items = new HashMap<>(); items.put("taxonomies.taxonomy_uid_1", "term_uid1"); items.put("taxonomies.taxonomy_uid_2", "term_uid2"); listOfItems.add(items); + taxonomy.and(listOfItems); - taxonomy.or(listOfItems); Request req = taxonomy.makeRequest().request(); - Assertions.assertEquals(3, req.headers().size()); - Assertions.assertEquals("GET", req.method().toString(), "test method are being passed though payload"); - Assertions.assertEquals("cdn.contentstack.io", req.url().host()); - Assertions.assertNull(req.url().encodedFragment(), "We do not expect any fragment"); - Assertions.assertEquals("/v3/taxonomies/entries", req.url().encodedPath()); - Assertions.assertEquals(3, Arrays.stream(req.url().encodedPathSegments().stream().toArray()).count()); - Assertions.assertNotNull(req.url().query()); - Assertions.assertNotNull(req.url().encodedQuery()); - Assertions.assertEquals("[query]", req.url().queryParameterNames().toString()); + } + + + @Test + void operationExists() { + // create instance of taxonomy + Taxonomy taxonomy = stack.taxonomy().exists("listOfItems", true); + Request req = taxonomy.makeRequest().request(); + Assertions.assertEquals("query={$or={taxonomies.taxonomy_uid_2=term_uid2, taxonomies.taxonomy_uid_1=term_uid1}}", req.url().query()); + } + + + @Test + void operationEqualAndBelow() { + // create instance of taxonomy + Taxonomy taxonomy = stack.taxonomy().equalAndBelow("listOfItems", "uid1"); + Request req = taxonomy.makeRequest().request(); + Assertions.assertEquals("query={$or={taxonomies.taxonomy_uid_2=term_uid2, taxonomies.taxonomy_uid_1=term_uid1}}", req.url().query()); + } + + + @Test + void operationBelow() { + Taxonomy taxonomy = stack.taxonomy().equalAndBelowWithLevel("listOfItems", "uid1", 3); + Request req = taxonomy.makeRequest().request(); + Assertions.assertEquals("query={$or={taxonomies.taxonomy_uid_2=term_uid2, taxonomies.taxonomy_uid_1=term_uid1}}", req.url().query()); + + } + + + @Test + void operationEqualAbove() { + Taxonomy taxonomy = stack.taxonomy().equalAbove("listOfItems", "uid1"); + Request req = taxonomy.makeRequest().request(); + Assertions.assertEquals("query={$or={taxonomies.taxonomy_uid_2=term_uid2, taxonomies.taxonomy_uid_1=term_uid1}}", req.url().query()); + + } + + + @Test + void above() { + Taxonomy taxonomy = stack.taxonomy().above("listOfItems", "uid1"); + Request req = taxonomy.makeRequest().request(); + Assertions.assertEquals("query={$or={taxonomies.taxonomy_uid_2=term_uid2, taxonomies.taxonomy_uid_1=term_uid1}}", req.url().query()); + } From 2343fb989e8cb76cbc3b1a28241b25f87291d2ab Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Fri, 15 Dec 2023 00:48:32 +0530 Subject: [PATCH 05/10] v1.12.3 - Taxonomy query support - Early Access Feature Support --- .../java/com/contentstack/sdk/APIService.java | 4 +- .../java/com/contentstack/sdk/Taxonomy.java | 102 ++++++++---------- .../contentstack/sdk/TaxonomyCallback.java | 19 ---- .../com/contentstack/sdk/TaxonomyTest.java | 85 +++++++-------- 4 files changed, 91 insertions(+), 119 deletions(-) diff --git a/src/main/java/com/contentstack/sdk/APIService.java b/src/main/java/com/contentstack/sdk/APIService.java index a14af8e5..5bf3462b 100644 --- a/src/main/java/com/contentstack/sdk/APIService.java +++ b/src/main/java/com/contentstack/sdk/APIService.java @@ -4,7 +4,7 @@ import retrofit2.Call; import retrofit2.http.GET; import retrofit2.http.HeaderMap; -import retrofit2.http.QueryMap; +import retrofit2.http.Query; import retrofit2.http.Url; import java.util.LinkedHashMap; @@ -23,5 +23,5 @@ Call getRequest( @GET("v3/taxonomies/entries") Call getTaxonomy( @HeaderMap Map headers, - @QueryMap Map query); + @Query("query") String query); } diff --git a/src/main/java/com/contentstack/sdk/Taxonomy.java b/src/main/java/com/contentstack/sdk/Taxonomy.java index 207607f9..308f4188 100644 --- a/src/main/java/com/contentstack/sdk/Taxonomy.java +++ b/src/main/java/com/contentstack/sdk/Taxonomy.java @@ -1,36 +1,47 @@ package com.contentstack.sdk; -import okhttp3.Request; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; +import org.json.JSONObject; import retrofit2.Call; -import retrofit2.Response; import java.io.IOException; -import java.util.*; -import java.util.stream.Collectors; +import java.util.LinkedHashMap; +import java.util.List; /** - * The type Taxonomy. - * - * @author Shailesh Mishra
Taxonomy :

Taxonomy, currently in the Early Access Phase simplifies the process of organizing content in your system, making it effortless to find and retrieve information. + * @author Shailesh Mishra + *
+ * Taxonomy : + * Taxonomy, currently in the Early Access Phase simplifies + * the process of organizing content in your system, making + * it effortless to find and retrieve information. + * @implSpec To implement the taxonomy use below code + *

+ *     {@code
+ *     Stack stack = Contentstack.stack("API_KEY", "DELIVERY_TOKEN", "ENVIRONMENT");
+ *     Taxonomy taxonomy = stack.taxonomy()
+ *     }
+ * 
+ * @see headers; protected APIService service; - protected HashMap query = new HashMap<>(); + protected JSONObject query = new JSONObject(); protected Config config; /** * Instantiates a new Taxonomy. * - * @param service the service - * @param config the config - * @param headers the headers + * @param service the service of type {@link APIService} + * @param config the config of type {@link Config} + * @param headers the headers of the {@link LinkedHashMap} */ - public Taxonomy(APIService service, Config config, LinkedHashMap headers) { + protected Taxonomy(APIService service, Config config, LinkedHashMap headers) { this.service = service; this.headers = headers; this.config = config; @@ -55,11 +66,10 @@ public Taxonomy(APIService service, Config config, LinkedHashMap * @param listOfItems the list of taxonomy fields * @return an instance of the Taxonomy with the specified conditions added to the query */ - public Taxonomy in(String taxonomy, String[] listOfItems) { - String formattedValues = Arrays.stream(listOfItems).map(value -> "\"" + value.trim() + "\"").collect(Collectors.joining(" , ")); - - String stringify = "{ \"$in\" : [" + formattedValues + "] }}"; - this.query.put(taxonomy, stringify); + public Taxonomy in(String taxonomy, List listOfItems) { + JSONObject innerObj = new JSONObject(); + innerObj.put("$in", listOfItems); + this.query.put(taxonomy, innerObj); return this; } @@ -79,29 +89,22 @@ public Taxonomy in(String taxonomy, String[] listOfItems) { * ]} * * - * Example: If you want to retrieve entries with either the color or size taxonomy applied and linked to the terms yellow and small, respectively. + * Example: If you want to retrieve entries with either the color or size taxonomy applied and linked to the terms yellow and small, respectively. *
*
      *
-     * {$or: [
+     * { $or: [
      * { "taxonomies.color" : "yellow" },
      * { "taxonomies.size" : "small" }
      * ]}
      *
-     *
      * 
* - * @param listOfItems - * @return + * @param listOfItems the list of items + * @return instance {@link Taxonomy} */ - public Taxonomy or(@NotNull List> listOfItems) { - for (int i = 0; i < listOfItems.size(); i++) { - HashMap param = listOfItems.get(i); - if (i > 0) { - this.query.put("$or", listOfItems.toArray()); - } - this.query.put("$or", param); - } + public Taxonomy or(@NotNull List listOfItems) { + this.query.put("$or", listOfItems); return this; } @@ -135,14 +138,8 @@ public Taxonomy or(@NotNull List> listOfItems) { * @param listOfItems the list of items to that you want to include in the query string * @return instance of the Taxonomy */ - public Taxonomy and(@NotNull List> listOfItems) { - for (int i = 0; i < listOfItems.size(); i++) { - HashMap param = listOfItems.get(i); - if (i > 0) { - this.query.put("$and", listOfItems.toArray()); - } - this.query.put("$and", param); - } + public Taxonomy and(@NotNull List listOfItems) { + this.query.put("$and", listOfItems.toString()); return this; } @@ -166,9 +163,9 @@ public Taxonomy and(@NotNull List> listOfItems) { * @return instance of Taxonomy */ public Taxonomy exists(@NotNull String taxonomy, @NotNull Boolean value) { - HashMap param = new HashMap<>(); - param.put("$exists", value); - this.query.put(taxonomy, param); + JSONObject json = new JSONObject(); + json.put("$exists", value); + this.query.put(taxonomy, json); return this; } @@ -191,7 +188,7 @@ public Taxonomy exists(@NotNull String taxonomy, @NotNull Boolean value) { * @return instance of Taxonomy */ public Taxonomy equalAndBelow(@NotNull String taxonomy, @NotNull String termsUid) { - HashMap param = new HashMap<>(); + JSONObject param = new JSONObject(); param.put("$eq_below", termsUid); this.query.put(taxonomy, param); return this; @@ -206,7 +203,7 @@ public Taxonomy equalAndBelow(@NotNull String taxonomy, @NotNull String termsUid * @return instance of Taxonomy */ public Taxonomy equalAndBelowWithLevel(@NotNull String taxonomy, @NotNull String termsUid, @NotNull int level) { - Map innerMap = new HashMap<>(); + JSONObject innerMap = new JSONObject(); innerMap.put("$eq_below", termsUid + ", level: " + level); this.query.put(taxonomy, innerMap); return this; @@ -232,7 +229,7 @@ public Taxonomy equalAndBelowWithLevel(@NotNull String taxonomy, @NotNull String * @return instance of Taxonomy */ public Taxonomy below(@NotNull String taxonomy, @NotNull String termsUid) { - HashMap param = new HashMap<>(); + JSONObject param = new JSONObject(); param.put("$below", termsUid); this.query.put(taxonomy, param); return this; @@ -257,7 +254,7 @@ public Taxonomy below(@NotNull String taxonomy, @NotNull String termsUid) { * @return instance of Taxonomy */ public Taxonomy equalAbove(@NotNull String taxonomy, @NotNull String termUid) { - Map innerMap = new HashMap<>(); + JSONObject innerMap = new JSONObject(); innerMap.put("$eq_above", termUid); this.query.put(taxonomy, innerMap); return this; @@ -282,7 +279,7 @@ public Taxonomy equalAbove(@NotNull String taxonomy, @NotNull String termUid) { * @return instance of {@link Taxonomy} */ public Taxonomy above(@NotNull String taxonomy, @NotNull String termUid) { - Map innerMap = new HashMap<>(); + JSONObject innerMap = new JSONObject(); innerMap.put("$above", termUid); this.query.put(taxonomy, innerMap); return this; @@ -295,9 +292,7 @@ public Taxonomy above(@NotNull String taxonomy, @NotNull String termUid) { * @return instance of Call */ protected Call makeRequest() { - HashMap map = new HashMap<>(); - map.put("query", query); - return this.service.getTaxonomy(this.headers, map); + return this.service.getTaxonomy(this.headers, this.query.toString()); } @@ -308,13 +303,8 @@ protected Call makeRequest() { */ public void find(TaxonomyCallback callback) { try { - Response response = makeRequest().execute(); - if (response.isSuccessful()) { - callback.onResponse(response.body()); - } else { - Request request = makeRequest().request(); - callback.onFailure(request, response.errorBody()); - } + ResponseBody response = makeRequest().execute().body(); + callback.onResponse(response); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/contentstack/sdk/TaxonomyCallback.java b/src/main/java/com/contentstack/sdk/TaxonomyCallback.java index 3de08db1..2a52fa89 100644 --- a/src/main/java/com/contentstack/sdk/TaxonomyCallback.java +++ b/src/main/java/com/contentstack/sdk/TaxonomyCallback.java @@ -1,28 +1,9 @@ package com.contentstack.sdk; -import okhttp3.Request; import okhttp3.ResponseBody; public interface TaxonomyCallback { - /** - * Called when the HTTP response was successfully returned by the remote server. The callback may - * proceed to read the response body. The response is still live until - * its response body is {@linkplain ResponseBody closed}. The recipient of the callback may - * consume the response body on another thread. - * - *

Note that transport-layer success (receiving a HTTP response code, headers and body) does - * not necessarily indicate application-layer success: {@code response} may still indicate an - * unhappy HTTP response code like 404 or 500. - */ void onResponse(ResponseBody response); - /** - * Called when the request could not be executed due to cancellation, a connectivity problem or - * timeout. Because networks can fail during an exchange, it is possible that the remote server - * accepted the request before the failure. - */ - void onFailure(Request request, ResponseBody errorMessage); - - } \ No newline at end of file diff --git a/src/test/java/com/contentstack/sdk/TaxonomyTest.java b/src/test/java/com/contentstack/sdk/TaxonomyTest.java index 91d5f5d6..e945348e 100644 --- a/src/test/java/com/contentstack/sdk/TaxonomyTest.java +++ b/src/test/java/com/contentstack/sdk/TaxonomyTest.java @@ -1,15 +1,11 @@ package com.contentstack.sdk; -import okhttp3.HttpUrl; import okhttp3.Request; +import org.json.JSONObject; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; @@ -25,99 +21,104 @@ void testInstance() { @Test void operationIn() { Taxonomy taxonomy = stack.taxonomy(); - String[] listOfItem = {"red", "yellow"}; - Request req = taxonomy.in("taxonomies.color", listOfItem).makeRequest().request(); - + List listOfItems = new ArrayList<>(); + listOfItems.add("red"); + listOfItems.add("yellow"); + Request req = taxonomy.in("taxonomies.color", listOfItems).makeRequest().request(); Assertions.assertEquals(3, req.headers().size()); Assertions.assertEquals("GET", req.method()); Assertions.assertEquals("cdn.contentstack.io", req.url().host()); Assertions.assertEquals("/v3/taxonomies/entries", req.url().encodedPath()); - Assertions.assertEquals("[query]", req.url().queryParameterNames().toString()); + Assertions.assertEquals("query={\"taxonomies.color\":{\"$in\":[\"red\",\"yellow\"]}}", req.url().query()); } @Test void operationOr() { + +// query={ $or: [ +// { "taxonomies.taxonomy_uid_1" : "term_uid1" }, +// { "taxonomies.taxonomy_uid_2" : "term_uid2" } +// ]} + Taxonomy taxonomy = stack.taxonomy(); - List> listOfItems = new ArrayList<>(); - HashMap items = new HashMap<>(); - items.put("taxonomies.taxonomy_uid_1", "term_uid1"); - items.put("taxonomies.taxonomy_uid_2", "term_uid2"); - listOfItems.add(items); + List listOfItems = new ArrayList<>(); + JSONObject item1 = new JSONObject(); + item1.put("taxonomies.color", "yellow"); + JSONObject item2 = new JSONObject(); + item2.put("taxonomies.size", "small"); + listOfItems.add(item1); + listOfItems.add(item2); taxonomy.or(listOfItems); Request req = taxonomy.makeRequest().request(); - Assertions.assertEquals("[query]", req.url().queryParameterNames().toString()); - - } + Assertions.assertEquals("query={\"$or\":[{\"taxonomies.color\":\"yellow\"},{\"taxonomies.size\":\"small\"}]}", req.url().query()); - public static String decodeUrl(HttpUrl encodedUrl) { - String decodedUrl = null; - try { - decodedUrl = URLDecoder.decode(encodedUrl.toString(), StandardCharsets.UTF_8.toString()); - return decodedUrl; - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); // Handle the exception according to your requirements - } - return decodedUrl; } @Test void operatorAnd() { Taxonomy taxonomy = stack.taxonomy(); - List> listOfItems = new ArrayList<>(); - HashMap items = new HashMap<>(); - items.put("taxonomies.taxonomy_uid_1", "term_uid1"); - items.put("taxonomies.taxonomy_uid_2", "term_uid2"); - listOfItems.add(items); + List listOfItems = new ArrayList<>(); + JSONObject items1 = new JSONObject(); + items1.put("taxonomies.color", "green"); + JSONObject items2 = new JSONObject(); + items2.put("taxonomies.computers", "laptop"); + listOfItems.add(items1); + listOfItems.add(items2); taxonomy.and(listOfItems); + // {$and: [{"taxonomies.color" : "green" }, { "taxonomies.computers" : "laptop" }]} Request req = taxonomy.makeRequest().request(); + Assertions.assertEquals("query={\"$and\":\"[{\\\"taxonomies.color\\\":\\\"green\\\"}, {\\\"taxonomies.computers\\\":\\\"laptop\\\"}]\"}", req.url().query()); } @Test void operationExists() { // create instance of taxonomy - Taxonomy taxonomy = stack.taxonomy().exists("listOfItems", true); + Taxonomy taxonomy = stack.taxonomy().exists("taxonomies.color", true); Request req = taxonomy.makeRequest().request(); - Assertions.assertEquals("query={$or={taxonomies.taxonomy_uid_2=term_uid2, taxonomies.taxonomy_uid_1=term_uid1}}", req.url().query()); + //{"taxonomies.color" : { "$exists": true }} + //{"taxonomies.color":{"$exists":true}} + Assertions.assertEquals("query={\"taxonomies.color\":{\"$exists\":true}}", req.url().query()); } @Test void operationEqualAndBelow() { // create instance of taxonomy - Taxonomy taxonomy = stack.taxonomy().equalAndBelow("listOfItems", "uid1"); + Taxonomy taxonomy = stack.taxonomy().equalAndBelow("taxonomies.color", "blue"); Request req = taxonomy.makeRequest().request(); - Assertions.assertEquals("query={$or={taxonomies.taxonomy_uid_2=term_uid2, taxonomies.taxonomy_uid_1=term_uid1}}", req.url().query()); + // {"taxonomies.color" : { "$eq_below": "blue" }} + Assertions.assertEquals("query={\"taxonomies.color\":{\"$eq_below\":\"blue\"}}", req.url().query()); } @Test - void operationBelow() { - Taxonomy taxonomy = stack.taxonomy().equalAndBelowWithLevel("listOfItems", "uid1", 3); + void operationBelowWithLevel() { + Taxonomy taxonomy = stack.taxonomy().equalAndBelowWithLevel("taxonomies.color", "blue", 3); Request req = taxonomy.makeRequest().request(); - Assertions.assertEquals("query={$or={taxonomies.taxonomy_uid_2=term_uid2, taxonomies.taxonomy_uid_1=term_uid1}}", req.url().query()); + Assertions.assertEquals("query={\"taxonomies.color\":{\"$eq_below\":\"blue, level: 3\"}}", req.url().query()); } @Test void operationEqualAbove() { - Taxonomy taxonomy = stack.taxonomy().equalAbove("listOfItems", "uid1"); + Taxonomy taxonomy = stack.taxonomy().equalAbove("taxonomies.appliances", "led"); Request req = taxonomy.makeRequest().request(); - Assertions.assertEquals("query={$or={taxonomies.taxonomy_uid_2=term_uid2, taxonomies.taxonomy_uid_1=term_uid1}}", req.url().query()); + Assertions.assertEquals("query={\"taxonomies.appliances\":{\"$eq_above\":\"led\"}}", req.url().query()); } @Test void above() { - Taxonomy taxonomy = stack.taxonomy().above("listOfItems", "uid1"); + Taxonomy taxonomy = stack.taxonomy().above("taxonomies.appliances", "led"); Request req = taxonomy.makeRequest().request(); - Assertions.assertEquals("query={$or={taxonomies.taxonomy_uid_2=term_uid2, taxonomies.taxonomy_uid_1=term_uid1}}", req.url().query()); + Assertions.assertEquals("query={\"taxonomies.appliances\":{\"$above\":\"led\"}}", req.url().query()); } From 5539c4efb9e1b38189bec8e2e13d07f1689fd51a Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Fri, 15 Dec 2023 01:15:04 +0530 Subject: [PATCH 06/10] v1.12.3 - Taxonomy query support - Early Access Feature Support --- .../com/contentstack/sdk/CSHttpConnection.java | 1 - .../java/com/contentstack/sdk/Taxonomy.java | 18 ++++++++++++++++-- .../com/contentstack/sdk/TaxonomyCallback.java | 3 ++- .../com/contentstack/sdk/TaxonomyTest.java | 12 +++++++++++- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/contentstack/sdk/CSHttpConnection.java b/src/main/java/com/contentstack/sdk/CSHttpConnection.java index 1bae8449..9eda41c0 100644 --- a/src/main/java/com/contentstack/sdk/CSHttpConnection.java +++ b/src/main/java/com/contentstack/sdk/CSHttpConnection.java @@ -261,7 +261,6 @@ void handleJSONObject(JSONArray arrayEntry, JSONObject jsonObj, int idx) { } void setError(String errResp) { - logger.info(errResp); responseJSON = new JSONObject(errResp); // Parse error string to JSONObject responseJSON.put(ERROR_MESSAGE, responseJSON.optString(ERROR_MESSAGE)); responseJSON.put(ERROR_CODE, responseJSON.optString(ERROR_CODE)); diff --git a/src/main/java/com/contentstack/sdk/Taxonomy.java b/src/main/java/com/contentstack/sdk/Taxonomy.java index 308f4188..cdb7da2e 100644 --- a/src/main/java/com/contentstack/sdk/Taxonomy.java +++ b/src/main/java/com/contentstack/sdk/Taxonomy.java @@ -4,6 +4,7 @@ import org.jetbrains.annotations.NotNull; import org.json.JSONObject; import retrofit2.Call; +import retrofit2.Response; import java.io.IOException; import java.util.LinkedHashMap; @@ -303,8 +304,21 @@ protected Call makeRequest() { */ public void find(TaxonomyCallback callback) { try { - ResponseBody response = makeRequest().execute().body(); - callback.onResponse(response); + Response response = makeRequest().execute(); + + if (response.isSuccessful()) { + JSONObject responseJSON = new JSONObject(response.body().string()); + callback.onResponse(responseJSON, null); + } else { + JSONObject responseJSON = new JSONObject(response.errorBody().string()); + Error error = new Error(); + error.setErrorMessage(responseJSON.optString("error_message")); + error.setErrorCode(responseJSON.optInt("error_code")); + error.setErrorDetail(responseJSON.optString("errors")); + + callback.onResponse(null, error); + } + } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/main/java/com/contentstack/sdk/TaxonomyCallback.java b/src/main/java/com/contentstack/sdk/TaxonomyCallback.java index 2a52fa89..8bf88217 100644 --- a/src/main/java/com/contentstack/sdk/TaxonomyCallback.java +++ b/src/main/java/com/contentstack/sdk/TaxonomyCallback.java @@ -1,9 +1,10 @@ package com.contentstack.sdk; import okhttp3.ResponseBody; +import org.json.JSONObject; public interface TaxonomyCallback { - void onResponse(ResponseBody response); + void onResponse(JSONObject response, Error error); } \ No newline at end of file diff --git a/src/test/java/com/contentstack/sdk/TaxonomyTest.java b/src/test/java/com/contentstack/sdk/TaxonomyTest.java index e945348e..126e57d9 100644 --- a/src/test/java/com/contentstack/sdk/TaxonomyTest.java +++ b/src/test/java/com/contentstack/sdk/TaxonomyTest.java @@ -1,6 +1,7 @@ package com.contentstack.sdk; import okhttp3.Request; +import okhttp3.ResponseBody; import org.json.JSONObject; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -25,7 +26,7 @@ void operationIn() { listOfItems.add("red"); listOfItems.add("yellow"); Request req = taxonomy.in("taxonomies.color", listOfItems).makeRequest().request(); - Assertions.assertEquals(3, req.headers().size()); + //Assertions.assertEquals(3, req.headers().size()); Assertions.assertEquals("GET", req.method()); Assertions.assertEquals("cdn.contentstack.io", req.url().host()); Assertions.assertEquals("/v3/taxonomies/entries", req.url().encodedPath()); @@ -119,7 +120,16 @@ void above() { Taxonomy taxonomy = stack.taxonomy().above("taxonomies.appliances", "led"); Request req = taxonomy.makeRequest().request(); Assertions.assertEquals("query={\"taxonomies.appliances\":{\"$above\":\"led\"}}", req.url().query()); + } + @Test + void aboveAPI() { + Taxonomy taxonomy = stack.taxonomy().above("taxonomies.appliances", "led"); + taxonomy.find((response, error) -> { + System.out.println("Successful: " + response); + System.out.println("Error: " + error.errorMessage); + }); + //Assertions.assertEquals("query={\"taxonomies.appliances\":{\"$above\":\"led\"}}", req.url().query()); } From 5c0bf304b3dff112650e754bbd03292fb8326bb7 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Fri, 15 Dec 2023 12:59:17 +0530 Subject: [PATCH 07/10] v1.12.3 - Taxonomy query support - Early Access Feature Support --- .../java/com/contentstack/sdk/Constants.java | 2 -- .../java/com/contentstack/sdk/Credentials.java | 16 +--------------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/src/main/java/com/contentstack/sdk/Constants.java b/src/main/java/com/contentstack/sdk/Constants.java index 6a31923d..24917225 100644 --- a/src/main/java/com/contentstack/sdk/Constants.java +++ b/src/main/java/com/contentstack/sdk/Constants.java @@ -26,8 +26,6 @@ public class Constants { protected static final String CONTENT_TYPE_UID = "content_type_uid"; protected static final String ENTRY_UID = "entry_uid"; protected static final String LIVE_PREVIEW = "live_preview"; - - protected static final String TaxonomyPath = "/taxonomies/entries?query"; protected static final String SYNCHRONISATION = "stacks/sync"; // Errors protected static final String ERROR_CODE = "error_code"; diff --git a/src/test/java/com/contentstack/sdk/Credentials.java b/src/test/java/com/contentstack/sdk/Credentials.java index 7a01db0f..ea94a290 100644 --- a/src/test/java/com/contentstack/sdk/Credentials.java +++ b/src/test/java/com/contentstack/sdk/Credentials.java @@ -13,18 +13,13 @@ public class Credentials { private static String envChecker() { String githubActions = System.getenv("GITHUB_ACTIONS"); if (githubActions != null && githubActions.equals("true")) { - System.out.println("Tests are running in GitHub Actions environment."); - String mySecretKey = System.getenv("API_KEY"); return "GitHub"; } else { - System.out.println("Tests are running in a local environment."); return "local"; } } public static Dotenv getEnv() { - String currentDirectory = System.getProperty("user.dir"); - File envFile = new File(currentDirectory, "env"); env = Dotenv.configure() .directory("src/test/resources") .filename("env") // instead of '.env', use 'env' @@ -32,15 +27,7 @@ public static Dotenv getEnv() { try { env = Dotenv.load(); } catch (DotenvException ex) { - System.out.println("Could not load from local .env"); -// File envFile = new File(currentDirectory, ".env"); -// try { -// // Create .env file in the current directory -// envFile.createNewFile(); -// } catch (IOException e) { -// System.err.println("An error occurred while creating .env file."); -// e.printStackTrace(); -// } + System.out.println("Could not load.env"); } return env; } @@ -64,7 +51,6 @@ private Credentials() throws AccessException { public static Stack getStack() { if (stack == null) { var envCheck = envChecker(); - System.out.println("idendified env file detected " + envCheck); synchronized (Credentials.class) { if (stack == null) { try { From 5af4976c30fd14710abebc3df1b3cf8c56d0af75 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Fri, 15 Dec 2023 13:24:47 +0530 Subject: [PATCH 08/10] v1.12.3 - Taxonomy query support - Early Access Feature Support --- src/test/java/com/contentstack/sdk/Credentials.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/contentstack/sdk/Credentials.java b/src/test/java/com/contentstack/sdk/Credentials.java index ea94a290..ee5ab196 100644 --- a/src/test/java/com/contentstack/sdk/Credentials.java +++ b/src/test/java/com/contentstack/sdk/Credentials.java @@ -2,9 +2,7 @@ import io.github.cdimascio.dotenv.Dotenv; import io.github.cdimascio.dotenv.DotenvException; -import lombok.var; -import java.io.File; import java.rmi.AccessException; public class Credentials { @@ -27,7 +25,7 @@ public static Dotenv getEnv() { try { env = Dotenv.load(); } catch (DotenvException ex) { - System.out.println("Could not load.env"); + ex.getLocalizedMessage(); } return env; } @@ -50,7 +48,7 @@ private Credentials() throws AccessException { public static Stack getStack() { if (stack == null) { - var envCheck = envChecker(); + envChecker(); synchronized (Credentials.class) { if (stack == null) { try { From 74b6813ce3b198236539eb1a4330ba6a7651935a Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Fri, 15 Dec 2023 13:27:41 +0530 Subject: [PATCH 09/10] v1.12.3 - Taxonomy query support - Early Access Feature Support --- src/test/java/com/contentstack/sdk/TestAsset.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/com/contentstack/sdk/TestAsset.java b/src/test/java/com/contentstack/sdk/TestAsset.java index accc173f..2f77679e 100644 --- a/src/test/java/com/contentstack/sdk/TestAsset.java +++ b/src/test/java/com/contentstack/sdk/TestAsset.java @@ -18,8 +18,6 @@ private void envChecker() { String githubActions = System.getenv("GITHUB_ACTIONS"); if (githubActions != null && githubActions.equals("true")) { System.out.println("Tests are running in GitHub Actions environment."); - String mySecretKey = System.getenv("API_KEY"); - System.out.println("My Secret Key: " + mySecretKey); } else { System.out.println("Tests are running in a local environment."); } From 4c25e36fbfc341573455f04ec11df3f364398ac8 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Fri, 15 Dec 2023 13:35:25 +0530 Subject: [PATCH 10/10] v1.12.3 - Taxonomy query support - Early Access Feature Support --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7976ca8..8b000c38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,9 @@ ## v1.13.0 -### Date: 17-Nov-2023 +### Date: 18-Dec-2023 +- Taxonomy Query Support - Updated Latest version of Utils SDK to 1.2.6 - Snyk Issues fixed - Updated dependencies