All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.configcat.publicapi.java.client.model.UpdateEvaluationFormulaWithIdModel Maven / Gradle / Ivy

/*
 * ConfigCat Public Management API
 * The purpose of this API is to access the ConfigCat platform programmatically. You can **Create**, **Read**, **Update** and **Delete** any entities like **Feature Flags, Configs, Environments** or **Products** within ConfigCat.  **Base API URL**: https://api.configcat.com  If you prefer the swagger documentation, you can find it here: [Swagger UI](https://api.configcat.com/swagger).  The API is based on HTTP REST, uses resource-oriented URLs, status codes and supports JSON  format.   **Important:** Do not use this API for accessing and evaluating feature flag values. Use the [SDKs](https://configcat.com/docs/sdk-reference/overview) or the [ConfigCat Proxy](https://configcat.com/docs/advanced/proxy/proxy-overview/) instead.  # OpenAPI Specification  The complete specification is publicly available in the following formats:  - [OpenAPI v3](https://api.configcat.com/docs/v1/swagger.json) - [Swagger v2](https://api.configcat.com/docs/v1/swagger.v2.json)  You can use it to generate client libraries in various languages with [OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) or [Swagger Codegen](https://swagger.io/tools/swagger-codegen/) to interact with this API.  # Authentication This API uses the [Basic HTTP Authentication Scheme](https://en.wikipedia.org/wiki/Basic_access_authentication).     # Throttling and rate limits All the rate limited API calls are returning information about the current rate limit period in the following HTTP headers:  | Header | Description | | :- | :- | | X-Rate-Limit-Remaining | The maximum number of requests remaining in the current rate limit period. | | X-Rate-Limit-Reset     | The time when the current rate limit period resets.        |  When the rate limit is exceeded by a request, the API returns with a `HTTP 429 - Too many requests` status along with a `Retry-After` HTTP header.
 *
 * The version of the OpenAPI document: v1
 * 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.configcat.publicapi.java.client.model;


import com.configcat.publicapi.java.client.JSON;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
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.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.openapitools.jackson.nullable.JsonNullable;

/** UpdateEvaluationFormulaWithIdModel */
@javax.annotation.Generated(
        value = "org.openapitools.codegen.languages.JavaClientCodegen",
        date = "2024-10-09T12:38:06.739118192Z[Etc/UTC]",
        comments = "Generator version: 7.7.0")
public class UpdateEvaluationFormulaWithIdModel {
    public static final String SERIALIZED_NAME_DEFAULT_VALUE = "defaultValue";

    @SerializedName(SERIALIZED_NAME_DEFAULT_VALUE)
    private ValueModel defaultValue;

    public static final String SERIALIZED_NAME_TARGETING_RULES = "targetingRules";

    @SerializedName(SERIALIZED_NAME_TARGETING_RULES)
    private List targetingRules;

    public static final String SERIALIZED_NAME_PERCENTAGE_EVALUATION_ATTRIBUTE =
            "percentageEvaluationAttribute";

    @SerializedName(SERIALIZED_NAME_PERCENTAGE_EVALUATION_ATTRIBUTE)
    private String percentageEvaluationAttribute;

    public static final String SERIALIZED_NAME_SETTING_ID = "settingId";

    @SerializedName(SERIALIZED_NAME_SETTING_ID)
    private Integer settingId;

    public UpdateEvaluationFormulaWithIdModel() {}

    public UpdateEvaluationFormulaWithIdModel defaultValue(ValueModel defaultValue) {
        this.defaultValue = defaultValue;
        return this;
    }

    /**
     * Get defaultValue
     *
     * @return defaultValue
     */
    @javax.annotation.Nonnull
    public ValueModel getDefaultValue() {
        return defaultValue;
    }

    public void setDefaultValue(ValueModel defaultValue) {
        this.defaultValue = defaultValue;
    }

    public UpdateEvaluationFormulaWithIdModel targetingRules(
            List targetingRules) {
        this.targetingRules = targetingRules;
        return this;
    }

    public UpdateEvaluationFormulaWithIdModel addTargetingRulesItem(
            TargetingRuleModel targetingRulesItem) {
        if (this.targetingRules == null) {
            this.targetingRules = new ArrayList<>();
        }
        this.targetingRules.add(targetingRulesItem);
        return this;
    }

    /**
     * The targeting rules of the Feature Flag or Setting.
     *
     * @return targetingRules
     */
    @javax.annotation.Nullable
    public List getTargetingRules() {
        return targetingRules;
    }

    public void setTargetingRules(List targetingRules) {
        this.targetingRules = targetingRules;
    }

    public UpdateEvaluationFormulaWithIdModel percentageEvaluationAttribute(
            String percentageEvaluationAttribute) {
        this.percentageEvaluationAttribute = percentageEvaluationAttribute;
        return this;
    }

    /**
     * The user attribute used for percentage evaluation. If not set, it defaults to the
     * `Identifier` user object attribute.
     *
     * @return percentageEvaluationAttribute
     */
    @javax.annotation.Nullable
    public String getPercentageEvaluationAttribute() {
        return percentageEvaluationAttribute;
    }

    public void setPercentageEvaluationAttribute(String percentageEvaluationAttribute) {
        this.percentageEvaluationAttribute = percentageEvaluationAttribute;
    }

    public UpdateEvaluationFormulaWithIdModel settingId(Integer settingId) {
        this.settingId = settingId;
        return this;
    }

    /**
     * The identifier of the feature flag or setting.
     *
     * @return settingId
     */
    @javax.annotation.Nullable
    public Integer getSettingId() {
        return settingId;
    }

    public void setSettingId(Integer settingId) {
        this.settingId = settingId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        UpdateEvaluationFormulaWithIdModel updateEvaluationFormulaWithIdModel =
                (UpdateEvaluationFormulaWithIdModel) o;
        return Objects.equals(this.defaultValue, updateEvaluationFormulaWithIdModel.defaultValue)
                && Objects.equals(
                        this.targetingRules, updateEvaluationFormulaWithIdModel.targetingRules)
                && Objects.equals(
                        this.percentageEvaluationAttribute,
                        updateEvaluationFormulaWithIdModel.percentageEvaluationAttribute)
                && Objects.equals(this.settingId, updateEvaluationFormulaWithIdModel.settingId);
    }

    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(defaultValue, targetingRules, percentageEvaluationAttribute, settingId);
    }

    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 UpdateEvaluationFormulaWithIdModel {\n");
        sb.append("    defaultValue: ").append(toIndentedString(defaultValue)).append("\n");
        sb.append("    targetingRules: ").append(toIndentedString(targetingRules)).append("\n");
        sb.append("    percentageEvaluationAttribute: ")
                .append(toIndentedString(percentageEvaluationAttribute))
                .append("\n");
        sb.append("    settingId: ").append(toIndentedString(settingId)).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("defaultValue");
        openapiFields.add("targetingRules");
        openapiFields.add("percentageEvaluationAttribute");
        openapiFields.add("settingId");

        // a set of required properties/fields (JSON key names)
        openapiRequiredFields = new HashSet();
        openapiRequiredFields.add("defaultValue");
    }

    /**
     * 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
     *     UpdateEvaluationFormulaWithIdModel
     */
    public static void validateJsonElement(JsonElement jsonElement) throws IOException {
        if (jsonElement == null) {
            if (!UpdateEvaluationFormulaWithIdModel.openapiRequiredFields
                    .isEmpty()) { // has required fields but JSON element is null
                throw new IllegalArgumentException(
                        String.format(
                                "The required field(s) %s in UpdateEvaluationFormulaWithIdModel is"
                                        + " not found in the empty JSON string",
                                UpdateEvaluationFormulaWithIdModel.openapiRequiredFields
                                        .toString()));
            }
        }

        Set> entries = jsonElement.getAsJsonObject().entrySet();
        // check to see if the JSON string contains additional fields
        for (Map.Entry entry : entries) {
            if (!UpdateEvaluationFormulaWithIdModel.openapiFields.contains(entry.getKey())) {
                throw new IllegalArgumentException(
                        String.format(
                                "The field `%s` in the JSON string is not defined in the"
                                    + " `UpdateEvaluationFormulaWithIdModel` properties. JSON: %s",
                                entry.getKey(), jsonElement.toString()));
            }
        }

        // check to make sure all required properties/fields are present in the JSON string
        for (String requiredField : UpdateEvaluationFormulaWithIdModel.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();
        // validate the required field `defaultValue`
        ValueModel.validateJsonElement(jsonObj.get("defaultValue"));
        if (jsonObj.get("targetingRules") != null && !jsonObj.get("targetingRules").isJsonNull()) {
            JsonArray jsonArraytargetingRules = jsonObj.getAsJsonArray("targetingRules");
            if (jsonArraytargetingRules != null) {
                // ensure the json data is an array
                if (!jsonObj.get("targetingRules").isJsonArray()) {
                    throw new IllegalArgumentException(
                            String.format(
                                    "Expected the field `targetingRules` to be an array in the"
                                            + " JSON string but got `%s`",
                                    jsonObj.get("targetingRules").toString()));
                }

                // validate the optional field `targetingRules` (array)
                for (int i = 0; i < jsonArraytargetingRules.size(); i++) {
                    TargetingRuleModel.validateJsonElement(jsonArraytargetingRules.get(i));
                }
                ;
            }
        }
        if ((jsonObj.get("percentageEvaluationAttribute") != null
                        && !jsonObj.get("percentageEvaluationAttribute").isJsonNull())
                && !jsonObj.get("percentageEvaluationAttribute").isJsonPrimitive()) {
            throw new IllegalArgumentException(
                    String.format(
                            "Expected the field `percentageEvaluationAttribute` to be a primitive"
                                    + " type in the JSON string but got `%s`",
                            jsonObj.get("percentageEvaluationAttribute").toString()));
        }
    }

    public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
        @SuppressWarnings("unchecked")
        @Override
        public  TypeAdapter create(Gson gson, TypeToken type) {
            if (!UpdateEvaluationFormulaWithIdModel.class.isAssignableFrom(type.getRawType())) {
                return null; // this class only serializes 'UpdateEvaluationFormulaWithIdModel' and
                // its subtypes
            }
            final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
            final TypeAdapter thisAdapter =
                    gson.getDelegateAdapter(
                            this, TypeToken.get(UpdateEvaluationFormulaWithIdModel.class));

            return (TypeAdapter)
                    new TypeAdapter() {
                        @Override
                        public void write(JsonWriter out, UpdateEvaluationFormulaWithIdModel value)
                                throws IOException {
                            JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
                            elementAdapter.write(out, obj);
                        }

                        @Override
                        public UpdateEvaluationFormulaWithIdModel read(JsonReader in)
                                throws IOException {
                            JsonElement jsonElement = elementAdapter.read(in);
                            validateJsonElement(jsonElement);
                            return thisAdapter.fromJsonTree(jsonElement);
                        }
                    }.nullSafe();
        }
    }

    /**
     * Create an instance of UpdateEvaluationFormulaWithIdModel given an JSON string
     *
     * @param jsonString JSON string
     * @return An instance of UpdateEvaluationFormulaWithIdModel
     * @throws IOException if the JSON string is invalid with respect to
     *     UpdateEvaluationFormulaWithIdModel
     */
    public static UpdateEvaluationFormulaWithIdModel fromJson(String jsonString)
            throws IOException {
        return JSON.getGson().fromJson(jsonString, UpdateEvaluationFormulaWithIdModel.class);
    }

    /**
     * Convert an instance of UpdateEvaluationFormulaWithIdModel to an JSON string
     *
     * @return JSON string
     */
    public String toJson() {
        return JSON.getGson().toJson(this);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy