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

software.amazon.awssdk.services.verifiedpermissions.model.AttributeValue Maven / Gradle / Ivy

Go to download

The AWS Java SDK for Verified Permissions module holds the client classes that are used for communicating with Verified Permissions.

There is a newer version: 2.29.39
Show newest version
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

package software.amazon.awssdk.services.verifiedpermissions.model;

import java.beans.Transient;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.traits.MapTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructMap;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructMap;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;

/**
 * 

* The value of an attribute. *

*

* Contains information about the runtime context for a request for which an authorization decision is made. *

*

* This data type is used as a member of the ContextDefinition structure which is uses as a request parameter for the IsAuthorized, BatchIsAuthorized * , and IsAuthorizedWithToken operations. *

*/ @Generated("software.amazon.awssdk:codegen") public final class AttributeValue implements SdkPojo, Serializable, ToCopyableBuilder { private static final SdkField BOOLEAN_FIELD = SdkField. builder(MarshallingType.BOOLEAN) .memberName("boolean").getter(getter(AttributeValue::booleanValue)).setter(setter(Builder::booleanValue)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("boolean").build()).build(); private static final SdkField ENTITY_IDENTIFIER_FIELD = SdkField . builder(MarshallingType.SDK_POJO).memberName("entityIdentifier") .getter(getter(AttributeValue::entityIdentifier)).setter(setter(Builder::entityIdentifier)) .constructor(EntityIdentifier::builder) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("entityIdentifier").build()).build(); private static final SdkField LONG_FIELD = SdkField. builder(MarshallingType.LONG).memberName("long") .getter(getter(AttributeValue::longValue)).setter(setter(Builder::longValue)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("long").build()).build(); private static final SdkField STRING_FIELD = SdkField. builder(MarshallingType.STRING).memberName("string") .getter(getter(AttributeValue::string)).setter(setter(Builder::string)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("string").build()).build(); private static final SdkField> SET_FIELD = SdkField .> builder(MarshallingType.LIST) .memberName("set") .getter(getter(AttributeValue::set)) .setter(setter(Builder::set)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("set").build(), ListTrait .builder() .memberLocationName(null) .memberFieldInfo( SdkField. builder(MarshallingType.SDK_POJO) .constructor(AttributeValue::builder) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD) .locationName("member").build()).build()).build()).build(); private static final SdkField> RECORD_FIELD = SdkField .> builder(MarshallingType.MAP) .memberName("record") .getter(getter(AttributeValue::record)) .setter(setter(Builder::record)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("record").build(), MapTrait.builder() .keyLocationName("key") .valueLocationName("value") .valueFieldInfo( SdkField. builder(MarshallingType.SDK_POJO) .constructor(AttributeValue::builder) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD) .locationName("value").build()).build()).build()).build(); private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(BOOLEAN_FIELD, ENTITY_IDENTIFIER_FIELD, LONG_FIELD, STRING_FIELD, SET_FIELD, RECORD_FIELD)); private static final long serialVersionUID = 1L; private final Boolean booleanValue; private final EntityIdentifier entityIdentifier; private final Long longValue; private final String string; private final List set; private final Map record; private final Type type; private AttributeValue(BuilderImpl builder) { this.booleanValue = builder.booleanValue; this.entityIdentifier = builder.entityIdentifier; this.longValue = builder.longValue; this.string = builder.string; this.set = builder.set; this.record = builder.record; this.type = builder.type; } /** *

* An attribute value of Boolean * type. *

*

* Example: {"boolean": true} *

* * @return An attribute value of Boolean type.

*

* Example: {"boolean": true} */ public final Boolean booleanValue() { return booleanValue; } /** *

* An attribute value of type EntityIdentifier. *

*

* Example: "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"} *

* * @return An attribute value of type EntityIdentifier.

*

* Example: * "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"} */ public final EntityIdentifier entityIdentifier() { return entityIdentifier; } /** *

* An attribute value of Long type. *

*

* Example: {"long": 0} *

* * @return An attribute value of Long * type.

*

* Example: {"long": 0} */ public final Long longValue() { return longValue; } /** *

* An attribute value of String * type. *

*

* Example: {"string": "abc"} *

* * @return An attribute value of String type.

*

* Example: {"string": "abc"} */ public final String string() { return string; } /** * For responses, this returns true if the service returned a value for the Set property. This DOES NOT check that * the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is useful * because the SDK will never return a null collection or map, but you may need to differentiate between the service * returning nothing (or null) and the service returning an empty collection or map. For requests, this returns true * if a value for the property was specified in the request builder, and false if a value was not specified. */ public final boolean hasSet() { return set != null && !(set instanceof SdkAutoConstructList); } /** *

* An attribute value of Set type. *

*

* Example: {"set": [ {} ] } *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

*

* This method will never return null. If you would like to know whether the service returned this field (so that * you can differentiate between null and empty), you can use the {@link #hasSet} method. *

* * @return An attribute value of Set * type.

*

* Example: {"set": [ {} ] } */ public final List set() { return set; } /** * For responses, this returns true if the service returned a value for the Record property. This DOES NOT check * that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is * useful because the SDK will never return a null collection or map, but you may need to differentiate between the * service returning nothing (or null) and the service returning an empty collection or map. For requests, this * returns true if a value for the property was specified in the request builder, and false if a value was not * specified. */ public final boolean hasRecord() { return record != null && !(record instanceof SdkAutoConstructMap); } /** *

* An attribute value of Record * type. *

*

* Example: {"record": { "keyName": {} } } *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

*

* This method will never return null. If you would like to know whether the service returned this field (so that * you can differentiate between null and empty), you can use the {@link #hasRecord} method. *

* * @return An attribute value of Record type.

*

* Example: {"record": { "keyName": {} } } */ public final Map record() { return record; } @Override public Builder toBuilder() { return new BuilderImpl(this); } public static Builder builder() { return new BuilderImpl(); } public static Class serializableBuilderClass() { return BuilderImpl.class; } @Override public final int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(booleanValue()); hashCode = 31 * hashCode + Objects.hashCode(entityIdentifier()); hashCode = 31 * hashCode + Objects.hashCode(longValue()); hashCode = 31 * hashCode + Objects.hashCode(string()); hashCode = 31 * hashCode + Objects.hashCode(hasSet() ? set() : null); hashCode = 31 * hashCode + Objects.hashCode(hasRecord() ? record() : null); return hashCode; } @Override public final boolean equals(Object obj) { return equalsBySdkFields(obj); } @Override public final boolean equalsBySdkFields(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof AttributeValue)) { return false; } AttributeValue other = (AttributeValue) obj; return Objects.equals(booleanValue(), other.booleanValue()) && Objects.equals(entityIdentifier(), other.entityIdentifier()) && Objects.equals(longValue(), other.longValue()) && Objects.equals(string(), other.string()) && hasSet() == other.hasSet() && Objects.equals(set(), other.set()) && hasRecord() == other.hasRecord() && Objects.equals(record(), other.record()); } /** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. */ @Override public final String toString() { return ToString.builder("AttributeValue") .add("Boolean", booleanValue() == null ? null : "*** Sensitive Data Redacted ***") .add("EntityIdentifier", entityIdentifier()) .add("Long", longValue() == null ? null : "*** Sensitive Data Redacted ***") .add("String", string() == null ? null : "*** Sensitive Data Redacted ***").add("Set", hasSet() ? set() : null) .add("Record", hasRecord() ? record() : null).build(); } public final Optional getValueForField(String fieldName, Class clazz) { switch (fieldName) { case "boolean": return Optional.ofNullable(clazz.cast(booleanValue())); case "entityIdentifier": return Optional.ofNullable(clazz.cast(entityIdentifier())); case "long": return Optional.ofNullable(clazz.cast(longValue())); case "string": return Optional.ofNullable(clazz.cast(string())); case "set": return Optional.ofNullable(clazz.cast(set())); case "record": return Optional.ofNullable(clazz.cast(record())); default: return Optional.empty(); } } /** * Create an instance of this class with {@link #booleanValue()} initialized to the given value. * *

* An attribute value of Boolean * type. *

*

* Example: {"boolean": true} *

* * @param booleanValue * An attribute value of Boolean type.

*

* Example: {"boolean": true} */ public static AttributeValue fromBooleanValue(Boolean booleanValue) { return builder().booleanValue(booleanValue).build(); } /** * Create an instance of this class with {@link #entityIdentifier()} initialized to the given value. * *

* An attribute value of type EntityIdentifier. *

*

* Example: "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"} *

* * @param entityIdentifier * An attribute value of type EntityIdentifier.

*

* Example: "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"} */ public static AttributeValue fromEntityIdentifier(EntityIdentifier entityIdentifier) { return builder().entityIdentifier(entityIdentifier).build(); } /** * Create an instance of this class with {@link #entityIdentifier()} initialized to the given value. * *

* An attribute value of type EntityIdentifier. *

*

* Example: "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"} *

* * @param entityIdentifier * An attribute value of type EntityIdentifier.

*

* Example: "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"} */ public static AttributeValue fromEntityIdentifier(Consumer entityIdentifier) { EntityIdentifier.Builder builder = EntityIdentifier.builder(); entityIdentifier.accept(builder); return fromEntityIdentifier(builder.build()); } /** * Create an instance of this class with {@link #longValue()} initialized to the given value. * *

* An attribute value of Long type. *

*

* Example: {"long": 0} *

* * @param longValue * An attribute value of Long * type.

*

* Example: {"long": 0} */ public static AttributeValue fromLongValue(Long longValue) { return builder().longValue(longValue).build(); } /** * Create an instance of this class with {@link #string()} initialized to the given value. * *

* An attribute value of String * type. *

*

* Example: {"string": "abc"} *

* * @param string * An attribute value of String type.

*

* Example: {"string": "abc"} */ public static AttributeValue fromString(String string) { return builder().string(string).build(); } /** * Create an instance of this class with {@link #set()} initialized to the given value. * *

* An attribute value of Set type. *

*

* Example: {"set": [ {} ] } *

* * @param set * An attribute value of Set * type.

*

* Example: {"set": [ {} ] } */ public static AttributeValue fromSet(List set) { return builder().set(set).build(); } /** * Create an instance of this class with {@link #record()} initialized to the given value. * *

* An attribute value of Record * type. *

*

* Example: {"record": { "keyName": {} } } *

* * @param record * An attribute value of Record type.

*

* Example: {"record": { "keyName": {} } } */ public static AttributeValue fromRecord(Map record) { return builder().record(record).build(); } /** * Retrieve an enum value representing which member of this object is populated. * * When this class is returned in a service response, this will be {@link Type#UNKNOWN_TO_SDK_VERSION} if the * service returned a member that is only known to a newer SDK version. * * When this class is created directly in your code, this will be {@link Type#UNKNOWN_TO_SDK_VERSION} if zero * members are set, and {@code null} if more than one member is set. */ public Type type() { return type; } @Override public final List> sdkFields() { return SDK_FIELDS; } private static Function getter(Function g) { return obj -> g.apply((AttributeValue) obj); } private static BiConsumer setter(BiConsumer s) { return (obj, val) -> s.accept((Builder) obj, val); } public interface Builder extends SdkPojo, CopyableBuilder { /** *

* An attribute value of Boolean type. *

*

* Example: {"boolean": true} *

* * @param booleanValue * An attribute value of Boolean type.

*

* Example: {"boolean": true} * @return Returns a reference to this object so that method calls can be chained together. */ Builder booleanValue(Boolean booleanValue); /** *

* An attribute value of type EntityIdentifier. *

*

* Example: "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"} *

* * @param entityIdentifier * An attribute value of type EntityIdentifier.

*

* Example: * "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"} * @return Returns a reference to this object so that method calls can be chained together. */ Builder entityIdentifier(EntityIdentifier entityIdentifier); /** *

* An attribute value of type EntityIdentifier. *

*

* Example: "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"} *

* This is a convenience method that creates an instance of the {@link EntityIdentifier.Builder} avoiding the * need to create one manually via {@link EntityIdentifier#builder()}. * *

* When the {@link Consumer} completes, {@link EntityIdentifier.Builder#build()} is called immediately and its * result is passed to {@link #entityIdentifier(EntityIdentifier)}. * * @param entityIdentifier * a consumer that will call methods on {@link EntityIdentifier.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #entityIdentifier(EntityIdentifier) */ default Builder entityIdentifier(Consumer entityIdentifier) { return entityIdentifier(EntityIdentifier.builder().applyMutation(entityIdentifier).build()); } /** *

* An attribute value of Long * type. *

*

* Example: {"long": 0} *

* * @param longValue * An attribute value of Long type.

*

* Example: {"long": 0} * @return Returns a reference to this object so that method calls can be chained together. */ Builder longValue(Long longValue); /** *

* An attribute value of String * type. *

*

* Example: {"string": "abc"} *

* * @param string * An attribute value of String type.

*

* Example: {"string": "abc"} * @return Returns a reference to this object so that method calls can be chained together. */ Builder string(String string); /** *

* An attribute value of Set type. *

*

* Example: {"set": [ {} ] } *

* * @param set * An attribute value of Set type.

*

* Example: {"set": [ {} ] } * @return Returns a reference to this object so that method calls can be chained together. */ Builder set(Collection set); /** *

* An attribute value of Set type. *

*

* Example: {"set": [ {} ] } *

* * @param set * An attribute value of Set type.

*

* Example: {"set": [ {} ] } * @return Returns a reference to this object so that method calls can be chained together. */ Builder set(AttributeValue... set); /** *

* An attribute value of Set type. *

*

* Example: {"set": [ {} ] } *

* This is a convenience method that creates an instance of the * {@link software.amazon.awssdk.services.verifiedpermissions.model.AttributeValue.Builder} avoiding the need to * create one manually via * {@link software.amazon.awssdk.services.verifiedpermissions.model.AttributeValue#builder()}. * *

* When the {@link Consumer} completes, * {@link software.amazon.awssdk.services.verifiedpermissions.model.AttributeValue.Builder#build()} is called * immediately and its result is passed to {@link #set(List)}. * * @param set * a consumer that will call methods on * {@link software.amazon.awssdk.services.verifiedpermissions.model.AttributeValue.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #set(java.util.Collection) */ Builder set(Consumer... set); /** *

* An attribute value of Record * type. *

*

* Example: {"record": { "keyName": {} } } *

* * @param record * An attribute value of Record type.

*

* Example: {"record": { "keyName": {} } } * @return Returns a reference to this object so that method calls can be chained together. */ Builder record(Map record); } static final class BuilderImpl implements Builder { private Boolean booleanValue; private EntityIdentifier entityIdentifier; private Long longValue; private String string; private List set = DefaultSdkAutoConstructList.getInstance(); private Map record = DefaultSdkAutoConstructMap.getInstance(); private Type type = Type.UNKNOWN_TO_SDK_VERSION; private Set setTypes = EnumSet.noneOf(Type.class); private BuilderImpl() { } private BuilderImpl(AttributeValue model) { booleanValue(model.booleanValue); entityIdentifier(model.entityIdentifier); longValue(model.longValue); string(model.string); set(model.set); record(model.record); } public final Boolean getBooleanValue() { return booleanValue; } public final void setBooleanValue(Boolean booleanValue) { Object oldValue = this.booleanValue; this.booleanValue = booleanValue; handleUnionValueChange(Type.BOOLEAN, oldValue, this.booleanValue); } @Override public final Builder booleanValue(Boolean booleanValue) { Object oldValue = this.booleanValue; this.booleanValue = booleanValue; handleUnionValueChange(Type.BOOLEAN, oldValue, this.booleanValue); return this; } public final EntityIdentifier.Builder getEntityIdentifier() { return entityIdentifier != null ? entityIdentifier.toBuilder() : null; } public final void setEntityIdentifier(EntityIdentifier.BuilderImpl entityIdentifier) { Object oldValue = this.entityIdentifier; this.entityIdentifier = entityIdentifier != null ? entityIdentifier.build() : null; handleUnionValueChange(Type.ENTITY_IDENTIFIER, oldValue, this.entityIdentifier); } @Override public final Builder entityIdentifier(EntityIdentifier entityIdentifier) { Object oldValue = this.entityIdentifier; this.entityIdentifier = entityIdentifier; handleUnionValueChange(Type.ENTITY_IDENTIFIER, oldValue, this.entityIdentifier); return this; } public final Long getLongValue() { return longValue; } public final void setLongValue(Long longValue) { Object oldValue = this.longValue; this.longValue = longValue; handleUnionValueChange(Type.LONG, oldValue, this.longValue); } @Override public final Builder longValue(Long longValue) { Object oldValue = this.longValue; this.longValue = longValue; handleUnionValueChange(Type.LONG, oldValue, this.longValue); return this; } public final String getString() { return string; } public final void setString(String string) { Object oldValue = this.string; this.string = string; handleUnionValueChange(Type.STRING, oldValue, this.string); } @Override public final Builder string(String string) { Object oldValue = this.string; this.string = string; handleUnionValueChange(Type.STRING, oldValue, this.string); return this; } public final List getSet() { List result = SetAttributeCopier.copyToBuilder(this.set); if (result instanceof SdkAutoConstructList) { return null; } return result; } public final void setSet(Collection set) { Object oldValue = this.set; this.set = SetAttributeCopier.copyFromBuilder(set); handleUnionValueChange(Type.SET, oldValue, this.set); } @Override @Transient public final Builder set(Collection set) { Object oldValue = this.set; this.set = SetAttributeCopier.copy(set); handleUnionValueChange(Type.SET, oldValue, this.set); return this; } @Override @Transient @SafeVarargs public final Builder set(AttributeValue... set) { set(Arrays.asList(set)); return this; } @Override @Transient @SafeVarargs public final Builder set(Consumer... set) { set(Stream.of(set).map(c -> AttributeValue.builder().applyMutation(c).build()).collect(Collectors.toList())); return this; } public final Map getRecord() { Map result = RecordAttributeCopier.copyToBuilder(this.record); if (result instanceof SdkAutoConstructMap) { return null; } return result; } public final void setRecord(Map record) { Object oldValue = this.record; this.record = RecordAttributeCopier.copyFromBuilder(record); handleUnionValueChange(Type.RECORD, oldValue, this.record); } @Override public final Builder record(Map record) { Object oldValue = this.record; this.record = RecordAttributeCopier.copy(record); handleUnionValueChange(Type.RECORD, oldValue, this.record); return this; } @Override public AttributeValue build() { return new AttributeValue(this); } @Override public List> sdkFields() { return SDK_FIELDS; } private final void handleUnionValueChange(Type type, Object oldValue, Object newValue) { if (this.type == type || oldValue == newValue) { return; } if (newValue == null || newValue instanceof SdkAutoConstructList || newValue instanceof SdkAutoConstructMap) { setTypes.remove(type); } else if (oldValue == null || oldValue instanceof SdkAutoConstructList || oldValue instanceof SdkAutoConstructMap) { setTypes.add(type); } if (setTypes.size() == 1) { this.type = setTypes.iterator().next(); } else if (setTypes.isEmpty()) { this.type = Type.UNKNOWN_TO_SDK_VERSION; } else { this.type = null; } } } /** * @see AttributeValue#type() */ public enum Type { BOOLEAN, ENTITY_IDENTIFIER, LONG, STRING, SET, RECORD, UNKNOWN_TO_SDK_VERSION } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy