Skip to content

Commit 33c2667

Browse files
Merge pull request #162 from contentstack/staging
DX | 07-07-2025 | Staging
2 parents 9db909e + abf6247 commit 33c2667

17 files changed

+914
-42
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,5 @@ src/main/resources/
271271
.vscode/settings.json
272272
.vscode/
273273
/.vscode/
274-
.env
274+
.env
275+

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v1.7.0
4+
5+
### Jul 07, 2025
6+
7+
- Nested Global Field Support added
8+
- Snyk fixes
9+
310
## v1.6.1
411

512
### Jun 23, 2025

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<artifactId>cms</artifactId>
88
<packaging>jar</packaging>
99
<name>contentstack-management-java</name>
10-
<version>1.6.1</version>
10+
<version>1.7.0</version>
1111
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
1212
API-first approach
1313
</description>
@@ -89,14 +89,14 @@
8989
<maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
9090
<dotenv-source.version>5.2.2</dotenv-source.version>
9191
<rxjava-source.version>3.1.10</rxjava-source.version>
92-
<retrofit-source.version>2.11.0</retrofit-source.version>
93-
<converter-gson-version>2.11.0</converter-gson-version>
92+
<retrofit-source.version>2.12.0</retrofit-source.version>
93+
<converter-gson-version>2.12.0</converter-gson-version>
9494
<okhttp.version>4.12.0</okhttp.version>
9595
<jococo-plugin.version>0.8.7</jococo-plugin.version>
9696
<lombok-source.version>1.18.38</lombok-source.version>
9797
<junit-jupiter.version>5.11.4</junit-jupiter.version>
9898
<junit-jupiter-engine.version>5.10.1</junit-jupiter-engine.version>
99-
<gson.version>2.13.0</gson.version>
99+
<gson.version>2.13.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>
102102
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
@@ -213,7 +213,7 @@
213213
<dependency>
214214
<groupId>org.jetbrains.kotlin</groupId>
215215
<artifactId>kotlin-stdlib</artifactId>
216-
<version>2.1.20</version>
216+
<version>2.1.21</version>
217217
</dependency>
218218
</dependencies>
219219

src/main/java/com/contentstack/cms/stack/GlobalField.java

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class GlobalField implements BaseImplementation<GlobalField> {
3737
protected HashMap<String, Object> headers;
3838
protected HashMap<String, Object> params;
3939
protected String globalFiledUid;
40-
40+
protected String apiVersion;
4141
protected GlobalField(Retrofit retrofit,Map<String, Object> headers) {
4242
this.headers = new HashMap<>();
4343
this.headers.putAll(headers);
@@ -85,7 +85,23 @@ public GlobalField addParam(@NotNull String key, @NotNull Object value) {
8585
*/
8686
@Override
8787
public GlobalField addHeader(@NotNull String key, @NotNull String value) {
88-
this.headers.put(key, value);
88+
if ("api_version".equalsIgnoreCase(key)) {
89+
this.apiVersion = value;
90+
} else {
91+
this.headers.put(key, value);
92+
}
93+
return this;
94+
}
95+
96+
/**
97+
* @param key The key parameter is a string that represents the name or
98+
* identifier of the header.
99+
* It is used to specify the type of information being sent in the
100+
* header.
101+
* @return instance of the GlobalField object
102+
*/
103+
public GlobalField removeHeader(@NotNull String key) {
104+
this.headers.remove(key);
89105
return this;
90106
}
91107

@@ -110,6 +126,10 @@ public GlobalField addParams(@NotNull HashMap<String, Object> params) {
110126
*/
111127
@Override
112128
public GlobalField addHeaders(@NotNull HashMap<String, String> headers) {
129+
if (headers.containsKey("api_version")) {
130+
this.apiVersion = headers.get("api_version");
131+
headers.remove("api_version");
132+
}
113133
this.headers.putAll(headers);
114134
return this;
115135
}
@@ -134,6 +154,21 @@ protected GlobalField clearParams() {
134154
this.params.clear();
135155
return this;
136156
}
157+
/*
158+
* For Nested Global Fields the api_version is set to 3.2 which needs
159+
* to removed from the headers inorder for other modules to function correctly
160+
*/
161+
162+
/**
163+
* Returns a copy of the headers with api_version set if needed.
164+
*/
165+
private Map<String, Object> getRequestHeaders() {
166+
Map<String, Object> requestHeaders = new HashMap<>(this.headers);
167+
if (this.apiVersion != null) {
168+
requestHeaders.put("api_version", this.apiVersion);
169+
}
170+
return requestHeaders;
171+
}
137172

138173
/**
139174
* <b>Get All Global Fields</b>
@@ -158,7 +193,7 @@ protected GlobalField clearParams() {
158193
* @since 0.1.0
159194
*/
160195
public Call<ResponseBody> find() {
161-
return this.service.fetch(this.headers, this.params);
196+
return this.service.fetch(getRequestHeaders(), this.params);
162197
}
163198

164199
/**
@@ -188,7 +223,7 @@ public Call<ResponseBody> find() {
188223
*/
189224
public Call<ResponseBody> fetch() {
190225
validate();
191-
return this.service.single(this.headers, this.globalFiledUid, this.params);
226+
return this.service.single(getRequestHeaders(), this.globalFiledUid, this.params);
192227
}
193228

194229
/**
@@ -219,7 +254,7 @@ public Call<ResponseBody> fetch() {
219254
* @since 0.1.0
220255
*/
221256
public Call<ResponseBody> create(@NotNull JSONObject requestBody) {
222-
return this.service.create(this.headers, requestBody);
257+
return this.service.create(getRequestHeaders(), requestBody);
223258
}
224259

225260
/**
@@ -249,7 +284,7 @@ public Call<ResponseBody> create(@NotNull JSONObject requestBody) {
249284
*/
250285
public Call<ResponseBody> update(@NotNull JSONObject requestBody) {
251286
validate();
252-
return this.service.update(this.headers, this.globalFiledUid, requestBody);
287+
return this.service.update(getRequestHeaders(), this.globalFiledUid, requestBody);
253288
}
254289

255290
/**
@@ -274,7 +309,7 @@ public Call<ResponseBody> update(@NotNull JSONObject requestBody) {
274309
*/
275310
public Call<ResponseBody> delete() {
276311
validate();
277-
return this.service.delete(this.headers, this.globalFiledUid);
312+
return this.service.delete(getRequestHeaders(), this.globalFiledUid);
278313
}
279314

280315
/**
@@ -301,7 +336,7 @@ public Call<ResponseBody> delete() {
301336
* @since 0.1.0
302337
*/
303338
public Call<ResponseBody> imports(@NotNull JSONObject body) {
304-
return this.service.imports(this.headers, body);
339+
return this.service.imports(getRequestHeaders(), body);
305340
}
306341

307342
/**
@@ -322,6 +357,36 @@ public Call<ResponseBody> imports(@NotNull JSONObject body) {
322357
*/
323358
public Call<ResponseBody> export() {
324359
validate();
325-
return this.service.export(this.headers, this.globalFiledUid);
360+
return this.service.export(getRequestHeaders(), this.globalFiledUid);
361+
}
362+
363+
/**
364+
* <b>Restore a global field </b>
365+
* <p>
366+
* The <b>Restore a global field</b> request allows you to restore the schema of
367+
* a deleted global field.
368+
* <p>
369+
* When executing the API call, in the <b>URI Parameters</b> section, provide
370+
* the unique ID of your global field.
371+
*
372+
* <b>Note:</b> You need to use either the stack's Management Token or the user
373+
* Authtoken (any one is mandatory), along with the stack API key, to make a
374+
* valid Content Management API request.
375+
* Read more about authentication.
376+
*
377+
* @param requestBody the request body
378+
* @return Call
379+
* @see <a href=
380+
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#restore-a-global-field">Restore
381+
* a global
382+
* field
383+
*
384+
* </a>
385+
* @see #addHeader(String, String) to add headers
386+
* @since 0.1.0
387+
*/
388+
public Call<ResponseBody> restore(@NotNull JSONObject requestBody) {
389+
validate();
390+
return this.service.restore(getRequestHeaders(), this.globalFiledUid, requestBody);
326391
}
327392
}

src/main/java/com/contentstack/cms/stack/GlobalFieldService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,10 @@ Call<ResponseBody> imports(
4646
Call<ResponseBody> export(
4747
@HeaderMap Map<String, Object> headers,
4848
@Path("global_field_uid") String globalFieldUid);
49+
50+
@PUT("global_fields/{global_field_uid}/restore")
51+
Call<ResponseBody> restore(
52+
@HeaderMap Map<String, Object> headers,
53+
@Path("global_field_uid") String globalFieldUid,
54+
@Body JSONObject body);
4955
}

src/test/java/com/contentstack/cms/stack/APISanityTestSuite.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
RoleAPITest.class,
1919
StackAPITest.class,
2020
TokenAPITest.class,
21-
OrgApiTests.class
21+
OrgApiTests.class,
22+
GlobalFieldAPITest.class
2223

2324
})
2425
public class APISanityTestSuite {

0 commit comments

Comments
 (0)