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

com.azure.resourcemanager.dataprotection.models.AzureRetentionRule Maven / Gradle / Ivy

Go to download

This package contains Microsoft Azure SDK for DataProtection Management SDK. For documentation on how to use this package, please see https://aka.ms/azsdk/java/mgmt. Open API 2.0 Specs for Azure Data Protection service. Package tag package-2024-04.

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

package com.azure.resourcemanager.dataprotection.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.List;

/**
 * AzureRetentionRule
 * 
 * Azure retention rule.
 */
@Fluent
public final class AzureRetentionRule extends BasePolicyRule {
    /*
     * The objectType property.
     */
    private String objectType = "AzureRetentionRule";

    /*
     * The isDefault property.
     */
    private Boolean isDefault;

    /*
     * The lifecycles property.
     */
    private List lifecycles;

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

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

    /**
     * Get the isDefault property: The isDefault property.
     * 
     * @return the isDefault value.
     */
    public Boolean isDefault() {
        return this.isDefault;
    }

    /**
     * Set the isDefault property: The isDefault property.
     * 
     * @param isDefault the isDefault value to set.
     * @return the AzureRetentionRule object itself.
     */
    public AzureRetentionRule withIsDefault(Boolean isDefault) {
        this.isDefault = isDefault;
        return this;
    }

    /**
     * Get the lifecycles property: The lifecycles property.
     * 
     * @return the lifecycles value.
     */
    public List lifecycles() {
        return this.lifecycles;
    }

    /**
     * Set the lifecycles property: The lifecycles property.
     * 
     * @param lifecycles the lifecycles value to set.
     * @return the AzureRetentionRule object itself.
     */
    public AzureRetentionRule withLifecycles(List lifecycles) {
        this.lifecycles = lifecycles;
        return this;
    }

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

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

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

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("name", name());
        jsonWriter.writeArrayField("lifecycles", this.lifecycles, (writer, element) -> writer.writeJson(element));
        jsonWriter.writeStringField("objectType", this.objectType);
        jsonWriter.writeBooleanField("isDefault", this.isDefault);
        return jsonWriter.writeEndObject();
    }

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

                if ("name".equals(fieldName)) {
                    deserializedAzureRetentionRule.withName(reader.getString());
                } else if ("lifecycles".equals(fieldName)) {
                    List lifecycles = reader.readArray(reader1 -> SourceLifeCycle.fromJson(reader1));
                    deserializedAzureRetentionRule.lifecycles = lifecycles;
                } else if ("objectType".equals(fieldName)) {
                    deserializedAzureRetentionRule.objectType = reader.getString();
                } else if ("isDefault".equals(fieldName)) {
                    deserializedAzureRetentionRule.isDefault = reader.getNullable(JsonReader::getBoolean);
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedAzureRetentionRule;
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy