Skip to content

Commit 2b1f8ae

Browse files
🪴 Extensions.java added
1 parent 8e2e2e7 commit 2b1f8ae

File tree

13 files changed

+462
-28
lines changed

13 files changed

+462
-28
lines changed

cms.iml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.14.9" level="project" />
1919
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.17.2" level="project" />
2020
<orderEntry type="library" name="Maven: com.squareup.retrofit2:converter-gson:2.9.0" level="project" />
21-
<orderEntry type="library" name="Maven: com.squareup.okhttp3:logging-interceptor:4.7.2" level="project" />
21+
<orderEntry type="library" name="Maven: com.squareup.okhttp3:logging-interceptor:4.9.3" level="project" />
22+
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10" level="project" />
23+
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.10" level="project" />
2224
<orderEntry type="library" scope="PROVIDED" name="Maven: org.jetbrains:annotations:23.0.0" level="project" />
2325
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.24" level="project" />
2426
<orderEntry type="library" scope="TEST" name="Maven: io.github.cdimascio:java-dotenv:5.2.2" level="project" />
25-
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.4.0" level="project" />
26-
<orderEntry type="library" scope="TEST" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.4.0" level="project" />
27+
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib:1.4.0" level="project" />
28+
<orderEntry type="library" name="Maven: org.jetbrains.kotlin:kotlin-stdlib-common:1.4.0" level="project" />
2729
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter:5.8.2" level="project" />
2830
<orderEntry type="library" scope="TEST" name="Maven: org.junit.jupiter:junit-jupiter-api:5.8.2" level="project" />
2931
<orderEntry type="library" scope="TEST" name="Maven: org.opentest4j:opentest4j:1.2.0" level="project" />

pom.xml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
<rxjava-source.version>3.1.4</rxjava-source.version>
8484
<retrofit-source.version>2.9.0</retrofit-source.version>
8585
<converter-gson-version>2.9.0</converter-gson-version>
86-
<loggin.version>4.9.3</loggin.version>
86+
<logging.version>4.9.3</logging.version>
8787
<jococo-plugin.version>0.8.5</jococo-plugin.version>
8888
<lombok-source.version>1.18.24</lombok-source.version>
8989
<junit-jupiter.version>5.8.2</junit-jupiter.version>
@@ -127,21 +127,15 @@
127127
<dependency>
128128
<groupId>com.squareup.okhttp3</groupId>
129129
<artifactId>logging-interceptor</artifactId>
130-
<version>${loggin.version}</version>
131-
<scope>runtime</scope>
130+
<version>${logging.version}</version>
131+
<scope>compile</scope>
132132
</dependency>
133133
<dependency>
134134
<groupId>org.jetbrains</groupId>
135135
<artifactId>annotations</artifactId>
136136
<version>23.0.0</version>
137137
<scope>provided</scope>
138138
</dependency>
139-
<!--com.squareup.okhttp3:logging-interceptor:4.7.2-->
140-
<dependency>
141-
<groupId>com.squareup.okhttp3</groupId>
142-
<artifactId>logging-interceptor</artifactId>
143-
<version>4.7.2</version>
144-
</dependency>
145139
<dependency>
146140
<groupId>org.projectlombok</groupId>
147141
<artifactId>lombok</artifactId>

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
import com.google.gson.Gson;
1111
import okhttp3.OkHttpClient;
1212
import okhttp3.ResponseBody;
13-
import okhttp3.logging.HttpLoggingInterceptor;
1413
import org.jetbrains.annotations.NotNull;
1514
import retrofit2.Response;
1615
import retrofit2.Retrofit;
1716
import retrofit2.converter.gson.GsonConverterFactory;
17+
import okhttp3.logging.HttpLoggingInterceptor;
1818

1919
import java.io.IOException;
2020
import java.net.Proxy;
@@ -503,15 +503,17 @@ private void validateClient(Contentstack contentstack) {
503503

504504
private OkHttpClient httpClient(Contentstack contentstack, Boolean retryOnFailure) {
505505
this.authInterceptor = contentstack.interceptor = new AuthInterceptor();
506-
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
507-
logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
508506
return new OkHttpClient.Builder()
509507
.addInterceptor(this.authInterceptor)
510-
.addInterceptor(logging)
508+
.addInterceptor(logger())
511509
.proxy(this.proxy)
512510
.retryOnConnectionFailure(retryOnFailure)
513511
.build();
514512
}
515513

514+
private HttpLoggingInterceptor logger() {
515+
return new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.NONE);
516+
}
517+
516518
}
517519
}

src/main/java/com/contentstack/cms/core/Callback.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.contentstack.cms.core;
22

33
public interface Callback {
4-
54
void result();
65

76
void fail();
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
package com.contentstack.cms.stack;
2+
3+
import com.contentstack.cms.core.CMSRuntimeException;
4+
import okhttp3.RequestBody;
5+
import okhttp3.ResponseBody;
6+
import org.jetbrains.annotations.NotNull;
7+
import org.json.simple.JSONObject;
8+
import retrofit2.Call;
9+
import retrofit2.Retrofit;
10+
11+
import java.util.HashMap;
12+
import java.util.Map;
13+
14+
public class Extensions {
15+
16+
protected final ExtensionsService service;
17+
protected HashMap<String, Object> headers;
18+
protected HashMap<String, Object> params;
19+
20+
protected Extensions(Retrofit retrofit, HashMap<String, Object> stackHeaders) {
21+
this.headers = new HashMap<>();
22+
this.params = new HashMap<>();
23+
this.headers.putAll(stackHeaders);
24+
this.service = retrofit.create(ExtensionsService.class);
25+
}
26+
27+
public Extensions addHeader(@NotNull String key, @NotNull String value) {
28+
this.headers.put(key, value);
29+
return this;
30+
}
31+
32+
public Extensions addParam(@NotNull String key, @NotNull String value) {
33+
this.params.put(key, value);
34+
return this;
35+
}
36+
37+
/**
38+
* The Get all custom fields request is used to get the information of all custom fields created in a stack.
39+
*
40+
* @param query
41+
* For custom fields <b>Example:"type":"field"</b>
42+
* @param isIncludeBranch
43+
* Set this to 'true' to include the '_branch' top-level key in the response. This key states the unique ID
44+
* of the branch where the concerned Contentstack module resides.
45+
* <b>Example:false</b>
46+
* @return @{@link Call}
47+
*/
48+
public Call<ResponseBody> getAll(@NotNull String query, boolean isIncludeBranch) {
49+
return this.service.getAll(this.headers, query, isIncludeBranch);
50+
}
51+
52+
53+
/**
54+
* @param customFieldUid
55+
* Enter the UID of the custom field of which you want to retrieve the details.
56+
* @param queryParam
57+
* Set this to 'true' to include the '_branch' top-level key in the response. This key states the unique ID
58+
* of the branch where the concerned Contentstack module resides.
59+
* <p>
60+
* <b>Example:false</b>
61+
* @return Call
62+
*/
63+
public Call<ResponseBody> get(@NotNull String customFieldUid, Map<String, Object> queryParam) {
64+
if (queryParam == null) {
65+
queryParam = new HashMap<>();
66+
this.headers.put("Content-Type", "multipart/form-data");
67+
}
68+
return this.service.getSingle(this.headers, customFieldUid, queryParam);
69+
}
70+
71+
/**
72+
* The Upload a custom field request is used to upload a custom field to Contentstack.
73+
* <p>
74+
* - extension[upload]: Select the HTML file of the custom field that you want to upload<br> - extension[title]:
75+
* Enter the title of the custom field that you want to upload<br> - extension[data_type]: Enter the data type for
76+
* the input field of the custom field<br> - extension[tags]: Enter the tags that you want to assign to the custom
77+
* field<br> - extension[multiple]: Enter ‘true’ if you want your custom field to store multiple values<br> -
78+
* extension[type]: Enter type as ‘field’, since this is a custom field extension.<br>
79+
*
80+
* @param queryParam
81+
* Set this to 'true' to include the '_branch' top-level key in the response. This key states the unique ID
82+
* of the branch where the concerned Contentstack module resides.
83+
* <p>
84+
* <b>Example:false</b>
85+
* @param body
86+
* In the ‘Body’ section, you need to provide the following ‘Body’ parameters under ‘form-data’
87+
* <pre>
88+
* Use like: Map<String, RequestBody> params = new HashMap<>();
89+
* //prepare RequestBody RequestBody someDataBody = ....;
90+
* //add it Map object params.put("DYNAMIC_PARAM_NAME", someDataBody);
91+
* </pre>
92+
* @return Call
93+
*/
94+
public Call<ResponseBody> uploadCustomField(Map<String, RequestBody> body, Map<String, Object> queryParam) {
95+
if (queryParam == null) {
96+
queryParam = new HashMap<>();
97+
}
98+
this.headers.put("Content-Type", "multipart/form-data");
99+
return this.service.uploadCustomField(this.headers, body, queryParam);
100+
}
101+
102+
/**
103+
* The Upload a custom field request is used to upload a custom field to Contentstack.
104+
* <p>
105+
* - extension[upload]: Select the HTML file of the custom field that you want to upload<br> - extension[title]:
106+
* Enter the title of the custom field that you want to upload<br> - extension[data_type]: Enter the data type for
107+
* the input field of the custom field<br> - extension[tags]: Enter the tags that you want to assign to the custom
108+
* field<br> - extension[multiple]: Enter ‘true’ if you want your custom field to store multiple values<br> -
109+
* extension[type]: Enter type as ‘field’, since this is a custom field extension.<br>
110+
*
111+
* @param queryParam
112+
* Set this to 'true' to include the '_branch' top-level key in the response. This key states the unique ID
113+
* of the branch where the concerned Contentstack module resides.
114+
* <p>
115+
* <b>Example:false</b>
116+
* @param body
117+
* In the ‘Body’ section, you need to provide the following ‘Body’ parameters under ‘form-data’
118+
* <pre>
119+
* Use like: Map<String, RequestBody> params = new HashMap<>();
120+
* //prepare RequestBody RequestBody someDataBody = ....;
121+
* //add it Map object params.put("DYNAMIC_PARAM_NAME", someDataBody);
122+
* </pre>
123+
* @return Call
124+
*/
125+
public Call<ResponseBody> uploadCustomField(Map<String, Object> queryParam, JSONObject body) {
126+
if (queryParam != null) {
127+
queryParam = new HashMap<>();
128+
if (!this.headers.containsKey("Content-Type")) {
129+
this.headers.put("Content-Type", "application/json");
130+
}
131+
}
132+
return this.service.uploadCustomField(this.headers, queryParam, body);
133+
}
134+
135+
136+
/**
137+
* @param customFieldUid
138+
* The UID of the custom field that you want to update
139+
* @param queryParam
140+
* Set this to 'true' to include the '_branch' top-level key in the response. This key states the unique ID
141+
* of the branch where the concerned Contentstack module resides.
142+
* <br>
143+
* <b>Example:false</b>
144+
* @param body
145+
* JSON requestBody
146+
* @return Call
147+
*/
148+
public Call<ResponseBody> update(@NotNull String customFieldUid, Map<String, Object> queryParam, JSONObject body) {
149+
if (body == null) {
150+
try {
151+
throw new CMSRuntimeException("body can not be Null");
152+
} catch (CMSRuntimeException e) {
153+
throw new RuntimeException(e.getLocalizedMessage());
154+
}
155+
}
156+
if (queryParam == null) {
157+
queryParam = new HashMap<>();
158+
}
159+
return this.service.update(this.headers, customFieldUid, queryParam, body);
160+
}
161+
162+
163+
/**
164+
* Delete custom field request is used to delete a specific custom field
165+
*
166+
* @param customFieldUid
167+
* UID of the custom field that you want to update
168+
* @return Call
169+
*/
170+
public Call<ResponseBody> delete(@NotNull String customFieldUid) {
171+
return this.service.delete(this.headers, customFieldUid);
172+
}
173+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.contentstack.cms.stack;
2+
3+
import okhttp3.MultipartBody;
4+
import okhttp3.RequestBody;
5+
import okhttp3.ResponseBody;
6+
import org.json.simple.JSONObject;
7+
import retrofit2.Call;
8+
import retrofit2.http.*;
9+
10+
import java.util.Map;
11+
12+
public interface ExtensionsService {
13+
14+
15+
@GET("extensions")
16+
Call<ResponseBody> getAll(
17+
@HeaderMap Map<String, Object> headers,
18+
@Query("query") String query,
19+
@Query("include_branch") Boolean isIncludeBranch);
20+
21+
@GET("extensions/{custom_field_uid}")
22+
Call<ResponseBody> getSingle(
23+
@HeaderMap Map<String, Object> headers,
24+
@Path("custom_field_uid") String customFieldUid,
25+
@QueryMap(encoded = true) Map<String, Object> queryParameter);
26+
27+
28+
@Multipart
29+
@POST("extensions")
30+
Call<ResponseBody> uploadCustomField(
31+
@HeaderMap Map<String, Object> headers,
32+
@PartMap Map<String, RequestBody> params,
33+
@QueryMap(encoded = true) Map<String, Object> queryParameter);
34+
35+
@POST("extensions")
36+
Call<ResponseBody> uploadCustomField(
37+
@HeaderMap Map<String, Object> headers,
38+
@QueryMap(encoded = true) Map<String, Object> queryParameter,
39+
@Body JSONObject body);
40+
41+
@PUT("extensions/{custom_field_uid}")
42+
Call<ResponseBody> update(
43+
@HeaderMap Map<String, Object> headers,
44+
@Path("custom_field_uid") String customFieldUid,
45+
@QueryMap(encoded = true) Map<String, Object> queryParameter,
46+
@Body JSONObject body);
47+
48+
@DELETE("extensions/{custom_field_uid}")
49+
Call<ResponseBody> delete(
50+
@HeaderMap Map<String, Object> headers,
51+
@Path("custom_field_uid") String customFieldUid);
52+
53+
@POST("content_types")
54+
Call<ResponseBody> createContentTypeWithExtensionField(
55+
@HeaderMap Map<String, Object> headers,
56+
@QueryMap(encoded = true) Map<String, Object> queryParameter,
57+
@Body JSONObject body);
58+
59+
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public Label addBranch(@NotNull String value) {
5959
*
6060
* @return Call
6161
*/
62-
public Call<RequestBody> get() {
62+
public Call<ResponseBody> get() {
6363
return this.service.get(this.headers);
6464
}
6565

@@ -77,7 +77,7 @@ public Call<RequestBody> get() {
7777
*
7878
* @return Call
7979
*/
80-
public Call<RequestBody> get(@NotNull Map<String, Object> jsonRequest) {
80+
public Call<ResponseBody> get(@NotNull Map<String, Object> jsonRequest) {
8181
return this.service.get(this.headers, jsonRequest);
8282
}
8383

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.contentstack.cms.stack;
22

3-
import okhttp3.RequestBody;
43
import okhttp3.ResponseBody;
54
import org.json.simple.JSONObject;
65
import retrofit2.Call;
@@ -11,11 +10,11 @@
1110
public interface LabelService {
1211

1312
@GET("labels")
14-
Call<RequestBody> get(
13+
Call<ResponseBody> get(
1514
@HeaderMap Map<String, Object> headers);
1615

1716
@GET("labels")
18-
Call<RequestBody> get(
17+
Call<ResponseBody> get(
1918
@HeaderMap Map<String, Object> headers,
2019
@QueryMap(encoded = true) Map<String, Object> queryParameter);
2120

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,23 @@ public Label label() {
168168
return new Label(client, this.headers);
169169
}
170170

171+
172+
/**
173+
* Extensions let you create custom fields and custom widgets that lets you customize Contentstack's default UI and
174+
* behavior. Read more about Extensions.
175+
* <p>
176+
* You can now pass the branch header in the API request to fetch or manage modules located within specific branches
177+
* of the stack. Additionally, you can also set the include_branch query parameter to true to include the _branch
178+
* top-level key in the response. This key specifies the unique ID of the branch where the concerned Contentstack
179+
* module resides.
180+
* <p>
181+
*
182+
* @return instance of {@link Extensions}
183+
*/
184+
public Extensions extensions() {
185+
return new Extensions(client, this.headers);
186+
}
187+
171188
/**
172189
* <b>Get a single stack</b>
173190
* <br>

src/test/java/com/contentstack/cms/organization/OrgApiTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ void testAllInvitation() throws IOException {
317317
organization.getAllInvitations(organizationUid).execute();
318318
if (response.isSuccessful()) {
319319
JsonObject respJson = toJson(response);
320-
Assertions.assertTrue(respJson.has("notice"));
321320
Assertions.assertTrue(respJson.has("shares"));
322321
} else {
323322
Error error = new Gson().fromJson(response.errorBody().string(),

0 commit comments

Comments
 (0)