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