001package com.box.sdk;
002
003import java.util.Date;
004
005import com.eclipsesource.json.JsonObject;
006import com.eclipsesource.json.JsonValue;
007
008/**
009 * The abstract base class for types that can be added to collaborations.
010 */
011public abstract class BoxCollaborator extends BoxResource {
012
013    /**
014     * Constructs a BoxCollaborator for a collaborator with a given ID.
015     * @param  api the API connection to be used by the collaborator.
016     * @param  id  the ID of the collaborator.
017     */
018    public BoxCollaborator(BoxAPIConnection api, String id) {
019        super(api, id);
020    }
021
022    /**
023     * Contains information about a BoxCollaborator.
024     */
025    public abstract class Info extends BoxResource.Info {
026        private String name;
027        private Date createdAt;
028        private Date modifiedAt;
029        private String login;
030
031        /**
032         * Constructs an empty Info object.
033         */
034        public Info() {
035            super();
036        }
037
038        /**
039         * Constructs an Info object by parsing information from a JSON string.
040         * @param  json the JSON string to parse.
041         */
042        public Info(String json) {
043            super(json);
044        }
045
046        /**
047         * Constructs an Info object using an already parsed JSON object.
048         * @param  jsonObject the parsed JSON object.
049         */
050        Info(JsonObject jsonObject) {
051            super(jsonObject);
052        }
053
054        /**
055         * Gets the name of the collaborator.
056         * @return the name of the collaborator.
057         */
058        public String getName() {
059            return this.name;
060        }
061
062        /**
063         * Sets the name of the collaborator.
064         * @param name the new name of the collaborator.
065         */
066        public void setName(String name) {
067            this.name = name;
068            this.addPendingChange("name", name);
069        }
070
071        /**
072         * Gets the date that the collaborator was created.
073         * @return the date that the collaborator was created.
074         */
075        public Date getCreatedAt() {
076            return this.createdAt;
077        }
078
079        /**
080         * Gets the date that the collaborator was modified.
081         * @return the date that the collaborator was modified.
082         */
083        public Date getModifiedAt() {
084            return this.modifiedAt;
085        }
086
087        /**
088         * Gets the login for the collaborator.
089         * @return the login of the collaboraor.
090         */
091        public String getLogin() {
092            return this.login;
093        }
094
095        @Override
096        protected void parseJSONMember(JsonObject.Member member) {
097            super.parseJSONMember(member);
098            JsonValue value = member.getValue();
099            String name = member.getName();
100
101            try {
102
103                if (name.equals("name")) {
104                    this.name = value.asString();
105                } else if (name.equals("created_at")) {
106                    this.createdAt = BoxDateFormat.parse(value.asString());
107                } else if (name.equals("modified_at")) {
108                    this.modifiedAt = BoxDateFormat.parse(value.asString());
109                } else if (name.equals("login")) {
110                    this.login = value.asString();
111                }
112            } catch (Exception e) {
113                throw new BoxDeserializationException(name, value.toString(), e);
114            }
115        }
116    }
117}