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 the content, 012 * you can prefill them using this prefillTag by referencing the 013 * 'id' of the tag as the 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 074 * of the files being used to 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 /** 127 * {@inheritDoc} 128 */ 129 @Override 130 void parseJSONMember(JsonObject.Member member) { 131 JsonValue value = member.getValue(); 132 String memberName = member.getName(); 133 try { 134 if ("document_tag_id".equals(memberName)) { 135 this.documentTagId = value.asString(); 136 } else if ("text_value".equals(memberName)) { 137 this.textValue = value.asString(); 138 } else if ("checkbox_value".equals(memberName)) { 139 this.checkboxValue = value.asBoolean(); 140 } else if ("date_value".equals(memberName)) { 141 this.dateValue = BoxDateFormat.parseDateOnly(value.asString()); 142 } 143 } catch (Exception e) { 144 throw new BoxDeserializationException(memberName, value.toString(), e); 145 } 146 } 147}