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

com.finbourne.access.model.PolicyTemplateResponse Maven / Gradle / Ivy

The newest version!
/*
 * FINBOURNE Access Management 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.access.model;

import java.util.Objects;
import com.finbourne.access.model.PolicyTemplatedSelector;
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.access.JSON;

/**
 * Response object for a policy template
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class PolicyTemplateResponse {
  public static final String SERIALIZED_NAME_DISPLAY_NAME = "displayName";
  @SerializedName(SERIALIZED_NAME_DISPLAY_NAME)
  private String displayName;

  public static final String SERIALIZED_NAME_SCOPE = "scope";
  @SerializedName(SERIALIZED_NAME_SCOPE)
  private String scope;

  public static final String SERIALIZED_NAME_CODE = "code";
  @SerializedName(SERIALIZED_NAME_CODE)
  private String code;

  public static final String SERIALIZED_NAME_DESCRIPTION = "description";
  @SerializedName(SERIALIZED_NAME_DESCRIPTION)
  private String description;

  public static final String SERIALIZED_NAME_APPLICATIONS = "applications";
  @SerializedName(SERIALIZED_NAME_APPLICATIONS)
  private List applications;

  public static final String SERIALIZED_NAME_TAGS = "tags";
  @SerializedName(SERIALIZED_NAME_TAGS)
  private List tags;

  public static final String SERIALIZED_NAME_TEMPLATED_SELECTORS = "templatedSelectors";
  @SerializedName(SERIALIZED_NAME_TEMPLATED_SELECTORS)
  private List templatedSelectors;

  public PolicyTemplateResponse() {
  }

  public PolicyTemplateResponse displayName(String displayName) {
    
    this.displayName = displayName;
    return this;
  }

   /**
   * Display name of the policy template being created
   * @return displayName
  **/
  @jakarta.annotation.Nullable
  public String getDisplayName() {
    return displayName;
  }


  public void setDisplayName(String displayName) {
    this.displayName = displayName;
  }


  public PolicyTemplateResponse scope(String scope) {
    
    this.scope = scope;
    return this;
  }

   /**
   * The Scope of the policy template being created
   * @return scope
  **/
  @jakarta.annotation.Nullable
  public String getScope() {
    return scope;
  }


  public void setScope(String scope) {
    this.scope = scope;
  }


  public PolicyTemplateResponse code(String code) {
    
    this.code = code;
    return this;
  }

   /**
   * The Code of the policy template being created
   * @return code
  **/
  @jakarta.annotation.Nullable
  public String getCode() {
    return code;
  }


  public void setCode(String code) {
    this.code = code;
  }


  public PolicyTemplateResponse description(String description) {
    
    this.description = description;
    return this;
  }

   /**
   * Description of the policy template being created
   * @return description
  **/
  @jakarta.annotation.Nullable
  public String getDescription() {
    return description;
  }


  public void setDescription(String description) {
    this.description = description;
  }


  public PolicyTemplateResponse applications(List applications) {
    
    this.applications = applications;
    return this;
  }

  public PolicyTemplateResponse addApplicationsItem(String applicationsItem) {
    if (this.applications == null) {
      this.applications = new ArrayList<>();
    }
    this.applications.add(applicationsItem);
    return this;
  }

   /**
   * List of applications that this policy template covers
   * @return applications
  **/
  @jakarta.annotation.Nullable
  public List getApplications() {
    return applications;
  }


  public void setApplications(List applications) {
    this.applications = applications;
  }


  public PolicyTemplateResponse tags(List tags) {
    
    this.tags = tags;
    return this;
  }

  public PolicyTemplateResponse addTagsItem(String tagsItem) {
    if (this.tags == null) {
      this.tags = new ArrayList<>();
    }
    this.tags.add(tagsItem);
    return this;
  }

   /**
   * List of policy types that this policy template covers
   * @return tags
  **/
  @jakarta.annotation.Nullable
  public List getTags() {
    return tags;
  }


  public void setTags(List tags) {
    this.tags = tags;
  }


  public PolicyTemplateResponse templatedSelectors(List templatedSelectors) {
    
    this.templatedSelectors = templatedSelectors;
    return this;
  }

  public PolicyTemplateResponse addTemplatedSelectorsItem(PolicyTemplatedSelector templatedSelectorsItem) {
    if (this.templatedSelectors == null) {
      this.templatedSelectors = new ArrayList<>();
    }
    this.templatedSelectors.add(templatedSelectorsItem);
    return this;
  }

   /**
   * The selector definitions of policies included in this policy template
   * @return templatedSelectors
  **/
  @jakarta.annotation.Nullable
  public List getTemplatedSelectors() {
    return templatedSelectors;
  }


  public void setTemplatedSelectors(List templatedSelectors) {
    this.templatedSelectors = templatedSelectors;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    PolicyTemplateResponse policyTemplateResponse = (PolicyTemplateResponse) o;
    return Objects.equals(this.displayName, policyTemplateResponse.displayName) &&
        Objects.equals(this.scope, policyTemplateResponse.scope) &&
        Objects.equals(this.code, policyTemplateResponse.code) &&
        Objects.equals(this.description, policyTemplateResponse.description) &&
        Objects.equals(this.applications, policyTemplateResponse.applications) &&
        Objects.equals(this.tags, policyTemplateResponse.tags) &&
        Objects.equals(this.templatedSelectors, policyTemplateResponse.templatedSelectors);
  }

  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(displayName, scope, code, description, applications, tags, templatedSelectors);
  }

  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 PolicyTemplateResponse {\n");
    sb.append("    displayName: ").append(toIndentedString(displayName)).append("\n");
    sb.append("    scope: ").append(toIndentedString(scope)).append("\n");
    sb.append("    code: ").append(toIndentedString(code)).append("\n");
    sb.append("    description: ").append(toIndentedString(description)).append("\n");
    sb.append("    applications: ").append(toIndentedString(applications)).append("\n");
    sb.append("    tags: ").append(toIndentedString(tags)).append("\n");
    sb.append("    templatedSelectors: ").append(toIndentedString(templatedSelectors)).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("displayName");
    openapiFields.add("scope");
    openapiFields.add("code");
    openapiFields.add("description");
    openapiFields.add("applications");
    openapiFields.add("tags");
    openapiFields.add("templatedSelectors");

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

 /**
  * 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 PolicyTemplateResponse
  */
  public static void validateJsonElement(JsonElement jsonElement) throws IOException {
      if (jsonElement == null) {
        if (!PolicyTemplateResponse.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
          throw new IllegalArgumentException(String.format("The required field(s) %s in PolicyTemplateResponse is not found in the empty JSON string", PolicyTemplateResponse.openapiRequiredFields.toString()));
        }
      }
        JsonObject jsonObj = jsonElement.getAsJsonObject();
      if ((jsonObj.get("displayName") != null && !jsonObj.get("displayName").isJsonNull()) && !jsonObj.get("displayName").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `displayName` to be a primitive type in the JSON string but got `%s`", jsonObj.get("displayName").toString()));
      }
      if ((jsonObj.get("scope") != null && !jsonObj.get("scope").isJsonNull()) && !jsonObj.get("scope").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `scope` to be a primitive type in the JSON string but got `%s`", jsonObj.get("scope").toString()));
      }
      if ((jsonObj.get("code") != null && !jsonObj.get("code").isJsonNull()) && !jsonObj.get("code").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `code` to be a primitive type in the JSON string but got `%s`", jsonObj.get("code").toString()));
      }
      if ((jsonObj.get("description") != null && !jsonObj.get("description").isJsonNull()) && !jsonObj.get("description").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `description` to be a primitive type in the JSON string but got `%s`", jsonObj.get("description").toString()));
      }
      // ensure the optional json data is an array if present
      if (jsonObj.get("applications") != null && !jsonObj.get("applications").isJsonNull() && !jsonObj.get("applications").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `applications` to be an array in the JSON string but got `%s`", jsonObj.get("applications").toString()));
      }
      // ensure the optional json data is an array if present
      if (jsonObj.get("tags") != null && !jsonObj.get("tags").isJsonNull() && !jsonObj.get("tags").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `tags` to be an array in the JSON string but got `%s`", jsonObj.get("tags").toString()));
      }
      if (jsonObj.get("templatedSelectors") != null && !jsonObj.get("templatedSelectors").isJsonNull()) {
        JsonArray jsonArraytemplatedSelectors = jsonObj.getAsJsonArray("templatedSelectors");
        if (jsonArraytemplatedSelectors != null) {
          // ensure the json data is an array
          if (!jsonObj.get("templatedSelectors").isJsonArray()) {
            throw new IllegalArgumentException(String.format("Expected the field `templatedSelectors` to be an array in the JSON string but got `%s`", jsonObj.get("templatedSelectors").toString()));
          }

          // validate the optional field `templatedSelectors` (array)
          for (int i = 0; i < jsonArraytemplatedSelectors.size(); i++) {
            PolicyTemplatedSelector.validateJsonElement(jsonArraytemplatedSelectors.get(i));
          };
        }
      }
  }

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

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

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

       }.nullSafe();
    }
  }

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy