com.finbourne.workflow.model.WorkerConfiguration Maven / Gradle / Ivy
/*
* 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.Fail;
import com.finbourne.workflow.model.HealthCheck;
import com.finbourne.workflow.model.LuminesceView;
import com.finbourne.workflow.model.ResourceId;
import com.finbourne.workflow.model.SchedulerJob;
import com.finbourne.workflow.model.Sleep;
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.net.URI;
import java.util.Arrays;
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 WorkerConfiguration extends AbstractOpenApiSchema {
private static final Logger log = Logger.getLogger(WorkerConfiguration.class.getName());
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public TypeAdapter create(Gson gson, TypeToken type) {
if (!WorkerConfiguration.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'WorkerConfiguration' and its subtypes
}
final TypeAdapter elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter adapterFail = gson.getDelegateAdapter(this, TypeToken.get(Fail.class));
final TypeAdapter adapterHealthCheck = gson.getDelegateAdapter(this, TypeToken.get(HealthCheck.class));
final TypeAdapter adapterLuminesceView = gson.getDelegateAdapter(this, TypeToken.get(LuminesceView.class));
final TypeAdapter adapterSchedulerJob = gson.getDelegateAdapter(this, TypeToken.get(SchedulerJob.class));
final TypeAdapter adapterSleep = gson.getDelegateAdapter(this, TypeToken.get(Sleep.class));
return (TypeAdapter) new TypeAdapter() {
@Override
public void write(JsonWriter out, WorkerConfiguration value) throws IOException {
if (value == null || value.getActualInstance() == null) {
elementAdapter.write(out, null);
return;
}
// check if the actual instance is of the type `Fail`
if (value.getActualInstance() instanceof Fail) {
JsonElement element = adapterFail.toJsonTree((Fail)value.getActualInstance());
elementAdapter.write(out, element);
return;
}
// check if the actual instance is of the type `HealthCheck`
if (value.getActualInstance() instanceof HealthCheck) {
JsonElement element = adapterHealthCheck.toJsonTree((HealthCheck)value.getActualInstance());
elementAdapter.write(out, element);
return;
}
// check if the actual instance is of the type `LuminesceView`
if (value.getActualInstance() instanceof LuminesceView) {
JsonElement element = adapterLuminesceView.toJsonTree((LuminesceView)value.getActualInstance());
elementAdapter.write(out, element);
return;
}
// check if the actual instance is of the type `SchedulerJob`
if (value.getActualInstance() instanceof SchedulerJob) {
JsonElement element = adapterSchedulerJob.toJsonTree((SchedulerJob)value.getActualInstance());
elementAdapter.write(out, element);
return;
}
// check if the actual instance is of the type `Sleep`
if (value.getActualInstance() instanceof Sleep) {
JsonElement element = adapterSleep.toJsonTree((Sleep)value.getActualInstance());
elementAdapter.write(out, element);
return;
}
throw new IOException("Failed to serialize as the type doesn't match oneOf schemas: Fail, HealthCheck, LuminesceView, SchedulerJob, Sleep");
}
@Override
public WorkerConfiguration read(JsonReader in) throws IOException {
Object deserialized = null;
JsonElement jsonElement = elementAdapter.read(in);
int match = 0;
ArrayList errorMessages = new ArrayList<>();
TypeAdapter actualAdapter = elementAdapter;
// deserialize Fail
try {
// validate the JSON object to see if any exception is thrown
Fail.validateJsonElement(jsonElement);
actualAdapter = adapterFail;
match++;
log.log(Level.FINER, "Input data matches schema 'Fail'");
} catch (Exception e) {
// deserialization failed, continue
errorMessages.add(String.format("Deserialization for Fail failed with `%s`.", e.getMessage()));
log.log(Level.FINER, "Input data does not match schema 'Fail'", e);
}
// deserialize HealthCheck
try {
// validate the JSON object to see if any exception is thrown
HealthCheck.validateJsonElement(jsonElement);
actualAdapter = adapterHealthCheck;
match++;
log.log(Level.FINER, "Input data matches schema 'HealthCheck'");
} catch (Exception e) {
// deserialization failed, continue
errorMessages.add(String.format("Deserialization for HealthCheck failed with `%s`.", e.getMessage()));
log.log(Level.FINER, "Input data does not match schema 'HealthCheck'", e);
}
// deserialize LuminesceView
try {
// validate the JSON object to see if any exception is thrown
LuminesceView.validateJsonElement(jsonElement);
actualAdapter = adapterLuminesceView;
match++;
log.log(Level.FINER, "Input data matches schema 'LuminesceView'");
} catch (Exception e) {
// deserialization failed, continue
errorMessages.add(String.format("Deserialization for LuminesceView failed with `%s`.", e.getMessage()));
log.log(Level.FINER, "Input data does not match schema 'LuminesceView'", e);
}
// deserialize SchedulerJob
try {
// validate the JSON object to see if any exception is thrown
SchedulerJob.validateJsonElement(jsonElement);
actualAdapter = adapterSchedulerJob;
match++;
log.log(Level.FINER, "Input data matches schema 'SchedulerJob'");
} catch (Exception e) {
// deserialization failed, continue
errorMessages.add(String.format("Deserialization for SchedulerJob failed with `%s`.", e.getMessage()));
log.log(Level.FINER, "Input data does not match schema 'SchedulerJob'", e);
}
// deserialize Sleep
try {
// validate the JSON object to see if any exception is thrown
Sleep.validateJsonElement(jsonElement);
actualAdapter = adapterSleep;
match++;
log.log(Level.FINER, "Input data matches schema 'Sleep'");
} catch (Exception e) {
// deserialization failed, continue
errorMessages.add(String.format("Deserialization for Sleep failed with `%s`.", e.getMessage()));
log.log(Level.FINER, "Input data does not match schema 'Sleep'", e);
}
if (match == 1) {
WorkerConfiguration ret = new WorkerConfiguration();
ret.setActualInstance(actualAdapter.fromJsonTree(jsonElement));
return ret;
}
throw new IOException(String.format("Failed deserialization for WorkerConfiguration: %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 WorkerConfiguration() {
super("oneOf", Boolean.FALSE);
}
public WorkerConfiguration(Fail o) {
super("oneOf", Boolean.FALSE);
setActualInstance(o);
}
public WorkerConfiguration(HealthCheck o) {
super("oneOf", Boolean.FALSE);
setActualInstance(o);
}
public WorkerConfiguration(LuminesceView o) {
super("oneOf", Boolean.FALSE);
setActualInstance(o);
}
public WorkerConfiguration(SchedulerJob o) {
super("oneOf", Boolean.FALSE);
setActualInstance(o);
}
public WorkerConfiguration(Sleep o) {
super("oneOf", Boolean.FALSE);
setActualInstance(o);
}
static {
schemas.put("Fail", Fail.class);
schemas.put("HealthCheck", HealthCheck.class);
schemas.put("LuminesceView", LuminesceView.class);
schemas.put("SchedulerJob", SchedulerJob.class);
schemas.put("Sleep", Sleep.class);
}
@Override
public Map> getSchemas() {
return WorkerConfiguration.schemas;
}
/**
* Set the instance that matches the oneOf child schema, check
* the instance parameter is valid against the oneOf child schemas:
* Fail, HealthCheck, LuminesceView, SchedulerJob, Sleep
*
* It could be an instance of the 'oneOf' schemas.
*/
@Override
public void setActualInstance(Object instance) {
if (instance instanceof Fail) {
super.setActualInstance(instance);
return;
}
if (instance instanceof HealthCheck) {
super.setActualInstance(instance);
return;
}
if (instance instanceof LuminesceView) {
super.setActualInstance(instance);
return;
}
if (instance instanceof SchedulerJob) {
super.setActualInstance(instance);
return;
}
if (instance instanceof Sleep) {
super.setActualInstance(instance);
return;
}
throw new RuntimeException("Invalid instance type. Must be Fail, HealthCheck, LuminesceView, SchedulerJob, Sleep");
}
/**
* Get the actual instance, which can be the following:
* Fail, HealthCheck, LuminesceView, SchedulerJob, Sleep
*
* @return The actual instance (Fail, HealthCheck, LuminesceView, SchedulerJob, Sleep)
*/
@Override
public Object getActualInstance() {
return super.getActualInstance();
}
/**
* Get the actual instance of `Fail`. If the actual instance is not `Fail`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `Fail`
* @throws ClassCastException if the instance is not `Fail`
*/
public Fail getFail() throws ClassCastException {
return (Fail)super.getActualInstance();
}
/**
* Get the actual instance of `HealthCheck`. If the actual instance is not `HealthCheck`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `HealthCheck`
* @throws ClassCastException if the instance is not `HealthCheck`
*/
public HealthCheck getHealthCheck() throws ClassCastException {
return (HealthCheck)super.getActualInstance();
}
/**
* Get the actual instance of `LuminesceView`. If the actual instance is not `LuminesceView`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `LuminesceView`
* @throws ClassCastException if the instance is not `LuminesceView`
*/
public LuminesceView getLuminesceView() throws ClassCastException {
return (LuminesceView)super.getActualInstance();
}
/**
* Get the actual instance of `SchedulerJob`. If the actual instance is not `SchedulerJob`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `SchedulerJob`
* @throws ClassCastException if the instance is not `SchedulerJob`
*/
public SchedulerJob getSchedulerJob() throws ClassCastException {
return (SchedulerJob)super.getActualInstance();
}
/**
* Get the actual instance of `Sleep`. If the actual instance is not `Sleep`,
* the ClassCastException will be thrown.
*
* @return The actual instance of `Sleep`
* @throws ClassCastException if the instance is not `Sleep`
*/
public Sleep getSleep() throws ClassCastException {
return (Sleep)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 WorkerConfiguration
*/
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 Fail
try {
Fail.validateJsonElement(jsonElement);
validCount++;
} catch (Exception e) {
errorMessages.add(String.format("Deserialization for Fail failed with `%s`.", e.getMessage()));
// continue to the next one
}
// validate the json string with HealthCheck
try {
HealthCheck.validateJsonElement(jsonElement);
validCount++;
} catch (Exception e) {
errorMessages.add(String.format("Deserialization for HealthCheck failed with `%s`.", e.getMessage()));
// continue to the next one
}
// validate the json string with LuminesceView
try {
LuminesceView.validateJsonElement(jsonElement);
validCount++;
} catch (Exception e) {
errorMessages.add(String.format("Deserialization for LuminesceView failed with `%s`.", e.getMessage()));
// continue to the next one
}
// validate the json string with SchedulerJob
try {
SchedulerJob.validateJsonElement(jsonElement);
validCount++;
} catch (Exception e) {
errorMessages.add(String.format("Deserialization for SchedulerJob failed with `%s`.", e.getMessage()));
// continue to the next one
}
// validate the json string with Sleep
try {
Sleep.validateJsonElement(jsonElement);
validCount++;
} catch (Exception e) {
errorMessages.add(String.format("Deserialization for Sleep failed with `%s`.", e.getMessage()));
// continue to the next one
}
if (validCount != 1) {
throw new IOException(String.format("The JSON string is invalid for WorkerConfiguration with oneOf schemas: Fail, HealthCheck, LuminesceView, SchedulerJob, Sleep. %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 WorkerConfiguration given an JSON string
*
* @param jsonString JSON string
* @return An instance of WorkerConfiguration
* @throws IOException if the JSON string is invalid with respect to WorkerConfiguration
*/
public static WorkerConfiguration fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, WorkerConfiguration.class);
}
/**
* Convert an instance of WorkerConfiguration to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy