software.amazon.awssdk.services.kendra.model.DataSourceToIndexFieldMapping Maven / Gradle / Ivy
Show all versions of kendra Show documentation
/*
* 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.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
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.LocationTrait;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Maps attributes or field names of the documents synced from the data source to Amazon Kendra index field names. You
* can set up field mappings for each data source when calling CreateDataSource or UpdateDataSource API. To
* create custom fields, use the UpdateIndex
API to first create an index field and then map to the data
* source field. For more information, see Mapping data source fields.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class DataSourceToIndexFieldMapping implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField DATA_SOURCE_FIELD_NAME_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("DataSourceFieldName").getter(getter(DataSourceToIndexFieldMapping::dataSourceFieldName))
.setter(setter(Builder::dataSourceFieldName))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("DataSourceFieldName").build())
.build();
private static final SdkField DATE_FIELD_FORMAT_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("DateFieldFormat").getter(getter(DataSourceToIndexFieldMapping::dateFieldFormat))
.setter(setter(Builder::dateFieldFormat))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("DateFieldFormat").build()).build();
private static final SdkField INDEX_FIELD_NAME_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("IndexFieldName").getter(getter(DataSourceToIndexFieldMapping::indexFieldName))
.setter(setter(Builder::indexFieldName))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("IndexFieldName").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(DATA_SOURCE_FIELD_NAME_FIELD,
DATE_FIELD_FORMAT_FIELD, INDEX_FIELD_NAME_FIELD));
private static final long serialVersionUID = 1L;
private final String dataSourceFieldName;
private final String dateFieldFormat;
private final String indexFieldName;
private DataSourceToIndexFieldMapping(BuilderImpl builder) {
this.dataSourceFieldName = builder.dataSourceFieldName;
this.dateFieldFormat = builder.dateFieldFormat;
this.indexFieldName = builder.indexFieldName;
}
/**
*
* The name of the field in the data source. You must first create the index field using the
* UpdateIndex
API.
*
*
* @return The name of the field in the data source. You must first create the index field using the
* UpdateIndex
API.
*/
public final String dataSourceFieldName() {
return dataSourceFieldName;
}
/**
*
* The format for date fields in the data source. If the field specified in DataSourceFieldName
is a
* date field, you must specify the date format. If the field is not a date field, an exception is thrown.
*
*
* @return The format for date fields in the data source. If the field specified in DataSourceFieldName
* is a date field, you must specify the date format. If the field is not a date field, an exception is
* thrown.
*/
public final String dateFieldFormat() {
return dateFieldFormat;
}
/**
*
* The name of the index field to map to the data source field. The index field type must match the data source
* field type.
*
*
* @return The name of the index field to map to the data source field. The index field type must match the data
* source field type.
*/
public final String indexFieldName() {
return indexFieldName;
}
@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 + Objects.hashCode(dataSourceFieldName());
hashCode = 31 * hashCode + Objects.hashCode(dateFieldFormat());
hashCode = 31 * hashCode + Objects.hashCode(indexFieldName());
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 DataSourceToIndexFieldMapping)) {
return false;
}
DataSourceToIndexFieldMapping other = (DataSourceToIndexFieldMapping) obj;
return Objects.equals(dataSourceFieldName(), other.dataSourceFieldName())
&& Objects.equals(dateFieldFormat(), other.dateFieldFormat())
&& Objects.equals(indexFieldName(), other.indexFieldName());
}
/**
* 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("DataSourceToIndexFieldMapping").add("DataSourceFieldName", dataSourceFieldName())
.add("DateFieldFormat", dateFieldFormat()).add("IndexFieldName", indexFieldName()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "DataSourceFieldName":
return Optional.ofNullable(clazz.cast(dataSourceFieldName()));
case "DateFieldFormat":
return Optional.ofNullable(clazz.cast(dateFieldFormat()));
case "IndexFieldName":
return Optional.ofNullable(clazz.cast(indexFieldName()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function