Skip to content

Commit 91f3667

Browse files
branch and alias added
1 parent 1a8508f commit 91f3667

28 files changed

+950
-211
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
package com.contentstack.cms.stack;
2+
3+
import okhttp3.ResponseBody;
4+
import org.jetbrains.annotations.NotNull;
5+
import org.json.simple.JSONObject;
6+
import retrofit2.Call;
7+
import retrofit2.Retrofit;
8+
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
12+
13+
/**
14+
* An alias acts as a pointer to a particular branch. You can specify the alias ID in your frontend code to pull content
15+
* from the target branch associated with an alias.
16+
*
17+
* @author ***REMOVED***
18+
* @version 1.0.0
19+
* @see <a href="https://www.contentstack.com/docs/developers/apis/content-management-api/#aliases">About Aliases
20+
* </a>
21+
* @since 2022-05-19
22+
*/
23+
public class Alias {
24+
25+
protected final Map<String, Object> headers;
26+
protected Map<String, Object> params;
27+
protected final AliasService service;
28+
29+
protected Alias(Retrofit instance, @NotNull Map<String, Object> stackHeaders) {
30+
this.headers = new HashMap<>();
31+
this.headers.put("Content-Type", "application/json");
32+
this.headers.putAll(stackHeaders);
33+
params = new HashMap<>();
34+
this.service = instance.create(AliasService.class);
35+
}
36+
37+
/**
38+
* Sets header for the request
39+
*
40+
* @param key
41+
* header key for the request
42+
* @param value
43+
* header value for the request
44+
*/
45+
public void addHeader(@NotNull String key, @NotNull Object value) {
46+
this.headers.put(key, value);
47+
}
48+
49+
/**
50+
* Sets header for the request
51+
*
52+
* @param key
53+
* query param key for the request
54+
* @param value
55+
* query param value for the request
56+
*/
57+
public void addParam(@NotNull String key, @NotNull Object value) {
58+
this.params.put(key, value);
59+
}
60+
61+
62+
/**
63+
* Set header for the request
64+
*
65+
* @param key
66+
* Removes query param using key of request
67+
*/
68+
public void removeParam(@NotNull String key) {
69+
this.params.remove(key);
70+
}
71+
72+
73+
/**
74+
* To clear all the query params
75+
*/
76+
protected void clearParams() {
77+
this.params.clear();
78+
}
79+
80+
81+
/**
82+
* The Get all aliases request returns comprehensive information of all the aliases available in a particular stack
83+
* in your account.
84+
* <p>
85+
*
86+
* @return Call
87+
* @see <a href="https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-aliases">Get all
88+
* aliases</a>
89+
* @since 1.0.0
90+
*/
91+
public Call<ResponseBody> fetch() {
92+
return this.service.fetch(this.headers, this.params);
93+
}
94+
95+
/**
96+
* The Get a single alias request returns information of a specific alias.
97+
*
98+
* @param uid
99+
* The unique ID of the alias of which you want to retrieve the details. The UID of an alias is unique
100+
* across a stack. Execute the Get all aliases call to retrieve the UID of an alias
101+
* @return Call
102+
* @see <a href="https://www.contentstack.com/docs/developers/apis/content-management-api/#get-a-single-branch">
103+
* Get a single branch</a>
104+
* @since 1.0.0
105+
*/
106+
public Call<ResponseBody> single(@NotNull String uid) {
107+
return this.service.single(this.headers, uid);
108+
}
109+
110+
/**
111+
* <b>Assign or Update an alias</b>
112+
* <br>
113+
* The Assign an alias request creates a new alias in a particular stack of your organization. This alias can point
114+
* to any existing branch (target branch) of your stack.
115+
* <p>
116+
* You can use the same request to update the target branch of an alias. In the “Body” section, you need to provide
117+
* the UID of the new target branch that will be associated with the alias.
118+
*
119+
* @return Call
120+
* @see <a
121+
* href="https://www.contentstack.com/docs/developers/apis/content-management-api/#assign-or-update-an-alias">Update
122+
* a branch</a>
123+
* @see #addHeader(String, Object) to add headers
124+
* @since 1.0.0
125+
*/
126+
public Call<ResponseBody> update(@NotNull JSONObject body) {
127+
return this.service.update(this.headers, body);
128+
}
129+
130+
/**
131+
* The Delete an alias request deletes an existing alias.
132+
* <p>
133+
* To confirm deletion of an alias, you need to specify the force=true query parameter.
134+
* <p>
135+
* When executing the API call, in the “URL Parameters” section, provide the UID of your alias.
136+
*
137+
* @return Call
138+
* @see <a href="https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-an-alias">Delete a
139+
* branch</a>
140+
* @see #addHeader(String, Object) to add headers
141+
* @see #addParam(String, Object) to add query params
142+
* @since 1.0.0
143+
*/
144+
public Call<ResponseBody> delete(@NotNull String branchUid) {
145+
return this.service.delete(this.headers, branchUid, this.params);
146+
}
147+
148+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.contentstack.cms.stack;
2+
3+
import okhttp3.ResponseBody;
4+
import org.json.simple.JSONObject;
5+
import retrofit2.Call;
6+
import retrofit2.http.*;
7+
8+
import java.util.Map;
9+
10+
public interface AliasService {
11+
12+
@GET("stacks/branch_aliases")
13+
Call<ResponseBody> fetch(
14+
@HeaderMap Map<String, Object> headers, @QueryMap Map<String, Object> query);
15+
16+
@GET("stacks/branch_aliases/{branch_alias_uid}")
17+
Call<ResponseBody> single(
18+
@HeaderMap Map<String, Object> headers, @Path("branch_alias_uid") String uid);
19+
20+
@PUT("stacks/branch_aliases")
21+
Call<ResponseBody> update(
22+
@HeaderMap Map<String, Object> headers, @Body JSONObject body);
23+
24+
@DELETE("stacks/branch_aliases/{branch_alias_uid}")
25+
Call<ResponseBody> delete(
26+
@HeaderMap Map<String, Object> headers,
27+
@Path("branch_alias_uid") String uid, @QueryMap Map<String, Object> query);
28+
29+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package com.contentstack.cms.stack;
2+
3+
import okhttp3.ResponseBody;
4+
import org.jetbrains.annotations.NotNull;
5+
import org.json.simple.JSONObject;
6+
import retrofit2.Call;
7+
import retrofit2.Retrofit;
8+
9+
import java.util.HashMap;
10+
import java.util.Map;
11+
12+
13+
/**
14+
* Branches allows you to isolate and easily manage your “in-progress” work from your stable, live work in the
15+
* production environment. It helps multiple development teams to work in parallel in a more collaborative, organized,
16+
* and structured manner without impacting each other.
17+
*
18+
* @author ***REMOVED***
19+
* @version 1.0.0
20+
* @see <a href="https://www.contentstack.com/docs/developers/apis/content-management-api/#branches">About Branches
21+
* </a>
22+
* @since 2022-05-19
23+
*/
24+
public class Branch {
25+
26+
protected final Map<String, Object> headers;
27+
protected Map<String, Object> params;
28+
protected final BranchService service;
29+
30+
protected Branch(Retrofit instance, @NotNull Map<String, Object> stackHeaders) {
31+
this.headers = new HashMap<>();
32+
this.headers.put("Content-Type", "application/json");
33+
this.headers.putAll(stackHeaders);
34+
params = new HashMap<>();
35+
this.service = instance.create(BranchService.class);
36+
}
37+
38+
/**
39+
* Sets header for the request
40+
*
41+
* @param key
42+
* header key for the request
43+
* @param value
44+
* header value for the request
45+
*/
46+
public void addHeader(@NotNull String key, @NotNull Object value) {
47+
this.headers.put(key, value);
48+
}
49+
50+
/**
51+
* Sets header for the request
52+
*
53+
* @param key
54+
* query param key for the request
55+
* @param value
56+
* query param value for the request
57+
*/
58+
public void addParam(@NotNull String key, @NotNull Object value) {
59+
this.params.put(key, value);
60+
}
61+
62+
63+
/**
64+
* Set header for the request
65+
*
66+
* @param key
67+
* Removes query param using key of request
68+
*/
69+
public void removeParam(@NotNull String key) {
70+
this.params.remove(key);
71+
}
72+
73+
74+
/**
75+
* To clear all the query params
76+
*/
77+
protected void clearParams() {
78+
this.params.clear();
79+
}
80+
81+
82+
/**
83+
* The Get all branches request returns comprehensive information of all the branches available in a particular
84+
* stack in your account.
85+
* <p>
86+
* Example:file_size
87+
*
88+
* @return Call
89+
* @see <a href="https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-branches">Get all
90+
* branches</a>
91+
* @since 1.0.0
92+
*/
93+
public Call<ResponseBody> fetch() {
94+
return this.service.fetch(this.headers, this.params);
95+
}
96+
97+
/**
98+
* The Get a single branch request returns information of a specific branch.
99+
*
100+
* @param uid
101+
* The unique ID of the branch of which you want to retrieve the details. The UID of a branch is unique
102+
* across a stack. Execute the <b>Get all branches</b> call to retrieve the UID of a branch
103+
* @return Call
104+
* @see <a href="https://www.contentstack.com/docs/developers/apis/content-management-api/#get-a-single-branch">
105+
* Get a single branch</a>
106+
* @since 1.0.0
107+
*/
108+
public Call<ResponseBody> single(@NotNull String uid) {
109+
return this.service.single(this.headers, uid);
110+
}
111+
112+
/**
113+
* The Create a branch request creates a new branch in a particular stack of your organization.
114+
*
115+
* @return Call
116+
* @see <a href="https://www.contentstack.com/docs/developers/apis/content-management-api/#create-a-branch">Create a
117+
* branch</a>
118+
* @see #addHeader(String, Object) to add headers
119+
* @since 1.0.0
120+
*/
121+
public Call<ResponseBody> create(@NotNull JSONObject body) {
122+
return this.service.create(this.headers, body);
123+
}
124+
125+
/**
126+
* The Get assets and folders of a parent folder retrieves details of both assets and asset subfolders within a
127+
* specific parent asset folder.
128+
*
129+
* @return Call
130+
* @see <a href="https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-a-branch">Delete a
131+
* branch</a>
132+
* @see #addHeader(String, Object) to add headers
133+
* @see #addParam(String, Object) to add query params
134+
* @since 1.0.0
135+
*/
136+
public Call<ResponseBody> delete(@NotNull String branchUid) {
137+
return this.service.delete(this.headers, branchUid, this.params);
138+
}
139+
140+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.contentstack.cms.stack;
2+
3+
import okhttp3.ResponseBody;
4+
import org.json.simple.JSONObject;
5+
import retrofit2.Call;
6+
import retrofit2.http.*;
7+
8+
import java.util.Map;
9+
10+
public interface BranchService {
11+
12+
@GET("stacks/branches")
13+
Call<ResponseBody> fetch(
14+
@HeaderMap Map<String, Object> headers, @QueryMap Map<String, Object> query);
15+
16+
@GET("stacks/branches/{branch_uid}")
17+
Call<ResponseBody> single(
18+
@HeaderMap Map<String, Object> headers, @Path("branch_uid") String uid);
19+
20+
@POST("stacks/branches")
21+
Call<ResponseBody> create(
22+
@HeaderMap Map<String, Object> headers, @Body JSONObject body);
23+
24+
@DELETE("stacks/branches/{branch_uid}")
25+
Call<ResponseBody> delete(
26+
@HeaderMap Map<String, Object> headers,
27+
@Path("branch_uid") String uid, @QueryMap Map<String, Object> query);
28+
29+
}

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,32 @@ public Webhook webhook() {
341341
return new Webhook(this.client, this.headers);
342342
}
343343

344+
345+
/**
346+
* <b>Branches</b>
347+
* <br>
348+
* <b>Branches</b> allows you to isolate and easily manage your <b>in-progress</b> work from your stable, live work
349+
* in the production environment. It helps multiple development teams to work in parallel in a more collaborative,
350+
* organized, and structured manner without impacting each other.
351+
* <br>
352+
*
353+
* @return Branch
354+
*/
355+
public Branch branch() {
356+
return new Branch(this.client, this.headers);
357+
}
358+
359+
360+
/**
361+
* An alias acts as a pointer to a particular branch. You can specify the alias ID in your frontend code to pull
362+
* content from the target branch associated with an alias.
363+
*
364+
* @return Alias
365+
*/
366+
public Alias alias() {
367+
return new Alias(this.client, this.headers);
368+
}
369+
344370
/**
345371
* <b>Get stacks</b>
346372
* <br>

0 commit comments

Comments
 (0)