001package com.box.sdk; 002 003import java.net.URL; 004import java.util.ArrayList; 005import java.util.Collection; 006import java.util.Iterator; 007import java.util.List; 008 009import com.eclipsesource.json.JsonArray; 010import com.eclipsesource.json.JsonObject; 011import com.eclipsesource.json.JsonValue; 012 013/** 014 * Represents a Box user account. 015 * 016 * <p>Unless otherwise noted, the methods in this class can throw an unchecked {@link BoxAPIException} (unchecked 017 * meaning that the compiler won't force you to handle it) if an error occurs. If you wish to implement custom error 018 * handling for errors related to the Box REST API, you should capture this exception explicitly.</p> 019 */ 020@BoxResourceType("user") 021public class BoxUser extends BoxCollaborator { 022 023 /** 024 * An array of all possible file fields that can be requested when calling {@link #getInfo(String...)}. 025 */ 026 public static final String[] ALL_FIELDS = {"type", "id", "name", "login", "created_at", "modified_at", "role", 027 "language", "timezone", "space_amount", "space_used", "max_upload_size", "tracking_codes", 028 "can_see_managed_users", "is_sync_enabled", "is_external_collab_restricted", "status", "job_title", "phone", 029 "address", "avatar_url", "is_exempt_from_device_limits", "is_exempt_from_login_verification", "enterprise", 030 "my_tags", "hostname", "is_platform_access_only", "external_app_user_id"}; 031 032 /** 033 * User URL Template. 034 */ 035 public static final URLTemplate USER_URL_TEMPLATE = new URLTemplate("users/%s"); 036 /** 037 * Get Me URL Template. 038 */ 039 public static final URLTemplate GET_ME_URL = new URLTemplate("users/me"); 040 /** 041 * Users URL Template. 042 */ 043 public static final URLTemplate USERS_URL_TEMPLATE = new URLTemplate("users"); 044 /** 045 * User Memberships URL Template. 046 */ 047 public static final URLTemplate USER_MEMBERSHIPS_URL_TEMPLATE = new URLTemplate("users/%s/memberships"); 048 /** 049 * E-Mail Alias URL Template. 050 */ 051 public static final URLTemplate EMAIL_ALIAS_URL_TEMPLATE = new URLTemplate("users/%s/email_aliases/%s"); 052 /** 053 * E-Mail Aliases URL Template. 054 */ 055 public static final URLTemplate EMAIL_ALIASES_URL_TEMPLATE = new URLTemplate("users/%s/email_aliases"); 056 /** 057 * Move Folder To User Template. 058 */ 059 public static final URLTemplate MOVE_FOLDER_TO_USER_TEMPLATE = new URLTemplate("users/%s/folders/%s"); 060 061 /** 062 * Constructs a BoxUser for a user with a given ID. 063 * @param api the API connection to be used by the user. 064 * @param id the ID of the user. 065 */ 066 public BoxUser(BoxAPIConnection api, String id) { 067 super(api, id); 068 } 069 070 /** 071 * Provisions a new app user in an enterprise using Box Developer Edition. 072 * @param api the API connection to be used by the created user. 073 * @param name the name of the user. 074 * @return the created user's info. 075 */ 076 public static BoxUser.Info createAppUser(BoxAPIConnection api, String name) { 077 return createAppUser(api, name, new CreateUserParams()); 078 } 079 080 /** 081 * Provisions a new app user in an enterprise with additional user information using Box Developer Edition. 082 * @param api the API connection to be used by the created user. 083 * @param name the name of the user. 084 * @param params additional user information. 085 * @return the created user's info. 086 */ 087 public static BoxUser.Info createAppUser(BoxAPIConnection api, String name, 088 CreateUserParams params) { 089 090 params.setIsPlatformAccessOnly(true); 091 return createEnterpriseUser(api, null, name, params); 092 } 093 094 /** 095 * Provisions a new user in an enterprise. 096 * @param api the API connection to be used by the created user. 097 * @param login the email address the user will use to login. 098 * @param name the name of the user. 099 * @return the created user's info. 100 */ 101 public static BoxUser.Info createEnterpriseUser(BoxAPIConnection api, String login, String name) { 102 return createEnterpriseUser(api, login, name, null); 103 } 104 105 /** 106 * Provisions a new user in an enterprise with additional user information. 107 * @param api the API connection to be used by the created user. 108 * @param login the email address the user will use to login. 109 * @param name the name of the user. 110 * @param params additional user information. 111 * @return the created user's info. 112 */ 113 public static BoxUser.Info createEnterpriseUser(BoxAPIConnection api, String login, String name, 114 CreateUserParams params) { 115 116 JsonObject requestJSON = new JsonObject(); 117 requestJSON.add("login", login); 118 requestJSON.add("name", name); 119 120 if (params != null) { 121 if (params.getRole() != null) { 122 requestJSON.add("role", params.getRole().toJSONValue()); 123 } 124 125 if (params.getStatus() != null) { 126 requestJSON.add("status", params.getStatus().toJSONValue()); 127 } 128 129 requestJSON.add("language", params.getLanguage()); 130 requestJSON.add("is_sync_enabled", params.getIsSyncEnabled()); 131 requestJSON.add("job_title", params.getJobTitle()); 132 requestJSON.add("phone", params.getPhone()); 133 requestJSON.add("address", params.getAddress()); 134 requestJSON.add("space_amount", params.getSpaceAmount()); 135 requestJSON.add("can_see_managed_users", params.getCanSeeManagedUsers()); 136 requestJSON.add("timezone", params.getTimezone()); 137 requestJSON.add("is_exempt_from_device_limits", params.getIsExemptFromDeviceLimits()); 138 requestJSON.add("is_exempt_from_login_verification", params.getIsExemptFromLoginVerification()); 139 requestJSON.add("is_platform_access_only", params.getIsPlatformAccessOnly()); 140 requestJSON.add("external_app_user_id", params.getExternalAppUserId()); 141 } 142 143 URL url = USERS_URL_TEMPLATE.build(api.getBaseURL()); 144 BoxJSONRequest request = new BoxJSONRequest(api, url, "POST"); 145 request.setBody(requestJSON.toString()); 146 BoxJSONResponse response = (BoxJSONResponse) request.send(); 147 JsonObject responseJSON = JsonObject.readFrom(response.getJSON()); 148 149 BoxUser createdUser = new BoxUser(api, responseJSON.get("id").asString()); 150 return createdUser.new Info(responseJSON); 151 } 152 153 /** 154 * Gets the current user. 155 * @param api the API connection of the current user. 156 * @return the current user. 157 */ 158 public static BoxUser getCurrentUser(BoxAPIConnection api) { 159 URL url = GET_ME_URL.build(api.getBaseURL()); 160 BoxAPIRequest request = new BoxAPIRequest(api, url, "GET"); 161 BoxJSONResponse response = (BoxJSONResponse) request.send(); 162 JsonObject jsonObject = JsonObject.readFrom(response.getJSON()); 163 return new BoxUser(api, jsonObject.get("id").asString()); 164 } 165 166 /** 167 * Returns an iterable containing all the enterprise users. 168 * @param api the API connection to be used when retrieving the users. 169 * @return an iterable containing all the enterprise users. 170 */ 171 public static Iterable<BoxUser.Info> getAllEnterpriseUsers(final BoxAPIConnection api) { 172 return getAllEnterpriseUsers(api, null); 173 } 174 175 /** 176 * Returns an iterable containing all the enterprise users that matches the filter and specifies which child fields 177 * to retrieve from the API. 178 * @param api the API connection to be used when retrieving the users. 179 * @param filterTerm used to filter the results to only users starting with this string in either the name or the 180 * login. Can be null to not filter the results. 181 * @param fields the fields to retrieve. Leave this out for the standard fields. 182 * @return an iterable containing all the enterprise users that matches the filter. 183 */ 184 public static Iterable<BoxUser.Info> getAllEnterpriseUsers(final BoxAPIConnection api, final String filterTerm, 185 final String... fields) { 186 return getUsersInfoForType(api, filterTerm, null, null, fields); 187 } 188 189 /** 190 * Gets a limited set of information about an external user. (A user collaborating 191 * on content owned by the enterprise). Note: Only fields the user has permission to 192 * see will be returned with values. Other fields will return a value of null. 193 * @param api the API connection to be used when retrieving the users. 194 * @param filterTerm used to filter the results to only users matching the given login. 195 * This does exact match only, so if no filter term is passed in, nothing 196 * will be returned. 197 * @param fields the fields to retrieve. Leave this out for the standard fields. 198 * @return an iterable containing external users matching the given email 199 */ 200 public static Iterable<BoxUser.Info> getExternalUsers(final BoxAPIConnection api, final String filterTerm, 201 final String... fields) { 202 return getUsersInfoForType(api, filterTerm, "external", null, fields); 203 } 204 205 /** 206 * Gets any managed users that match the filter term as well as any external users that 207 * match the filter term. For managed users it matches any users names or emails that 208 * start with the term. For external, it only does full match on email. This method 209 * is ideal to use in the case where you have a full email for a user and you don't 210 * know if they're managed or external. 211 * @param api the API connection to be used when retrieving the users. 212 * @param filterTerm The filter term to lookup users by (login for external, login or name for managed) 213 * @param fields the fields to retrieve. Leave this out for the standard fields. 214 * @return an iterable containing users matching the given email 215 */ 216 public static Iterable<BoxUser.Info> getAllEnterpriseOrExternalUsers(final BoxAPIConnection api, 217 final String filterTerm, final String... fields) { 218 return getUsersInfoForType(api, filterTerm, "all", null, fields); 219 } 220 221 /** 222 * Gets any app users that has an exact match with the externalAppUserId term. 223 * @param api the API connection to be used when retrieving the users. 224 * @param externalAppUserId the external app user id that has been set for app user 225 * @param fields the fields to retrieve. Leave this out for the standard fields. 226 * @return an iterable containing users matching the given email 227 */ 228 public static Iterable<BoxUser.Info> getAppUsersByExternalAppUserID(final BoxAPIConnection api, 229 final String externalAppUserId, final String... fields) { 230 return getUsersInfoForType(api, null, null, externalAppUserId, fields); 231 } 232 233 /** 234 * Helper method to abstract out the common logic from the various users methods. 235 * 236 * @param api the API connection to be used when retrieving the users. 237 * @param filterTerm The filter term to lookup users by (login for external, login or name for managed) 238 * @param userType The type of users we want to search with this request. 239 * Valid values are 'managed' (enterprise users), 'external' or 'all' 240 * @param externalAppUserId the external app user id that has been set for an app user 241 * @param fields the fields to retrieve. Leave this out for the standard fields. 242 * @return An iterator over the selected users. 243 */ 244 private static Iterable<BoxUser.Info> getUsersInfoForType(final BoxAPIConnection api, 245 final String filterTerm, final String userType, final String externalAppUserId, final String... fields) { 246 return new Iterable<BoxUser.Info>() { 247 public Iterator<BoxUser.Info> iterator() { 248 QueryStringBuilder builder = new QueryStringBuilder(); 249 if (filterTerm != null) { 250 builder.appendParam("filter_term", filterTerm); 251 } 252 if (userType != null) { 253 builder.appendParam("user_type", userType); 254 } 255 if (externalAppUserId != null) { 256 builder.appendParam("external_app_user_id", externalAppUserId); 257 } 258 if (fields.length > 0) { 259 builder.appendParam("fields", fields); 260 } 261 URL url = USERS_URL_TEMPLATE.buildWithQuery(api.getBaseURL(), builder.toString()); 262 return new BoxUserIterator(api, url); 263 } 264 }; 265 } 266 267 /** 268 * Gets information about this user. 269 * @param fields the optional fields to retrieve. 270 * @return info about this user. 271 */ 272 public BoxUser.Info getInfo(String... fields) { 273 URL url; 274 if (fields.length > 0) { 275 String queryString = new QueryStringBuilder().appendParam("fields", fields).toString(); 276 url = USER_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), queryString, this.getID()); 277 } else { 278 url = USER_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); 279 } 280 BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET"); 281 BoxJSONResponse response = (BoxJSONResponse) request.send(); 282 JsonObject jsonObject = JsonObject.readFrom(response.getJSON()); 283 return new Info(jsonObject); 284 } 285 286 /** 287 * Gets information about all of the group memberships for this user. 288 * Does not support paging. 289 * 290 * <p>Note: This method is only available to enterprise admins.</p> 291 * 292 * @return a collection of information about the group memberships for this user. 293 */ 294 public Collection<BoxGroupMembership.Info> getMemberships() { 295 BoxAPIConnection api = this.getAPI(); 296 URL url = USER_MEMBERSHIPS_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); 297 298 BoxAPIRequest request = new BoxAPIRequest(api, url, "GET"); 299 BoxJSONResponse response = (BoxJSONResponse) request.send(); 300 JsonObject responseJSON = JsonObject.readFrom(response.getJSON()); 301 302 int entriesCount = responseJSON.get("total_count").asInt(); 303 Collection<BoxGroupMembership.Info> memberships = new ArrayList<BoxGroupMembership.Info>(entriesCount); 304 JsonArray entries = responseJSON.get("entries").asArray(); 305 for (JsonValue entry : entries) { 306 JsonObject entryObject = entry.asObject(); 307 BoxGroupMembership membership = new BoxGroupMembership(api, entryObject.get("id").asString()); 308 BoxGroupMembership.Info info = membership.new Info(entryObject); 309 memberships.add(info); 310 } 311 312 return memberships; 313 } 314 315 /** 316 * Gets information about all of the group memberships for this user as iterable with paging support. 317 * @param fields the fields to retrieve. 318 * @return an iterable with information about the group memberships for this user. 319 */ 320 public Iterable<BoxGroupMembership.Info> getAllMemberships(String ... fields) { 321 final QueryStringBuilder builder = new QueryStringBuilder(); 322 if (fields.length > 0) { 323 builder.appendParam("fields", fields); 324 } 325 return new Iterable<BoxGroupMembership.Info>() { 326 public Iterator<BoxGroupMembership.Info> iterator() { 327 URL url = USER_MEMBERSHIPS_URL_TEMPLATE.buildWithQuery( 328 BoxUser.this.getAPI().getBaseURL(), builder.toString(), BoxUser.this.getID()); 329 return new BoxGroupMembershipIterator(BoxUser.this.getAPI(), url); 330 } 331 }; 332 } 333 334 /** 335 * Adds a new email alias to this user's account. 336 * @param email the email address to add as an alias. 337 * @return the newly created email alias. 338 */ 339 public EmailAlias addEmailAlias(String email) { 340 URL url = EMAIL_ALIASES_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); 341 BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "POST"); 342 343 JsonObject requestJSON = new JsonObject() 344 .add("email", email); 345 request.setBody(requestJSON.toString()); 346 BoxJSONResponse response = (BoxJSONResponse) request.send(); 347 JsonObject responseJSON = JsonObject.readFrom(response.getJSON()); 348 return new EmailAlias(responseJSON); 349 } 350 351 /** 352 * Deletes an email alias from this user's account. 353 * 354 * <p>The IDs of the user's email aliases can be found by calling {@link #getEmailAliases}.</p> 355 * 356 * @param emailAliasID the ID of the email alias to delete. 357 */ 358 public void deleteEmailAlias(String emailAliasID) { 359 URL url = EMAIL_ALIAS_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID(), emailAliasID); 360 BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "DELETE"); 361 BoxAPIResponse response = request.send(); 362 response.disconnect(); 363 } 364 365 /** 366 * Gets a collection of all the email aliases for this user. 367 * 368 * <p>Note that the user's primary login email is not included in the collection of email aliases.</p> 369 * 370 * @return a collection of all the email aliases for this user. 371 */ 372 public Collection<EmailAlias> getEmailAliases() { 373 URL url = EMAIL_ALIASES_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); 374 BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET"); 375 BoxJSONResponse response = (BoxJSONResponse) request.send(); 376 JsonObject responseJSON = JsonObject.readFrom(response.getJSON()); 377 378 int totalCount = responseJSON.get("total_count").asInt(); 379 Collection<EmailAlias> emailAliases = new ArrayList<EmailAlias>(totalCount); 380 JsonArray entries = responseJSON.get("entries").asArray(); 381 for (JsonValue value : entries) { 382 JsonObject emailAliasJSON = value.asObject(); 383 emailAliases.add(new EmailAlias(emailAliasJSON)); 384 } 385 386 return emailAliases; 387 } 388 389 /** 390 * Deletes a user from an enterprise account. 391 * @param notifyUser whether or not to send an email notification to the user that their account has been deleted. 392 * @param force whether or not this user should be deleted even if they still own files. 393 */ 394 public void delete(boolean notifyUser, boolean force) { 395 String queryString = new QueryStringBuilder() 396 .appendParam("notify", String.valueOf(notifyUser)) 397 .appendParam("force", String.valueOf(force)) 398 .toString(); 399 400 URL url = USER_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), queryString, this.getID()); 401 BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "DELETE"); 402 BoxAPIResponse response = request.send(); 403 response.disconnect(); 404 } 405 406 /** 407 * Updates the information about this user with any info fields that have been modified locally. 408 * 409 * <p>Note: This method is only available to enterprise admins.</p> 410 * 411 * @param info info the updated info. 412 */ 413 public void updateInfo(BoxUser.Info info) { 414 URL url = USER_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID()); 415 BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "PUT"); 416 request.setBody(info.getPendingChanges()); 417 BoxJSONResponse response = (BoxJSONResponse) request.send(); 418 JsonObject jsonObject = JsonObject.readFrom(response.getJSON()); 419 info.update(jsonObject); 420 } 421 422 /** 423 * Moves all of the owned content from within one user’s folder into a new folder in another user's account. 424 * You can move folders across users as long as the you have administrative permissions and the 'source' 425 * user owns the folders. Per the documentation at the link below, this will move everything from the root 426 * folder, as this is currently the only mode of operation supported. 427 * 428 * See also https://box-content.readme.io/reference#move-folder-into-another-users-folder 429 * 430 * @param sourceUserID the user id of the user whose files will be the source for this operation 431 * @return info for the newly created folder 432 */ 433 public BoxFolder.Info moveFolderToUser(String sourceUserID) { 434 // Currently the API only supports moving of the root folder (0), hence the hard coded "0" 435 URL url = MOVE_FOLDER_TO_USER_TEMPLATE.build(this.getAPI().getBaseURL(), sourceUserID, "0"); 436 BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "PUT"); 437 JsonObject idValue = new JsonObject(); 438 idValue.add("id", this.getID()); 439 JsonObject ownedBy = new JsonObject(); 440 ownedBy.add("owned_by", idValue); 441 request.setBody(ownedBy.toString()); 442 BoxJSONResponse response = (BoxJSONResponse) request.send(); 443 JsonObject responseJSON = JsonObject.readFrom(response.getJSON()); 444 BoxFolder movedFolder = new BoxFolder(this.getAPI(), responseJSON.get("id").asString()); 445 446 return movedFolder.new Info(responseJSON); 447 } 448 449 /** 450 * Enumerates the possible roles that a user can have within an enterprise. 451 */ 452 public enum Role { 453 /** 454 * The user is an administrator of their enterprise. 455 */ 456 ADMIN ("admin"), 457 458 /** 459 * The user is a co-administrator of their enterprise. 460 */ 461 COADMIN ("coadmin"), 462 463 /** 464 * The user is a regular user within their enterprise. 465 */ 466 USER ("user"); 467 468 private final String jsonValue; 469 470 private Role(String jsonValue) { 471 this.jsonValue = jsonValue; 472 } 473 474 static Role fromJSONValue(String jsonValue) { 475 return Role.valueOf(jsonValue.toUpperCase()); 476 } 477 478 String toJSONValue() { 479 return this.jsonValue; 480 } 481 } 482 483 /** 484 * Enumerates the possible statuses that a user's account can have. 485 */ 486 public enum Status { 487 /** 488 * The user's account is active. 489 */ 490 ACTIVE ("active"), 491 492 /** 493 * The user's account is inactive. 494 */ 495 INACTIVE ("inactive"), 496 497 /** 498 * The user's account cannot delete or edit content. 499 */ 500 CANNOT_DELETE_EDIT ("cannot_delete_edit"), 501 502 /** 503 * The user's account cannot delete, edit, or upload content. 504 */ 505 CANNOT_DELETE_EDIT_UPLOAD ("cannot_delete_edit_upload"); 506 507 private final String jsonValue; 508 509 private Status(String jsonValue) { 510 this.jsonValue = jsonValue; 511 } 512 513 static Status fromJSONValue(String jsonValue) { 514 return Status.valueOf(jsonValue.toUpperCase()); 515 } 516 517 String toJSONValue() { 518 return this.jsonValue; 519 } 520 } 521 522 /** 523 * Contains information about a BoxUser. 524 */ 525 public class Info extends BoxCollaborator.Info { 526 private String login; 527 private Role role; 528 private String language; 529 private String timezone; 530 private long spaceAmount; 531 private long spaceUsed; 532 private long maxUploadSize; 533 private boolean canSeeManagedUsers; 534 private boolean isSyncEnabled; 535 private boolean isExternalCollabRestricted; 536 private Status status; 537 private String jobTitle; 538 private String phone; 539 private String address; 540 private String avatarURL; 541 private boolean isExemptFromDeviceLimits; 542 private boolean isExemptFromLoginVerification; 543 private boolean isPasswordResetRequired; 544 private boolean isPlatformAccessOnly; 545 private String externalAppUserId; 546 private BoxEnterprise enterprise; 547 private List<String> myTags; 548 private String hostname; 549 550 /** 551 * Constructs an empty Info object. 552 */ 553 public Info() { 554 super(); 555 } 556 557 Info(JsonObject jsonObject) { 558 super(jsonObject); 559 } 560 561 @Override 562 public BoxUser getResource() { 563 return BoxUser.this; 564 } 565 566 /** 567 * Gets the email address the user uses to login. 568 * @return the email address the user uses to login. 569 */ 570 public String getLogin() { 571 return this.login; 572 } 573 574 /** 575 * Sets the email address the user uses to login. The new login must be one of the user's already confirmed 576 * email aliases. 577 * @param login one of the user's confirmed email aliases. 578 */ 579 public void setLogin(String login) { 580 this.login = login; 581 this.addPendingChange("login", login); 582 } 583 584 /** 585 * Gets the user's enterprise role. 586 * @return the user's enterprise role. 587 */ 588 public Role getRole() { 589 return this.role; 590 } 591 592 /** 593 * Sets the user's role in their enterprise. 594 * @param role the user's new role in their enterprise. 595 */ 596 public void setRole(Role role) { 597 this.role = role; 598 this.addPendingChange("role", role.name().toLowerCase()); 599 } 600 601 /** 602 * Gets the language of the user. 603 * @return the language of the user. 604 */ 605 public String getLanguage() { 606 return this.language; 607 } 608 609 /** 610 * Sets the language of the user. 611 * @param language the new language of the user. 612 */ 613 public void setLanguage(String language) { 614 this.language = language; 615 this.addPendingChange("language", language); 616 } 617 618 /** 619 * Gets the timezone of the user. 620 * @return the timezone of the user. 621 */ 622 public String getTimezone() { 623 return this.timezone; 624 } 625 626 /** 627 * Sets the timezone of the user. 628 * @param timezone the new timezone of the user. 629 */ 630 public void setTimezone(String timezone) { 631 this.timezone = timezone; 632 this.addPendingChange("timezone", timezone); 633 } 634 635 /** 636 * Gets the user's total available space in bytes. 637 * @return the user's total available space in bytes. 638 */ 639 public long getSpaceAmount() { 640 return this.spaceAmount; 641 } 642 643 /** 644 * Sets the user's total available space in bytes. 645 * @param spaceAmount the new amount of space available to the user in bytes, or -1 for unlimited storage. 646 */ 647 public void setSpaceAmount(long spaceAmount) { 648 this.spaceAmount = spaceAmount; 649 this.addPendingChange("space_amount", spaceAmount); 650 } 651 652 /** 653 * Gets the amount of space the user has used in bytes. 654 * @return the amount of space the user has used in bytes. 655 */ 656 public long getSpaceUsed() { 657 return this.spaceUsed; 658 } 659 660 /** 661 * Gets the maximum individual file size in bytes the user can have. 662 * @return the maximum individual file size in bytes the user can have. 663 */ 664 public long getMaxUploadSize() { 665 return this.maxUploadSize; 666 } 667 668 /** 669 * Gets the user's current account status. 670 * @return the user's current account status. 671 */ 672 public Status getStatus() { 673 return this.status; 674 } 675 676 /** 677 * Sets the user's current account status. 678 * @param status the user's new account status. 679 */ 680 public void setStatus(Status status) { 681 this.status = status; 682 this.addPendingChange("status", status.name().toLowerCase()); 683 } 684 685 /** 686 * Gets the job title of the user. 687 * @return the job title of the user. 688 */ 689 public String getJobTitle() { 690 return this.jobTitle; 691 } 692 693 /** 694 * Sets the job title of the user. 695 * @param jobTitle the new job title of the user. 696 */ 697 public void setJobTitle(String jobTitle) { 698 this.jobTitle = jobTitle; 699 this.addPendingChange("job_title", jobTitle); 700 } 701 702 /** 703 * Gets the phone number of the user. 704 * @return the phone number of the user. 705 */ 706 public String getPhone() { 707 return this.phone; 708 } 709 710 /** 711 * Sets the phone number of the user. 712 * @param phone the new phone number of the user. 713 */ 714 public void setPhone(String phone) { 715 this.phone = phone; 716 this.addPendingChange("phone", phone); 717 } 718 719 /** 720 * Gets the address of the user. 721 * @return the address of the user. 722 */ 723 public String getAddress() { 724 return this.address; 725 } 726 727 /** 728 * Sets the address of the user. 729 * @param address the new address of the user. 730 */ 731 public void setAddress(String address) { 732 this.address = address; 733 this.addPendingChange("address", address); 734 } 735 736 /** 737 * Gets the URL of the user's avatar. 738 * @return the URL of the user's avatar. 739 */ 740 public String getAvatarURL() { 741 return this.avatarURL; 742 } 743 744 /** 745 * Gets the enterprise that the user belongs to. 746 * @return the enterprise that the user belongs to. 747 */ 748 public BoxEnterprise getEnterprise() { 749 return this.enterprise; 750 } 751 752 /** 753 * Removes the user from their enterprise and converts them to a standalone free user. 754 */ 755 public void removeEnterprise() { 756 this.removeChildObject("enterprise"); 757 this.enterprise = null; 758 this.addChildObject("enterprise", null); 759 } 760 761 /** 762 * Gets whether or not the user can use Box Sync. 763 * @return true if the user can use Box Sync; otherwise false. 764 */ 765 public boolean getIsSyncEnabled() { 766 return this.isSyncEnabled; 767 } 768 769 /** 770 * Gets whether this user is allowed to collaborate with users outside their enterprise. 771 * @return true if this user is allowed to collaborate with users outside their enterprise; otherwise false. 772 */ 773 public boolean getIsExternalCollabRestricted() { 774 return this.isExternalCollabRestricted; 775 } 776 777 /** 778 * Sets whether or not the user can use Box Sync. 779 * @param enabled whether or not the user can use Box Sync. 780 */ 781 public void setIsSyncEnabled(boolean enabled) { 782 this.isSyncEnabled = enabled; 783 this.addPendingChange("is_sync_enabled", enabled); 784 } 785 786 /** 787 * Gets whether or not the user can see other enterprise users in their contact list. 788 * @return true if the user can see other enterprise users in their contact list; otherwise false. 789 */ 790 public boolean getCanSeeManagedUsers() { 791 return this.canSeeManagedUsers; 792 } 793 794 /** 795 * Sets whether or not the user can see other enterprise users in their contact list. 796 * @param canSeeManagedUsers whether or not the user can see other enterprise users in their contact list. 797 */ 798 public void setCanSeeManagedUsers(boolean canSeeManagedUsers) { 799 this.canSeeManagedUsers = canSeeManagedUsers; 800 this.addPendingChange("can_see_managed_users", canSeeManagedUsers); 801 } 802 803 /** 804 * Gets whether or not the user is exempt from enterprise device limits. 805 * @return true if the user is exempt from enterprise device limits; otherwise false. 806 */ 807 public boolean getIsExemptFromDeviceLimits() { 808 return this.isExemptFromDeviceLimits; 809 } 810 811 /** 812 * Sets whether or not the user is exempt from enterprise device limits. 813 * @param isExemptFromDeviceLimits whether or not the user is exempt from enterprise device limits. 814 */ 815 public void setIsExemptFromDeviceLimits(boolean isExemptFromDeviceLimits) { 816 this.isExemptFromDeviceLimits = isExemptFromDeviceLimits; 817 this.addPendingChange("is_exempt_from_device_limits", isExemptFromDeviceLimits); 818 } 819 820 /** 821 * Gets whether or not the user must use two-factor authentication. 822 * @return true if the user must use two-factor authentication; otherwise false. 823 */ 824 public boolean getIsExemptFromLoginVerification() { 825 return this.isExemptFromLoginVerification; 826 } 827 828 /** 829 * Sets whether or not the user must use two-factor authentication. 830 * @param isExemptFromLoginVerification whether or not the user must use two-factor authentication. 831 */ 832 public void setIsExemptFromLoginVerification(boolean isExemptFromLoginVerification) { 833 this.isExemptFromLoginVerification = isExemptFromLoginVerification; 834 this.addPendingChange("is_exempt_from_login_verification", isExemptFromLoginVerification); 835 } 836 837 /** 838 * Gets whether or not the user is required to reset password. 839 * @return true if the user is required to reset password; otherwise false. 840 */ 841 public boolean getIsPasswordResetRequired() { 842 return this.isPasswordResetRequired; 843 } 844 845 /** 846 * Sets whether or not the user is required to reset password. 847 * @param isPasswordResetRequired whether or not the user is required to reset password. 848 */ 849 public void setIsPasswordResetRequired(boolean isPasswordResetRequired) { 850 this.isPasswordResetRequired = isPasswordResetRequired; 851 this.addPendingChange("is_password_reset_required", isPasswordResetRequired); 852 } 853 854 /** 855 * Gets whether or not the user we are creating is an app user with Box Developer Edition. 856 * @return true if the new user is an app user for Box Developer Addition; otherwise false. 857 */ 858 public boolean getIsPlatformAccessOnly() { 859 return this.isPlatformAccessOnly; 860 } 861 862 /** 863 * Gets the external app user id that has been set for the app user. 864 * @return the external app user id. 865 */ 866 public String getExternalAppUserId() { 867 return this.externalAppUserId; 868 } 869 870 /** 871 * Sets the external app user id. 872 * @param externalAppUserId external app user id. 873 */ 874 public void setExternalAppUserId(String externalAppUserId) { 875 this.externalAppUserId = externalAppUserId; 876 this.addPendingChange("external_app_user_id", externalAppUserId); 877 } 878 879 /** 880 * Gets the tags for all files and folders owned by this user. 881 * @return the tags for all files and folders owned by this user. 882 */ 883 public List<String> getMyTags() { 884 return this.myTags; 885 } 886 887 /** 888 * Gets the root (protocol, subdomain, domain) of any links that need to be generated for this user. 889 * @return the root (protocol, subdomain, domain) of any links that need to be generated for this user. 890 */ 891 public String getHostname() { 892 return this.hostname; 893 } 894 895 @Override 896 protected void parseJSONMember(JsonObject.Member member) { 897 super.parseJSONMember(member); 898 899 JsonValue value = member.getValue(); 900 String memberName = member.getName(); 901 if (memberName.equals("login")) { 902 this.login = value.asString(); 903 } else if (memberName.equals("role")) { 904 this.role = Role.fromJSONValue(value.asString()); 905 } else if (memberName.equals("language")) { 906 this.language = value.asString(); 907 } else if (memberName.equals("timezone")) { 908 this.timezone = value.asString(); 909 } else if (memberName.equals("space_amount")) { 910 this.spaceAmount = Double.valueOf(value.toString()).longValue(); 911 } else if (memberName.equals("space_used")) { 912 this.spaceUsed = Double.valueOf(value.toString()).longValue(); 913 } else if (memberName.equals("max_upload_size")) { 914 this.maxUploadSize = Double.valueOf(value.toString()).longValue(); 915 } else if (memberName.equals("status")) { 916 this.status = Status.fromJSONValue(value.asString()); 917 } else if (memberName.equals("job_title")) { 918 this.jobTitle = value.asString(); 919 } else if (memberName.equals("phone")) { 920 this.phone = value.asString(); 921 } else if (memberName.equals("address")) { 922 this.address = value.asString(); 923 } else if (memberName.equals("avatar_url")) { 924 this.avatarURL = value.asString(); 925 } else if (memberName.equals("can_see_managed_users")) { 926 this.canSeeManagedUsers = value.asBoolean(); 927 } else if (memberName.equals("is_sync_enabled")) { 928 this.isSyncEnabled = value.asBoolean(); 929 } else if (memberName.equals("is_external_collab_restricted")) { 930 this.isExternalCollabRestricted = value.asBoolean(); 931 } else if (memberName.equals("is_exempt_from_device_limits")) { 932 this.isExemptFromDeviceLimits = value.asBoolean(); 933 } else if (memberName.equals("is_exempt_from_login_verification")) { 934 this.isExemptFromLoginVerification = value.asBoolean(); 935 } else if (memberName.equals("is_password_reset_required")) { 936 this.isPasswordResetRequired = value.asBoolean(); 937 } else if (memberName.equals("is_platform_access_only")) { 938 this.isPlatformAccessOnly = value.asBoolean(); 939 } else if (memberName.equals("external_app_user_id")) { 940 this.externalAppUserId = value.asString(); 941 } else if (memberName.equals("enterprise")) { 942 JsonObject jsonObject = value.asObject(); 943 if (this.enterprise == null) { 944 this.enterprise = new BoxEnterprise(jsonObject); 945 } else { 946 this.enterprise.update(jsonObject); 947 } 948 } else if (memberName.equals("my_tags")) { 949 this.myTags = this.parseMyTags(value.asArray()); 950 } else if (memberName.equals("hostname")) { 951 this.hostname = value.asString(); 952 } 953 } 954 955 private List<String> parseMyTags(JsonArray jsonArray) { 956 List<String> myTags = new ArrayList<String>(jsonArray.size()); 957 for (JsonValue value : jsonArray) { 958 myTags.add(value.asString()); 959 } 960 961 return myTags; 962 } 963 } 964}