001package com.box.sdk;
002
003import static com.box.sdk.BoxDateFormat.formatAsDateOnly;
004
005import com.box.sdk.internal.utils.JsonUtils;
006import com.eclipsesource.json.JsonObject;
007import com.eclipsesource.json.JsonValue;
008import java.util.Date;
009
010/**
011 * Represents a prefill tag used in BoxSignRequest. When a document contains sign related tags in
012 * the content, you can prefill them using this prefillTag by referencing the 'id' of the tag as the
013 * externalId field of the prefill tag.
014 */
015public class BoxSignRequestPrefillTag extends BoxJSONObject {
016  private String documentTagId;
017  private String textValue;
018  private Boolean checkboxValue;
019  private Date dateValue;
020
021  /**
022   * Constructs a BoxSignRequestPrefillTag with text prefill value.
023   *
024   * @param documentTagId if of the tag.
025   * @param textValue text prefill value.
026   */
027  public BoxSignRequestPrefillTag(String documentTagId, String textValue) {
028    this.documentTagId = documentTagId;
029    this.textValue = textValue;
030  }
031
032  /**
033   * Constructs a BoxSignRequestPrefillTag with checkbox prefill value.
034   *
035   * @param documentTagId if of the tag.
036   * @param checkboxValue checkbox prefill value.
037   */
038  public BoxSignRequestPrefillTag(String documentTagId, Boolean checkboxValue) {
039    this.documentTagId = documentTagId;
040    this.checkboxValue = checkboxValue;
041  }
042
043  /**
044   * Constructs a BoxSignRequestPrefillTag with date prefill value.
045   *
046   * @param documentTagId if of the tag.
047   * @param dateValue date prefill value.
048   */
049  public BoxSignRequestPrefillTag(String documentTagId, Date dateValue) {
050    this.documentTagId = documentTagId;
051    this.dateValue = dateValue;
052  }
053
054  /**
055   * Constructs a BoxSignRequestPrefillTag from a JSON string.
056   *
057   * @param json the JSON encoded enterprise.
058   */
059  public BoxSignRequestPrefillTag(String json) {
060    super(json);
061  }
062
063  /**
064   * Constructs an BoxSignRequestPrefillTag object using an already parsed JSON object.
065   *
066   * @param jsonObject the parsed JSON object.
067   */
068  BoxSignRequestPrefillTag(JsonObject jsonObject) {
069    super(jsonObject);
070  }
071
072  /**
073   * Gets the reference id of a particular tag added to the content of the files being used to
074   * create the sign request.
075   *
076   * @return document tag id.
077   */
078  public String getDocumentTagId() {
079    return this.documentTagId;
080  }
081
082  /**
083   * Gets the text prefill value.
084   *
085   * @return text prefill value.
086   */
087  public String getTextValue() {
088    return this.textValue;
089  }
090
091  /**
092   * Gets the checkbox prefill value.
093   *
094   * @return checkbox prefill value.
095   */
096  public Boolean getCheckboxValue() {
097    return this.checkboxValue;
098  }
099
100  /**
101   * Gets the date prefill value.
102   *
103   * @return date prefill value.
104   */
105  public Date getDateValue() {
106    return this.dateValue;
107  }
108
109  /**
110   * Gets a JSON object representing this class.
111   *
112   * @return the JSON object representing this class.
113   */
114  public JsonObject getJSONObject() {
115    JsonObject prefillTagObj = new JsonObject();
116    JsonUtils.addIfNotNull(prefillTagObj, "document_tag_id", this.documentTagId);
117    JsonUtils.addIfNotNull(prefillTagObj, "text_value", this.textValue);
118    JsonUtils.addIfNotNull(prefillTagObj, "checkbox_value", this.checkboxValue);
119    if (this.dateValue != null) {
120      prefillTagObj.add("date_value", formatAsDateOnly(this.dateValue));
121    }
122
123    return prefillTagObj;
124  }
125
126  /** {@inheritDoc} */
127  @Override
128  void parseJSONMember(JsonObject.Member member) {
129    JsonValue value = member.getValue();
130    String memberName = member.getName();
131    try {
132      if ("document_tag_id".equals(memberName)) {
133        this.documentTagId = value.asString();
134      } else if ("text_value".equals(memberName)) {
135        this.textValue = value.asString();
136      } else if ("checkbox_value".equals(memberName)) {
137        this.checkboxValue = value.asBoolean();
138      } else if ("date_value".equals(memberName)) {
139        this.dateValue = BoxDateFormat.parseDateOnly(value.asString());
140      }
141    } catch (Exception e) {
142      throw new BoxDeserializationException(memberName, value.toString(), e);
143    }
144  }
145}