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

software.amazon.awssdk.services.kendra.model.UserContext Maven / Gradle / Ivy

Go to download

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

There is a newer version: 2.29.15
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.kendra.model;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
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.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;

/**
 * 

* Provides information about the user context for an Amazon Kendra index. *

*

* User context filtering is a kind of personalized search with the benefit of controlling access to documents. For * example, not all teams that search the company portal for information should access top-secret company documents, nor * are these documents relevant to all users. Only specific users or groups of teams given access to top-secret * documents should see these documents in their search results. *

*

* You provide one of the following: *

*
    *
  • *

    * User token *

    *
  • *
  • *

    * User ID, the groups the user belongs to, and any data sources the groups can access. *

    *
  • *
*

* If you provide both, an exception is thrown. *

*/ @Generated("software.amazon.awssdk:codegen") public final class UserContext implements SdkPojo, Serializable, ToCopyableBuilder { private static final SdkField TOKEN_FIELD = SdkField. builder(MarshallingType.STRING).memberName("Token") .getter(getter(UserContext::token)).setter(setter(Builder::token)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Token").build()).build(); private static final SdkField USER_ID_FIELD = SdkField. builder(MarshallingType.STRING).memberName("UserId") .getter(getter(UserContext::userId)).setter(setter(Builder::userId)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("UserId").build()).build(); private static final SdkField> GROUPS_FIELD = SdkField .> builder(MarshallingType.LIST) .memberName("Groups") .getter(getter(UserContext::groups)) .setter(setter(Builder::groups)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Groups").build(), ListTrait .builder() .memberLocationName(null) .memberFieldInfo( SdkField. builder(MarshallingType.STRING) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD) .locationName("member").build()).build()).build()).build(); private static final SdkField> DATA_SOURCE_GROUPS_FIELD = SdkField .> builder(MarshallingType.LIST) .memberName("DataSourceGroups") .getter(getter(UserContext::dataSourceGroups)) .setter(setter(Builder::dataSourceGroups)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("DataSourceGroups").build(), ListTrait .builder() .memberLocationName(null) .memberFieldInfo( SdkField. builder(MarshallingType.SDK_POJO) .constructor(DataSourceGroup::builder) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD) .locationName("member").build()).build()).build()).build(); private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(TOKEN_FIELD, USER_ID_FIELD, GROUPS_FIELD, DATA_SOURCE_GROUPS_FIELD)); private static final long serialVersionUID = 1L; private final String token; private final String userId; private final List groups; private final List dataSourceGroups; private UserContext(BuilderImpl builder) { this.token = builder.token; this.userId = builder.userId; this.groups = builder.groups; this.dataSourceGroups = builder.dataSourceGroups; } /** *

* The user context token for filtering search results for a user. It must be a JWT or a JSON token. *

* * @return The user context token for filtering search results for a user. It must be a JWT or a JSON token. */ public final String token() { return token; } /** *

* The identifier of the user you want to filter search results based on their access to documents. *

* * @return The identifier of the user you want to filter search results based on their access to documents. */ public final String userId() { return userId; } /** * For responses, this returns true if the service returned a value for the Groups 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 hasGroups() { return groups != null && !(groups instanceof SdkAutoConstructList); } /** *

* The list of groups you want to filter search results based on the groups' access to documents. *

*

* 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 #hasGroups} method. *

* * @return The list of groups you want to filter search results based on the groups' access to documents. */ public final List groups() { return groups; } /** * For responses, this returns true if the service returned a value for the DataSourceGroups 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 hasDataSourceGroups() { return dataSourceGroups != null && !(dataSourceGroups instanceof SdkAutoConstructList); } /** *

* The list of data source groups you want to filter search results based on groups' access to documents in that * data source. *

*

* 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 #hasDataSourceGroups} method. *

* * @return The list of data source groups you want to filter search results based on groups' access to documents in * that data source. */ public final List dataSourceGroups() { return dataSourceGroups; } @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(token()); hashCode = 31 * hashCode + Objects.hashCode(userId()); hashCode = 31 * hashCode + Objects.hashCode(hasGroups() ? groups() : null); hashCode = 31 * hashCode + Objects.hashCode(hasDataSourceGroups() ? dataSourceGroups() : 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 UserContext)) { return false; } UserContext other = (UserContext) obj; return Objects.equals(token(), other.token()) && Objects.equals(userId(), other.userId()) && hasGroups() == other.hasGroups() && Objects.equals(groups(), other.groups()) && hasDataSourceGroups() == other.hasDataSourceGroups() && Objects.equals(dataSourceGroups(), other.dataSourceGroups()); } /** * 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("UserContext").add("Token", token()).add("UserId", userId()) .add("Groups", hasGroups() ? groups() : null) .add("DataSourceGroups", hasDataSourceGroups() ? dataSourceGroups() : null).build(); } public final Optional getValueForField(String fieldName, Class clazz) { switch (fieldName) { case "Token": return Optional.ofNullable(clazz.cast(token())); case "UserId": return Optional.ofNullable(clazz.cast(userId())); case "Groups": return Optional.ofNullable(clazz.cast(groups())); case "DataSourceGroups": return Optional.ofNullable(clazz.cast(dataSourceGroups())); default: return Optional.empty(); } } @Override public final List> sdkFields() { return SDK_FIELDS; } private static Function getter(Function g) { return obj -> g.apply((UserContext) obj); } private static BiConsumer setter(BiConsumer s) { return (obj, val) -> s.accept((Builder) obj, val); } public interface Builder extends SdkPojo, CopyableBuilder { /** *

* The user context token for filtering search results for a user. It must be a JWT or a JSON token. *

* * @param token * The user context token for filtering search results for a user. It must be a JWT or a JSON token. * @return Returns a reference to this object so that method calls can be chained together. */ Builder token(String token); /** *

* The identifier of the user you want to filter search results based on their access to documents. *

* * @param userId * The identifier of the user you want to filter search results based on their access to documents. * @return Returns a reference to this object so that method calls can be chained together. */ Builder userId(String userId); /** *

* The list of groups you want to filter search results based on the groups' access to documents. *

* * @param groups * The list of groups you want to filter search results based on the groups' access to documents. * @return Returns a reference to this object so that method calls can be chained together. */ Builder groups(Collection groups); /** *

* The list of groups you want to filter search results based on the groups' access to documents. *

* * @param groups * The list of groups you want to filter search results based on the groups' access to documents. * @return Returns a reference to this object so that method calls can be chained together. */ Builder groups(String... groups); /** *

* The list of data source groups you want to filter search results based on groups' access to documents in that * data source. *

* * @param dataSourceGroups * The list of data source groups you want to filter search results based on groups' access to documents * in that data source. * @return Returns a reference to this object so that method calls can be chained together. */ Builder dataSourceGroups(Collection dataSourceGroups); /** *

* The list of data source groups you want to filter search results based on groups' access to documents in that * data source. *

* * @param dataSourceGroups * The list of data source groups you want to filter search results based on groups' access to documents * in that data source. * @return Returns a reference to this object so that method calls can be chained together. */ Builder dataSourceGroups(DataSourceGroup... dataSourceGroups); /** *

* The list of data source groups you want to filter search results based on groups' access to documents in that * data source. *

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

* When the {@link Consumer} completes, * {@link software.amazon.awssdk.services.kendra.model.DataSourceGroup.Builder#build()} is called immediately * and its result is passed to {@link #dataSourceGroups(List)}. * * @param dataSourceGroups * a consumer that will call methods on * {@link software.amazon.awssdk.services.kendra.model.DataSourceGroup.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #dataSourceGroups(java.util.Collection) */ Builder dataSourceGroups(Consumer... dataSourceGroups); } static final class BuilderImpl implements Builder { private String token; private String userId; private List groups = DefaultSdkAutoConstructList.getInstance(); private List dataSourceGroups = DefaultSdkAutoConstructList.getInstance(); private BuilderImpl() { } private BuilderImpl(UserContext model) { token(model.token); userId(model.userId); groups(model.groups); dataSourceGroups(model.dataSourceGroups); } public final String getToken() { return token; } public final void setToken(String token) { this.token = token; } @Override public final Builder token(String token) { this.token = token; return this; } public final String getUserId() { return userId; } public final void setUserId(String userId) { this.userId = userId; } @Override public final Builder userId(String userId) { this.userId = userId; return this; } public final Collection getGroups() { if (groups instanceof SdkAutoConstructList) { return null; } return groups; } public final void setGroups(Collection groups) { this.groups = GroupsCopier.copy(groups); } @Override public final Builder groups(Collection groups) { this.groups = GroupsCopier.copy(groups); return this; } @Override @SafeVarargs public final Builder groups(String... groups) { groups(Arrays.asList(groups)); return this; } public final List getDataSourceGroups() { List result = DataSourceGroupsCopier.copyToBuilder(this.dataSourceGroups); if (result instanceof SdkAutoConstructList) { return null; } return result; } public final void setDataSourceGroups(Collection dataSourceGroups) { this.dataSourceGroups = DataSourceGroupsCopier.copyFromBuilder(dataSourceGroups); } @Override public final Builder dataSourceGroups(Collection dataSourceGroups) { this.dataSourceGroups = DataSourceGroupsCopier.copy(dataSourceGroups); return this; } @Override @SafeVarargs public final Builder dataSourceGroups(DataSourceGroup... dataSourceGroups) { dataSourceGroups(Arrays.asList(dataSourceGroups)); return this; } @Override @SafeVarargs public final Builder dataSourceGroups(Consumer... dataSourceGroups) { dataSourceGroups(Stream.of(dataSourceGroups).map(c -> DataSourceGroup.builder().applyMutation(c).build()) .collect(Collectors.toList())); return this; } @Override public UserContext build() { return new UserContext(this); } @Override public List> sdkFields() { return SDK_FIELDS; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy