001/* 002 * Copyright 2013 Box, Inc. All rights reserved. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.nuxeo.box.api.marshalling.dao; 017 018import com.fasterxml.jackson.annotation.JsonInclude; 019import com.fasterxml.jackson.annotation.JsonProperty; 020import com.fasterxml.jackson.annotation.JsonTypeInfo; 021 022import java.util.Map; 023 024/** 025 * Box item, this is a base class for the box items({@link org.nuxeo.box.api .dao.BoxFile}/{@link BoxFolder}/...) 026 */ 027@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", defaultImpl = BoxItem.class) 028public class BoxItem extends BoxTypedObject { 029 030 public static final String FIELD_ETAG = "etag"; 031 032 public static final String FIELD_SEQUENCE_ID = "sequence_id"; 033 034 public static final String FIELD_NAME = "name"; 035 036 public static final String FIELD_DESCRIPTION = "description"; 037 038 public static final String FIELD_SIZE = "size"; 039 040 public static final String FIELD_ITEM_STATUS = "item_status"; 041 042 public static final String FIELD_SHARED_LINK = "shared_link"; 043 044 public static final String FIELD_CREATED_BY = "created_by"; 045 046 public static final String FIELD_MODIFIED_BY = "modified_by"; 047 048 public static final String FIELD_OWNED_BY = "owned_by"; 049 050 public static final String FIELD_PARENT = "parent"; 051 052 public static final String FIELD_PATH_COLLECTION = "path_collection"; 053 054 public static final String FIELD_TAGS = "tags"; 055 056 public BoxItem() { 057 } 058 059 /** 060 * Copy constructor, this does deep copy for all the fields. 061 * 062 * @param obj 063 */ 064 public BoxItem(BoxItem obj) { 065 super(obj); 066 } 067 068 /** 069 * Instantiate the object from a map. Each entry in the map reflects to a field. 070 * 071 * @param map 072 */ 073 public BoxItem(Map<String, Object> map) { 074 super(map); 075 } 076 077 /** 078 * Get the path of folders to this item, starting at the root. 079 * 080 * @return the path_collection 081 */ 082 @JsonProperty(FIELD_PATH_COLLECTION) 083 public BoxCollection getPathCollection() { 084 return (BoxCollection) getValue(FIELD_PATH_COLLECTION); 085 } 086 087 /** 088 * This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 089 * 090 * @param pathCollection the path_collection to set 091 */ 092 @JsonProperty(FIELD_PATH_COLLECTION) 093 private void setPathCollection(BoxCollection pathCollection) { 094 put(FIELD_PATH_COLLECTION, pathCollection); 095 } 096 097 /** 098 * Get the tags that are set on this item. 099 * 100 * @return the tags 101 */ 102 @JsonProperty(FIELD_TAGS) 103 public String[] getTags() { 104 return (String[]) getValue(FIELD_TAGS); 105 } 106 107 /** 108 * This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 109 * 110 * @param tags the tags to set 111 */ 112 @JsonProperty(FIELD_TAGS) 113 private void setTags(String[] tags) { 114 put(FIELD_TAGS, tags); 115 } 116 117 /** 118 * Getter. 119 * 120 * @return sequence id 121 */ 122 // NXIO-45: don't skip null value to fit to Box json payload response 123 @JsonInclude(JsonInclude.Include.ALWAYS) 124 @JsonProperty(FIELD_SEQUENCE_ID) 125 public String getSequenceId() { 126 return (String) getValue(FIELD_SEQUENCE_ID); 127 } 128 129 /** 130 * Setter.This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 131 * 132 * @param sequenceId sequence id 133 */ 134 @JsonProperty(FIELD_SEQUENCE_ID) 135 private void setSequenceId(String sequenceId) { 136 put(FIELD_SEQUENCE_ID, sequenceId); 137 } 138 139 /** 140 * Get name of the item. 141 * 142 * @return name of the item 143 */ 144 @JsonProperty(FIELD_NAME) 145 public String getName() { 146 return (String) getValue(FIELD_NAME); 147 } 148 149 /** 150 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 151 * 152 * @param name name of the item 153 */ 154 @JsonProperty(FIELD_NAME) 155 private void setName(String name) { 156 put(FIELD_NAME, name); 157 } 158 159 /** 160 * Get description of the item. 161 * 162 * @return description of the item 163 */ 164 @JsonProperty(FIELD_DESCRIPTION) 165 public String getDescription() { 166 return (String) getValue(FIELD_DESCRIPTION); 167 } 168 169 /** 170 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 171 * 172 * @param description description 173 */ 174 @JsonProperty(FIELD_DESCRIPTION) 175 private void setDescription(String description) { 176 put(FIELD_DESCRIPTION, description); 177 } 178 179 /** 180 * Get size of the box item. In bytes. 181 * 182 * @return size of the box item in bytes. 183 */ 184 @JsonProperty(FIELD_SIZE) 185 public Double getSize() { 186 return (Double) getValue(FIELD_SIZE); 187 } 188 189 /** 190 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 191 * 192 * @param size 193 */ 194 @JsonProperty(FIELD_SIZE) 195 private void setSize(Double size) { 196 put(FIELD_SIZE, size); 197 } 198 199 /** 200 * Get shared link of box item. Note if there is not shared link created, this is null. 201 * 202 * @return shared link of box item 203 */ 204 @JsonProperty(FIELD_SHARED_LINK) 205 public BoxSharedLink getSharedLink() { 206 return (BoxSharedLink) getValue(FIELD_SHARED_LINK); 207 } 208 209 /** 210 * Set the shared link. 211 * 212 * @param sharedLink shared link 213 */ 214 @JsonProperty(FIELD_SHARED_LINK) 215 private void setSharedLink(BoxSharedLink sharedLink) { 216 put(FIELD_SHARED_LINK, sharedLink); 217 } 218 219 /** 220 * Get the user creating this item. 221 * 222 * @return user creating this item 223 */ 224 @JsonProperty(FIELD_CREATED_BY) 225 public BoxUser getCreatedBy() { 226 return (BoxUser) getValue(FIELD_CREATED_BY); 227 } 228 229 /** 230 * Set the user creating this item. 231 * 232 * @param createdBy created by 233 */ 234 @JsonProperty(FIELD_CREATED_BY) 235 private void setCreatedBy(BoxUser createdBy) { 236 put(FIELD_CREATED_BY, createdBy); 237 } 238 239 /** 240 * Get the user last modified the item. 241 * 242 * @return user last modified the item 243 */ 244 @JsonProperty(FIELD_MODIFIED_BY) 245 public BoxUser getModifiedBy() { 246 return (BoxUser) getValue(FIELD_MODIFIED_BY); 247 } 248 249 /** 250 * Set the user last modified the item. 251 * 252 * @param modifiedBy 253 */ 254 @JsonProperty(FIELD_MODIFIED_BY) 255 private void setModifiedBy(BoxUser modifiedBy) { 256 put(FIELD_MODIFIED_BY, modifiedBy); 257 } 258 259 /** 260 * Get owner of the item. 261 * 262 * @return owner of the item 263 */ 264 @JsonProperty(FIELD_OWNED_BY) 265 public BoxUser getOwnedBy() { 266 return (BoxUser) getValue(FIELD_OWNED_BY); 267 } 268 269 /** 270 * Set the owner. 271 * 272 * @param ownedBy owner 273 */ 274 @JsonProperty(FIELD_OWNED_BY) 275 private void setOwnedBy(BoxUser ownedBy) { 276 put(FIELD_OWNED_BY, ownedBy); 277 } 278 279 /** 280 * Get parent folder. 281 * 282 * @return parent folder 283 */ 284 @JsonProperty(FIELD_PARENT) 285 public BoxFolder getParent() { 286 return (BoxFolder) getValue(FIELD_PARENT); 287 } 288 289 /** 290 * Set the parent. 291 * 292 * @param parent parent folder 293 */ 294 @JsonProperty(FIELD_PARENT) 295 private void setParent(BoxFolder parent) { 296 put(FIELD_PARENT, parent); 297 } 298 299 /** 300 * Get etag. 301 * 302 * @return etag 303 */ 304 // NXIO-45: don't skip null value to fit to Box json payload response 305 @JsonInclude(JsonInclude.Include.ALWAYS) 306 @JsonProperty(FIELD_ETAG) 307 public String getEtag() { 308 return (String) getValue(FIELD_ETAG); 309 } 310 311 /** 312 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 313 * 314 * @param etag etag 315 */ 316 @JsonProperty(FIELD_ETAG) 317 private void setEtag(String etag) { 318 put(FIELD_ETAG, etag); 319 } 320 321 /** 322 * Get the status of this item, which indicates whether this item is deleted or not. 323 * 324 * @return the item_status 325 */ 326 @JsonProperty(FIELD_ITEM_STATUS) 327 public String getItemStatus() { 328 return (String) getValue(FIELD_ITEM_STATUS); 329 } 330 331 /** 332 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 333 * 334 * @param itemStatus the item_status to set 335 */ 336 @JsonProperty(FIELD_ITEM_STATUS) 337 private void setItemStatus(String itemStatus) { 338 put(FIELD_ITEM_STATUS, itemStatus); 339 } 340}