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

com.azure.security.keyvault.secrets.implementation.models.Attributes Maven / Gradle / Ivy

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.security.keyvault.secrets.implementation.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.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;

/** The object attributes managed by the KeyVault service. */
@Fluent
public class Attributes implements JsonSerializable {
    /*
     * Determines whether the object is enabled.
     */
    private Boolean enabled;

    /*
     * Not before date in UTC.
     */
    private Long notBefore;

    /*
     * Expiry date in UTC.
     */
    private Long expires;

    /*
     * Creation time in UTC.
     */
    private Long created;

    /*
     * Last updated time in UTC.
     */
    private Long updated;

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

    /**
     * Get the enabled property: Determines whether the object is enabled.
     *
     * @return the enabled value.
     */
    public Boolean isEnabled() {
        return this.enabled;
    }

    /**
     * Set the enabled property: Determines whether the object is enabled.
     *
     * @param enabled the enabled value to set.
     * @return the Attributes object itself.
     */
    public Attributes setEnabled(Boolean enabled) {
        this.enabled = enabled;
        return this;
    }

    /**
     * Get the notBefore property: Not before date in UTC.
     *
     * @return the notBefore value.
     */
    public OffsetDateTime getNotBefore() {
        if (this.notBefore == null) {
            return null;
        }
        return OffsetDateTime.ofInstant(Instant.ofEpochSecond(this.notBefore), ZoneOffset.UTC);
    }

    /**
     * Set the notBefore property: Not before date in UTC.
     *
     * @param notBefore the notBefore value to set.
     * @return the Attributes object itself.
     */
    public Attributes setNotBefore(OffsetDateTime notBefore) {
        if (notBefore == null) {
            this.notBefore = null;
        } else {
            this.notBefore = notBefore.toEpochSecond();
        }
        return this;
    }

    /**
     * Get the expires property: Expiry date in UTC.
     *
     * @return the expires value.
     */
    public OffsetDateTime getExpires() {
        if (this.expires == null) {
            return null;
        }
        return OffsetDateTime.ofInstant(Instant.ofEpochSecond(this.expires), ZoneOffset.UTC);
    }

    /**
     * Set the expires property: Expiry date in UTC.
     *
     * @param expires the expires value to set.
     * @return the Attributes object itself.
     */
    public Attributes setExpires(OffsetDateTime expires) {
        if (expires == null) {
            this.expires = null;
        } else {
            this.expires = expires.toEpochSecond();
        }
        return this;
    }

    /**
     * Get the created property: Creation time in UTC.
     *
     * @return the created value.
     */
    public OffsetDateTime getCreated() {
        if (this.created == null) {
            return null;
        }
        return OffsetDateTime.ofInstant(Instant.ofEpochSecond(this.created), ZoneOffset.UTC);
    }

    /**
     * Set the created property: Creation time in UTC.
     *
     * @param created the created value to set.
     * @return the Attributes object itself.
     */
    Attributes setCreated(Long created) {
        this.created = created;
        return this;
    }

    /**
     * Get the updated property: Last updated time in UTC.
     *
     * @return the updated value.
     */
    public OffsetDateTime getUpdated() {
        if (this.updated == null) {
            return null;
        }
        return OffsetDateTime.ofInstant(Instant.ofEpochSecond(this.updated), ZoneOffset.UTC);
    }

    /**
     * Set the updated property: Last updated time in UTC.
     *
     * @param updated the updated value to set.
     * @return the Attributes object itself.
     */
    Attributes setUpdated(Long updated) {
        this.updated = updated;
        return this;
    }

    @Override
    public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
        jsonWriter.writeStartObject();
        jsonWriter.writeBooleanField("enabled", this.enabled);
        jsonWriter.writeNumberField("nbf", this.notBefore);
        jsonWriter.writeNumberField("exp", this.expires);
        return jsonWriter.writeEndObject();
    }

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

                        if ("enabled".equals(fieldName)) {
                            deserializedAttributes.enabled = reader.getNullable(JsonReader::getBoolean);
                        } else if ("nbf".equals(fieldName)) {
                            deserializedAttributes.notBefore = reader.getNullable(JsonReader::getLong);
                        } else if ("exp".equals(fieldName)) {
                            deserializedAttributes.expires = reader.getNullable(JsonReader::getLong);
                        } else if ("created".equals(fieldName)) {
                            deserializedAttributes.created = reader.getNullable(JsonReader::getLong);
                        } else if ("updated".equals(fieldName)) {
                            deserializedAttributes.updated = reader.getNullable(JsonReader::getLong);
                        } else {
                            reader.skipChildren();
                        }
                    }

                    return deserializedAttributes;
                });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy