forked from crowdin/crowdin-api-client-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsersApi.java
More file actions
408 lines (380 loc) · 22.2 KB
/
UsersApi.java
File metadata and controls
408 lines (380 loc) · 22.2 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
package com.crowdin.client.users;
import com.crowdin.client.core.CrowdinApi;
import com.crowdin.client.core.http.HttpRequestConfig;
import com.crowdin.client.core.http.exceptions.HttpBadRequestException;
import com.crowdin.client.core.http.exceptions.HttpException;
import com.crowdin.client.core.model.*;
import com.crowdin.client.users.model.*;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
public class UsersApi extends CrowdinApi {
public UsersApi(Credentials credentials) {
super(credentials);
}
public UsersApi(Credentials credentials, ClientConfig clientConfig) {
super(credentials, clientConfig);
}
/**
* List group managers. For Crowdin Enterprise only
* @param groupId Group Identifier. Get via List Groups
* @param teamIds Defines team ids. It can be one team id or a list of comma-separated ones.
* @param orderBy
* @return list of group managers
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.groups.managers.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<GroupManager> listGroupManagers(Long groupId, List<Long> teamIds, String orderBy) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"teamIds", Optional.ofNullable(teamIds),
"orderBy", Optional.ofNullable(orderBy)
);
GroupManagerResponseList response = this.httpClient.get(this.url + "/groups/" + groupId + "/managers", new HttpRequestConfig(queryParams), GroupManagerResponseList.class);
return GroupManagerResponseList.to(response);
}
/**
* List group managers. For Crowdin Enterprise only
* @param groupId Group Identifier. Get via List Groups
* @param params ListGroupManagersParams
* @return list of group managers
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.groups.managers.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<GroupManager> listGroupManagers(Long groupId, ListGroupManagersParams params) throws HttpException, HttpBadRequestException {
ListGroupManagersParams query = Optional.ofNullable(params).orElse(new ListGroupManagersParams());
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"teamIds", Optional.ofNullable(query.getTeamIds()),
"orderBy", Optional.ofNullable(OrderByField.generateSortParam(query.getOrderBy()))
);
GroupManagerResponseList response = this.httpClient.get(this.url + "/groups/" + groupId + "/managers", new HttpRequestConfig(queryParams), GroupManagerResponseList.class);
return GroupManagerResponseList.to(response);
}
/**
* Update group managers. For Crowdin Enterprise only
* @param groupId group identifier
* @param request request object
* @return list of updated group managers
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.groups.managers.patch" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<GroupManager> updateGroupManagers(Long groupId, List<PatchRequest> request) throws HttpException, HttpBadRequestException {
GroupManagerResponseList response = this.httpClient.patch(this.url + "/groups/" + groupId + "/managers", request, new HttpRequestConfig(), GroupManagerResponseList.class);
return GroupManagerResponseList.to(response);
}
/**
* Get group manager. For Crowdin Enterprise only
* @param groupId group identifier
* @param userId user identifier
* @return group manager
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.groups.managers.get" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<GroupManager> getGroupManager(Long groupId, Long userId) throws HttpException, HttpBadRequestException {
GroupManagerResponseObject response = this.httpClient.get(this.url + "/groups/" + groupId + "/managers/" + userId, new HttpRequestConfig(), GroupManagerResponseObject.class);
return ResponseObject.of(response.getData());
}
/**
* List project members. For Crowdin Enterprise only
* @param projectId Project Identifier. Get via List Projects
* @param search Search users by firstName, lastName or username
* @param languageId Language Identifier. Get via Project Target Languages
* @param workflowStepId Workflow Step Identifier. Get via List Workflow Steps
* @param limit A maximum number of items to retrieve
* @param offset A starting offset in the collection
* @return list of project members
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.members.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<ProjectMember> listProjectMembersEnterprise(Long projectId, String search, String languageId, Long workflowStepId, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/members", this.url, projectId);
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"search", Optional.ofNullable(search),
"languageId", Optional.ofNullable(languageId),
"workflowStepId", Optional.ofNullable(workflowStepId),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
);
ProjectMemberResponseList response = this.httpClient.get(builtUrl, new HttpRequestConfig(queryParams), ProjectMemberResponseList.class);
return ProjectMemberResponseList.to(response);
}
/**
* List project members. For Crowdin Enterprise only
* @param projectId Project Identifier. Get via List Projects
* @param search Search users by firstName, lastName or username
* @param languageId Language Identifier. Get via Project Target Languages
* @param workflowStepId Workflow Step Identifier. Get via List Workflow Steps
* @param limit A maximum number of items to retrieve
* @param offset A starting offset in the collection
* @param orderBy list of OrderByField
* @return list of project members
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.members.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<ProjectMember> listProjectMembersEnterprise(Long projectId, String search, String languageId, Long workflowStepId, Integer limit, Integer offset, List<OrderByField> orderBy) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/members", this.url, projectId);
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"search", Optional.ofNullable(search),
"languageId", Optional.ofNullable(languageId),
"workflowStepId", Optional.ofNullable(workflowStepId),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset),
"orderBy", Optional.ofNullable(OrderByField.generateSortParam(orderBy))
);
ProjectMemberResponseList response = this.httpClient.get(builtUrl, new HttpRequestConfig(queryParams), ProjectMemberResponseList.class);
return ProjectMemberResponseList.to(response);
}
/**
* @param projectId project identifier
* @param request request object
* @return project team members response info
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.members.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ProjectMembersResponse addProjectMember(Long projectId, AddProjectMemberRequest request) throws HttpException, HttpBadRequestException {
return this.httpClient.post(this.url + "/projects/" + projectId + "/members", request, new HttpRequestConfig(), ProjectMembersResponse.class);
}
/**
* @param projectId project identifier
* @param memberId member identifier
* @return project member info
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.members.get" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<ProjectMember> getProjectMemberPermissions(Long projectId, Long memberId) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/members/%d", this.url, projectId, memberId);
ProjectMemberResponseObject response = this.httpClient.get(builtUrl, new HttpRequestConfig(), ProjectMemberResponseObject.class);
return ResponseObject.of(response.getData());
}
/**
* @param projectId project identifier
* @param memberId member identifier
* @param request request object
* @return updated project member info
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.members.put" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<ProjectMember> replaceProjectMemberPermissions(Long projectId, Long memberId, ReplaceProjectMemberPermissionsRequest request) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/members/%d", this.url, projectId, memberId);
ProjectMemberResponseObject response = this.httpClient.put(builtUrl, request, new HttpRequestConfig(), ProjectMemberResponseObject.class);
return ResponseObject.of(response.getData());
}
/**
* @param projectId project identifier
* @param memberId member identifier
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.projects.members.delete" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public void deleteMemberFromProject(Long projectId, Long memberId) throws HttpException, HttpBadRequestException {
String builtUrl = String.format("%s/projects/%d/members/%d", this.url, projectId, memberId);
this.httpClient.delete(builtUrl, new HttpRequestConfig(), Void.class);
}
/**
* @param status filter by status
* @param search search users by firstName, lastName, username, or email (2 or more characters)
* @param twoFactor filter by two-factor authentication status
* @param limit maximum number of items to retrieve (default 25)
* @param offset starting offset in the collection (default 0)
* @return list of users
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.users.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<User> listUsers(Status status, String search, TwoFactor twoFactor, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"status", Optional.ofNullable(status),
"search", Optional.ofNullable(search),
"twoFactor", Optional.ofNullable(twoFactor),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
);
UserResponseList userResponseList = this.httpClient.get(this.url + "/users", new HttpRequestConfig(queryParams), UserResponseList.class);
return UserResponseList.to(userResponseList);
}
/**
* @param status filter by status
* @param search search users by firstName, lastName, username, or email (2 or more characters)
* @param twoFactor filter by two-factor authentication status
* @param limit maximum number of items to retrieve (default 25)
* @param offset starting offset in the collection (default 0)
* @param orderBy list of OrderByField
* @return list of users
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.users.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<User> listUsers(Status status, String search, TwoFactor twoFactor, Integer limit, Integer offset, List<OrderByField> orderBy) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"status", Optional.ofNullable(status),
"search", Optional.ofNullable(search),
"twoFactor", Optional.ofNullable(twoFactor),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset),
"orderBy", Optional.ofNullable(OrderByField.generateSortParam(orderBy))
);
UserResponseList userResponseList = this.httpClient.get(this.url + "/users", new HttpRequestConfig(queryParams), UserResponseList.class);
return UserResponseList.to(userResponseList);
}
/**
* @param params ListUsersParams
* @return list of teams
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.users.getMany" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseList<User> listUsers(ListUsersParams params) throws HttpException, HttpBadRequestException {
ListUsersParams query = Optional.ofNullable(params).orElse(new ListUsersParams());
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"status", Optional.ofNullable(query.getStatus()),
"search", Optional.ofNullable(query.getSearch()),
"twoFactor", Optional.ofNullable(query.getTwoFactor()),
"limit", Optional.ofNullable(query.getLimit()),
"offset", Optional.ofNullable(query.getOffset()),
"orderBy", Optional.ofNullable(OrderByField.generateSortParam(query.getOrderBy())),
"organizationRoles", Optional.ofNullable(
query.getOrganizationRoles() == null ? null : query.getOrganizationRoles().stream()
.map(organizationRole -> organizationRole.to(organizationRole))
.collect(Collectors.joining(","))
),
"teamId", Optional.ofNullable(query.getTeamId()),
"projectIds", Optional.ofNullable(
query.getProjectIds() == null ? null : query.getProjectIds().stream()
.map(String::valueOf)
.collect(Collectors.joining(","))
),
"projectRoles", Optional.ofNullable(
query.getProjectRoles() == null ? null : query.getProjectRoles().stream()
.map(projectRole -> projectRole.to(projectRole))
.collect(Collectors.joining(","))
),
"languageIds", Optional.ofNullable(
query.getLanguageIds() == null ? null : String.join(",", query.getLanguageIds())
),
"groupIds", Optional.ofNullable(
query.getGroupIds() == null ? null : query.getGroupIds().stream()
.map(String::valueOf)
.collect(Collectors.joining(","))
),
"lastSeenFrom", Optional.ofNullable(query.getLastSeenFrom()),
"lastSeenTo", Optional.ofNullable(query.getLastSeenTo())
);
UserResponseList userResponseList = this.httpClient.get(this.url + "/users", new HttpRequestConfig(queryParams), UserResponseList.class);
return UserResponseList.to(userResponseList);
}
/**
* @param request request object
* @return invited user
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.users.post" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<User> inviteUser(InviteUserRequest request) throws HttpException, HttpBadRequestException {
UserResponseObject invitedUserResponseObject = this.httpClient.post(this.url + "/users", request, new HttpRequestConfig(), UserResponseObject.class);
return ResponseObject.of(invitedUserResponseObject.getData());
}
/**
* @param userId user identifier
* @return user
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.users.getById" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<User> getUser(Long userId) throws HttpException, HttpBadRequestException {
UserResponseObject languageResponseObject = this.httpClient.get(this.url + "/users/" + userId, new HttpRequestConfig(), UserResponseObject.class);
return ResponseObject.of(languageResponseObject.getData());
}
/**
* @param userId user identifier
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.users.delete" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public void deleteUser(Long userId) throws HttpException, HttpBadRequestException{
this.httpClient.delete(this.url + "/users/" + userId, new HttpRequestConfig(), Void.class);
}
/**
* @param userId user identifier
* @param request request object
* @return updated user
* @see <ul>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.users.patch" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<User> editUser(Long userId, List<PatchRequest> request) throws HttpException, HttpBadRequestException {
UserResponseObject editedUserResponseObject = this.httpClient.patch(this.url + "/users/" + userId, request, new HttpRequestConfig(), UserResponseObject.class);
return ResponseObject.of(editedUserResponseObject.getData());
}
/**
* @return current authenticated user
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.user.get" target="_blank"><b>API Documentation</b></a></li>
* <li><a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.user.get" target="_blank"><b>Enterprise API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<User> getAuthenticatedUser() throws HttpException, HttpBadRequestException {
UserResponseObject languageResponseObject = this.httpClient.get(this.url + "/user", new HttpRequestConfig(), UserResponseObject.class);
return ResponseObject.of(languageResponseObject.getData());
}
/**
* @param projectId project identifier
* @param search search users by firstName, lastName, username, or email (2 or more characters)
* @param limit maximum number of items to retrieve (default 25)
* @param offset starting offset in the collection (default 0)
* @return list of team members
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.members.getMany" target="_blank"><b>API Documentation</b></a></li>
* </ul>
*/
public ResponseList<TeamMember> listProjectMembers(Long projectId, String search, Integer limit, Integer offset) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"search", Optional.ofNullable(search),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset)
);
TeamMemberResponseList teamMemberResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/members", new HttpRequestConfig(queryParams), TeamMemberResponseList.class);
return TeamMemberResponseList.to(teamMemberResponseList);
}
/**
* @param projectId project identifier
* @param search search users by firstName, lastName, username, or email (2 or more characters)
* @param limit maximum number of items to retrieve (default 25)
* @param offset starting offset in the collection (default 0)
* @param orderBy list of OrderByField
* @return list of team members
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.members.getMany" target="_blank"><b>API Documentation</b></a></li>
* </ul>
*/
public ResponseList<TeamMember> listProjectMembers(Long projectId, String search, Integer limit, Integer offset, List<OrderByField> orderBy) throws HttpException, HttpBadRequestException {
Map<String, Optional<Object>> queryParams = HttpRequestConfig.buildUrlParams(
"search", Optional.ofNullable(search),
"limit", Optional.ofNullable(limit),
"offset", Optional.ofNullable(offset),
"orderBy", Optional.ofNullable(OrderByField.generateSortParam(orderBy))
);
TeamMemberResponseList teamMemberResponseList = this.httpClient.get(this.url + "/projects/" + projectId + "/members", new HttpRequestConfig(queryParams), TeamMemberResponseList.class);
return TeamMemberResponseList.to(teamMemberResponseList);
}
/**
* @param projectId project identifier
* @param memberId member identifier
* @return team member
* @see <ul>
* <li><a href="https://developer.crowdin.com/api/v2/#operation/api.projects.members.get" target="_blank"><b>API Documentation</b></a></li>
* </ul>
*/
public ResponseObject<TeamMember> getMemberInfo(Long projectId, Long memberId) throws HttpException, HttpBadRequestException {
TeamMemberResponseObject teamMemberResponseObject = this.httpClient.get(this.url + "/projects/" + projectId + "/members/" + memberId, new HttpRequestConfig(), TeamMemberResponseObject.class);
return ResponseObject.of(teamMemberResponseObject.getData());
}
}