Skip to content

Commit f615e81

Browse files
v1.12.3 Early Access Feature Support
1 parent 09751e8 commit f615e81

File tree

7 files changed

+110
-78
lines changed

7 files changed

+110
-78
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# CHANGELOG
22

3+
## v1.13.0
4+
5+
### Date: 17-Nov-2023
6+
7+
- Updated Latest version of Utils SDK to 1.2.6
8+
- Snyk Issues fixed
9+
- Updated dependencies
10+
- Added support for early access feature
11+
312
## v1.12.3
413

514
### Date: 28-SEP-2023

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.contentstack.sdk</groupId>
77
<artifactId>java</artifactId>
8-
<version>1.12.3</version>
8+
<version>1.13.0</version>
99
<packaging>jar</packaging>
1010
<name>contentstack-java</name>
1111
<description>Java SDK for Contentstack Content Delivery API</description>
@@ -25,18 +25,18 @@
2525
<loggin.version>5.0.0-alpha.11</loggin.version>
2626
<jococo-plugin.version>0.8.5</jococo-plugin.version>
2727
<lombok-source.version>1.18.30</lombok-source.version>
28-
<junit-jupiter.version>5.10.0</junit-jupiter.version>
28+
<junit-jupiter.version>5.10.1</junit-jupiter.version>
2929
<junit-jupiter-engine.version>5.8.0-M1</junit-jupiter-engine.version>
3030
<gson.version>2.8.8</gson.version>
3131
<json-simple-version>1.1.1</json-simple-version>
3232
<maven-site-plugin.version>3.3</maven-site-plugin.version>
3333
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
3434
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
3535
<nexus-staging-maven-plugin.version>1.6.13</nexus-staging-maven-plugin.version>
36-
<json-version>20230618</json-version>
36+
<json-version>20231013</json-version>
3737
<jacoco-maven-plugin-version>0.8.7</jacoco-maven-plugin-version>
3838
<maven-release-plugin-version>2.5.3</maven-release-plugin-version>
39-
<contentstack-utils-version>1.2.4</contentstack-utils-version>
39+
<contentstack-utils-version>1.2.6</contentstack-utils-version>
4040
</properties>
4141

4242
<parent>

src/main/java/com/contentstack/sdk/Config.java

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.contentstack.sdk;
22

3+
import lombok.Getter;
4+
import lombok.Setter;
35
import okhttp3.ConnectionPool;
46
import org.jetbrains.annotations.NotNull;
57
import org.json.JSONObject;
@@ -17,6 +19,7 @@ public class Config {
1719
protected String livePreviewHash = null;
1820
protected String livePreviewContentType = null;
1921
protected String livePreviewEntryUid = null;
22+
@Getter
2023
protected String host = "cdn.contentstack.io";
2124
protected String version = "v3";
2225
protected String scheme = "https://";
@@ -26,38 +29,36 @@ public class Config {
2629
protected JSONObject livePreviewEntry = null;
2730
protected ContentstackRegion region = ContentstackRegion.US;
2831
protected String managementToken;
32+
@Setter
33+
@Getter
2934
protected String branch;
35+
/**
36+
* -- SETTER --
37+
* Proxy can be set like below.
38+
*
39+
* @param proxy Proxy setting, typically a type (http, socks) and a socket address. A Proxy is an immutable object
40+
* <br>
41+
* <br>
42+
* <b>Example:</b><br>
43+
* <br>
44+
* <code>
45+
* java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyHost", "proxyPort"));
46+
* java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("sl.theproxyvpn.io", 80)); Config
47+
* config = new Config(); config.setProxy(proxy);
48+
* </code>
49+
*/
50+
@Setter
3051
protected Proxy proxy = null;
3152
protected ConnectionPool connectionPool = new ConnectionPool();
3253

3354
protected List<ContentstackPlugin> plugins = null;
3455

35-
public String getBranch() {
36-
return branch;
37-
}
38-
39-
public void setBranch(String branch) {
40-
this.branch = branch;
41-
}
42-
4356
/**
44-
* Proxy can be set like below.
45-
*
46-
* @param proxy
47-
* Proxy setting, typically a type (http, socks) and a socket address. A Proxy is an immutable object
48-
* <br>
49-
* <br>
50-
* <b>Example:</b><br>
51-
* <br>
52-
* <code>
53-
* java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyHost", "proxyPort"));
54-
* java.net.Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("sl.theproxyvpn.io", 80)); Config
55-
* config = new Config(); config.setProxy(proxy);
56-
* </code>
57+
* -- GETTER --
58+
* The configuration for the contentstack that contains support for
5759
*/
58-
public void setProxy(Proxy proxy) {
59-
this.proxy = proxy;
60-
}
60+
@Getter
61+
protected String[] earlyAccess;
6162

6263
/**
6364
* Returns the Proxy instance
@@ -73,12 +74,9 @@ public Proxy getProxy() {
7374
* {@link okhttp3.Address} may share a {@link okhttp3.Connection}. This class implements the policy * of which
7475
* connections to keep open for future use.
7576
*
76-
* @param maxIdleConnections
77-
* the maxIdleConnections default value is 5
78-
* @param keepAliveDuration
79-
* the keepAliveDuration default value is 5
80-
* @param timeUnit
81-
* the timeUnit default value is TimeUnit. MINUTES
77+
* @param maxIdleConnections the maxIdleConnections default value is 5
78+
* @param keepAliveDuration the keepAliveDuration default value is 5
79+
* @param timeUnit the timeUnit default value is TimeUnit. MINUTES
8280
* @return ConnectionPool
8381
*/
8482
public ConnectionPool connectionPool(int maxIdleConnections, long keepAliveDuration, TimeUnit timeUnit) {
@@ -98,8 +96,7 @@ public ContentstackRegion getRegion() {
9896
/**
9997
* Sets region.
10098
*
101-
* @param region
102-
* the region
99+
* @param region the region
103100
* @return the region
104101
*/
105102
public ContentstackRegion setRegion(ContentstackRegion region) {
@@ -119,20 +116,10 @@ public void setPlugins(List<ContentstackPlugin> plugins) {
119116
this.plugins = plugins;
120117
}
121118

122-
/**
123-
* Gets host.
124-
*
125-
* @return the host
126-
*/
127-
public String getHost() {
128-
return host;
129-
}
130-
131119
/**
132120
* Sets host.
133121
*
134-
* @param hostName
135-
* the host name
122+
* @param hostName the host name
136123
*/
137124
public void setHost(String hostName) {
138125
if (hostName != null && !hostName.isEmpty()) {
@@ -152,8 +139,7 @@ public String getVersion() {
152139
/**
153140
* Enable live preview config.
154141
*
155-
* @param enableLivePreview
156-
* to enable live preview
142+
* @param enableLivePreview to enable live preview
157143
* @return the config
158144
*/
159145
public Config enableLivePreview(boolean enableLivePreview) {
@@ -164,8 +150,7 @@ public Config enableLivePreview(boolean enableLivePreview) {
164150
/**
165151
* Sets live preview host.
166152
*
167-
* @param livePreviewHost
168-
* the live preview host
153+
* @param livePreviewHost the live preview host
169154
* @return the live preview host
170155
*/
171156
public Config setLivePreviewHost(@NotNull String livePreviewHost) {
@@ -181,8 +166,7 @@ protected Config setLivePreviewEntry(@NotNull JSONObject livePreviewEntry) {
181166
/**
182167
* Sets management token.
183168
*
184-
* @param managementToken
185-
* the management token
169+
* @param managementToken the management token
186170
* @return the management token
187171
*/
188172
public Config setManagementToken(@NotNull String managementToken) {
@@ -197,4 +181,23 @@ public enum ContentstackRegion {
197181
US, EU, AZURE_NA, AZURE_EU
198182
}
199183

184+
185+
/**
186+
* The configuration for the contentstack that contains support for Early Access Feature
187+
*
188+
* @param earlyAccessFeatures The list of Early Access Features
189+
* {@code
190+
* Config config = new Config();
191+
* String[] earlyAccess = {"Taxonomy", "Teams", "Terms", "LivePreview"};
192+
* config.earlyAccess(earlyAccess);
193+
* Stack stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENV, config);
194+
* <p>
195+
* }
196+
* @return Config
197+
*/
198+
public Config earlyAccess(@NotNull String[] earlyAccessFeatures) {
199+
this.earlyAccess = earlyAccessFeatures;
200+
return this;
201+
}
202+
200203
}

src/main/java/com/contentstack/sdk/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
public class Constants {
2222

2323
private static final Logger logger = Logger.getLogger(Constants.class.getSimpleName());
24-
protected static final String SDK_VERSION = "1.12.3";
24+
protected static final String SDK_VERSION = "1.13.0";
2525
protected static final String ENVIRONMENT = "environment";
2626
protected static final String CONTENT_TYPE_UID = "content_type_uid";
2727
protected static final String ENTRY_UID = "entry_uid";

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

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,23 @@ protected Contentstack() throws IllegalAccessException {
3131
* key of your stack. <br>
3232
* Find Your Stack Credentials from Contentstack .
3333
*
34-
* @param stackApiKey
35-
* The API Key is a unique key assigned to each stack.
36-
* @param deliveryToken
37-
* The Delivery Token is a read-only credential that you
34+
* @param stackApiKey The API Key is a unique key assigned to each stack.
35+
* @param deliveryToken The Delivery Token is a read-only credential that you
3836
* can create for different environments of your
3937
* stack
40-
* @param environment
41-
* the environment for the stack
38+
* @param environment the environment for the stack
4239
* @return the stack
43-
* @throws IllegalAccessException
44-
* the illegal access exception
40+
* @throws IllegalAccessException the illegal access exception
4541
* <p>
4642
* <b>Example</b>
4743
*
4844
* <pre>
49-
* {
50-
* &#64;Code
51-
* Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
52-
* }
45+
* {
46+
* &#64;Code
47+
* Stack stack = contentstack.Stack("apiKey", "deliveryToken", "environment");
48+
* }
5349
*
54-
* </pre>
50+
* </pre>
5551
*/
5652
public static Stack stack(String stackApiKey, String deliveryToken, String environment)
5753
throws IllegalAccessException {
@@ -66,19 +62,14 @@ public static Stack stack(String stackApiKey, String deliveryToken, String envir
6662
* create content structures, content entries, users, etc. related to the
6763
* project.
6864
*
69-
* @param stackApiKey
70-
* The API Key is a unique key assigned to each stack.
71-
* @param deliveryToken
72-
* The Delivery Token is a read-only credential that you
65+
* @param stackApiKey The API Key is a unique key assigned to each stack.
66+
* @param deliveryToken The Delivery Token is a read-only credential that you
7367
* can create for different environments of your
7468
* stack
75-
* @param environment
76-
* the environment for the stack
77-
* @param config
78-
* the config
69+
* @param environment the environment for the stack
70+
* @param config the config
7971
* @return the stack
80-
* @throws IllegalAccessException
81-
* the illegal access exception <b>Example</b>
72+
* @throws IllegalAccessException the illegal access exception <b>Example</b>
8273
* <p>
8374
* { @Code Stack stack =
8475
* contentstack.Stack("apiKey", "deliveryToken",
@@ -115,6 +106,10 @@ private static Stack initializeStack(String stackApiKey, String deliveryToken, S
115106
if (config.getBranch() != null && !config.getBranch().isEmpty()) {
116107
stack.setHeader("branch", config.getBranch());
117108
}
109+
if (config.getEarlyAccess() != null && config.getEarlyAccess().length > 0) {
110+
String eaValues = String.join(",", config.earlyAccess).replace("\"", "");
111+
stack.setHeader("x-header-ea", eaValues);
112+
}
118113
stack.setConfig(config);
119114
return stack;
120115
}

src/main/java/com/contentstack/sdk/Stack.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public void setHeader(@NotNull String headerKey, @NotNull String headerValue) {
276276
* @return the string
277277
*/
278278
public String imageTransform(@NotNull String imageUrl, @NotNull Map<String, Object> parameters) {
279-
if (parameters.size() == 0) {
279+
if (parameters.isEmpty()) {
280280
return imageUrl;
281281
}
282282
String query = getQueryParam(parameters);

src/test/java/com/contentstack/sdk/TestContentstack.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,29 @@ void initStackWithConfigs() throws IllegalAccessException {
105105
Assertions.assertEquals("cdn.contentstack.io", config.host);
106106
Assertions.assertNotNull(stack);
107107
}
108+
109+
110+
@Test
111+
void testConfigEarlyAccessSingleFeature() throws IllegalAccessException {
112+
Config config = new Config();
113+
String[] earlyAccess = {"Taxonomy"};
114+
config.earlyAccess(earlyAccess);
115+
Stack stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENV, config);
116+
Assertions.assertEquals(earlyAccess[0], config.earlyAccess[0]);
117+
Assertions.assertNotNull(stack.headers.containsKey("x-header-ea"));
118+
Assertions.assertEquals("Taxonomy", stack.headers.get("x-header-ea"));
119+
120+
}
121+
122+
@Test
123+
void testConfigEarlyAccessMultipleFeature() throws IllegalAccessException {
124+
Config config = new Config();
125+
String[] earlyAccess = {"Taxonomy", "Teams", "Terms", "LivePreview"};
126+
config.earlyAccess(earlyAccess);
127+
Stack stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENV, config);
128+
Assertions.assertEquals(4, stack.headers.keySet().size());
129+
Assertions.assertEquals(earlyAccess[1], config.earlyAccess[1]);
130+
Assertions.assertTrue(stack.headers.containsKey("x-header-ea"));
131+
Assertions.assertEquals("Taxonomy,Teams,Terms,LivePreview", stack.headers.get("x-header-ea"));
132+
}
108133
}

0 commit comments

Comments
 (0)