Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,5 @@ src/main/resources/
.vscode/settings.json
.vscode/
/.vscode/
.env
.env

7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v1.7.0

### Jul 07, 2025

- Nested Global Field Support added
- Snyk fixes

## v1.6.1

### Jun 23, 2025
Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<artifactId>cms</artifactId>
<packaging>jar</packaging>
<name>contentstack-management-java</name>
<version>1.6.1</version>
<version>1.7.0</version>
<description>Contentstack Java Management SDK for Content Management API, Contentstack is a headless CMS with an
API-first approach
</description>
Expand Down Expand Up @@ -89,14 +89,14 @@
<maven-javadoc-plugin.version>3.0.0</maven-javadoc-plugin.version>
<dotenv-source.version>5.2.2</dotenv-source.version>
<rxjava-source.version>3.1.10</rxjava-source.version>
<retrofit-source.version>2.11.0</retrofit-source.version>
<converter-gson-version>2.11.0</converter-gson-version>
<retrofit-source.version>2.12.0</retrofit-source.version>
<converter-gson-version>2.12.0</converter-gson-version>
<okhttp.version>4.12.0</okhttp.version>
<jococo-plugin.version>0.8.7</jococo-plugin.version>
<lombok-source.version>1.18.38</lombok-source.version>
<junit-jupiter.version>5.11.4</junit-jupiter.version>
<junit-jupiter-engine.version>5.10.1</junit-jupiter-engine.version>
<gson.version>2.13.0</gson.version>
<gson.version>2.13.1</gson.version>
<maven-site-plugin.version>3.3</maven-site-plugin.version>
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
Expand Down Expand Up @@ -213,7 +213,7 @@
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>2.1.20</version>
<version>2.1.21</version>
</dependency>
</dependencies>

Expand Down
83 changes: 74 additions & 9 deletions src/main/java/com/contentstack/cms/stack/GlobalField.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class GlobalField implements BaseImplementation<GlobalField> {
protected HashMap<String, Object> headers;
protected HashMap<String, Object> params;
protected String globalFiledUid;

protected String apiVersion;
protected GlobalField(Retrofit retrofit,Map<String, Object> headers) {
this.headers = new HashMap<>();
this.headers.putAll(headers);
Expand Down Expand Up @@ -85,7 +85,23 @@ public GlobalField addParam(@NotNull String key, @NotNull Object value) {
*/
@Override
public GlobalField addHeader(@NotNull String key, @NotNull String value) {
this.headers.put(key, value);
if ("api_version".equalsIgnoreCase(key)) {
this.apiVersion = value;
} else {
this.headers.put(key, value);
}
return this;
}

/**
* @param key The key parameter is a string that represents the name or
* identifier of the header.
* It is used to specify the type of information being sent in the
* header.
* @return instance of the GlobalField object
*/
public GlobalField removeHeader(@NotNull String key) {
this.headers.remove(key);
return this;
}

Expand All @@ -110,6 +126,10 @@ public GlobalField addParams(@NotNull HashMap<String, Object> params) {
*/
@Override
public GlobalField addHeaders(@NotNull HashMap<String, String> headers) {
if (headers.containsKey("api_version")) {
this.apiVersion = headers.get("api_version");
headers.remove("api_version");
}
this.headers.putAll(headers);
return this;
}
Expand All @@ -134,6 +154,21 @@ protected GlobalField clearParams() {
this.params.clear();
return this;
}
/*
* For Nested Global Fields the api_version is set to 3.2 which needs
* to removed from the headers inorder for other modules to function correctly
*/

/**
* Returns a copy of the headers with api_version set if needed.
*/
private Map<String, Object> getRequestHeaders() {
Map<String, Object> requestHeaders = new HashMap<>(this.headers);
if (this.apiVersion != null) {
requestHeaders.put("api_version", this.apiVersion);
}
return requestHeaders;
}

/**
* <b>Get All Global Fields</b>
Expand All @@ -158,7 +193,7 @@ protected GlobalField clearParams() {
* @since 0.1.0
*/
public Call<ResponseBody> find() {
return this.service.fetch(this.headers, this.params);
return this.service.fetch(getRequestHeaders(), this.params);
}

/**
Expand Down Expand Up @@ -188,7 +223,7 @@ public Call<ResponseBody> find() {
*/
public Call<ResponseBody> fetch() {
validate();
return this.service.single(this.headers, this.globalFiledUid, this.params);
return this.service.single(getRequestHeaders(), this.globalFiledUid, this.params);
}

/**
Expand Down Expand Up @@ -219,7 +254,7 @@ public Call<ResponseBody> fetch() {
* @since 0.1.0
*/
public Call<ResponseBody> create(@NotNull JSONObject requestBody) {
return this.service.create(this.headers, requestBody);
return this.service.create(getRequestHeaders(), requestBody);
}

/**
Expand Down Expand Up @@ -249,7 +284,7 @@ public Call<ResponseBody> create(@NotNull JSONObject requestBody) {
*/
public Call<ResponseBody> update(@NotNull JSONObject requestBody) {
validate();
return this.service.update(this.headers, this.globalFiledUid, requestBody);
return this.service.update(getRequestHeaders(), this.globalFiledUid, requestBody);
}

/**
Expand All @@ -274,7 +309,7 @@ public Call<ResponseBody> update(@NotNull JSONObject requestBody) {
*/
public Call<ResponseBody> delete() {
validate();
return this.service.delete(this.headers, this.globalFiledUid);
return this.service.delete(getRequestHeaders(), this.globalFiledUid);
}

/**
Expand All @@ -301,7 +336,7 @@ public Call<ResponseBody> delete() {
* @since 0.1.0
*/
public Call<ResponseBody> imports(@NotNull JSONObject body) {
return this.service.imports(this.headers, body);
return this.service.imports(getRequestHeaders(), body);
}

/**
Expand All @@ -322,6 +357,36 @@ public Call<ResponseBody> imports(@NotNull JSONObject body) {
*/
public Call<ResponseBody> export() {
validate();
return this.service.export(this.headers, this.globalFiledUid);
return this.service.export(getRequestHeaders(), this.globalFiledUid);
}

/**
* <b>Restore a global field </b>
* <p>
* The <b>Restore a global field</b> request allows you to restore the schema of
* a deleted global field.
* <p>
* When executing the API call, in the <b>URI Parameters</b> section, provide
* the unique ID of your global field.
*
* <b>Note:</b> You need to use either the stack's Management Token or the user
* Authtoken (any one is mandatory), along with the stack API key, to make a
* valid Content Management API request.
* Read more about authentication.
*
* @param requestBody the request body
* @return Call
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#restore-a-global-field">Restore
* a global
* field
*
* </a>
* @see #addHeader(String, String) to add headers
* @since 0.1.0
*/
public Call<ResponseBody> restore(@NotNull JSONObject requestBody) {
validate();
return this.service.restore(getRequestHeaders(), this.globalFiledUid, requestBody);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ Call<ResponseBody> imports(
Call<ResponseBody> export(
@HeaderMap Map<String, Object> headers,
@Path("global_field_uid") String globalFieldUid);

@PUT("global_fields/{global_field_uid}/restore")
Call<ResponseBody> restore(
@HeaderMap Map<String, Object> headers,
@Path("global_field_uid") String globalFieldUid,
@Body JSONObject body);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
RoleAPITest.class,
StackAPITest.class,
TokenAPITest.class,
OrgApiTests.class
OrgApiTests.class,
GlobalFieldAPITest.class

})
public class APISanityTestSuite {
Expand Down
Loading