com.finbourne.scheduler.model.Image Maven / Gradle / Ivy
/*
* FINBOURNE Scheduler 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.scheduler.model;
import java.util.Objects;
import com.finbourne.scheduler.model.ScanReport;
import com.finbourne.scheduler.model.Tag;
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.time.OffsetDateTime;
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.scheduler.JSON;
/**
* Represents the metadata of an image
*/
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class Image {
public static final String SERIALIZED_NAME_NAME = "name";
@SerializedName(SERIALIZED_NAME_NAME)
private String name;
public static final String SERIALIZED_NAME_PUSH_TIME = "pushTime";
@SerializedName(SERIALIZED_NAME_PUSH_TIME)
private OffsetDateTime pushTime;
public static final String SERIALIZED_NAME_PULL_TIME = "pullTime";
@SerializedName(SERIALIZED_NAME_PULL_TIME)
private OffsetDateTime pullTime;
public static final String SERIALIZED_NAME_DIGEST = "digest";
@SerializedName(SERIALIZED_NAME_DIGEST)
private String digest;
public static final String SERIALIZED_NAME_SIZE = "size";
@SerializedName(SERIALIZED_NAME_SIZE)
private Long size;
public static final String SERIALIZED_NAME_TAGS = "tags";
@SerializedName(SERIALIZED_NAME_TAGS)
private List tags;
public static final String SERIALIZED_NAME_SCAN_REPORT = "scanReport";
@SerializedName(SERIALIZED_NAME_SCAN_REPORT)
private ScanReport scanReport;
public Image() {
}
public Image name(String name) {
this.name = name;
return this;
}
/**
* Name of the image
* @return name
**/
@jakarta.annotation.Nullable
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Image pushTime(OffsetDateTime pushTime) {
this.pushTime = pushTime;
return this;
}
/**
* The push time of the image
* @return pushTime
**/
@jakarta.annotation.Nullable
public OffsetDateTime getPushTime() {
return pushTime;
}
public void setPushTime(OffsetDateTime pushTime) {
this.pushTime = pushTime;
}
public Image pullTime(OffsetDateTime pullTime) {
this.pullTime = pullTime;
return this;
}
/**
* The latest pull time of the image
* @return pullTime
**/
@jakarta.annotation.Nullable
public OffsetDateTime getPullTime() {
return pullTime;
}
public void setPullTime(OffsetDateTime pullTime) {
this.pullTime = pullTime;
}
public Image digest(String digest) {
this.digest = digest;
return this;
}
/**
* The digest of the image
* @return digest
**/
@jakarta.annotation.Nullable
public String getDigest() {
return digest;
}
public void setDigest(String digest) {
this.digest = digest;
}
public Image size(Long size) {
this.size = size;
return this;
}
/**
* The size of the image (in bytes)
* @return size
**/
@jakarta.annotation.Nullable
public Long getSize() {
return size;
}
public void setSize(Long size) {
this.size = size;
}
public Image tags(List tags) {
this.tags = tags;
return this;
}
public Image addTagsItem(Tag tagsItem) {
if (this.tags == null) {
this.tags = new ArrayList<>();
}
this.tags.add(tagsItem);
return this;
}
/**
* The tags of the image
* @return tags
**/
@jakarta.annotation.Nullable
public List getTags() {
return tags;
}
public void setTags(List tags) {
this.tags = tags;
}
public Image scanReport(ScanReport scanReport) {
this.scanReport = scanReport;
return this;
}
/**
* Get scanReport
* @return scanReport
**/
@jakarta.annotation.Nullable
public ScanReport getScanReport() {
return scanReport;
}
public void setScanReport(ScanReport scanReport) {
this.scanReport = scanReport;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Image image = (Image) o;
return Objects.equals(this.name, image.name) &&
Objects.equals(this.pushTime, image.pushTime) &&
Objects.equals(this.pullTime, image.pullTime) &&
Objects.equals(this.digest, image.digest) &&
Objects.equals(this.size, image.size) &&
Objects.equals(this.tags, image.tags) &&
Objects.equals(this.scanReport, image.scanReport);
}
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(name, pushTime, pullTime, digest, size, tags, scanReport);
}
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 Image {\n");
sb.append(" name: ").append(toIndentedString(name)).append("\n");
sb.append(" pushTime: ").append(toIndentedString(pushTime)).append("\n");
sb.append(" pullTime: ").append(toIndentedString(pullTime)).append("\n");
sb.append(" digest: ").append(toIndentedString(digest)).append("\n");
sb.append(" size: ").append(toIndentedString(size)).append("\n");
sb.append(" tags: ").append(toIndentedString(tags)).append("\n");
sb.append(" scanReport: ").append(toIndentedString(scanReport)).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("name");
openapiFields.add("pushTime");
openapiFields.add("pullTime");
openapiFields.add("digest");
openapiFields.add("size");
openapiFields.add("tags");
openapiFields.add("scanReport");
// 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 Image
*/
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
if (jsonElement == null) {
if (!Image.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
throw new IllegalArgumentException(String.format("The required field(s) %s in Image is not found in the empty JSON string", Image.openapiRequiredFields.toString()));
}
}
JsonObject jsonObj = jsonElement.getAsJsonObject();
if ((jsonObj.get("name") != null && !jsonObj.get("name").isJsonNull()) && !jsonObj.get("name").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `name` to be a primitive type in the JSON string but got `%s`", jsonObj.get("name").toString()));
}
if ((jsonObj.get("digest") != null && !jsonObj.get("digest").isJsonNull()) && !jsonObj.get("digest").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `digest` to be a primitive type in the JSON string but got `%s`", jsonObj.get("digest").toString()));
}
if (jsonObj.get("tags") != null && !jsonObj.get("tags").isJsonNull()) {
JsonArray jsonArraytags = jsonObj.getAsJsonArray("tags");
if (jsonArraytags != null) {
// ensure the json data is an array
if (!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()));
}
// validate the optional field `tags` (array)
for (int i = 0; i < jsonArraytags.size(); i++) {
Tag.validateJsonElement(jsonArraytags.get(i));
};
}
}
// validate the optional field `scanReport`
if (jsonObj.get("scanReport") != null && !jsonObj.get("scanReport").isJsonNull()) {
ScanReport.validateJsonElement(jsonObj.get("scanReport"));
}
}
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (!Image.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'Image' and its subtypes
}
final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(Image.class));
return (TypeAdapter) new TypeAdapter() {
@Override
public void write(JsonWriter out, Image value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}
@Override
public Image read(JsonReader in) throws IOException {
JsonElement jsonElement = elementAdapter.read(in);
validateJsonElement(jsonElement);
return thisAdapter.fromJsonTree(jsonElement);
}
}.nullSafe();
}
}
/**
* Create an instance of Image given an JSON string
*
* @param jsonString JSON string
* @return An instance of Image
* @throws IOException if the JSON string is invalid with respect to Image
*/
public static Image fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, Image.class);
}
/**
* Convert an instance of Image to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}