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 * This is base class for all box objects. 012 */ 013@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "type", defaultImpl = BoxTypedObject.class) 014public class BoxTypedObject extends BoxObject { 015 016 public static final String FIELD_TYPE = "type"; 017 018 public static final String FIELD_ID = "id"; 019 020 public static final String FIELD_CREATED_AT = "created_at"; 021 022 public static final String FIELD_MODIFIED_AT = "modified_at"; 023 024 public BoxTypedObject() { 025 } 026 027 /** 028 * Copy constructor, this does deep copy for all the fields. 029 * 030 * @param obj 031 */ 032 public BoxTypedObject(BoxTypedObject obj) { 033 super(obj); 034 } 035 036 /** 037 * Instantiate the object from a map. Each entry in the map reflects to a field. 038 * 039 * @param map 040 */ 041 public BoxTypedObject(Map<String, Object> map) { 042 super(map); 043 } 044 045 /** 046 * Get BoxResourceType of this object. using getBoxResourceType() instead . use getTypeFromLowercaseString method in 047 * IBoxResourceHub to parse the result String into type object. 048 * 049 * @return 050 */ 051 @Deprecated 052 public BoxResourceType resourceType() { 053 return BoxResourceType.getTypeFromLowercaseString(getType()); 054 } 055 056 /** 057 * Get the type. 058 * 059 * @return type 060 */ 061 @JsonProperty(FIELD_TYPE) 062 public String getType() { 063 return (String) getValue(FIELD_TYPE); 064 } 065 066 /** 067 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 068 * 069 * @param type type 070 */ 071 @JsonProperty(FIELD_TYPE) 072 public void setType(String type) { 073 put(FIELD_TYPE, type); 074 } 075 076 /** 077 * Get id. 078 * 079 * @return id 080 */ 081 @JsonProperty(FIELD_ID) 082 public String getId() { 083 return (String) getValue(FIELD_ID); 084 } 085 086 /** 087 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 088 * 089 * @param id id 090 */ 091 @JsonProperty(FIELD_ID) 092 private void setId(String id) { 093 put(FIELD_ID, id); 094 } 095 096 /** 097 * Get the time this user was created at. (This returns a String and can be parsed into {@link java.util.Date} by 098 * 099 * @return the created_at 100 */ 101 @JsonProperty(FIELD_CREATED_AT) 102 public String getCreatedAt() { 103 return (String) getValue(FIELD_CREATED_AT); 104 } 105 106 /** 107 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 108 * 109 * @param createdAt the created_at to set 110 */ 111 @JsonProperty(FIELD_CREATED_AT) 112 private void setCreatedAt(String createdAt) { 113 put(FIELD_CREATED_AT, createdAt); 114 } 115 116 /** 117 * Get the time created at. 118 * 119 * @return Date representation of the created_at value. Null if there was no created_at or if it could not be parsed 120 * as an ISO8601 date. 121 * @throws java.text.ParseException 122 */ 123 public Date dateCreatedAt() { 124 return ISO8601DateParser.parseSilently(getCreatedAt()); 125 } 126 127 /** 128 * Get the time this user was modified the last time. (This returns a String and can be parsed into 129 * {@link java.util.Date} by 130 * 131 * @return the modified_at 132 */ 133 @JsonProperty(FIELD_MODIFIED_AT) 134 public String getModifiedAt() { 135 return (String) getValue(FIELD_MODIFIED_AT); 136 } 137 138 /** 139 * Setter. This is only used by {@see <a href="http://jackson.codehaus .org">Jackson JSON processer</a>} 140 * 141 * @param modifiedAt the modified_at to set 142 */ 143 @JsonProperty(FIELD_MODIFIED_AT) 144 private void setModifiedAt(String modifiedAt) { 145 put(FIELD_MODIFIED_AT, modifiedAt); 146 } 147 148 /** 149 * Get the date this object is modified at. 150 * 151 * @return Date representation of the modified_at value. Null if there was no date_modified or if it could not be 152 * parsed as an ISO8601 date. 153 * @throws java.text.ParseException 154 */ 155 public Date dateModifiedAt() { 156 return ISO8601DateParser.parseSilently(getModifiedAt()); 157 } 158}