diff --git a/.env b/.env index e69de29b..02fbc6ea 100644 --- a/.env +++ b/.env @@ -0,0 +1 @@ +dev-host=api.contentstack.io // use developer host here \ No newline at end of file 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/pom.xml b/pom.xml index 1a88368f..5d0f1bfd 100644 --- a/pom.xml +++ b/pom.xml @@ -7,13 +7,14 @@ 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 https://github.com/contentstack/contentstack-management-java/ - + + org.sonatype.oss oss-parent @@ -66,11 +67,11 @@ Apache Maven Packages Snapshot https://oss.sonatype.org/content/repositories/snapshots - + + + + + ossrh Apache Maven Packages Release @@ -87,15 +88,14 @@ 2.2.1 3.0.0 5.2.2 - 3.1.6 + 3.1.8 2.9.0 2.9.0 - 4.10.0 + 5.0.0-alpha.11 0.8.7 - 1.18.28 - 5.9.2 + 1.18.30 + 5.10.0 5.8.0-M1 - 5.9.2 2.10.1 3.3 1.5 @@ -162,7 +162,13 @@ org.junit.vintage junit-vintage-engine - ${junit-vintage-engine.version} + ${junit-jupiter.version} + test + + + org.mockito + mockito-core + 5.6.0 test @@ -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..fd9c42d5 100644 --- a/src/main/java/com/contentstack/cms/BaseImplementation.java +++ b/src/main/java/com/contentstack/cms/BaseImplementation.java @@ -5,14 +5,13 @@ import java.util.HashMap; /** - * The interface @{@link BaseImplementation} + * The interface 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/Contentstack.java b/src/main/java/com/contentstack/cms/Contentstack.java index 938257e0..0d9d4ba8 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.*; @@ -78,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() { @@ -128,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) @@ -181,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) @@ -199,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 { @@ -285,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();
      *         
@@ -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();
+         * 

+ * {@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 */ @@ -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. + *

+ *

+ * 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(); *

* - * @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..98df66b5 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() { @@ -116,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 */ @@ -145,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 */ @@ -178,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) { @@ -207,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) { @@ -232,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() { @@ -260,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) { @@ -280,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/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