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