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

com.finbourne.notifications.model.Delivery Maven / Gradle / Ivy

There is a newer version: 2.0.75
Show newest version
/*
 * FINBOURNE Notifications 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.notifications.model;

import java.util.Objects;
import com.finbourne.notifications.model.Attempt;
import com.finbourne.notifications.model.ResourceId;
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 java.util.UUID;

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.notifications.JSON;

/**
 * Delivery
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class Delivery {
  public static final String SERIALIZED_NAME_ID = "id";
  @SerializedName(SERIALIZED_NAME_ID)
  private UUID id;

  public static final String SERIALIZED_NAME_EVENT_ID = "eventId";
  @SerializedName(SERIALIZED_NAME_EVENT_ID)
  private String eventId;

  public static final String SERIALIZED_NAME_SUBSCRIPTION_ID = "subscriptionId";
  @SerializedName(SERIALIZED_NAME_SUBSCRIPTION_ID)
  private ResourceId subscriptionId;

  public static final String SERIALIZED_NAME_NOTIFICATION_ID = "notificationId";
  @SerializedName(SERIALIZED_NAME_NOTIFICATION_ID)
  private String notificationId;

  public static final String SERIALIZED_NAME_DELIVERY_CHANNEL = "deliveryChannel";
  @SerializedName(SERIALIZED_NAME_DELIVERY_CHANNEL)
  private String deliveryChannel;

  public static final String SERIALIZED_NAME_MESSAGE_DETAILS = "messageDetails";
  @SerializedName(SERIALIZED_NAME_MESSAGE_DETAILS)
  private String messageDetails;

  public static final String SERIALIZED_NAME_ATTEMPTS = "attempts";
  @SerializedName(SERIALIZED_NAME_ATTEMPTS)
  private List attempts = new ArrayList<>();

  public Delivery() {
  }

  public Delivery id(UUID id) {
    
    this.id = id;
    return this;
  }

   /**
   * The identifier of the delivery.
   * @return id
  **/
  @jakarta.annotation.Nonnull
  public UUID getId() {
    return id;
  }


  public void setId(UUID id) {
    this.id = id;
  }


  public Delivery eventId(String eventId) {
    
    this.eventId = eventId;
    return this;
  }

   /**
   * The identifier of the associated event.
   * @return eventId
  **/
  @jakarta.annotation.Nonnull
  public String getEventId() {
    return eventId;
  }


  public void setEventId(String eventId) {
    this.eventId = eventId;
  }


  public Delivery subscriptionId(ResourceId subscriptionId) {
    
    this.subscriptionId = subscriptionId;
    return this;
  }

   /**
   * Get subscriptionId
   * @return subscriptionId
  **/
  @jakarta.annotation.Nonnull
  public ResourceId getSubscriptionId() {
    return subscriptionId;
  }


  public void setSubscriptionId(ResourceId subscriptionId) {
    this.subscriptionId = subscriptionId;
  }


  public Delivery notificationId(String notificationId) {
    
    this.notificationId = notificationId;
    return this;
  }

   /**
   * The identifier of the associated notification.
   * @return notificationId
  **/
  @jakarta.annotation.Nonnull
  public String getNotificationId() {
    return notificationId;
  }


  public void setNotificationId(String notificationId) {
    this.notificationId = notificationId;
  }


  public Delivery deliveryChannel(String deliveryChannel) {
    
    this.deliveryChannel = deliveryChannel;
    return this;
  }

   /**
   * The delivery channel of the message.
   * @return deliveryChannel
  **/
  @jakarta.annotation.Nonnull
  public String getDeliveryChannel() {
    return deliveryChannel;
  }


  public void setDeliveryChannel(String deliveryChannel) {
    this.deliveryChannel = deliveryChannel;
  }


  public Delivery messageDetails(String messageDetails) {
    
    this.messageDetails = messageDetails;
    return this;
  }

   /**
   * The Details of the delivery message as JSON string.
   * @return messageDetails
  **/
  @jakarta.annotation.Nonnull
  public String getMessageDetails() {
    return messageDetails;
  }


  public void setMessageDetails(String messageDetails) {
    this.messageDetails = messageDetails;
  }


  public Delivery attempts(List attempts) {
    
    this.attempts = attempts;
    return this;
  }

  public Delivery addAttemptsItem(Attempt attemptsItem) {
    if (this.attempts == null) {
      this.attempts = new ArrayList<>();
    }
    this.attempts.add(attemptsItem);
    return this;
  }

   /**
   * A list of all the delivery attempts made for this message.
   * @return attempts
  **/
  @jakarta.annotation.Nonnull
  public List getAttempts() {
    return attempts;
  }


  public void setAttempts(List attempts) {
    this.attempts = attempts;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    Delivery delivery = (Delivery) o;
    return Objects.equals(this.id, delivery.id) &&
        Objects.equals(this.eventId, delivery.eventId) &&
        Objects.equals(this.subscriptionId, delivery.subscriptionId) &&
        Objects.equals(this.notificationId, delivery.notificationId) &&
        Objects.equals(this.deliveryChannel, delivery.deliveryChannel) &&
        Objects.equals(this.messageDetails, delivery.messageDetails) &&
        Objects.equals(this.attempts, delivery.attempts);
  }

  @Override
  public int hashCode() {
    return Objects.hash(id, eventId, subscriptionId, notificationId, deliveryChannel, messageDetails, attempts);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("class Delivery {\n");
    sb.append("    id: ").append(toIndentedString(id)).append("\n");
    sb.append("    eventId: ").append(toIndentedString(eventId)).append("\n");
    sb.append("    subscriptionId: ").append(toIndentedString(subscriptionId)).append("\n");
    sb.append("    notificationId: ").append(toIndentedString(notificationId)).append("\n");
    sb.append("    deliveryChannel: ").append(toIndentedString(deliveryChannel)).append("\n");
    sb.append("    messageDetails: ").append(toIndentedString(messageDetails)).append("\n");
    sb.append("    attempts: ").append(toIndentedString(attempts)).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("id");
    openapiFields.add("eventId");
    openapiFields.add("subscriptionId");
    openapiFields.add("notificationId");
    openapiFields.add("deliveryChannel");
    openapiFields.add("messageDetails");
    openapiFields.add("attempts");

    // a set of required properties/fields (JSON key names)
    openapiRequiredFields = new HashSet();
    openapiRequiredFields.add("id");
    openapiRequiredFields.add("eventId");
    openapiRequiredFields.add("subscriptionId");
    openapiRequiredFields.add("notificationId");
    openapiRequiredFields.add("deliveryChannel");
    openapiRequiredFields.add("messageDetails");
    openapiRequiredFields.add("attempts");
  }

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

      // check to make sure all required properties/fields are present in the JSON string
      for (String requiredField : Delivery.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("id").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `id` to be a primitive type in the JSON string but got `%s`", jsonObj.get("id").toString()));
      }
      if (!jsonObj.get("eventId").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `eventId` to be a primitive type in the JSON string but got `%s`", jsonObj.get("eventId").toString()));
      }
      // validate the required field `subscriptionId`
      ResourceId.validateJsonElement(jsonObj.get("subscriptionId"));
      if (!jsonObj.get("notificationId").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `notificationId` to be a primitive type in the JSON string but got `%s`", jsonObj.get("notificationId").toString()));
      }
      if (!jsonObj.get("deliveryChannel").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `deliveryChannel` to be a primitive type in the JSON string but got `%s`", jsonObj.get("deliveryChannel").toString()));
      }
      if (!jsonObj.get("messageDetails").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `messageDetails` to be a primitive type in the JSON string but got `%s`", jsonObj.get("messageDetails").toString()));
      }
      // ensure the json data is an array
      if (!jsonObj.get("attempts").isJsonArray()) {
        throw new IllegalArgumentException(String.format("Expected the field `attempts` to be an array in the JSON string but got `%s`", jsonObj.get("attempts").toString()));
      }

      JsonArray jsonArrayattempts = jsonObj.getAsJsonArray("attempts");
      // validate the required field `attempts` (array)
      for (int i = 0; i < jsonArrayattempts.size(); i++) {
        Attempt.validateJsonElement(jsonArrayattempts.get(i));
      };
  }

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

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

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

       }.nullSafe();
    }
  }

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy