-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOrganization.java
More file actions
443 lines (417 loc) · 15.6 KB
/
Organization.java
File metadata and controls
443 lines (417 loc) · 15.6 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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
package com.contentstack.cms.organization;
import com.contentstack.cms.core.ErrorMessages;
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.Objects;
/**
* Organization is the top-level entity in the hierarchy of Contentstack,
* consisting of stacks and stack resources, and
* users. Organization allows easy management of projects as well as users
* within the Organization.
*
* @author ***REMOVED***
* @version v0.1.0
* @since 2022-10-20
*/
public class Organization implements BaseImplementation<Organization> {
private final OrganizationService service;
protected HashMap<String, String> headers;
protected HashMap<String, Object> params;
private String organizationUid;
final String ERROR_MSG = ErrorMessages.ORGANIZATION_UID_REQUIRED;
/**
* Instantiates a new Organization.
*
* @param client The retrofit client
*/
public Organization(Retrofit client) {
this.headers = new HashMap<>();
this.params = new HashMap<>();
this.service = client.create(OrganizationService.class);
}
/**
* Instantiates a new Organization.
*
* @param client The retrofit client
* @param uid The uid of the organisation
*/
public Organization(Retrofit client, String uid) {
this.headers = new HashMap<>();
this.organizationUid = uid;
this.params = new HashMap<>();
this.service = client.create(OrganizationService.class);
}
/**
* Sets header for the request
*
* @param key header key for the request
* @param value header value for the request
* return Organization the instance of Organization
* @return Organization instance of organization
*/
public Organization addHeader(@NotNull String key, @NotNull String value) {
this.headers.put(key, value);
return this;
}
@Override
public Organization addParams(@NotNull HashMap<String, Object> params) {
this.params.putAll(params);
return this;
}
@Override
public Organization addHeaders(@NotNull HashMap<String, String> headers) {
this.headers.putAll(headers);
return this;
}
/**
* Sets header for the request
*
* @param key header key for the request
* @param value header value for the request
* @return instance of Organization
*/
public Organization addParam(@NotNull String key, @NotNull Object value) {
this.params.put(key, value);
return this;
}
/**
* The function clears the parameters of an organization object and returns the
* object itself.
*
* @return The method is returning an instance of the Organization class.
*/
protected Organization clearParams() {
this.params.clear();
return this;
}
/**
* <b>Gets all organizations.</b><br>
* The <b>Get all organizations</b> call lists all organizations related to the
* system user in the order that they
* were created
* <br>
* {@link #addParam(String, Object)} queryParams the query params query
* parameters are below <br>
* <ul>
* <li>limit(optional) The
* <b>limit</b> parameter will return a specific number of
* Organization roles in the output.
* Example, if there are 10 organization roles and you wish
* to fetch only the first 2, you need to
* specify '2' as the value in this parameter. <br>
* <li>skip(optional) The <b>skip</b>
* parameter will skip a specific number of Organization
* roles in the output. For example, if there
* are 12 organization roles and you want to skip the first 2
* to get only the last 10 in the
* response body, you need to specify '2' here. <br>
* <li>asc(optional) The <b>asc</b>
* parameter allows you to sort the list of organization
* roles in ascending order on the basis of a
* parameter. <br>
* <li>desc(optional) The <b>desc</b> parameter allows you to
* sort the list
* of organization roles in descending order on the basis of
* a parameter. <br>
* <li>
* include_count(optional) The <b>include_count</b> parameter
* returns the total number of roles in
* an organization. For example: If you want to know the
* total number of roles in an organization,
* you need to mention 'true'. <br>
* <li>typehead(optional) = "contentstack"
* </ul>
*
* @return Call
*/
public Call<ResponseBody> find() {
return this.service.fetch(this.headers, this.params);
}
/**
* Get a single organization
* <br>
* The Get a single organization call gets the comprehensive details of a
* specific organization related to the
* system user
* <br>
*
* <br>
* {@link #addParam(String, Object)} the Query Parameters include_plan(optional)
* = true
*
* @return Call
*/
public Call<ResponseBody> fetch() {
Objects.requireNonNull(this.organizationUid, ERROR_MSG);
return service.getSingle(this.headers, organizationUid, this.params);
}
/**
* Gets organization role.
*
* <br>
* {@link #addParam(String, Object)} the query params query parameters are below
* <br>
* <ul>
* <li>limit(optional) The
* <b>limit</b> parameter will return a specific number
* of Organization roles in the output.
* Example, if there are 10 organization roles, and you
* wish to fetch only the first 2, you need to
* specify '2' as the value in this parameter. <br>
* <li>skip(optional) The <b>skip</b>
* parameter will skip a specific number of Organization
* roles in the output. For example, if there
* are 12 organization roles and you want to skip the
* first 2 to get only the last 10 in the
* response body, you need to specify '2' here. <br>
* <li>asc(optional) The <b>asc</b>
* parameter allows you to sort the list of organization
* roles in an ascending order on the basis of
* a parameter. <br>
* <li>desc(optional) The <b>desc</b> parameter allows
* you to sort the
* list of organization roles in descending order on the
* basis of a parameter. <br>
* <li>include_count(optional) The <b>include_count</b>
* parameter returns the total number of
* roles
* in an organization. For example: If you want to know
* the total number of roles in an
* organization, you need to mention <b>true</b>. <br>
* <li>include_stack_roles(optional)
* The <b>include_stack_roles</b> parameter, when set to
* <b>true</b>, includes the details of
* stack-level roles in the Response body.
* </ul>
*
* @return Call
*/
public Call<ResponseBody> roles() {
Objects.requireNonNull(this.organizationUid, ERROR_MSG);
return service.getRoles(this.headers, this.organizationUid, this.params);
}
/**
* Gets organization users.
* <p>
* The Add users to organization call allows you to send invitations to add
* users to your organization. Only the
* owner or the admin of the organization can add users
* <p>
* When executing the API call, provide the Organization UID
*
* @param body the request body JSONObject
* @return Call
*/
public Call<ResponseBody> inviteUser(JSONObject body) {
Objects.requireNonNull(this.organizationUid, ERROR_MSG);
return service.inviteUser(this.headers, this.organizationUid, body);
}
/**
* Remove users from organization
* <br>
* Note: Only the owner or the admin of the organization can remove users
* <br>
* The Remove users from organization request allows you to remove existing
* users from your organization
* <br>
*
* @param body the request body JSONObject
* @return Call
*/
public Call<ResponseBody> removeUsers(JSONObject body) {
Objects.requireNonNull(this.organizationUid, ERROR_MSG);
return service.removeUser(this.headers, this.organizationUid, body);
}
/**
* Resend pending organization invitations call.
* <br>
* Resend pending organization invitation call allows you to resend Organization
* invitations to users who have not
* yet accepted the earlier invitation. Only the owner or the admin of the
* Organization can resend the invitation to
* add users to an Organization
*
* @param shareUid the share uid
* @return Call
*/
public Call<ResponseBody> resendInvitation(String shareUid) {
Objects.requireNonNull(this.organizationUid, ERROR_MSG);
return service.resendInvitation(this.headers, this.organizationUid, shareUid);
}
/**
* Get all organization invitations
* <br>
* The Get all organization invitations call gives you a list of all the
* Organization invitations. Only the owner or
* the admin of the Organization can resend the invitation to add users to an
* Organization.
* <br>
* <p>
* When executing the API call, provide the Organization UID
*
* <br>
* {@link #addParam(String, Object)} the query params query parameters are below
* <br>
* <ul>
* <li>limit(optional) The
* 'limit' parameter will return a specific number of
* sent organization invitations in the output.
* Example, if 10 invitations were sent out and you wish
* to fetch only the first 8, you need to
* specify '2' as the value in this parameter. <br>
* <li>skip(optional) The 'skip' parameter
* will skip a specific number of organization roles in
* the output. Example, if there are 12
* organization roles and you want to skip the last 2 to
* get only the first 10 in the response body,
* you need to specify '2' here. <br>
* <li>asc(optional) The 'asc' parameter allows you to
* sort the list of organization invitations in ascending
* order on the basis of a specific
* parameter. <br>
* <li>desc(optional) The 'desc' parameter allows you to
* sort the list of
* organization invitations in descending order on the
* basis of a specific parameter. <br>
* <li>include_count(optional) The 'include_count'
* parameter returns the total number of organization
* invitations sent out. Example: If you wish to know the
* total number of organization invitations,
* you need to mention 'true'. <br>
* <li>include_roles(optional) The 'include_roles'
* parameter, when set to 'true', will display the
* details of the roles that are assigned to the
* user in an organization. <br>
* <li>include_invited_by(optional) The
* 'include_invited_by'
* parameter, when set to 'true', includes the details of
* the user who sent out the organization
* invitation. <br>
* <li>include_user_details(optional) The
* 'include_user_details'
* parameter, when set to 'true', lets you know whether
* the user who has been sent the organization
* invitation has enabled Two-factor Authentication or
* not. <br>
* <li>
* typeahead(optional) The 'typeahead' parameter allows
* you to perform a name-based search on all the
* stacks on an organization based on the value provided.
* For example, it allows you to perform an
* email-ID-based search on all users based on the email
* ID provided.
* </ul>
*
* @return Call
*/
public Call<ResponseBody> allInvitations() {
Objects.requireNonNull(this.organizationUid, ERROR_MSG);
return service.getAllInvitations(this.headers, this.organizationUid, this.params);
}
/**
* Transfer organizations ownership call.<br>
* The Transfer organization ownership call transfers the ownership of an
* Organization to another user. When the call is executed, an email invitation
* for accepting the ownership of a
* particular Organization is sent to the specified user<br>
*
* @param body The request body @codes { "transfer_to": "abc@sample.com" }
* @return Call
*/
public Call<ResponseBody> transferOwnership(JSONObject body) {
Objects.requireNonNull(this.organizationUid, ERROR_MSG);
return service.transferOwnership(this.headers, this.organizationUid, body);
}
/**
* Gets all stacks in an organizations.
* <br>
* The Get all stacks in an organization call fetches the list of all stacks in
* an Organization
*
* <br>
* {@link #addParam(String, Object)} the query params query parameters are below
* <br>
* <ul>
* <li>limit(optional) The
* 'limit' parameter will return a specific number of
* sent organization invitations in the output.
* Example, if 10 invitations were sent out and you wish
* to fetch only the first 8, you need to
* specify '2' as the value in this parameter. <br>
* <li>skip(optional) The 'skip' parameter
* will skip a specific number of organization roles in
* the output. Example, if there are 12
* organization roles and you want to skip the last 2 to
* get only the first 10 in the response body,
* you need to specify '2' here. <br>
* <li>asc(optional) The 'asc' parameter allows you to
* sort the list of organization invitations in ascending
* order on the basis of a specific
* parameter. <br>
* <li>desc(optional) The 'desc' parameter allows you to
* sort the list of
* organization invitations in descending order on the
* basis of a specific parameter. <br>
* <li>include_count(optional) The 'include_count'
* parameter returns the total number of organization
* invitations sent out. Example: If you wish to know the
* total number of organization invitations,
* you need to mention 'true'.
* <li>typeahead(optional) The 'typeahead' parameter
* allows you
* to perform a name-based search on all the stacks on an
* organization based on the value provided.
* </ul>
*
* @return Call
*/
public Call<ResponseBody> stacks() {
Objects.requireNonNull(this.organizationUid, ERROR_MSG);
return service.getStacks(this.headers, this.organizationUid, this.params);
}
/**
* Gets organization logs.
* <br>
* The Get organization log details request is used to retrieve the audit log
* details of an organization
* <br>
* <b>
* Tip: This request returns only the first 25 audit log items of the specified
* organization. If you get more than
* 25 items in your response, refer the Pagination section to retrieve all the
* log items in paginated form
* </b>
* <br>
*
* @return Call
*/
public Call<ResponseBody> logsDetails() {
return service.getLogDetails(this.headers, this.organizationUid);
}
/**
* Gets organization logs.
* <br>
* The Get organization log details request is used to retrieve the audit log
* details of an organization
* <br>
* <b>
* Tip: This request returns only the first 25 audit log items of the specified
* organization. If you get more than
* 25 items in your response, refer the Pagination section to retrieve all the
* log items in paginated form
* </b>
* <br>
*
* @param logUid the log uid
* @return Call
*/
public Call<ResponseBody> logItem(String logUid) {
Objects.requireNonNull(this.organizationUid, ERROR_MSG);
return service.getLogItems(this.headers, this.organizationUid, logUid);
}
}