+ ** - * @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* Contentstack contentstack = new Contentstack.Builder().build(); * Organization org = contentstack.organization(); *@@ -396,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 @@ -467,6 +468,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,14 +486,16 @@ 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(); + *- * + * * @param proxy the proxy * @return the Builder instance */ @@ -550,6 +559,40 @@ 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. + *+ * {@code + * +
+ * Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433)); + * Contentstack contentstack = new Contentstack.Builder().setProxy(proxy).build(); + * +
* } - *
+ *
+ * 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 +625,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/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/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/main/java/com/contentstack/cms/stack/Alias.java b/src/main/java/com/contentstack/cms/stack/Alias.java index feafe653..1da9ca72 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; @@ -17,13 +18,10 @@ * * @author ishaileshmishra * @version v0.1.0 - * @see About - * Aliases - * - * @since 2022-10-20 + * @see About Aliases + * @since 2022 -10-20 */ -public class Alias { +public class Alias implements BaseImplementation{ protected final Map headers; protected Map params; @@ -57,21 +55,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 +80,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. @@ -102,14 +134,13 @@ 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 * @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 +153,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 +173,13 @@ 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) { @@ -167,16 +196,15 @@ public Call update(@NotNull JSONObject body) { * of your alias. * * @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(); *