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

com.finbourne.workflow.model.WorkerConfigurationResponse Maven / Gradle / Ivy

There is a newer version: 2.0.166
Show newest version
/*
 * FINBOURNE Workflow 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.workflow.model;

import java.util.Objects;
import com.finbourne.workflow.model.FailResponse;
import com.finbourne.workflow.model.HealthCheckResponse;
import com.finbourne.workflow.model.LuminesceViewResponse;
import com.finbourne.workflow.model.ResourceId;
import com.finbourne.workflow.model.SchedulerJobResponse;
import com.finbourne.workflow.model.SleepResponse;
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.Arrays;
import org.openapitools.jackson.nullable.JsonNullable;



import java.io.IOException;
import java.lang.reflect.Type;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.google.gson.TypeAdapter;
import com.google.gson.TypeAdapterFactory;
import com.google.gson.reflect.TypeToken;
import com.google.gson.JsonPrimitive;
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 com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonArray;
import com.google.gson.JsonParseException;

import com.finbourne.workflow.JSON;

@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class WorkerConfigurationResponse extends AbstractOpenApiSchema {
    private static final Logger log = Logger.getLogger(WorkerConfigurationResponse.class.getName());

    public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
        @SuppressWarnings("unchecked")
        @Override
        public  TypeAdapter create(Gson gson, TypeToken type) {
            if (!WorkerConfigurationResponse.class.isAssignableFrom(type.getRawType())) {
                return null; // this class only serializes 'WorkerConfigurationResponse' and its subtypes
            }
            final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
            final TypeAdapter adapterFailResponse = gson.getDelegateAdapter(this, TypeToken.get(FailResponse.class));
            final TypeAdapter adapterHealthCheckResponse = gson.getDelegateAdapter(this, TypeToken.get(HealthCheckResponse.class));
            final TypeAdapter adapterLuminesceViewResponse = gson.getDelegateAdapter(this, TypeToken.get(LuminesceViewResponse.class));
            final TypeAdapter adapterSchedulerJobResponse = gson.getDelegateAdapter(this, TypeToken.get(SchedulerJobResponse.class));
            final TypeAdapter adapterSleepResponse = gson.getDelegateAdapter(this, TypeToken.get(SleepResponse.class));

            return (TypeAdapter) new TypeAdapter() {
                @Override
                public void write(JsonWriter out, WorkerConfigurationResponse value) throws IOException {
                    if (value == null || value.getActualInstance() == null) {
                        elementAdapter.write(out, null);
                        return;
                    }

                    // check if the actual instance is of the type `FailResponse`
                    if (value.getActualInstance() instanceof FailResponse) {
                      JsonElement element = adapterFailResponse.toJsonTree((FailResponse)value.getActualInstance());
                      elementAdapter.write(out, element);
                      return;
                    }
                    // check if the actual instance is of the type `HealthCheckResponse`
                    if (value.getActualInstance() instanceof HealthCheckResponse) {
                      JsonElement element = adapterHealthCheckResponse.toJsonTree((HealthCheckResponse)value.getActualInstance());
                      elementAdapter.write(out, element);
                      return;
                    }
                    // check if the actual instance is of the type `LuminesceViewResponse`
                    if (value.getActualInstance() instanceof LuminesceViewResponse) {
                      JsonElement element = adapterLuminesceViewResponse.toJsonTree((LuminesceViewResponse)value.getActualInstance());
                      elementAdapter.write(out, element);
                      return;
                    }
                    // check if the actual instance is of the type `SchedulerJobResponse`
                    if (value.getActualInstance() instanceof SchedulerJobResponse) {
                      JsonElement element = adapterSchedulerJobResponse.toJsonTree((SchedulerJobResponse)value.getActualInstance());
                      elementAdapter.write(out, element);
                      return;
                    }
                    // check if the actual instance is of the type `SleepResponse`
                    if (value.getActualInstance() instanceof SleepResponse) {
                      JsonElement element = adapterSleepResponse.toJsonTree((SleepResponse)value.getActualInstance());
                      elementAdapter.write(out, element);
                      return;
                    }
                    throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: FailResponse, HealthCheckResponse, LuminesceViewResponse, SchedulerJobResponse, SleepResponse");
                }

                @Override
                public WorkerConfigurationResponse read(JsonReader in) throws IOException {
                    Object deserialized = null;
                    JsonElement jsonElement = elementAdapter.read(in);

                    int match = 0;
                    ArrayList errorMessages = new ArrayList<>();
                    TypeAdapter actualAdapter = elementAdapter;

                    // deserialize FailResponse
                    try {
                      // validate the JSON object to see if any exception is thrown
                      FailResponse.validateJsonElement(jsonElement);
                      actualAdapter = adapterFailResponse;
                      match++;
                      log.log(Level.FINER, "Input data matches schema 'FailResponse'");
                    } catch (Exception e) {
                      // deserialization failed, continue
                      errorMessages.add(String.format("Deserialization for FailResponse failed with `%s`.", e.getMessage()));
                      log.log(Level.FINER, "Input data does not match schema 'FailResponse'", e);
                    }
                    // deserialize HealthCheckResponse
                    try {
                      // validate the JSON object to see if any exception is thrown
                      HealthCheckResponse.validateJsonElement(jsonElement);
                      actualAdapter = adapterHealthCheckResponse;
                      match++;
                      log.log(Level.FINER, "Input data matches schema 'HealthCheckResponse'");
                    } catch (Exception e) {
                      // deserialization failed, continue
                      errorMessages.add(String.format("Deserialization for HealthCheckResponse failed with `%s`.", e.getMessage()));
                      log.log(Level.FINER, "Input data does not match schema 'HealthCheckResponse'", e);
                    }
                    // deserialize LuminesceViewResponse
                    try {
                      // validate the JSON object to see if any exception is thrown
                      LuminesceViewResponse.validateJsonElement(jsonElement);
                      actualAdapter = adapterLuminesceViewResponse;
                      match++;
                      log.log(Level.FINER, "Input data matches schema 'LuminesceViewResponse'");
                    } catch (Exception e) {
                      // deserialization failed, continue
                      errorMessages.add(String.format("Deserialization for LuminesceViewResponse failed with `%s`.", e.getMessage()));
                      log.log(Level.FINER, "Input data does not match schema 'LuminesceViewResponse'", e);
                    }
                    // deserialize SchedulerJobResponse
                    try {
                      // validate the JSON object to see if any exception is thrown
                      SchedulerJobResponse.validateJsonElement(jsonElement);
                      actualAdapter = adapterSchedulerJobResponse;
                      match++;
                      log.log(Level.FINER, "Input data matches schema 'SchedulerJobResponse'");
                    } catch (Exception e) {
                      // deserialization failed, continue
                      errorMessages.add(String.format("Deserialization for SchedulerJobResponse failed with `%s`.", e.getMessage()));
                      log.log(Level.FINER, "Input data does not match schema 'SchedulerJobResponse'", e);
                    }
                    // deserialize SleepResponse
                    try {
                      // validate the JSON object to see if any exception is thrown
                      SleepResponse.validateJsonElement(jsonElement);
                      actualAdapter = adapterSleepResponse;
                      match++;
                      log.log(Level.FINER, "Input data matches schema 'SleepResponse'");
                    } catch (Exception e) {
                      // deserialization failed, continue
                      errorMessages.add(String.format("Deserialization for SleepResponse failed with `%s`.", e.getMessage()));
                      log.log(Level.FINER, "Input data does not match schema 'SleepResponse'", e);
                    }

                    if (match == 1) {
                        WorkerConfigurationResponse ret = new WorkerConfigurationResponse();
                        ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement));
                        return ret;
                    }

                    throw new IOException(String.format("Failed deserialization for WorkerConfigurationResponse: %d classes match result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", match, errorMessages, jsonElement.toString()));
                }
            }.nullSafe();
        }
    }

    // store a list of schema names defined in oneOf
    public static final Map> schemas = new HashMap>();

    public WorkerConfigurationResponse() {
        super("oneOf", Boolean.FALSE);
    }

    public WorkerConfigurationResponse(FailResponse o) {
        super("oneOf", Boolean.FALSE);
        setActualInstance(o);
    }

    public WorkerConfigurationResponse(HealthCheckResponse o) {
        super("oneOf", Boolean.FALSE);
        setActualInstance(o);
    }

    public WorkerConfigurationResponse(LuminesceViewResponse o) {
        super("oneOf", Boolean.FALSE);
        setActualInstance(o);
    }

    public WorkerConfigurationResponse(SchedulerJobResponse o) {
        super("oneOf", Boolean.FALSE);
        setActualInstance(o);
    }

    public WorkerConfigurationResponse(SleepResponse o) {
        super("oneOf", Boolean.FALSE);
        setActualInstance(o);
    }

    static {
        schemas.put("FailResponse", FailResponse.class);
        schemas.put("HealthCheckResponse", HealthCheckResponse.class);
        schemas.put("LuminesceViewResponse", LuminesceViewResponse.class);
        schemas.put("SchedulerJobResponse", SchedulerJobResponse.class);
        schemas.put("SleepResponse", SleepResponse.class);
    }

    @Override
    public Map> getSchemas() {
        return WorkerConfigurationResponse.schemas;
    }

    /**
     * Set the instance that matches the oneOf child schema, check
     * the instance parameter is valid against the oneOf child schemas:
     * FailResponse, HealthCheckResponse, LuminesceViewResponse, SchedulerJobResponse, SleepResponse
     *
     * It could be an instance of the 'oneOf' schemas.
     */
    @Override
    public void setActualInstance(Object instance) {
        if (instance instanceof FailResponse) {
            super.setActualInstance(instance);
            return;
        }

        if (instance instanceof HealthCheckResponse) {
            super.setActualInstance(instance);
            return;
        }

        if (instance instanceof LuminesceViewResponse) {
            super.setActualInstance(instance);
            return;
        }

        if (instance instanceof SchedulerJobResponse) {
            super.setActualInstance(instance);
            return;
        }

        if (instance instanceof SleepResponse) {
            super.setActualInstance(instance);
            return;
        }

        throw new RuntimeException("Invalid instance type. Must be FailResponse, HealthCheckResponse, LuminesceViewResponse, SchedulerJobResponse, SleepResponse");
    }

    /**
     * Get the actual instance, which can be the following:
     * FailResponse, HealthCheckResponse, LuminesceViewResponse, SchedulerJobResponse, SleepResponse
     *
     * @return The actual instance (FailResponse, HealthCheckResponse, LuminesceViewResponse, SchedulerJobResponse, SleepResponse)
     */
    @Override
    public Object getActualInstance() {
        return super.getActualInstance();
    }

    /**
     * Get the actual instance of `FailResponse`. If the actual instance is not `FailResponse`,
     * the ClassCastException will be thrown.
     *
     * @return The actual instance of `FailResponse`
     * @throws ClassCastException if the instance is not `FailResponse`
     */
    public FailResponse getFailResponse() throws ClassCastException {
        return (FailResponse)super.getActualInstance();
    }
    /**
     * Get the actual instance of `HealthCheckResponse`. If the actual instance is not `HealthCheckResponse`,
     * the ClassCastException will be thrown.
     *
     * @return The actual instance of `HealthCheckResponse`
     * @throws ClassCastException if the instance is not `HealthCheckResponse`
     */
    public HealthCheckResponse getHealthCheckResponse() throws ClassCastException {
        return (HealthCheckResponse)super.getActualInstance();
    }
    /**
     * Get the actual instance of `LuminesceViewResponse`. If the actual instance is not `LuminesceViewResponse`,
     * the ClassCastException will be thrown.
     *
     * @return The actual instance of `LuminesceViewResponse`
     * @throws ClassCastException if the instance is not `LuminesceViewResponse`
     */
    public LuminesceViewResponse getLuminesceViewResponse() throws ClassCastException {
        return (LuminesceViewResponse)super.getActualInstance();
    }
    /**
     * Get the actual instance of `SchedulerJobResponse`. If the actual instance is not `SchedulerJobResponse`,
     * the ClassCastException will be thrown.
     *
     * @return The actual instance of `SchedulerJobResponse`
     * @throws ClassCastException if the instance is not `SchedulerJobResponse`
     */
    public SchedulerJobResponse getSchedulerJobResponse() throws ClassCastException {
        return (SchedulerJobResponse)super.getActualInstance();
    }
    /**
     * Get the actual instance of `SleepResponse`. If the actual instance is not `SleepResponse`,
     * the ClassCastException will be thrown.
     *
     * @return The actual instance of `SleepResponse`
     * @throws ClassCastException if the instance is not `SleepResponse`
     */
    public SleepResponse getSleepResponse() throws ClassCastException {
        return (SleepResponse)super.getActualInstance();
    }

 /**
  * 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 WorkerConfigurationResponse
  */
  public static void validateJsonElement(JsonElement jsonElement) throws IOException {
    // validate oneOf schemas one by one
    int validCount = 0;
    ArrayList errorMessages = new ArrayList<>();
    // validate the json string with FailResponse
    try {
      FailResponse.validateJsonElement(jsonElement);
      validCount++;
    } catch (Exception e) {
      errorMessages.add(String.format("Deserialization for FailResponse failed with `%s`.", e.getMessage()));
      // continue to the next one
    }
    // validate the json string with HealthCheckResponse
    try {
      HealthCheckResponse.validateJsonElement(jsonElement);
      validCount++;
    } catch (Exception e) {
      errorMessages.add(String.format("Deserialization for HealthCheckResponse failed with `%s`.", e.getMessage()));
      // continue to the next one
    }
    // validate the json string with LuminesceViewResponse
    try {
      LuminesceViewResponse.validateJsonElement(jsonElement);
      validCount++;
    } catch (Exception e) {
      errorMessages.add(String.format("Deserialization for LuminesceViewResponse failed with `%s`.", e.getMessage()));
      // continue to the next one
    }
    // validate the json string with SchedulerJobResponse
    try {
      SchedulerJobResponse.validateJsonElement(jsonElement);
      validCount++;
    } catch (Exception e) {
      errorMessages.add(String.format("Deserialization for SchedulerJobResponse failed with `%s`.", e.getMessage()));
      // continue to the next one
    }
    // validate the json string with SleepResponse
    try {
      SleepResponse.validateJsonElement(jsonElement);
      validCount++;
    } catch (Exception e) {
      errorMessages.add(String.format("Deserialization for SleepResponse failed with `%s`.", e.getMessage()));
      // continue to the next one
    }
    if (validCount != 1) {
      throw new IOException(String.format("The JSON string is invalid for WorkerConfigurationResponse with oneOf schemas: FailResponse, HealthCheckResponse, LuminesceViewResponse, SchedulerJobResponse, SleepResponse. %d class(es) match the result, expected 1. Detailed failure message for oneOf schemas: %s. JSON: %s", validCount, errorMessages, jsonElement.toString()));
    }
  }

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

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





© 2015 - 2024 Weber Informatics LLC | Privacy Policy