software.amazon.awssdk.services.qbusiness.model.Message Maven / Gradle / Ivy
Show all versions of qbusiness 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.qbusiness.model;
import java.io.Serializable;
import java.time.Instant;
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;
/**
*
* A message in an Amazon Q Business web experience.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class Message implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField MESSAGE_ID_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("messageId").getter(getter(Message::messageId)).setter(setter(Builder::messageId))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("messageId").build()).build();
private static final SdkField BODY_FIELD = SdkField. builder(MarshallingType.STRING).memberName("body")
.getter(getter(Message::body)).setter(setter(Builder::body))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("body").build()).build();
private static final SdkField TIME_FIELD = SdkField. builder(MarshallingType.INSTANT).memberName("time")
.getter(getter(Message::time)).setter(setter(Builder::time))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("time").build()).build();
private static final SdkField TYPE_FIELD = SdkField. builder(MarshallingType.STRING).memberName("type")
.getter(getter(Message::typeAsString)).setter(setter(Builder::type))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("type").build()).build();
private static final SdkField> ATTACHMENTS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("attachments")
.getter(getter(Message::attachments))
.setter(setter(Builder::attachments))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("attachments").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(AttachmentOutput::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField> SOURCE_ATTRIBUTION_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("sourceAttribution")
.getter(getter(Message::sourceAttribution))
.setter(setter(Builder::sourceAttribution))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("sourceAttribution").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(SourceAttribution::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField ACTION_REVIEW_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.memberName("actionReview").getter(getter(Message::actionReview)).setter(setter(Builder::actionReview))
.constructor(ActionReview::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("actionReview").build()).build();
private static final SdkField ACTION_EXECUTION_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("actionExecution")
.getter(getter(Message::actionExecution)).setter(setter(Builder::actionExecution))
.constructor(ActionExecution::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("actionExecution").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(MESSAGE_ID_FIELD, BODY_FIELD,
TIME_FIELD, TYPE_FIELD, ATTACHMENTS_FIELD, SOURCE_ATTRIBUTION_FIELD, ACTION_REVIEW_FIELD, ACTION_EXECUTION_FIELD));
private static final long serialVersionUID = 1L;
private final String messageId;
private final String body;
private final Instant time;
private final String type;
private final List attachments;
private final List sourceAttribution;
private final ActionReview actionReview;
private final ActionExecution actionExecution;
private Message(BuilderImpl builder) {
this.messageId = builder.messageId;
this.body = builder.body;
this.time = builder.time;
this.type = builder.type;
this.attachments = builder.attachments;
this.sourceAttribution = builder.sourceAttribution;
this.actionReview = builder.actionReview;
this.actionExecution = builder.actionExecution;
}
/**
*
* The identifier of the Amazon Q Business web experience message.
*
*
* @return The identifier of the Amazon Q Business web experience message.
*/
public final String messageId() {
return messageId;
}
/**
*
* The content of the Amazon Q Business web experience message.
*
*
* @return The content of the Amazon Q Business web experience message.
*/
public final String body() {
return body;
}
/**
*
* The timestamp of the first Amazon Q Business web experience message.
*
*
* @return The timestamp of the first Amazon Q Business web experience message.
*/
public final Instant time() {
return time;
}
/**
*
* The type of Amazon Q Business message, whether HUMAN
or AI
generated.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #type} will return
* {@link MessageType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #typeAsString}.
*
*
* @return The type of Amazon Q Business message, whether HUMAN
or AI
generated.
* @see MessageType
*/
public final MessageType type() {
return MessageType.fromValue(type);
}
/**
*
* The type of Amazon Q Business message, whether HUMAN
or AI
generated.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #type} will return
* {@link MessageType#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #typeAsString}.
*
*
* @return The type of Amazon Q Business message, whether HUMAN
or AI
generated.
* @see MessageType
*/
public final String typeAsString() {
return type;
}
/**
* For responses, this returns true if the service returned a value for the Attachments 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 hasAttachments() {
return attachments != null && !(attachments instanceof SdkAutoConstructList);
}
/**
*
* A file directly uploaded into an Amazon Q Business web experience chat.
*
*
* 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 #hasAttachments} method.
*
*
* @return A file directly uploaded into an Amazon Q Business web experience chat.
*/
public final List attachments() {
return attachments;
}
/**
* For responses, this returns true if the service returned a value for the SourceAttribution 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 hasSourceAttribution() {
return sourceAttribution != null && !(sourceAttribution instanceof SdkAutoConstructList);
}
/**
*
* The source documents used to generate Amazon Q Business web experience message.
*
*
* 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 #hasSourceAttribution} method.
*
*
* @return The source documents used to generate Amazon Q Business web experience message.
*/
public final List sourceAttribution() {
return sourceAttribution;
}
/**
* Returns the value of the ActionReview property for this object.
*
* @return The value of the ActionReview property for this object.
*/
public final ActionReview actionReview() {
return actionReview;
}
/**
* Returns the value of the ActionExecution property for this object.
*
* @return The value of the ActionExecution property for this object.
*/
public final ActionExecution actionExecution() {
return actionExecution;
}
@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(messageId());
hashCode = 31 * hashCode + Objects.hashCode(body());
hashCode = 31 * hashCode + Objects.hashCode(time());
hashCode = 31 * hashCode + Objects.hashCode(typeAsString());
hashCode = 31 * hashCode + Objects.hashCode(hasAttachments() ? attachments() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasSourceAttribution() ? sourceAttribution() : null);
hashCode = 31 * hashCode + Objects.hashCode(actionReview());
hashCode = 31 * hashCode + Objects.hashCode(actionExecution());
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 Message)) {
return false;
}
Message other = (Message) obj;
return Objects.equals(messageId(), other.messageId()) && Objects.equals(body(), other.body())
&& Objects.equals(time(), other.time()) && Objects.equals(typeAsString(), other.typeAsString())
&& hasAttachments() == other.hasAttachments() && Objects.equals(attachments(), other.attachments())
&& hasSourceAttribution() == other.hasSourceAttribution()
&& Objects.equals(sourceAttribution(), other.sourceAttribution())
&& Objects.equals(actionReview(), other.actionReview())
&& Objects.equals(actionExecution(), other.actionExecution());
}
/**
* 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("Message").add("MessageId", messageId()).add("Body", body()).add("Time", time())
.add("Type", typeAsString()).add("Attachments", hasAttachments() ? attachments() : null)
.add("SourceAttribution", hasSourceAttribution() ? sourceAttribution() : null)
.add("ActionReview", actionReview()).add("ActionExecution", actionExecution()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "messageId":
return Optional.ofNullable(clazz.cast(messageId()));
case "body":
return Optional.ofNullable(clazz.cast(body()));
case "time":
return Optional.ofNullable(clazz.cast(time()));
case "type":
return Optional.ofNullable(clazz.cast(typeAsString()));
case "attachments":
return Optional.ofNullable(clazz.cast(attachments()));
case "sourceAttribution":
return Optional.ofNullable(clazz.cast(sourceAttribution()));
case "actionReview":
return Optional.ofNullable(clazz.cast(actionReview()));
case "actionExecution":
return Optional.ofNullable(clazz.cast(actionExecution()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function