
software.amazon.awssdk.services.verifiedpermissions.model.GetPolicyResponse Maven / Gradle / Ivy
/*
* 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.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
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.TimestampFormatTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*/
@Generated("software.amazon.awssdk:codegen")
public final class GetPolicyResponse extends VerifiedPermissionsResponse implements
ToCopyableBuilder {
private static final SdkField POLICY_STORE_ID_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("policyStoreId").getter(getter(GetPolicyResponse::policyStoreId)).setter(setter(Builder::policyStoreId))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("policyStoreId").build()).build();
private static final SdkField POLICY_ID_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("policyId").getter(getter(GetPolicyResponse::policyId)).setter(setter(Builder::policyId))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("policyId").build()).build();
private static final SdkField POLICY_TYPE_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("policyType").getter(getter(GetPolicyResponse::policyTypeAsString)).setter(setter(Builder::policyType))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("policyType").build()).build();
private static final SdkField PRINCIPAL_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("principal")
.getter(getter(GetPolicyResponse::principal)).setter(setter(Builder::principal))
.constructor(EntityIdentifier::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("principal").build()).build();
private static final SdkField RESOURCE_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("resource")
.getter(getter(GetPolicyResponse::resource)).setter(setter(Builder::resource)).constructor(EntityIdentifier::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("resource").build()).build();
private static final SdkField> ACTIONS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("actions")
.getter(getter(GetPolicyResponse::actions))
.setter(setter(Builder::actions))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("actions").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(ActionIdentifier::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField DEFINITION_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("definition")
.getter(getter(GetPolicyResponse::definition)).setter(setter(Builder::definition))
.constructor(PolicyDefinitionDetail::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("definition").build()).build();
private static final SdkField CREATED_DATE_FIELD = SdkField
. builder(MarshallingType.INSTANT)
.memberName("createdDate")
.getter(getter(GetPolicyResponse::createdDate))
.setter(setter(Builder::createdDate))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("createdDate").build(),
TimestampFormatTrait.create(TimestampFormatTrait.Format.ISO_8601)).build();
private static final SdkField LAST_UPDATED_DATE_FIELD = SdkField
. builder(MarshallingType.INSTANT)
.memberName("lastUpdatedDate")
.getter(getter(GetPolicyResponse::lastUpdatedDate))
.setter(setter(Builder::lastUpdatedDate))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("lastUpdatedDate").build(),
TimestampFormatTrait.create(TimestampFormatTrait.Format.ISO_8601)).build();
private static final SdkField EFFECT_FIELD = SdkField. builder(MarshallingType.STRING).memberName("effect")
.getter(getter(GetPolicyResponse::effectAsString)).setter(setter(Builder::effect))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("effect").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(POLICY_STORE_ID_FIELD,
POLICY_ID_FIELD, POLICY_TYPE_FIELD, PRINCIPAL_FIELD, RESOURCE_FIELD, ACTIONS_FIELD, DEFINITION_FIELD,
CREATED_DATE_FIELD, LAST_UPDATED_DATE_FIELD, EFFECT_FIELD));
private static final Map> SDK_NAME_TO_FIELD = memberNameToFieldInitializer();
private final String policyStoreId;
private final String policyId;
private final String policyType;
private final EntityIdentifier principal;
private final EntityIdentifier resource;
private final List actions;
private final PolicyDefinitionDetail definition;
private final Instant createdDate;
private final Instant lastUpdatedDate;
private final String effect;
private GetPolicyResponse(BuilderImpl builder) {
super(builder);
this.policyStoreId = builder.policyStoreId;
this.policyId = builder.policyId;
this.policyType = builder.policyType;
this.principal = builder.principal;
this.resource = builder.resource;
this.actions = builder.actions;
this.definition = builder.definition;
this.createdDate = builder.createdDate;
this.lastUpdatedDate = builder.lastUpdatedDate;
this.effect = builder.effect;
}
/**
*
* The ID of the policy store that contains the policy that you want information about.
*
*
* @return The ID of the policy store that contains the policy that you want information about.
*/
public final String policyStoreId() {
return policyStoreId;
}
/**
*
* The unique ID of the policy that you want information about.
*
*
* @return The unique ID of the policy that you want information about.
*/
public final String policyId() {
return policyId;
}
/**
*
* The type of the policy.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #policyType} will
* return {@link PolicyType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #policyTypeAsString}.
*
*
* @return The type of the policy.
* @see PolicyType
*/
public final PolicyType policyType() {
return PolicyType.fromValue(policyType);
}
/**
*
* The type of the policy.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #policyType} will
* return {@link PolicyType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #policyTypeAsString}.
*
*
* @return The type of the policy.
* @see PolicyType
*/
public final String policyTypeAsString() {
return policyType;
}
/**
*
* The principal specified in the policy's scope. This element isn't included in the response when
* Principal
isn't present in the policy content.
*
*
* @return The principal specified in the policy's scope. This element isn't included in the response when
* Principal
isn't present in the policy content.
*/
public final EntityIdentifier principal() {
return principal;
}
/**
*
* The resource specified in the policy's scope. This element isn't included in the response when
* Resource
isn't present in the policy content.
*
*
* @return The resource specified in the policy's scope. This element isn't included in the response when
* Resource
isn't present in the policy content.
*/
public final EntityIdentifier resource() {
return resource;
}
/**
* For responses, this returns true if the service returned a value for the Actions 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 hasActions() {
return actions != null && !(actions instanceof SdkAutoConstructList);
}
/**
*
* The action that a policy permits or forbids. For example,
* {"actions": [{"actionId": "ViewPhoto", "actionType": "PhotoFlash::Action"}, {"entityID": "SharePhoto", "entityType": "PhotoFlash::Action"}]}
* .
*
*
* 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 #hasActions} method.
*
*
* @return The action that a policy permits or forbids. For example,
* {"actions": [{"actionId": "ViewPhoto", "actionType": "PhotoFlash::Action"}, {"entityID": "SharePhoto", "entityType": "PhotoFlash::Action"}]}
* .
*/
public final List actions() {
return actions;
}
/**
*
* The definition of the requested policy.
*
*
* @return The definition of the requested policy.
*/
public final PolicyDefinitionDetail definition() {
return definition;
}
/**
*
* The date and time that the policy was originally created.
*
*
* @return The date and time that the policy was originally created.
*/
public final Instant createdDate() {
return createdDate;
}
/**
*
* The date and time that the policy was last updated.
*
*
* @return The date and time that the policy was last updated.
*/
public final Instant lastUpdatedDate() {
return lastUpdatedDate;
}
/**
*
* The effect of the decision that a policy returns to an authorization request. For example,
* "effect": "Permit"
.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #effect} will
* return {@link PolicyEffect#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #effectAsString}.
*
*
* @return The effect of the decision that a policy returns to an authorization request. For example,
* "effect": "Permit"
.
* @see PolicyEffect
*/
public final PolicyEffect effect() {
return PolicyEffect.fromValue(effect);
}
/**
*
* The effect of the decision that a policy returns to an authorization request. For example,
* "effect": "Permit"
.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #effect} will
* return {@link PolicyEffect#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #effectAsString}.
*
*
* @return The effect of the decision that a policy returns to an authorization request. For example,
* "effect": "Permit"
.
* @see PolicyEffect
*/
public final String effectAsString() {
return effect;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + super.hashCode();
hashCode = 31 * hashCode + Objects.hashCode(policyStoreId());
hashCode = 31 * hashCode + Objects.hashCode(policyId());
hashCode = 31 * hashCode + Objects.hashCode(policyTypeAsString());
hashCode = 31 * hashCode + Objects.hashCode(principal());
hashCode = 31 * hashCode + Objects.hashCode(resource());
hashCode = 31 * hashCode + Objects.hashCode(hasActions() ? actions() : null);
hashCode = 31 * hashCode + Objects.hashCode(definition());
hashCode = 31 * hashCode + Objects.hashCode(createdDate());
hashCode = 31 * hashCode + Objects.hashCode(lastUpdatedDate());
hashCode = 31 * hashCode + Objects.hashCode(effectAsString());
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return super.equals(obj) && equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof GetPolicyResponse)) {
return false;
}
GetPolicyResponse other = (GetPolicyResponse) obj;
return Objects.equals(policyStoreId(), other.policyStoreId()) && Objects.equals(policyId(), other.policyId())
&& Objects.equals(policyTypeAsString(), other.policyTypeAsString())
&& Objects.equals(principal(), other.principal()) && Objects.equals(resource(), other.resource())
&& hasActions() == other.hasActions() && Objects.equals(actions(), other.actions())
&& Objects.equals(definition(), other.definition()) && Objects.equals(createdDate(), other.createdDate())
&& Objects.equals(lastUpdatedDate(), other.lastUpdatedDate())
&& Objects.equals(effectAsString(), other.effectAsString());
}
/**
* 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("GetPolicyResponse").add("PolicyStoreId", policyStoreId()).add("PolicyId", policyId())
.add("PolicyType", policyTypeAsString()).add("Principal", principal()).add("Resource", resource())
.add("Actions", hasActions() ? actions() : null).add("Definition", definition())
.add("CreatedDate", createdDate()).add("LastUpdatedDate", lastUpdatedDate()).add("Effect", effectAsString())
.build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "policyStoreId":
return Optional.ofNullable(clazz.cast(policyStoreId()));
case "policyId":
return Optional.ofNullable(clazz.cast(policyId()));
case "policyType":
return Optional.ofNullable(clazz.cast(policyTypeAsString()));
case "principal":
return Optional.ofNullable(clazz.cast(principal()));
case "resource":
return Optional.ofNullable(clazz.cast(resource()));
case "actions":
return Optional.ofNullable(clazz.cast(actions()));
case "definition":
return Optional.ofNullable(clazz.cast(definition()));
case "createdDate":
return Optional.ofNullable(clazz.cast(createdDate()));
case "lastUpdatedDate":
return Optional.ofNullable(clazz.cast(lastUpdatedDate()));
case "effect":
return Optional.ofNullable(clazz.cast(effectAsString()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
@Override
public final Map> sdkFieldNameToField() {
return SDK_NAME_TO_FIELD;
}
private static Map> memberNameToFieldInitializer() {
Map> map = new HashMap<>();
map.put("policyStoreId", POLICY_STORE_ID_FIELD);
map.put("policyId", POLICY_ID_FIELD);
map.put("policyType", POLICY_TYPE_FIELD);
map.put("principal", PRINCIPAL_FIELD);
map.put("resource", RESOURCE_FIELD);
map.put("actions", ACTIONS_FIELD);
map.put("definition", DEFINITION_FIELD);
map.put("createdDate", CREATED_DATE_FIELD);
map.put("lastUpdatedDate", LAST_UPDATED_DATE_FIELD);
map.put("effect", EFFECT_FIELD);
return Collections.unmodifiableMap(map);
}
private static Function