|
| 1 | +/* |
| 2 | + * SPDX-License-Identifier: Apache-2.0 |
| 3 | + * |
| 4 | + * The OpenSearch Contributors require contributions made to |
| 5 | + * this file be licensed under the Apache-2.0 license or a |
| 6 | + * compatible open source license. |
| 7 | + */ |
| 8 | + |
| 9 | +package org.opensearch.client.opensearch._types; |
| 10 | + |
| 11 | +// typedef: _types.TaskFailure |
| 12 | + |
| 13 | +import jakarta.json.stream.JsonGenerator; |
| 14 | +import java.util.function.Function; |
| 15 | +import javax.annotation.Nullable; |
| 16 | +import org.opensearch.client.json.*; |
| 17 | +import org.opensearch.client.util.ApiTypeHelper; |
| 18 | +import org.opensearch.client.util.ObjectBuilder; |
| 19 | +import org.opensearch.client.util.ObjectBuilderBase; |
| 20 | + |
| 21 | +@JsonpDeserializable |
| 22 | +public class TaskFailure implements JsonpSerializable { |
| 23 | + |
| 24 | + private final ErrorCause cause; |
| 25 | + |
| 26 | + @Nullable |
| 27 | + private final String id; |
| 28 | + |
| 29 | + @Nullable |
| 30 | + private final String index; |
| 31 | + |
| 32 | + @Nullable |
| 33 | + private final Integer status; |
| 34 | + |
| 35 | + @Nullable |
| 36 | + private final String type; |
| 37 | + |
| 38 | + // --------------------------------------------------------------------------------------------- |
| 39 | + |
| 40 | + private TaskFailure(Builder builder) { |
| 41 | + |
| 42 | + this.index = builder.index; |
| 43 | + this.id = builder.id; |
| 44 | + this.cause = ApiTypeHelper.requireNonNull(builder.cause, this, "cause"); |
| 45 | + this.status = builder.status; |
| 46 | + this.type = builder.type; |
| 47 | + |
| 48 | + } |
| 49 | + |
| 50 | + public static TaskFailure of(Function<Builder, ObjectBuilder<TaskFailure>> fn) { |
| 51 | + return fn.apply(new Builder()).build(); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * API name: {@code index} |
| 56 | + */ |
| 57 | + @Nullable |
| 58 | + public final String index() { |
| 59 | + return this.index; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * API name: {@code id} |
| 64 | + */ |
| 65 | + @Nullable |
| 66 | + public final String id() { |
| 67 | + return this.id; |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Required - API name: {@code cause} |
| 72 | + */ |
| 73 | + public final ErrorCause cause() { |
| 74 | + return this.cause; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * API name: {@code status} |
| 79 | + */ |
| 80 | + @Nullable |
| 81 | + public final Integer status() { |
| 82 | + return this.status; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * API name: {@code type} |
| 87 | + */ |
| 88 | + @Nullable |
| 89 | + public final String type() { |
| 90 | + return this.type; |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Serialize this object to JSON. |
| 95 | + */ |
| 96 | + public void serialize(JsonGenerator generator, JsonpMapper mapper) { |
| 97 | + generator.writeStartObject(); |
| 98 | + serializeInternal(generator, mapper); |
| 99 | + generator.writeEnd(); |
| 100 | + } |
| 101 | + |
| 102 | + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { |
| 103 | + |
| 104 | + if (this.index != null) { |
| 105 | + generator.writeKey("index"); |
| 106 | + generator.write(this.index); |
| 107 | + |
| 108 | + } |
| 109 | + if (this.id != null) { |
| 110 | + generator.writeKey("id"); |
| 111 | + generator.write(this.id); |
| 112 | + } |
| 113 | + |
| 114 | + generator.writeKey("cause"); |
| 115 | + this.cause.serialize(generator, mapper); |
| 116 | + |
| 117 | + if (this.status != null) { |
| 118 | + generator.writeKey("status"); |
| 119 | + generator.write(this.status); |
| 120 | + } |
| 121 | + if (this.type != null) { |
| 122 | + generator.writeKey("type"); |
| 123 | + generator.write(this.type); |
| 124 | + } |
| 125 | + |
| 126 | + } |
| 127 | + |
| 128 | + // --------------------------------------------------------------------------------------------- |
| 129 | + |
| 130 | + /** |
| 131 | + * Builder for {@link TaskFailure}. |
| 132 | + */ |
| 133 | + |
| 134 | + public static class Builder extends ObjectBuilderBase implements ObjectBuilder<TaskFailure> { |
| 135 | + @Nullable |
| 136 | + private String index; |
| 137 | + |
| 138 | + @Nullable |
| 139 | + private String id; |
| 140 | + |
| 141 | + private ErrorCause cause; |
| 142 | + |
| 143 | + @Nullable |
| 144 | + private Integer status; |
| 145 | + |
| 146 | + @Nullable |
| 147 | + private String type; |
| 148 | + |
| 149 | + /** |
| 150 | + * API name: {@code index} |
| 151 | + */ |
| 152 | + public final Builder index(@Nullable String value) { |
| 153 | + this.index = value; |
| 154 | + return this; |
| 155 | + } |
| 156 | + |
| 157 | + /** |
| 158 | + * API name: {@code id} |
| 159 | + */ |
| 160 | + public final Builder id(@Nullable String value) { |
| 161 | + this.id = value; |
| 162 | + return this; |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * Required - API name: {@code cause} |
| 167 | + */ |
| 168 | + public final Builder cause(ErrorCause value) { |
| 169 | + this.cause = value; |
| 170 | + return this; |
| 171 | + } |
| 172 | + |
| 173 | + /** |
| 174 | + * Required - API name: {@code cause} |
| 175 | + */ |
| 176 | + public final Builder cause(Function<ErrorCause.Builder, ObjectBuilder<ErrorCause>> fn) { |
| 177 | + return this.cause(fn.apply(new ErrorCause.Builder()).build()); |
| 178 | + } |
| 179 | + |
| 180 | + /** |
| 181 | + * API name: {@code status} |
| 182 | + */ |
| 183 | + public final Builder status(@Nullable Integer value) { |
| 184 | + this.status = value; |
| 185 | + return this; |
| 186 | + } |
| 187 | + |
| 188 | + /** |
| 189 | + * API name: {@code type} |
| 190 | + */ |
| 191 | + public final Builder type(@Nullable String value) { |
| 192 | + this.type = value; |
| 193 | + return this; |
| 194 | + } |
| 195 | + |
| 196 | + /** |
| 197 | + * Builds a {@link TaskFailure}. |
| 198 | + * |
| 199 | + * @throws NullPointerException |
| 200 | + * if some of the required fields are null. |
| 201 | + */ |
| 202 | + public TaskFailure build() { |
| 203 | + _checkSingleUse(); |
| 204 | + |
| 205 | + return new TaskFailure(this); |
| 206 | + } |
| 207 | + } |
| 208 | + |
| 209 | + // --------------------------------------------------------------------------------------------- |
| 210 | + |
| 211 | + /** |
| 212 | + * Json deserializer for {@link TaskFailure} |
| 213 | + */ |
| 214 | + public static final JsonpDeserializer<TaskFailure> _DESERIALIZER = ObjectBuilderDeserializer.lazy( |
| 215 | + Builder::new, |
| 216 | + TaskFailure::setupTaskFailureDeserializer |
| 217 | + ); |
| 218 | + |
| 219 | + protected static void setupTaskFailureDeserializer(ObjectDeserializer<Builder> op) { |
| 220 | + |
| 221 | + op.add(Builder::index, JsonpDeserializer.stringDeserializer(), "index"); |
| 222 | + op.add(Builder::id, JsonpDeserializer.stringDeserializer(), "id"); |
| 223 | + op.add(Builder::cause, ErrorCause._DESERIALIZER, "cause"); |
| 224 | + op.add(Builder::status, JsonpDeserializer.integerDeserializer(), "status"); |
| 225 | + op.add(Builder::type, JsonpDeserializer.stringDeserializer(), "type"); |
| 226 | + |
| 227 | + } |
| 228 | + |
| 229 | +} |
0 commit comments