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