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