Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dev-host=api.contentstack.io // use developer host here
11 changes: 0 additions & 11 deletions .github/workflows/sast-scan.yml

This file was deleted.

33 changes: 20 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
<artifactId>cms</artifactId>
<packaging>jar</packaging>
<name>contentstack-management-java</name>
<version>1.0.0</version>
<version>1.1.0</version>
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
API-first approach
</description>
<url>https://github.com/contentstack/contentstack-management-java/</url>

<!-- Release the package using mvn clean deploy -->
<!--mvn versions:display-dependency-updates-->
<!--Release the package using mvn clean deploy -->
<parent>
<groupId>org.sonatype.oss</groupId>
<artifactId>oss-parent</artifactId>
Expand Down Expand Up @@ -66,11 +67,11 @@
<name>Apache Maven Packages Snapshot</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<!-- <snapshotRepository>
<id>github</id>
<name>GitHub Apache Maven Packages</name>
<url>https://maven.pkg.github.com/contentstack/contentstack-management-java</url>
</snapshotRepository> -->
<!-- <snapshotRepository>-->
<!-- <id>github</id>-->
<!-- <name>GitHub Apache Maven Packages</name>-->
<!-- <url>https://maven.pkg.github.com/contentstack/contentstack-management-java</url>-->
<!-- </snapshotRepository> -->
<repository>
<id>ossrh</id>
<name>Apache Maven Packages Release</name>
Expand All @@ -87,15 +88,14 @@
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
<maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
<dotenv-source.version>5.2.2</dotenv-source.version>
<rxjava-source.version>3.1.6</rxjava-source.version>
<rxjava-source.version>3.1.8</rxjava-source.version>
<retrofit-source.version>2.9.0</retrofit-source.version>
<converter-gson-version>2.9.0</converter-gson-version>
<logging.version>4.10.0</logging.version>
<logging.version>5.0.0-alpha.11</logging.version>
<jococo-plugin.version>0.8.7</jococo-plugin.version>
<lombok-source.version>1.18.28</lombok-source.version>
<junit-jupiter.version>5.9.2</junit-jupiter.version>
<lombok-source.version>1.18.30</lombok-source.version>
<junit-jupiter.version>5.10.0</junit-jupiter.version>
<junit-jupiter-engine.version>5.8.0-M1</junit-jupiter-engine.version>
<junit-vintage-engine.version>5.9.2</junit-vintage-engine.version>
<gson.version>2.10.1</gson.version>
<maven-site-plugin.version>3.3</maven-site-plugin.version>
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
Expand Down Expand Up @@ -162,7 +162,13 @@
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-vintage-engine.version}</version>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -328,6 +334,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pdf-plugin</artifactId>
<version>1.6.1</version>
<executions>
<execution>
<id>pdf</id>
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/com/contentstack/cms/BaseImplementation.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
import java.util.HashMap;

/**
* The interface @{@link BaseImplementation}
* The interface BaseImplementation
*/
public interface BaseImplementation {
public interface BaseImplementation<T> {

/**
* The function adds a parameter to a collection using a key-value pair.
*
* @param <T> 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.
Expand All @@ -21,12 +20,11 @@ public interface BaseImplementation {
* object as its value.
* @return The method is returning an object of type T.
*/
<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 <T> 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
Expand All @@ -35,30 +33,28 @@ public interface BaseImplementation {
* header.
* @return The method is returning an object of type T.
*/
<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 <T> 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> T addParams(@NotNull HashMap<String, Object> params);
T addParams(@NotNull HashMap<String, Object> params);

/**
* The function adds headers to a HashMap.
*
* @param <T> 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> T addHeaders(@NotNull HashMap<String, String> headers);
T addHeaders(@NotNull HashMap<String, String> headers);
}
89 changes: 67 additions & 22 deletions src/main/java/com/contentstack/cms/Contentstack.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.*;
Expand Down Expand Up @@ -78,8 +80,8 @@ public class Contentstack {
* @return User
* @author ishaileshmishra
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
* @since 2022-05-19
*/
public User user() {
Expand Down Expand Up @@ -128,8 +130,8 @@ public User user() {
* @throws IOException the IOException
* @author ishaileshmishra
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
*/
public Response<LoginDetails> login(String emailId, String password) throws IOException {
if (this.authtoken != null)
Expand Down Expand Up @@ -181,10 +183,10 @@ public Response<LoginDetails> login(String emailId, String password) throws IOEx
* @throws IOException the IOException
* @author ishaileshmishra
* @see <a
* href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#log-in-to-your-account">Login
* your account
* </a>
* href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#log-in-to-your-account">Login
* your account
* </a>
*/
public Response<LoginDetails> login(String emailId, String password, String tfaToken) throws IOException {
if (this.authtoken != null)
Expand All @@ -199,7 +201,7 @@ public Response<LoginDetails> login(String emailId, String password, String tfaT
private void setupLoginCredentials(Response<LoginDetails> 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 {
Expand Down Expand Up @@ -285,10 +287,10 @@ public Organization organization() {
*
* @param organizationUid The UID of the organization that you want to retrieve
* @return the organization
* <br>
* <b>Example</b>
* <br>
* <b>Example</b>
*
* <pre>
* <pre>
* Contentstack contentstack = new Contentstack.Builder().build();
* Organization org = contentstack.organization();
* </pre>
Expand Down Expand Up @@ -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);
}


/**
* <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#stacks">stack</a>
Expand Down Expand Up @@ -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.
*/
Expand All @@ -479,14 +486,16 @@ public Builder() {
* Proxy(Proxy.Type.HTTP, new
* InetSocketAddress(proxyHost, proxyPort));
* <br>
*
* <pre>
* {
* Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433));
* Contentstack contentstack = new Contentstack.Builder().setProxy(proxy).build();
* <p>
* {@code
*
<p>
* Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433));
* Contentstack contentstack = new Contentstack.Builder().setProxy(proxy).build();
*
<p>
* }
* </pre>
*
*
* @param proxy the proxy
* @return the Builder instance
*/
Expand Down Expand Up @@ -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.
* <p>
* <p>
* 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
* <p>
* 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
*
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading