001package com.box.sdk;
002
003import com.eclipsesource.json.JsonObject;
004import com.eclipsesource.json.JsonValue;
005import java.util.Date;
006
007/**
008 * Represents a watermark.
009 * Watermarks are used to protect sensitive information in the Box account.
010 *
011 * @see <a href="https://developer.box.com/reference/resources/watermark/">Watermarking</a>
012 */
013public class BoxWatermark extends BoxJSONObject {
014
015    /**
016     * Default imprint for watermarks.
017     */
018    public static final String WATERMARK_DEFAULT_IMPRINT = "default";
019
020    /**
021     * Json key for watermark.
022     *
023     * @see BoxWatermark#parseJSONMember(JsonObject.Member)
024     */
025    public static final String WATERMARK_JSON_KEY = "watermark";
026
027    /**
028     * Json key for created_at param.
029     *
030     * @see BoxWatermark#parseJSONMember(JsonObject.Member)
031     */
032    public static final String CREATED_AT_JSON_KEY = "created_at";
033
034    /**
035     * Json key for modified_at param.
036     *
037     * @see BoxWatermark#parseJSONMember(JsonObject.Member)
038     */
039    public static final String MODIFIED_AT_JSON_KEY = "modified_at";
040
041    /**
042     * Json key for watermark param.
043     */
044    public static final String WATERMARK_IMPRINT_JSON_KEY = "imprint";
045
046    /**
047     * @see #getCreatedAt()
048     */
049    private Date createdAt;
050
051    /**
052     * @see #getModifiedAt()
053     */
054    private Date modifiedAt;
055
056    /**
057     * Constructs an empty watermark object.
058     */
059    public BoxWatermark() {
060        super();
061    }
062
063    /**
064     * Constructs a watermark object by parsing information from a JSON string.
065     *
066     * @param json the JSON string to parse.
067     */
068    public BoxWatermark(String json) {
069        super(json);
070    }
071
072    /**
073     * Constructs a watermark object using an already parsed JSON object.
074     *
075     * @param jsonObject the parsed JSON object.
076     */
077    BoxWatermark(JsonObject jsonObject) {
078        super(jsonObject);
079    }
080
081    /**
082     * @return the time that the watermark was created.
083     */
084    public Date getCreatedAt() {
085        return this.createdAt;
086    }
087
088    /**
089     * @return the time that the watermark was last modified.
090     */
091    public Date getModifiedAt() {
092        return this.modifiedAt;
093    }
094
095    /**
096     * {@inheritDoc}
097     */
098    public BoxWatermark getResource() {
099        return BoxWatermark.this;
100    }
101
102    /**
103     * {@inheritDoc}
104     */
105    @Override
106    void parseJSONMember(JsonObject.Member member) {
107        super.parseJSONMember(member);
108        String memberName = member.getName();
109        JsonValue value = member.getValue();
110        if (memberName.equals(WATERMARK_JSON_KEY)) {
111            try {
112                this.createdAt = BoxDateFormat.parse(value.asObject().get(CREATED_AT_JSON_KEY).asString());
113                this.modifiedAt = BoxDateFormat.parse(value.asObject().get(MODIFIED_AT_JSON_KEY).asString());
114            } catch (Exception e) {
115                throw new BoxDeserializationException(memberName, value.toString(), e);
116            }
117        }
118    }
119
120}