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

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

/**
 * Avro dataset.
 */
@Fluent
public final class AvroDataset extends Dataset {
    /*
     * Type of dataset.
     */
    private String type = "Avro";

    /*
     * Avro dataset properties.
     */
    private AvroDatasetTypeProperties innerTypeProperties;

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

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

    /**
     * Get the innerTypeProperties property: Avro dataset properties.
     * 
     * @return the innerTypeProperties value.
     */
    private AvroDatasetTypeProperties innerTypeProperties() {
        return this.innerTypeProperties;
    }

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

    /**
     * {@inheritDoc}
     */
    @Override
    public AvroDataset withStructure(Object structure) {
        super.withStructure(structure);
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public AvroDataset withSchema(Object schema) {
        super.withSchema(schema);
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public AvroDataset withLinkedServiceName(LinkedServiceReference linkedServiceName) {
        super.withLinkedServiceName(linkedServiceName);
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public AvroDataset withParameters(Map parameters) {
        super.withParameters(parameters);
        return this;
    }

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

    /**
     * {@inheritDoc}
     */
    @Override
    public AvroDataset withFolder(DatasetFolder folder) {
        super.withFolder(folder);
        return this;
    }

    /**
     * Get the location property: The location of the avro storage.
     * 
     * @return the location value.
     */
    public DatasetLocation location() {
        return this.innerTypeProperties() == null ? null : this.innerTypeProperties().location();
    }

    /**
     * Set the location property: The location of the avro storage.
     * 
     * @param location the location value to set.
     * @return the AvroDataset object itself.
     */
    public AvroDataset withLocation(DatasetLocation location) {
        if (this.innerTypeProperties() == null) {
            this.innerTypeProperties = new AvroDatasetTypeProperties();
        }
        this.innerTypeProperties().withLocation(location);
        return this;
    }

    /**
     * Get the avroCompressionCodec property: The data avroCompressionCodec. Type: string (or Expression with resultType
     * string).
     * 
     * @return the avroCompressionCodec value.
     */
    public Object avroCompressionCodec() {
        return this.innerTypeProperties() == null ? null : this.innerTypeProperties().avroCompressionCodec();
    }

    /**
     * Set the avroCompressionCodec property: The data avroCompressionCodec. Type: string (or Expression with resultType
     * string).
     * 
     * @param avroCompressionCodec the avroCompressionCodec value to set.
     * @return the AvroDataset object itself.
     */
    public AvroDataset withAvroCompressionCodec(Object avroCompressionCodec) {
        if (this.innerTypeProperties() == null) {
            this.innerTypeProperties = new AvroDatasetTypeProperties();
        }
        this.innerTypeProperties().withAvroCompressionCodec(avroCompressionCodec);
        return this;
    }

    /**
     * Get the avroCompressionLevel property: The avroCompressionLevel property.
     * 
     * @return the avroCompressionLevel value.
     */
    public Integer avroCompressionLevel() {
        return this.innerTypeProperties() == null ? null : this.innerTypeProperties().avroCompressionLevel();
    }

    /**
     * Set the avroCompressionLevel property: The avroCompressionLevel property.
     * 
     * @param avroCompressionLevel the avroCompressionLevel value to set.
     * @return the AvroDataset object itself.
     */
    public AvroDataset withAvroCompressionLevel(Integer avroCompressionLevel) {
        if (this.innerTypeProperties() == null) {
            this.innerTypeProperties = new AvroDatasetTypeProperties();
        }
        this.innerTypeProperties().withAvroCompressionLevel(avroCompressionLevel);
        return this;
    }

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

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

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

    /**
     * Reads an instance of AvroDataset from the JsonReader.
     * 
     * @param jsonReader The JsonReader being read.
     * @return An instance of AvroDataset 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 AvroDataset.
     */
    public static AvroDataset fromJson(JsonReader jsonReader) throws IOException {
        return jsonReader.readObject(reader -> {
            AvroDataset deserializedAvroDataset = new AvroDataset();
            Map additionalProperties = null;
            while (reader.nextToken() != JsonToken.END_OBJECT) {
                String fieldName = reader.getFieldName();
                reader.nextToken();

                if ("linkedServiceName".equals(fieldName)) {
                    deserializedAvroDataset.withLinkedServiceName(LinkedServiceReference.fromJson(reader));
                } else if ("description".equals(fieldName)) {
                    deserializedAvroDataset.withDescription(reader.getString());
                } else if ("structure".equals(fieldName)) {
                    deserializedAvroDataset.withStructure(reader.readUntyped());
                } else if ("schema".equals(fieldName)) {
                    deserializedAvroDataset.withSchema(reader.readUntyped());
                } else if ("parameters".equals(fieldName)) {
                    Map parameters
                        = reader.readMap(reader1 -> ParameterSpecification.fromJson(reader1));
                    deserializedAvroDataset.withParameters(parameters);
                } else if ("annotations".equals(fieldName)) {
                    List annotations = reader.readArray(reader1 -> reader1.readUntyped());
                    deserializedAvroDataset.withAnnotations(annotations);
                } else if ("folder".equals(fieldName)) {
                    deserializedAvroDataset.withFolder(DatasetFolder.fromJson(reader));
                } else if ("type".equals(fieldName)) {
                    deserializedAvroDataset.type = reader.getString();
                } else if ("typeProperties".equals(fieldName)) {
                    deserializedAvroDataset.innerTypeProperties = AvroDatasetTypeProperties.fromJson(reader);
                } else {
                    if (additionalProperties == null) {
                        additionalProperties = new LinkedHashMap<>();
                    }

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

            return deserializedAvroDataset;
        });
    }
}