software.amazon.awssdk.services.iot.model.TopicRule Maven / Gradle / Ivy
Show all versions of iot 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.iot.model;
import java.io.Serializable;
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.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;
/**
*
* Describes a rule.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class TopicRule implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField RULE_NAME_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("ruleName").getter(getter(TopicRule::ruleName)).setter(setter(Builder::ruleName))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ruleName").build()).build();
private static final SdkField SQL_FIELD = SdkField. builder(MarshallingType.STRING).memberName("sql")
.getter(getter(TopicRule::sql)).setter(setter(Builder::sql))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("sql").build()).build();
private static final SdkField DESCRIPTION_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("description").getter(getter(TopicRule::description)).setter(setter(Builder::description))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("description").build()).build();
private static final SdkField CREATED_AT_FIELD = SdkField. builder(MarshallingType.INSTANT)
.memberName("createdAt").getter(getter(TopicRule::createdAt)).setter(setter(Builder::createdAt))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("createdAt").build()).build();
private static final SdkField> ACTIONS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("actions")
.getter(getter(TopicRule::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(Action::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField RULE_DISABLED_FIELD = SdkField. builder(MarshallingType.BOOLEAN)
.memberName("ruleDisabled").getter(getter(TopicRule::ruleDisabled)).setter(setter(Builder::ruleDisabled))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ruleDisabled").build()).build();
private static final SdkField AWS_IOT_SQL_VERSION_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("awsIotSqlVersion").getter(getter(TopicRule::awsIotSqlVersion)).setter(setter(Builder::awsIotSqlVersion))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("awsIotSqlVersion").build()).build();
private static final SdkField ERROR_ACTION_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.memberName("errorAction").getter(getter(TopicRule::errorAction)).setter(setter(Builder::errorAction))
.constructor(Action::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("errorAction").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(RULE_NAME_FIELD, SQL_FIELD,
DESCRIPTION_FIELD, CREATED_AT_FIELD, ACTIONS_FIELD, RULE_DISABLED_FIELD, AWS_IOT_SQL_VERSION_FIELD,
ERROR_ACTION_FIELD));
private static final Map> SDK_NAME_TO_FIELD = memberNameToFieldInitializer();
private static final long serialVersionUID = 1L;
private final String ruleName;
private final String sql;
private final String description;
private final Instant createdAt;
private final List actions;
private final Boolean ruleDisabled;
private final String awsIotSqlVersion;
private final Action errorAction;
private TopicRule(BuilderImpl builder) {
this.ruleName = builder.ruleName;
this.sql = builder.sql;
this.description = builder.description;
this.createdAt = builder.createdAt;
this.actions = builder.actions;
this.ruleDisabled = builder.ruleDisabled;
this.awsIotSqlVersion = builder.awsIotSqlVersion;
this.errorAction = builder.errorAction;
}
/**
*
* The name of the rule.
*
*
* @return The name of the rule.
*/
public final String ruleName() {
return ruleName;
}
/**
*
* The SQL statement used to query the topic. When using a SQL query with multiple lines, be sure to escape the
* newline characters.
*
*
* @return The SQL statement used to query the topic. When using a SQL query with multiple lines, be sure to escape
* the newline characters.
*/
public final String sql() {
return sql;
}
/**
*
* The description of the rule.
*
*
* @return The description of the rule.
*/
public final String description() {
return description;
}
/**
*
* The date and time the rule was created.
*
*
* @return The date and time the rule was created.
*/
public final Instant createdAt() {
return createdAt;
}
/**
* 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 actions associated with the rule.
*
*
* 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 actions associated with the rule.
*/
public final List actions() {
return actions;
}
/**
*
* Specifies whether the rule is disabled.
*
*
* @return Specifies whether the rule is disabled.
*/
public final Boolean ruleDisabled() {
return ruleDisabled;
}
/**
*
* The version of the SQL rules engine to use when evaluating the rule.
*
*
* @return The version of the SQL rules engine to use when evaluating the rule.
*/
public final String awsIotSqlVersion() {
return awsIotSqlVersion;
}
/**
*
* The action to perform when an error occurs.
*
*
* @return The action to perform when an error occurs.
*/
public final Action errorAction() {
return errorAction;
}
@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(ruleName());
hashCode = 31 * hashCode + Objects.hashCode(sql());
hashCode = 31 * hashCode + Objects.hashCode(description());
hashCode = 31 * hashCode + Objects.hashCode(createdAt());
hashCode = 31 * hashCode + Objects.hashCode(hasActions() ? actions() : null);
hashCode = 31 * hashCode + Objects.hashCode(ruleDisabled());
hashCode = 31 * hashCode + Objects.hashCode(awsIotSqlVersion());
hashCode = 31 * hashCode + Objects.hashCode(errorAction());
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 TopicRule)) {
return false;
}
TopicRule other = (TopicRule) obj;
return Objects.equals(ruleName(), other.ruleName()) && Objects.equals(sql(), other.sql())
&& Objects.equals(description(), other.description()) && Objects.equals(createdAt(), other.createdAt())
&& hasActions() == other.hasActions() && Objects.equals(actions(), other.actions())
&& Objects.equals(ruleDisabled(), other.ruleDisabled())
&& Objects.equals(awsIotSqlVersion(), other.awsIotSqlVersion())
&& Objects.equals(errorAction(), other.errorAction());
}
/**
* 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("TopicRule").add("RuleName", ruleName()).add("Sql", sql()).add("Description", description())
.add("CreatedAt", createdAt()).add("Actions", hasActions() ? actions() : null)
.add("RuleDisabled", ruleDisabled()).add("AwsIotSqlVersion", awsIotSqlVersion())
.add("ErrorAction", errorAction()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "ruleName":
return Optional.ofNullable(clazz.cast(ruleName()));
case "sql":
return Optional.ofNullable(clazz.cast(sql()));
case "description":
return Optional.ofNullable(clazz.cast(description()));
case "createdAt":
return Optional.ofNullable(clazz.cast(createdAt()));
case "actions":
return Optional.ofNullable(clazz.cast(actions()));
case "ruleDisabled":
return Optional.ofNullable(clazz.cast(ruleDisabled()));
case "awsIotSqlVersion":
return Optional.ofNullable(clazz.cast(awsIotSqlVersion()));
case "errorAction":
return Optional.ofNullable(clazz.cast(errorAction()));
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("ruleName", RULE_NAME_FIELD);
map.put("sql", SQL_FIELD);
map.put("description", DESCRIPTION_FIELD);
map.put("createdAt", CREATED_AT_FIELD);
map.put("actions", ACTIONS_FIELD);
map.put("ruleDisabled", RULE_DISABLED_FIELD);
map.put("awsIotSqlVersion", AWS_IOT_SQL_VERSION_FIELD);
map.put("errorAction", ERROR_ACTION_FIELD);
return Collections.unmodifiableMap(map);
}
private static Function