Skip to content

Commit aaa228f

Browse files
Team Impl
1 parent ff8741d commit aaa228f

File tree

14 files changed

+745
-38
lines changed

14 files changed

+745
-38
lines changed

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

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public class Contentstack {
5151
protected final Boolean retryOnFailure;
5252
protected final Proxy proxy;
5353
protected AuthInterceptor interceptor;
54+
protected String[] earlyAccess;
5455
protected User user;
5556

5657
/**
@@ -80,8 +81,8 @@ public class Contentstack {
8081
* @return User
8182
* @author ***REMOVED***
8283
* @see <a href=
83-
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
84-
* </a>
84+
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
85+
* </a>
8586
* @since 2022-05-19
8687
*/
8788
public User user() {
@@ -130,8 +131,8 @@ public User user() {
130131
* @throws IOException the IOException
131132
* @author ***REMOVED***
132133
* @see <a href=
133-
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
134-
* </a>
134+
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
135+
* </a>
135136
*/
136137
public Response<LoginDetails> login(String emailId, String password) throws IOException {
137138
if (this.authtoken != null)
@@ -183,10 +184,10 @@ public Response<LoginDetails> login(String emailId, String password) throws IOEx
183184
* @throws IOException the IOException
184185
* @author ***REMOVED***
185186
* @see <a
186-
* href=
187-
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#log-in-to-your-account">Login
188-
* your account
189-
* </a>
187+
* href=
188+
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#log-in-to-your-account">Login
189+
* your account
190+
* </a>
190191
*/
191192
public Response<LoginDetails> login(String emailId, String password, String tfaToken) throws IOException {
192193
if (this.authtoken != null)
@@ -287,11 +288,12 @@ public Organization organization() {
287288
*
288289
* @param organizationUid The UID of the organization that you want to retrieve
289290
* @return the organization
290-
* <br>
291-
* <b>Example</b>
291+
* <br>
292+
* <b>Example</b>
292293
*
293-
* <pre>
294+
* <pre>
294295
* Contentstack contentstack = new Contentstack.Builder().build();
296+
* <br>
295297
* Organization org = contentstack.organization();
296298
* </pre>
297299
*/
@@ -447,6 +449,7 @@ public Contentstack(Builder builder) {
447449
this.retryOnFailure = builder.retry;
448450
this.proxy = builder.proxy;
449451
this.interceptor = builder.authInterceptor;
452+
this.earlyAccess = builder.earlyAccess;
450453
}
451454

452455
/**
@@ -461,6 +464,7 @@ public static class Builder {
461464
private AuthInterceptor authInterceptor;
462465

463466
private String authtoken; // authtoken for client
467+
private String[] earlyAccess;
464468
private Retrofit instance; // client instance
465469
private String hostname = Util.HOST; // Default Host for Contentstack API (default: api.contentstack.io)
466470
private String port = Util.PORT; // Default PORT for Contentstack API
@@ -488,14 +492,14 @@ public Builder() {
488492
* <br>
489493
* <p>
490494
* {@code
491-
*
492-
<p>
495+
*
496+
* <p>
493497
* Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433));
494498
* Contentstack contentstack = new Contentstack.Builder().setProxy(proxy).build();
495-
*
496-
<p>
499+
*
500+
* <p>
497501
* }
498-
*
502+
*
499503
* @param proxy the proxy
500504
* @return the Builder instance
501505
*/
@@ -578,9 +582,9 @@ public Builder setTimeout(int timeout) {
578582
* unit of granularity and provides utility methods to
579583
* convert across units
580584
* @return instance of Builder
581-
* <p>
582-
* Example:
583-
* {@code
585+
* <p>
586+
* Example:
587+
* {@code
584588
* Contentstack cs = new Contentstack.Builder()
585589
* .setAuthtoken(AUTHTOKEN)
586590
* .setConnectionPool(5, 400, TimeUnit.MILLISECONDS)
@@ -604,6 +608,12 @@ public Builder setAuthtoken(String authtoken) {
604608
return this;
605609
}
606610

611+
612+
public Builder earlyAccess(String[] earlyAccess) {
613+
this.earlyAccess = earlyAccess;
614+
return this;
615+
}
616+
607617
/**
608618
* Build contentstack.
609619
*

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
public class AuthInterceptor implements Interceptor {
2626

2727
protected String authtoken;
28+
protected String[] earlyAccess;
2829

2930
// The `public AuthInterceptor() {}` is a default constructor for the
3031
// `AuthInterceptor` class. It is
@@ -51,6 +52,10 @@ public void setAuthtoken(String authtoken) {
5152
this.authtoken = authtoken;
5253
}
5354

55+
public void setEarlyAccess(String[] earlyAccess) {
56+
this.earlyAccess = earlyAccess;
57+
}
58+
5459
/**
5560
* This function intercepts a request and adds headers to it, including a user
5661
* agent, content type, and
@@ -73,6 +78,10 @@ public Response intercept(Chain chain) throws IOException {
7378
if (this.authtoken != null) {
7479
request.addHeader(Util.AUTHTOKEN, this.authtoken);
7580
}
81+
if (this.earlyAccess!=null && this.earlyAccess.length > 0) {
82+
String commaSeparated = String.join(", ", earlyAccess);
83+
request.addHeader(Util.EARLY_ACCESS_HEADER, commaSeparated);
84+
}
7685
return chain.proceed(request.build());
7786
}
7887

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class Util {
3838
public static final String API_KEY = "api_key";
3939
public static final String AUTHORIZATION = "authorization";
4040
public static final String AUTHTOKEN = "authtoken";
41+
public static final String EARLY_ACCESS_HEADER = "x-header-ea";
4142
public static final String BRANCH = "branch";
4243
public static final String X_USER_AGENT = "X-User-Agent";
4344
public static final String USER_AGENT = "User-Agent";

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
import java.util.Map;
99

10+
11+
/**
12+
* The interface Alias service.
13+
*/
1014
public interface AliasService {
1115

1216
@GET("stacks/branch_aliases")

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,17 @@ public Alias alias(String aliasUid) {
822822
}
823823

824824

825+
/**
826+
* Teams streamline the process of assigning roles and permissions by grouping users together.
827+
* Rather than assigning roles to individual users or at the stack level, you can assign roles directly to a team. This ensures that all users within a team share the same set of role permissions, making role management more efficient.
828+
*
829+
* @return instance of {@link Teams}
830+
*/
831+
public Teams teams() {
832+
return new Teams(this.client, this.headers);
833+
}
834+
835+
825836
/**
826837
* The taxonomy works on data where hierarchy is configured
827838
*
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.contentstack.cms.stack;
2+
3+
import com.contentstack.cms.BaseImplementation;
4+
import okhttp3.ResponseBody;
5+
import org.jetbrains.annotations.NotNull;
6+
import org.json.simple.JSONObject;
7+
import retrofit2.Call;
8+
9+
import java.util.HashMap;
10+
11+
/**
12+
* Teams streamline the process of assigning roles and permissions by grouping users together.
13+
* Rather than assigning roles to individual users or at the stack level,
14+
* you can assign roles directly to a team.
15+
* This ensures that all users within a team share the same set of role permissions,
16+
* making role management more efficient.
17+
*/
18+
public class StackRoleMapping implements BaseImplementation<StackRoleMapping> {
19+
20+
private HashMap<String, Object> headers;
21+
private HashMap<String, Object> params;
22+
final TeamService teamService;
23+
final String teamId;
24+
25+
public StackRoleMapping(TeamService service, HashMap<String, Object> headers, @NotNull String teamId) {
26+
this.headers.putAll(headers);
27+
this.params = new HashMap<>();
28+
this.teamId = teamId;
29+
this.teamService = service;
30+
}
31+
32+
@Override
33+
public StackRoleMapping addParam(@NotNull String key, @NotNull Object value) {
34+
this.params.put(key, value);
35+
return this;
36+
}
37+
38+
@Override
39+
public StackRoleMapping addHeader(@NotNull String key, @NotNull String value) {
40+
this.headers.put(key, value);
41+
return this;
42+
}
43+
44+
@Override
45+
public StackRoleMapping addParams(@NotNull HashMap<String, Object> params) {
46+
this.params.putAll(params);
47+
return this;
48+
}
49+
50+
@Override
51+
public StackRoleMapping addHeaders(@NotNull HashMap<String, String> headers) {
52+
this.headers.putAll(headers);
53+
return this;
54+
}
55+
56+
57+
public Call<ResponseBody> create(@NotNull JSONObject body) {
58+
return this.teamService.create(this.headers, body);
59+
}
60+
61+
// public Call<ResponseBody> find() {
62+
// return this.teamService.find(this.headers, body);
63+
// }
64+
//
65+
// public Call<ResponseBody> update(@NotNull String stackApiKey, @NotNull JSONObject body) {
66+
// return this.teamService.update(this.headers, this.teamId, stackApiKey, body);
67+
// }
68+
//
69+
// public Call<ResponseBody> delete(@NotNull String stackApiKey) {
70+
// return this.teamService.delete(this.headers, this.teamId, stackApiKey);
71+
// }
72+
73+
74+
}

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

1212

1313
/**
14-
* The type Taxonomy.
14+
* Taxonomy is a system that classifies and organizes content in your collection or system.
15+
* It simplifies finding and retrieving information by categorizing items based on specific
16+
* criteria like their purpose, audience, or other relevant factors.
17+
* <p>
18+
* This hierarchical organization streamlines navigation and search processes.
1519
*/
1620
public class Taxonomy implements BaseImplementation<Taxonomy> {
1721

@@ -147,7 +151,7 @@ public Taxonomy addParams(@NotNull HashMap<String, Object> params) {
147151
* </li>
148152
* </ul>
149153
*
150-
* @return the call <p></p> <b>Example</b> <pre> {@code
154+
* @return the call <b>Example</b> <pre> {@code
151155
* Response<ResponseBody> response = taxonomy.find().execute();
152156
* } </pre>
153157
*/
@@ -172,7 +176,7 @@ public Call<ResponseBody> find() {
172176
* </ul>
173177
*
174178
* @param taxonomyId the taxonomy id
175-
* @return the call <p></p> <b>Example</b> <pre> {@code
179+
* @return the call <b>Example</b> <pre> {@code
176180
* Response<ResponseBody> response = taxonomy.fetch("taxonomyId").execute();
177181
* } </pre>
178182
*/
@@ -184,7 +188,7 @@ public Call<ResponseBody> fetch(@NotNull String taxonomyId) {
184188
* Create Taxonomy call.
185189
*
186190
* @param body the body
187-
* @return the call <p></p> <b>Example</b> <pre> {@code
191+
* @return the call <b>Example</b> <pre> {@code
188192
* JSONObject body = new JSONObject
189193
* Response<ResponseBody> response = taxonomy.create(body).execute();
190194
* } </pre>
@@ -198,7 +202,7 @@ public Call<ResponseBody> create(@NotNull JSONObject body) {
198202
*
199203
* @param taxonomyId - The taxonomy for which we need to update the details
200204
* @param body the body
201-
* @return the call <p></p> <b>Example</b> <pre> {@code
205+
* @return the call <b>Example</b> <pre> {@code
202206
* JSONObject body = new JSONObject();
203207
* JSONObject bodyContent = new JSONObject();
204208
* bodyContent.put("name", "Taxonomy 1");
@@ -215,14 +219,15 @@ public Call<ResponseBody> update(@NotNull String taxonomyId, @NotNull JSONObject
215219
* Delete Taxonomy call.
216220
*
217221
* @param taxonomyId - The taxonomy for which we need to update the details
218-
* @return the call <p></p> <b>Example</b> <pre> {@code
222+
* @return the call <b>Example</b> <pre> {@code
219223
* Response<ResponseBody> response = taxonomy.delete("taxonomyId").execute();
220224
* } </pre>
221225
*/
222226
public Call<ResponseBody> delete(@NotNull String taxonomyId) {
223227
return this.taxonomyService.delete(this.headers, taxonomyId);
224228
}
225229

230+
226231
/**
227232
* Clear params for internal uses only for testing
228233
*/
@@ -233,12 +238,11 @@ protected void clearParams() {
233238

234239
/**
235240
* Get terms information
236-
* <p>
237241
* <p>Examples</p>
238242
* <pre>
239243
* {@code
240244
* Term terms = stack("authtoken").taxonomy("taxonomyId").term();
241-
* }*
245+
* }
242246
* </pre>
243247
*
244248
* @return instance of {@link Terms}
@@ -247,5 +251,4 @@ public Terms terms() {
247251
return new Terms(this.taxonomyService, this.headers, this.taxonomyId);
248252
}
249253

250-
251254
}

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111
public interface TaxonomyService {
1212

1313
@GET("taxonomies")
14-
Call<ResponseBody> find(@HeaderMap Map<String, Object> headers, @QueryMap Map<String, Object> params);
14+
Call<ResponseBody> find(
15+
@HeaderMap Map<String, Object> headers,
16+
@QueryMap Map<String, Object> params);
1517

1618
@GET("taxonomies/{taxonomy_uid}")
17-
Call<ResponseBody> fetch(@HeaderMap Map<String, Object> headers, @Path("taxonomy_uid") String uid, @QueryMap Map<String, Object> query);
19+
Call<ResponseBody> fetch(
20+
@HeaderMap Map<String, Object> headers,
21+
@Path("taxonomy_uid") String uid,
22+
@QueryMap Map<String, Object> query);
1823

1924
@POST("taxonomies")
2025
Call<ResponseBody> create(
@@ -32,7 +37,8 @@ Call<ResponseBody> delete(
3237
@HeaderMap Map<String, Object> headers,
3338
@Path("taxonomy_uid") String uid);
3439

35-
//--Terms--
40+
41+
// --Terms--
3642
@POST("taxonomies/{taxonomy_uid}/terms")
3743
Call<ResponseBody> createTerm(
3844
@HeaderMap HashMap<String, Object> headers,
@@ -73,10 +79,16 @@ Call<ResponseBody> updateTerm(
7379
@Path("term_id") String termId,
7480
@Body JSONObject body);
7581

82+
@PUT("taxonomies/{taxonomy_uid}/terms/{term_id}/move")
83+
Call<ResponseBody> reorder(
84+
@HeaderMap HashMap<String, Object> headers,
85+
@Path("taxonomy_uid") String taxonomyId,
86+
@Path("term_id") String termId,
87+
@QueryMap Map<String, Object> queryParams,
88+
@Body JSONObject body);
7689

77-
@GET("taxonomies/all/terms")
90+
@GET("taxonomies/$all/terms")
7891
Call<ResponseBody> searchTerm(
7992
@HeaderMap HashMap<String, Object> headers,
80-
@Query("term") String termString
81-
);
93+
@Query("typeahead") String termString);
8294
}

0 commit comments

Comments
 (0)