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

com.finbourne.workflow.model.CreateNewTaskActivity 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.EventHandlerMapping;
import com.finbourne.workflow.model.FieldMapping;
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.HashMap;
import java.util.List;
import java.util.Map;
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.workflow.JSON;

/**
 * Define a Task Activity that creates a new task
 */
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class CreateNewTaskActivity {
  public static final String SERIALIZED_NAME_INITIAL_TRIGGER = "initialTrigger";
  @SerializedName(SERIALIZED_NAME_INITIAL_TRIGGER)
  private String initialTrigger;

  /**
   * The type of task activity
   */
  @JsonAdapter(TypeEnum.Adapter.class)
  public enum TypeEnum {
    CREATENEWTASK("CreateNewTask");

    private String value;

    TypeEnum(String value) {
      this.value = value;
    }

    public String getValue() {
      return value;
    }

    @Override
    public String toString() {
      return String.valueOf(value);
    }

    public static TypeEnum fromValue(String value) {
      for (TypeEnum b : TypeEnum.values()) {
        if (b.value.equals(value)) {
          return b;
        }
      }
      throw new IllegalArgumentException("Unexpected value '" + value + "'");
    }

    public static class Adapter extends TypeAdapter {
      @Override
      public void write(final JsonWriter jsonWriter, final TypeEnum enumeration) throws IOException {
        jsonWriter.value(enumeration.getValue());
      }

      @Override
      public TypeEnum read(final JsonReader jsonReader) throws IOException {
        String value =  jsonReader.nextString();
        return TypeEnum.fromValue(value);
      }
    }
  }

  public static final String SERIALIZED_NAME_TYPE = "type";
  @SerializedName(SERIALIZED_NAME_TYPE)
  private TypeEnum type;

  public static final String SERIALIZED_NAME_CORRELATION_IDS = "correlationIds";
  @SerializedName(SERIALIZED_NAME_CORRELATION_IDS)
  private List correlationIds;

  public static final String SERIALIZED_NAME_TASK_FIELDS = "taskFields";
  @SerializedName(SERIALIZED_NAME_TASK_FIELDS)
  private Map taskFields;

  public CreateNewTaskActivity() {
  }

  public CreateNewTaskActivity initialTrigger(String initialTrigger) {
    
    this.initialTrigger = initialTrigger;
    return this;
  }

   /**
   * Trigger to supply to all tasks to be made
   * @return initialTrigger
  **/
  @jakarta.annotation.Nullable
  public String getInitialTrigger() {
    return initialTrigger;
  }


  public void setInitialTrigger(String initialTrigger) {
    this.initialTrigger = initialTrigger;
  }


  public CreateNewTaskActivity type(TypeEnum type) {
    
    this.type = type;
    return this;
  }

   /**
   * The type of task activity
   * @return type
  **/
  @jakarta.annotation.Nonnull
  public TypeEnum getType() {
    return type;
  }


  public void setType(TypeEnum type) {
    this.type = type;
  }


  public CreateNewTaskActivity correlationIds(List correlationIds) {
    
    this.correlationIds = correlationIds;
    return this;
  }

  public CreateNewTaskActivity addCorrelationIdsItem(EventHandlerMapping correlationIdsItem) {
    if (this.correlationIds == null) {
      this.correlationIds = new ArrayList<>();
    }
    this.correlationIds.add(correlationIdsItem);
    return this;
  }

   /**
   * The event to correlation ID mappings
   * @return correlationIds
  **/
  @jakarta.annotation.Nullable
  public List getCorrelationIds() {
    return correlationIds;
  }


  public void setCorrelationIds(List correlationIds) {
    this.correlationIds = correlationIds;
  }


  public CreateNewTaskActivity taskFields(Map taskFields) {
    
    this.taskFields = taskFields;
    return this;
  }

  public CreateNewTaskActivity putTaskFieldsItem(String key, FieldMapping taskFieldsItem) {
    if (this.taskFields == null) {
      this.taskFields = new HashMap<>();
    }
    this.taskFields.put(key, taskFieldsItem);
    return this;
  }

   /**
   * The event to task field mappings
   * @return taskFields
  **/
  @jakarta.annotation.Nullable
  public Map getTaskFields() {
    return taskFields;
  }


  public void setTaskFields(Map taskFields) {
    this.taskFields = taskFields;
  }



  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    CreateNewTaskActivity createNewTaskActivity = (CreateNewTaskActivity) o;
    return Objects.equals(this.initialTrigger, createNewTaskActivity.initialTrigger) &&
        Objects.equals(this.type, createNewTaskActivity.type) &&
        Objects.equals(this.correlationIds, createNewTaskActivity.correlationIds) &&
        Objects.equals(this.taskFields, createNewTaskActivity.taskFields);
  }

  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(initialTrigger, type, correlationIds, taskFields);
  }

  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 CreateNewTaskActivity {\n");
    sb.append("    initialTrigger: ").append(toIndentedString(initialTrigger)).append("\n");
    sb.append("    type: ").append(toIndentedString(type)).append("\n");
    sb.append("    correlationIds: ").append(toIndentedString(correlationIds)).append("\n");
    sb.append("    taskFields: ").append(toIndentedString(taskFields)).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("initialTrigger");
    openapiFields.add("type");
    openapiFields.add("correlationIds");
    openapiFields.add("taskFields");

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

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

      // check to make sure all required properties/fields are present in the JSON string
      for (String requiredField : CreateNewTaskActivity.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("initialTrigger") != null && !jsonObj.get("initialTrigger").isJsonNull()) && !jsonObj.get("initialTrigger").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `initialTrigger` to be a primitive type in the JSON string but got `%s`", jsonObj.get("initialTrigger").toString()));
      }
      if (!jsonObj.get("type").isJsonPrimitive()) {
        throw new IllegalArgumentException(String.format("Expected the field `type` to be a primitive type in the JSON string but got `%s`", jsonObj.get("type").toString()));
      }
      if (jsonObj.get("correlationIds") != null && !jsonObj.get("correlationIds").isJsonNull()) {
        JsonArray jsonArraycorrelationIds = jsonObj.getAsJsonArray("correlationIds");
        if (jsonArraycorrelationIds != null) {
          // ensure the json data is an array
          if (!jsonObj.get("correlationIds").isJsonArray()) {
            throw new IllegalArgumentException(String.format("Expected the field `correlationIds` to be an array in the JSON string but got `%s`", jsonObj.get("correlationIds").toString()));
          }

          // validate the optional field `correlationIds` (array)
          for (int i = 0; i < jsonArraycorrelationIds.size(); i++) {
            EventHandlerMapping.validateJsonElement(jsonArraycorrelationIds.get(i));
          };
        }
      }
  }

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

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

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

       }.nullSafe();
    }
  }

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy