001package org.nuxeo.box.api.marshalling.dao; 002 003import com.fasterxml.jackson.annotation.JsonProperty; 004import com.fasterxml.jackson.annotation.JsonTypeInfo; 005import org.nuxeo.box.api.utils.ISO8601DateParser; 006 007import java.util.Date; 008import java.util.Map; 009 010/** 011 * Box File object 012 */ 013@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", defaultImpl = BoxFile.class) 014public class BoxFile extends BoxItem { 015 016 public final static String FIELD_SHA1 = "sha1"; 017 018 public final static String FIELD_VERSION_NUMBER = "version_number"; 019 020 public final static String FIELD_COMMENT_COUNT = "comment_count"; 021 022 public final static String FIELD_CONTENT_CREATED_AT = "content_created_at"; 023 024 public final static String FIELD_CONTENT_MODIFIED_AT = "content_modified_at"; 025 026 /** 027 * Constructor. 028 */ 029 public BoxFile() { 030 setType(BoxResourceType.FILE.toString()); 031 } 032 033 /** 034 * Copy constructor, this does deep copy for all the fields. 035 * 036 * @param obj 037 */ 038 public BoxFile(BoxFile obj) { 039 super(obj); 040 } 041 042 /** 043 * Instantiate the object from a map. Each entry in the map reflects to a field. 044 * 045 * @param map 046 */ 047 public BoxFile(Map<String, Object> map) { 048 super(map); 049 } 050 051 /** 052 * Get sha1 of the file. 053 * 054 * @return sha1 of the file. 055 */ 056 @JsonProperty(FIELD_SHA1) 057 public String getSha1() { 058 return (String) getValue(FIELD_SHA1); 059 } 060 061 /** 062 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 063 * 064 * @param sha1 sha1 065 */ 066 @JsonProperty(FIELD_SHA1) 067 private void setSha1(String sha1) { 068 put(FIELD_SHA1, sha1); 069 } 070 071 @JsonProperty(FIELD_CONTENT_CREATED_AT) 072 public String getContentCreatedAt() { 073 return (String) getValue(FIELD_CONTENT_CREATED_AT); 074 } 075 076 /** 077 * Return the date content created on local machine, if this date was not provided when uploading the file, this 078 * will be the time file was uploaded. 079 * 080 * @return 081 */ 082 public Date dateContentCreatedAt() { 083 return ISO8601DateParser.parseSilently(getContentCreatedAt()); 084 } 085 086 @JsonProperty(FIELD_CONTENT_CREATED_AT) 087 private void setContentCreatedAt(String createdAt) { 088 put(FIELD_CONTENT_CREATED_AT, createdAt); 089 } 090 091 @JsonProperty(FIELD_CONTENT_MODIFIED_AT) 092 public String getContentModifiedAt() { 093 return (String) getValue(FIELD_CONTENT_MODIFIED_AT); 094 } 095 096 /** 097 * Return the date content last modified on local machine, if this date was not provided when uploading the file, 098 * this will be the time file was uploaded. 099 * 100 * @return 101 */ 102 public Date dateContentModifieddAt() { 103 return ISO8601DateParser.parseSilently(getContentModifiedAt()); 104 } 105 106 @JsonProperty(FIELD_CONTENT_MODIFIED_AT) 107 private void setContentModifiedAt(String modifiedAt) { 108 put(FIELD_CONTENT_MODIFIED_AT, modifiedAt); 109 } 110 111 /** 112 * Get version number of the file. 113 * 114 * @return version number of the file. 115 */ 116 @JsonProperty(FIELD_VERSION_NUMBER) 117 public String getVersionNumber() { 118 return (String) getValue(FIELD_VERSION_NUMBER); 119 } 120 121 /** 122 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 123 * 124 * @param versionNumber version number 125 */ 126 @JsonProperty(FIELD_VERSION_NUMBER) 127 private void setVersionNumber(String versionNumber) { 128 put(FIELD_VERSION_NUMBER, versionNumber); 129 } 130 131 /** 132 * Get comment count of the file. 133 * 134 * @return comment count of the file. 135 */ 136 @JsonProperty(FIELD_COMMENT_COUNT) 137 public Integer getCommentCount() { 138 return (Integer) getValue(FIELD_COMMENT_COUNT); 139 } 140 141 /** 142 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 143 * 144 * @param commentCount comment count 145 */ 146 @JsonProperty(FIELD_COMMENT_COUNT) 147 private void setCommentCount(Integer commentCount) { 148 put(FIELD_COMMENT_COUNT, commentCount); 149 } 150}