Skip to content

Commit dba5270

Browse files
Merge pull request #50 from contentstack/azure-na
azure-na support added
2 parents 46af46d + c128399 commit dba5270

File tree

13 files changed

+135
-39
lines changed

13 files changed

+135
-39
lines changed

pom.xml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,22 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.contentstack.sdk</groupId>
77
<artifactId>java</artifactId>
8-
<version>${sdk.version.release}</version>
8+
<version>1.9.0-SNAPSHOT</version>
99
<packaging>jar</packaging>
1010
<name>contentstack-java</name>
1111
<description>Java SDK for Contentstack Content Delivery API</description>
1212
<url>https://github.com/contentstack/contentstack-java/</url>
1313

1414

1515
<properties>
16-
<!--update sdk version before every release push for SNAPSHOT/RELEASE-->
17-
<sdk.version.snapshot>1.8.1-SNAPSHOT</sdk.version.snapshot>
18-
<sdk.version.release>1.8.1</sdk.version.release>
16+
<sdk.version.snapshot>1.9.0-SNAPSHOT</sdk.version.snapshot>
17+
<sdk.version.release>1.9.0</sdk.version.release>
1918
<maven.compiler.target>1.8</maven.compiler.target>
2019
<maven.compiler.source>1.8</maven.compiler.source>
2120
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2221
<surefire-report-plugin.version>2.22.0</surefire-report-plugin.version>
2322
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
24-
<maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
23+
<maven-javadoc-plugin.version>3.3.2</maven-javadoc-plugin.version>
2524
<dotenv-source.version>5.2.2</dotenv-source.version>
2625
<rxjava-source.version>3.1.3</rxjava-source.version>
2726
<retrofit-source.version>2.9.0</retrofit-source.version>
@@ -39,7 +38,7 @@
3938
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
4039
<nexus-staging-maven-plugin.version>1.6.7</nexus-staging-maven-plugin.version>
4140
<maven-release-plugin.version>2.5.3</maven-release-plugin.version>
42-
<json-version>20210307</json-version>
41+
<json-version>20211205</json-version>
4342
<jacoco-maven-plugin-version>0.8.7</jacoco-maven-plugin-version>
4443
<maven-release-plugin-version>2.5.3</maven-release-plugin-version>
4544
<nexus-staging-maven-plugin-version>1.6.7</nexus-staging-maven-plugin-version>
@@ -283,7 +282,9 @@
283282
<configuration>
284283
<source>1.8</source>
285284
<target>1.8</target>
286-
<compilerArgument>-Xlint:all</compilerArgument>
285+
<compilerArgument>
286+
-Xlint:all,-serial,-processing
287+
</compilerArgument>
287288
<showWarnings>true</showWarnings>
288289
<showDeprecation>true</showDeprecation>
289290
</configuration>

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ public void send() {
184184
private void getService(String requestUrl) throws IOException {
185185
Retrofit retrofit = new Retrofit.Builder().baseUrl(this.endpoint).build();
186186
APIService service = retrofit.create(APIService.class);
187-
this.headers.remove(Constants.ENVIRONMENT);
188187
this.headers.put(X_USER_AGENT, CLIENT_USER_AGENT);
189188
this.headers.put(CONTENT_TYPE, APPLICATION_JSON);
190189
Response<ResponseBody> response = service.getRequest(requestUrl, this.headers).execute();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,11 @@ public Config setManagementToken(@NotNull String managementToken) {
119119
}
120120

121121
/**
122-
* The enum Contentstack region.
122+
* The enum Contentstack region. for now contentstack supports
123+
* [US, EU, AZURE_NA]
123124
*/
124125
public enum ContentstackRegion {
125-
US, EU
126+
US, EU, AZURE_NA
126127
}
127128

128129
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
public class Constants {
1515

1616
private static final Logger logger = Logger.getLogger(Constants.class.getSimpleName());
17-
protected static final String SDK_VERSION = "1.8.1";
17+
protected static final String SDK_VERSION = "1.9.0";
1818
protected static final String ENVIRONMENT = "environment";
1919
protected static final String CONTENT_TYPE_UID = "content_type_uid";
2020
protected static final String SYNCHRONISATION = "stacks/sync";

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,6 @@ public List<Asset> getAssets(String key) {
647647
}
648648

649649
/**
650-
* @param key
651-
*
652-
*
653-
* Get a group from entry.
654650
*
655651
* @param key field_uid as key. <br>
656652
* <br>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class EntryModel {
2626
protected String createdBy = null;
2727
protected Boolean isDirectory = false;
2828
protected String[] tags = null;
29-
protected String description = null;
29+
protected Object description = null;
3030
protected String environment = null;
3131
protected JSONArray images = null;
3232
protected String locale = null;
@@ -57,7 +57,7 @@ public EntryModel(JSONObject response) {
5757
this.url = (String) this.jsonObject.opt(urlKey);
5858
}
5959
if (this.jsonObject.has("description")) {
60-
this.description = (String) this.jsonObject.opt("description");
60+
this.description = this.jsonObject.opt("description");
6161
}
6262

6363
this.images = (JSONArray) this.jsonObject.opt("images");

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,19 @@ protected Stack(@NotNull String apiKey) {
3737
protected void setConfig(Config config) {
3838
this.config = config;
3939
String urlDomain = config.host;
40+
4041
if (!config.region.name().isEmpty()) {
4142
String region = config.region.name().toLowerCase();
42-
if (!region.equalsIgnoreCase("us")) {
43+
if (region.equalsIgnoreCase("eu")) {
4344
if (urlDomain.equalsIgnoreCase("cdn.contentstack.io")) {
4445
urlDomain = "cdn.contentstack.com";
4546
}
4647
config.host = region + "-" + urlDomain;
48+
} else if (region.equalsIgnoreCase("azure_na")) {
49+
if (urlDomain.equalsIgnoreCase("cdn.contentstack.io")) {
50+
urlDomain = "cdn.contentstack.com";
51+
}
52+
config.host = "azure-na" + "-" + urlDomain;
4753
}
4854
}
4955

@@ -191,9 +197,9 @@ public String getApplicationKey() {
191197
}
192198

193199
/**
194-
* @deprecated accessToken of particular stack
195-
*
196200
* @return {@link Stack} accessToken
201+
* @deprecated This method is no longer acceptable to get access token.
202+
* <p> Use getDeliveryToken instead.
197203
*/
198204
@Deprecated
199205
public String getAccessToken() {
@@ -481,8 +487,8 @@ public void syncPublishType(PublishType publishType, SyncResultCallBack syncCall
481487
*
482488
*
483489
*/
484-
public void sync(String contentType, Date fromDate, String localeCode, PublishType publishType,
485-
SyncResultCallBack syncCallBack) {
490+
public void sync(
491+
String contentType, Date fromDate, String localeCode, PublishType publishType, SyncResultCallBack syncCallBack) {
486492
String newDate = convertUTCToISO(fromDate);
487493
this.sync(null);
488494
syncParams.put("start_from", newDate);
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.contentstack.sdk;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.Test;
5+
6+
class TestAzureRegion {
7+
8+
@Test
9+
void testAzureRegion() {
10+
Assertions.assertTrue(true);
11+
}
12+
13+
@Test
14+
void testAzureRegionBehaviourUS() {
15+
Config config = new Config();
16+
Config.ContentstackRegion region = Config.ContentstackRegion.US;
17+
config.setRegion(region);
18+
Assertions.assertFalse(config.region.name().isEmpty());
19+
Assertions.assertEquals("US", config.region.name());
20+
}
21+
22+
@Test
23+
void testAzureRegionBehaviourEU() {
24+
Config config = new Config();
25+
Config.ContentstackRegion region = Config.ContentstackRegion.EU;
26+
config.setRegion(region);
27+
Assertions.assertFalse(config.region.name().isEmpty());
28+
Assertions.assertEquals("EU", config.region.name());
29+
}
30+
31+
@Test
32+
void testAzureRegionBehaviourAzure() {
33+
Config config = new Config();
34+
Config.ContentstackRegion region = Config.ContentstackRegion.AZURE_NA;
35+
config.setRegion(region);
36+
Assertions.assertFalse(config.region.name().isEmpty());
37+
Assertions.assertEquals("AZURE_NA", config.region.name());
38+
}
39+
40+
@Test
41+
void testAzureRegionBehaviourAzureStack() throws IllegalAccessException {
42+
Config config = new Config();
43+
Config.ContentstackRegion region = Config.ContentstackRegion.AZURE_NA;
44+
config.setRegion(region);
45+
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
46+
Assertions.assertFalse(config.region.name().isEmpty());
47+
Assertions.assertEquals("AZURE_NA", stack.config.region.name());
48+
}
49+
50+
@Test
51+
void testAzureRegionBehaviourAzureStackHost() throws IllegalAccessException {
52+
Config config = new Config();
53+
Config.ContentstackRegion region = Config.ContentstackRegion.AZURE_NA;
54+
config.setRegion(region);
55+
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
56+
Assertions.assertFalse(config.region.name().isEmpty());
57+
Assertions.assertEquals("azure-na-cdn.contentstack.com", stack.config.host);
58+
}
59+
60+
@Test
61+
void testAzureRegionBehaviourAzureStackInit() throws IllegalAccessException {
62+
Config config = new Config();
63+
Config.ContentstackRegion region = Config.ContentstackRegion.AZURE_NA;
64+
config.setRegion(region);
65+
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
66+
Query query = stack.contentType("fakeCT").query();
67+
query.find(new QueryResultsCallBack() {
68+
@Override
69+
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
70+
System.out.println("So something here...");
71+
}
72+
});
73+
Assertions.assertEquals("azure-na-cdn.contentstack.com", stack.config.host);
74+
}
75+
76+
@Test
77+
void testAzureRegionBehaviourEUStack() throws IllegalAccessException {
78+
Config config = new Config();
79+
Config.ContentstackRegion region = Config.ContentstackRegion.EU;
80+
config.setRegion(region);
81+
Stack stack = Contentstack.stack("fakeApiKey", "fakeDeliveryToken", "fakeEnvironment", config);
82+
Query query = stack.contentType("fakeCT").query();
83+
query.find(new QueryResultsCallBack() {
84+
@Override
85+
public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
86+
System.out.println("So something here...");
87+
}
88+
});
89+
Assertions.assertEquals("eu-cdn.contentstack.com", stack.config.host);
90+
}
91+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void testEntryInstance() {
6969
Entry entry = contentType.entry("just-fake-it");
7070
Assertions.assertEquals("product", entry.getContentType());
7171
Assertions.assertEquals("just-fake-it", entry.uid);
72-
Assertions.assertEquals(4, entry.headers.size());
72+
Assertions.assertEquals(5, entry.headers.size());
7373
logger.info("passed...");
7474
}
7575

@@ -78,7 +78,7 @@ void testQueryInstance() {
7878
ContentType contentType = stack.contentType("product");
7979
Query query = contentType.query();
8080
Assertions.assertEquals("product", query.getContentType());
81-
Assertions.assertEquals(4, query.headers.size());
81+
Assertions.assertEquals(5, query.headers.size());
8282
logger.info("passed...");
8383
}
8484

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void onCompletion(ResponseType responseType, Error error) {
8484
@Test
8585
@Order(4)
8686
void entryCalling() {
87-
Assertions.assertEquals(4, entry.headers.size());
87+
Assertions.assertEquals(5, entry.headers.size());
8888
logger.info("passed...");
8989
}
9090

0 commit comments

Comments
 (0)