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

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

/**
 * Base class for all control activities like IfCondition, ForEach , Until.
 */
@Fluent
public class ControlActivity extends Activity {
    /*
     * Type of activity.
     */
    private String type = "Container";

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

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

    /**
     * {@inheritDoc}
     */
    @Override
    public ControlActivity withName(String name) {
        super.withName(name);
        return this;
    }

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

    /**
     * {@inheritDoc}
     */
    @Override
    public ControlActivity withState(ActivityState state) {
        super.withState(state);
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ControlActivity withOnInactiveMarkAs(ActivityOnInactiveMarkAs onInactiveMarkAs) {
        super.withOnInactiveMarkAs(onInactiveMarkAs);
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ControlActivity withDependsOn(List dependsOn) {
        super.withDependsOn(dependsOn);
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public ControlActivity withUserProperties(List userProperties) {
        super.withUserProperties(userProperties);
        return this;
    }

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

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

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("name", name());
        jsonWriter.writeStringField("description", description());
        jsonWriter.writeStringField("state", state() == null ? null : state().toString());
        jsonWriter.writeStringField("onInactiveMarkAs",
            onInactiveMarkAs() == null ? null : onInactiveMarkAs().toString());
        jsonWriter.writeArrayField("dependsOn", dependsOn(), (writer, element) -> writer.writeJson(element));
        jsonWriter.writeArrayField("userProperties", userProperties(), (writer, element) -> writer.writeJson(element));
        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 ControlActivity from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of ControlActivity 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 ControlActivity.
     */
    public static ControlActivity fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            String discriminatorValue = null;
            try (JsonReader readerToUse = reader.bufferObject()) {
                readerToUse.nextToken(); // Prepare for reading
                while (readerToUse.nextToken() != JsonToken.END_OBJECT) {
                    String fieldName = readerToUse.getFieldName();
                    readerToUse.nextToken();
                    if ("type".equals(fieldName)) {
                        discriminatorValue = readerToUse.getString();
                        break;
                    } else {
                        readerToUse.skipChildren();
                    }
                }
                // Use the discriminator value to determine which subtype should be deserialized.
                if ("ExecutePipeline".equals(discriminatorValue)) {
                    return ExecutePipelineActivity.fromJson(readerToUse.reset());
                } else if ("IfCondition".equals(discriminatorValue)) {
                    return IfConditionActivity.fromJson(readerToUse.reset());
                } else if ("Switch".equals(discriminatorValue)) {
                    return SwitchActivity.fromJson(readerToUse.reset());
                } else if ("ForEach".equals(discriminatorValue)) {
                    return ForEachActivity.fromJson(readerToUse.reset());
                } else if ("Wait".equals(discriminatorValue)) {
                    return WaitActivity.fromJson(readerToUse.reset());
                } else if ("Fail".equals(discriminatorValue)) {
                    return FailActivity.fromJson(readerToUse.reset());
                } else if ("Until".equals(discriminatorValue)) {
                    return UntilActivity.fromJson(readerToUse.reset());
                } else if ("Validation".equals(discriminatorValue)) {
                    return ValidationActivity.fromJson(readerToUse.reset());
                } else if ("Filter".equals(discriminatorValue)) {
                    return FilterActivity.fromJson(readerToUse.reset());
                } else if ("SetVariable".equals(discriminatorValue)) {
                    return SetVariableActivity.fromJson(readerToUse.reset());
                } else if ("AppendVariable".equals(discriminatorValue)) {
                    return AppendVariableActivity.fromJson(readerToUse.reset());
                } else if ("WebHook".equals(discriminatorValue)) {
                    return WebhookActivity.fromJson(readerToUse.reset());
                } else {
                    return fromJsonKnownDiscriminator(readerToUse.reset());
                }
            }
        });
    }

    static ControlActivity fromJsonKnownDiscriminator(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            ControlActivity deserializedControlActivity = new ControlActivity();
            Map additionalProperties = null;
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("name".equals(fieldName)) {
                    deserializedControlActivity.withName(reader.getString());
                } else if ("description".equals(fieldName)) {
                    deserializedControlActivity.withDescription(reader.getString());
                } else if ("state".equals(fieldName)) {
                    deserializedControlActivity.withState(ActivityState.fromString(reader.getString()));
                } else if ("onInactiveMarkAs".equals(fieldName)) {
                    deserializedControlActivity
                        .withOnInactiveMarkAs(ActivityOnInactiveMarkAs.fromString(reader.getString()));
                } else if ("dependsOn".equals(fieldName)) {
                    List dependsOn
                        = reader.readArray(reader1 -> ActivityDependency.fromJson(reader1));
                    deserializedControlActivity.withDependsOn(dependsOn);
                } else if ("userProperties".equals(fieldName)) {
                    List userProperties = reader.readArray(reader1 -> UserProperty.fromJson(reader1));
                    deserializedControlActivity.withUserProperties(userProperties);
                } else if ("type".equals(fieldName)) {
                    deserializedControlActivity.type = reader.getString();
                } else {
                    if (additionalProperties == null) {
                        additionalProperties = new LinkedHashMap<>();
                    }

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

            return deserializedControlActivity;
        });
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy