Skip to content

Commit 9c725ac

Browse files
v1.12.3
- Taxonomy query support - Early Access Feature Support
1 parent 65f32c0 commit 9c725ac

File tree

4 files changed

+109
-34
lines changed

4 files changed

+109
-34
lines changed

pom.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,14 @@
122122
<scope>compile</scope>
123123
</dependency>
124124

125+
<!-- https://mvnrepository.com/artifact/io.github.cdimascio/java-dotenv -->
125126
<dependency>
126127
<groupId>io.github.cdimascio</groupId>
127-
<artifactId>dotenv-java</artifactId>
128-
<version>${dotenv-source.version}</version>
129-
<!--<scope>runtime</scope>-->
128+
<artifactId>java-dotenv</artifactId>
129+
<version>5.2.2</version>
130130
</dependency>
131131

132+
132133
<dependency>
133134
<groupId>io.reactivex.rxjava3</groupId>
134135
<artifactId>rxjava</artifactId>

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

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

3-
import lombok.Getter;
4-
import lombok.Setter;
53
import okhttp3.ConnectionPool;
64
import org.jetbrains.annotations.NotNull;
75
import org.json.JSONObject;
@@ -19,7 +17,6 @@ public class Config {
1917
protected String livePreviewHash = null;
2018
protected String livePreviewContentType = null;
2119
protected String livePreviewEntryUid = null;
22-
@Getter
2320
protected String host = "cdn.contentstack.io";
2421
protected String version = "v3";
2522
protected String scheme = "https://";
@@ -29,21 +26,48 @@ public class Config {
2926
protected JSONObject livePreviewEntry = null;
3027
protected ContentstackRegion region = ContentstackRegion.US;
3128
protected String managementToken;
32-
@Setter
33-
@Getter
3429
protected String branch;
35-
@Setter
3630
protected Proxy proxy = null;
31+
protected String[] earlyAccess = null;
3732
protected ConnectionPool connectionPool = new ConnectionPool();
3833

3934
protected List<ContentstackPlugin> plugins = null;
4035

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

4872
/**
4973
* Returns the Proxy instance
@@ -101,6 +125,15 @@ public void setPlugins(List<ContentstackPlugin> plugins) {
101125
this.plugins = plugins;
102126
}
103127

128+
/**
129+
* Gets host.
130+
*
131+
* @return the host
132+
*/
133+
public String getHost() {
134+
return host;
135+
}
136+
104137
/**
105138
* Sets host.
106139
*
@@ -166,23 +199,4 @@ public enum ContentstackRegion {
166199
US, EU, AZURE_NA, AZURE_EU
167200
}
168201

169-
170-
/**
171-
* The configuration for the contentstack that contains support for Early Access Feature
172-
*
173-
* @param earlyAccessFeatures The list of Early Access Features
174-
* {@code
175-
* Config config = new Config();
176-
* String[] earlyAccess = {"Taxonomy", "Teams", "Terms", "LivePreview"};
177-
* config.earlyAccess(earlyAccess);
178-
* Stack stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENV, config);
179-
* <p>
180-
* }
181-
* @return Config
182-
*/
183-
public Config earlyAccess(@NotNull String[] earlyAccessFeatures) {
184-
this.earlyAccess = earlyAccessFeatures;
185-
return this;
186-
}
187-
188202
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.contentstack.sdk;
2+
import io.github.cdimascio.dotenv.Dotenv;
3+
4+
import java.rmi.AccessException;
5+
6+
public class Credentials {
7+
static Dotenv env = getEnv();
8+
9+
private static String envChecker() {
10+
String githubActions = System.getenv("GITHUB_ACTIONS");
11+
if (githubActions != null && githubActions.equals("true")) {
12+
return "GitHub";
13+
} else {
14+
return "local";
15+
}
16+
}
17+
18+
public static Dotenv getEnv() {
19+
env = Dotenv.configure()
20+
.directory("src/test/resources")
21+
.filename("env") // instead of '.env', use 'env'
22+
.load();
23+
24+
return Dotenv.load();
25+
}
26+
27+
28+
public final static String HOST = (env.get("HOST") != null) ? env.get("HOST") : "cdn.contentstack.io";
29+
public final static String API_KEY = (env.get("API_KEY") != null) ? env.get("API_KEY") : "";
30+
public final static String DELIVERY_TOKEN = (env.get("DELIVERY_TOKEN") != null) ? env.get("DELIVERY_TOKEN") : "";
31+
public final static String ENVIRONMENT = (env.get("ENVIRONMENT") != null) ? env.get("ENVIRONMENT") : "env1";
32+
public final static String CONTENT_TYPE = (env.get("contentType") != null) ? env.get("contentType") : "product";
33+
public final static String ENTRY_UID = (env.get("assetUid") != null) ? env.get("assetUid") : "";
34+
35+
36+
private static volatile Stack stack;
37+
38+
private Credentials() throws AccessException {
39+
throw new AccessException("Can not access");
40+
}
41+
42+
public static Stack getStack() {
43+
if (stack == null) {
44+
envChecker();
45+
synchronized (Credentials.class) {
46+
if (stack == null) {
47+
try {
48+
Config config = new Config();
49+
config.setHost(HOST);
50+
stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENVIRONMENT, config);
51+
} catch (IllegalAccessException e) {
52+
throw new RuntimeException(e);
53+
}
54+
}
55+
}
56+
}
57+
return stack;
58+
}
59+
60+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ void initStackWithConfigs() throws IllegalAccessException {
111111
void testConfigEarlyAccessSingleFeature() throws IllegalAccessException {
112112
Config config = new Config();
113113
String[] earlyAccess = {"Taxonomy"};
114-
config.earlyAccess(earlyAccess);
114+
config.setEarlyAccess(earlyAccess);
115115
Stack stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENV, config);
116116
Assertions.assertEquals(earlyAccess[0], config.earlyAccess[0]);
117117
Assertions.assertNotNull(stack.headers.containsKey("x-header-ea"));
@@ -122,7 +122,7 @@ void testConfigEarlyAccessSingleFeature() throws IllegalAccessException {
122122
void testConfigEarlyAccessMultipleFeature() throws IllegalAccessException {
123123
Config config = new Config();
124124
String[] earlyAccess = {"Taxonomy", "Teams", "Terms", "LivePreview"};
125-
config.earlyAccess(earlyAccess);
125+
config.setEarlyAccess(earlyAccess);
126126
Stack stack = Contentstack.stack(API_KEY, DELIVERY_TOKEN, ENV, config);
127127
Assertions.assertEquals(4, stack.headers.keySet().size());
128128
Assertions.assertEquals(earlyAccess[1], config.earlyAccess[1]);

0 commit comments

Comments
 (0)