-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBranch.java
More file actions
261 lines (242 loc) · 8.59 KB
/
Branch.java
File metadata and controls
261 lines (242 loc) · 8.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
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 retrofit2.Retrofit;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* Branches allows you to isolate and easily manage your “in-progress” work from
* your stable, live work in the
* production environment. It helps multiple development teams to work in
* parallel in a more collaborative, organized,
* and structured manner without impacting each other.
*
* @author ***REMOVED***
* @version v1.0.0
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#branches">About
* Branches
* </a>
* @since 2022-10-22
*/
public class Branch implements BaseImplementation<Branch> {
protected final Map<String, Object> headers;
protected Map<String, Object> params;
protected final BranchService service;
private Retrofit instance;
private String baseBranchId;
protected Branch(Retrofit instance,Map<String, Object> headers) {
this.headers = new HashMap<>();
this.headers.putAll(headers);
this.headers.put("Content-Type", "application/json");
this.params = new HashMap<>();
this.service = instance.create(BranchService.class);
}
protected Branch(Retrofit instance,Map<String, Object> headers, String uid) {
this.headers = new HashMap<>();
this.headers.putAll(headers);
this.headers.put("Content-Type", "application/json");
this.baseBranchId = uid;
this.params = new HashMap<>();
this.instance = instance;
this.service = instance.create(BranchService.class);
}
void validate() {
final String ERROR_MESSAGE = "The Branch UID Can Not Be Null ORr Empty";
Objects.requireNonNull(this.baseBranchId, ERROR_MESSAGE);
if (this.baseBranchId.isEmpty())
throw new IllegalStateException(ERROR_MESSAGE);
}
/**
* Adds a header with the specified key and value to this location and returns
* the updated location.
*
* @param key the key of the header to be added
* @param value the value of the header to be added
* @return a new {@link Branch} object with the specified header added
* @throws NullPointerException if the key or value argument is null
*/
@Override
public Branch addParam(@NotNull String key, @NotNull Object value) {
this.params.put(key, value);
return this;
}
/**
* Adds a header with the specified key and value to this location and returns
* the updated location.
*
* @param key the key of the header to be added
* @param value the value of the header to be added
* @return a new {@link Branch} object with the specified header added
* @throws NullPointerException if the key or value argument is null
*/
@Override
public Branch addHeader(@NotNull String key, @NotNull String value) {
this.headers.put(key, value);
return this;
}
/**
* Adds the specified parameters to this location and returns the updated
* location.
*
* @param params a {@link HashMap} containing the parameters to be added
* @return a new {@link Branch} object with the specified parameters added
* @throws NullPointerException if the params argument is null
*/
@Override
public Branch addParams(@NotNull HashMap params) {
this.params.putAll(params);
return this;
}
/**
* Adds a header with the specified key and value to this location and returns
* the updated location.
*
* @param headers headers of type {@link HashMap} will be added
* @throws NullPointerException if the key or value argument is null
*/
@Override
public Branch addHeaders(HashMap headers) {
this.headers.putAll(headers);
return this;
}
/**
* To clear all the query params
*/
protected void clearParams() {
this.params.clear();
}
/**
* The Get all branches request returns comprehensive information of all the
* branches available in a particular
* stack in your account.
* <p>
* Example:file_size
*
* @return Call
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-all-branches">Get
* all branches</a>
* @since 0.1.0
*/
public Call<ResponseBody> find() {
return this.service.fetch(this.headers, this.params);
}
/**
* The Get a single branch request returns information of a specific branch.
*
* @return Call
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#get-a-single-branch">
* Get a single branch</a>
* @since 0.1.0
*/
public Call<ResponseBody> fetch() {
validate();
return this.service.single(this.headers, this.baseBranchId);
}
/**
* The Create a branch request creates a new branch in a particular stack of
* your organization.
*
* @param body the request body
* @return Call
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#create-a-branch">Create
* a branch</a>
* @see #addHeader(String, String) to add headers
* @since 0.1.0
*/
public Call<ResponseBody> create(@NotNull JSONObject body) {
return this.service.create(this.headers, body);
}
/**
* The Get assets and folders of a parent folder retrieves details of both
* assets and asset subfolders within a
* specific parent asset folder.
*
* @return Call
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#delete-a-branch">Delete
* a branch</a>
* @see #addHeader(String, String) to add headers
* @see #addParam(String, Object) to add query params
* @since 0.1.0
*/
public Call<ResponseBody> delete() {
validate();
return this.service.delete(this.headers, this.baseBranchId, this.params);
}
/**
* With the Comparing Branches functionality, you can compare and check the
* differences between any two branches.
* <br>
* The <b>Compare branches</b> request returns a list of all the differences
* between two branches
* <br>
* <b>Note:</b>
* <br>
* <ul>
* <li>
* The compare branches feature is only available for the content types and
* global fields modules.
* </li>
* <li>
* If the number of Content Types/Global Fields that need to be compared is more
* than 100, you will receive a Next URL in the response body.
* The comparison limit is set at 100, and for every comparison that goes beyond
* this limit,
* the process will be completed in segments of 100.
* </li>
* </ul>
*
* @param compareBranchId the branch you want to compare with the base branch
* @return instance of @{@link Compare}
* @see <a href=
* "https://www.contentstack.com/docs/developers/apis/content-management-api/#compare-branches"></a>Compare
* Branches
*/
public Compare compare(@NotNull String compareBranchId) {
return new Compare(this.instance, this.baseBranchId, compareBranchId);
}
/**
* <b>Merge Branches</b>
* <br>
* The Merge branches request merges the specified two branches as per the merge
* strategy selected.
* <br>
* You can pass ignore in the default_merge_strategy query parameter, and pass
* the item_merge_strategies in the
* request body to override the default strategy and use a different merge
* strategy for specific content types or
* global fields.
* <br>
* <b>Note:</b>
* <ul>
* <li>
* The merge branches feature is only available for the content types and global
* fields modules
* </li>
* <li>
* You can create an additional revert branch beyond the established limit of 10
* branches per stack.
* For instance, if you already have 10 branches in your stack, you can perform
* a merge operation,
* provided that you manually delete the backup branch or any other
* branch before attempting the next merge.
* </li>
* </ul>
*
* @return instance of @{@link Merge}
* @see <a href=
* "https://www.contentstack.com/docs/developers/branches/merging-branches/"></a>Merging
* Branches
*/
public Merge mergeQueue() {
return new Merge(this.instance, this.baseBranchId);
}
}