com.finbourne.luminesce.model.WriterDesign Maven / Gradle / Ivy
/*
* FINBOURNE Luminesce Web API
*
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package com.finbourne.luminesce.model;
import java.util.Objects;
import com.finbourne.luminesce.model.AvailableParameter;
import com.finbourne.luminesce.model.ExpressionWithAlias;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.JsonAdapter;
import com.google.gson.annotations.SerializedName;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.openapitools.jackson.nullable.JsonNullable;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import com.finbourne.luminesce.JSON;
/**
* Representation of a \"designable Query for a writer\" suitable for formatting to SQL or being built from compliant SQL.
*/
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class WriterDesign {
public static final String SERIALIZED_NAME_SQL = "sql";
@SerializedName(SERIALIZED_NAME_SQL)
private String sql;
public static final String SERIALIZED_NAME_AVAILABLE_TO_MAP_FROM = "availableToMapFrom";
@SerializedName(SERIALIZED_NAME_AVAILABLE_TO_MAP_FROM)
private List availableToMapFrom;
public static final String SERIALIZED_NAME_PARAMETER = "parameter";
@SerializedName(SERIALIZED_NAME_PARAMETER)
private AvailableParameter parameter;
public static final String SERIALIZED_NAME_AVAILABLE_PARAMETERS = "availableParameters";
@SerializedName(SERIALIZED_NAME_AVAILABLE_PARAMETERS)
private List availableParameters;
public WriterDesign() {
}
public WriterDesign sql(String sql) {
this.sql = sql;
return this;
}
/**
* Original SQL that started this off
* @return sql
**/
@jakarta.annotation.Nonnull
public String getSql() {
return sql;
}
public void setSql(String sql) {
this.sql = sql;
}
public WriterDesign availableToMapFrom(List availableToMapFrom) {
this.availableToMapFrom = availableToMapFrom;
return this;
}
public WriterDesign addAvailableToMapFromItem(ExpressionWithAlias availableToMapFromItem) {
if (this.availableToMapFrom == null) {
this.availableToMapFrom = new ArrayList<>();
}
this.availableToMapFrom.add(availableToMapFromItem);
return this;
}
/**
* The data able to be mapped from as derived from the Sql
* @return availableToMapFrom
**/
@jakarta.annotation.Nullable
public List getAvailableToMapFrom() {
return availableToMapFrom;
}
public void setAvailableToMapFrom(List availableToMapFrom) {
this.availableToMapFrom = availableToMapFrom;
}
public WriterDesign parameter(AvailableParameter parameter) {
this.parameter = parameter;
return this;
}
/**
* Get parameter
* @return parameter
**/
@jakarta.annotation.Nullable
public AvailableParameter getParameter() {
return parameter;
}
public void setParameter(AvailableParameter parameter) {
this.parameter = parameter;
}
public WriterDesign availableParameters(List availableParameters) {
this.availableParameters = availableParameters;
return this;
}
public WriterDesign addAvailableParametersItem(AvailableParameter availableParametersItem) {
if (this.availableParameters == null) {
this.availableParameters = new ArrayList<>();
}
this.availableParameters.add(availableParametersItem);
return this;
}
/**
* All the parameter the user may wish to design
* @return availableParameters
**/
@jakarta.annotation.Nullable
public List getAvailableParameters() {
return availableParameters;
}
public void setAvailableParameters(List availableParameters) {
this.availableParameters = availableParameters;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
WriterDesign writerDesign = (WriterDesign) o;
return Objects.equals(this.sql, writerDesign.sql) &&
Objects.equals(this.availableToMapFrom, writerDesign.availableToMapFrom) &&
Objects.equals(this.parameter, writerDesign.parameter) &&
Objects.equals(this.availableParameters, writerDesign.availableParameters);
}
private static boolean equalsNullable(JsonNullable a, JsonNullable b) {
return a == b || (a != null && b != null && a.isPresent() && b.isPresent() && Objects.deepEquals(a.get(), b.get()));
}
@Override
public int hashCode() {
return Objects.hash(sql, availableToMapFrom, parameter, availableParameters);
}
private static int hashCodeNullable(JsonNullable a) {
if (a == null) {
return 1;
}
return a.isPresent() ? Arrays.deepHashCode(new Object[]{a.get()}) : 31;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class WriterDesign {\n");
sb.append(" sql: ").append(toIndentedString(sql)).append("\n");
sb.append(" availableToMapFrom: ").append(toIndentedString(availableToMapFrom)).append("\n");
sb.append(" parameter: ").append(toIndentedString(parameter)).append("\n");
sb.append(" availableParameters: ").append(toIndentedString(availableParameters)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}
public static HashSet openapiFields;
public static HashSet openapiRequiredFields;
static {
// a set of all properties/fields (JSON key names)
openapiFields = new HashSet();
openapiFields.add("sql");
openapiFields.add("availableToMapFrom");
openapiFields.add("parameter");
openapiFields.add("availableParameters");
// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet();
openapiRequiredFields.add("sql");
}
/**
* Validates the JSON Element and throws an exception if issues found
*
* @param jsonElement JSON Element
* @throws IOException if the JSON Element is invalid with respect to WriterDesign
*/
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
if (jsonElement == null) {
if (!WriterDesign.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
throw new IllegalArgumentException(String.format("The required field(s) %s in WriterDesign is not found in the empty JSON string", WriterDesign.openapiRequiredFields.toString()));
}
}
// check to make sure all required properties/fields are present in the JSON string
for (String requiredField : WriterDesign.openapiRequiredFields) {
if (jsonElement.getAsJsonObject().get(requiredField) == null) {
throw new IllegalArgumentException(String.format("The required field `%s` is not found in the JSON string: %s", requiredField, jsonElement.toString()));
}
}
JsonObject jsonObj = jsonElement.getAsJsonObject();
if (!jsonObj.get("sql").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `sql` to be a primitive type in the JSON string but got `%s`", jsonObj.get("sql").toString()));
}
if (jsonObj.get("availableToMapFrom") != null && !jsonObj.get("availableToMapFrom").isJsonNull()) {
JsonArray jsonArrayavailableToMapFrom = jsonObj.getAsJsonArray("availableToMapFrom");
if (jsonArrayavailableToMapFrom != null) {
// ensure the json data is an array
if (!jsonObj.get("availableToMapFrom").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `availableToMapFrom` to be an array in the JSON string but got `%s`", jsonObj.get("availableToMapFrom").toString()));
}
// validate the optional field `availableToMapFrom` (array)
for (int i = 0; i < jsonArrayavailableToMapFrom.size(); i++) {
ExpressionWithAlias.validateJsonElement(jsonArrayavailableToMapFrom.get(i));
};
}
}
// validate the optional field `parameter`
if (jsonObj.get("parameter") != null && !jsonObj.get("parameter").isJsonNull()) {
AvailableParameter.validateJsonElement(jsonObj.get("parameter"));
}
if (jsonObj.get("availableParameters") != null && !jsonObj.get("availableParameters").isJsonNull()) {
JsonArray jsonArrayavailableParameters = jsonObj.getAsJsonArray("availableParameters");
if (jsonArrayavailableParameters != null) {
// ensure the json data is an array
if (!jsonObj.get("availableParameters").isJsonArray()) {
throw new IllegalArgumentException(String.format("Expected the field `availableParameters` to be an array in the JSON string but got `%s`", jsonObj.get("availableParameters").toString()));
}
// validate the optional field `availableParameters` (array)
for (int i = 0; i < jsonArrayavailableParameters.size(); i++) {
AvailableParameter.validateJsonElement(jsonArrayavailableParameters.get(i));
};
}
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (!WriterDesign.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'WriterDesign' and its subtypes
}
final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(WriterDesign.class));
return (TypeAdapter) new TypeAdapter() {
@Override
public void write(JsonWriter out, WriterDesign value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public WriterDesign read(JsonReader in) throws IOException {
JsonElement jsonElement = elementAdapter.read(in);
validateJsonElement(jsonElement);
return thisAdapter.fromJsonTree(jsonElement);
}
}.nullSafe();
}
}
/**
* Create an instance of WriterDesign given an JSON string
*
* @param jsonString JSON string
* @return An instance of WriterDesign
* @throws IOException if the JSON string is invalid with respect to WriterDesign
*/
public static WriterDesign fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, WriterDesign.class);
}
/**
* Convert an instance of WriterDesign to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}