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

com.azure.resourcemanager.datafactory.models.CustomEventsTrigger Maven / Gradle / Ivy

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.resourcemanager.datafactory.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.json.JsonReader;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import com.azure.resourcemanager.datafactory.fluent.models.CustomEventsTriggerTypeProperties;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Trigger that runs every time a custom event is received.
 */
@Fluent
public final class CustomEventsTrigger extends MultiplePipelineTrigger {
    /*
     * Trigger type.
     */
    private String type = "CustomEventsTrigger";

    /*
     * Custom Events Trigger properties.
     */
    private CustomEventsTriggerTypeProperties innerTypeProperties = new CustomEventsTriggerTypeProperties();

    /**
     * Creates an instance of CustomEventsTrigger class.
     */
    public CustomEventsTrigger() {
    }

    /**
     * Get the type property: Trigger type.
     * 
     * @return the type value.
     */
    @Override
    public String type() {
        return this.type;
    }

    /**
     * Get the innerTypeProperties property: Custom Events Trigger properties.
     * 
     * @return the innerTypeProperties value.
     */
    private CustomEventsTriggerTypeProperties innerTypeProperties() {
        return this.innerTypeProperties;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public CustomEventsTrigger withPipelines(List pipelines) {
        super.withPipelines(pipelines);
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public CustomEventsTrigger withDescription(String description) {
        super.withDescription(description);
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public CustomEventsTrigger withAnnotations(List annotations) {
        super.withAnnotations(annotations);
        return this;
    }

    /**
     * Get the subjectBeginsWith property: The event subject must begin with the pattern provided for trigger to fire.
     * At least one of these must be provided: subjectBeginsWith, subjectEndsWith.
     * 
     * @return the subjectBeginsWith value.
     */
    public String subjectBeginsWith() {
        return this.innerTypeProperties() == null ? null : this.innerTypeProperties().subjectBeginsWith();
    }

    /**
     * Set the subjectBeginsWith property: The event subject must begin with the pattern provided for trigger to fire.
     * At least one of these must be provided: subjectBeginsWith, subjectEndsWith.
     * 
     * @param subjectBeginsWith the subjectBeginsWith value to set.
     * @return the CustomEventsTrigger object itself.
     */
    public CustomEventsTrigger withSubjectBeginsWith(String subjectBeginsWith) {
        if (this.innerTypeProperties() == null) {
            this.innerTypeProperties = new CustomEventsTriggerTypeProperties();
        }
        this.innerTypeProperties().withSubjectBeginsWith(subjectBeginsWith);
        return this;
    }

    /**
     * Get the subjectEndsWith property: The event subject must end with the pattern provided for trigger to fire. At
     * least one of these must be provided: subjectBeginsWith, subjectEndsWith.
     * 
     * @return the subjectEndsWith value.
     */
    public String subjectEndsWith() {
        return this.innerTypeProperties() == null ? null : this.innerTypeProperties().subjectEndsWith();
    }

    /**
     * Set the subjectEndsWith property: The event subject must end with the pattern provided for trigger to fire. At
     * least one of these must be provided: subjectBeginsWith, subjectEndsWith.
     * 
     * @param subjectEndsWith the subjectEndsWith value to set.
     * @return the CustomEventsTrigger object itself.
     */
    public CustomEventsTrigger withSubjectEndsWith(String subjectEndsWith) {
        if (this.innerTypeProperties() == null) {
            this.innerTypeProperties = new CustomEventsTriggerTypeProperties();
        }
        this.innerTypeProperties().withSubjectEndsWith(subjectEndsWith);
        return this;
    }

    /**
     * Get the events property: The list of event types that cause this trigger to fire.
     * 
     * @return the events value.
     */
    public List events() {
        return this.innerTypeProperties() == null ? null : this.innerTypeProperties().events();
    }

    /**
     * Set the events property: The list of event types that cause this trigger to fire.
     * 
     * @param events the events value to set.
     * @return the CustomEventsTrigger object itself.
     */
    public CustomEventsTrigger withEvents(List events) {
        if (this.innerTypeProperties() == null) {
            this.innerTypeProperties = new CustomEventsTriggerTypeProperties();
        }
        this.innerTypeProperties().withEvents(events);
        return this;
    }

    /**
     * Get the scope property: The ARM resource ID of the Azure Event Grid Topic.
     * 
     * @return the scope value.
     */
    public String scope() {
        return this.innerTypeProperties() == null ? null : this.innerTypeProperties().scope();
    }

    /**
     * Set the scope property: The ARM resource ID of the Azure Event Grid Topic.
     * 
     * @param scope the scope value to set.
     * @return the CustomEventsTrigger object itself.
     */
    public CustomEventsTrigger withScope(String scope) {
        if (this.innerTypeProperties() == null) {
            this.innerTypeProperties = new CustomEventsTriggerTypeProperties();
        }
        this.innerTypeProperties().withScope(scope);
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    @Override
    public void validate() {
        if (innerTypeProperties() == null) {
            throw LOGGER.atError()
                .log(new IllegalArgumentException(
                    "Missing required property innerTypeProperties in model CustomEventsTrigger"));
        } else {
            innerTypeProperties().validate();
        }
        if (pipelines() != null) {
            pipelines().forEach(e -> e.validate());
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(CustomEventsTrigger.class);

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("description", description());
        jsonWriter.writeArrayField("annotations", annotations(), (writer, element) -> writer.writeUntyped(element));
        jsonWriter.writeArrayField("pipelines", pipelines(), (writer, element) -> writer.writeJson(element));
        jsonWriter.writeJsonField("typeProperties", this.innerTypeProperties);
        jsonWriter.writeStringField("type", this.type);
        if (additionalProperties() != null) {
            for (Map.Entry additionalProperty : additionalProperties().entrySet()) {
                jsonWriter.writeUntypedField(additionalProperty.getKey(), additionalProperty.getValue());
            }
        }
        return jsonWriter.writeEndObject();
    }

    /**
     * Reads an instance of CustomEventsTrigger from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of CustomEventsTrigger if the JsonReader was pointing to an instance of it, or null if it was
     * pointing to JSON null.
     * @throws IllegalStateException If the deserialized JSON object was missing any required properties.
     * @throws IOException If an error occurs while reading the CustomEventsTrigger.
     */
    public static CustomEventsTrigger fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            CustomEventsTrigger deserializedCustomEventsTrigger = new CustomEventsTrigger();
            Map additionalProperties = null;
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("description".equals(fieldName)) {
                    deserializedCustomEventsTrigger.withDescription(reader.getString());
                } else if ("runtimeState".equals(fieldName)) {
                    deserializedCustomEventsTrigger
                        .withRuntimeState(TriggerRuntimeState.fromString(reader.getString()));
                } else if ("annotations".equals(fieldName)) {
                    List annotations = reader.readArray(reader1 -> reader1.readUntyped());
                    deserializedCustomEventsTrigger.withAnnotations(annotations);
                } else if ("pipelines".equals(fieldName)) {
                    List pipelines
                        = reader.readArray(reader1 -> TriggerPipelineReference.fromJson(reader1));
                    deserializedCustomEventsTrigger.withPipelines(pipelines);
                } else if ("typeProperties".equals(fieldName)) {
                    deserializedCustomEventsTrigger.innerTypeProperties
                        = CustomEventsTriggerTypeProperties.fromJson(reader);
                } else if ("type".equals(fieldName)) {
                    deserializedCustomEventsTrigger.type = reader.getString();
                } else {
                    if (additionalProperties == null) {
                        additionalProperties = new LinkedHashMap<>();
                    }

                    additionalProperties.put(fieldName, reader.readUntyped());
                }
            }
            deserializedCustomEventsTrigger.withAdditionalProperties(additionalProperties);

            return deserializedCustomEventsTrigger;
        });
    }
}