|
11 | 11 | import java.util.UUID; |
12 | 12 |
|
13 | 13 | public class AddActiveUserService { |
14 | | - // ds-snippet-start:Admin1Step5 |
15 | | - public static NewUserResponse createNewActiveUser( |
16 | | - String groupId, |
17 | | - String profileId, |
18 | | - String email, |
19 | | - String userName, |
20 | | - String firstName, |
21 | | - String lastName, |
22 | | - UsersApi usersApi, |
23 | | - UUID organizationId, |
24 | | - UUID accountId) throws Exception { |
25 | | - java.util.List<GroupRequest> groups = new ArrayList<>(); |
26 | | - groups.add(new GroupRequest().id(Long.valueOf(groupId))); |
27 | | - |
28 | | - // Fill the request with data from the form |
29 | | - NewUserRequest accountUserRequest = new NewUserRequest() |
30 | | - .defaultAccountId(accountId) |
31 | | - .addAccountsItem( |
32 | | - new NewUserRequestAccountProperties() |
33 | | - .id(accountId) |
34 | | - .permissionProfile( |
35 | | - new PermissionProfileRequest() |
36 | | - .id(Long.valueOf( |
37 | | - profileId))) |
38 | | - .groups(groups)) |
39 | | - .email(email) |
40 | | - .userName(userName) |
41 | | - .firstName(firstName) |
42 | | - .lastName(lastName) |
43 | | - .autoActivateMemberships(true); |
44 | | - // ds-snippet-end:Admin1Step5 |
45 | | - |
46 | | - // ds-snippet-start:Admin1Step6 |
47 | | - ApiResponse<NewUserResponse> response = usersApi.createUserWithHttpInfo(organizationId, |
48 | | - accountUserRequest); |
49 | | - |
50 | | - Map<String, List<String>> headers = response.getHeaders(); |
51 | | - List<String> remaining = headers.get("X-RateLimit-Remaining"); |
52 | | - List<String> reset = headers.get("X-RateLimit-Reset"); |
53 | | - |
54 | | - if (remaining != null & reset != null) { |
55 | | - Instant resetInstant = Instant.ofEpochSecond(Long.parseLong(reset.get(0))); |
56 | | - System.out.println("API calls remaining: " + remaining); |
57 | | - System.out.println("Next Reset: " + resetInstant); |
58 | | - } |
59 | | - |
60 | | - return response.getData(); |
61 | | - // ds-snippet-end:Admin1Step6 |
62 | | - } |
| 14 | + //ds-snippet-start:Admin1Step5 |
| 15 | + public static NewUserResponse createNewActiveUser( |
| 16 | + String groupId, |
| 17 | + String profileId, |
| 18 | + String email, |
| 19 | + String userName, |
| 20 | + String firstName, |
| 21 | + String lastName, |
| 22 | + UsersApi usersApi, |
| 23 | + UUID organizationId, |
| 24 | + UUID accountId) throws Exception { |
| 25 | + java.util.List<GroupRequest> groups = new ArrayList<>(); |
| 26 | + groups.add(new GroupRequest().id(Long.valueOf(groupId))); |
| 27 | + |
| 28 | + // Fill the request with data from the form |
| 29 | + NewUserRequest accountUserRequest = new NewUserRequest() |
| 30 | + .defaultAccountId(accountId) |
| 31 | + .addAccountsItem( |
| 32 | + new NewUserRequestAccountProperties() |
| 33 | + .id(accountId) |
| 34 | + .permissionProfile( |
| 35 | + new PermissionProfileRequest() |
| 36 | + .id(Long.valueOf( |
| 37 | + profileId))) |
| 38 | + .groups(groups)) |
| 39 | + .email(email) |
| 40 | + .userName(userName) |
| 41 | + .firstName(firstName) |
| 42 | + .lastName(lastName) |
| 43 | + .autoActivateMemberships(true); |
| 44 | + //ds-snippet-end:Admin1Step5 |
| 45 | + |
| 46 | + //ds-snippet-start:Admin1Step6 |
| 47 | + ApiResponse<NewUserResponse> response = usersApi.createUserWithHttpInfo(organizationId, |
| 48 | + accountUserRequest); |
| 49 | + |
| 50 | + Map<String, List<String>> headers = response.getHeaders(); |
| 51 | + List<String> remaining = headers.get("X-RateLimit-Remaining"); |
| 52 | + List<String> reset = headers.get("X-RateLimit-Reset"); |
| 53 | + |
| 54 | + if (remaining != null & reset != null) { |
| 55 | + Instant resetInstant = Instant.ofEpochSecond(Long.parseLong(reset.get(0))); |
| 56 | + System.out.println("API calls remaining: " + remaining); |
| 57 | + System.out.println("Next Reset: " + resetInstant); |
| 58 | + } |
| 59 | + |
| 60 | + return response.getData(); |
| 61 | + //ds-snippet-end:Admin1Step6 |
| 62 | + } |
63 | 63 | } |
0 commit comments