Skip to content

Commit

Permalink
Team Impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaileshmishra committed Dec 15, 2023
1 parent 1b63a00 commit 0c9b3d3
Show file tree
Hide file tree
Showing 14 changed files with 745 additions and 38 deletions.
48 changes: 29 additions & 19 deletions src/main/java/com/contentstack/cms/Contentstack.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class Contentstack {
protected final Boolean retryOnFailure;
protected final Proxy proxy;
protected AuthInterceptor interceptor;
protected String[] earlyAccess;
protected User user;

/**
Expand Down Expand Up @@ -80,8 +81,8 @@ public class Contentstack {
* @return User
* @author ishaileshmishra
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
* @since 2022-05-19
*/
public User user() {
Expand Down Expand Up @@ -130,8 +131,8 @@ public User user() {
* @throws IOException the IOException
* @author ishaileshmishra
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#users">User
* </a>
*/
public Response<LoginDetails> login(String emailId, String password) throws IOException {
if (this.authtoken != null)
Expand Down Expand Up @@ -183,10 +184,10 @@ public Response<LoginDetails> login(String emailId, String password) throws IOEx
* @throws IOException the IOException
* @author ishaileshmishra
* @see <a
* href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#log-in-to-your-account">Login
* your account
* </a>
* href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#log-in-to-your-account">Login
* your account
* </a>
*/
public Response<LoginDetails> login(String emailId, String password, String tfaToken) throws IOException {
if (this.authtoken != null)
Expand Down Expand Up @@ -287,11 +288,12 @@ public Organization organization() {
*
* @param organizationUid The UID of the organization that you want to retrieve
* @return the organization
* <br>
* <b>Example</b>
* <br>
* <b>Example</b>
*
* <pre>
* <pre>
* Contentstack contentstack = new Contentstack.Builder().build();
* <br>
* Organization org = contentstack.organization();
* </pre>
*/
Expand Down Expand Up @@ -447,6 +449,7 @@ public Contentstack(Builder builder) {
this.retryOnFailure = builder.retry;
this.proxy = builder.proxy;
this.interceptor = builder.authInterceptor;
this.earlyAccess = builder.earlyAccess;
}

/**
Expand All @@ -461,6 +464,7 @@ public static class Builder {
private AuthInterceptor authInterceptor;

private String authtoken; // authtoken for client
private String[] earlyAccess;
private Retrofit instance; // client instance
private String hostname = Util.HOST; // Default Host for Contentstack API (default: api.contentstack.io)
private String port = Util.PORT; // Default PORT for Contentstack API
Expand Down Expand Up @@ -488,14 +492,14 @@ public Builder() {
* <br>
* <p>
* {@code
*
<p>
*
* <p>
* Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("hostname", 433));
* Contentstack contentstack = new Contentstack.Builder().setProxy(proxy).build();
*
<p>
*
* <p>
* }
*
*
* @param proxy the proxy
* @return the Builder instance
*/
Expand Down Expand Up @@ -578,9 +582,9 @@ public Builder setTimeout(int timeout) {
* unit of granularity and provides utility methods to
* convert across units
* @return instance of Builder
* <p>
* Example:
* {@code
* <p>
* Example:
* {@code
* Contentstack cs = new Contentstack.Builder()
* .setAuthtoken(AUTHTOKEN)
* .setConnectionPool(5, 400, TimeUnit.MILLISECONDS)
Expand All @@ -604,6 +608,12 @@ public Builder setAuthtoken(String authtoken) {
return this;
}


public Builder earlyAccess(String[] earlyAccess) {
this.earlyAccess = earlyAccess;
return this;
}

/**
* Build contentstack.
*
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/contentstack/cms/core/AuthInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class AuthInterceptor implements Interceptor {

protected String authtoken;
protected String[] earlyAccess;

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

public void setEarlyAccess(String[] earlyAccess) {
this.earlyAccess = earlyAccess;
}

/**
* This function intercepts a request and adds headers to it, including a user
* agent, content type, and
Expand All @@ -73,6 +78,10 @@ public Response intercept(Chain chain) throws IOException {
if (this.authtoken != null) {
request.addHeader(Util.AUTHTOKEN, this.authtoken);
}
if (this.earlyAccess!=null && this.earlyAccess.length > 0) {
String commaSeparated = String.join(", ", earlyAccess);
request.addHeader(Util.EARLY_ACCESS_HEADER, commaSeparated);
}
return chain.proceed(request.build());
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/contentstack/cms/core/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class Util {
public static final String API_KEY = "api_key";
public static final String AUTHORIZATION = "authorization";
public static final String AUTHTOKEN = "authtoken";
public static final String EARLY_ACCESS_HEADER = "x-header-ea";
public static final String BRANCH = "branch";
public static final String X_USER_AGENT = "X-User-Agent";
public static final String USER_AGENT = "User-Agent";
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/contentstack/cms/stack/AliasService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

import java.util.Map;


/**
* The interface Alias service.
*/
public interface AliasService {

@GET("stacks/branch_aliases")
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/contentstack/cms/stack/Stack.java
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,17 @@ public Alias alias(String aliasUid) {
}


/**
* Teams streamline the process of assigning roles and permissions by grouping users together.
* 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.
*
* @return instance of {@link Teams}
*/
public Teams teams() {
return new Teams(this.client, this.headers);
}


/**
* The taxonomy works on data where hierarchy is configured
*
Expand Down
74 changes: 74 additions & 0 deletions src/main/java/com/contentstack/cms/stack/StackRoleMapping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.contentstack.cms.stack;

import com.contentstack.cms.BaseImplementation;
import okhttp3.ResponseBody;
import org.jetbrains.annotations.NotNull;
import org.json.simple.JSONObject;
import retrofit2.Call;

import java.util.HashMap;

/**
* Teams streamline the process of assigning roles and permissions by grouping users together.
* 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.
*/
public class StackRoleMapping implements BaseImplementation<StackRoleMapping> {

private HashMap<String, Object> headers;
private HashMap<String, Object> params;
final TeamService teamService;
final String teamId;

public StackRoleMapping(TeamService service, HashMap<String, Object> headers, @NotNull String teamId) {
this.headers.putAll(headers);
this.params = new HashMap<>();
this.teamId = teamId;
this.teamService = service;
}

@Override
public StackRoleMapping addParam(@NotNull String key, @NotNull Object value) {
this.params.put(key, value);
return this;
}

@Override
public StackRoleMapping addHeader(@NotNull String key, @NotNull String value) {
this.headers.put(key, value);
return this;
}

@Override
public StackRoleMapping addParams(@NotNull HashMap<String, Object> params) {
this.params.putAll(params);
return this;
}

@Override
public StackRoleMapping addHeaders(@NotNull HashMap<String, String> headers) {
this.headers.putAll(headers);
return this;
}


public Call<ResponseBody> create(@NotNull JSONObject body) {
return this.teamService.create(this.headers, body);
}

// public Call<ResponseBody> find() {
// return this.teamService.find(this.headers, body);
// }
//
// public Call<ResponseBody> update(@NotNull String stackApiKey, @NotNull JSONObject body) {
// return this.teamService.update(this.headers, this.teamId, stackApiKey, body);
// }
//
// public Call<ResponseBody> delete(@NotNull String stackApiKey) {
// return this.teamService.delete(this.headers, this.teamId, stackApiKey);
// }


}
21 changes: 12 additions & 9 deletions src/main/java/com/contentstack/cms/stack/Taxonomy.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@


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

Expand Down Expand Up @@ -147,7 +151,7 @@ public Taxonomy addParams(@NotNull HashMap<String, Object> params) {
* </li>
* </ul>
*
* @return the call <p></p> <b>Example</b> <pre> {@code
* @return the call <b>Example</b> <pre> {@code
* Response<ResponseBody> response = taxonomy.find().execute();
* } </pre>
*/
Expand All @@ -172,7 +176,7 @@ public Call<ResponseBody> find() {
* </ul>
*
* @param taxonomyId the taxonomy id
* @return the call <p></p> <b>Example</b> <pre> {@code
* @return the call <b>Example</b> <pre> {@code
* Response<ResponseBody> response = taxonomy.fetch("taxonomyId").execute();
* } </pre>
*/
Expand All @@ -184,7 +188,7 @@ public Call<ResponseBody> fetch(@NotNull String taxonomyId) {
* Create Taxonomy call.
*
* @param body the body
* @return the call <p></p> <b>Example</b> <pre> {@code
* @return the call <b>Example</b> <pre> {@code
* JSONObject body = new JSONObject
* Response<ResponseBody> response = taxonomy.create(body).execute();
* } </pre>
Expand All @@ -198,7 +202,7 @@ public Call<ResponseBody> create(@NotNull JSONObject body) {
*
* @param taxonomyId - The taxonomy for which we need to update the details
* @param body the body
* @return the call <p></p> <b>Example</b> <pre> {@code
* @return the call <b>Example</b> <pre> {@code
* JSONObject body = new JSONObject();
* JSONObject bodyContent = new JSONObject();
* bodyContent.put("name", "Taxonomy 1");
Expand All @@ -215,14 +219,15 @@ public Call<ResponseBody> update(@NotNull String taxonomyId, @NotNull JSONObject
* Delete Taxonomy call.
*
* @param taxonomyId - The taxonomy for which we need to update the details
* @return the call <p></p> <b>Example</b> <pre> {@code
* @return the call <b>Example</b> <pre> {@code
* Response<ResponseBody> response = taxonomy.delete("taxonomyId").execute();
* } </pre>
*/
public Call<ResponseBody> delete(@NotNull String taxonomyId) {
return this.taxonomyService.delete(this.headers, taxonomyId);
}


/**
* Clear params for internal uses only for testing
*/
Expand All @@ -233,12 +238,11 @@ protected void clearParams() {

/**
* Get terms information
* <p>
* <p>Examples</p>
* <pre>
* {@code
* Term terms = stack("authtoken").taxonomy("taxonomyId").term();
* }*
* }
* </pre>
*
* @return instance of {@link Terms}
Expand All @@ -247,5 +251,4 @@ public Terms terms() {
return new Terms(this.taxonomyService, this.headers, this.taxonomyId);
}


}
24 changes: 18 additions & 6 deletions src/main/java/com/contentstack/cms/stack/TaxonomyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@
public interface TaxonomyService {

@GET("taxonomies")
Call<ResponseBody> find(@HeaderMap Map<String, Object> headers, @QueryMap Map<String, Object> params);
Call<ResponseBody> find(
@HeaderMap Map<String, Object> headers,
@QueryMap Map<String, Object> params);

@GET("taxonomies/{taxonomy_uid}")
Call<ResponseBody> fetch(@HeaderMap Map<String, Object> headers, @Path("taxonomy_uid") String uid, @QueryMap Map<String, Object> query);
Call<ResponseBody> fetch(
@HeaderMap Map<String, Object> headers,
@Path("taxonomy_uid") String uid,
@QueryMap Map<String, Object> query);

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

//--Terms--

// --Terms--
@POST("taxonomies/{taxonomy_uid}/terms")
Call<ResponseBody> createTerm(
@HeaderMap HashMap<String, Object> headers,
Expand Down Expand Up @@ -73,10 +79,16 @@ Call<ResponseBody> updateTerm(
@Path("term_id") String termId,
@Body JSONObject body);

@PUT("taxonomies/{taxonomy_uid}/terms/{term_id}/move")
Call<ResponseBody> reorder(
@HeaderMap HashMap<String, Object> headers,
@Path("taxonomy_uid") String taxonomyId,
@Path("term_id") String termId,
@QueryMap Map<String, Object> queryParams,
@Body JSONObject body);

@GET("taxonomies/all/terms")
@GET("taxonomies/$all/terms")
Call<ResponseBody> searchTerm(
@HeaderMap HashMap<String, Object> headers,
@Query("term") String termString
);
@Query("typeahead") String termString);
}
Loading

0 comments on commit 0c9b3d3

Please sign in to comment.