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

com.azure.resourcemanager.security.fluent.models.ApplicationProperties 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.security.fluent.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.azure.json.JsonReader;
import com.azure.json.JsonSerializable;
import com.azure.json.JsonToken;
import com.azure.json.JsonWriter;
import com.azure.resourcemanager.security.models.ApplicationSourceResourceType;
import java.io.IOException;
import java.util.List;

/**
 * Describes properties of an application.
 */
@Fluent
public final class ApplicationProperties implements JsonSerializable {
    /*
     * display name of the application
     */
    private String displayName;

    /*
     * description of the application
     */
    private String description;

    /*
     * The application source, what it affects, e.g. Assessments
     */
    private ApplicationSourceResourceType sourceResourceType;

    /*
     * The application conditionSets - see examples
     */
    private List conditionSets;

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

    /**
     * Get the displayName property: display name of the application.
     * 
     * @return the displayName value.
     */
    public String displayName() {
        return this.displayName;
    }

    /**
     * Set the displayName property: display name of the application.
     * 
     * @param displayName the displayName value to set.
     * @return the ApplicationProperties object itself.
     */
    public ApplicationProperties withDisplayName(String displayName) {
        this.displayName = displayName;
        return this;
    }

    /**
     * Get the description property: description of the application.
     * 
     * @return the description value.
     */
    public String description() {
        return this.description;
    }

    /**
     * Set the description property: description of the application.
     * 
     * @param description the description value to set.
     * @return the ApplicationProperties object itself.
     */
    public ApplicationProperties withDescription(String description) {
        this.description = description;
        return this;
    }

    /**
     * Get the sourceResourceType property: The application source, what it affects, e.g. Assessments.
     * 
     * @return the sourceResourceType value.
     */
    public ApplicationSourceResourceType sourceResourceType() {
        return this.sourceResourceType;
    }

    /**
     * Set the sourceResourceType property: The application source, what it affects, e.g. Assessments.
     * 
     * @param sourceResourceType the sourceResourceType value to set.
     * @return the ApplicationProperties object itself.
     */
    public ApplicationProperties withSourceResourceType(ApplicationSourceResourceType sourceResourceType) {
        this.sourceResourceType = sourceResourceType;
        return this;
    }

    /**
     * Get the conditionSets property: The application conditionSets - see examples.
     * 
     * @return the conditionSets value.
     */
    public List conditionSets() {
        return this.conditionSets;
    }

    /**
     * Set the conditionSets property: The application conditionSets - see examples.
     * 
     * @param conditionSets the conditionSets value to set.
     * @return the ApplicationProperties object itself.
     */
    public ApplicationProperties withConditionSets(List conditionSets) {
        this.conditionSets = conditionSets;
        return this;
    }

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

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

    /**
     * {@inheritDoc}
     */
    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeStringField("sourceResourceType",
            this.sourceResourceType == null ? null : this.sourceResourceType.toString());
        jsonWriter.writeArrayField("conditionSets", this.conditionSets,
            (writer, element) -> writer.writeUntyped(element));
        jsonWriter.writeStringField("displayName", this.displayName);
        jsonWriter.writeStringField("description", this.description);
        return jsonWriter.writeEndObject();
    }

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

                if ("sourceResourceType".equals(fieldName)) {
                    deserializedApplicationProperties.sourceResourceType
                        = ApplicationSourceResourceType.fromString(reader.getString());
                } else if ("conditionSets".equals(fieldName)) {
                    List conditionSets = reader.readArray(reader1 -> reader1.readUntyped());
                    deserializedApplicationProperties.conditionSets = conditionSets;
                } else if ("displayName".equals(fieldName)) {
                    deserializedApplicationProperties.displayName = reader.getString();
                } else if ("description".equals(fieldName)) {
                    deserializedApplicationProperties.description = reader.getString();
                } else {
                    reader.skipChildren();
                }
            }

            return deserializedApplicationProperties;
        });
    }
}