From d9dffd445c8cc75d35983809c98b13b970c45610 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Sat, 9 Sep 2023 00:09:37 +0530 Subject: [PATCH 1/7] Taxonomy and Terms --- pom.xml | 9 +- .../contentstack/cms/BaseImplementation.java | 14 +- .../cms/core/CMARuntimeException.java | 11 +- .../cms/organization/Organization.java | 26 +- .../com/contentstack/cms/stack/Alias.java | 84 ++++-- .../com/contentstack/cms/stack/Asset.java | 47 ++- .../com/contentstack/cms/stack/AuditLog.java | 37 ++- .../com/contentstack/cms/stack/Branch.java | 2 +- .../contentstack/cms/stack/BulkOperation.java | 6 +- .../com/contentstack/cms/stack/Compare.java | 2 +- .../contentstack/cms/stack/ContentType.java | 183 +++++++----- .../contentstack/cms/stack/DeliveryToken.java | 74 +++-- .../com/contentstack/cms/stack/Entry.java | 60 ++-- .../contentstack/cms/stack/Environment.java | 70 +++-- .../contentstack/cms/stack/Extensions.java | 73 +++-- .../com/contentstack/cms/stack/Folder.java | 101 ++++--- .../contentstack/cms/stack/GlobalField.java | 62 +++- .../com/contentstack/cms/stack/Label.java | 60 +++- .../com/contentstack/cms/stack/Locale.java | 67 +++-- .../cms/stack/ManagementToken.java | 45 ++- .../com/contentstack/cms/stack/Merge.java | 2 +- .../contentstack/cms/stack/PublishQueue.java | 87 ++++-- .../com/contentstack/cms/stack/Release.java | 79 +++-- .../contentstack/cms/stack/ReleaseItem.java | 69 ++++- .../com/contentstack/cms/stack/Roles.java | 111 ++++--- .../com/contentstack/cms/stack/Stack.java | 131 ++++++--- .../com/contentstack/cms/stack/Taxonomy.java | 254 ++++++++++++++++ .../cms/stack/TaxonomyService.java | 50 ++++ .../com/contentstack/cms/stack/Terms.java | 277 ++++++++++++++++++ .../com/contentstack/cms/stack/Webhook.java | 81 +++-- .../com/contentstack/cms/stack/Workflow.java | 110 ++++--- .../cms/ContentstackUnitTest.java | 6 +- .../cms/organization/OrgUnitTests.java | 9 - .../contentstack/cms/stack/AssetAPITest.java | 2 +- .../contentstack/cms/stack/TaxonomyTest.java | 269 +++++++++++++++++ 35 files changed, 2003 insertions(+), 567 deletions(-) create mode 100644 src/main/java/com/contentstack/cms/stack/Taxonomy.java create mode 100644 src/main/java/com/contentstack/cms/stack/TaxonomyService.java create mode 100644 src/main/java/com/contentstack/cms/stack/Terms.java create mode 100644 src/test/java/com/contentstack/cms/stack/TaxonomyTest.java diff --git a/pom.xml b/pom.xml index 1a88368f..e0960a9a 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ cms jar contentstack-management-java - 1.0.0 + 1.1.0 Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an API-first approach @@ -165,6 +165,12 @@ ${junit-vintage-engine.version} test + + org.mockito + mockito-core + 2.8.9 + test + com.googlecode.json-simple json-simple @@ -328,6 +334,7 @@ org.apache.maven.plugins maven-pdf-plugin + 1.6.1 pdf diff --git a/src/main/java/com/contentstack/cms/BaseImplementation.java b/src/main/java/com/contentstack/cms/BaseImplementation.java index 766a966a..6246f887 100644 --- a/src/main/java/com/contentstack/cms/BaseImplementation.java +++ b/src/main/java/com/contentstack/cms/BaseImplementation.java @@ -7,12 +7,11 @@ /** * The interface @{@link BaseImplementation} */ -public interface BaseImplementation { +public interface BaseImplementation { /** * The function adds a parameter to a collection using a key-value pair. * - * @param the type of the parameter * @param key A string representing the key of the parameter. It cannot be * null and must be * provided as a non-null value. @@ -21,12 +20,11 @@ public interface BaseImplementation { * object as its value. * @return The method is returning an object of type T. */ - T addParam(@NotNull String key, @NotNull Object value); + T addParam(@NotNull String key, @NotNull Object value); /** * The function adds a header with a key-value pair to a request. * - * @param the type of the parameter * @param key The key parameter is a string that represents the name or * identifier of the header. * It is used to specify the type of information being sent in the @@ -35,30 +33,28 @@ public interface BaseImplementation { * header. * @return The method is returning an object of type T. */ - T addHeader(@NotNull String key, @NotNull String value); + T addHeader(@NotNull String key, @NotNull String value); /** * The function "addParams" takes a HashMap of String keys and Object values as * input and returns a * generic type T. * - * @param the type of the parameter * @param params The "params" parameter is a HashMap that maps String keys to * Object values. It is * annotated with @NotNull, indicating that it cannot be null. * @return The method is returning an object of type T. */ - T addParams(@NotNull HashMap params); + T addParams(@NotNull HashMap params); /** * The function adds headers to a HashMap. * - * @param the type of the parameter * @param headers A HashMap containing key-value pairs of headers, where the key * is a String * representing the header name and the value is a String * representing the header value. * @return The method is returning an object of type T. */ - T addHeaders(@NotNull HashMap headers); + T addHeaders(@NotNull HashMap headers); } diff --git a/src/main/java/com/contentstack/cms/core/CMARuntimeException.java b/src/main/java/com/contentstack/cms/core/CMARuntimeException.java index b3083209..64cf8bc4 100644 --- a/src/main/java/com/contentstack/cms/core/CMARuntimeException.java +++ b/src/main/java/com/contentstack/cms/core/CMARuntimeException.java @@ -8,9 +8,14 @@ * @since 2022-10-20 */ public class CMARuntimeException extends Exception { - // The code `public CMARuntimeException(String message) { super(message); }` is - // defining a constructor - // for the `CMARuntimeException` class. + + /** + * The code `public CMARuntimeException(String message) { super(message); }` is + * defining a constructor + * for the `CMARuntimeException` class. + * + * @param message the message for exception + */ public CMARuntimeException(String message) { super(message); } diff --git a/src/main/java/com/contentstack/cms/organization/Organization.java b/src/main/java/com/contentstack/cms/organization/Organization.java index 21cd4f6a..52fb13b6 100644 --- a/src/main/java/com/contentstack/cms/organization/Organization.java +++ b/src/main/java/com/contentstack/cms/organization/Organization.java @@ -1,5 +1,6 @@ package com.contentstack.cms.organization; +import com.contentstack.cms.BaseImplementation; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; import org.json.simple.JSONObject; @@ -19,7 +20,7 @@ * @version v0.1.0 * @since 2022-10-20 */ -public class Organization { +public class Organization implements BaseImplementation { private final OrganizationService service; protected HashMap headers; @@ -65,6 +66,18 @@ public Organization addHeader(@NotNull String key, @NotNull String value) { return this; } + @Override + public Organization addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + @Override + public Organization addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; + } + /** * Sets header for the request * @@ -89,17 +102,6 @@ protected Organization clearParams() { return this; } - /** - * Sets header for the request - * - * @param key header key for the request - * @return instance of {@link Organization} - */ - public Organization removeParam(@NotNull String key) { - this.params.remove(key); - return this; - } - /** * Gets all organizations.
* The Get all organizations call lists all organizations related to the diff --git a/src/main/java/com/contentstack/cms/stack/Alias.java b/src/main/java/com/contentstack/cms/stack/Alias.java index feafe653..b8ebca31 100644 --- a/src/main/java/com/contentstack/cms/stack/Alias.java +++ b/src/main/java/com/contentstack/cms/stack/Alias.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; import org.json.simple.JSONObject; @@ -18,12 +19,12 @@ * @author ishaileshmishra * @version v0.1.0 * @see About - * Aliases - * + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#aliases">About + * Aliases + * * @since 2022-10-20 */ -public class Alias { +public class Alias implements BaseImplementation { protected final Map headers; protected Map params; @@ -57,21 +58,24 @@ protected Alias(Retrofit instance, String aliasUid) { /** * The addHeader function adds a key-value pair to the headers map. - * + * * @param key A string representing the key of the header. This is used to * identify the header when * retrieving or modifying it. * @param value The value parameter is of type Object, which means it can accept * any type of object as * its value. + * @return instance of the `Alias` class */ - public void addHeader(@NotNull String key, @NotNull Object value) { + @Override + public Alias addHeader(@NotNull String key, @NotNull String value) { this.headers.put(key, value); + return this; } /** * The addParam function adds a key-value pair to a map. - * + * * @param key A string representing the key for the parameter. It is annotated * with @NotNull, * indicating that it cannot be null. @@ -79,14 +83,45 @@ public void addHeader(@NotNull String key, @NotNull Object value) { * any type of object as * its value. */ - public void addParam(@NotNull String key, @NotNull Object value) { + @Override + public Alias addParam(@NotNull String key, @NotNull Object value) { this.params.put(key, value); + return this; + } + + /** + * The addParam function adds a key-value pair to Alias + * + * @param params The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of {@link Alias} + */ + @Override + public Alias addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + /** + * The removeParam function removes a key-value pair from + * + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of Alias + */ + @Override + public Alias addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; } /** * The removeParam function removes a parameter from a map using the specified * key. - * + * * @param key The parameter "key" is of type String and is used to specify the * key of the parameter * that needs to be removed from the "params" collection. @@ -107,9 +142,9 @@ protected void clearParams() { * @return Call * @author ishaileshmishra * @see Get - * all - * aliases + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-aliases">Get + * all + * aliases * @since 2022-10-20 */ public Call find() { @@ -122,12 +157,12 @@ public Call find() { * @return Call * @author ishaileshmishra * @see - * Get a single branch + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-a-single-branch"> + * Get a single branch * @since 2022-10-20 */ public Call fetch() { - Objects.requireNonNull(this.uid,"Global Field Uid can not be null or empty"); + Objects.requireNonNull(this.uid, "Global Field Uid can not be null or empty"); return this.service.single(this.headers, this.uid); } @@ -142,15 +177,14 @@ public Call fetch() { * “Body” section, you need to provide * the UID of the new target branch that will be associated with the alias. * - * @param body - * the request body + * @param body the request body * @return Call * @author ishaileshmishra * @see Update - * a - * branch - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#assign-or-update-an-alias">Update + * a + * branch + * @see #addHeader(String, String) to add headers * @since 2022-10-20 */ public Call update(@NotNull JSONObject body) { @@ -169,14 +203,14 @@ public Call update(@NotNull JSONObject body) { * @return Call * @author ishaileshmishra * @see Delete - * a branch - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-an-alias">Delete + * a branch + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query params * @since 2022-10-20 */ public Call delete() { - Objects.requireNonNull(this.uid,"Global Field Uid can not be null or empty"); + Objects.requireNonNull(this.uid, "Global Field Uid can not be null or empty"); return this.service.delete(this.headers, this.uid, this.params); } diff --git a/src/main/java/com/contentstack/cms/stack/Asset.java b/src/main/java/com/contentstack/cms/stack/Asset.java index 5aa836e3..2f106282 100644 --- a/src/main/java/com/contentstack/cms/stack/Asset.java +++ b/src/main/java/com/contentstack/cms/stack/Asset.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import okhttp3.MediaType; import okhttp3.MultipartBody; import okhttp3.RequestBody; @@ -24,7 +25,7 @@ * @author ishaileshmishra * @since 2022-10-20 */ -public class Asset { +public class Asset implements BaseImplementation { protected final Map headers; protected Map params; @@ -50,26 +51,62 @@ protected Asset(Retrofit instance, Map header, String uid) { } - public Asset addParam(String key, Object value) { + /** + * @param key A string representing the key of the parameter. It cannot be + * null and must be + * provided as a non-null value. + * @param value The "value" parameter is of type Object, which means it can + * accept any type of + * object as its value. + * @return instance of Asset + */ + public Asset addParam(@NotNull String key, @NotNull Object value) { this.params.put(key, value); return this; } - public Asset addHeader(String key, String value) { + /** + * @param key The key parameter is a string that represents the name or + * identifier of the header. + * It is used to specify the type of information being sent in the + * header. + * @param value The value parameter is a string that represents the value of the + * header. + * @return instance of Asset + */ + public Asset addHeader(@NotNull String key, @NotNull String value) { this.headers.put(key, value); return this; } - public Asset addHeaders(HashMap headers) { + /** + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of Asset + */ + public Asset addHeaders(@NotNull HashMap headers) { this.headers.putAll(headers); return this; } - public Asset addParams(HashMap headers) { + + /** + * @param headers The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of Asset + */ + public Asset addParams(@NotNull HashMap headers) { this.params.putAll(headers); return this; } + + /** + * clears all params in the request + */ protected void clearParams() { this.params.clear(); } diff --git a/src/main/java/com/contentstack/cms/stack/AuditLog.java b/src/main/java/com/contentstack/cms/stack/AuditLog.java index 2700923e..6e7b30d2 100644 --- a/src/main/java/com/contentstack/cms/stack/AuditLog.java +++ b/src/main/java/com/contentstack/cms/stack/AuditLog.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; import retrofit2.Call; @@ -29,7 +30,7 @@ * @version v0.1.0 * @since 2022-10-22 */ -public class AuditLog { +public class AuditLog implements BaseImplementation { protected final AuditLogService service; protected HashMap headers; @@ -49,24 +50,28 @@ protected AuditLog(Retrofit retrofit, String uid) { this.service = retrofit.create(AuditLogService.class); } - /** - * Sets header for the request - * - * @param key header key for the request - * @param value header value for the request - */ - public void addHeader(@NotNull String key, @NotNull Object value) { + @Override + public AuditLog addParam(@NotNull String key, @NotNull Object value) { + this.params.put(key, value); + return this; + } + + @Override + public AuditLog addHeader(@NotNull String key, @NotNull String value) { this.headers.put(key, value); + return this; } - /** - * Sets header for the request - * - * @param key header key for the request - * @param value header value for the request - */ - public void addParam(@NotNull String key, @NotNull Object value) { - this.params.put(key, value); + @Override + public AuditLog addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + @Override + public AuditLog addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; } /** diff --git a/src/main/java/com/contentstack/cms/stack/Branch.java b/src/main/java/com/contentstack/cms/stack/Branch.java index 2ef22310..e67987c4 100644 --- a/src/main/java/com/contentstack/cms/stack/Branch.java +++ b/src/main/java/com/contentstack/cms/stack/Branch.java @@ -26,7 +26,7 @@ * * @since 2022-10-22 */ -public class Branch implements BaseImplementation { +public class Branch implements BaseImplementation { protected final Map headers; protected Map params; diff --git a/src/main/java/com/contentstack/cms/stack/BulkOperation.java b/src/main/java/com/contentstack/cms/stack/BulkOperation.java index 6caa84de..506420a3 100644 --- a/src/main/java/com/contentstack/cms/stack/BulkOperation.java +++ b/src/main/java/com/contentstack/cms/stack/BulkOperation.java @@ -27,7 +27,7 @@ * Bulk Operations Queue * @since 2023 -08-23 */ -public class BulkOperation implements BaseImplementation { +public class BulkOperation implements BaseImplementation { /** * The Service. @@ -124,7 +124,6 @@ public Call publish(@NotNull JSONObject body) { * satisfy the publish rules, pass * additional query parameters, skip_workflow_stage_check=true and * approvals=true. - *

* * @param body the body * @return Call call @@ -154,7 +153,6 @@ public Call unpublish(@NotNull JSONObject body) { * Authtoken (any one is mandatory), * along with the stack API key, to make a valid Content Management API request. * Read more about authentication. - *

* * @param body the body * @return Call call @@ -188,7 +186,7 @@ public Call delete(JSONObject body) { *

* * @param body the body - * @return Call call + * @return Call * @see Bulk * Delete Operation diff --git a/src/main/java/com/contentstack/cms/stack/Compare.java b/src/main/java/com/contentstack/cms/stack/Compare.java index 197be7db..06e456e9 100644 --- a/src/main/java/com/contentstack/cms/stack/Compare.java +++ b/src/main/java/com/contentstack/cms/stack/Compare.java @@ -36,7 +36,7 @@ * "https://www.contentstack.com/docs/developers/apis/content-management-api/#compare-branches">Compare * Branches */ -public class Compare implements BaseImplementation { +public class Compare implements BaseImplementation { private final CompareService service; private final Map headers; diff --git a/src/main/java/com/contentstack/cms/stack/ContentType.java b/src/main/java/com/contentstack/cms/stack/ContentType.java index 2653fe2f..7b43924c 100644 --- a/src/main/java/com/contentstack/cms/stack/ContentType.java +++ b/src/main/java/com/contentstack/cms/stack/ContentType.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; import org.json.simple.JSONObject; @@ -28,10 +29,10 @@ * @author ishaileshmishra * @version v0.1.0 * @see Content - * Types + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#content-types">Content + * Types */ -public class ContentType { +public class ContentType implements BaseImplementation { protected final ContentTypeService service; protected final Map headers; @@ -42,10 +43,8 @@ public class ContentType { /** * Instantiates a new Content type. * - * @param instance - * the {@link Retrofit} instance - * @param headers - * the headers + * @param instance the {@link Retrofit} instance + * @param headers the headers */ protected ContentType(@NotNull Retrofit instance, Map headers) { this.instance = instance; @@ -58,12 +57,9 @@ protected ContentType(@NotNull Retrofit instance, Map headers) { /** * Instantiates a new Content type. * - * @param instance - * the {@link Retrofit} instance - * @param headers - * the headers - * @param uid - * the contentTypeUid + * @param instance the {@link Retrofit} instance + * @param headers the headers + * @param uid the contentTypeUid */ public ContentType(@NotNull Retrofit instance, Map headers, String uid) { this.instance = instance; @@ -74,35 +70,70 @@ public ContentType(@NotNull Retrofit instance, Map headers, Stri this.service = instance.create(ContentTypeService.class); } + + //---------------------------------------------------------------- + // GETTERS + //---------------------------------------------------------------- + /** - * Sets header for the request - * - * @param key - * header key for the request - * @param value - * header value for the request + * @param key A string representing the key of the parameter. It cannot be + * null and must be + * provided as a non-null value. + * @param value The "value" parameter is of type Object, which means it can + * accept any type of + * object as its value. + * @return instance of ContentType + */ + @Override + public ContentType addParam(@NotNull String key, @NotNull Object value) { + this.params.put(key, value); + return this; + } + + /** + * @param key The key parameter is a string that represents the name or + * identifier of the header. + * It is used to specify the type of information being sent in the + * header. + * @param value The value parameter is a string that represents the value of the + * header. + * @return instance of ContentType */ - public void addHeader(@NotNull String key, @NotNull Object value) { + @Override + public ContentType addHeader(@NotNull String key, @NotNull String value) { this.headers.put(key, value); + return this; } /** - * Sets header for the request - * - * @param key - * key of query parameters of request - * @param value - * value of query parameters of request + * @param params The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of ContentType */ - public void addParam(@NotNull String key, @NotNull Object value) { - this.params.put(key, value); + @Override + public ContentType addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + /** + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of ContentType + */ + @Override + public ContentType addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; } /** * Sets header for the request * - * @param key - * Remove query parameters of request by key + * @param key remove query parameters of request by key */ public void removeParam(@NotNull String key) { this.params.remove(key); @@ -128,8 +159,7 @@ public Entry entry() { /** * An entry is the actual piece of content created using one of the defined * - * @param entryUid - * The entry uid + * @param entryUid The entry uid * @return Entry */ public Entry entry(@NotNull String entryUid) { @@ -156,9 +186,9 @@ public Entry entry(@NotNull String entryUid) { * * @return the call * @see - * Get all content types - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-content-types"> + * Get all content types + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query params * @since 0.1.0 */ @@ -206,10 +236,10 @@ public Call find() { * * @return Call * @see - * Get a - * single content type - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-a-single-content-type"> + * Get a + * single content type + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query params * @since 0.1.0 */ @@ -250,13 +280,12 @@ public Call fetch() { * {@link Call} response = contentType.create(managementToken, bodyStr).execute(); * * - * @param requestBody - * the request body + * @param requestBody the request body * @return Call * @see - * Create A Content Type - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#create-a-content-type"> + * Create A Content Type + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query params * @since 0.1.0 */ @@ -277,13 +306,12 @@ public Call create(JSONObject requestBody) { * href=https://www.contentstack.com/docs/developers/apis/content-management-api/#update-content-type>Read * more * - * @param requestBody - * the request body + * @param requestBody the request body * @return Call * @see - * Update Content Type - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#update-content-type"> + * Update Content Type + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query params * @since 0.1.0 */ @@ -308,13 +336,12 @@ public Call update(JSONObject requestBody) { * required fields to the content type and saved it) or while editing a content * type (both via UI and API). * - * @param requestBody - * the request body JSONBody + * @param requestBody the request body JSONBody * @return Call * @see - * Set Field Visibility Rule for Content Type - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#set-field-visibility-rule-for-content-type"> + * Set Field Visibility Rule for Content Type + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query params * @since 0.1.0 */ @@ -339,9 +366,9 @@ public Call fieldVisibilityRule(JSONObject requestBody) { * * @return Call * @see - * Delete Content Type - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-content-type"> + * Delete Content Type + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query params * @since 0.1.0 */ @@ -367,13 +394,12 @@ public Call delete() { * Management API request. Read more about * authentication. * - * @param isIncludeGlobalField - * Include Global Field true/false + * @param isIncludeGlobalField Include Global Field true/false * @return Call * @see - * Get All References Of Content Type - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-references-of-content-type"> + * Get All References Of Content Type + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call reference(Boolean isIncludeGlobalField) { @@ -399,9 +425,9 @@ public Call reference(Boolean isIncludeGlobalField) { * * @return Call * @see - * Get All References Of Content Type - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-references-of-content-type"> + * Get All References Of Content Type + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call referenceIncludeGlobalField() { @@ -426,9 +452,9 @@ public Call referenceIncludeGlobalField() { * * @return Call * @see - * Export A Content Type - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#export-a-content-type"> + * Export A Content Type + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call export() { @@ -451,15 +477,14 @@ public Call export() { * valid Content Management API request. * Read more about authentication. * - * @param version - * The version of content type you want to retrieve. If no + * @param version The version of content type you want to retrieve. If no * version is specified, you will get the latest * version of the content type * @return Call * @see - * Export A Content Type - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#export-a-content-type"> + * Export A Content Type + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call export(int version) { @@ -476,9 +501,9 @@ public Call export(int version) { * * @return Call * @see - * Import A Content Type - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#import-a-content-type"> + * Import A Content Type + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call imports() { @@ -498,9 +523,9 @@ public Call imports() { * * @return Call * @see - * Import A Content Type - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#import-a-content-type"> + * Import A Content Type + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call importOverwrite() { diff --git a/src/main/java/com/contentstack/cms/stack/DeliveryToken.java b/src/main/java/com/contentstack/cms/stack/DeliveryToken.java index fa85d159..1cb30e93 100644 --- a/src/main/java/com/contentstack/cms/stack/DeliveryToken.java +++ b/src/main/java/com/contentstack/cms/stack/DeliveryToken.java @@ -1,6 +1,6 @@ package com.contentstack.cms.stack; -import com.contentstack.cms.organization.Organization; +import com.contentstack.cms.BaseImplementation; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; import org.json.simple.JSONObject; @@ -23,7 +23,7 @@ * @version v0.1.0 * @since 2022-10-22 */ -public class DeliveryToken { +public class DeliveryToken implements BaseImplementation { protected final TokenService service; protected HashMap headers; @@ -44,21 +44,6 @@ protected DeliveryToken(TokenService service, @NotNull String tokenUid) { this.service = service; } - /** - * The addHeader function adds a key-value pair to the headers map. - * - * @param key A string representing the key of the header. This is used to - * identify the header when - * retrieving or modifying it. - * @param value The value parameter is of type Object, which means it can accept - * any type of object as - * its value. - * @return instance of {@link DeliveryToken} - */ - public DeliveryToken addHeader(@NotNull String key, @NotNull Object value) { - this.headers.put(key, value); - return this; - } /** * The addParam function adds a key-value pair to a map. @@ -69,13 +54,54 @@ public DeliveryToken addHeader(@NotNull String key, @NotNull Object value) { * @param value The value parameter is of type Object, which means it can accept * any type of object as * its value. - * @return instance of {@link DeliveryToken} + * @return instance of {@link DeliveryToken} */ + @Override public DeliveryToken addParam(@NotNull String key, @NotNull Object value) { this.params.put(key, value); return this; } + /** + * @param key The key parameter is a string that represents the name or + * identifier of the header. + * It is used to specify the type of information being sent in the + * header. + * @param value The value parameter is a string that represents the value of the + * header. + * @return instance of {@link DeliveryToken} + */ + @Override + public DeliveryToken addHeader(@NotNull String key, @NotNull String value) { + this.headers.put(key, value); + return this; + } + + /** + * @param params The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of {@link DeliveryToken} + */ + @Override + public DeliveryToken addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + /** + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of {@link DeliveryToken} + */ + @Override + public DeliveryToken addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; + } + /** * The function removes a parameter from a map using the specified key. * @@ -101,7 +127,7 @@ protected DeliveryToken clearParams() { * all * Delivery Tokens * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -119,7 +145,7 @@ public Call find() { * a * Single Delivery Token * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -143,7 +169,7 @@ public Call fetch() { * Delivery * Token * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -171,7 +197,7 @@ public Call create(@NotNull JSONObject requestBody) { * Delivery * Token * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -189,7 +215,7 @@ public Call update(@NotNull JSONObject requestBody) { * Delivery * Token * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -208,7 +234,7 @@ public Call delete() { * Delivery * Token * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ diff --git a/src/main/java/com/contentstack/cms/stack/Entry.java b/src/main/java/com/contentstack/cms/stack/Entry.java index 486d62b7..a630fac2 100644 --- a/src/main/java/com/contentstack/cms/stack/Entry.java +++ b/src/main/java/com/contentstack/cms/stack/Entry.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; import org.json.simple.JSONObject; @@ -25,7 +26,7 @@ * @version v0.1.0 * @since 2022-10-22 */ -public class Entry { +public class Entry implements BaseImplementation { final String ERROR_ENTRY_UID = "Entry UID Is Required"; final String ERROR_CT_UID = "Content Type UID Is Required"; @@ -66,9 +67,10 @@ private void validateCT() { * * @param key header key for the request * @param value header value for the request - * @return instance of {@link Entry} + * @return instance of {@link Entry} */ - public Entry addHeader(@NotNull String key, @NotNull Object value) { + @Override + public Entry addHeader(@NotNull String key, @NotNull String value) { this.headers.put(key, value); return this; } @@ -78,13 +80,26 @@ public Entry addHeader(@NotNull String key, @NotNull Object value) { * * @param key query param key for the request * @param value query param value for the request - * @return instance of {@link Entry} + * @return instance of {@link Entry} */ public Entry addParam(@NotNull String key, @NotNull Object value) { this.params.put(key, value); return this; } + + @Override + public Entry addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + @Override + public Entry addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; + } + /** * Set header for the request * @@ -97,6 +112,7 @@ public Entry removeParam(@NotNull String key) { /** * To clear all the query params + * * @return instance of {@link Entry} */ protected Entry clearParams() { @@ -194,7 +210,7 @@ public Call fetch() { * @see Create * A Entry - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -221,7 +237,7 @@ public Call create(JSONObject requestBody) { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#update-an-entry"> * Update * an entry - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -275,7 +291,7 @@ public Call update(JSONObject requestBody) { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#atomic-updates-to-entries"> * Atomic * Operation - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -317,7 +333,7 @@ public Call atomicOperation(JSONObject requestBody) { * @see Get * Delete An Entry - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -367,7 +383,7 @@ public Call delete() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-an-entry"> * Delete * An Entry - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -393,7 +409,7 @@ public Call delete(JSONObject requestBody) { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#set-version-name-for-entry"> * Set * Version Name for Entry - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call versionName(int version, JSONObject requestBody) { @@ -434,7 +450,7 @@ public Call versionName(int version, JSONObject requestBody) { * @see * Get Details of All Versions of an Entry - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call detailOfAllVersion() { @@ -453,7 +469,7 @@ public Call detailOfAllVersion() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-version-name-of-entry"> * Delete * Version Name of Entry - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call deleteVersionName(int versionNumber, JSONObject requestBody) { @@ -481,7 +497,7 @@ public Call deleteVersionName(int versionNumber, JSONObject reques * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-references-of-an-entry"> * Get * references of an entry - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -505,7 +521,7 @@ public Call getReference() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-languages-of-an-entry"> * Get * language of an entry - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -537,7 +553,7 @@ public Call getLanguage() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#localize-an-entry"> * Localize an entry * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call localize(@NotNull JSONObject requestBody, @@ -558,7 +574,7 @@ public Call localize(@NotNull JSONObject requestBody, * "https://www.contentstack.com/docs/developers/apis/content-management-api/#unlocalize-an-entry"> * unlocalize an entry * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call unLocalize(@NotNull String localeCode) { @@ -578,7 +594,7 @@ public Call unLocalize(@NotNull String localeCode) { * Export * an entry * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -614,7 +630,7 @@ public Call export() { * Import * an entry * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -642,7 +658,7 @@ public Call imports() { * Import * an entry * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -688,7 +704,7 @@ public Call importExisting() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#publish-an-entry"> * Publish an entry * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call publish(@NotNull JSONObject requestBody) { @@ -718,7 +734,7 @@ public Call publish(@NotNull JSONObject requestBody) { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#publish-an-entry-with-references"> * Publish an entry With reference * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -752,7 +768,7 @@ public Call publishWithReference(@NotNull JSONObject requestBody) * "https://www.contentstack.com/docs/developers/apis/content-management-api/#unpublish-an-entry"> * Unpublish an entry * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call unpublish(@NotNull JSONObject requestBody) { diff --git a/src/main/java/com/contentstack/cms/stack/Environment.java b/src/main/java/com/contentstack/cms/stack/Environment.java index 0807adc0..fdbfde50 100644 --- a/src/main/java/com/contentstack/cms/stack/Environment.java +++ b/src/main/java/com/contentstack/cms/stack/Environment.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; import org.json.simple.JSONObject; @@ -19,7 +20,7 @@ * @version v0.1.0 * @since 2022-10-22 */ -public class Environment { +public class Environment implements BaseImplementation { protected final Map headers; protected final Map params; @@ -47,23 +48,58 @@ void validate() { } /** - * Sets header for the request - * - * @param key header key for the request - * @param value header value for the request + * @param key A string representing the key of the parameter. It cannot be + * null and must be + * provided as a non-null value. + * @param value The "value" parameter is of type Object, which means it can + * accept any type of + * object as its value. + * @return instance of the Environment + */ + @Override + public Environment addParam(@NotNull String key, @NotNull Object value) { + this.params.put(key, value); + return this; + } + + /** + * @param key The key parameter is a string that represents the name or + * identifier of the header. + * It is used to specify the type of information being sent in the + * header. + * @param value The value parameter is a string that represents the value of the + * header. + * @return instance of the Environment */ - public void addHeader(@NotNull String key, @NotNull Object value) { + @Override + public Environment addHeader(@NotNull String key, @NotNull String value) { this.headers.put(key, value); + return this; } /** - * Sets header for the request - * - * @param key query param key for the request - * @param value query param value for the request + * @param params The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of the Environment */ - public void addParam(@NotNull String key, @NotNull Object value) { - this.params.put(key, value); + @Override + public Environment addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + /** + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of the Environment + */ + @Override + public Environment addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; } /** @@ -104,7 +140,7 @@ protected void clearParams() { * all * environments * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -126,7 +162,7 @@ public Call find() { * a single * environments * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -154,7 +190,7 @@ public Call fetch() { * all * environments * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -181,7 +217,7 @@ public Call create(@NotNull JSONObject body) { * @see Update * Environment - * @see #addHeader(String, Object) to add headers to the request + * @see #addHeader(String, String) to add headers to the request * @since 0.1.0 */ public Call update(@NotNull JSONObject requestBody) { @@ -201,7 +237,7 @@ public Call update(@NotNull JSONObject requestBody) { * @see Delete * Environment - * @see #addHeader(String, Object) to add headers to the request + * @see #addHeader(String, String) to add headers to the request * @since 0.1.0 */ public Call delete() { diff --git a/src/main/java/com/contentstack/cms/stack/Extensions.java b/src/main/java/com/contentstack/cms/stack/Extensions.java index 78b738dd..75bd8ea0 100644 --- a/src/main/java/com/contentstack/cms/stack/Extensions.java +++ b/src/main/java/com/contentstack/cms/stack/Extensions.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import com.contentstack.cms.core.Util; import okhttp3.RequestBody; import okhttp3.ResponseBody; @@ -28,7 +29,7 @@ * @version v0.1.0 * @since 2022-10-22 */ -public class Extensions { +public class Extensions implements BaseImplementation { protected final ExtensionsService service; protected HashMap headers; @@ -53,24 +54,60 @@ void validate() { throw new IllegalAccessError("Custom Field UID Can Not Be Null OR Empty"); } + /** - * Sets header for the request - * - * @param key header key for the request - * @param value header value for the request + * @param key A string representing the key of the parameter. It cannot be + * null and must be + * provided as a non-null value. + * @param value The "value" parameter is of type Object, which means it can + * accept any type of + * object as its value. + * @return instance of {@link Extensions} + */ + @Override + public Extensions addParam(@NotNull String key, @NotNull Object value) { + this.params.put(key, value); + return this; + } + + /** + * @param key The key parameter is a string that represents the name or + * identifier of the header. + * It is used to specify the type of information being sent in the + * header. + * @param value The value parameter is a string that represents the value of the + * header. + * @return instance of {@link Extensions} */ - public void addHeader(@NotNull String key, @NotNull Object value) { + @Override + public Extensions addHeader(@NotNull String key, @NotNull String value) { this.headers.put(key, value); + return this; } /** - * Sets header for the request - * - * @param key query param key for the request - * @param value query param value for the request + * @param params The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of {@link Extensions} */ - public void addParam(@NotNull String key, @NotNull Object value) { - this.params.put(key, value); + @Override + public Extensions addParams(@NotNull HashMap params) { + this.params.putAll(params); + return null; + } + + /** + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of {@link Extensions} + */ + @Override + public Extensions addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; } /** @@ -103,7 +140,7 @@ protected void clearParams() { * * * @return Call call - * @see #addHeader(String, Object) #addHeader(String, Object)#addHeader(String, + * @see #addHeader(String, String) #addHeader(String, Object)#addHeader(String, * Object)to add headers * @see #addParam(String, Object) #addParam(String, Object)#addParam(String, * Object)to add query parameters @@ -120,7 +157,7 @@ public Call find() { * a * Single Custom Field * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -164,7 +201,7 @@ public Call fetch() { * a custom * field * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -205,7 +242,7 @@ public Call uploadCustomField(Map body) { * a custom * field * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -222,7 +259,7 @@ public Call uploadCustomFieldUsingJSONObject(JSONObject body) { * a custom * field * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call update(JSONObject body) { @@ -240,7 +277,7 @@ public Call update(JSONObject body) { * a custom * field * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call delete() { diff --git a/src/main/java/com/contentstack/cms/stack/Folder.java b/src/main/java/com/contentstack/cms/stack/Folder.java index a24010fd..b8211427 100644 --- a/src/main/java/com/contentstack/cms/stack/Folder.java +++ b/src/main/java/com/contentstack/cms/stack/Folder.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -10,7 +11,7 @@ import java.util.HashMap; import java.util.Map; -public class Folder { +public class Folder implements BaseImplementation { protected final Map headers; protected Map params; @@ -36,34 +37,64 @@ void validate() { } /** - * Sets header for the request - * - * @param key - * header key for the request - * @param value - * header value for the request + * @param key A string representing the key of the parameter. It cannot be + * null and must be + * provided as a non-null value. + * @param value The "value" parameter is of type Object, which means it can + * accept any type of + * object as its value. + * @return instance of the {@link Folder} + */ + @Override + public Folder addParam(@NotNull String key, @NotNull Object value) { + this.params.put(key, value); + return this; + } + + /** + * @param key The key parameter is a string that represents the name or + * identifier of the header. + * It is used to specify the type of information being sent in the + * header. + * @param value The value parameter is a string that represents the value of the + * header. + * @return instance of the {@link Folder} */ - public void addHeader(@NotNull String key, @NotNull Object value) { + @Override + public Folder addHeader(@NotNull String key, @NotNull String value) { this.headers.put(key, value); + return this; } /** - * Sets header for the request - * - * @param key - * query param key for the request - * @param value - * query param value for the request + * @param params The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of the {@link Folder} */ - public void addParam(@NotNull String key, @NotNull Object value) { - this.params.put(key, value); + @Override + public Folder addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + /** + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of the {@link Folder} + */ + @Override + public Folder addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; } /** * Set header for the request * - * @param key - * Removes query param using key of request + * @param key Removes query param using key of request */ public void removeParam(@NotNull String key) { this.params.remove(key); @@ -94,9 +125,9 @@ protected void clearParams() { * * @return Call * @see - * Unpublish An Asset - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#unpublish-an-asset"> + * Unpublish An Asset + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query params * @since 0.1.0 */ @@ -125,14 +156,13 @@ public Call fetch() { * is 5. When nesting folder, you * cannot nest a folder within the same folder or within its child folders * - * @param requestBody - * JSONObject request body + * @param requestBody JSONObject request body * @return Call * @see - * Create - * a folder - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#create-a-folder"> + * Create + * a folder + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query params * @since 0.1.0 */ @@ -159,13 +189,12 @@ public Call create(@Nullable JSONObject requestBody) { * is 5. When nesting folder, you * cannot nest a folder within the same folder or within its child folders. * - * @param requestBody - * JSONObject request body { "asset": { "name": "Demo" } } + * @param requestBody JSONObject request body { "asset": { "name": "Demo" } } * @return Call * @see - * Update ORr Move Folder - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#update-or-move-folder"> + * Update ORr Move Folder + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query params * @since 0.1.0 */ @@ -182,10 +211,10 @@ public Call update(@Nullable JSONObject requestBody) { * * @return Call * @see - * Delete - * A Folder - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-a-folder"> + * Delete + * A Folder + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query params * @since 0.1.0 */ diff --git a/src/main/java/com/contentstack/cms/stack/GlobalField.java b/src/main/java/com/contentstack/cms/stack/GlobalField.java index 67bb7684..2cc0aa4c 100644 --- a/src/main/java/com/contentstack/cms/stack/GlobalField.java +++ b/src/main/java/com/contentstack/cms/stack/GlobalField.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; import org.json.simple.JSONObject; @@ -26,7 +27,7 @@ * @version v0.1.0 * @since 2022-10-22 */ -public class GlobalField { +public class GlobalField implements BaseImplementation { /** * The Service. @@ -54,27 +55,59 @@ void validate() { throw new IllegalAccessError("Global Field Uid can not be null or empty"); } + /** - * Sets header for the request - * - * @param key header key for the request - * @param value header value for the request - * @return instance of {@link GlobalField} + * @param key A string representing the key of the parameter. It cannot be + * null and must be + * provided as a non-null value. + * @param value The "value" parameter is of type Object, which means it can + * accept any type of + * object as its value. + * @return instance of the GlobalField object + */ + @Override + public GlobalField addParam(@NotNull String key, @NotNull Object value) { + this.params.put(key, value); + return this; + } + + /** + * @param key The key parameter is a string that represents the name or + * identifier of the header. + * It is used to specify the type of information being sent in the + * header. + * @param value The value parameter is a string that represents the value of the + * header. + * @return instance of the GlobalField object */ - public GlobalField addHeader(@NotNull String key, @NotNull Object value) { + @Override + public GlobalField addHeader(@NotNull String key, @NotNull String value) { this.headers.put(key, value); return this; } /** - * Sets header for the request - * - * @param key query param key for the request - * @param value query param value for the request - * @return instance of {@link GlobalField} + * @param params The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of the GlobalField object */ - public GlobalField addParam(@NotNull String key, @NotNull Object value) { - this.params.put(key, value); + @Override + public GlobalField addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + /** + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of the GlobalField object + */ + @Override + public GlobalField addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); return this; } @@ -91,6 +124,7 @@ public GlobalField removeParam(@NotNull String key) { /** * To clear all the query params + * * @return instance of {@link GlobalField} */ protected GlobalField clearParams() { diff --git a/src/main/java/com/contentstack/cms/stack/Label.java b/src/main/java/com/contentstack/cms/stack/Label.java index ccd8f548..fb41369f 100644 --- a/src/main/java/com/contentstack/cms/stack/Label.java +++ b/src/main/java/com/contentstack/cms/stack/Label.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; import org.json.simple.JSONObject; @@ -24,7 +25,7 @@ * @version v0.1.0 * @since 2022-10-22 */ -public class Label { +public class Label implements BaseImplementation

* You can now pass the branch header in the API request to fetch or manage @@ -29,7 +30,7 @@ * @version v0.1.0 * @since 2022-10-22 */ -public class Release { +public class Release implements BaseImplementation { protected final ReleaseService service; protected HashMap headers; @@ -57,24 +58,60 @@ void validate() { throw new IllegalAccessError("Release Uid Can Not Be Null OR Empty"); } + /** - * Sets header for the request - * - * @param key header key for the request - * @param value header value for the request + * @param key A string representing the key of the parameter. It cannot be + * null and must be + * provided as a non-null value. + * @param value The "value" parameter is of type Object, which means it can + * accept any type of + * object as its value. + * @return instance of {@link @Release} + */ + @Override + public Release addParam(@NotNull String key, @NotNull Object value) { + this.params.put(key, value); + return this; + } + + /** + * @param key The key parameter is a string that represents the name or + * identifier of the header. + * It is used to specify the type of information being sent in the + * header. + * @param value The value parameter is a string that represents the value of the + * header. + * @return instance of {@link @Release} */ - public void addHeader(@NotNull String key, @NotNull Object value) { + @Override + public Release addHeader(@NotNull String key, @NotNull String value) { this.headers.put(key, value); + return this; } /** - * Sets header for the request - * - * @param key query param key for the request - * @param value query param value for the request + * @param params The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of {@link @Release} */ - public void addParam(@NotNull String key, @NotNull Object value) { - this.params.put(key, value); + @Override + public Release addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + /** + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of {@link @Release} + */ + @Override + public Release addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; } /** @@ -103,7 +140,7 @@ protected void clearParams() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-releases">Get * all Releases * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -123,7 +160,7 @@ public Call find() { * a singel * release * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -145,7 +182,7 @@ public Call fetch() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#create-a-release">Create * a release * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -167,7 +204,7 @@ public Call create(@NotNull JSONObject requestBody) { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#update-a-release">Update * a release * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -187,7 +224,7 @@ public Call update(@NotNull JSONObject requestBody) { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-a-release">Delete * a release * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -211,7 +248,7 @@ public Call delete() { * a * release item * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -237,7 +274,7 @@ public ReleaseItem item() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#deploy-a-release">Deploy * a release * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -260,7 +297,7 @@ public Call deploy(@NotNull JSONObject requestBody) { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#clone-a-release">Clone * all release * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call clone(@NotNull JSONObject requestBody) { diff --git a/src/main/java/com/contentstack/cms/stack/ReleaseItem.java b/src/main/java/com/contentstack/cms/stack/ReleaseItem.java index c4cae1cb..c728ac5c 100644 --- a/src/main/java/com/contentstack/cms/stack/ReleaseItem.java +++ b/src/main/java/com/contentstack/cms/stack/ReleaseItem.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; import org.json.simple.JSONObject; @@ -21,7 +22,7 @@ * @version v0.1.0 * @since 2022-10-22 */ -public class ReleaseItem { +public class ReleaseItem implements BaseImplementation { protected final ReleaseService service; protected HashMap headers; @@ -40,24 +41,60 @@ void validate() { throw new IllegalAccessError("Release Uid can not be null or empty"); } + /** - * Sets header for the request - * - * @param key header key for the request - * @param value header value for the request + * @param key A string representing the key of the parameter. It cannot be + * null and must be + * provided as a non-null value. + * @param value The "value" parameter is of type Object, which means it can + * accept any type of + * object as its value. + * @return instance of {@link ReleaseItem} + */ + @Override + public ReleaseItem addParam(@NotNull String key, @NotNull Object value) { + this.params.put(key, value); + return this; + } + + /** + * @param key The key parameter is a string that represents the name or + * identifier of the header. + * It is used to specify the type of information being sent in the + * header. + * @param value The value parameter is a string that represents the value of the + * header. + * @return instance of {@link ReleaseItem} */ - public void addHeader(@NotNull String key, @NotNull Object value) { + @Override + public ReleaseItem addHeader(@NotNull String key, @NotNull String value) { this.headers.put(key, value); + return this; } /** - * Sets header for the request - * - * @param key query param key for the request - * @param value query param value for the request + * @param params The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of {@link ReleaseItem} */ - public void addParam(@NotNull String key, @NotNull Object value) { - this.params.put(key, value); + @Override + public ReleaseItem addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + /** + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of {@link ReleaseItem} + */ + @Override + public ReleaseItem addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; } /** @@ -98,7 +135,7 @@ public Call find() { * 'Body' section, you need to provide * the details of the item such as the UID, version (of the entry), content type * UID (of an entry), the action to be - * performed (publish/unpublish), and the locale of the item. + * performed (publish/un-publish), and the locale of the item. * * @param jsonBody requestBody for create/add single Item * @return Call @@ -116,7 +153,7 @@ public Call create(@NotNull JSONObject jsonBody) { * 'Body' section, you need to provide * the details of the items such as their UIDs, versions (in case of entries), * content type UIDs (in case of - * entries), the action to be performed (publish/unpublish), and the locales of + * entries), the action to be performed (publish/un-publish), and the locales of * the items. * * @param jsonBody requestBody for create/add single Item @@ -184,7 +221,7 @@ public Call update(@NotNull JSONObject jsonBody) { * section, you need to provide the * details of the item such as their UIDs, version (of the entry), content type * UID (of an entry), the action to be - * performed (publish/unpublish), and the locale of the item. + * performed (publish/un-publish), and the locale of the item. *

* OR *

@@ -196,7 +233,7 @@ public Call update(@NotNull JSONObject jsonBody) { * section, you need to provide the UIDs * of the items along with details such as their locale, versions, the action to * be performed on the items - * (publish/unpublish), and content type UID of entries (if any). + * (publish/un-publish), and content type UID of entries (if any). * * @return Call */ diff --git a/src/main/java/com/contentstack/cms/stack/Roles.java b/src/main/java/com/contentstack/cms/stack/Roles.java index a2848215..bc1e7390 100644 --- a/src/main/java/com/contentstack/cms/stack/Roles.java +++ b/src/main/java/com/contentstack/cms/stack/Roles.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; import org.json.simple.JSONObject; @@ -16,12 +17,11 @@ * @author ishaileshmishra * @version v0.1.0 * @see Roles - * - * + * "https://www.contentstack.com/docs/developers/invite-users-and-assign-roles/about-stack-roles">Roles + * * @since 2022-10-22 */ -public class Roles { +public class Roles implements BaseImplementation { protected final RolesService service; protected HashMap headers; @@ -46,35 +46,11 @@ void validate() { throw new IllegalAccessError("Role uid can not be null or empty"); } - /** - * Sets header for the request - * - * @param key - * header key for the request - * @param value - * header value for the request - */ - public void addHeader(@NotNull String key, @NotNull Object value) { - this.headers.put(key, value); - } - - /** - * Sets header for the request - * - * @param key - * query param key for the request - * @param value - * query param value for the request - */ - public void addParam(@NotNull String key, @NotNull Object value) { - this.params.put(key, value); - } /** * Set header for the request * - * @param key - * Removes query param using key of request + * @param key Removes query param using key of request */ public void removeParam(@NotNull String key) { this.params.remove(key); @@ -100,11 +76,11 @@ protected void clearParams() { * * @return Call * @see Get - * all - * Roles - * - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-roles">Get + * all + * Roles + * + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -118,11 +94,11 @@ public Call find() { * * @return Call * @see Get - * a - * single Roles - * - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-a-single-role">Get + * a + * single Roles + * + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -140,15 +116,14 @@ public Call fetch() { * permissions (which include the details of * the content types, environments, and languages that are accessible). * - * @param requestBody - * details of the delivery role in @{@link JSONObject} format + * @param requestBody details of the delivery role in @{@link JSONObject} format * @return Call * @see Create - * a - * Roles - * - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#create-a-role">Create + * a + * Roles + * + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call create(@NotNull JSONObject requestBody) { @@ -167,14 +142,13 @@ public Call create(@NotNull JSONObject requestBody) { * (which include the details of the content types, environments, and languages * that are accessible). * - * @param requestBody - * the body should be of @{@link JSONObject} type + * @param requestBody the body should be of @{@link JSONObject} type * @return Call * @see Update - * Role - * - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#update-role">Update + * Role + * + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -188,11 +162,11 @@ public Call update(@NotNull JSONObject requestBody) { * * @return Call * @see Delete - * a - * Role - * - * @see #addHeader(String, Object) to add headers + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-role">Delete + * a + * Role + * + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call delete() { @@ -200,4 +174,27 @@ public Call delete() { return this.service.deleteRole(this.headers, this.roleUid); } + @Override + public Roles addParam(@NotNull String key, @NotNull Object value) { + this.params.put(key, value); + return this; + } + + @Override + public Roles addHeader(@NotNull String key, @NotNull String value) { + this.headers.put(key, value); + return this; + } + + @Override + public Roles addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + @Override + public Roles addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; + } } diff --git a/src/main/java/com/contentstack/cms/stack/Stack.java b/src/main/java/com/contentstack/cms/stack/Stack.java index 55054c5f..2bd21fd4 100644 --- a/src/main/java/com/contentstack/cms/stack/Stack.java +++ b/src/main/java/com/contentstack/cms/stack/Stack.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; import org.json.simple.JSONObject; @@ -16,9 +17,9 @@ * * @author ishaileshmishra * @version v0.1.0 - * @since 2022-10-22 + * @since 2022 -10-22 */ -public class Stack { +public class Stack implements BaseImplementation { private final StackService service; protected Retrofit client; @@ -37,24 +38,6 @@ public Stack(@NotNull Retrofit client) { this.service = client.create(StackService.class); } - /** - * The addHeader function adds a key-value pair to the headers map and returns - * the updated Stack - * object. - * - * @param key A string representing the key of the header. It is marked - * as @NotNull, which means it - * cannot be null and must be provided. - * @param value The value parameter is of type Object, which means it can accept - * any type of object as - * its value. - * @return The method is returning a Stack object. - */ - public Stack addHeader(@NotNull String key, @NotNull Object value) { - this.headers.put(key, value); - return this; - } - /** * The addParam function adds a key-value pair to a stack and returns the * updated stack. @@ -71,6 +54,46 @@ public Stack addParam(@NotNull String key, @NotNull Object value) { return this; } + /** + * @param key The key parameter is a string that represents the name or + * identifier of the header. + * It is used to specify the type of information being sent in the + * header. + * @param value The value parameter is a string that represents the value of the + * header. + * @return instance of the Stack + */ + @Override + public Stack addHeader(@NotNull String key, @NotNull String value) { + this.headers.put(key, value); + return this; + } + + /** + * @param params The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of the Stack + */ + @Override + public Stack addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + /** + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of the Stack + */ + @Override + public Stack addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; + } + /** * The function removes a parameter from a stack and returns the modified stack. * @@ -546,10 +569,10 @@ public Roles roles(String roleUid) { } /** - * You can pin a set of entries and assets (along with the deploy action, i.e., - * publish/unpublish) to a + * You can pin a set of entries and assets (along with the deployment action, i.e., + * publish/un-publish) to a * release, and then deploy this release to an environment. This will - * publish/unpublish all the items of the release to the specified environment. + * publish/un-publish all the items of the release to the specified environment. * Read more about Releases. * * @return Release @@ -559,10 +582,10 @@ public Release releases() { } /** - * You can pin a set of entries and assets (along with the deploy action, i.e., - * publish/unpublish) to a + * You can pin a set of entries and assets (along with the deployment action, i.e., + * publish/un-publish) to a * release, and then deploy this release to an environment. This will - * publish/unpublish all the items of the release to the specified environment. + * publish/un-publish all the items of the release to the specified environment. * Read more about Releases. * * @param releaseUid The unique ID of the release of which you want to retrieve @@ -631,7 +654,7 @@ public AuditLog auditLog(@NotNull String logItemUid) { /** * The Publishing Queue displays the historical and current details of - * activities such as publish, unpublish, or + * activities such as publish, un-publish, or * delete that can be performed on entries and/or assets. It also shows details * of Release deployments. These * details include time, entry, content type, version, language, user, @@ -649,7 +672,7 @@ public PublishQueue publishQueue() { } /** - * You can perform bulk operations such as Publish, Unpublish, and Delete on + * You can perform bulk operations such as Publish, Un-publish, and Delete on * multiple entries or assets, or Change * the Workflow Details of multiple entries or assets at the same time. *

@@ -666,7 +689,7 @@ public BulkOperation bulkOperation() { /** * The Publishing Queue displays the historical and current details of - * activities such as publish, unpublish, or + * activities such as publish, un-publish, or * delete that can be performed on entries and/or assets. It also shows details * of Release deployments. These * details include time, entry, content type, version, language, user, @@ -798,6 +821,45 @@ public Alias alias(String aliasUid) { return new Alias(this.client, aliasUid); } + + /** + * The taxonomy works on data where hierarchy is configured + * + *

+     * {@code
+     * Stack stack = new Contentstack.Builder().setAuthtoken("authtoken").build().stack();
+     * Taxonomy taxonomy = stack.taxonomy();
+     * Call response = taxonomy.fetch().execute();
+     * }
+     * 
+ * + * @return instance of Taxonomy + */ + public Taxonomy taxonomy() { + return new Taxonomy(this.client, this.headers); + } + + + /** + * The taxonomy works on data where hierarchy is configured + * + * @param taxonomyUid the taxonomy uid + * @return instance of Taxonomy + *

+ *
+     * {@code
+     * Stack stack = new Contentstack.Builder().setAuthtoken("authtoken").build().stack();
+     * Taxonomy taxonomy = stack.taxonomy("taxonomyId");
+     * taxonomy.terms();
+     * taxonomy.fetch();
+     * taxonomy.find();
+     * }
+     * 
+ */ + public Taxonomy taxonomy(@NotNull String taxonomyUid) { + return new Taxonomy(this.client, this.headers, taxonomyUid); + } + /** * Get stacks *
@@ -826,7 +888,7 @@ public Alias alias(String aliasUid) { * UID in the header. *
*
- * - Add headers using {@link #addHeader(String, Object)} + * - Add headers using {@link #addHeader(String, String)} *
* - Add query parameters using {@link #addParam(String, Object)} * @@ -945,7 +1007,7 @@ public Call transferOwnership(@NotNull JSONObject body) { *
    *
  • To Accept stack owned by other user, user * {@link #addParam(String, Object)} to add query parameters
  • - *
  • To Add Header use {@link #addHeader(String, Object)}
  • + *
  • To Add Header use {@link #addHeader(String, String)}
  • *
* * @param ownershipToken the ownership token received via email by another user. @@ -1116,16 +1178,16 @@ public Call share(@NotNull JSONObject requestBody) { } /** - * Unshare a stack + * Un-share a stack *

- * The Unshare a stack removes the user account from the list of collaborators. + * The Un-share a stack removes the user account from the list of collaborators. * Once this call is executed, the user * will not be able to view the stack in their account. *

*
*

* In the 'Body' section, you need to provide the email ID of the user from whom - * you wish to unshare the stack. + * you wish to un-share the stack. *

* Here is a sample of the Request Body: * @@ -1190,4 +1252,5 @@ public Call roles(@NotNull JSONObject body) { return service.updateUserRoles(this.headers, body); } + } diff --git a/src/main/java/com/contentstack/cms/stack/Taxonomy.java b/src/main/java/com/contentstack/cms/stack/Taxonomy.java new file mode 100644 index 00000000..ca991101 --- /dev/null +++ b/src/main/java/com/contentstack/cms/stack/Taxonomy.java @@ -0,0 +1,254 @@ +package com.contentstack.cms.stack; + +import com.contentstack.cms.BaseImplementation; +import okhttp3.ResponseBody; +import org.jetbrains.annotations.NotNull; +import org.json.simple.JSONObject; +import retrofit2.Call; +import retrofit2.Retrofit; + +import java.util.HashMap; + + +public class Taxonomy implements BaseImplementation { + + private String taxonomyId; + final TaxonomyService taxonomyService; + protected HashMap headers; + protected HashMap params; + + + protected Taxonomy(Retrofit client, HashMap headers) { + this.headers = new HashMap<>(); + this.params = new HashMap<>(); + this.headers.putAll(headers); + this.taxonomyService = client.create(TaxonomyService.class); + } + + protected Taxonomy(Retrofit client, HashMap headers, @NotNull String taxonomyId) { + this.headers = new HashMap<>(); + this.params = new HashMap<>(); + this.taxonomyId = taxonomyId; + this.headers.putAll(headers); + this.taxonomyService = client.create(TaxonomyService.class); + } + + /** + * @param key A string representing the key of the parameter. It cannot be + * null and must be + * provided as a non-null value. + * @param value The "value" parameter is of type Object, which means it can + * accept any type of + * object as its value. + * @return instance of Taxonomy + */ + @Override + public Taxonomy addParam(@NotNull String key, @NotNull Object value) { + this.params.put(key, value); + return this; + } + + /** + * @param key The key parameter is a string that represents the name or + * identifier of the header. + * It is used to specify the type of information being sent in the + * header. + * @param value The value parameter is a string that represents the value of the + * header. + * @return instance of Taxonomy + */ + @Override + public Taxonomy addHeader(@NotNull String key, @NotNull String value) { + this.headers.put(key, value); + return this; + } + + /** + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of Taxonomy + */ + @Override + public Taxonomy addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; + } + + /** + * @param params The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of Taxonomy + */ + @Override + public Taxonomy addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + /** + * Get all taxonomies call. + *

+ * Query parameters: + *

    + *
  • + * include_terms_count: Whether to include the count of terms in the response. Values: true or false. + *
  • + *
  • + * include_referenced_terms_count: Whether to include the count of referenced terms in the response. Values: true or false. + *
  • + *
  • + * include_referenced_entries_count: Whether to include the count of referenced entries in the response. Values: true or false. + *
  • + *
  • + * include_count: Whether to include the total count of taxonomies in the response. Values: true or false. + *
  • + *
  • + * asc or desc: Sort order based on the UID field. Values: field_uid (replace with the actual field UID), or omit for no sorting. + *
  • + *
  • + * typeahead: Search string for typeahead functionality. Values: Any search string. + *
  • + *
  • + * include_deleted: Whether to include deleted taxonomies in the response. Values: true or false. + *
  • + *
  • + * skip: Number of records to skip in pagination. Values: Any non-negative integer. + *
  • + *
  • + * limit: Maximum number of records to return. Values: Any positive integer. + *
  • + *
+ * + * @return the call + * + *

+ * Example + *
+     *     {@code
+     *     Response response = taxonomy.find().execute();
+     *     }
+     * 
+ */ + public Call find() { + return this.taxonomyService.find(this.headers, this.params); + } + + /** + * Fetch Single Taxonomy Call. + *

+ * Query Parameters: + *

    + *
  • + * include_terms_count: Whether to include the count of terms in the response. Values: true or false. + *
  • + *
  • + * include_referenced_terms_count: Whether to include the count of terms referred in at least 1 entry. Values: true or false. + *
  • + *
  • + * include_referenced_entries_count: Whether to include the count of entries where at least 1 term of this taxonomy is referred. Values: true or false + *
  • + *
+ * + * @param taxonomyId the taxonomy id + * @return the call + *

+ * Example + *
+     *     {@code
+     *     Response response = taxonomy.fetch("taxonomyId").execute();
+     *     }
+     * 
+ */ + public Call fetch(@NotNull String taxonomyId) { + return this.taxonomyService.fetch(this.headers, taxonomyId, this.params); + } + + /** + * Create Taxonomy call. + * + * @param body the body + * @return the call + * + *

+ * Example + *
+     *     {@code
+     *     JSONObject body = new JSONObject
+     *     Response response = taxonomy.create(body).execute();
+     *     }
+     * 
+ */ + public Call create(@NotNull JSONObject body) { + return this.taxonomyService.create(this.headers, body); + } + + /** + * Update Taxonomy call. + * + * @param taxonomyId - The taxonomy for which we need to update the details + * @param body the body + * @return the call + * + *

+ * Example + *
+     *     {@code
+     *     JSONObject body = new JSONObject();
+     *     JSONObject bodyContent = new JSONObject();
+     *     bodyContent.put("name", "Taxonomy 1");
+     *     bodyContent.put("description", "Description updated for Taxonomy 1);
+     *     body.put("taxonomy", bodyContent);
+     *     Response response = taxonomy.update("taxonomyId", body).execute();
+     *     }
+     * 
+ */ + public Call update(@NotNull String taxonomyId, @NotNull JSONObject body) { + return this.taxonomyService.update(this.headers, taxonomyId, body); + } + + /** + * Delete Taxonomy call. + * + * @param taxonomyId - The taxonomy for which we need to update the details + * @return the call + *

+ * Example + *
+     *     {@code
+     *     Response response = taxonomy.delete("taxonomyId").execute();
+     *     }
+     * 
+ */ + public Call delete(@NotNull String taxonomyId) { + return this.taxonomyService.delete(this.headers, taxonomyId); + } + + /** + * Clear params for internal uses only for testing + */ + protected void clearParams() { + this.params.clear(); + } + + + /** + * Get terms information + *

+ *

Examples

+ *
+     *     {@code
+     *     Term terms = stack("authtoken").taxonomy("taxonomyId").term();
+     *     }
+     * 
+ * + * @return instance of {@link Terms} + */ + public Terms terms() { + return new Terms(this.taxonomyService, this.headers, this.taxonomyId); + } + + +} diff --git a/src/main/java/com/contentstack/cms/stack/TaxonomyService.java b/src/main/java/com/contentstack/cms/stack/TaxonomyService.java new file mode 100644 index 00000000..d000927b --- /dev/null +++ b/src/main/java/com/contentstack/cms/stack/TaxonomyService.java @@ -0,0 +1,50 @@ +package com.contentstack.cms.stack; + +import okhttp3.ResponseBody; +import org.json.simple.JSONObject; +import retrofit2.Call; +import retrofit2.http.*; + +import java.util.HashMap; +import java.util.Map; + +public interface TaxonomyService { + + @GET("taxonomies") + Call find(@HeaderMap Map headers, @QueryMap Map params); + + @GET("taxonomies/{taxonomy_uid}") + Call fetch(@HeaderMap Map headers, @Path("taxonomy_uid") String uid, @QueryMap Map query); + + @GET("taxonomies") + Call create(@HeaderMap Map headers, @Body JSONObject body); + + @PUT("taxonomies/{taxonomy_uid}") + Call update(@HeaderMap Map headers, @Path("taxonomy_uid") String uid, @Body JSONObject body); + + @DELETE("taxonomies/{taxonomy_uid}") + Call delete(@HeaderMap Map headers, @Path("taxonomy_uid") String uid); + + //--Terms-- + @POST("taxonomies/{taxonomy_uid}/terms") + Call createTerm(@HeaderMap HashMap headers, @Path("taxonomy_uid") String taxonomyId, @Body JSONObject body); + + @GET("taxonomies/{taxonomy_uid}/terms") + Call findTerm(@HeaderMap HashMap headers, @Path("taxonomy_uid") String taxonomyId, @QueryMap Map queryParams); + + @GET("taxonomies/{taxonomy_uid}/terms/{term_id}") + Call fetchTerm(@HeaderMap HashMap headers, @Path("taxonomy_uid") String taxonomyId, @Path("term_id") String termId, @QueryMap Map queryParams); + + @GET("taxonomies/{taxonomy_uid}/terms/{term_id}/descendants") + Call descendantsTerm(@HeaderMap HashMap headers, @Path("taxonomy_uid") String taxonomyId, @Path("term_id") String termId, @QueryMap Map queryParams); + + @GET("taxonomies/{taxonomy_uid}/terms/{term_id}/ancestors") + Call ancestorsTerm(@HeaderMap HashMap headers, @Path("taxonomy_uid") String taxonomyId, @Path("term_id") String termId, @QueryMap Map queryParams); + + @PUT("taxonomies/{taxonomy_uid}/terms/{term_id}") + Call updateTerm(@HeaderMap HashMap headers, @Path("taxonomy_uid") String taxonomyId, @Path("term_id") String termId, @Body JSONObject body); + + @GET("taxonomies/all/terms?term={term_string}") + Call searchTerm(@HeaderMap HashMap headers, @Path("term_string") String termString); + +} diff --git a/src/main/java/com/contentstack/cms/stack/Terms.java b/src/main/java/com/contentstack/cms/stack/Terms.java new file mode 100644 index 00000000..2a258913 --- /dev/null +++ b/src/main/java/com/contentstack/cms/stack/Terms.java @@ -0,0 +1,277 @@ +package com.contentstack.cms.stack; + +import com.contentstack.cms.BaseImplementation; +import okhttp3.ResponseBody; +import org.jetbrains.annotations.NotNull; +import org.json.simple.JSONObject; +import retrofit2.Call; + +import java.util.HashMap; + +/** + * @author @ishaileshmishra + * @since 1.1.0 + * provides an implementation + *
    + *
  • Create a Term
  • + *
  • Get all Terms of a Taxonomy
  • + *
  • Get a single Term
  • + *
  • Get descendants of a single Term
  • + *
  • Get ancestors of a single Term
  • + *
  • Update a Term
  • + *
  • Search for all Terms within all Taxonomies
  • + *
+ */ +public class Terms implements BaseImplementation { + + final TaxonomyService taxonomyService; + final HashMap headers; + final String taxonomyId; + final HashMap params; + + + public Terms(@NotNull TaxonomyService service, HashMap headers, String taxonomyId) { + this.taxonomyService = service; + this.headers = headers; + this.taxonomyId = taxonomyId; + this.params = new HashMap<>(); + } + + + /** + * @param key A string representing the key of the parameter. It cannot be + * null and must be + * provided as a non-null value. + * @param value The "value" parameter is of type Object, which means it can + * accept any type of + * object as its value. + * @return instance of Terms + */ + @Override + public Terms addParam(@NotNull String key, @NotNull Object value) { + this.params.put(key, value); + return this; + } + + /** + * @param key The key parameter is a string that represents the name or + * identifier of the header. + * It is used to specify the type of information being sent in the + * header. + * @param value The value parameter is a string that represents the value of the + * header. + * @return instance of Terms + */ + @Override + public Terms addHeader(@NotNull String key, @NotNull String value) { + this.headers.put(key, value); + return this; + } + + /** + * @param params The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of Terms + */ + @Override + public Terms addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + /** + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of Terms + */ + @Override + public Terms addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; + } + + + /** + * Create Terms call. + * + * @param body The JSONObject request body + * @return instance of Call + * + *

+ * Example + *
+     *     {@code
+     *     Stack stack = new Contentstack.Builder().build().stack(headers);
+     *     JSONObject body = new JSONObject();
+     *     Term term = stack.taxonomy("taxonomyId").terms().create(body);
+     *     }
+     * 
+ */ + public Call create(@NotNull JSONObject body) { + return this.taxonomyService.createTerm(this.headers, taxonomyId, body); + } + + /** + *

+ * Supported Query Parameters: to use query parameters use #addParams("key", "value"); + *

    + *
  • + * taxonomy_uid - The taxonomy for which we need the terms + *
  • + *
  • + * depth - Include the terms upto the depth specified if set to a number greater than 0, include all the terms if set to 0, default depth will be set to 1 + *
  • + *
  • + * include_children_count - Include count of number of children under each term if set to true + *
  • + *
  • + * include_referenced_entries_count - Include count of the entries where this term is referred + *
  • + *
  • + * include_count - Include count of the documents/nodes that matched the query + *
  • + *
  • + * asc|desc - Sort the given field in either ascending or descending order + *
  • + *
  • + * typeahead - Used to match the given string in all terms and return the matched result + *
  • + *
  • + * deleted - Used to fetch only the deleted terms + *
  • + *
  • + * skip - Skip the number of documents/nodes + *
  • + *
  • + * limit - Limit the result to number of documents/nodes + *
  • + *
+ *

+ * Example + *
+     *     {@code
+     *     Stack stack = new Contentstack.Builder().build().stack(headers);
+     *     Term term = stack.taxonomy("taxonomyId").terms().addParam("limit", 2).find();
+     *     }
+     * 
+ * + * @see #addParam(String, Object) to add query parameters + * returns instance of Call + */ + public Call find() { + return this.taxonomyService.findTerm(this.headers, taxonomyId, this.params); + } + + /** + * Fetch single term based on term uid. + * + * @param termUid The term for which we need the details + * @return instance of call

Supported Query Parameters: to use query parameters use #addParams("key", "value");

  • include_children_count - Include count of number of children under each term
  • include_referenced_entries_count - Include count of the entries where this term is referred

Example
     {@code
+     *     Stack stack = new Contentstack.Builder().build().stack(headers);
+     *     Term term = stack.taxonomy("taxonomyId").terms().find();
+     *     } 
+ * @see #addParam(String, Object) #addParam(String, Object)to add query parameters + */ + public Call fetch(@NotNull String termUid) { + return this.taxonomyService.fetchTerm(this.headers, taxonomyId, termUid, this.params); + } + + /** + * Get descendants of a single Term + * + * @param termUid The term for which we need the details + * @return The details of the term descendants + *

+ * URL/Query parameters + *

    + *
  • + * depth - Include the terms upto the depth specified if set to a number greater than 0, include all the terms if set to 0, default depth will be set to 1 + *
  • + * include_children_count - Include count of number of children under each term + *
  • + * include_referenced_entries_count - Include count of the entries where atleast 1 term of this taxonomy is referred + *
  • + * include_count - Include count of the documents/nodes that matched the query + *
  • + * skip - Skip the number of documents/nodes + *
  • + * limit - Limit the result to number of documents/nodes + *
  • + *
+ *

Example

 {@code
+     *      Stack stack = new Contentstack.Builder().build().stack(headers);
+     *      Term term = stack.taxonomy("taxonomyId").terms().descendants("termId").;
+     *     }
+     *     
+ *

+ */ + public Call descendants(@NotNull String termUid) { + return this.taxonomyService.descendantsTerm(this.headers, this.taxonomyId, termUid, this.params); + } + + /** + * Get ancestors of a single Term + * + * @param termUid The term for which we need the details + * @return The details of the term ancestors + *

Example

 {@code
+     *      Stack stack = new Contentstack.Builder().build().stack(headers);
+     *      Term term = stack.taxonomy("taxonomyId").terms().ancestors("termId");
+     *     }
+     *     
+ * + */ + public Call ancestors(@NotNull String termUid) { + return this.taxonomyService.ancestorsTerm(this.headers, this.taxonomyId, termUid, this.params); + } + + /** + * @param termUid - The term for which we need the details + * @param body the JSONObject body for the request + * @return instance of Call + *

+ * Example + *

+     * {@code
+     *   body = new RequestBody{
+     *   "term": {
+     *     "name": "Term 1",
+     *     "description": "Term 1 Description updated for Taxonomy 1"
+     *   }
+     * }
+     *
+     * Stack stack = new Contentstack.Builder().build().stack(headers);
+     * Term term = stack.taxonomy("taxonomyId").terms().update(body);
+     * }
+     * 
+ */ + public Call update(@NotNull String termUid, @NotNull JSONObject body) { + return this.taxonomyService.updateTerm(this.headers, this.taxonomyId, termUid, body); + } + + + /** + * @param termString: The string for which we need to search for the matching terms, should either match with term uid or term name + * @return instance of Call + *

+ + * Example + *

+     * {@code
+     * Stack stack = new Contentstack.Builder().build().stack(headers);
+     * Term term = stack.taxonomy("taxonomyId").terms().search("search anything");
+     * }
+     * 
+ */ + public Call search(@NotNull String termString) { + return this.taxonomyService.searchTerm(this.headers, termString); + } + + + protected void clearParams() { + this.params.clear(); + } +} diff --git a/src/main/java/com/contentstack/cms/stack/Webhook.java b/src/main/java/com/contentstack/cms/stack/Webhook.java index 1b23d654..d209d17a 100644 --- a/src/main/java/com/contentstack/cms/stack/Webhook.java +++ b/src/main/java/com/contentstack/cms/stack/Webhook.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import com.contentstack.cms.core.Util; import okhttp3.MediaType; import okhttp3.MultipartBody; @@ -30,7 +31,7 @@ * * @since 2022-10-22 */ -public class Webhook { +public class Webhook implements BaseImplementation { protected final WebhookService service; protected HashMap headers; @@ -55,24 +56,60 @@ void validate() { throw new IllegalAccessError("Webhook uid can not be null or empty"); } + /** - * Sets header for the request - * - * @param key header key for the request - * @param value header value for the request + * @param key A string representing the key of the parameter. It cannot be + * null and must be + * provided as a non-null value. + * @param value The "value" parameter is of type Object, which means it can + * accept any type of + * object as its value. + * @return instance of {@link Webhook} + */ + @Override + public Webhook addParam(@NotNull String key, @NotNull Object value) { + this.params.put(key, value); + return this; + } + + /** + * @param key The key parameter is a string that represents the name or + * identifier of the header. + * It is used to specify the type of information being sent in the + * header. + * @param value The value parameter is a string that represents the value of the + * header. + * @return instance of {@link Webhook} */ - public void addHeader(@NotNull String key, @NotNull Object value) { + @Override + public Webhook addHeader(@NotNull String key, @NotNull String value) { this.headers.put(key, value); + return this; } /** - * Sets header for the request - * - * @param key query param key for the request - * @param value query param value for the request + * @param params The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of {@link Webhook} */ - public void addParam(@NotNull String key, @NotNull Object value) { - this.params.put(key, value); + @Override + public Webhook addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + /** + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of {@link Webhook} + */ + @Override + public Webhook addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; } /** @@ -105,7 +142,7 @@ protected void clearParams() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-webhooks">Get * all Webhooks * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -171,7 +208,7 @@ public Call fetch() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#create-a-webhook">Create * a Webhook * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call create(@NotNull JSONObject requestBody) { @@ -220,7 +257,7 @@ public Call create(@NotNull JSONObject requestBody) { * a * Webhook * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call update(JSONObject requestBody) { @@ -240,7 +277,7 @@ public Call update(JSONObject requestBody) { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-webhook">Delete * Webhook * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -261,7 +298,7 @@ public Call delete() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#export-a-webhook">Export * Webhook * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -283,7 +320,7 @@ public Call export() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#import-a-webhook">Import * Webhook * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -304,7 +341,7 @@ public Call importWebhook(@NotNull String fileName, @NotNull Strin * "https://www.contentstack.com/docs/developers/apis/content-management-api/#import-an-existing-webhook">Import * Existing * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call importExisting() { @@ -370,7 +407,7 @@ public Call importExisting() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-executions-of-a-webhook">Get * executions of a webhook * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -397,7 +434,7 @@ public Call getExecutions() { * a * Webhook * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call retry(@NotNull String executionUid) { @@ -422,7 +459,7 @@ public Call retry(@NotNull String executionUid) { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-latest-execution-log-of-a-webhook">Get * latest execution log of a webhook * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call getExecutionLog(@NotNull String executionUid) { diff --git a/src/main/java/com/contentstack/cms/stack/Workflow.java b/src/main/java/com/contentstack/cms/stack/Workflow.java index cf9162c6..3dbff4dd 100644 --- a/src/main/java/com/contentstack/cms/stack/Workflow.java +++ b/src/main/java/com/contentstack/cms/stack/Workflow.java @@ -1,5 +1,6 @@ package com.contentstack.cms.stack; +import com.contentstack.cms.BaseImplementation; import okhttp3.ResponseBody; import org.jetbrains.annotations.NotNull; import org.json.simple.JSONObject; @@ -16,7 +17,6 @@ *

* Read more about Workflow - * * Note: You cannot create workflows in a stack that supports branches * when using the classic Contentstack interface. * @@ -24,7 +24,7 @@ * @version v01.0 * @since 2022-10-22 */ -public class Workflow { +public class Workflow implements BaseImplementation { protected final WorkflowService service; protected HashMap headers; @@ -49,25 +49,6 @@ void validate() { throw new IllegalAccessError("Workflow uid can not be null or empty"); } - /** - * Sets header for the request - * - * @param key header key for the request - * @param value header value for the request - */ - public void addHeader(@NotNull String key, @NotNull Object value) { - this.headers.put(key, value); - } - - /** - * Sets header for the request - * - * @param key query param key for the request - * @param value query param value for the request - */ - public void addParam(@NotNull String key, @NotNull Object value) { - this.params.put(key, value); - } /** * Set header for the request @@ -94,7 +75,7 @@ protected void clearParams() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-workflows">Get * all workflow * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call find() { @@ -111,7 +92,7 @@ public Call find() { * a singel * workflow * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call fetch() { @@ -139,7 +120,6 @@ public Call fetch() { * To control who can edit an entry at different stages of the workflow, you can * pass the entry_lock parameter * inside each workflow stage. - * * Note: Workflow superusers, organization owners, and stack * owners/admins can edit or delete the entry in any workflow stage, * irrespective of the stage access rules set for @@ -154,7 +134,7 @@ public Call fetch() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#create-a-workflow">Create * workflow * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call create(@NotNull JSONObject requestBody) { @@ -193,7 +173,7 @@ public Call create(@NotNull JSONObject requestBody) { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#add-or-update-workflow-details">Update * Workflow * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call update(@NotNull JSONObject requestBody) { @@ -208,9 +188,8 @@ public Call update(@NotNull JSONObject requestBody) { * @see Disable * workflow - * * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call disable() { @@ -226,7 +205,7 @@ public Call disable() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#enable-workflow">Enable * Workflow * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -243,7 +222,7 @@ public Call enable() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-workflow">Delete * Workflow * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -279,7 +258,7 @@ public Call delete() { * Publish * Rule * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call createPublishRule(@NotNull JSONObject requestBody) { @@ -303,7 +282,7 @@ public Call createPublishRule(@NotNull JSONObject requestBody) { * Publish * Rules * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call updatePublishRule(@NotNull String ruleUid, @NotNull JSONObject requestBody) { @@ -314,14 +293,14 @@ public Call updatePublishRule(@NotNull String ruleUid, @NotNull JS * To Delete Publish Rules request allows you to delete an existing publish * rule. * - * @param ruleUid The UID of the publish rule that you want to delete + * @param ruleUid The UID of the publishing rule that you want to delete * @return Call * @see Delete * Publish * Rules * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -341,7 +320,7 @@ public Call deletePublishRule(@NotNull String ruleUid) { * all publish * rule * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -356,15 +335,14 @@ public Call fetchPublishRules(@NotNull List contentTypes) * a specific publish rule of a * Workflow. * - * @param ruleUid The UID of the publish rule that you want to fetch + * @param ruleUid The UID of the publishing rule that you want to fetch * @return Call * @see Get * all publish * rules - * * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -388,7 +366,7 @@ public Call fetchPublishRule(@NotNull String ruleUid) { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-publish-rules-by-content-types">Get * Publish Rules By Content Types * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -417,4 +395,58 @@ public Call fetchTasks() { return this.service.fetchTasks(this.headers, this.params); } + /** + * @param key A string representing the key of the parameter. It cannot be + * null and must be + * provided as a non-null value. + * @param value The "value" parameter is of type Object, which means it can + * accept any type of + * object as its value. + * @return instance of the {@link Workflow} + */ + @Override + public Workflow addParam(@NotNull String key, @NotNull Object value) { + this.params.put(key, value); + return this; + } + + /** + * @param key The key parameter is a string that represents the name or + * identifier of the header. + * It is used to specify the type of information being sent in the + * header. + * @param value The value parameter is a string that represents the value of the + * header. + * @return instance of the {@link Workflow} + */ + @Override + public Workflow addHeader(@NotNull String key, @NotNull String value) { + this.headers.put(key, value); + return this; + } + + /** + * @param params The "params" parameter is a HashMap that maps String keys to + * Object values. It is + * annotated with @NotNull, indicating that it cannot be null. + * @return instance of the {@link Workflow} + */ + @Override + public Workflow addParams(@NotNull HashMap params) { + this.params.putAll(params); + return this; + } + + /** + * @param headers A HashMap containing key-value pairs of headers, where the key + * is a String + * representing the header name and the value is a String + * representing the header value. + * @return instance of the {@link Workflow} + */ + @Override + public Workflow addHeaders(@NotNull HashMap headers) { + this.headers.putAll(headers); + return this; + } } diff --git a/src/test/java/com/contentstack/cms/ContentstackUnitTest.java b/src/test/java/com/contentstack/cms/ContentstackUnitTest.java index 3b933270..ea4e09f6 100644 --- a/src/test/java/com/contentstack/cms/ContentstackUnitTest.java +++ b/src/test/java/com/contentstack/cms/ContentstackUnitTest.java @@ -116,11 +116,11 @@ void testClientSetPortMethod() { @Test void setProxy() { // This is how a developer can set the proxy - Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433)); + Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("api.contentstack.io", 433)); Contentstack contentstack = new Contentstack.Builder() .setProxy(proxy) .build(); - Assertions.assertEquals("HTTP @ hostname:433", contentstack.proxy.toString()); + Assertions.assertNotNull(contentstack.proxy.toString()); } @@ -250,7 +250,7 @@ public void testValidOrganization() { @Test public void testNullOrganizationUid() { Contentstack client = new Contentstack.Builder().setAuthtoken("fake@authtoken").build(); - Assertions.assertThrows(NullPointerException.class, () -> client.organization(null)); + Assertions.assertThrows(IllegalArgumentException.class, () -> client.organization(null)); } @Test diff --git a/src/test/java/com/contentstack/cms/organization/OrgUnitTests.java b/src/test/java/com/contentstack/cms/organization/OrgUnitTests.java index eb0b9960..df697565 100644 --- a/src/test/java/com/contentstack/cms/organization/OrgUnitTests.java +++ b/src/test/java/com/contentstack/cms/organization/OrgUnitTests.java @@ -632,14 +632,5 @@ void testGetLogItemsRequestParam() { requestInfo.url().query()); } - @Test - @Order(59) - void testGetAllWithQueryParamLimit() { - Request requestInfo = organization.removeParam("asc").find().request(); - Assertions.assertEquals("GET", requestInfo.method()); - assertTrue(isValid(requestInfo.url().toString())); - assertNull(requestInfo.url().queryParameter("limit")); - - } } diff --git a/src/test/java/com/contentstack/cms/stack/AssetAPITest.java b/src/test/java/com/contentstack/cms/stack/AssetAPITest.java index 35f52fc2..c4df3ca2 100644 --- a/src/test/java/com/contentstack/cms/stack/AssetAPITest.java +++ b/src/test/java/com/contentstack/cms/stack/AssetAPITest.java @@ -250,7 +250,7 @@ void testAssetDownloadPermanentUrl() throws IOException { @Test void testAssetUploadWithMultipleParams() throws IOException { String description = "The calender has been placed to assets by ishaileshmishra"; - String filePath = "/Users/shailesh.mishra/Desktop/contentstack-management-java/src/test/resources/asset.png"; + String filePath = "/Users/shaileshmishra/Documents/workspace/GitHub/contentstack-management-java/src/test/resources/asset.png"; Contentstack client = new Contentstack.Builder().build(); Stack stack = client.stack("Your-api-key", "authorization"); Response upload = stack.asset() diff --git a/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java b/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java new file mode 100644 index 00000000..8b3c5e09 --- /dev/null +++ b/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java @@ -0,0 +1,269 @@ +package com.contentstack.cms.stack; + +import com.contentstack.cms.Contentstack; +import com.contentstack.cms.TestClient; +import com.contentstack.cms.core.Util; +import okhttp3.Request; +import okhttp3.ResponseBody; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.junit.jupiter.api.*; +import retrofit2.Response; + +import java.io.IOException; +import java.util.HashMap; + +@Tag("unit") +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class TaxonomyTest { + + protected static String API_KEY = TestClient.API_KEY; + protected static String _uid = TestClient.AUTHTOKEN; + protected static String MANAGEMENT_TOKEN = TestClient.MANAGEMENT_TOKEN; + protected static Taxonomy taxonomy; + protected static Terms terms; + protected static JSONObject body; + + // Create a JSONObject, JSONObject could be created in multiple ways. + // We choose JSONParser that converts string to JSONObject + static String theBody = "{\n" + + " \"taxonomy\": {\n" + + " \"name\": \"Taxonomy 1\",\n" + + " \"description\": \"Description updated for Taxonomy 1\"\n" + + " }\n" + + "}"; + + @BeforeAll + static void setup() { + final String AUTHTOKEN = TestClient.AUTHTOKEN; + HashMap headers = new HashMap<>(); + headers.put(Util.API_KEY, API_KEY); + headers.put(Util.AUTHORIZATION, MANAGEMENT_TOKEN); + Stack stack = new Contentstack.Builder().setAuthtoken(AUTHTOKEN).build().stack(headers); + taxonomy = stack.taxonomy(); + terms = stack.taxonomy(_uid).terms(); + try { + JSONParser parser = new JSONParser(); + body = (JSONObject) parser.parse(theBody); + } catch (ParseException e) { + System.out.println(e.getLocalizedMessage()); + throw new RuntimeException(e); + } + + } + + @Test + void findTest() { + Request request = taxonomy.find().request(); + Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals("GET", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(2, request.url().pathSegments().size()); + Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); + Assertions.assertEquals("v3", request.url().pathSegments().get(0)); + Assertions.assertNotNull(request.url().encodedQuery()); + Assertions.assertEquals( + "https://api.contentstack.io/v3/taxonomies?include_rules=true&include_permissions=true", + request.url().toString()); + } + + @Test + void findTestWithParams() { + taxonomy.addParam("limit", 2); + taxonomy.addParam("skip", 2); + taxonomy.addParam("include_count", false); + Request request = taxonomy.find().request(); + Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals("GET", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(2, request.url().pathSegments().size()); + Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); + Assertions.assertEquals("v3", request.url().pathSegments().get(0)); + Assertions.assertNotNull(request.url().encodedQuery()); + Assertions.assertEquals( + "https://api.contentstack.io/v3/taxonomies?limit=2&skip=2&include_count=false", + request.url().toString()); + } + + @Test + void findTestCustomParams() { + taxonomy.clearParams(); + taxonomy.addParam("include_rules", true); + taxonomy.addParam("include_permissions", true); + Request request = taxonomy.find().request(); + Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals("GET", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(2, request.url().pathSegments().size()); + Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); + Assertions.assertEquals("v3", request.url().pathSegments().get(0)); + Assertions.assertNotNull(request.url().encodedQuery()); + Assertions.assertEquals( + "https://api.contentstack.io/v3/taxonomies?include_rules=true&include_permissions=true", + request.url().toString()); + } + + @Test + void fetchTest() { + Request request = taxonomy.fetch("taxonomyId").request(); + Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals("GET", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(3, request.url().pathSegments().size()); + Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); + Assertions.assertEquals("v3", request.url().pathSegments().get(0)); + Assertions.assertNotNull(request.url().encodedQuery()); + Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/taxonomyId?limit=2&skip=2&include_count=false", request.url().toString()); + } + + @Test + void updateTest() { + Request request = taxonomy.update("taxonomyId", body).request(); + Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals("PUT", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(3, request.url().pathSegments().size()); + Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); + Assertions.assertNotNull(request.body()); + Assertions.assertNull(request.url().encodedQuery()); + Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/taxonomyId", request.url().toString()); + } + + @Test + void deleteTest() { + Request request = taxonomy.delete("taxonomyId").request(); + Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals("DELETE", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(3, request.url().pathSegments().size()); + Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); + Assertions.assertNull(request.body()); + Assertions.assertNull(request.url().encodedQuery()); + Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/taxonomyId", request.url().toString()); + } + + @Test + void testCreateTerm() { + terms.clearParams(); + JSONObject term = new JSONObject(); + JSONObject termDetails = new JSONObject(); + termDetails.put("uid", "term_1"); + termDetails.put("name", "Term 1"); + termDetails.put("description", "Term 1 Description for Taxonomy 1"); + term.put("term", termDetails); + term.put("parent_uid", null); + Request request = terms.create(term).request(); + Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals("POST", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(4, request.url().pathSegments().size()); + Assertions.assertEquals("v3", request.url().pathSegments().get(0)); + Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); + Assertions.assertEquals(_uid, request.url().pathSegments().get(2)); + Assertions.assertEquals("terms", request.url().pathSegments().get(3)); + Assertions.assertNotNull(request.body()); + Assertions.assertNull(request.url().encodedQuery()); + Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms", request.url().toString()); + } + + @Test + void testFindTerm() { + terms.clearParams(); + terms.addParam("limit", 3); + Request request = terms.find().request(); + Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals("GET", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(4, request.url().pathSegments().size()); + Assertions.assertEquals("v3", request.url().pathSegments().get(0)); + Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); + Assertions.assertEquals(_uid, request.url().pathSegments().get(2)); + Assertions.assertEquals("terms", request.url().pathSegments().get(3)); + Assertions.assertNull(request.body()); + Assertions.assertEquals("limit=3", request.url().encodedQuery()); + Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/" + _uid + "/terms?limit=3", request.url().toString()); + } + + @Test + void testFetchTerm() { + terms.clearParams(); + terms.addParam("include_referenced_entries_count", true); + terms.addParam("include_children_count", false); + + Request request = terms.fetch(_uid).request(); + Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals("GET", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(5, request.url().pathSegments().size()); + Assertions.assertEquals("v3", request.url().pathSegments().get(0)); + Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); + Assertions.assertEquals(_uid, request.url().pathSegments().get(2)); + Assertions.assertEquals("terms", request.url().pathSegments().get(3)); + Assertions.assertNull(request.body()); + Assertions.assertEquals("include_children_count=false&include_referenced_entries_count=true", request.url().encodedQuery()); + Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms/auth999999999?include_children_count=false&include_referenced_entries_count=true", request.url().toString()); + } + + @Test + void testDescendantsTerm() { + terms.clearParams(); + terms.addParam("include_count", true); + Request request = terms.descendants("termId45").request(); + Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals("GET", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(6, request.url().pathSegments().size()); + Assertions.assertEquals("v3", request.url().pathSegments().get(0)); + Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); + Assertions.assertEquals(_uid, request.url().pathSegments().get(2)); + Assertions.assertEquals("terms", request.url().pathSegments().get(3)); + Assertions.assertNull(request.body()); + Assertions.assertEquals("include_count=true", request.url().encodedQuery()); + Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms/termId45/descendants?include_count=true", request.url().toString()); + } + + @Test + void testAncestorsTerm() { + terms.clearParams(); + terms.addParam("include_referenced_entries_count", true); + terms.addParam("include_children_count", false); + Request request = terms.ancestors("termId45").request(); + Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals("GET", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(6, request.url().pathSegments().size()); + Assertions.assertEquals("v3", request.url().pathSegments().get(0)); + Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); + Assertions.assertEquals(_uid, request.url().pathSegments().get(2)); + Assertions.assertEquals("terms", request.url().pathSegments().get(3)); + Assertions.assertNull(request.body()); + Assertions.assertEquals("include_children_count=false&include_referenced_entries_count=true", request.url().encodedQuery()); + Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms/termId45/ancestors?include_children_count=false&include_referenced_entries_count=true", request.url().toString()); + } + + @Test + void findTestAPI() throws IOException { + Taxonomy taxonomy = new Contentstack.Builder() + .setAuthtoken("blt67b95aeb964f5262") + .setHost("dev18-app.csnonprod.com") + .build() + .stack("blt12c1ba95c1b11e88", "") + .taxonomy(); + Response response = taxonomy.addHeader("authtoken", "blt67b95aeb964f5262").find().execute(); + System.out.println(response); + //Assertions.assertEquals(2, request.headers().names().size()); + } + +} From ecdd3289670b0e87473d262a5a1cc84357b7a6e9 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Mon, 18 Sep 2023 20:12:50 +0530 Subject: [PATCH 2/7] Taxonomy and Terms --- .env | 1 + pom.xml | 16 ++-- .../cms/stack/TaxonomyService.java | 60 ++++++++++---- .../com/contentstack/cms/stack/Terms.java | 9 ++- .../java/com/contentstack/cms/TestClient.java | 1 + .../contentstack/cms/stack/TaxonomyTest.java | 81 +++++++++++++++++-- 6 files changed, 138 insertions(+), 30 deletions(-) diff --git a/.env b/.env index e69de29b..236d6798 100644 --- a/.env +++ b/.env @@ -0,0 +1 @@ +dev-host=dev18-app.csnonprod.com \ No newline at end of file diff --git a/pom.xml b/pom.xml index e0960a9a..81551d9c 100644 --- a/pom.xml +++ b/pom.xml @@ -7,13 +7,14 @@ cms jar contentstack-management-java - 1.1.0 + 1.1.0-SNAPSHOT Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an API-first approach https://github.com/contentstack/contentstack-management-java/ - + + org.sonatype.oss oss-parent @@ -87,15 +88,14 @@ 2.2.1 3.0.0 5.2.2 - 3.1.6 + 3.1.7 2.9.0 2.9.0 - 4.10.0 + 5.0.0-alpha.11 0.8.7 1.18.28 - 5.9.2 + 5.10.0 5.8.0-M1 - 5.9.2 2.10.1 3.3 1.5 @@ -162,13 +162,13 @@ org.junit.vintage junit-vintage-engine - ${junit-vintage-engine.version} + ${junit-jupiter.version} test org.mockito mockito-core - 2.8.9 + 5.5.0 test diff --git a/src/main/java/com/contentstack/cms/stack/TaxonomyService.java b/src/main/java/com/contentstack/cms/stack/TaxonomyService.java index d000927b..aebf2cb7 100644 --- a/src/main/java/com/contentstack/cms/stack/TaxonomyService.java +++ b/src/main/java/com/contentstack/cms/stack/TaxonomyService.java @@ -16,35 +16,67 @@ public interface TaxonomyService { @GET("taxonomies/{taxonomy_uid}") Call fetch(@HeaderMap Map headers, @Path("taxonomy_uid") String uid, @QueryMap Map query); - @GET("taxonomies") - Call create(@HeaderMap Map headers, @Body JSONObject body); + @POST("taxonomies") + Call create( + @HeaderMap Map headers, + @Body JSONObject body); @PUT("taxonomies/{taxonomy_uid}") - Call update(@HeaderMap Map headers, @Path("taxonomy_uid") String uid, @Body JSONObject body); + Call update( + @HeaderMap Map headers, + @Path("taxonomy_uid") String uid, + @Body JSONObject body); @DELETE("taxonomies/{taxonomy_uid}") - Call delete(@HeaderMap Map headers, @Path("taxonomy_uid") String uid); + Call delete( + @HeaderMap Map headers, + @Path("taxonomy_uid") String uid); //--Terms-- @POST("taxonomies/{taxonomy_uid}/terms") - Call createTerm(@HeaderMap HashMap headers, @Path("taxonomy_uid") String taxonomyId, @Body JSONObject body); + Call createTerm( + @HeaderMap HashMap headers, + @Path("taxonomy_uid") String taxonomyId, + @Body JSONObject body); @GET("taxonomies/{taxonomy_uid}/terms") - Call findTerm(@HeaderMap HashMap headers, @Path("taxonomy_uid") String taxonomyId, @QueryMap Map queryParams); + Call findTerm( + @HeaderMap HashMap headers, + @Path("taxonomy_uid") String taxonomyId, + @QueryMap Map queryParams); @GET("taxonomies/{taxonomy_uid}/terms/{term_id}") - Call fetchTerm(@HeaderMap HashMap headers, @Path("taxonomy_uid") String taxonomyId, @Path("term_id") String termId, @QueryMap Map queryParams); + Call fetchTerm( + @HeaderMap HashMap headers, + @Path("taxonomy_uid") String taxonomyId, + @Path("term_id") String termId, + @QueryMap Map queryParams); @GET("taxonomies/{taxonomy_uid}/terms/{term_id}/descendants") - Call descendantsTerm(@HeaderMap HashMap headers, @Path("taxonomy_uid") String taxonomyId, @Path("term_id") String termId, @QueryMap Map queryParams); + Call descendantsTerm( + @HeaderMap HashMap headers, + @Path("taxonomy_uid") String taxonomyId, + @Path("term_id") String termId, + @QueryMap Map queryParams); @GET("taxonomies/{taxonomy_uid}/terms/{term_id}/ancestors") - Call ancestorsTerm(@HeaderMap HashMap headers, @Path("taxonomy_uid") String taxonomyId, @Path("term_id") String termId, @QueryMap Map queryParams); + Call ancestorsTerm( + @HeaderMap HashMap headers, + @Path("taxonomy_uid") String taxonomyId, + @Path("term_id") String termId, + @QueryMap Map queryParams); @PUT("taxonomies/{taxonomy_uid}/terms/{term_id}") - Call updateTerm(@HeaderMap HashMap headers, @Path("taxonomy_uid") String taxonomyId, @Path("term_id") String termId, @Body JSONObject body); - - @GET("taxonomies/all/terms?term={term_string}") - Call searchTerm(@HeaderMap HashMap headers, @Path("term_string") String termString); - + Call updateTerm( + @HeaderMap HashMap headers, + @Path("taxonomy_uid") String taxonomyId, + @Path("term_id") String termId, + @Body JSONObject body); + + + @GET("taxonomies/all/terms") + Call searchTerm( + @HeaderMap HashMap headers, + @Query("term") String termString + ); } diff --git a/src/main/java/com/contentstack/cms/stack/Terms.java b/src/main/java/com/contentstack/cms/stack/Terms.java index 2a258913..c91f2f2a 100644 --- a/src/main/java/com/contentstack/cms/stack/Terms.java +++ b/src/main/java/com/contentstack/cms/stack/Terms.java @@ -222,7 +222,6 @@ public Call descendants(@NotNull String termUid) { * Term term = stack.taxonomy("taxonomyId").terms().ancestors("termId"); * } * - * */ public Call ancestors(@NotNull String termUid) { return this.taxonomyService.ancestorsTerm(this.headers, this.taxonomyId, termUid, this.params); @@ -231,7 +230,7 @@ public Call ancestors(@NotNull String termUid) { /** * @param termUid - The term for which we need the details * @param body the JSONObject body for the request - * @return instance of Call + * @return instance of Call *

* Example *

@@ -257,7 +256,7 @@ public Call update(@NotNull String termUid, @NotNull JSONObject bo
      * @param termString: The string for which we need to search for the matching terms, should either match with term uid or term name
      * @return instance of Call
      * 

- + * * Example *

      * {@code
@@ -265,8 +264,12 @@ public Call update(@NotNull String termUid, @NotNull JSONObject bo
      * Term term = stack.taxonomy("taxonomyId").terms().search("search anything");
      * }
      * 
+ * @throws IllegalArgumentException if the termString is empty */ public Call search(@NotNull String termString) { + if (termString.isEmpty()) { + throw new IllegalArgumentException("termString must not be empty"); + } return this.taxonomyService.searchTerm(this.headers, termString); } diff --git a/src/test/java/com/contentstack/cms/TestClient.java b/src/test/java/com/contentstack/cms/TestClient.java index 79a5ae0a..f7c3f271 100644 --- a/src/test/java/com/contentstack/cms/TestClient.java +++ b/src/test/java/com/contentstack/cms/TestClient.java @@ -17,6 +17,7 @@ public class TestClient { public final static String API_KEY = (env.get("apiKey") != null) ? env.get("apiKey") : "apiKey99999999"; public final static String MANAGEMENT_TOKEN = (env.get("managementToken") != null) ? env.get("managementToken") : "managementToken99999999"; + public final static String DEV_HOST = (env.get("dev_host") != null) ? env.get("dev_host") : "dev18-app.csnonprod.com"; private static Contentstack instance; private static Stack stackInstance; diff --git a/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java b/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java index 8b3c5e09..d6abfb74 100644 --- a/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java +++ b/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java @@ -138,7 +138,32 @@ void updateTest() { @Test void deleteTest() { Request request = taxonomy.delete("taxonomyId").request(); - Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals(5, request.headers().names().size()); + Assertions.assertEquals("DELETE", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(3, request.url().pathSegments().size()); + Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); + Assertions.assertNull(request.body()); + Assertions.assertNull(request.url().encodedQuery()); + Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/taxonomyId", request.url().toString()); + } + + + @Test + void deleteTestWithHeaders() { + taxonomy.clearParams(); + taxonomy.addHeader("Content-Type", "application/json"); + HashMap headers = new HashMap<>(); + HashMap params = new HashMap<>(); + headers.put("key_param1", "key_param_value"); + headers.put("key_param2", "key_param_value"); + params.put("key_param3", "key_param_value"); + params.put("key_param4", "key_param_value"); + taxonomy.addHeaders(headers); + taxonomy.addParams(params); + Request request = taxonomy.delete("taxonomyId").request(); + Assertions.assertEquals(5, request.headers().names().size()); Assertions.assertEquals("DELETE", request.method()); Assertions.assertTrue(request.url().isHttps()); Assertions.assertEquals("api.contentstack.io", request.url().host()); @@ -149,6 +174,22 @@ void deleteTest() { Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/taxonomyId", request.url().toString()); } + + @Test + void createTest() { + JSONObject obj = new JSONObject(); + obj.put("name", "sample"); + Request request = taxonomy.create(obj).request(); + Assertions.assertEquals(4, request.headers().names().size()); + Assertions.assertEquals("POST", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(2, request.url().pathSegments().size()); + Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); + Assertions.assertNull(request.url().encodedQuery()); + Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies", request.url().toString()); + } + @Test void testCreateTerm() { terms.clearParams(); @@ -198,7 +239,6 @@ void testFetchTerm() { terms.clearParams(); terms.addParam("include_referenced_entries_count", true); terms.addParam("include_children_count", false); - Request request = terms.fetch(_uid).request(); Assertions.assertEquals(2, request.headers().names().size()); Assertions.assertEquals("GET", request.method()); @@ -214,6 +254,38 @@ void testFetchTerm() { Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms/auth999999999?include_children_count=false&include_referenced_entries_count=true", request.url().toString()); } + + @Test + void testTermUpdate() { + terms.clearParams(); + HashMap headers = new HashMap<>(); + HashMap params = new HashMap<>(); + terms.addParam("include_referenced_entries_count", true); + terms.addParam("include_children_count", false); + terms.addHeader("Accept-Encoding", "UTF-8"); + headers.put("Accept-Encoding", "UTF-8"); + params.put("include_children_count", "true"); + terms.addParams(params); + terms.addHeaders(headers); + Request request = terms.update(_uid, new JSONObject()).request(); + Assertions.assertEquals(3, request.headers().names().size()); + Assertions.assertEquals("PUT", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(5, request.url().pathSegments().size()); + } + + @Test + void testTermSearch() { + terms.clearParams(); + Request request = terms.search("contentstack").request(); + Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals("GET", request.method()); + Assertions.assertTrue(request.url().isHttps()); + Assertions.assertEquals("api.contentstack.io", request.url().host()); + Assertions.assertEquals(4, request.url().pathSegments().size()); + } + @Test void testDescendantsTerm() { terms.clearParams(); @@ -239,7 +311,7 @@ void testAncestorsTerm() { terms.addParam("include_referenced_entries_count", true); terms.addParam("include_children_count", false); Request request = terms.ancestors("termId45").request(); - Assertions.assertEquals(2, request.headers().names().size()); + Assertions.assertEquals(3, request.headers().names().size()); Assertions.assertEquals("GET", request.method()); Assertions.assertTrue(request.url().isHttps()); Assertions.assertEquals("api.contentstack.io", request.url().host()); @@ -256,14 +328,13 @@ void testAncestorsTerm() { @Test void findTestAPI() throws IOException { Taxonomy taxonomy = new Contentstack.Builder() - .setAuthtoken("blt67b95aeb964f5262") + .setAuthtoken(TestClient.AUTHTOKEN) .setHost("dev18-app.csnonprod.com") .build() .stack("blt12c1ba95c1b11e88", "") .taxonomy(); Response response = taxonomy.addHeader("authtoken", "blt67b95aeb964f5262").find().execute(); System.out.println(response); - //Assertions.assertEquals(2, request.headers().names().size()); } } From 702f1874127842c3878aaa42d902477fb1cff0bf Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Tue, 26 Sep 2023 14:59:17 +0530 Subject: [PATCH 3/7] Taxonomy and Terms --- .../com/contentstack/cms/Contentstack.java | 53 ++++++++++++++++--- .../java/com/contentstack/cms/TestClient.java | 9 +++- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/contentstack/cms/Contentstack.java b/src/main/java/com/contentstack/cms/Contentstack.java index 938257e0..24cd6356 100644 --- a/src/main/java/com/contentstack/cms/Contentstack.java +++ b/src/main/java/com/contentstack/cms/Contentstack.java @@ -8,6 +8,7 @@ import com.contentstack.cms.stack.Stack; import com.contentstack.cms.user.User; import com.google.gson.Gson; +import okhttp3.ConnectionPool; import okhttp3.OkHttpClient; import okhttp3.ResponseBody; import okhttp3.logging.HttpLoggingInterceptor; @@ -22,6 +23,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.concurrent.TimeUnit; import java.util.logging.Logger; import static com.contentstack.cms.core.Util.*; @@ -467,6 +469,12 @@ public static class Builder { private int timeout = Util.TIMEOUT; // Default timeout 30 seconds private Boolean retry = Util.RETRY_ON_FAILURE;// Default base url for contentstack + /** + * Default ConnectionPool holds up to 5 idle connections which + * will be evicted after 5 minutes of inactivity. + */ + private ConnectionPool connectionPool = new ConnectionPool(); // Connection + /** * Instantiates a new Builder. */ @@ -479,11 +487,12 @@ public Builder() { * Proxy(Proxy.Type.HTTP, new * InetSocketAddress(proxyHost, proxyPort)); *
- * - *
-         * {
-         *     Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433));
-         *     Contentstack contentstack = new Contentstack.Builder().setProxy(proxy).build();
+         * 

+ * {@code + *

+ * Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433)); + * Contentstack contentstack = new Contentstack.Builder().setProxy(proxy).build(); + *

* } *

* @@ -550,6 +559,36 @@ public Builder setTimeout(int timeout) { return this; } + + /** + * Create a new connection pool with tuning parameters appropriate for a single-user application. + * The tuning parameters in this pool are subject to change in future OkHttp releases. Currently, + * this pool holds up to 5 idle connections which will be evicted after 5 minutes of inactivity. + *

+ *

+ * public ConnectionPool() { + * this(5, 5, TimeUnit.MINUTES); + * } + * + * @param maxIdleConnections Maximum number of idle connections + * @param keepAliveDuration The Keep Alive Duration + * @param timeUnit A TimeUnit represents time durations at a given unit of granularity and provides utility methods to convert across units + * @return instance of Builder + *

+ * Example: + * {@code + * Contentstack cs = new Contentstack.Builder() + * .setAuthtoken(AUTHTOKEN) + * .setConnectionPool(5, 400, TimeUnit.MILLISECONDS) + * .setHost("host") + * .build(); + * Connection} + */ + public Builder setConnectionPool(int maxIdleConnections, int keepAliveDuration, TimeUnit timeUnit) { + this.connectionPool = new ConnectionPool(maxIdleConnections, keepAliveDuration, timeUnit); + return this; + } + /** * Sets authtoken for the client * @@ -582,7 +621,9 @@ private void validateClient(Contentstack contentstack) { private OkHttpClient httpClient(Contentstack contentstack, Boolean retryOnFailure) { this.authInterceptor = contentstack.interceptor = new AuthInterceptor(); - return new OkHttpClient.Builder().addInterceptor(this.authInterceptor) + return new OkHttpClient.Builder() + .connectionPool(this.connectionPool) + .addInterceptor(this.authInterceptor) .addInterceptor(logger()) .proxy(this.proxy) .connectTimeout(Duration.ofSeconds(this.timeout)) diff --git a/src/test/java/com/contentstack/cms/TestClient.java b/src/test/java/com/contentstack/cms/TestClient.java index f7c3f271..4b95fea6 100644 --- a/src/test/java/com/contentstack/cms/TestClient.java +++ b/src/test/java/com/contentstack/cms/TestClient.java @@ -5,6 +5,7 @@ import io.github.cdimascio.dotenv.Dotenv; import java.util.HashMap; +import java.util.concurrent.TimeUnit; public class TestClient { @@ -41,7 +42,9 @@ public static Contentstack getCustomClient() { if (instance == null) { synchronized (Contentstack.class) { if (instance == null) { - instance = new Contentstack.Builder().setAuthtoken(AUTHTOKEN) + instance = new Contentstack.Builder() + .setAuthtoken(AUTHTOKEN) + .setConnectionPool(5, 400, TimeUnit.MILLISECONDS) .setHost("kpm.ishaileshmishra.io/path/another").build(); } } @@ -49,6 +52,10 @@ public static Contentstack getCustomClient() { return instance; } + public static void main(String[] args) { + getCustomClient(); + } + public static Stack getStack() { HashMap headers = new HashMap<>(); headers.put(Util.API_KEY, API_KEY); From e544751613a29df1996a8047df5d9d6159f5d738 Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Mon, 9 Oct 2023 19:10:17 +0530 Subject: [PATCH 4/7] Taxonomy and Terms keep Alive Duration Snyk issue --- pom.xml | 6 +- .../contentstack/cms/BaseImplementation.java | 2 +- .../com/contentstack/cms/Contentstack.java | 2 - .../com/contentstack/cms/stack/Alias.java | 10 +- .../contentstack/cms/stack/GlobalField.java | 14 +-- .../contentstack/cms/stack/PublishQueue.java | 6 +- .../com/contentstack/cms/stack/Release.java | 8 +- .../com/contentstack/cms/stack/Roles.java | 1 - .../com/contentstack/cms/stack/Taxonomy.java | 75 +++++++-------- .../com/contentstack/cms/stack/Terms.java | 95 ++++++++----------- .../com/contentstack/cms/stack/Webhook.java | 2 +- 11 files changed, 97 insertions(+), 124 deletions(-) diff --git a/pom.xml b/pom.xml index 81551d9c..9e97275f 100644 --- a/pom.xml +++ b/pom.xml @@ -88,12 +88,12 @@ 2.2.1 3.0.0 5.2.2 - 3.1.7 + 3.1.8 2.9.0 2.9.0 5.0.0-alpha.11 0.8.7 - 1.18.28 + 1.18.30 5.10.0 5.8.0-M1 2.10.1 @@ -168,7 +168,7 @@ org.mockito mockito-core - 5.5.0 + 5.6.0 test diff --git a/src/main/java/com/contentstack/cms/BaseImplementation.java b/src/main/java/com/contentstack/cms/BaseImplementation.java index 6246f887..513b7ff8 100644 --- a/src/main/java/com/contentstack/cms/BaseImplementation.java +++ b/src/main/java/com/contentstack/cms/BaseImplementation.java @@ -5,7 +5,7 @@ import java.util.HashMap; /** - * The interface @{@link BaseImplementation} + * The interface BaseImplementation */ public interface BaseImplementation { diff --git a/src/main/java/com/contentstack/cms/Contentstack.java b/src/main/java/com/contentstack/cms/Contentstack.java index 24cd6356..5e684a54 100644 --- a/src/main/java/com/contentstack/cms/Contentstack.java +++ b/src/main/java/com/contentstack/cms/Contentstack.java @@ -494,8 +494,6 @@ public Builder() { * Contentstack contentstack = new Contentstack.Builder().setProxy(proxy).build(); *

* } - *

- * * @param proxy the proxy * @return the Builder instance */ diff --git a/src/main/java/com/contentstack/cms/stack/Alias.java b/src/main/java/com/contentstack/cms/stack/Alias.java index b8ebca31..1da9ca72 100644 --- a/src/main/java/com/contentstack/cms/stack/Alias.java +++ b/src/main/java/com/contentstack/cms/stack/Alias.java @@ -18,11 +18,8 @@ * * @author ishaileshmishra * @version v0.1.0 - * @see About - * Aliases - * - * @since 2022-10-20 + * @see About Aliases + * @since 2022 -10-20 */ public class Alias implements BaseImplementation { @@ -137,7 +134,6 @@ protected void clearParams() { /** * The Get all aliases request returns comprehensive information of all the * aliases available in a particular stack in your account. - *

* * @return Call * @author ishaileshmishra @@ -179,7 +175,6 @@ public Call fetch() { * * @param body the request body * @return Call - * @author ishaileshmishra * @see Update * a @@ -201,7 +196,6 @@ public Call update(@NotNull JSONObject body) { * of your alias. * * @return Call - * @author ishaileshmishra * @see Delete * a branch diff --git a/src/main/java/com/contentstack/cms/stack/GlobalField.java b/src/main/java/com/contentstack/cms/stack/GlobalField.java index 2cc0aa4c..98df66b5 100644 --- a/src/main/java/com/contentstack/cms/stack/GlobalField.java +++ b/src/main/java/com/contentstack/cms/stack/GlobalField.java @@ -150,7 +150,7 @@ protected GlobalField clearParams() { * all * environments * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -179,7 +179,7 @@ public Call find() { * a * single global field * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -212,7 +212,7 @@ public Call fetch() { * field * * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call create(@NotNull JSONObject requestBody) { @@ -241,7 +241,7 @@ public Call create(@NotNull JSONObject requestBody) { * field * * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call update(@NotNull JSONObject requestBody) { @@ -266,7 +266,7 @@ public Call update(@NotNull JSONObject requestBody) { * global * field * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call delete() { @@ -294,7 +294,7 @@ public Call delete() { * field * * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call imports(@NotNull JSONObject body) { @@ -314,7 +314,7 @@ public Call imports(@NotNull JSONObject body) { * field * * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call export() { diff --git a/src/main/java/com/contentstack/cms/stack/PublishQueue.java b/src/main/java/com/contentstack/cms/stack/PublishQueue.java index bd5c64b7..8ab11278 100644 --- a/src/main/java/com/contentstack/cms/stack/PublishQueue.java +++ b/src/main/java/com/contentstack/cms/stack/PublishQueue.java @@ -159,7 +159,7 @@ protected void clearParams() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-publish-queue">Get * publish queue * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -182,7 +182,7 @@ public Call find() { * "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-publish-queue-activity">Get * publish queue activity * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ @@ -202,7 +202,7 @@ public Call fetchActivity() { * scheduled action * * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @see #addParam(String, Object) to add query parameters * @since 0.1.0 */ diff --git a/src/main/java/com/contentstack/cms/stack/Release.java b/src/main/java/com/contentstack/cms/stack/Release.java index 597704ca..3a137082 100644 --- a/src/main/java/com/contentstack/cms/stack/Release.java +++ b/src/main/java/com/contentstack/cms/stack/Release.java @@ -66,7 +66,7 @@ void validate() { * @param value The "value" parameter is of type Object, which means it can * accept any type of * object as its value. - * @return instance of {@link @Release} + * @return instance of Release */ @Override public Release addParam(@NotNull String key, @NotNull Object value) { @@ -81,7 +81,7 @@ public Release addParam(@NotNull String key, @NotNull Object value) { * header. * @param value The value parameter is a string that represents the value of the * header. - * @return instance of {@link @Release} + * @return instance of Release */ @Override public Release addHeader(@NotNull String key, @NotNull String value) { @@ -93,7 +93,7 @@ public Release addHeader(@NotNull String key, @NotNull String value) { * @param params The "params" parameter is a HashMap that maps String keys to * Object values. It is * annotated with @NotNull, indicating that it cannot be null. - * @return instance of {@link @Release} + * @return instance of Release */ @Override public Release addParams(@NotNull HashMap params) { @@ -106,7 +106,7 @@ public Release addParams(@NotNull HashMap params) { * is a String * representing the header name and the value is a String * representing the header value. - * @return instance of {@link @Release} + * @return instance of Release */ @Override public Release addHeaders(@NotNull HashMap headers) { diff --git a/src/main/java/com/contentstack/cms/stack/Roles.java b/src/main/java/com/contentstack/cms/stack/Roles.java index bc1e7390..2b85a2ee 100644 --- a/src/main/java/com/contentstack/cms/stack/Roles.java +++ b/src/main/java/com/contentstack/cms/stack/Roles.java @@ -12,7 +12,6 @@ /** * A role is a collection of permissions that will be applicable to all the * users who are assigned this role. - *

* * @author ishaileshmishra * @version v0.1.0 diff --git a/src/main/java/com/contentstack/cms/stack/Taxonomy.java b/src/main/java/com/contentstack/cms/stack/Taxonomy.java index ca991101..65f1fb0c 100644 --- a/src/main/java/com/contentstack/cms/stack/Taxonomy.java +++ b/src/main/java/com/contentstack/cms/stack/Taxonomy.java @@ -10,14 +10,32 @@ import java.util.HashMap; +/** + * The type Taxonomy. + */ public class Taxonomy implements BaseImplementation { private String taxonomyId; + /** + * The Taxonomy service. + */ final TaxonomyService taxonomyService; + /** + * The Headers. + */ protected HashMap headers; + /** + * The Params. + */ protected HashMap params; + /** + * Instantiates a new Taxonomy. + * + * @param client the client + * @param headers the headers + */ protected Taxonomy(Retrofit client, HashMap headers) { this.headers = new HashMap<>(); this.params = new HashMap<>(); @@ -25,6 +43,13 @@ protected Taxonomy(Retrofit client, HashMap headers) { this.taxonomyService = client.create(TaxonomyService.class); } + /** + * Instantiates a new Taxonomy. + * + * @param client the client + * @param headers the headers + * @param taxonomyId the taxonomy id + */ protected Taxonomy(Retrofit client, HashMap headers, @NotNull String taxonomyId) { this.headers = new HashMap<>(); this.params = new HashMap<>(); @@ -122,15 +147,9 @@ public Taxonomy addParams(@NotNull HashMap params) { * * * - * @return the call - * - *

- * Example - *
-     *     {@code
+     * @return the call 

Example
     {@code
      *     Response response = taxonomy.find().execute();
-     *     }
-     * 
+ * }
*/ public Call find() { return this.taxonomyService.find(this.headers, this.params); @@ -153,14 +172,9 @@ public Call find() { * * * @param taxonomyId the taxonomy id - * @return the call - *

- * Example - *
-     *     {@code
+     * @return the call 

Example
     {@code
      *     Response response = taxonomy.fetch("taxonomyId").execute();
-     *     }
-     * 
+ * }
*/ public Call fetch(@NotNull String taxonomyId) { return this.taxonomyService.fetch(this.headers, taxonomyId, this.params); @@ -170,16 +184,10 @@ public Call fetch(@NotNull String taxonomyId) { * Create Taxonomy call. * * @param body the body - * @return the call - * - *

- * Example - *
-     *     {@code
+     * @return the call 

Example
     {@code
      *     JSONObject body = new JSONObject
      *     Response response = taxonomy.create(body).execute();
-     *     }
-     * 
+ * }
*/ public Call create(@NotNull JSONObject body) { return this.taxonomyService.create(this.headers, body); @@ -190,20 +198,14 @@ public Call create(@NotNull JSONObject body) { * * @param taxonomyId - The taxonomy for which we need to update the details * @param body the body - * @return the call - * - *

- * Example - *
-     *     {@code
+     * @return the call 

Example
     {@code
      *     JSONObject body = new JSONObject();
      *     JSONObject bodyContent = new JSONObject();
      *     bodyContent.put("name", "Taxonomy 1");
      *     bodyContent.put("description", "Description updated for Taxonomy 1);
      *     body.put("taxonomy", bodyContent);
      *     Response response = taxonomy.update("taxonomyId", body).execute();
-     *     }
-     * 
+ * }
*/ public Call update(@NotNull String taxonomyId, @NotNull JSONObject body) { return this.taxonomyService.update(this.headers, taxonomyId, body); @@ -213,14 +215,9 @@ public Call update(@NotNull String taxonomyId, @NotNull JSONObject * Delete Taxonomy call. * * @param taxonomyId - The taxonomy for which we need to update the details - * @return the call - *

- * Example - *
-     *     {@code
+     * @return the call 

Example
     {@code
      *     Response response = taxonomy.delete("taxonomyId").execute();
-     *     }
-     * 
+ * }
*/ public Call delete(@NotNull String taxonomyId) { return this.taxonomyService.delete(this.headers, taxonomyId); @@ -241,7 +238,7 @@ protected void clearParams() { *
      *     {@code
      *     Term terms = stack("authtoken").taxonomy("taxonomyId").term();
-     *     }
+     *     }*
      * 
* * @return instance of {@link Terms} diff --git a/src/main/java/com/contentstack/cms/stack/Terms.java b/src/main/java/com/contentstack/cms/stack/Terms.java index c91f2f2a..61e09a09 100644 --- a/src/main/java/com/contentstack/cms/stack/Terms.java +++ b/src/main/java/com/contentstack/cms/stack/Terms.java @@ -9,8 +9,6 @@ import java.util.HashMap; /** - * @author @ishaileshmishra - * @since 1.1.0 * provides an implementation *
    *
  • Create a Term
  • @@ -24,12 +22,31 @@ */ public class Terms implements BaseImplementation { + /** + * The Taxonomy service. + */ final TaxonomyService taxonomyService; + /** + * The Headers. + */ final HashMap headers; + /** + * The Taxonomy id. + */ final String taxonomyId; + /** + * The Params. + */ final HashMap params; + /** + * Instantiates a new Terms. + * + * @param service the service + * @param headers the headers + * @param taxonomyId the taxonomy id + */ public Terms(@NotNull TaxonomyService service, HashMap headers, String taxonomyId) { this.taxonomyService = service; this.headers = headers; @@ -98,17 +115,11 @@ public Terms addHeaders(@NotNull HashMap headers) { * Create Terms call. * * @param body The JSONObject request body - * @return instance of Call - * - *

    - * Example - *
    -     *     {@code
    +     * @return instance of Call 

    Example
         {@code
          *     Stack stack = new Contentstack.Builder().build().stack(headers);
          *     JSONObject body = new JSONObject();
          *     Term term = stack.taxonomy("taxonomyId").terms().create(body);
    -     *     }
    -     * 
    + * }
    */ public Call create(@NotNull JSONObject body) { return this.taxonomyService.createTerm(this.headers, taxonomyId, body); @@ -155,11 +166,11 @@ public Call create(@NotNull JSONObject body) { * {@code * Stack stack = new Contentstack.Builder().build().stack(headers); * Term term = stack.taxonomy("taxonomyId").terms().addParam("limit", 2).find(); - * } + * }* * * - * @see #addParam(String, Object) to add query parameters - * returns instance of Call + * @return the call + * @see #addParam(String, Object) #addParam(String, Object)to add query parameters returns instance of Call */ public Call find() { return this.taxonomyService.findTerm(this.headers, taxonomyId, this.params); @@ -173,7 +184,7 @@ public Call find() { * Stack stack = new Contentstack.Builder().build().stack(headers); * Term term = stack.taxonomy("taxonomyId").terms().find(); * } - * @see #addParam(String, Object) #addParam(String, Object)to add query parameters + * @see #addParam(String, Object) #addParam(String, Object)#addParam(String, Object)to add query parameters */ public Call fetch(@NotNull String termUid) { return this.taxonomyService.fetchTerm(this.headers, taxonomyId, termUid, this.params); @@ -183,30 +194,10 @@ public Call fetch(@NotNull String termUid) { * Get descendants of a single Term * * @param termUid The term for which we need the details - * @return The details of the term descendants - *

    - * URL/Query parameters - *

      - *
    • - * depth - Include the terms upto the depth specified if set to a number greater than 0, include all the terms if set to 0, default depth will be set to 1 - *
    • - * include_children_count - Include count of number of children under each term - *
    • - * include_referenced_entries_count - Include count of the entries where atleast 1 term of this taxonomy is referred - *
    • - * include_count - Include count of the documents/nodes that matched the query - *
    • - * skip - Skip the number of documents/nodes - *
    • - * limit - Limit the result to number of documents/nodes - *
    • - *
    - *

    Example

     {@code
    +     * @return The details of the term descendants 

    URL/Query parameters

    • depth - Include the terms upto the depth specified if set to a number greater than 0, include all the terms if set to 0, default depth will be set to 1
    • include_children_count - Include count of number of children under each term
    • include_referenced_entries_count - Include count of the entries where atleast 1 term of this taxonomy is referred
    • include_count - Include count of the documents/nodes that matched the query
    • skip - Skip the number of documents/nodes
    • limit - Limit the result to number of documents/nodes

    Example

     {@code
          *      Stack stack = new Contentstack.Builder().build().stack(headers);
          *      Term term = stack.taxonomy("taxonomyId").terms().descendants("termId").;
    -     *     }
    -     *     
    - *

    + * }

    */ public Call descendants(@NotNull String termUid) { return this.taxonomyService.descendantsTerm(this.headers, this.taxonomyId, termUid, this.params); @@ -216,25 +207,21 @@ public Call descendants(@NotNull String termUid) { * Get ancestors of a single Term * * @param termUid The term for which we need the details - * @return The details of the term ancestors - *

    Example

     {@code
    +     * @return The details of the term ancestors 

    Example

     {@code
          *      Stack stack = new Contentstack.Builder().build().stack(headers);
          *      Term term = stack.taxonomy("taxonomyId").terms().ancestors("termId");
    -     *     }
    -     *     
    + * }
    */ public Call ancestors(@NotNull String termUid) { return this.taxonomyService.ancestorsTerm(this.headers, this.taxonomyId, termUid, this.params); } /** + * Update call. + * * @param termUid - The term for which we need the details * @param body the JSONObject body for the request - * @return instance of Call - *

    - * Example - *

    -     * {@code
    +     * @return instance of Call 

    Example

     {@code
          *   body = new RequestBody{
          *   "term": {
          *     "name": "Term 1",
    @@ -244,8 +231,7 @@ public Call ancestors(@NotNull String termUid) {
          *
          * Stack stack = new Contentstack.Builder().build().stack(headers);
          * Term term = stack.taxonomy("taxonomyId").terms().update(body);
    -     * }
    -     * 
    + * }
    */ public Call update(@NotNull String termUid, @NotNull JSONObject body) { return this.taxonomyService.updateTerm(this.headers, this.taxonomyId, termUid, body); @@ -253,17 +239,13 @@ public Call update(@NotNull String termUid, @NotNull JSONObject bo /** - * @param termString: The string for which we need to search for the matching terms, should either match with term uid or term name - * @return instance of Call - *

    + * Search call. * - * Example - *

    -     * {@code
    +     * @param termString : The string for which we need to search for the matching terms, should either match with term uid or term name
    +     * @return instance of Call 

    Example

     {@code
          * Stack stack = new Contentstack.Builder().build().stack(headers);
          * Term term = stack.taxonomy("taxonomyId").terms().search("search anything");
    -     * }
    -     * 
    + * }
    * @throws IllegalArgumentException if the termString is empty */ public Call search(@NotNull String termString) { @@ -274,6 +256,9 @@ public Call search(@NotNull String termString) { } + /** + * Clear params. + */ protected void clearParams() { this.params.clear(); } diff --git a/src/main/java/com/contentstack/cms/stack/Webhook.java b/src/main/java/com/contentstack/cms/stack/Webhook.java index d209d17a..491fcba3 100644 --- a/src/main/java/com/contentstack/cms/stack/Webhook.java +++ b/src/main/java/com/contentstack/cms/stack/Webhook.java @@ -160,7 +160,7 @@ public Call find() { * a * Single Delivery Token * - * @see #addHeader(String, Object) to add headers + * @see #addHeader(String, String) to add headers * @since 0.1.0 */ public Call fetch() { From 5ce5b35427c8e1d643b37a00240199cb84d63c2c Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Tue, 10 Oct 2023 14:59:13 +0530 Subject: [PATCH 5/7] Taxonomy and Terms keep Alive Duration Snyk issue --- .github/workflows/sast-scan.yml | 11 ----------- .github/workflows/sca-scan.yml | 15 --------------- 2 files changed, 26 deletions(-) delete mode 100644 .github/workflows/sast-scan.yml delete mode 100644 .github/workflows/sca-scan.yml diff --git a/.github/workflows/sast-scan.yml b/.github/workflows/sast-scan.yml deleted file mode 100644 index f9316303..00000000 --- a/.github/workflows/sast-scan.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: SAST Scan -on: - pull_request: - types: [opened, synchronize, reopened] -jobs: - security: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Horusec Scan - run: docker run -v /var/run/docker.sock:/var/run/docker.sock -v $(pwd):/src horuszup/horusec-cli:latest horusec start -p /src -P $(pwd) \ No newline at end of file diff --git a/.github/workflows/sca-scan.yml b/.github/workflows/sca-scan.yml deleted file mode 100644 index 2de23956..00000000 --- a/.github/workflows/sca-scan.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Source Composition Analysis Scan -on: - pull_request: - types: [opened, synchronize, reopened] -jobs: - security: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: Run Snyk to check for vulnerabilities - uses: snyk/actions/maven@master - env: - SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} - with: - args: --fail-on=all From 99b958a798c24d17fefab63773d681f6cc60a858 Mon Sep 17 00:00:00 2001 From: Aravind Kumar Date: Fri, 13 Oct 2023 16:00:45 +0530 Subject: [PATCH 6/7] Create sca-scan.yml --- .github/workflows/sca-scan.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/workflows/sca-scan.yml diff --git a/.github/workflows/sca-scan.yml b/.github/workflows/sca-scan.yml new file mode 100644 index 00000000..2de23956 --- /dev/null +++ b/.github/workflows/sca-scan.yml @@ -0,0 +1,15 @@ +name: Source Composition Analysis Scan +on: + pull_request: + types: [opened, synchronize, reopened] +jobs: + security: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Run Snyk to check for vulnerabilities + uses: snyk/actions/maven@master + env: + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + with: + args: --fail-on=all From 1b63a003da20acbbf67416d7882e6f103b30cabe Mon Sep 17 00:00:00 2001 From: Shailesh Mishra Date: Fri, 27 Oct 2023 11:19:00 +0530 Subject: [PATCH 7/7] removed dev host --- .env | 2 +- pom.xml | 12 ++--- .../contentstack/cms/BaseImplementation.java | 6 +-- .../com/contentstack/cms/Contentstack.java | 54 ++++++++++--------- .../com/contentstack/cms/package-info.java | 3 +- .../java/com/contentstack/cms/TestClient.java | 14 ++--- .../contentstack/cms/stack/TaxonomyTest.java | 33 +++++++----- 7 files changed, 71 insertions(+), 53 deletions(-) diff --git a/.env b/.env index 236d6798..02fbc6ea 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -dev-host=dev18-app.csnonprod.com \ No newline at end of file +dev-host=api.contentstack.io // use developer host here \ No newline at end of file diff --git a/pom.xml b/pom.xml index 9e97275f..5d0f1bfd 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ cms jar contentstack-management-java - 1.1.0-SNAPSHOT + 1.1.0 Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an API-first approach @@ -67,11 +67,11 @@ Apache Maven Packages Snapshot https://oss.sonatype.org/content/repositories/snapshots - + + + + + ossrh Apache Maven Packages Release diff --git a/src/main/java/com/contentstack/cms/BaseImplementation.java b/src/main/java/com/contentstack/cms/BaseImplementation.java index 513b7ff8..fd9c42d5 100644 --- a/src/main/java/com/contentstack/cms/BaseImplementation.java +++ b/src/main/java/com/contentstack/cms/BaseImplementation.java @@ -20,7 +20,7 @@ public interface BaseImplementation { * object as its value. * @return The method is returning an object of type T. */ - T addParam(@NotNull String key, @NotNull Object value); + T addParam(@NotNull String key, @NotNull Object value); /** * The function adds a header with a key-value pair to a request. @@ -45,7 +45,7 @@ public interface BaseImplementation { * annotated with @NotNull, indicating that it cannot be null. * @return The method is returning an object of type T. */ - T addParams(@NotNull HashMap params); + T addParams(@NotNull HashMap params); /** * The function adds headers to a HashMap. @@ -56,5 +56,5 @@ public interface BaseImplementation { * representing the header value. * @return The method is returning an object of type T. */ - T addHeaders(@NotNull HashMap headers); + T addHeaders(@NotNull HashMap headers); } diff --git a/src/main/java/com/contentstack/cms/Contentstack.java b/src/main/java/com/contentstack/cms/Contentstack.java index 5e684a54..0d9d4ba8 100644 --- a/src/main/java/com/contentstack/cms/Contentstack.java +++ b/src/main/java/com/contentstack/cms/Contentstack.java @@ -80,8 +80,8 @@ public class Contentstack { * @return User * @author ishaileshmishra * @see User - * + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User + * * @since 2022-05-19 */ public User user() { @@ -130,8 +130,8 @@ public User user() { * @throws IOException the IOException * @author ishaileshmishra * @see User - * + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User + * */ public Response login(String emailId, String password) throws IOException { if (this.authtoken != null) @@ -183,10 +183,10 @@ public Response login(String emailId, String password) throws IOEx * @throws IOException the IOException * @author ishaileshmishra * @see Login - * your account - * + * href= + * "https://www.contentstack.com/docs/developers/apis/content-management-api/#log-in-to-your-account">Login + * your account + * */ public Response login(String emailId, String password, String tfaToken) throws IOException { if (this.authtoken != null) @@ -201,7 +201,7 @@ public Response login(String emailId, String password, String tfaT private void setupLoginCredentials(Response loginResponse) throws IOException { if (loginResponse.isSuccessful()) { assert loginResponse.body() != null; - //logger.info(loginResponse.body().getNotice()); + // logger.info(loginResponse.body().getNotice()); this.authtoken = loginResponse.body().getUser().getAuthtoken(); this.interceptor.setAuthtoken(this.authtoken); } else { @@ -287,10 +287,10 @@ public Organization organization() { * * @param organizationUid The UID of the organization that you want to retrieve * @return the organization - *
    - * Example + *
    + * Example * - *
    +     *         
          *         Contentstack contentstack = new Contentstack.Builder().build();
          *         Organization org = contentstack.organization();
          *         
    @@ -398,13 +398,12 @@ public Stack stack(@NotNull String key) { // When API_Key is available headers.put(API_KEY, key); } else { - //When branch is available + // When branch is available headers.put(BRANCH, key); } return new Stack(this.instance, headers); } - /** * stack @@ -489,11 +488,14 @@ public Builder() { *
    *

    * {@code - *

    + * +

    * Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433)); * Contentstack contentstack = new Contentstack.Builder().setProxy(proxy).build(); - *

    + * +

    * } + * * @param proxy the proxy * @return the Builder instance */ @@ -557,11 +559,13 @@ public Builder setTimeout(int timeout) { return this; } - /** - * Create a new connection pool with tuning parameters appropriate for a single-user application. - * The tuning parameters in this pool are subject to change in future OkHttp releases. Currently, - * this pool holds up to 5 idle connections which will be evicted after 5 minutes of inactivity. + * Create a new connection pool with tuning parameters appropriate for a + * single-user application. + * The tuning parameters in this pool are subject to change in future OkHttp + * releases. Currently, + * this pool holds up to 5 idle connections which will be evicted after 5 + * minutes of inactivity. *

    *

    * public ConnectionPool() { @@ -570,11 +574,13 @@ public Builder setTimeout(int timeout) { * * @param maxIdleConnections Maximum number of idle connections * @param keepAliveDuration The Keep Alive Duration - * @param timeUnit A TimeUnit represents time durations at a given unit of granularity and provides utility methods to convert across units + * @param timeUnit A TimeUnit represents time durations at a given + * unit of granularity and provides utility methods to + * convert across units * @return instance of Builder - *

    - * Example: - * {@code + *

    + * Example: + * {@code * Contentstack cs = new Contentstack.Builder() * .setAuthtoken(AUTHTOKEN) * .setConnectionPool(5, 400, TimeUnit.MILLISECONDS) diff --git a/src/main/java/com/contentstack/cms/package-info.java b/src/main/java/com/contentstack/cms/package-info.java index 6998a405..24fb2de1 100644 --- a/src/main/java/com/contentstack/cms/package-info.java +++ b/src/main/java/com/contentstack/cms/package-info.java @@ -1,5 +1,6 @@ /** - * This is topmost package that is used to contains all the sub-packages in itself + * This is topmost package that is used to contains all the sub-packages in + * itself * like core, models, organisations, stacks, users and contentstack */ package com.contentstack.cms; diff --git a/src/test/java/com/contentstack/cms/TestClient.java b/src/test/java/com/contentstack/cms/TestClient.java index 4b95fea6..c30f7e99 100644 --- a/src/test/java/com/contentstack/cms/TestClient.java +++ b/src/test/java/com/contentstack/cms/TestClient.java @@ -11,14 +11,18 @@ public class TestClient { final static Dotenv env = Dotenv.load(); - public final static String ORGANIZATION_UID = (env.get("organizationUid") != null) ? env.get("organizationUid") : "orgId999999999"; + public final static String ORGANIZATION_UID = (env.get("organizationUid") != null) ? env.get("organizationUid") + : "orgId999999999"; public final static String AUTHTOKEN = (env.get("authToken") != null) ? env.get("authToken") : "auth999999999"; public final static String USER_ID = (env.get("userId") != null) ? env.get("userId") : "c11e668e0295477f"; - public final static String OWNERSHIP = (env.get("ownershipToken") != null) ? env.get("ownershipToken") : "ownershipTokenId"; + public final static String OWNERSHIP = (env.get("ownershipToken") != null) ? env.get("ownershipToken") + : "ownershipTokenId"; public final static String API_KEY = (env.get("apiKey") != null) ? env.get("apiKey") : "apiKey99999999"; - public final static String MANAGEMENT_TOKEN = (env.get("managementToken") != null) ? env.get("managementToken") : "managementToken99999999"; + public final static String MANAGEMENT_TOKEN = (env.get("managementToken") != null) ? env.get("managementToken") + : "managementToken99999999"; - public final static String DEV_HOST = (env.get("dev_host") != null) ? env.get("dev_host") : "dev18-app.csnonprod.com"; + public final static String DEV_HOST = "api.contentstack.io"; + // (env.get("dev_host") != null) ? env.get("dev_host") : "api.contentstack.io"; private static Contentstack instance; private static Stack stackInstance; @@ -37,7 +41,6 @@ public static Contentstack getClient() { return instance; } - public static Contentstack getCustomClient() { if (instance == null) { synchronized (Contentstack.class) { @@ -71,4 +74,3 @@ public static Stack getStack() { } } - diff --git a/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java b/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java index d6abfb74..a3a77a28 100644 --- a/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java +++ b/src/test/java/com/contentstack/cms/stack/TaxonomyTest.java @@ -118,7 +118,9 @@ void fetchTest() { Assertions.assertEquals("taxonomies", request.url().pathSegments().get(1)); Assertions.assertEquals("v3", request.url().pathSegments().get(0)); Assertions.assertNotNull(request.url().encodedQuery()); - Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/taxonomyId?limit=2&skip=2&include_count=false", request.url().toString()); + Assertions.assertEquals( + "https://api.contentstack.io/v3/taxonomies/taxonomyId?limit=2&skip=2&include_count=false", + request.url().toString()); } @Test @@ -149,7 +151,6 @@ void deleteTest() { Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/taxonomyId", request.url().toString()); } - @Test void deleteTestWithHeaders() { taxonomy.clearParams(); @@ -174,7 +175,6 @@ void deleteTestWithHeaders() { Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/taxonomyId", request.url().toString()); } - @Test void createTest() { JSONObject obj = new JSONObject(); @@ -212,7 +212,8 @@ void testCreateTerm() { Assertions.assertEquals("terms", request.url().pathSegments().get(3)); Assertions.assertNotNull(request.body()); Assertions.assertNull(request.url().encodedQuery()); - Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms", request.url().toString()); + Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms", + request.url().toString()); } @Test @@ -231,7 +232,8 @@ void testFindTerm() { Assertions.assertEquals("terms", request.url().pathSegments().get(3)); Assertions.assertNull(request.body()); Assertions.assertEquals("limit=3", request.url().encodedQuery()); - Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/" + _uid + "/terms?limit=3", request.url().toString()); + Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/" + _uid + "/terms?limit=3", + request.url().toString()); } @Test @@ -250,11 +252,13 @@ void testFetchTerm() { Assertions.assertEquals(_uid, request.url().pathSegments().get(2)); Assertions.assertEquals("terms", request.url().pathSegments().get(3)); Assertions.assertNull(request.body()); - Assertions.assertEquals("include_children_count=false&include_referenced_entries_count=true", request.url().encodedQuery()); - Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms/auth999999999?include_children_count=false&include_referenced_entries_count=true", request.url().toString()); + Assertions.assertEquals("include_children_count=false&include_referenced_entries_count=true", + request.url().encodedQuery()); + Assertions.assertEquals( + "https://api.contentstack.io/v3/taxonomies/auth999999999/terms/auth999999999?include_children_count=false&include_referenced_entries_count=true", + request.url().toString()); } - @Test void testTermUpdate() { terms.clearParams(); @@ -302,7 +306,9 @@ void testDescendantsTerm() { Assertions.assertEquals("terms", request.url().pathSegments().get(3)); Assertions.assertNull(request.body()); Assertions.assertEquals("include_count=true", request.url().encodedQuery()); - Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms/termId45/descendants?include_count=true", request.url().toString()); + Assertions.assertEquals( + "https://api.contentstack.io/v3/taxonomies/auth999999999/terms/termId45/descendants?include_count=true", + request.url().toString()); } @Test @@ -321,15 +327,18 @@ void testAncestorsTerm() { Assertions.assertEquals(_uid, request.url().pathSegments().get(2)); Assertions.assertEquals("terms", request.url().pathSegments().get(3)); Assertions.assertNull(request.body()); - Assertions.assertEquals("include_children_count=false&include_referenced_entries_count=true", request.url().encodedQuery()); - Assertions.assertEquals("https://api.contentstack.io/v3/taxonomies/auth999999999/terms/termId45/ancestors?include_children_count=false&include_referenced_entries_count=true", request.url().toString()); + Assertions.assertEquals("include_children_count=false&include_referenced_entries_count=true", + request.url().encodedQuery()); + Assertions.assertEquals( + "https://api.contentstack.io/v3/taxonomies/auth999999999/terms/termId45/ancestors?include_children_count=false&include_referenced_entries_count=true", + request.url().toString()); } @Test void findTestAPI() throws IOException { Taxonomy taxonomy = new Contentstack.Builder() .setAuthtoken(TestClient.AUTHTOKEN) - .setHost("dev18-app.csnonprod.com") + .setHost("api.contentstack.io") .build() .stack("blt12c1ba95c1b11e88", "") .taxonomy();