|
| 1 | +/* |
| 2 | + * Segment Public API |
| 3 | + * The Segment Public API helps you manage your Segment Workspaces and its resources. You can use the API to perform CRUD (create, read, update, delete) operations at no extra charge. This includes working with resources such as Sources, Destinations, Warehouses, Tracking Plans, and the Segment Destinations and Sources Catalogs. All CRUD endpoints in the API follow REST conventions and use standard HTTP methods. Different URL endpoints represent different resources in a Workspace. See the next sections for more information on how to use the Segment Public API. |
| 4 | + * |
| 5 | + |
| 6 | + * |
| 7 | + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). |
| 8 | + * https://openapi-generator.tech |
| 9 | + * Do not edit the class manually. |
| 10 | + */ |
| 11 | + |
| 12 | +package com.segment.publicapi.models; |
| 13 | + |
| 14 | +import com.google.gson.Gson; |
| 15 | +import com.google.gson.JsonElement; |
| 16 | +import com.google.gson.JsonObject; |
| 17 | +import com.google.gson.TypeAdapter; |
| 18 | +import com.google.gson.TypeAdapterFactory; |
| 19 | +import com.google.gson.annotations.JsonAdapter; |
| 20 | +import com.google.gson.annotations.SerializedName; |
| 21 | +import com.google.gson.reflect.TypeToken; |
| 22 | +import com.google.gson.stream.JsonReader; |
| 23 | +import com.google.gson.stream.JsonWriter; |
| 24 | +import com.segment.publicapi.JSON; |
| 25 | +import java.io.IOException; |
| 26 | +import java.util.HashSet; |
| 27 | +import java.util.Map; |
| 28 | +import java.util.Objects; |
| 29 | +import java.util.Set; |
| 30 | + |
| 31 | +/** Defines an audience definition. */ |
| 32 | +public class AudienceDefinitionBeta { |
| 33 | + public static final String SERIALIZED_NAME_QUERY = "query"; |
| 34 | + |
| 35 | + @SerializedName(SERIALIZED_NAME_QUERY) |
| 36 | + private String query; |
| 37 | + |
| 38 | + /** |
| 39 | + * The underlying data type being segmented for this audience. Possible values: users, accounts. |
| 40 | + */ |
| 41 | + @JsonAdapter(TypeEnum.Adapter.class) |
| 42 | + public enum TypeEnum { |
| 43 | + ACCOUNTS("ACCOUNTS"), |
| 44 | + |
| 45 | + USERS("USERS"); |
| 46 | + |
| 47 | + private String value; |
| 48 | + |
| 49 | + TypeEnum(String value) { |
| 50 | + this.value = value; |
| 51 | + } |
| 52 | + |
| 53 | + public String getValue() { |
| 54 | + return value; |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public String toString() { |
| 59 | + return String.valueOf(value); |
| 60 | + } |
| 61 | + |
| 62 | + public static TypeEnum fromValue(String value) { |
| 63 | + for (TypeEnum b : TypeEnum.values()) { |
| 64 | + if (b.value.equals(value)) { |
| 65 | + return b; |
| 66 | + } |
| 67 | + } |
| 68 | + throw new IllegalArgumentException("Unexpected value '" + value + "'"); |
| 69 | + } |
| 70 | + |
| 71 | + public static class Adapter extends TypeAdapter<TypeEnum> { |
| 72 | + @Override |
| 73 | + public void write(final JsonWriter jsonWriter, final TypeEnum enumeration) |
| 74 | + throws IOException { |
| 75 | + jsonWriter.value(enumeration.getValue()); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public TypeEnum read(final JsonReader jsonReader) throws IOException { |
| 80 | + String value = jsonReader.nextString(); |
| 81 | + return TypeEnum.fromValue(value); |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + public static final String SERIALIZED_NAME_TYPE = "type"; |
| 87 | + |
| 88 | + @SerializedName(SERIALIZED_NAME_TYPE) |
| 89 | + private TypeEnum type; |
| 90 | + |
| 91 | + public AudienceDefinitionBeta() {} |
| 92 | + |
| 93 | + public AudienceDefinitionBeta query(String query) { |
| 94 | + |
| 95 | + this.query = query; |
| 96 | + return this; |
| 97 | + } |
| 98 | + |
| 99 | + /** |
| 100 | + * The query language string defining the audience segmentation criteria. |
| 101 | + * |
| 102 | + * @return query |
| 103 | + */ |
| 104 | + @javax.annotation.Nonnull |
| 105 | + public String getQuery() { |
| 106 | + return query; |
| 107 | + } |
| 108 | + |
| 109 | + public void setQuery(String query) { |
| 110 | + this.query = query; |
| 111 | + } |
| 112 | + |
| 113 | + public AudienceDefinitionBeta type(TypeEnum type) { |
| 114 | + |
| 115 | + this.type = type; |
| 116 | + return this; |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * The underlying data type being segmented for this audience. Possible values: users, accounts. |
| 121 | + * |
| 122 | + * @return type |
| 123 | + */ |
| 124 | + @javax.annotation.Nonnull |
| 125 | + public TypeEnum getType() { |
| 126 | + return type; |
| 127 | + } |
| 128 | + |
| 129 | + public void setType(TypeEnum type) { |
| 130 | + this.type = type; |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public boolean equals(Object o) { |
| 135 | + if (this == o) { |
| 136 | + return true; |
| 137 | + } |
| 138 | + if (o == null || getClass() != o.getClass()) { |
| 139 | + return false; |
| 140 | + } |
| 141 | + AudienceDefinitionBeta audienceDefinitionBeta = (AudienceDefinitionBeta) o; |
| 142 | + return Objects.equals(this.query, audienceDefinitionBeta.query) |
| 143 | + && Objects.equals(this.type, audienceDefinitionBeta.type); |
| 144 | + } |
| 145 | + |
| 146 | + @Override |
| 147 | + public int hashCode() { |
| 148 | + return Objects.hash(query, type); |
| 149 | + } |
| 150 | + |
| 151 | + @Override |
| 152 | + public String toString() { |
| 153 | + StringBuilder sb = new StringBuilder(); |
| 154 | + sb.append("class AudienceDefinitionBeta {\n"); |
| 155 | + sb.append(" query: ").append(toIndentedString(query)).append("\n"); |
| 156 | + sb.append(" type: ").append(toIndentedString(type)).append("\n"); |
| 157 | + sb.append("}"); |
| 158 | + return sb.toString(); |
| 159 | + } |
| 160 | + |
| 161 | + /** |
| 162 | + * Convert the given object to string with each line indented by 4 spaces (except the first |
| 163 | + * line). |
| 164 | + */ |
| 165 | + private String toIndentedString(Object o) { |
| 166 | + if (o == null) { |
| 167 | + return "null"; |
| 168 | + } |
| 169 | + return o.toString().replace("\n", "\n "); |
| 170 | + } |
| 171 | + |
| 172 | + public static HashSet<String> openapiFields; |
| 173 | + public static HashSet<String> openapiRequiredFields; |
| 174 | + |
| 175 | + static { |
| 176 | + // a set of all properties/fields (JSON key names) |
| 177 | + openapiFields = new HashSet<String>(); |
| 178 | + openapiFields.add("query"); |
| 179 | + openapiFields.add("type"); |
| 180 | + |
| 181 | + // a set of required properties/fields (JSON key names) |
| 182 | + openapiRequiredFields = new HashSet<String>(); |
| 183 | + openapiRequiredFields.add("query"); |
| 184 | + openapiRequiredFields.add("type"); |
| 185 | + } |
| 186 | + |
| 187 | + /** |
| 188 | + * Validates the JSON Element and throws an exception if issues found |
| 189 | + * |
| 190 | + * @param jsonElement JSON Element |
| 191 | + * @throws IOException if the JSON Element is invalid with respect to AudienceDefinitionBeta |
| 192 | + */ |
| 193 | + public static void validateJsonElement(JsonElement jsonElement) throws IOException { |
| 194 | + if (jsonElement == null) { |
| 195 | + if (!AudienceDefinitionBeta.openapiRequiredFields |
| 196 | + .isEmpty()) { // has required fields but JSON element is null |
| 197 | + throw new IllegalArgumentException( |
| 198 | + String.format( |
| 199 | + "The required field(s) %s in AudienceDefinitionBeta is not found in" |
| 200 | + + " the empty JSON string", |
| 201 | + AudienceDefinitionBeta.openapiRequiredFields.toString())); |
| 202 | + } |
| 203 | + } |
| 204 | + |
| 205 | + Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet(); |
| 206 | + // check to see if the JSON string contains additional fields |
| 207 | + for (Map.Entry<String, JsonElement> entry : entries) { |
| 208 | + if (!AudienceDefinitionBeta.openapiFields.contains(entry.getKey())) { |
| 209 | + throw new IllegalArgumentException( |
| 210 | + String.format( |
| 211 | + "The field `%s` in the JSON string is not defined in the" |
| 212 | + + " `AudienceDefinitionBeta` properties. JSON: %s", |
| 213 | + entry.getKey(), jsonElement.toString())); |
| 214 | + } |
| 215 | + } |
| 216 | + |
| 217 | + // check to make sure all required properties/fields are present in the JSON string |
| 218 | + for (String requiredField : AudienceDefinitionBeta.openapiRequiredFields) { |
| 219 | + if (jsonElement.getAsJsonObject().get(requiredField) == null) { |
| 220 | + throw new IllegalArgumentException( |
| 221 | + String.format( |
| 222 | + "The required field `%s` is not found in the JSON string: %s", |
| 223 | + requiredField, jsonElement.toString())); |
| 224 | + } |
| 225 | + } |
| 226 | + JsonObject jsonObj = jsonElement.getAsJsonObject(); |
| 227 | + if (!jsonObj.get("query").isJsonPrimitive()) { |
| 228 | + throw new IllegalArgumentException( |
| 229 | + String.format( |
| 230 | + "Expected the field `query` to be a primitive type in the JSON string" |
| 231 | + + " but got `%s`", |
| 232 | + jsonObj.get("query").toString())); |
| 233 | + } |
| 234 | + if (!jsonObj.get("type").isJsonPrimitive()) { |
| 235 | + throw new IllegalArgumentException( |
| 236 | + String.format( |
| 237 | + "Expected the field `type` to be a primitive type in the JSON string" |
| 238 | + + " but got `%s`", |
| 239 | + jsonObj.get("type").toString())); |
| 240 | + } |
| 241 | + } |
| 242 | + |
| 243 | + public static class CustomTypeAdapterFactory implements TypeAdapterFactory { |
| 244 | + @SuppressWarnings("unchecked") |
| 245 | + @Override |
| 246 | + public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) { |
| 247 | + if (!AudienceDefinitionBeta.class.isAssignableFrom(type.getRawType())) { |
| 248 | + return null; // this class only serializes 'AudienceDefinitionBeta' and its subtypes |
| 249 | + } |
| 250 | + final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class); |
| 251 | + final TypeAdapter<AudienceDefinitionBeta> thisAdapter = |
| 252 | + gson.getDelegateAdapter(this, TypeToken.get(AudienceDefinitionBeta.class)); |
| 253 | + |
| 254 | + return (TypeAdapter<T>) |
| 255 | + new TypeAdapter<AudienceDefinitionBeta>() { |
| 256 | + @Override |
| 257 | + public void write(JsonWriter out, AudienceDefinitionBeta value) |
| 258 | + throws IOException { |
| 259 | + JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject(); |
| 260 | + elementAdapter.write(out, obj); |
| 261 | + } |
| 262 | + |
| 263 | + @Override |
| 264 | + public AudienceDefinitionBeta read(JsonReader in) throws IOException { |
| 265 | + JsonElement jsonElement = elementAdapter.read(in); |
| 266 | + validateJsonElement(jsonElement); |
| 267 | + return thisAdapter.fromJsonTree(jsonElement); |
| 268 | + } |
| 269 | + }.nullSafe(); |
| 270 | + } |
| 271 | + } |
| 272 | + |
| 273 | + /** |
| 274 | + * Create an instance of AudienceDefinitionBeta given an JSON string |
| 275 | + * |
| 276 | + * @param jsonString JSON string |
| 277 | + * @return An instance of AudienceDefinitionBeta |
| 278 | + * @throws IOException if the JSON string is invalid with respect to AudienceDefinitionBeta |
| 279 | + */ |
| 280 | + public static AudienceDefinitionBeta fromJson(String jsonString) throws IOException { |
| 281 | + return JSON.getGson().fromJson(jsonString, AudienceDefinitionBeta.class); |
| 282 | + } |
| 283 | + |
| 284 | + /** |
| 285 | + * Convert an instance of AudienceDefinitionBeta to an JSON string |
| 286 | + * |
| 287 | + * @return JSON string |
| 288 | + */ |
| 289 | + public String toJson() { |
| 290 | + return JSON.getGson().toJson(this); |
| 291 | + } |
| 292 | +} |
0 commit comments