001package org.nuxeo.box.api.marshalling.dao;
002
003import com.fasterxml.jackson.annotation.JsonInclude;
004import com.fasterxml.jackson.annotation.JsonProperty;
005import com.fasterxml.jackson.annotation.JsonTypeInfo;
006import org.nuxeo.box.api.utils.ISO8601DateParser;
007
008import java.text.ParseException;
009import java.util.Date;
010import java.util.Map;
011
012/**
013 * Data for collaboration.
014 */
015@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", defaultImpl = BoxCollaboration.class)
016public class BoxCollaboration extends BoxTypedObject {
017
018    public static final String FIELD_CREATED_BY = "created_by";
019
020    public static final String FIELD_EXPIRES_AT = "expires_at";
021
022    public static final String FIELD_ACCESSIBLE_BY = "accessible_by";
023
024    public static final String FIELD_STATUS = "status";
025
026    public static final String FIELD_ACKNOWLEGED_AT = "acknowledged_at";
027
028    public static final String FIELD_FOLDER = "item";
029
030    public static final String FIELD_ROLE = "role";
031
032    /**
033     * Collaboration invitation is accepted.
034     */
035    public static final String STATUS_ACCEPTED = "accepted";
036
037    /**
038     * Collaboration invitation is pending.
039     */
040    public static final String STATUS_PENDING = "pending";
041
042    /**
043     * Collaboration invitation is rejected.
044     */
045    public static final String STATUS_REJECTED = "rejected";
046
047    /**
048     * Constructor.
049     */
050    public BoxCollaboration() {
051        setType(BoxResourceType.COLLABORATION.toString());
052    }
053
054    /**
055     * Copy constructor, this does deep copy for all the fields.
056     *
057     * @param obj
058     */
059    public BoxCollaboration(BoxCollaboration obj) {
060        super(obj);
061    }
062
063    /**
064     * Instantiate the object from a map. Each entry in the map reflects to a field.
065     *
066     * @param map
067     */
068    public BoxCollaboration(Map<String, Object> map) {
069        super(map);
070    }
071
072    /**
073     * Get the user creating this collaboration.
074     *
075     * @return the created_by
076     */
077    @JsonInclude(JsonInclude.Include.ALWAYS)
078    @JsonProperty(FIELD_CREATED_BY)
079    public BoxUser getCreatedBy() {
080        return (BoxUser) getValue(FIELD_CREATED_BY);
081    }
082
083    /**
084     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}.
085     *
086     * @param createdBy the created_by to set
087     */
088    @JsonProperty(FIELD_CREATED_BY)
089    private void setCreatedBy(BoxUser createdBy) {
090        put(FIELD_CREATED_BY, createdBy);
091    }
092
093    /**
094     * Get the user this collaboration applies to.
095     *
096     * @return the accessible_by
097     */
098    @JsonInclude(JsonInclude.Include.ALWAYS)
099    @JsonProperty(FIELD_ACCESSIBLE_BY)
100    public BoxUser getAccessibleBy() {
101        return (BoxUser) getValue(FIELD_ACCESSIBLE_BY);
102    }
103
104    /**
105     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}.
106     *
107     * @param accessibleBy the accessible_by to set
108     */
109    @JsonProperty(FIELD_ACCESSIBLE_BY)
110    private void setAccessibleBy(BoxUser accessibleBy) {
111        put(FIELD_ACCESSIBLE_BY, accessibleBy);
112    }
113
114    /**
115     * Get the time this collaboration expires. This returns a String and can be parsed into {@link java.util.Date} by
116     *
117     * @return the expires_at
118     */
119    @JsonInclude(JsonInclude.Include.ALWAYS)
120    @JsonProperty(FIELD_EXPIRES_AT)
121    public String getExpiresAt() {
122        return (String) getValue(FIELD_EXPIRES_AT);
123    }
124
125    /**
126     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}.
127     *
128     * @param expiresAt the expires_at to set
129     */
130    @JsonProperty(FIELD_EXPIRES_AT)
131    private void setExpiresAt(String expiresAt) {
132        put(FIELD_EXPIRES_AT, expiresAt);
133    }
134
135    /**
136     * Get the time this collaboration expires.
137     *
138     * @return Date representation of the expires_at value. Null if there was no expires_at or if it could not be parsed
139     *         as an ISO8601 date.
140     * @throws java.text.ParseException
141     */
142    public Date dateExpiresAt() throws ParseException {
143        return ISO8601DateParser.parseSilently(getExpiresAt());
144    }
145
146    /**
147     * Get the status of this collaboration. Can be STATUS_ACCEPTED, link STATUS_PENDING or STATUS_REJECTED
148     *
149     * @return the status
150     */
151    @JsonInclude(JsonInclude.Include.ALWAYS)
152    @JsonProperty(FIELD_STATUS)
153    public String getStatus() {
154        return (String) getValue(FIELD_STATUS);
155    }
156
157    /**
158     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}.
159     *
160     * @param status the status to set
161     */
162    @JsonProperty(FIELD_STATUS)
163    private void setStatus(String status) {
164        put(FIELD_STATUS, status);
165    }
166
167    /**
168     * Get the role/permission. This is a role/permission String defined in CollaborationRole
169     *
170     * @return the role/permission
171     */
172    @JsonProperty(FIELD_ROLE)
173    public String getRole() {
174        return (String) getValue(FIELD_ROLE);
175    }
176
177    /**
178     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}.
179     *
180     * @param role the role to set
181     */
182    @JsonProperty(FIELD_ROLE)
183    private void setRole(String role) {
184        put(FIELD_ROLE, role);
185    }
186
187    /**
188     * Get the time when the status of this collaboration was changed. This returns a String and can be parsed into
189     * {@link java.util.Date} by
190     *
191     * @return the acknowledged_at
192     */
193    @JsonInclude(JsonInclude.Include.ALWAYS)
194    @JsonProperty(FIELD_ACKNOWLEGED_AT)
195    public String getAcknowledgedAt() {
196        return (String) getValue(FIELD_ACKNOWLEGED_AT);
197    }
198
199    /**
200     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}.
201     *
202     * @param acknowledgedAt the acknowledged_at to set
203     */
204    @JsonProperty(FIELD_ACKNOWLEGED_AT)
205    private void setAcknowledgedAt(String acknowledgedAt) {
206        put(FIELD_ACKNOWLEGED_AT, acknowledgedAt);
207    }
208
209    /**
210     * Get the folder this collaboration is related to.
211     *
212     * @return item the folder this collaboration is related to
213     */
214    @JsonProperty(FIELD_FOLDER)
215    public BoxFolder getFolder() {
216        return (BoxFolder) getValue(FIELD_FOLDER);
217    }
218
219    /**
220     * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>}.
221     *
222     * @param item the item to set
223     */
224    @JsonProperty(FIELD_FOLDER)
225    private void setFolder(BoxFolder item) {
226        put(FIELD_FOLDER, item);
227    }
228}