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

com.azure.resourcemanager.datafactory.models.MapperTargetConnectionsInfo 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.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import java.io.IOException;
import java.util.List;

/**
 * A object which contains list of tables and connection details for a target connection.
 */
@Fluent
public final class MapperTargetConnectionsInfo implements JsonSerializable {
    /*
     * List of source tables for a target connection.
     */
    private List targetEntities;

    /*
     * Source connection details.
     */
    private MapperConnection connection;

    /*
     * List of table mappings.
     */
    private List dataMapperMappings;

    /*
     * List of relationship info among the tables.
     */
    private List relationships;

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

    /**
     * Get the targetEntities property: List of source tables for a target connection.
     * 
     * @return the targetEntities value.
     */
    public List targetEntities() {
        return this.targetEntities;
    }

    /**
     * Set the targetEntities property: List of source tables for a target connection.
     * 
     * @param targetEntities the targetEntities value to set.
     * @return the MapperTargetConnectionsInfo object itself.
     */
    public MapperTargetConnectionsInfo withTargetEntities(List targetEntities) {
        this.targetEntities = targetEntities;
        return this;
    }

    /**
     * Get the connection property: Source connection details.
     * 
     * @return the connection value.
     */
    public MapperConnection connection() {
        return this.connection;
    }

    /**
     * Set the connection property: Source connection details.
     * 
     * @param connection the connection value to set.
     * @return the MapperTargetConnectionsInfo object itself.
     */
    public MapperTargetConnectionsInfo withConnection(MapperConnection connection) {
        this.connection = connection;
        return this;
    }

    /**
     * Get the dataMapperMappings property: List of table mappings.
     * 
     * @return the dataMapperMappings value.
     */
    public List dataMapperMappings() {
        return this.dataMapperMappings;
    }

    /**
     * Set the dataMapperMappings property: List of table mappings.
     * 
     * @param dataMapperMappings the dataMapperMappings value to set.
     * @return the MapperTargetConnectionsInfo object itself.
     */
    public MapperTargetConnectionsInfo withDataMapperMappings(List dataMapperMappings) {
        this.dataMapperMappings = dataMapperMappings;
        return this;
    }

    /**
     * Get the relationships property: List of relationship info among the tables.
     * 
     * @return the relationships value.
     */
    public List relationships() {
        return this.relationships;
    }

    /**
     * Set the relationships property: List of relationship info among the tables.
     * 
     * @param relationships the relationships value to set.
     * @return the MapperTargetConnectionsInfo object itself.
     */
    public MapperTargetConnectionsInfo withRelationships(List relationships) {
        this.relationships = relationships;
        return this;
    }

    /**
     * Validates the instance.
     * 
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (targetEntities() != null) {
            targetEntities().forEach(e -> e.validate());
        }
        if (connection() != null) {
            connection().validate();
        }
        if (dataMapperMappings() != null) {
            dataMapperMappings().forEach(e -> e.validate());
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeArrayField("targetEntities", this.targetEntities,
            (writer, element) -> writer.writeJson(element));
        jsonWriter.writeJsonField("connection", this.connection);
        jsonWriter.writeArrayField("dataMapperMappings", this.dataMapperMappings,
            (writer, element) -> writer.writeJson(element));
        jsonWriter.writeArrayField("relationships", this.relationships,
            (writer, element) -> writer.writeUntyped(element));
        return jsonWriter.writeEndObject();
    }

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

                if ("targetEntities".equals(fieldName)) {
                    List targetEntities = reader.readArray(reader1 -> MapperTable.fromJson(reader1));
                    deserializedMapperTargetConnectionsInfo.targetEntities = targetEntities;
                } else if ("connection".equals(fieldName)) {
                    deserializedMapperTargetConnectionsInfo.connection = MapperConnection.fromJson(reader);
                } else if ("dataMapperMappings".equals(fieldName)) {
                    List dataMapperMappings
                        = reader.readArray(reader1 -> DataMapperMapping.fromJson(reader1));
                    deserializedMapperTargetConnectionsInfo.dataMapperMappings = dataMapperMappings;
                } else if ("relationships".equals(fieldName)) {
                    List relationships = reader.readArray(reader1 -> reader1.readUntyped());
                    deserializedMapperTargetConnectionsInfo.relationships = relationships;
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedMapperTargetConnectionsInfo;
        });
    }
}