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

com.azure.resourcemanager.datafactory.models.ChainingTrigger 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.ChainingTriggerTypeProperties;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * Trigger that allows the referenced pipeline to depend on other pipeline runs based on runDimension Name/Value pairs.
 * Upstream pipelines should declare the same runDimension Name and their runs should have the values for those
 * runDimensions. The referenced pipeline run would be triggered if the values for the runDimension match for all
 * upstream pipeline runs.
 */
@Fluent
public final class ChainingTrigger extends Trigger {
    /*
     * Trigger type.
     */
    private String type = "ChainingTrigger";

    /*
     * Pipeline for which runs are created when all upstream pipelines complete successfully.
     */
    private TriggerPipelineReference pipeline;

    /*
     * Chaining Trigger properties.
     */
    private ChainingTriggerTypeProperties innerTypeProperties = new ChainingTriggerTypeProperties();

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

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

    /**
     * Get the pipeline property: Pipeline for which runs are created when all upstream pipelines complete successfully.
     * 
     * @return the pipeline value.
     */
    public TriggerPipelineReference pipeline() {
        return this.pipeline;
    }

    /**
     * Set the pipeline property: Pipeline for which runs are created when all upstream pipelines complete successfully.
     * 
     * @param pipeline the pipeline value to set.
     * @return the ChainingTrigger object itself.
     */
    public ChainingTrigger withPipeline(TriggerPipelineReference pipeline) {
        this.pipeline = pipeline;
        return this;
    }

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

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

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

    /**
     * Get the dependsOn property: Upstream Pipelines.
     * 
     * @return the dependsOn value.
     */
    public List dependsOn() {
        return this.innerTypeProperties() == null ? null : this.innerTypeProperties().dependsOn();
    }

    /**
     * Set the dependsOn property: Upstream Pipelines.
     * 
     * @param dependsOn the dependsOn value to set.
     * @return the ChainingTrigger object itself.
     */
    public ChainingTrigger withDependsOn(List dependsOn) {
        if (this.innerTypeProperties() == null) {
            this.innerTypeProperties = new ChainingTriggerTypeProperties();
        }
        this.innerTypeProperties().withDependsOn(dependsOn);
        return this;
    }

    /**
     * Get the runDimension property: Run Dimension property that needs to be emitted by upstream pipelines.
     * 
     * @return the runDimension value.
     */
    public String runDimension() {
        return this.innerTypeProperties() == null ? null : this.innerTypeProperties().runDimension();
    }

    /**
     * Set the runDimension property: Run Dimension property that needs to be emitted by upstream pipelines.
     * 
     * @param runDimension the runDimension value to set.
     * @return the ChainingTrigger object itself.
     */
    public ChainingTrigger withRunDimension(String runDimension) {
        if (this.innerTypeProperties() == null) {
            this.innerTypeProperties = new ChainingTriggerTypeProperties();
        }
        this.innerTypeProperties().withRunDimension(runDimension);
        return this;
    }

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

    private static final ClientLogger LOGGER = new ClientLogger(ChainingTrigger.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.writeJsonField("pipeline", this.pipeline);
        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 ChainingTrigger from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of ChainingTrigger 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 ChainingTrigger.
     */
    public static ChainingTrigger fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            ChainingTrigger deserializedChainingTrigger = new ChainingTrigger();
            Map additionalProperties = null;
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

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

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

            return deserializedChainingTrigger;
        });
    }
}