Skip to content

Commit 06443c7

Browse files
Merge pull request #37 from contentstack/taxonomy
Taxonomy : Taxonomy, Team, Keep Alive Duration and Snyk Issues
2 parents 0472bc3 + fef8233 commit 06443c7

40 files changed

+2166
-627
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dev-host=***REMOVED***

.github/workflows/sast-scan.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/workflows/sca-scan.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.

pom.xml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
<artifactId>cms</artifactId>
88
<packaging>jar</packaging>
99
<name>contentstack-management-java</name>
10-
<version>1.0.0</version>
10+
<version>1.1.0-SNAPSHOT</version>
1111
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
1212
API-first approach
1313
</description>
1414
<url>https://github.com/contentstack/contentstack-management-java/</url>
1515

16-
<!-- Release the package using mvn clean deploy -->
16+
<!--mvn versions:display-dependency-updates-->
17+
<!--Release the package using mvn clean deploy -->
1718
<parent>
1819
<groupId>org.sonatype.oss</groupId>
1920
<artifactId>oss-parent</artifactId>
@@ -87,15 +88,14 @@
8788
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
8889
<maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
8990
<dotenv-source.version>5.2.2</dotenv-source.version>
90-
<rxjava-source.version>3.1.6</rxjava-source.version>
91+
<rxjava-source.version>3.1.8</rxjava-source.version>
9192
<retrofit-source.version>2.9.0</retrofit-source.version>
9293
<converter-gson-version>2.9.0</converter-gson-version>
93-
<logging.version>4.10.0</logging.version>
94+
<logging.version>5.0.0-alpha.11</logging.version>
9495
<jococo-plugin.version>0.8.7</jococo-plugin.version>
95-
<lombok-source.version>1.18.28</lombok-source.version>
96-
<junit-jupiter.version>5.9.2</junit-jupiter.version>
96+
<lombok-source.version>1.18.30</lombok-source.version>
97+
<junit-jupiter.version>5.10.0</junit-jupiter.version>
9798
<junit-jupiter-engine.version>5.8.0-M1</junit-jupiter-engine.version>
98-
<junit-vintage-engine.version>5.9.2</junit-vintage-engine.version>
9999
<gson.version>2.10.1</gson.version>
100100
<maven-site-plugin.version>3.3</maven-site-plugin.version>
101101
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
@@ -162,7 +162,13 @@
162162
<dependency>
163163
<groupId>org.junit.vintage</groupId>
164164
<artifactId>junit-vintage-engine</artifactId>
165-
<version>${junit-vintage-engine.version}</version>
165+
<version>${junit-jupiter.version}</version>
166+
<scope>test</scope>
167+
</dependency>
168+
<dependency>
169+
<groupId>org.mockito</groupId>
170+
<artifactId>mockito-core</artifactId>
171+
<version>5.6.0</version>
166172
<scope>test</scope>
167173
</dependency>
168174
<dependency>
@@ -328,6 +334,7 @@
328334
<plugin>
329335
<groupId>org.apache.maven.plugins</groupId>
330336
<artifactId>maven-pdf-plugin</artifactId>
337+
<version>1.6.1</version>
331338
<executions>
332339
<execution>
333340
<id>pdf</id>

src/main/java/com/contentstack/cms/BaseImplementation.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
import java.util.HashMap;
66

77
/**
8-
* The interface @{@link BaseImplementation}
8+
* The interface BaseImplementation
99
*/
10-
public interface BaseImplementation {
10+
public interface BaseImplementation<T> {
1111

1212
/**
1313
* The function adds a parameter to a collection using a key-value pair.
1414
*
15-
* @param <T> the type of the parameter
1615
* @param key A string representing the key of the parameter. It cannot be
1716
* null and must be
1817
* provided as a non-null value.
@@ -21,12 +20,11 @@ public interface BaseImplementation {
2120
* object as its value.
2221
* @return The method is returning an object of type T.
2322
*/
24-
<T> T addParam(@NotNull String key, @NotNull Object value);
23+
T addParam(@NotNull String key, @NotNull Object value);
2524

2625
/**
2726
* The function adds a header with a key-value pair to a request.
2827
*
29-
* @param <T> the type of the parameter
3028
* @param key The key parameter is a string that represents the name or
3129
* identifier of the header.
3230
* It is used to specify the type of information being sent in the
@@ -35,30 +33,28 @@ public interface BaseImplementation {
3533
* header.
3634
* @return The method is returning an object of type T.
3735
*/
38-
<T> T addHeader(@NotNull String key, @NotNull String value);
36+
T addHeader(@NotNull String key, @NotNull String value);
3937

4038
/**
4139
* The function "addParams" takes a HashMap of String keys and Object values as
4240
* input and returns a
4341
* generic type T.
4442
*
45-
* @param <T> the type of the parameter
4643
* @param params The "params" parameter is a HashMap that maps String keys to
4744
* Object values. It is
4845
* annotated with @NotNull, indicating that it cannot be null.
4946
* @return The method is returning an object of type T.
5047
*/
51-
<T> T addParams(@NotNull HashMap<String, Object> params);
48+
T addParams(@NotNull HashMap<String, Object> params);
5249

5350
/**
5451
* The function adds headers to a HashMap.
5552
*
56-
* @param <T> the type of the parameter
5753
* @param headers A HashMap containing key-value pairs of headers, where the key
5854
* is a String
5955
* representing the header name and the value is a String
6056
* representing the header value.
6157
* @return The method is returning an object of type T.
6258
*/
63-
<T> T addHeaders(@NotNull HashMap<String, String> headers);
59+
T addHeaders(@NotNull HashMap<String, String> headers);
6460
}

src/main/java/com/contentstack/cms/Contentstack.java

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.contentstack.cms.stack.Stack;
99
import com.contentstack.cms.user.User;
1010
import com.google.gson.Gson;
11+
import okhttp3.ConnectionPool;
1112
import okhttp3.OkHttpClient;
1213
import okhttp3.ResponseBody;
1314
import okhttp3.logging.HttpLoggingInterceptor;
@@ -22,6 +23,7 @@
2223
import java.util.HashMap;
2324
import java.util.Map;
2425
import java.util.Objects;
26+
import java.util.concurrent.TimeUnit;
2527
import java.util.logging.Logger;
2628

2729
import static com.contentstack.cms.core.Util.*;
@@ -467,6 +469,12 @@ public static class Builder {
467469
private int timeout = Util.TIMEOUT; // Default timeout 30 seconds
468470
private Boolean retry = Util.RETRY_ON_FAILURE;// Default base url for contentstack
469471

472+
/**
473+
* Default ConnectionPool holds up to 5 idle connections which
474+
* will be evicted after 5 minutes of inactivity.
475+
*/
476+
private ConnectionPool connectionPool = new ConnectionPool(); // Connection
477+
470478
/**
471479
* Instantiates a new Builder.
472480
*/
@@ -479,14 +487,13 @@ public Builder() {
479487
* Proxy(Proxy.Type.HTTP, new
480488
* InetSocketAddress(proxyHost, proxyPort));
481489
* <br>
482-
*
483-
* <pre>
484-
* {
485-
* Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433));
486-
* Contentstack contentstack = new Contentstack.Builder().setProxy(proxy).build();
490+
* <p>
491+
* {@code
492+
* <p>
493+
* Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433));
494+
* Contentstack contentstack = new Contentstack.Builder().setProxy(proxy).build();
495+
* <p>
487496
* }
488-
* </pre>
489-
*
490497
* @param proxy the proxy
491498
* @return the Builder instance
492499
*/
@@ -550,6 +557,36 @@ public Builder setTimeout(int timeout) {
550557
return this;
551558
}
552559

560+
561+
/**
562+
* Create a new connection pool with tuning parameters appropriate for a single-user application.
563+
* The tuning parameters in this pool are subject to change in future OkHttp releases. Currently,
564+
* this pool holds up to 5 idle connections which will be evicted after 5 minutes of inactivity.
565+
* <p>
566+
* <p>
567+
* public ConnectionPool() {
568+
* this(5, 5, TimeUnit.MINUTES);
569+
* }
570+
*
571+
* @param maxIdleConnections Maximum number of idle connections
572+
* @param keepAliveDuration The Keep Alive Duration
573+
* @param timeUnit A TimeUnit represents time durations at a given unit of granularity and provides utility methods to convert across units
574+
* @return instance of Builder
575+
* <p>
576+
* Example:
577+
* {@code
578+
* Contentstack cs = new Contentstack.Builder()
579+
* .setAuthtoken(AUTHTOKEN)
580+
* .setConnectionPool(5, 400, TimeUnit.MILLISECONDS)
581+
* .setHost("host")
582+
* .build();
583+
* Connection}
584+
*/
585+
public Builder setConnectionPool(int maxIdleConnections, int keepAliveDuration, TimeUnit timeUnit) {
586+
this.connectionPool = new ConnectionPool(maxIdleConnections, keepAliveDuration, timeUnit);
587+
return this;
588+
}
589+
553590
/**
554591
* Sets authtoken for the client
555592
*
@@ -582,7 +619,9 @@ private void validateClient(Contentstack contentstack) {
582619

583620
private OkHttpClient httpClient(Contentstack contentstack, Boolean retryOnFailure) {
584621
this.authInterceptor = contentstack.interceptor = new AuthInterceptor();
585-
return new OkHttpClient.Builder().addInterceptor(this.authInterceptor)
622+
return new OkHttpClient.Builder()
623+
.connectionPool(this.connectionPool)
624+
.addInterceptor(this.authInterceptor)
586625
.addInterceptor(logger())
587626
.proxy(this.proxy)
588627
.connectTimeout(Duration.ofSeconds(this.timeout))

src/main/java/com/contentstack/cms/core/CMARuntimeException.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
* @since 2022-10-20
99
*/
1010
public class CMARuntimeException extends Exception {
11-
// The code `public CMARuntimeException(String message) { super(message); }` is
12-
// defining a constructor
13-
// for the `CMARuntimeException` class.
11+
12+
/**
13+
* The code `public CMARuntimeException(String message) { super(message); }` is
14+
* defining a constructor
15+
* for the `CMARuntimeException` class.
16+
*
17+
* @param message the message for exception
18+
*/
1419
public CMARuntimeException(String message) {
1520
super(message);
1621
}

src/main/java/com/contentstack/cms/organization/Organization.java

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.contentstack.cms.organization;
22

3+
import com.contentstack.cms.BaseImplementation;
34
import okhttp3.ResponseBody;
45
import org.jetbrains.annotations.NotNull;
56
import org.json.simple.JSONObject;
@@ -19,7 +20,7 @@
1920
* @version v0.1.0
2021
* @since 2022-10-20
2122
*/
22-
public class Organization {
23+
public class Organization implements BaseImplementation<Organization> {
2324

2425
private final OrganizationService service;
2526
protected HashMap<String, String> headers;
@@ -65,6 +66,18 @@ public Organization addHeader(@NotNull String key, @NotNull String value) {
6566
return this;
6667
}
6768

69+
@Override
70+
public Organization addParams(@NotNull HashMap<String, Object> params) {
71+
this.params.putAll(params);
72+
return this;
73+
}
74+
75+
@Override
76+
public Organization addHeaders(@NotNull HashMap<String, String> headers) {
77+
this.headers.putAll(headers);
78+
return this;
79+
}
80+
6881
/**
6982
* Sets header for the request
7083
*
@@ -89,17 +102,6 @@ protected Organization clearParams() {
89102
return this;
90103
}
91104

92-
/**
93-
* Sets header for the request
94-
*
95-
* @param key header key for the request
96-
* @return instance of {@link Organization}
97-
*/
98-
public Organization removeParam(@NotNull String key) {
99-
this.params.remove(key);
100-
return this;
101-
}
102-
103105
/**
104106
* <b>Gets all organizations.</b><br>
105107
* The <b>Get all organizations</b> call lists all organizations related to the

0 commit comments

Comments
 (0)